blob: 34d3ab51ef477641a6fecd64df01cc24c26d24cb [file] [log] [blame]
alisionf76de3b2013-04-16 15:35:22 -04001/*
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 */
31package com.savoirfairelinux.sflphone.client;
32
33import java.util.Random;
34
35import android.app.ActionBar;
36import android.app.Activity;
37import android.app.Fragment;
38import android.app.FragmentManager;
39import android.app.FragmentTransaction;
40import android.content.ComponentName;
41import android.content.Context;
42import android.content.Intent;
43import android.content.IntentFilter;
44import android.content.ServiceConnection;
45import android.os.Bundle;
46import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040047import android.os.RemoteException;
alisionf76de3b2013-04-16 15:35:22 -040048import android.support.v13.app.FragmentStatePagerAdapter;
alisionf76de3b2013-04-16 15:35:22 -040049import android.support.v4.view.ViewPager;
50import android.util.Log;
alisionf76de3b2013-04-16 15:35:22 -040051import android.view.Menu;
52import android.view.MenuItem;
53import android.view.View;
54import android.view.View.OnClickListener;
alisionf76de3b2013-04-16 15:35:22 -040055import android.widget.EditText;
56import android.widget.ImageButton;
alisionf76de3b2013-04-16 15:35:22 -040057
58import com.savoirfairelinux.sflphone.R;
alisiond9e29442013-04-17 16:10:18 -040059import com.savoirfairelinux.sflphone.client.receiver.CallListReceiver;
alisionf76de3b2013-04-16 15:35:22 -040060import com.savoirfairelinux.sflphone.fragments.CallElementListFragment;
61import com.savoirfairelinux.sflphone.fragments.ContactListFragment;
alisiond9e29442013-04-17 16:10:18 -040062import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
alisionf76de3b2013-04-16 15:35:22 -040063import com.savoirfairelinux.sflphone.model.SipCall;
alisionf76de3b2013-04-16 15:35:22 -040064import com.savoirfairelinux.sflphone.service.ConfigurationManagerCallback;
alision5f899632013-04-22 17:26:56 -040065import com.savoirfairelinux.sflphone.service.ISipClient;
alisionf76de3b2013-04-16 15:35:22 -040066import com.savoirfairelinux.sflphone.service.ISipService;
67import com.savoirfairelinux.sflphone.service.SipService;
68
alision371b77e2013-04-23 14:51:26 -040069public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, CallElementListFragment.Callbacks {
alision5f899632013-04-22 17:26:56 -040070 SectionsPagerAdapter mSectionsPagerAdapter = null;
71 static final String TAG = "SFLPhoneHome";
72 private static final int REQUEST_CODE_PREFERENCES = 1;
73 ImageButton buttonCall, buttonHangup;
74 private ContactListFragment mContactListFragment = null;
75 private CallElementListFragment mCallElementList = null;
76 private HistoryFragment mHistorySectionFragment = null;
77 private boolean mBound = false;
78 private ISipService service;
alision371b77e2013-04-23 14:51:26 -040079 // public AccountListReceiver mAccountList;
80 // public CallListReceiver mCallList = new CallListReceiver(this);
alision5f899632013-04-22 17:26:56 -040081 private SFLphoneApplication mApplication;
alisionf76de3b2013-04-16 15:35:22 -040082
alision5f899632013-04-22 17:26:56 -040083 private static final int ACTION_BAR_TAB_CONTACT = 0;
84 private static final int ACTION_BAR_TAB_CALL = 1;
85 private static final int ACTION_BAR_TAB_HISTORY = 2;
alisionf76de3b2013-04-16 15:35:22 -040086
alision5f899632013-04-22 17:26:56 -040087 /**
88 * The {@link ViewPager} that will host the section contents.
89 */
90 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -040091
alision5f899632013-04-22 17:26:56 -040092 final private int[] icon_res_id = { R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history };
alisionf76de3b2013-04-16 15:35:22 -040093
alision5f899632013-04-22 17:26:56 -040094 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
alisionf76de3b2013-04-16 15:35:22 -040095
alision5f899632013-04-22 17:26:56 -040096 /* called before activity is killed, e.g. rotation */
97 @Override
98 protected void onSaveInstanceState(Bundle bundle) {
99 super.onSaveInstanceState(bundle);
100 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
101 try {
102 /* putFragment (Bundle bundle, String key, Fragment fragment) */
103 getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getFragment(i));
104 } catch (IllegalStateException e) {
105 Log.e(TAG, "IllegalStateException: fragment=" + mSectionsPagerAdapter.getFragment(i));
106 }
107 }
108 Log.w(TAG, "onSaveInstanceState()");
109 }
alisionf76de3b2013-04-16 15:35:22 -0400110
alision5f899632013-04-22 17:26:56 -0400111 @Override
112 public void onCreate(Bundle savedInstanceState) {
113 super.onCreate(savedInstanceState);
alisionf76de3b2013-04-16 15:35:22 -0400114
alision5f899632013-04-22 17:26:56 -0400115 mApplication = (SFLphoneApplication) getApplication();
alisionf76de3b2013-04-16 15:35:22 -0400116
alision5f899632013-04-22 17:26:56 -0400117 // Bind to LocalService
118 if (!mBound) {
119 Log.i(TAG, "onStart: Binding service...");
120 Intent intent = new Intent(this, SipService.class);
121 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
122 }
alisionf76de3b2013-04-16 15:35:22 -0400123
alision5f899632013-04-22 17:26:56 -0400124 setContentView(R.layout.activity_sflphone_home);
alisionf76de3b2013-04-16 15:35:22 -0400125
alision5f899632013-04-22 17:26:56 -0400126 if (mSectionsPagerAdapter == null) {
127 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
128 }
alisionf76de3b2013-04-16 15:35:22 -0400129
alision5f899632013-04-22 17:26:56 -0400130 /* getFragment(Bundle, String) */
131 if (savedInstanceState != null) {
132 Log.w(TAG, "Activity restarted, recreating PagerAdapter...");
133 /* getFragment (Bundle bundle, String key) */
134 mContactListFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState,
135 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CONTACT));
136 mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState,
137 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL));
138 mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState,
139 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY));
140 }
alisionf76de3b2013-04-16 15:35:22 -0400141
alision5f899632013-04-22 17:26:56 -0400142 if (mContactListFragment == null) {
143 mContactListFragment = new ContactListFragment();
144 Log.w(TAG, "Recreated mContactListFragment=" + mContactListFragment);
145 }
146 if (mCallElementList == null) {
147 mCallElementList = new CallElementListFragment();
148 Log.w(TAG, "Recreated mCallElementList=" + mCallElementList);
149 }
150 if (mHistorySectionFragment == null) {
151 mHistorySectionFragment = new HistoryFragment();
152 Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment);
153 }
alisionf76de3b2013-04-16 15:35:22 -0400154
alision5f899632013-04-22 17:26:56 -0400155 final ActionBar actionBar = getActionBar();
156 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
157 // final ActionBar actionBar = getActionBar();
alisionf76de3b2013-04-16 15:35:22 -0400158
alision5f899632013-04-22 17:26:56 -0400159 // Set up the ViewPager with the sections adapter.
160 mViewPager = (ViewPager) findViewById(R.id.pager);
161 mViewPager.setAdapter(mSectionsPagerAdapter);
alisionf76de3b2013-04-16 15:35:22 -0400162
alision5f899632013-04-22 17:26:56 -0400163 // When swiping between different sections, select the corresponding tab.
164 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
165 // Tab.
166 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
167 @Override
168 public void onPageSelected(int position) {
169 actionBar.setSelectedNavigationItem(position);
170 }
171 });
alisionf76de3b2013-04-16 15:35:22 -0400172
alision5f899632013-04-22 17:26:56 -0400173 // For each of the sections in the app, add a tab to the action bar.
174 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
175 // Create a tab with text corresponding to the page title defined by the adapter.
176 // Also specify this Activity object, which implements the TabListener interface, as the
177 // listener for when this tab is selected.
178 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
179 }
alisionf76de3b2013-04-16 15:35:22 -0400180
alision5f899632013-04-22 17:26:56 -0400181 actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
alisionf76de3b2013-04-16 15:35:22 -0400182
alision5f899632013-04-22 17:26:56 -0400183 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
184 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
alisionf76de3b2013-04-16 15:35:22 -0400185
alision5f899632013-04-22 17:26:56 -0400186 buttonCall.setOnClickListener(new OnClickListener() {
187 @Override
188 public void onClick(View v) {
189 processingNewCallAction();
190 }
191 });
alision371b77e2013-04-23 14:51:26 -0400192
193 buttonHangup.setOnClickListener(new OnClickListener() {
alision5f899632013-04-22 17:26:56 -0400194 @Override
195 public void onClick(View v) {
196 processingHangUpAction();
alision371b77e2013-04-23 14:51:26 -0400197
alision5f899632013-04-22 17:26:56 -0400198 }
199 });
alisionf76de3b2013-04-16 15:35:22 -0400200
alision371b77e2013-04-23 14:51:26 -0400201 // IntentFilter callFilter = new IntentFilter(CallManagerCallBack.NEW_CALL_CREATED);
202 // callFilter.addAction(CallManagerCallBack.INCOMING_CALL);
203 // callFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
204 // LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, callFilter);
205 //
206 // mAccountList = mApplication.getAccountList();
207 // Log.w(TAG, "mAccountList=" + mAccountList + ", mCallElementList=" + mCallElementList);
alisionf76de3b2013-04-16 15:35:22 -0400208
alision5f899632013-04-22 17:26:56 -0400209 IntentFilter accountFilter = new IntentFilter(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
alisionf76de3b2013-04-16 15:35:22 -0400210 accountFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
alision371b77e2013-04-23 14:51:26 -0400211 // LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, accountFilter);
alisionf76de3b2013-04-16 15:35:22 -0400212
alision371b77e2013-04-23 14:51:26 -0400213// SipCall.setSFLPhoneHomeContext(this);
alision5f899632013-04-22 17:26:56 -0400214 }
alisionf76de3b2013-04-16 15:35:22 -0400215
alision5f899632013-04-22 17:26:56 -0400216 @Override
217 protected void onStart() {
218 Log.i(TAG, "onStart");
219 super.onStart();
220 }
alisionf76de3b2013-04-16 15:35:22 -0400221
alision5f899632013-04-22 17:26:56 -0400222 /* user gets back to the activity, e.g. through task manager */
223 @Override
224 protected void onRestart() {
225 super.onRestart();
226 }
alisionf76de3b2013-04-16 15:35:22 -0400227
alision5f899632013-04-22 17:26:56 -0400228 /* activity gets back to the foreground and user input */
229 @Override
230 protected void onResume() {
231 Log.i(TAG, "onResume");
232 super.onResume();
233 }
alisionf76de3b2013-04-16 15:35:22 -0400234
alision5f899632013-04-22 17:26:56 -0400235 /* activity no more in foreground */
236 @Override
237 protected void onPause() {
238 super.onPause();
239 }
alisionf76de3b2013-04-16 15:35:22 -0400240
alision5f899632013-04-22 17:26:56 -0400241 /* activity is no longer visible */
242 @Override
243 protected void onStop() {
244 super.onStop();
245 }
alisionf76de3b2013-04-16 15:35:22 -0400246
alision5f899632013-04-22 17:26:56 -0400247 /* activity finishes itself or is being killed by the system */
248 @Override
249 protected void onDestroy() {
250 /* stop the service, if no other bound user, no need to check if it is running */
251 if (mBound) {
252 Log.i(TAG, "onStop: Unbinding service...");
253 unbindService(mConnection);
254 mBound = false;
255 }
alisionf76de3b2013-04-16 15:35:22 -0400256
alision5f899632013-04-22 17:26:56 -0400257 /* unregister broadcast receiver */
alision371b77e2013-04-23 14:51:26 -0400258 // LocalBroadcastManager.getInstance(this).unregisterReceiver(mCallList);
259 // LocalBroadcastManager.getInstance(this).unregisterReceiver(mAccountList);
alisionf76de3b2013-04-16 15:35:22 -0400260
alision5f899632013-04-22 17:26:56 -0400261 super.onDestroy();
262 }
alision371b77e2013-04-23 14:51:26 -0400263
264 public void launchCallActivity(SipCall.CallInfo infos)
265 {
266 Log.i(TAG, "Launch Call Activity");
267 Bundle bundle = new Bundle();
268 bundle.putParcelable("CallInfo", infos);
269 Intent intent = new Intent().setClass(this, CallActivity.class);
270 intent.putExtras(bundle);
271 startActivity(intent);
272 }
alisionf76de3b2013-04-16 15:35:22 -0400273
alision5f899632013-04-22 17:26:56 -0400274 /** Defines callbacks for service binding, passed to bindService() */
275 private ServiceConnection mConnection = new ServiceConnection() {
alisionf76de3b2013-04-16 15:35:22 -0400276
alision5f899632013-04-22 17:26:56 -0400277 private ISipClient callback = new ISipClient.Stub() {
alision371b77e2013-04-23 14:51:26 -0400278
alision5f899632013-04-22 17:26:56 -0400279 @Override
alision371b77e2013-04-23 14:51:26 -0400280 public void incomingCall(Intent call) throws RemoteException {
281 Log.i(TAG, "Incoming call transfered from Service");
282 SipCall.CallInfo infos = new SipCall.CallInfo(call);
alision5f899632013-04-22 17:26:56 -0400283
alision371b77e2013-04-23 14:51:26 -0400284 SipCall c = new SipCall(infos);
285 mCallElementList.addCall(c);
286 }
287
288 @Override
289 public void callStateChanged(Intent callState) throws RemoteException {
290 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
291 String cID = b.getString("CallID");
292 String state = b.getString("State");
293 Log.i(TAG,"callStateChanged"+cID+" "+state);
294 mCallElementList.updateCall(cID, state);
295
alision5f899632013-04-22 17:26:56 -0400296 }
297 };
alisionf76de3b2013-04-16 15:35:22 -0400298
alision5f899632013-04-22 17:26:56 -0400299 @Override
300 public void onServiceConnected(ComponentName className, IBinder binder) {
301 service = ISipService.Stub.asInterface(binder);
alision371b77e2013-04-23 14:51:26 -0400302
alision5f899632013-04-22 17:26:56 -0400303 try {
alision371b77e2013-04-23 14:51:26 -0400304 service.registerClient(callback);
alision5f899632013-04-22 17:26:56 -0400305 } catch (RemoteException e) {
alision371b77e2013-04-23 14:51:26 -0400306 Log.e(TAG, e.toString());
alision5f899632013-04-22 17:26:56 -0400307 }
308 mApplication.setSipService(service);
309 mBound = true;
alision5f899632013-04-22 17:26:56 -0400310 mCallElementList.onServiceSipBinded(service);
311 Log.d(TAG, "Service connected service=" + service);
312 }
313
314 @Override
315 public void onServiceDisconnected(ComponentName arg0) {
316 mApplication.setSipService(null);
317 mBound = false;
318 Log.d(TAG, "Service disconnected service=" + service);
319 }
320 };
321
322 @Override
323 public boolean onOptionsItemSelected(MenuItem item) {
324 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
325 if (item.getItemId() != 0) {
326 // When the button is clicked, launch an activity through this intent
327 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
328
329 // Make it a subactivity so we know when it returns
330 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
331 }
332
333 return super.onOptionsItemSelected(item);
334 }
alision371b77e2013-04-23 14:51:26 -0400335
alision5f899632013-04-22 17:26:56 -0400336 @Override
alision371b77e2013-04-23 14:51:26 -0400337 public void onActivityResult(int requestCode, int resultCode, Intent data) {
alision5f899632013-04-22 17:26:56 -0400338 super.onActivityResult(requestCode, resultCode, data);
alision371b77e2013-04-23 14:51:26 -0400339 if (REQUEST_CODE_PREFERENCES == requestCode && service != null) {
340 // Refresh Spinner with modified accounts
alision5f899632013-04-22 17:26:56 -0400341 mCallElementList.onServiceSipBinded(service);
342 }
343 }
344
345 @Override
346 public boolean onCreateOptionsMenu(Menu menu) {
347 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
348 return true;
349 }
350
351 @Override
352 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
353 }
354
355 @Override
356 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
357 // When the given tab is selected, switch to the corresponding page in the ViewPager.
358 mViewPager.setCurrentItem(tab.getPosition());
359 }
360
361 @Override
362 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
363 // Log.d(TAG, "onTabReselected");
364 }
365
alisionf76de3b2013-04-16 15:35:22 -0400366
alision5f899632013-04-22 17:26:56 -0400367 public void processingNewCallAction() {
368 // String accountID = mAccountList.currentAccountID;
369 Log.w(TAG, "processingNewCallAction() mCallElementList=" + mCallElementList);
370 String accountID = mCallElementList.getSelectedAccount();
371 EditText editText = (EditText) findViewById(R.id.phoneNumberTextEntry);
372 String to = editText.getText().toString();
alisionf76de3b2013-04-16 15:35:22 -0400373
alision5f899632013-04-22 17:26:56 -0400374 Random random = new Random();
375 String callID = Integer.toString(random.nextInt());
376 SipCall.CallInfo info = new SipCall.CallInfo();
alisionf76de3b2013-04-16 15:35:22 -0400377
alision5f899632013-04-22 17:26:56 -0400378 info.mCallID = callID;
379 info.mAccountID = accountID;
380 info.mDisplayName = "Cool Guy!";
381 info.mPhone = to;
382 info.mEmail = "coolGuy@coolGuy.com";
383 info.mCallType = SipCall.CALL_TYPE_OUTGOING;
alisionf76de3b2013-04-16 15:35:22 -0400384
alision5f899632013-04-22 17:26:56 -0400385 SipCall call = CallListReceiver.getCallInstance(info);
alision371b77e2013-04-23 14:51:26 -0400386 launchCallActivity(call.mCallInfo);
387
alision5f899632013-04-22 17:26:56 -0400388 try {
389 service.placeCall(info.mAccountID, info.mCallID, info.mPhone);
390 } catch (RemoteException e) {
391 Log.e(TAG, "Cannot call service method", e);
392 }
alision371b77e2013-04-23 14:51:26 -0400393 mCallElementList.addCall(call);
alision5f899632013-04-22 17:26:56 -0400394 }
alisionf76de3b2013-04-16 15:35:22 -0400395
alision5f899632013-04-22 17:26:56 -0400396 public void processingHangUpAction() {
397 SipCall call = (SipCall) buttonHangup.getTag();
398 if (call != null)
399 call.notifyServiceHangup(service);
400 }
alisionf76de3b2013-04-16 15:35:22 -0400401
alision5f899632013-04-22 17:26:56 -0400402 /**
403 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to one of the primary sections of the app.
404 */
405 public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
alisionf76de3b2013-04-16 15:35:22 -0400406
alision5f899632013-04-22 17:26:56 -0400407 public SectionsPagerAdapter(FragmentManager fm) {
408 super(fm);
409 }
alisionf76de3b2013-04-16 15:35:22 -0400410
alision5f899632013-04-22 17:26:56 -0400411 @Override
412 public Fragment getItem(int i) {
413 Fragment fragment;
alisionf76de3b2013-04-16 15:35:22 -0400414
alision5f899632013-04-22 17:26:56 -0400415 switch (i) {
416 case 0:
417 mContactListFragment = new ContactListFragment();
418 fragment = mContactListFragment;
419 Log.w(TAG, "getItem() ContactListFragment=" + fragment);
420 break;
421 case 1:
422 mCallElementList = new CallElementListFragment();
alision371b77e2013-04-23 14:51:26 -0400423// SipCall.setCallElementList(mCallElementList);
424 // mCallElementList.setAccountList(mAccountList);
alision5f899632013-04-22 17:26:56 -0400425 fragment = mCallElementList;
426 Log.w(TAG, "getItem() CallElementList=" + fragment);
427 break;
428 case 2:
429 fragment = new HistoryFragment();
430 Log.w(TAG, "getItem() HistoryFragment=" + fragment);
431 break;
432 default:
433 Log.e(TAG, "getItem() unknown tab position " + i);
434 return null;
435 }
alisionf76de3b2013-04-16 15:35:22 -0400436
alision5f899632013-04-22 17:26:56 -0400437 // Log.i(TAG, "getItem() fragment is " + fragment);
438 Bundle args = new Bundle();
439 args.putInt(HistoryFragment.ARG_SECTION_NUMBER, i + 1);
440 fragment.setArguments(args);
441 return fragment;
442 }
alisionf76de3b2013-04-16 15:35:22 -0400443
alision5f899632013-04-22 17:26:56 -0400444 public Fragment getFragment(int i) {
445 Fragment fragment;
alisionf76de3b2013-04-16 15:35:22 -0400446
alision5f899632013-04-22 17:26:56 -0400447 switch (i) {
448 case 0:
449 fragment = mContactListFragment;
450 break;
451 case 1:
452 fragment = mCallElementList;
453 break;
454 case 2:
455 fragment = mHistorySectionFragment;
456 break;
457 default:
458 Log.e(TAG, "getClassName: unknown fragment position " + i);
459 fragment = null;
460 }
alisionf76de3b2013-04-16 15:35:22 -0400461
alision5f899632013-04-22 17:26:56 -0400462 // Log.w(TAG, "getFragment: fragment=" + fragment);
463 return fragment;
464 }
alisionf76de3b2013-04-16 15:35:22 -0400465
alision5f899632013-04-22 17:26:56 -0400466 public String getClassName(int i) {
467 String name;
alisionf76de3b2013-04-16 15:35:22 -0400468
alision5f899632013-04-22 17:26:56 -0400469 switch (i) {
470 case 0:
471 name = ContactListFragment.class.getName();
472 break;
473 case 1:
474 name = CallElementListFragment.class.getName();
475 break;
476 case 2:
477 name = HistoryFragment.class.getName();
478 break;
alisionf76de3b2013-04-16 15:35:22 -0400479
alision5f899632013-04-22 17:26:56 -0400480 default:
481 Log.e(TAG, "getClassName: unknown fragment position " + i);
482 return null;
483 }
alisionf76de3b2013-04-16 15:35:22 -0400484
alision5f899632013-04-22 17:26:56 -0400485 // Log.w(TAG, "getClassName: name=" + name);
486 return name;
487 }
alisionf76de3b2013-04-16 15:35:22 -0400488
alision5f899632013-04-22 17:26:56 -0400489 @Override
490 public int getCount() {
491 return 3;
492 }
alisionf76de3b2013-04-16 15:35:22 -0400493
alision5f899632013-04-22 17:26:56 -0400494 @Override
495 public CharSequence getPageTitle(int position) {
496 switch (position) {
497 case 0:
498 return getString(R.string.title_section0).toUpperCase();
499 case 1:
500 return getString(R.string.title_section1).toUpperCase();
501 case 2:
502 return getString(R.string.title_section2).toUpperCase();
503 case 3:
504 return getString(R.string.title_section3).toUpperCase();
505 default:
506 Log.e(TAG, "getPageTitle: unknown tab position " + position);
507 break;
508 }
509 return null;
510 }
511 }
alisionf76de3b2013-04-16 15:35:22 -0400512
alision371b77e2013-04-23 14:51:26 -0400513 @Override
514 public void onCallSelected(SipCall c) {
515 launchCallActivity(c.mCallInfo);
516
517 }
518
alisionf76de3b2013-04-16 15:35:22 -0400519}