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