blob: 0e1c82237738954a796e74c7bef52240fa20b1c3 [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>
alision11e8e162013-05-28 10:33:14 -04005 * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
alisionf76de3b2013-04-16 15:35:22 -04006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * Additional permission under GNU GPL version 3 section 7:
22 *
23 * If you modify this program, or any covered work, by linking or
24 * combining it with the OpenSSL project's OpenSSL library (or a
25 * modified version of that library), containing parts covered by the
26 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
27 * grants you additional permission to convey the resulting work.
28 * Corresponding Source for a non-source form of such a combination
29 * shall include the source code for the parts of OpenSSL used as well
30 * as that of the covered work.
31 */
32package com.savoirfairelinux.sflphone.client;
33
alisionf76de3b2013-04-16 15:35:22 -040034import android.app.ActionBar;
35import android.app.Activity;
36import android.app.Fragment;
alisionf76de3b2013-04-16 15:35:22 -040037import android.app.FragmentTransaction;
38import android.content.ComponentName;
39import android.content.Context;
40import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040041import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040042import android.content.ServiceConnection;
43import android.os.Bundle;
44import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040045import android.os.RemoteException;
alision9f7a6ec2013-05-24 16:26:26 -040046import android.support.v4.app.ActionBarDrawerToggle;
47import android.support.v4.view.GravityCompat;
alisionf76de3b2013-04-16 15:35:22 -040048import android.support.v4.view.ViewPager;
alision9f7a6ec2013-05-24 16:26:26 -040049import android.support.v4.widget.DrawerLayout;
alisionf76de3b2013-04-16 15:35:22 -040050import android.util.Log;
alision9f7a6ec2013-05-24 16:26:26 -040051import android.view.MenuItem;
52import android.view.View;
alision7297bdb2013-05-21 11:56:55 -040053import android.widget.RelativeLayout;
alision04a00182013-05-10 17:05:29 -040054import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040055
56import com.savoirfairelinux.sflphone.R;
alision9f7a6ec2013-05-24 16:26:26 -040057import com.savoirfairelinux.sflphone.adapters.SectionsPagerAdapter;
alision84813a12013-05-27 17:40:39 -040058import com.savoirfairelinux.sflphone.client.receiver.CallReceiver;
alisionf76de3b2013-04-16 15:35:22 -040059import com.savoirfairelinux.sflphone.fragments.CallElementListFragment;
60import com.savoirfairelinux.sflphone.fragments.ContactListFragment;
alision7297bdb2013-05-21 11:56:55 -040061import com.savoirfairelinux.sflphone.fragments.DialingFragment;
alisiond9e29442013-04-17 16:10:18 -040062import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
alision9f7a6ec2013-05-24 16:26:26 -040063import com.savoirfairelinux.sflphone.fragments.MenuFragment;
alision84813a12013-05-27 17:40:39 -040064import com.savoirfairelinux.sflphone.interfaces.CallInterface;
65import com.savoirfairelinux.sflphone.model.CallContact;
alisionf76de3b2013-04-16 15:35:22 -040066import com.savoirfairelinux.sflphone.model.SipCall;
alision84813a12013-05-27 17:40:39 -040067import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
alisionf76de3b2013-04-16 15:35:22 -040068import com.savoirfairelinux.sflphone.service.ISipService;
69import com.savoirfairelinux.sflphone.service.SipService;
alision7297bdb2013-05-21 11:56:55 -040070import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer;
alisionf76de3b2013-04-16 15:35:22 -040071
alision84813a12013-05-27 17:40:39 -040072public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, DialingFragment.Callbacks, ContactListFragment.Callbacks,
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100073CallElementListFragment.Callbacks, HistoryFragment.Callbacks, CallInterface {
alisionfde875f2013-05-28 17:01:54 -040074
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100075 SectionsPagerAdapter mSectionsPagerAdapter = null;
76 static final String TAG = "SFLPhoneHomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040077
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100078 private ContactListFragment mContactsFragment = null;
79 private DialingFragment mDialingFragment = null;
80 private CallElementListFragment mCallElementList = null;
81 private HistoryFragment mHistorySectionFragment = null;
alisionf76de3b2013-04-16 15:35:22 -040082
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100083 Fragment fMenu;
alisionf76de3b2013-04-16 15:35:22 -040084
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100085 private boolean mBound = false;
86 private ISipService service;
alisionf76de3b2013-04-16 15:35:22 -040087
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100088 private CharSequence mDrawerTitle;
89 private CharSequence mTitle;
alisionf76de3b2013-04-16 15:35:22 -040090
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100091 private static final int REQUEST_CODE_PREFERENCES = 1;
92 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -040093
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100094 private static final int ACTION_BAR_TAB_DIALING = 0;
95 private static final int ACTION_BAR_TAB_CALL = 1;
96 private static final int ACTION_BAR_TAB_HISTORY = 2;
alisionf76de3b2013-04-16 15:35:22 -040097
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100098 RelativeLayout mSliderButton;
99 CustomSlidingDrawer mDrawer;
100 private DrawerLayout mDrawerLayout;
101 private ActionBarDrawerToggle mDrawerToggle;
102 /**
103 * The {@link ViewPager} that will host the section contents.
104 */
105 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400106
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000107 CallReceiver receiver;
alision84813a12013-05-27 17:40:39 -0400108
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000109 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 -0400110
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000111 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
alision9f7a6ec2013-05-24 16:26:26 -0400112
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000113 /* called before activity is killed, e.g. rotation */
114 @Override
115 protected void onSaveInstanceState(Bundle bundle) {
116 super.onSaveInstanceState(bundle);
117 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
118 try {
119 getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i));
120 } catch (IllegalStateException e) {
121 Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i));
122 }
123 }
alision9f7a6ec2013-05-24 16:26:26 -0400124
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000125 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
126 Log.w(TAG, "onSaveInstanceState()");
127 }
alision9f7a6ec2013-05-24 16:26:26 -0400128
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000129 @Override
130 public void onCreate(Bundle savedInstanceState) {
131 super.onCreate(savedInstanceState);
alision9f7a6ec2013-05-24 16:26:26 -0400132
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000133 receiver = new CallReceiver(this);
alision84813a12013-05-27 17:40:39 -0400134
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000135 String libraryPath = getApplicationInfo().dataDir + "/lib";
136 Log.i(TAG, libraryPath);
alision9f7a6ec2013-05-24 16:26:26 -0400137
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000138 // Bind to LocalService
139 if (!mBound) {
140 Log.i(TAG, "onStart: Binding service...");
141 Intent intent = new Intent(this, SipService.class);
142 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
143 }
alision9f7a6ec2013-05-24 16:26:26 -0400144
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000145 setContentView(R.layout.activity_sflphone_home);
alision9f7a6ec2013-05-24 16:26:26 -0400146
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000147 if (mSectionsPagerAdapter == null) {
148 mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager());
149 }
alision9f7a6ec2013-05-24 16:26:26 -0400150
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000151 /* getFragment(Bundle, String) */
152 if (savedInstanceState != null) {
153 Log.w(TAG, "Activity restarted, recreating PagerAdapter...");
154 /* getFragment (Bundle bundle, String key) */
155 mDialingFragment = (DialingFragment) getFragmentManager().getFragment(savedInstanceState,
156 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_DIALING));
157 mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState,
158 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL));
159 mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState,
160 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY));
161 }
alision9f7a6ec2013-05-24 16:26:26 -0400162
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000163 if (mDialingFragment == null) {
164 mDialingFragment = new DialingFragment();
165 Log.w(TAG, "Recreated mDialingFragment=" + mDialingFragment);
166 }
alisionf76de3b2013-04-16 15:35:22 -0400167
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000168 if (mContactsFragment == null) {
169 mContactsFragment = new ContactListFragment();
170 Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment);
171 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
172 }
173 if (mCallElementList == null) {
174 mCallElementList = new CallElementListFragment();
175 Log.w(TAG, "Recreated mCallElementList=" + mCallElementList);
176 }
177 if (mHistorySectionFragment == null) {
178 mHistorySectionFragment = new HistoryFragment();
179 Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment);
180 }
alision9f7a6ec2013-05-24 16:26:26 -0400181
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000182 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400183
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000184 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400185
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000186 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400187
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000188 final ActionBar actionBar = getActionBar();
189 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
alisionf76de3b2013-04-16 15:35:22 -0400190
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000191 // Set up the ViewPager with the sections adapter.
192 mViewPager = (ViewPager) findViewById(R.id.pager);
193 mViewPager.setAdapter(mSectionsPagerAdapter);
alisionf76de3b2013-04-16 15:35:22 -0400194
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000195 mTitle = mDrawerTitle = getTitle();
196 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
197 // mDrawerList = (ListView) findViewById(R.id.left_drawer);
alisionf76de3b2013-04-16 15:35:22 -0400198
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000199 // set a custom shadow that overlays the main content when the drawer opens
200 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
201 // set up the drawer's list view with items and click listener
202 // mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
203 // mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
alisionf76de3b2013-04-16 15:35:22 -0400204
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000205 getActionBar().setDisplayHomeAsUpEnabled(true);
206 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400207
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000208 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
209 mDrawerLayout, /* DrawerLayout object */
210 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
211 R.string.drawer_open, /* "open drawer" description for accessibility */
212 R.string.drawer_close /* "close drawer" description for accessibility */
213 ) {
214 @Override
215 public void onDrawerClosed(View view) {
216 getActionBar().setTitle(mTitle);
217 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
218 }
alisionf76de3b2013-04-16 15:35:22 -0400219
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000220 @Override
221 public void onDrawerOpened(View drawerView) {
222 getActionBar().setTitle(mDrawerTitle);
223 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
224 }
225 };
alisionf76de3b2013-04-16 15:35:22 -0400226
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000227 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400228
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000229 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
230 @Override
231 public void onPageSelected(int position) {
232 actionBar.setSelectedNavigationItem(position);
233 }
234 });
alisionf76de3b2013-04-16 15:35:22 -0400235
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000236 // For each of the sections in the app, add a tab to the action bar.
237 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
alisionf76de3b2013-04-16 15:35:22 -0400238
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000239 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
240 }
alisionf76de3b2013-04-16 15:35:22 -0400241
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000242 actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
alisionf76de3b2013-04-16 15:35:22 -0400243
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000244 fMenu = new MenuFragment();
245 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
246 }
alisionf76de3b2013-04-16 15:35:22 -0400247
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000248 @Override
249 protected void onStart() {
250 Log.i(TAG, "onStart");
251 super.onStart();
252 }
alisionf76de3b2013-04-16 15:35:22 -0400253
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000254 /* user gets back to the activity, e.g. through task manager */
255 @Override
256 protected void onRestart() {
257 super.onRestart();
258 }
alisionf76de3b2013-04-16 15:35:22 -0400259
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000260 /* activity gets back to the foreground and user input */
261 @Override
262 protected void onResume() {
263 Log.i(TAG, "onResume");
264 IntentFilter intentFilter = new IntentFilter();
265 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
266 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
267 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
268 registerReceiver(receiver, intentFilter);
269 super.onResume();
270 }
alisione2a38e12013-04-25 14:20:20 -0400271
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000272 /* activity no more in foreground */
273 @Override
274 protected void onPause() {
275 super.onPause();
276 unregisterReceiver(receiver);
277 }
alisionf76de3b2013-04-16 15:35:22 -0400278
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000279 /* activity is no longer visible */
280 @Override
281 protected void onStop() {
282 super.onStop();
283 }
alisionf76de3b2013-04-16 15:35:22 -0400284
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000285 /* activity finishes itself or is being killed by the system */
286 @Override
287 protected void onDestroy() {
288 /* stop the service, if no other bound user, no need to check if it is running */
289 if (mBound) {
290 Log.i(TAG, "onDestroy: Unbinding service...");
291 unbindService(mConnection);
292 mBound = false;
293 }
alision371b77e2013-04-23 14:51:26 -0400294
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000295 super.onDestroy();
296 }
alision73424b62013-04-26 11:49:18 -0400297
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000298 public void launchCallActivity(SipCall infos, String action) {
299 Log.i(TAG, "Launch Call Activity");
300 Bundle bundle = new Bundle();
301 bundle.putString("action", action);
302 bundle.putParcelable("CallInfo", infos);
303 Intent intent = new Intent().setClass(this, CallActivity.class);
304 intent.putExtras(bundle);
305 startActivityForResult(intent, REQUEST_CODE_CALL);
306 }
alisionf76de3b2013-04-16 15:35:22 -0400307
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000308 /** Defines callbacks for service binding, passed to bindService() */
309 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400310
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000311 @Override
312 public void onServiceConnected(ComponentName className, IBinder binder) {
313 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400314
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000315 mBound = true;
316 mCallElementList.onServiceSipBinded(service);
317 mHistorySectionFragment.onServiceSipBinded(service);
318 mDialingFragment.onServiceSipBinded(service);
319 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400320
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000321 }
alision5f899632013-04-22 17:26:56 -0400322
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000323 @Override
324 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400325
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000326 mBound = false;
327 Log.d(TAG, "Service disconnected service=" + service);
328 }
329 };
alision5f899632013-04-22 17:26:56 -0400330
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000331 @Override
332 public boolean onOptionsItemSelected(MenuItem item) {
333 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400334
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000335 if (mDrawerToggle.onOptionsItemSelected(item)) {
336 return true;
337 }
alision5f899632013-04-22 17:26:56 -0400338
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000339 return super.onOptionsItemSelected(item);
340 }
alisionf76de3b2013-04-16 15:35:22 -0400341
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000342 @Override
343 public void onActivityResult(int requestCode, int resultCode, Intent data) {
344 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400345
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000346 switch (requestCode) {
347 case REQUEST_CODE_PREFERENCES:
348 mCallElementList.onServiceSipBinded(service);
349 break;
350 case REQUEST_CODE_CALL:
alision84813a12013-05-27 17:40:39 -0400351
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000352 break;
353 }
alisionf76de3b2013-04-16 15:35:22 -0400354
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000355 }
alisionf76de3b2013-04-16 15:35:22 -0400356
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000357 // @Override
358 // public boolean onCreateOptionsMenu(Menu menu) {
359 // getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
360 // return true;
361 // }
alisionf76de3b2013-04-16 15:35:22 -0400362
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000363 @Override
364 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
365 }
alisionf76de3b2013-04-16 15:35:22 -0400366
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000367 @Override
368 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
369 // When the given tab is selected, switch to the corresponding page in the ViewPager.
370 mViewPager.setCurrentItem(tab.getPosition());
371 }
alisionf76de3b2013-04-16 15:35:22 -0400372
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000373 @Override
374 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
375 // Log.d(TAG, "onTabReselected");
376 }
alisionf76de3b2013-04-16 15:35:22 -0400377
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000378 @Override
379 public void onCallSelected(SipCall c) {
380 // launchCallActivity(c.mCallInfo);
alisionf76de3b2013-04-16 15:35:22 -0400381
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000382 }
alisionf76de3b2013-04-16 15:35:22 -0400383
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000384 @Override
385 public ISipService getService() {
386 return service;
387 }
alisionf76de3b2013-04-16 15:35:22 -0400388
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000389 /**
390 * Interface implemented to handle incoming events
391 */
392 @Override
393 public void incomingCall(Intent call) {
394 Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show();
395 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400396
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000397 mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400398
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000399 launchCallActivity(infos, CallManagerCallBack.INCOMING_CALL);
alision84813a12013-05-27 17:40:39 -0400400
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000401 }
alision84813a12013-05-27 17:40:39 -0400402
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000403 @Override
404 public void callStateChanged(Intent callState) {
405 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
406 String cID = b.getString("CallID");
407 String state = b.getString("State");
408 Log.i(TAG, "callStateChanged" + cID + " " + state);
409 mCallElementList.updateCall(cID, state);
alision84813a12013-05-27 17:40:39 -0400410
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000411 }
alision84813a12013-05-27 17:40:39 -0400412
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000413 @Override
414 public void incomingText(Intent msg) {
415 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
416 b.getString("CallID");
417 String from = b.getString("From");
418 String mess = b.getString("Msg");
419 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
420 }
alision84813a12013-05-27 17:40:39 -0400421
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000422 @Override
423 public void onContactSelected(CallContact c) {
alisionfde875f2013-05-28 17:01:54 -0400424
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000425 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
426 try {
427 callBuilder.startCallCreation().setAccountID(service.getAccountList().get(0).toString()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
428 } catch (RemoteException e1) {
429 Log.e(TAG,e1.toString());
430 }
431 callBuilder.addContact(c);
alisionfde875f2013-05-28 17:01:54 -0400432
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000433 try {
434 launchCallActivity(callBuilder.build(), "call");
435 } catch (Exception e) {
436 Log.e(TAG, e.toString());
437 }
alision84813a12013-05-27 17:40:39 -0400438
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000439 }
alision84813a12013-05-27 17:40:39 -0400440
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000441 @Override
442 public void onCallDialed(String accountID, String to) {
alision84813a12013-05-27 17:40:39 -0400443
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000444 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
445 callBuilder.startCallCreation().setAccountID(accountID).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
446 callBuilder.addContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400447
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000448 try {
449 launchCallActivity(callBuilder.build(), "call");
450 } catch (Exception e) {
451 Log.e(TAG, e.toString());
452 }
alision84813a12013-05-27 17:40:39 -0400453
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000454 }
alision371b77e2013-04-23 14:51:26 -0400455
alisionf76de3b2013-04-16 15:35:22 -0400456}