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