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; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 44 | import android.content.IntentFilter; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 45 | import android.content.ServiceConnection; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 46 | import android.os.Bundle; |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 47 | import android.os.Handler; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 48 | import android.os.IBinder; |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 49 | import android.os.Message; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 50 | import android.os.RemoteException; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 51 | import android.support.v13.app.FragmentStatePagerAdapter; |
| 52 | import android.support.v4.view.ViewPager; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 53 | import android.support.v4.content.LocalBroadcastManager; |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 54 | import android.util.Log; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 55 | import android.view.Gravity; |
| 56 | import android.view.LayoutInflater; |
| 57 | import android.view.Menu; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 58 | import android.view.MenuItem; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 59 | import android.view.View; |
| 60 | import android.view.ViewGroup; |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 61 | import android.view.View.OnClickListener; |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 62 | import android.view.animation.AlphaAnimation; |
| 63 | import android.view.animation.Animation; |
| 64 | import android.view.animation.LinearInterpolator; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 65 | import android.widget.Button; |
Emeric Vigier | d5c17f5 | 2012-08-29 09:29:33 -0400 | [diff] [blame] | 66 | import android.widget.EditText; |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 67 | import android.widget.ImageButton; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 68 | import android.widget.TextView; |
| 69 | |
| 70 | import com.savoirfairelinux.sflphone.R; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 71 | import com.savoirfairelinux.sflphone.service.ISipService; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 72 | import com.savoirfairelinux.sflphone.service.SipService; |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 73 | import com.savoirfairelinux.sflphone.utils.AccountList; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 74 | import com.savoirfairelinux.sflphone.utils.CallList; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 75 | |
Alexandre Savard | 7a902bc | 2012-10-04 16:32:35 -0400 | [diff] [blame] | 76 | import java.util.HashMap; |
| 77 | |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 78 | public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 79 | { |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 80 | SectionsPagerAdapter mSectionsPagerAdapter; |
| 81 | static final String TAG = "SFLPhoneHome"; |
| 82 | private ButtonSectionFragment buttonFragment; |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 83 | /* default callID */ |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 84 | static boolean serviceIsOn = false; |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 85 | private String incomingCallID = ""; |
| 86 | private static final int REQUEST_CODE_PREFERENCES = 1; |
| 87 | ImageButton buttonCall, buttonHangup; |
| 88 | Button buttonService; |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 89 | static Animation animation; |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 90 | ContactListFragment mContactListFragment; |
| 91 | CallElementList mCallElementList; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 92 | private boolean mBound = false; |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 93 | private SFLPhoneHome mHome = this; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 94 | private ISipService service; |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 95 | public AccountList mAccountList = new AccountList(); |
Alexandre Savard | 73bc56f | 2012-10-25 13:35:54 -0400 | [diff] [blame] | 96 | public CallList mCallList = new CallList(this); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 97 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 98 | /** |
| 99 | * The {@link ViewPager} that will host the section contents. |
| 100 | */ |
| 101 | ViewPager mViewPager; |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 102 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 103 | 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] | 104 | |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 105 | // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
| 106 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 107 | @Override |
| 108 | public void onCreate(Bundle savedInstanceState) |
| 109 | { |
| 110 | super.onCreate(savedInstanceState); |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 111 | |
| 112 | if (!serviceIsOn) { |
| 113 | Log.i(TAG, "starting SipService"); |
| 114 | startSipService(); |
| 115 | } |
| 116 | |
| 117 | // Bind to LocalService |
| 118 | if (!mBound) { |
| 119 | Log.i(TAG, "onStart: Binding service..."); |
| 120 | Intent intent = new Intent(this, SipService.class); |
| 121 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 122 | } |
| 123 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 124 | setContentView(R.layout.activity_sflphone_home); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 125 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 126 | mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 127 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 128 | final ActionBar actionBar = getActionBar(); |
| 129 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
| 130 | // final ActionBar actionBar = getActionBar(); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 131 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 132 | // Set up the ViewPager with the sections adapter. |
| 133 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 134 | mViewPager.setAdapter(mSectionsPagerAdapter); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 135 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 136 | // When swiping between different sections, select the corresponding tab. |
| 137 | // We can also use ActionBar.Tab#select() to do this if we have a reference to the |
| 138 | // Tab. |
| 139 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() |
| 140 | { |
| 141 | @Override |
| 142 | public void onPageSelected(int position) |
| 143 | { |
| 144 | actionBar.setSelectedNavigationItem(position); |
| 145 | } |
| 146 | }); |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 147 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 148 | // For each of the sections in the app, add a tab to the action bar. |
| 149 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 150 | // Create a tab with text corresponding to the page title defined by the adapter. |
| 151 | // Also specify this Activity object, which implements the TabListener interface, as the |
| 152 | // listener for when this tab is selected. |
| 153 | Log.i(TAG, "adding tab: " + i); |
| 154 | actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); |
| 155 | } |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 156 | |
Alexandre Savard | cb66fa4 | 2012-10-26 10:06:16 -0400 | [diff] [blame^] | 157 | actionBar.setSelectedNavigationItem(1); |
| 158 | |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 159 | buttonCall = (ImageButton) findViewById(R.id.buttonCall); |
| 160 | buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp); |
Alexandre Savard | def3bfa | 2012-09-12 16:20:06 -0400 | [diff] [blame] | 161 | |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 162 | // Change alpha from fully visible to invisible |
| 163 | animation = new AlphaAnimation(1, 0); |
| 164 | // duration - half a second |
| 165 | animation.setDuration(500); |
| 166 | // do not alter animation rate |
| 167 | animation.setInterpolator(new LinearInterpolator()); |
| 168 | // Repeat animation infinitely |
| 169 | animation.setRepeatCount(Animation.INFINITE); |
| 170 | // Reverse |
| 171 | animation.setRepeatMode(Animation.REVERSE); |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 172 | |
| 173 | LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("new-call-created")); |
| 174 | LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("call-state-changed")); |
| 175 | LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("incoming-call")); |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 176 | |
| 177 | SipCall.setSFLPhoneHomeContext(this); |
Alexandre Savard | 6c0584e | 2012-09-20 09:42:59 -0400 | [diff] [blame] | 178 | } |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 179 | |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 180 | @Override |
| 181 | protected void onStart() { |
| 182 | Log.i(TAG, "onStart"); |
| 183 | super.onStart(); |
| 184 | } |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 185 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 186 | /* user gets back to the activity, e.g. through task manager */ |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 187 | @Override |
| 188 | protected void onRestart() { |
| 189 | super.onRestart(); |
| 190 | } |
| 191 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 192 | /* activity gets back to the foreground and user input */ |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 193 | @Override |
| 194 | protected void onResume() { |
| 195 | Log.i(TAG, "onResume"); |
| 196 | super.onResume(); |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 197 | } |
| 198 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 199 | /* activity no more in foreground */ |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 200 | @Override |
| 201 | protected void onPause() { |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 202 | super.onPause(); |
| 203 | } |
| 204 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 205 | /* activity is no longer visible */ |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 206 | @Override |
| 207 | protected void onStop() { |
| 208 | super.onStop(); |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /* activity finishes itself or is being killed by the system */ |
| 212 | @Override |
| 213 | protected void onDestroy() { |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 214 | /* stop the service, if no other bound user, no need to check if it is running */ |
| 215 | if (mBound) { |
Emeric Vigier | fae29bd | 2012-09-24 11:32:03 -0400 | [diff] [blame] | 216 | Log.i(TAG, "onStop: Unbinding service..."); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 217 | unbindService(mConnection); |
| 218 | mBound = false; |
| 219 | } |
Emeric Vigier | fae29bd | 2012-09-24 11:32:03 -0400 | [diff] [blame] | 220 | Log.i(TAG, "onDestroy: stopping SipService..."); |
| 221 | stopService(new Intent(this, SipService.class)); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 222 | serviceIsOn = false; |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 223 | super.onDestroy(); |
| 224 | } |
| 225 | |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 226 | /** Defines callbacks for service binding, passed to bindService() */ |
| 227 | private ServiceConnection mConnection = new ServiceConnection() { |
| 228 | |
| 229 | @Override |
| 230 | public void onServiceConnected(ComponentName className, |
| 231 | IBinder binder) { |
| 232 | service = ISipService.Stub.asInterface(binder); |
| 233 | mBound = true; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 234 | mContactListFragment.setService(service); |
| 235 | mCallElementList.setService(service); |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 236 | Log.d(TAG, "Service connected"); |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void onServiceDisconnected(ComponentName arg0) { |
| 241 | mBound = false; |
| 242 | Log.d(TAG, "Service disconnected"); |
| 243 | } |
| 244 | }; |
| 245 | |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 246 | private void startSipService() { |
| 247 | Thread thread = new Thread("StartSFLphoneService") { |
| 248 | public void run() { |
| 249 | Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class); |
| 250 | //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class)); |
| 251 | startService(sipServiceIntent); |
Emeric Vigier | fae29bd | 2012-09-24 11:32:03 -0400 | [diff] [blame] | 252 | serviceIsOn = true; |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 253 | }; |
| 254 | }; |
| 255 | try { |
| 256 | thread.start(); |
| 257 | } catch (IllegalThreadStateException e) { |
| 258 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 259 | builder.setMessage("Cannot start SFLPhone SipService!"); |
| 260 | AlertDialog alert = builder.create(); |
| 261 | alert.show(); |
| 262 | finish(); |
| 263 | } |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public boolean onOptionsItemSelected(MenuItem item) { |
| 268 | Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId()); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 269 | if(item.getItemId() != 0) { |
| 270 | // When the button is clicked, launch an activity through this intent |
| 271 | Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 272 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 273 | // Make it a subactivity so we know when it returns |
| 274 | startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 275 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 276 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 277 | return super.onOptionsItemSelected(item); |
| 278 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 279 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 280 | @Override |
| 281 | public boolean onCreateOptionsMenu(Menu menu) |
| 282 | { |
| 283 | getMenuInflater().inflate(R.menu.activity_sflphone_home, menu); |
| 284 | return true; |
| 285 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 286 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 287 | @Override |
| 288 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 289 | { |
| 290 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 291 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 292 | @Override |
| 293 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 294 | { |
| 295 | // When the given tab is selected, switch to the corresponding page in the ViewPager. |
| 296 | mViewPager.setCurrentItem(tab.getPosition()); |
| 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 301 | { |
| 302 | // Log.d(TAG, "onTabReselected"); |
| 303 | } |
| 304 | |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 305 | public void onSelectedCallAction(SipCall call) { |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 306 | int callState = call.getCallStateInt(); |
| 307 | |
| 308 | if((callState == SipCall.CALL_STATE_NONE) || |
| 309 | (callState == SipCall.CALL_STATE_CURRENT)) { |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 310 | buttonCall.setEnabled(false); |
| 311 | buttonHangup.setEnabled(true); |
| 312 | } |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 313 | else { |
| 314 | buttonCall.setEnabled(true); |
| 315 | buttonHangup.setEnabled(false); |
| 316 | } |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 317 | |
| 318 | buttonCall.setTag(call); |
| 319 | buttonHangup.setTag(call); |
| 320 | } |
| 321 | |
| 322 | public void onUnselectedCallAction() { |
| 323 | buttonCall.setTag(null); |
| 324 | buttonCall.setTag(null); |
Alexandre Savard | a949eec | 2012-10-25 17:30:49 -0400 | [diff] [blame] | 325 | |
| 326 | buttonCall.setEnabled(true); |
| 327 | buttonHangup.setEnabled(false); |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 328 | } |
| 329 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 330 | public void setIncomingCallID(String accountID, String callID, String from) { |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 331 | Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")"); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 332 | incomingCallID = callID; |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 333 | buttonCall.startAnimation(animation); |
| 334 | buttonCall.setImageResource(R.drawable.ic_incomingcall); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 335 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 336 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 337 | /** |
| 338 | * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to |
| 339 | * one of the primary sections of the app. |
| 340 | */ |
| 341 | public class SectionsPagerAdapter extends FragmentStatePagerAdapter |
| 342 | { |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 343 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 344 | public SectionsPagerAdapter(FragmentManager fm) |
| 345 | { |
| 346 | super(fm); |
| 347 | } |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 348 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 349 | @Override |
| 350 | public Fragment getItem(int i) |
| 351 | { |
| 352 | Fragment fragment; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 353 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 354 | switch (i) { |
| 355 | case 0: |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 356 | mContactListFragment = new ContactListFragment(service); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 357 | fragment = mContactListFragment; |
| 358 | break; |
| 359 | case 1: |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 360 | mCallElementList = new CallElementList(service, mHome); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 361 | SipCall.setCallElementList(mCallElementList); |
| 362 | fragment = mCallElementList; |
| 363 | break; |
| 364 | case 2: |
| 365 | fragment = new DummySectionFragment(); |
| 366 | break; |
| 367 | case 3: |
| 368 | fragment = new ButtonSectionFragment(); |
| 369 | Log.i(TAG, "getItem: fragment is " + fragment); |
| 370 | break; |
| 371 | default: |
| 372 | Log.e(TAG, "getItem: unknown tab position " + i); |
| 373 | return null; |
| 374 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 375 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 376 | Bundle args = new Bundle(); |
| 377 | args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1); |
| 378 | fragment.setArguments(args); |
| 379 | return fragment; |
| 380 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 381 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 382 | @Override |
| 383 | public int getCount() |
| 384 | { |
| 385 | return 4; |
| 386 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 387 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 388 | @Override |
| 389 | public CharSequence getPageTitle(int position) |
| 390 | { |
| 391 | switch (position) { |
| 392 | case 0: |
| 393 | return getString(R.string.title_section0).toUpperCase(); |
| 394 | case 1: |
| 395 | return getString(R.string.title_section1).toUpperCase(); |
| 396 | case 2: |
| 397 | return getString(R.string.title_section2).toUpperCase(); |
| 398 | case 3: |
| 399 | return getString(R.string.title_section3).toUpperCase(); |
| 400 | default: |
| 401 | Log.e(TAG, "getPageTitle: unknown tab position " + position); |
| 402 | break; |
| 403 | } |
| 404 | return null; |
| 405 | } |
| 406 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 407 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 408 | /** |
| 409 | * A dummy fragment representing a section of the app, but that simply |
| 410 | * displays dummy text. |
| 411 | */ |
| 412 | public static class DummySectionFragment extends Fragment |
| 413 | { |
| 414 | public DummySectionFragment() |
| 415 | { |
| 416 | setRetainInstance(true); |
| 417 | } |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 418 | |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 419 | public static final String ARG_SECTION_NUMBER = "section_number"; |
| 420 | |
| 421 | @Override |
| 422 | public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) |
| 423 | { |
| 424 | TextView textView = new TextView(getActivity()); |
| 425 | textView.setGravity(Gravity.CENTER); |
| 426 | Bundle args = getArguments(); |
| 427 | textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER))); |
| 428 | textView.setText("java sucks"); |
| 429 | return textView; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | @Override |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 434 | public void onClick(View view) |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 435 | { |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 436 | Log.i(TAG, "onClic from SFLPhoneHome"); |
Alexandre Savard | 9105244 | 2012-10-25 16:14:26 -0400 | [diff] [blame] | 437 | switch (view.getId()) { |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 438 | case R.id.buttonCall: |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 439 | processingNewCallAction(); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 440 | break; |
| 441 | case R.id.buttonHangUp: |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 442 | processingHangUpAction(); |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 443 | break; |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 444 | default: |
| 445 | Log.w(TAG, "unknown button " + view.getId()); |
| 446 | break; |
Emeric Vigier | 6119d78 | 2012-09-21 18:04:14 -0400 | [diff] [blame] | 447 | } |
Emeric Vigier | bbde1ae | 2012-09-21 18:13:56 -0400 | [diff] [blame] | 448 | } |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 449 | |
| 450 | public void processingNewCallAction() { |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 451 | String accountID = mAccountList.currentAccountID; |
Alexandre Savard | cb66fa4 | 2012-10-26 10:06:16 -0400 | [diff] [blame^] | 452 | EditText editText = (EditText) findViewById(R.id.phoneNumberTextEntry); |
| 453 | String to = editText.getText().toString(); |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 454 | |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 455 | Random random = new Random(); |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 456 | String callID = Integer.toString(random.nextInt()); |
| 457 | SipCall.CallInfo info = new SipCall.CallInfo(); |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 458 | |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 459 | info.mCallID = callID; |
| 460 | info.mAccountID = accountID; |
| 461 | info.mDisplayName = "Cool Guy!"; |
| 462 | info.mPhone = to; |
| 463 | info.mEmail = "coolGuy@coolGuy.com"; |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 464 | |
Alexandre Savard | 27a5113 | 2012-10-25 18:35:14 -0400 | [diff] [blame] | 465 | SipCall call = CallList.getCallInstance(info); |
| 466 | call.launchCallActivity(this); |
| 467 | call.placeCallUpdateUi(); |
| 468 | call.notifyServicePlaceCall(service); |
| 469 | |
| 470 | onSelectedCallAction(call); |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | public void processingHangUpAction() { |
Alexandre Savard | f17e317 | 2012-10-25 16:09:09 -0400 | [diff] [blame] | 474 | SipCall call = (SipCall)buttonHangup.getTag(); |
| 475 | if(call != null) |
| 476 | call.notifyServiceHangup(service); |
Alexandre Savard | 6b8d1df | 2012-10-23 16:44:43 -0400 | [diff] [blame] | 477 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 478 | } |