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