alision | f76de3b | 2013-04-16 15:35:22 -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 | |
| 33 | import java.util.Random; |
| 34 | |
| 35 | import android.app.ActionBar; |
| 36 | import android.app.Activity; |
| 37 | import android.app.Fragment; |
| 38 | import android.app.FragmentManager; |
| 39 | import android.app.FragmentTransaction; |
| 40 | import android.content.ComponentName; |
| 41 | import android.content.Context; |
| 42 | import android.content.Intent; |
| 43 | import android.content.IntentFilter; |
| 44 | import android.content.ServiceConnection; |
| 45 | import android.os.Bundle; |
| 46 | import android.os.IBinder; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 47 | import android.os.RemoteException; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 48 | import android.support.v13.app.FragmentStatePagerAdapter; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 49 | import android.support.v4.view.ViewPager; |
| 50 | import android.util.Log; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 51 | import android.view.Menu; |
| 52 | import android.view.MenuItem; |
| 53 | import android.view.View; |
| 54 | import android.view.View.OnClickListener; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 55 | import android.widget.EditText; |
| 56 | import android.widget.ImageButton; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 57 | |
| 58 | import com.savoirfairelinux.sflphone.R; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 59 | import com.savoirfairelinux.sflphone.client.receiver.CallListReceiver; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 60 | import com.savoirfairelinux.sflphone.fragments.CallElementListFragment; |
| 61 | import com.savoirfairelinux.sflphone.fragments.ContactListFragment; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 62 | import com.savoirfairelinux.sflphone.fragments.HistoryFragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 63 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 64 | import com.savoirfairelinux.sflphone.service.ConfigurationManagerCallback; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 65 | import com.savoirfairelinux.sflphone.service.ISipClient; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 66 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 67 | import com.savoirfairelinux.sflphone.service.SipService; |
| 68 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 69 | public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, CallElementListFragment.Callbacks { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 70 | SectionsPagerAdapter mSectionsPagerAdapter = null; |
| 71 | static final String TAG = "SFLPhoneHome"; |
| 72 | private static final int REQUEST_CODE_PREFERENCES = 1; |
| 73 | ImageButton buttonCall, buttonHangup; |
| 74 | private ContactListFragment mContactListFragment = null; |
| 75 | private CallElementListFragment mCallElementList = null; |
| 76 | private HistoryFragment mHistorySectionFragment = null; |
| 77 | private boolean mBound = false; |
| 78 | private ISipService service; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 79 | // public AccountListReceiver mAccountList; |
| 80 | // public CallListReceiver mCallList = new CallListReceiver(this); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 81 | private SFLphoneApplication mApplication; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 82 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 83 | private static final int ACTION_BAR_TAB_CONTACT = 0; |
| 84 | private static final int ACTION_BAR_TAB_CALL = 1; |
| 85 | private static final int ACTION_BAR_TAB_HISTORY = 2; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 86 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 87 | /** |
| 88 | * The {@link ViewPager} that will host the section contents. |
| 89 | */ |
| 90 | ViewPager mViewPager; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 91 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 92 | final private int[] icon_res_id = { R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history }; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 93 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 94 | // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 95 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 96 | /* called before activity is killed, e.g. rotation */ |
| 97 | @Override |
| 98 | protected void onSaveInstanceState(Bundle bundle) { |
| 99 | super.onSaveInstanceState(bundle); |
| 100 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 101 | try { |
| 102 | /* putFragment (Bundle bundle, String key, Fragment fragment) */ |
| 103 | getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getFragment(i)); |
| 104 | } catch (IllegalStateException e) { |
| 105 | Log.e(TAG, "IllegalStateException: fragment=" + mSectionsPagerAdapter.getFragment(i)); |
| 106 | } |
| 107 | } |
| 108 | Log.w(TAG, "onSaveInstanceState()"); |
| 109 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 110 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 111 | @Override |
| 112 | public void onCreate(Bundle savedInstanceState) { |
| 113 | super.onCreate(savedInstanceState); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 114 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 115 | mApplication = (SFLphoneApplication) getApplication(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 116 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 117 | // Bind to LocalService |
| 118 | if (!mBound) { |
| 119 | Log.i(TAG, "onStart: Binding service..."); |
| 120 | Intent intent = new Intent(this, SipService.class); |
| 121 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 122 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 123 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 124 | setContentView(R.layout.activity_sflphone_home); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 125 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 126 | if (mSectionsPagerAdapter == null) { |
| 127 | mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); |
| 128 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 129 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 130 | /* getFragment(Bundle, String) */ |
| 131 | if (savedInstanceState != null) { |
| 132 | Log.w(TAG, "Activity restarted, recreating PagerAdapter..."); |
| 133 | /* getFragment (Bundle bundle, String key) */ |
| 134 | mContactListFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, |
| 135 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CONTACT)); |
| 136 | mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState, |
| 137 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL)); |
| 138 | mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState, |
| 139 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY)); |
| 140 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 141 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 142 | if (mContactListFragment == null) { |
| 143 | mContactListFragment = new ContactListFragment(); |
| 144 | Log.w(TAG, "Recreated mContactListFragment=" + mContactListFragment); |
| 145 | } |
| 146 | if (mCallElementList == null) { |
| 147 | mCallElementList = new CallElementListFragment(); |
| 148 | Log.w(TAG, "Recreated mCallElementList=" + mCallElementList); |
| 149 | } |
| 150 | if (mHistorySectionFragment == null) { |
| 151 | mHistorySectionFragment = new HistoryFragment(); |
| 152 | Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment); |
| 153 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 154 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 155 | final ActionBar actionBar = getActionBar(); |
| 156 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
| 157 | // final ActionBar actionBar = getActionBar(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 158 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 159 | // Set up the ViewPager with the sections adapter. |
| 160 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 161 | mViewPager.setAdapter(mSectionsPagerAdapter); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 162 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 163 | // When swiping between different sections, select the corresponding tab. |
| 164 | // We can also use ActionBar.Tab#select() to do this if we have a reference to the |
| 165 | // Tab. |
| 166 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { |
| 167 | @Override |
| 168 | public void onPageSelected(int position) { |
| 169 | actionBar.setSelectedNavigationItem(position); |
| 170 | } |
| 171 | }); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 172 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 173 | // For each of the sections in the app, add a tab to the action bar. |
| 174 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 175 | // Create a tab with text corresponding to the page title defined by the adapter. |
| 176 | // Also specify this Activity object, which implements the TabListener interface, as the |
| 177 | // listener for when this tab is selected. |
| 178 | actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); |
| 179 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 180 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 181 | actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 182 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 183 | buttonCall = (ImageButton) findViewById(R.id.buttonCall); |
| 184 | buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 185 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 186 | buttonCall.setOnClickListener(new OnClickListener() { |
| 187 | @Override |
| 188 | public void onClick(View v) { |
| 189 | processingNewCallAction(); |
| 190 | } |
| 191 | }); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 192 | |
| 193 | buttonHangup.setOnClickListener(new OnClickListener() { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 194 | @Override |
| 195 | public void onClick(View v) { |
| 196 | processingHangUpAction(); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 197 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 198 | } |
| 199 | }); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 200 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 201 | // IntentFilter callFilter = new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED); |
| 202 | // callFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 203 | // callFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); |
| 204 | // LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, callFilter); |
| 205 | // |
| 206 | // mAccountList = mApplication.getAccountList(); |
| 207 | // Log.w(TAG, "mAccountList=" + mAccountList + ", mCallElementList=" + mCallElementList); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 208 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 209 | IntentFilter accountFilter = new IntentFilter(ConfigurationManagerCallback.ACCOUNTS_CHANGED); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 210 | accountFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 211 | // LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, accountFilter); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 212 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 213 | // SipCall.setSFLPhoneHomeContext(this); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 214 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 215 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 216 | @Override |
| 217 | protected void onStart() { |
| 218 | Log.i(TAG, "onStart"); |
| 219 | super.onStart(); |
| 220 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 221 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 222 | /* user gets back to the activity, e.g. through task manager */ |
| 223 | @Override |
| 224 | protected void onRestart() { |
| 225 | super.onRestart(); |
| 226 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 227 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 228 | /* activity gets back to the foreground and user input */ |
| 229 | @Override |
| 230 | protected void onResume() { |
| 231 | Log.i(TAG, "onResume"); |
| 232 | super.onResume(); |
| 233 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 234 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 235 | /* activity no more in foreground */ |
| 236 | @Override |
| 237 | protected void onPause() { |
| 238 | super.onPause(); |
| 239 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 240 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 241 | /* activity is no longer visible */ |
| 242 | @Override |
| 243 | protected void onStop() { |
| 244 | super.onStop(); |
| 245 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 246 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 247 | /* activity finishes itself or is being killed by the system */ |
| 248 | @Override |
| 249 | protected void onDestroy() { |
| 250 | /* stop the service, if no other bound user, no need to check if it is running */ |
| 251 | if (mBound) { |
| 252 | Log.i(TAG, "onStop: Unbinding service..."); |
| 253 | unbindService(mConnection); |
| 254 | mBound = false; |
| 255 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 256 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 257 | /* unregister broadcast receiver */ |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 258 | // LocalBroadcastManager.getInstance(this).unregisterReceiver(mCallList); |
| 259 | // LocalBroadcastManager.getInstance(this).unregisterReceiver(mAccountList); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 260 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 261 | super.onDestroy(); |
| 262 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 263 | |
| 264 | public void launchCallActivity(SipCall.CallInfo infos) |
| 265 | { |
| 266 | Log.i(TAG, "Launch Call Activity"); |
| 267 | Bundle bundle = new Bundle(); |
| 268 | bundle.putParcelable("CallInfo", infos); |
| 269 | Intent intent = new Intent().setClass(this, CallActivity.class); |
| 270 | intent.putExtras(bundle); |
| 271 | startActivity(intent); |
| 272 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 273 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 274 | /** Defines callbacks for service binding, passed to bindService() */ |
| 275 | private ServiceConnection mConnection = new ServiceConnection() { |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 276 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 277 | private ISipClient callback = new ISipClient.Stub() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 278 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 279 | @Override |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 280 | public void incomingCall(Intent call) throws RemoteException { |
| 281 | Log.i(TAG, "Incoming call transfered from Service"); |
| 282 | SipCall.CallInfo infos = new SipCall.CallInfo(call); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 283 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 284 | SipCall c = new SipCall(infos); |
| 285 | mCallElementList.addCall(c); |
| 286 | } |
| 287 | |
| 288 | @Override |
| 289 | public void callStateChanged(Intent callState) throws RemoteException { |
| 290 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 291 | String cID = b.getString("CallID"); |
| 292 | String state = b.getString("State"); |
| 293 | Log.i(TAG,"callStateChanged"+cID+" "+state); |
| 294 | mCallElementList.updateCall(cID, state); |
| 295 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 296 | } |
| 297 | }; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 298 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 299 | @Override |
| 300 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 301 | service = ISipService.Stub.asInterface(binder); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 302 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 303 | try { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 304 | service.registerClient(callback); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 305 | } catch (RemoteException e) { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 306 | Log.e(TAG, e.toString()); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 307 | } |
| 308 | mApplication.setSipService(service); |
| 309 | mBound = true; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 310 | mCallElementList.onServiceSipBinded(service); |
| 311 | Log.d(TAG, "Service connected service=" + service); |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public void onServiceDisconnected(ComponentName arg0) { |
| 316 | mApplication.setSipService(null); |
| 317 | mBound = false; |
| 318 | Log.d(TAG, "Service disconnected service=" + service); |
| 319 | } |
| 320 | }; |
| 321 | |
| 322 | @Override |
| 323 | public boolean onOptionsItemSelected(MenuItem item) { |
| 324 | Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId()); |
| 325 | if (item.getItemId() != 0) { |
| 326 | // When the button is clicked, launch an activity through this intent |
| 327 | Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class); |
| 328 | |
| 329 | // Make it a subactivity so we know when it returns |
| 330 | startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES); |
| 331 | } |
| 332 | |
| 333 | return super.onOptionsItemSelected(item); |
| 334 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 335 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 336 | @Override |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 337 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 338 | super.onActivityResult(requestCode, resultCode, data); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 339 | if (REQUEST_CODE_PREFERENCES == requestCode && service != null) { |
| 340 | // Refresh Spinner with modified accounts |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 341 | mCallElementList.onServiceSipBinded(service); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public boolean onCreateOptionsMenu(Menu menu) { |
| 347 | getMenuInflater().inflate(R.menu.activity_sflphone_home, menu); |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | @Override |
| 352 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 357 | // When the given tab is selected, switch to the corresponding page in the ViewPager. |
| 358 | mViewPager.setCurrentItem(tab.getPosition()); |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 363 | // Log.d(TAG, "onTabReselected"); |
| 364 | } |
| 365 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 366 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 367 | public void processingNewCallAction() { |
| 368 | // String accountID = mAccountList.currentAccountID; |
| 369 | Log.w(TAG, "processingNewCallAction() mCallElementList=" + mCallElementList); |
| 370 | String accountID = mCallElementList.getSelectedAccount(); |
| 371 | EditText editText = (EditText) findViewById(R.id.phoneNumberTextEntry); |
| 372 | String to = editText.getText().toString(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 373 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 374 | Random random = new Random(); |
| 375 | String callID = Integer.toString(random.nextInt()); |
| 376 | SipCall.CallInfo info = new SipCall.CallInfo(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 377 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 378 | info.mCallID = callID; |
| 379 | info.mAccountID = accountID; |
| 380 | info.mDisplayName = "Cool Guy!"; |
| 381 | info.mPhone = to; |
| 382 | info.mEmail = "coolGuy@coolGuy.com"; |
| 383 | info.mCallType = SipCall.CALL_TYPE_OUTGOING; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 384 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 385 | SipCall call = CallListReceiver.getCallInstance(info); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 386 | launchCallActivity(call.mCallInfo); |
| 387 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 388 | try { |
| 389 | service.placeCall(info.mAccountID, info.mCallID, info.mPhone); |
| 390 | } catch (RemoteException e) { |
| 391 | Log.e(TAG, "Cannot call service method", e); |
| 392 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 393 | mCallElementList.addCall(call); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 394 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 395 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 396 | public void processingHangUpAction() { |
| 397 | SipCall call = (SipCall) buttonHangup.getTag(); |
| 398 | if (call != null) |
| 399 | call.notifyServiceHangup(service); |
| 400 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 401 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 402 | /** |
| 403 | * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to one of the primary sections of the app. |
| 404 | */ |
| 405 | public class SectionsPagerAdapter extends FragmentStatePagerAdapter { |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 406 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 407 | public SectionsPagerAdapter(FragmentManager fm) { |
| 408 | super(fm); |
| 409 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 410 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 411 | @Override |
| 412 | public Fragment getItem(int i) { |
| 413 | Fragment fragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 414 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 415 | switch (i) { |
| 416 | case 0: |
| 417 | mContactListFragment = new ContactListFragment(); |
| 418 | fragment = mContactListFragment; |
| 419 | Log.w(TAG, "getItem() ContactListFragment=" + fragment); |
| 420 | break; |
| 421 | case 1: |
| 422 | mCallElementList = new CallElementListFragment(); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 423 | // SipCall.setCallElementList(mCallElementList); |
| 424 | // mCallElementList.setAccountList(mAccountList); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 425 | fragment = mCallElementList; |
| 426 | Log.w(TAG, "getItem() CallElementList=" + fragment); |
| 427 | break; |
| 428 | case 2: |
| 429 | fragment = new HistoryFragment(); |
| 430 | Log.w(TAG, "getItem() HistoryFragment=" + fragment); |
| 431 | break; |
| 432 | default: |
| 433 | Log.e(TAG, "getItem() unknown tab position " + i); |
| 434 | return null; |
| 435 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 436 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 437 | // Log.i(TAG, "getItem() fragment is " + fragment); |
| 438 | Bundle args = new Bundle(); |
| 439 | args.putInt(HistoryFragment.ARG_SECTION_NUMBER, i + 1); |
| 440 | fragment.setArguments(args); |
| 441 | return fragment; |
| 442 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 443 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 444 | public Fragment getFragment(int i) { |
| 445 | Fragment fragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 446 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 447 | switch (i) { |
| 448 | case 0: |
| 449 | fragment = mContactListFragment; |
| 450 | break; |
| 451 | case 1: |
| 452 | fragment = mCallElementList; |
| 453 | break; |
| 454 | case 2: |
| 455 | fragment = mHistorySectionFragment; |
| 456 | break; |
| 457 | default: |
| 458 | Log.e(TAG, "getClassName: unknown fragment position " + i); |
| 459 | fragment = null; |
| 460 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 461 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 462 | // Log.w(TAG, "getFragment: fragment=" + fragment); |
| 463 | return fragment; |
| 464 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 465 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 466 | public String getClassName(int i) { |
| 467 | String name; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 468 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 469 | switch (i) { |
| 470 | case 0: |
| 471 | name = ContactListFragment.class.getName(); |
| 472 | break; |
| 473 | case 1: |
| 474 | name = CallElementListFragment.class.getName(); |
| 475 | break; |
| 476 | case 2: |
| 477 | name = HistoryFragment.class.getName(); |
| 478 | break; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 479 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 480 | default: |
| 481 | Log.e(TAG, "getClassName: unknown fragment position " + i); |
| 482 | return null; |
| 483 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 484 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 485 | // Log.w(TAG, "getClassName: name=" + name); |
| 486 | return name; |
| 487 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 488 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 489 | @Override |
| 490 | public int getCount() { |
| 491 | return 3; |
| 492 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 493 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 494 | @Override |
| 495 | public CharSequence getPageTitle(int position) { |
| 496 | switch (position) { |
| 497 | case 0: |
| 498 | return getString(R.string.title_section0).toUpperCase(); |
| 499 | case 1: |
| 500 | return getString(R.string.title_section1).toUpperCase(); |
| 501 | case 2: |
| 502 | return getString(R.string.title_section2).toUpperCase(); |
| 503 | case 3: |
| 504 | return getString(R.string.title_section3).toUpperCase(); |
| 505 | default: |
| 506 | Log.e(TAG, "getPageTitle: unknown tab position " + position); |
| 507 | break; |
| 508 | } |
| 509 | return null; |
| 510 | } |
| 511 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 512 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame^] | 513 | @Override |
| 514 | public void onCallSelected(SipCall c) { |
| 515 | launchCallActivity(c.mCallInfo); |
| 516 | |
| 517 | } |
| 518 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 519 | } |