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