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