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