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