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; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 41 | import android.content.ServiceConnection; |
| 42 | import android.os.Bundle; |
| 43 | import android.os.IBinder; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 44 | import android.os.RemoteException; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 45 | import android.support.v13.app.FragmentStatePagerAdapter; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 46 | import android.support.v4.view.ViewPager; |
| 47 | import android.util.Log; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 48 | import android.view.Menu; |
| 49 | import android.view.MenuItem; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 50 | import android.widget.ImageButton; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 51 | |
| 52 | import com.savoirfairelinux.sflphone.R; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 53 | import com.savoirfairelinux.sflphone.fragments.CallElementListFragment; |
| 54 | import com.savoirfairelinux.sflphone.fragments.ContactListFragment; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 55 | import com.savoirfairelinux.sflphone.fragments.HistoryFragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 56 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 57 | import com.savoirfairelinux.sflphone.service.ISipClient; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 58 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 59 | import com.savoirfairelinux.sflphone.service.SipService; |
| 60 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 61 | public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, CallElementListFragment.Callbacks, HistoryFragment.Callbacks { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 62 | SectionsPagerAdapter mSectionsPagerAdapter = null; |
| 63 | static final String TAG = "SFLPhoneHome"; |
| 64 | private static final int REQUEST_CODE_PREFERENCES = 1; |
| 65 | ImageButton buttonCall, buttonHangup; |
| 66 | private ContactListFragment mContactListFragment = null; |
| 67 | private CallElementListFragment mCallElementList = null; |
| 68 | private HistoryFragment mHistorySectionFragment = null; |
| 69 | private boolean mBound = false; |
| 70 | private ISipService service; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 71 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 72 | private static final int ACTION_BAR_TAB_CONTACT = 0; |
| 73 | private static final int ACTION_BAR_TAB_CALL = 1; |
| 74 | private static final int ACTION_BAR_TAB_HISTORY = 2; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 75 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 76 | /** |
| 77 | * The {@link ViewPager} that will host the section contents. |
| 78 | */ |
| 79 | ViewPager mViewPager; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 80 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 81 | 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] | 82 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 83 | // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 84 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 85 | /* called before activity is killed, e.g. rotation */ |
| 86 | @Override |
| 87 | protected void onSaveInstanceState(Bundle bundle) { |
| 88 | super.onSaveInstanceState(bundle); |
| 89 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 90 | try { |
| 91 | /* putFragment (Bundle bundle, String key, Fragment fragment) */ |
| 92 | getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getFragment(i)); |
| 93 | } catch (IllegalStateException e) { |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 94 | Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getFragment(i)); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | Log.w(TAG, "onSaveInstanceState()"); |
| 98 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 99 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 100 | @Override |
| 101 | public void onCreate(Bundle savedInstanceState) { |
| 102 | super.onCreate(savedInstanceState); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 103 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 104 | // Bind to LocalService |
| 105 | if (!mBound) { |
| 106 | Log.i(TAG, "onStart: Binding service..."); |
| 107 | Intent intent = new Intent(this, SipService.class); |
| 108 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 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 | setContentView(R.layout.activity_sflphone_home); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 112 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 113 | if (mSectionsPagerAdapter == null) { |
| 114 | mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); |
| 115 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 116 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 117 | /* getFragment(Bundle, String) */ |
| 118 | if (savedInstanceState != null) { |
| 119 | Log.w(TAG, "Activity restarted, recreating PagerAdapter..."); |
| 120 | /* getFragment (Bundle bundle, String key) */ |
| 121 | mContactListFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, |
| 122 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CONTACT)); |
| 123 | mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState, |
| 124 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL)); |
| 125 | mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState, |
| 126 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY)); |
| 127 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 128 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 129 | if (mContactListFragment == null) { |
| 130 | mContactListFragment = new ContactListFragment(); |
| 131 | Log.w(TAG, "Recreated mContactListFragment=" + mContactListFragment); |
| 132 | } |
| 133 | if (mCallElementList == null) { |
| 134 | mCallElementList = new CallElementListFragment(); |
| 135 | Log.w(TAG, "Recreated mCallElementList=" + mCallElementList); |
| 136 | } |
| 137 | if (mHistorySectionFragment == null) { |
| 138 | mHistorySectionFragment = new HistoryFragment(); |
| 139 | Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment); |
| 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 | final ActionBar actionBar = getActionBar(); |
| 143 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
| 144 | // final ActionBar actionBar = getActionBar(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 145 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 146 | // Set up the ViewPager with the sections adapter. |
| 147 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 148 | mViewPager.setAdapter(mSectionsPagerAdapter); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 149 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 150 | // When swiping between different sections, select the corresponding tab. |
| 151 | // We can also use ActionBar.Tab#select() to do this if we have a reference to the |
| 152 | // Tab. |
| 153 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { |
| 154 | @Override |
| 155 | public void onPageSelected(int position) { |
| 156 | actionBar.setSelectedNavigationItem(position); |
| 157 | } |
| 158 | }); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 159 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 160 | // For each of the sections in the app, add a tab to the action bar. |
| 161 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 162 | // Create a tab with text corresponding to the page title defined by the adapter. |
| 163 | // Also specify this Activity object, which implements the TabListener interface, as the |
| 164 | // listener for when this tab is selected. |
| 165 | actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); |
| 166 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 167 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 168 | actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 169 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 170 | // buttonHangup.setOnClickListener(new OnClickListener() { |
| 171 | // @Override |
| 172 | // public void onClick(View v) { |
| 173 | // processingHangUpAction(); |
| 174 | // |
| 175 | // } |
| 176 | // }); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 177 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 178 | // IntentFilter callFilter = new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED); |
| 179 | // callFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 180 | // callFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); |
| 181 | // LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, callFilter); |
| 182 | // |
| 183 | // mAccountList = mApplication.getAccountList(); |
| 184 | // Log.w(TAG, "mAccountList=" + mAccountList + ", mCallElementList=" + mCallElementList); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 185 | |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame^] | 186 | // IntentFilter accountFilter = new IntentFilter(ConfigurationManagerCallback.ACCOUNTS_CHANGED); |
| 187 | // accountFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 188 | // LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, accountFilter); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 189 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 190 | // SipCall.setSFLPhoneHomeContext(this); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 191 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 192 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 193 | @Override |
| 194 | protected void onStart() { |
| 195 | Log.i(TAG, "onStart"); |
| 196 | super.onStart(); |
| 197 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 198 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 199 | /* user gets back to the activity, e.g. through task manager */ |
| 200 | @Override |
| 201 | protected void onRestart() { |
| 202 | super.onRestart(); |
| 203 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 204 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 205 | /* activity gets back to the foreground and user input */ |
| 206 | @Override |
| 207 | protected void onResume() { |
| 208 | Log.i(TAG, "onResume"); |
| 209 | super.onResume(); |
| 210 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 211 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 212 | /* activity no more in foreground */ |
| 213 | @Override |
| 214 | protected void onPause() { |
| 215 | super.onPause(); |
| 216 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 217 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 218 | /* activity is no longer visible */ |
| 219 | @Override |
| 220 | protected void onStop() { |
| 221 | super.onStop(); |
| 222 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 223 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 224 | /* activity finishes itself or is being killed by the system */ |
| 225 | @Override |
| 226 | protected void onDestroy() { |
| 227 | /* stop the service, if no other bound user, no need to check if it is running */ |
| 228 | if (mBound) { |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame^] | 229 | Log.i(TAG, "onDestroy: Unbinding service..."); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 230 | unbindService(mConnection); |
| 231 | mBound = false; |
| 232 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 233 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 234 | /* unregister broadcast receiver */ |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 235 | // LocalBroadcastManager.getInstance(this).unregisterReceiver(mCallList); |
| 236 | // LocalBroadcastManager.getInstance(this).unregisterReceiver(mAccountList); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 237 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 238 | super.onDestroy(); |
| 239 | } |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 240 | |
| 241 | public void launchCallActivity(SipCall.CallInfo infos) { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 242 | Log.i(TAG, "Launch Call Activity"); |
| 243 | Bundle bundle = new Bundle(); |
| 244 | bundle.putParcelable("CallInfo", infos); |
| 245 | Intent intent = new Intent().setClass(this, CallActivity.class); |
| 246 | intent.putExtras(bundle); |
| 247 | startActivity(intent); |
| 248 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 249 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 250 | /** Defines callbacks for service binding, passed to bindService() */ |
| 251 | private ServiceConnection mConnection = new ServiceConnection() { |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 252 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 253 | private ISipClient callback = new ISipClient.Stub() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 254 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 255 | @Override |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 256 | public void incomingCall(Intent call) throws RemoteException { |
| 257 | Log.i(TAG, "Incoming call transfered from Service"); |
| 258 | SipCall.CallInfo infos = new SipCall.CallInfo(call); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 259 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 260 | SipCall c = new SipCall(infos); |
| 261 | mCallElementList.addCall(c); |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 262 | |
Adrien Béraud | 1947a10 | 2013-04-26 22:05:34 +1000 | [diff] [blame] | 263 | launchCallActivity(infos); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | @Override |
| 267 | public void callStateChanged(Intent callState) throws RemoteException { |
| 268 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 269 | String cID = b.getString("CallID"); |
| 270 | String state = b.getString("State"); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 271 | Log.i(TAG, "callStateChanged" + cID + " " + state); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 272 | mCallElementList.updateCall(cID, state); |
| 273 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 274 | } |
| 275 | }; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 276 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 277 | @Override |
| 278 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 279 | service = ISipService.Stub.asInterface(binder); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 280 | |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 281 | mBound = true; |
| 282 | mCallElementList.onServiceSipBinded(service); |
| 283 | mHistorySectionFragment.onServiceSipBinded(service); |
| 284 | Log.d(TAG, "Service connected service=" + service); |
| 285 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 286 | try { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 287 | service.registerClient(callback); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 288 | } catch (RemoteException e) { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 289 | Log.e(TAG, e.toString()); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 290 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | @Override |
| 294 | public void onServiceDisconnected(ComponentName arg0) { |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 295 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 296 | mBound = false; |
| 297 | Log.d(TAG, "Service disconnected service=" + service); |
| 298 | } |
| 299 | }; |
| 300 | |
| 301 | @Override |
| 302 | public boolean onOptionsItemSelected(MenuItem item) { |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 303 | Log.i(TAG, "onOptionsItemSelected " + item.getItemId()); |
| 304 | switch(item.getItemId()){ |
| 305 | case R.id.menu_settings : |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 306 | Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 307 | startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES); |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 308 | break; |
| 309 | case R.id.menu_custom_draw: |
| 310 | Intent launchNewInterfaceIntent = new Intent().setClass(this, BubblesViewActivity.class); |
| 311 | startActivityForResult(launchNewInterfaceIntent, 0); |
| 312 | break; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 313 | } |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 314 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 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 | } |