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