Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Adrien Beraud <adrien.beraud@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | package com.savoirfairelinux.sflphone.client; |
| 32 | |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 33 | import java.util.Random; |
| 34 | |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 35 | import android.app.ActionBar; |
| 36 | import android.app.Activity; |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 37 | import android.app.AlertDialog; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 38 | import android.app.Fragment; |
| 39 | import android.app.FragmentManager; |
| 40 | import android.app.FragmentTransaction; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 41 | import android.content.ComponentName; |
| 42 | import android.content.Context; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 43 | import android.content.Intent; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 44 | import android.content.ServiceConnection; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 45 | import android.os.Bundle; |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 46 | import android.os.Handler; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 47 | import android.os.IBinder; |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 48 | import android.os.Message; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 49 | import android.os.RemoteException; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 50 | import android.support.v13.app.FragmentStatePagerAdapter; |
| 51 | import android.support.v4.view.ViewPager; |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 52 | import android.util.Log; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 53 | import android.view.Gravity; |
| 54 | import android.view.LayoutInflater; |
| 55 | import android.view.Menu; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 56 | import android.view.MenuItem; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 57 | import android.view.View; |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 58 | import android.view.View.OnClickListener; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 59 | import android.view.ViewGroup; |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 60 | import android.view.animation.AlphaAnimation; |
| 61 | import android.view.animation.Animation; |
| 62 | import android.view.animation.LinearInterpolator; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 63 | import android.widget.Button; |
Emeric Vigier | d5c17f5 | 2012-08-29 09:29:33 -0400 | [diff] [blame] | 64 | import android.widget.EditText; |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 65 | import android.widget.ImageButton; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 66 | import android.widget.TextView; |
| 67 | |
| 68 | import com.savoirfairelinux.sflphone.R; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 69 | import com.savoirfairelinux.sflphone.service.ISipService; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 70 | import com.savoirfairelinux.sflphone.service.SipService; |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 71 | import com.savoirfairelinux.sflphone.utils.AccountList; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 72 | |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 73 | import java.util.HashMap; |
| 74 | |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 75 | public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 76 | { |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 77 | SectionsPagerAdapter mSectionsPagerAdapter; |
| 78 | static final String TAG = "SFLPhoneHome"; |
| 79 | private ButtonSectionFragment buttonFragment; |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 80 | /* default callID */ |
| 81 | static String callID = "007"; |
| 82 | static boolean callOnGoing = false; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 83 | static boolean serviceIsOn = false; |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 84 | private String incomingCallID = ""; |
| 85 | private static final int REQUEST_CODE_PREFERENCES = 1; |
| 86 | ImageButton buttonCall, buttonHangup; |
| 87 | Button buttonService; |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 88 | static Animation animation; |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 89 | ContactListFragment mContactListFragment; |
| 90 | CallElementList mCallElementList; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 91 | private boolean mBound = false; |
| 92 | private ISipService service; |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 93 | public AccountList mAccountList = new AccountList(); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 94 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 95 | /** |
| 96 | * The {@link ViewPager} that will host the section contents. |
| 97 | */ |
| 98 | ViewPager mViewPager; |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 99 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 100 | final private int[] icon_res_id = {R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history, R.drawable.ic_tab_play_selected}; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 101 | |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 102 | // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
| 103 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 104 | @Override |
| 105 | public void onCreate(Bundle savedInstanceState) |
| 106 | { |
| 107 | super.onCreate(savedInstanceState); |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 108 | |
| 109 | if (!serviceIsOn) { |
| 110 | Log.i(TAG, "starting SipService"); |
| 111 | startSipService(); |
| 112 | } |
| 113 | |
| 114 | // Bind to LocalService |
| 115 | if (!mBound) { |
| 116 | Log.i(TAG, "onStart: Binding service..."); |
| 117 | Intent intent = new Intent(this, SipService.class); |
| 118 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 119 | } |
| 120 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 121 | setContentView(R.layout.activity_sflphone_home); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 122 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 123 | mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 124 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 125 | final ActionBar actionBar = getActionBar(); |
| 126 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
| 127 | // final ActionBar actionBar = getActionBar(); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 128 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 129 | // Set up the ViewPager with the sections adapter. |
| 130 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 131 | mViewPager.setAdapter(mSectionsPagerAdapter); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 132 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 133 | // When swiping between different sections, select the corresponding tab. |
| 134 | // We can also use ActionBar.Tab#select() to do this if we have a reference to the |
| 135 | // Tab. |
| 136 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() |
| 137 | { |
| 138 | @Override |
| 139 | public void onPageSelected(int position) |
| 140 | { |
| 141 | actionBar.setSelectedNavigationItem(position); |
| 142 | } |
| 143 | }); |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 144 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 145 | // For each of the sections in the app, add a tab to the action bar. |
| 146 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 147 | // Create a tab with text corresponding to the page title defined by the adapter. |
| 148 | // Also specify this Activity object, which implements the TabListener interface, as the |
| 149 | // listener for when this tab is selected. |
| 150 | Log.i(TAG, "adding tab: " + i); |
| 151 | actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); |
| 152 | } |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 153 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 154 | buttonCall = (ImageButton) findViewById(R.id.buttonCall); |
| 155 | buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp); |
Alexandre Savard | def3bfa | 2012-09-12 16:20:06 -0400 | [diff] [blame] | 156 | |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 157 | // Change alpha from fully visible to invisible |
| 158 | animation = new AlphaAnimation(1, 0); |
| 159 | // duration - half a second |
| 160 | animation.setDuration(500); |
| 161 | // do not alter animation rate |
| 162 | animation.setInterpolator(new LinearInterpolator()); |
| 163 | // Repeat animation infinitely |
| 164 | animation.setRepeatCount(Animation.INFINITE); |
| 165 | // Reverse |
| 166 | animation.setRepeatMode(Animation.REVERSE); |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 167 | } |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 168 | |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 169 | @Override |
| 170 | protected void onStart() { |
| 171 | Log.i(TAG, "onStart"); |
| 172 | super.onStart(); |
| 173 | } |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 174 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 175 | /* user gets back to the activity, e.g. through task manager */ |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 176 | @Override |
| 177 | protected void onRestart() { |
| 178 | super.onRestart(); |
| 179 | } |
| 180 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 181 | /* activity gets back to the foreground and user input */ |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 182 | @Override |
| 183 | protected void onResume() { |
| 184 | Log.i(TAG, "onResume"); |
| 185 | super.onResume(); |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 186 | } |
| 187 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 188 | /* activity no more in foreground */ |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 189 | @Override |
| 190 | protected void onPause() { |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 191 | super.onPause(); |
| 192 | } |
| 193 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 194 | /* activity is no longer visible */ |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 195 | @Override |
| 196 | protected void onStop() { |
| 197 | super.onStop(); |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* activity finishes itself or is being killed by the system */ |
| 201 | @Override |
| 202 | protected void onDestroy() { |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 203 | /* stop the service, if no other bound user, no need to check if it is running */ |
| 204 | if (mBound) { |
Emeric Vigier | fae29bd | 2012-09-24 11:32:03 -0400 | [diff] [blame] | 205 | Log.i(TAG, "onStop: Unbinding service..."); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 206 | unbindService(mConnection); |
| 207 | mBound = false; |
| 208 | } |
Emeric Vigier | fae29bd | 2012-09-24 11:32:03 -0400 | [diff] [blame] | 209 | Log.i(TAG, "onDestroy: stopping SipService..."); |
| 210 | stopService(new Intent(this, SipService.class)); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 211 | serviceIsOn = false; |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 212 | super.onDestroy(); |
| 213 | } |
| 214 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 215 | /** Defines callbacks for service binding, passed to bindService() */ |
| 216 | private ServiceConnection mConnection = new ServiceConnection() { |
| 217 | |
| 218 | @Override |
| 219 | public void onServiceConnected(ComponentName className, |
| 220 | IBinder binder) { |
| 221 | service = ISipService.Stub.asInterface(binder); |
| 222 | mBound = true; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 223 | mContactListFragment.setService(service); |
| 224 | mCallElementList.setService(service); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 225 | Log.d(TAG, "Service connected"); |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public void onServiceDisconnected(ComponentName arg0) { |
| 230 | mBound = false; |
| 231 | Log.d(TAG, "Service disconnected"); |
| 232 | } |
| 233 | }; |
| 234 | |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 235 | private void startSipService() { |
| 236 | Thread thread = new Thread("StartSFLphoneService") { |
| 237 | public void run() { |
| 238 | Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class); |
| 239 | //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class)); |
| 240 | startService(sipServiceIntent); |
Emeric Vigier | fae29bd | 2012-09-24 11:32:03 -0400 | [diff] [blame] | 241 | serviceIsOn = true; |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 242 | }; |
| 243 | }; |
| 244 | try { |
| 245 | thread.start(); |
| 246 | } catch (IllegalThreadStateException e) { |
| 247 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 248 | builder.setMessage("Cannot start SFLPhone SipService!"); |
| 249 | AlertDialog alert = builder.create(); |
| 250 | alert.show(); |
| 251 | finish(); |
| 252 | } |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | @Override |
| 256 | public boolean onOptionsItemSelected(MenuItem item) { |
| 257 | Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId()); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 258 | if(item.getItemId() != 0) { |
| 259 | // When the button is clicked, launch an activity through this intent |
| 260 | Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 261 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 262 | // Make it a subactivity so we know when it returns |
| 263 | startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 264 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 265 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 266 | return super.onOptionsItemSelected(item); |
| 267 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 268 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 269 | @Override |
| 270 | public boolean onCreateOptionsMenu(Menu menu) |
| 271 | { |
| 272 | getMenuInflater().inflate(R.menu.activity_sflphone_home, menu); |
| 273 | return true; |
| 274 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 275 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 276 | @Override |
| 277 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 278 | { |
| 279 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 280 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 281 | @Override |
| 282 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 283 | { |
| 284 | // When the given tab is selected, switch to the corresponding page in the ViewPager. |
| 285 | mViewPager.setCurrentItem(tab.getPosition()); |
| 286 | } |
| 287 | |
| 288 | @Override |
| 289 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 290 | { |
| 291 | // Log.d(TAG, "onTabReselected"); |
| 292 | } |
| 293 | |
| 294 | public void setIncomingCallID(String accountID, String callID, String from) { |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 295 | Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")"); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 296 | incomingCallID = callID; |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 297 | buttonCall.startAnimation(animation); |
| 298 | buttonCall.setImageResource(R.drawable.ic_incomingcall); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 299 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 300 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 301 | /** |
| 302 | * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to |
| 303 | * one of the primary sections of the app. |
| 304 | */ |
| 305 | public class SectionsPagerAdapter extends FragmentStatePagerAdapter |
| 306 | { |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 307 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 308 | public SectionsPagerAdapter(FragmentManager fm) |
| 309 | { |
| 310 | super(fm); |
| 311 | } |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 312 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 313 | @Override |
| 314 | public Fragment getItem(int i) |
| 315 | { |
| 316 | Fragment fragment; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 317 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 318 | switch (i) { |
| 319 | case 0: |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 320 | mContactListFragment = new ContactListFragment(service); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 321 | fragment = mContactListFragment; |
| 322 | break; |
| 323 | case 1: |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 324 | mCallElementList = new CallElementList(service); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 325 | SipCall.setCallElementList(mCallElementList); |
| 326 | fragment = mCallElementList; |
| 327 | break; |
| 328 | case 2: |
| 329 | fragment = new DummySectionFragment(); |
| 330 | break; |
| 331 | case 3: |
| 332 | fragment = new ButtonSectionFragment(); |
| 333 | Log.i(TAG, "getItem: fragment is " + fragment); |
| 334 | break; |
| 335 | default: |
| 336 | Log.e(TAG, "getItem: unknown tab position " + i); |
| 337 | return null; |
| 338 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 339 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 340 | Bundle args = new Bundle(); |
| 341 | args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1); |
| 342 | fragment.setArguments(args); |
| 343 | return fragment; |
| 344 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 345 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 346 | @Override |
| 347 | public int getCount() |
| 348 | { |
| 349 | return 4; |
| 350 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 351 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 352 | @Override |
| 353 | public CharSequence getPageTitle(int position) |
| 354 | { |
| 355 | switch (position) { |
| 356 | case 0: |
| 357 | return getString(R.string.title_section0).toUpperCase(); |
| 358 | case 1: |
| 359 | return getString(R.string.title_section1).toUpperCase(); |
| 360 | case 2: |
| 361 | return getString(R.string.title_section2).toUpperCase(); |
| 362 | case 3: |
| 363 | return getString(R.string.title_section3).toUpperCase(); |
| 364 | default: |
| 365 | Log.e(TAG, "getPageTitle: unknown tab position " + position); |
| 366 | break; |
| 367 | } |
| 368 | return null; |
| 369 | } |
| 370 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 371 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 372 | /** |
| 373 | * A dummy fragment representing a section of the app, but that simply |
| 374 | * displays dummy text. |
| 375 | */ |
| 376 | public static class DummySectionFragment extends Fragment |
| 377 | { |
| 378 | public DummySectionFragment() |
| 379 | { |
| 380 | setRetainInstance(true); |
| 381 | } |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 382 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 383 | public static final String ARG_SECTION_NUMBER = "section_number"; |
| 384 | |
| 385 | @Override |
| 386 | public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) |
| 387 | { |
| 388 | TextView textView = new TextView(getActivity()); |
| 389 | textView.setGravity(Gravity.CENTER); |
| 390 | Bundle args = getArguments(); |
| 391 | textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER))); |
| 392 | textView.setText("java sucks"); |
| 393 | return textView; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | @Override |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 398 | public void onClick(View view) |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 399 | { |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 400 | Log.i(TAG, "onClic from SFLPhoneHome"); |
Alexandre Savard | 2c50e69 | 2012-09-24 11:18:31 -0400 | [diff] [blame] | 401 | |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 402 | buttonService = (Button) findViewById(R.id.buttonService); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 403 | |
| 404 | try { |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 405 | switch (view.getId()) { |
| 406 | case R.id.buttonCall: |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 407 | Log.i(TAG, "Processing new call action"); |
| 408 | processingNewCallAction(); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 409 | break; |
| 410 | case R.id.buttonHangUp: |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 411 | Log.i(TAG, "Processing hangup action"); |
| 412 | processingHangUpAction(); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 413 | break; |
| 414 | case R.id.buttonInit: |
| 415 | Log.i(TAG, "R.id.buttonInit"); |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 416 | // String audioPlugin = service.getCurrentAudioOutputPlugin(); |
| 417 | HashMap<String, String> map = (HashMap<String, String>)service.getAccountDetails("Account:1345153770"); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 418 | break; |
| 419 | case R.id.buttonService: |
| 420 | if (!serviceIsOn) { |
| 421 | startService(new Intent(this, SipService.class)); |
| 422 | serviceIsOn = true; |
| 423 | buttonService.setText("disable Service"); |
| 424 | } |
| 425 | else { |
| 426 | stopService(new Intent(this, SipService.class)); |
| 427 | serviceIsOn = false; |
| 428 | buttonService.setText("enable Service"); |
| 429 | } |
| 430 | break; |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 431 | default: |
| 432 | Log.w(TAG, "unknown button " + view.getId()); |
| 433 | break; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 434 | } |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 435 | } catch (RemoteException e) { |
| 436 | Log.e(TAG, "Cannot call service method", e); |
| 437 | } |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 438 | } |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 439 | |
| 440 | public void processingNewCallAction() { |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 441 | /* |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 442 | Log.d(TAG, "ProcessingNewCallAction()"); |
| 443 | TextView textView = (TextView) findViewById(R.id.editAccountID); |
| 444 | String accountID = mAccountList.currentAccountID; |
| 445 | // String accountID = textView.getText().toString(); |
| 446 | // buttonCall.setImageResource(R.drawable.ic_call); |
| 447 | EditText editText; |
| 448 | Random random = new Random(); |
| 449 | |
| 450 | try { |
| 451 | |
| 452 | if (incomingCallID != "") { |
| 453 | Log.d(TAG, "Incoming Call Branch"); |
| 454 | buttonCall.clearAnimation(); |
| 455 | service.accept(incomingCallID); |
| 456 | callID = incomingCallID; |
| 457 | incomingCallID=""; |
| 458 | callOnGoing = true; |
| 459 | buttonCall.setEnabled(false); |
| 460 | buttonHangup.setEnabled(true); |
| 461 | } else { |
| 462 | //if (callOnGoing == false) { |
| 463 | Log.d(TAG, "Outgoing Call Branch"); |
| 464 | editText = (EditText) findViewById(R.id.editTo); |
| 465 | String to = "147"; // editText.getText().toString(); |
| 466 | Log.d(TAG, "to string is " + to); |
| 467 | if (to == null) { |
| 468 | Log.e(TAG, "to string is " + to); |
| 469 | return; |
| 470 | } |
| 471 | |
| 472 | callID = Integer.toString(random.nextInt()); |
| 473 | |
| 474 | Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");"); |
| 475 | service.placeCall(accountID, callID, to); |
| 476 | callOnGoing = true; |
| 477 | buttonCall.setEnabled(false); |
| 478 | buttonHangup.setEnabled(true); |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 479 | launchCallActivity(); |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 480 | //} |
| 481 | } |
| 482 | |
| 483 | } catch (RemoteException e) { |
| 484 | Log.e(TAG, "Cannot call service method", e); |
| 485 | } |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 486 | */ |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame^] | 487 | SipCall call = new SipCall(); |
| 488 | launchCallActivity(call); |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | public void processingHangUpAction() { |
| 492 | try { |
| 493 | if (incomingCallID != "") { |
| 494 | buttonCall.clearAnimation(); |
| 495 | Log.d(TAG, "service.refuse(" + incomingCallID + ");"); |
| 496 | service.refuse(incomingCallID); |
| 497 | incomingCallID=""; |
| 498 | buttonCall.setEnabled(true); |
| 499 | buttonHangup.setEnabled(true); |
| 500 | } else { |
| 501 | if (callOnGoing == true) { |
| 502 | Log.d(TAG, "service.hangUp(" + callID + ");"); |
| 503 | service.hangUp(callID); |
| 504 | callOnGoing = false; |
| 505 | buttonCall.setEnabled(true); |
| 506 | buttonHangup.setEnabled(false); |
| 507 | } |
| 508 | } |
| 509 | } catch (RemoteException e) { |
| 510 | Log.e(TAG, "Cannot call service method", e); |
| 511 | } |
| 512 | |
| 513 | buttonCall.setImageResource(R.drawable.ic_call); |
| 514 | } |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 515 | |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame^] | 516 | private void launchCallActivity(SipCall call) |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 517 | { |
| 518 | Log.i(TAG, "Launch Call Activity"); |
Alexandre Savard | 6d54bbc | 2012-10-24 11:04:23 -0400 | [diff] [blame^] | 519 | Bundle bundle = new Bundle(); |
| 520 | bundle.putString("CallID", call.mCallInfo.mCallID); |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 521 | Intent intent = new Intent().setClass(this, CallActivity.class); |
| 522 | startActivity(intent); |
| 523 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 524 | } |