blob: ee5e2aaf1dbe0a4fe604629b102767a6183130ee [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
alisiond45da712013-05-30 09:18:49 -040034import java.util.HashMap;
alision84813a12013-05-27 17:40:39 -040035
alisionf76de3b2013-04-16 15:35:22 -040036import android.app.ActionBar;
37import android.app.Activity;
38import android.app.Fragment;
alisionf76de3b2013-04-16 15:35:22 -040039import android.app.FragmentTransaction;
40import android.content.ComponentName;
41import android.content.Context;
42import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040043import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040044import android.content.ServiceConnection;
45import android.os.Bundle;
46import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040047import android.os.RemoteException;
alision9f7a6ec2013-05-24 16:26:26 -040048import android.support.v4.app.ActionBarDrawerToggle;
49import android.support.v4.view.GravityCompat;
alisionf76de3b2013-04-16 15:35:22 -040050import android.support.v4.view.ViewPager;
alision9f7a6ec2013-05-24 16:26:26 -040051import android.support.v4.widget.DrawerLayout;
alisionf76de3b2013-04-16 15:35:22 -040052import android.util.Log;
alision9f7a6ec2013-05-24 16:26:26 -040053import android.view.MenuItem;
54import android.view.View;
alision7297bdb2013-05-21 11:56:55 -040055import android.widget.RelativeLayout;
alisiond45da712013-05-30 09:18:49 -040056import android.widget.TabHost;
alision3c5c2a92013-05-30 09:50:47 -040057import android.widget.TabHost.OnTabChangeListener;
alisiond45da712013-05-30 09:18:49 -040058import android.widget.TabHost.TabContentFactory;
alision04a00182013-05-10 17:05:29 -040059import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040060
61import com.savoirfairelinux.sflphone.R;
alision9f7a6ec2013-05-24 16:26:26 -040062import com.savoirfairelinux.sflphone.adapters.SectionsPagerAdapter;
alision84813a12013-05-27 17:40:39 -040063import com.savoirfairelinux.sflphone.client.receiver.CallReceiver;
alisionf76de3b2013-04-16 15:35:22 -040064import com.savoirfairelinux.sflphone.fragments.CallElementListFragment;
65import com.savoirfairelinux.sflphone.fragments.ContactListFragment;
alision7297bdb2013-05-21 11:56:55 -040066import com.savoirfairelinux.sflphone.fragments.DialingFragment;
alisiond9e29442013-04-17 16:10:18 -040067import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
alision9f7a6ec2013-05-24 16:26:26 -040068import com.savoirfairelinux.sflphone.fragments.MenuFragment;
alision84813a12013-05-27 17:40:39 -040069import com.savoirfairelinux.sflphone.interfaces.CallInterface;
70import com.savoirfairelinux.sflphone.model.CallContact;
alisionf76de3b2013-04-16 15:35:22 -040071import com.savoirfairelinux.sflphone.model.SipCall;
alision84813a12013-05-27 17:40:39 -040072import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
alisionf76de3b2013-04-16 15:35:22 -040073import com.savoirfairelinux.sflphone.service.ISipService;
74import com.savoirfairelinux.sflphone.service.SipService;
alision7297bdb2013-05-21 11:56:55 -040075import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer;
alisionf76de3b2013-04-16 15:35:22 -040076
alision84813a12013-05-27 17:40:39 -040077public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, DialingFragment.Callbacks, ContactListFragment.Callbacks,
78 CallElementListFragment.Callbacks, HistoryFragment.Callbacks, CallInterface {
alisionfde875f2013-05-28 17:01:54 -040079
alision9f7a6ec2013-05-24 16:26:26 -040080 SectionsPagerAdapter mSectionsPagerAdapter = null;
alision84813a12013-05-27 17:40:39 -040081 static final String TAG = "SFLPhoneHomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040082
alision9f7a6ec2013-05-24 16:26:26 -040083 private ContactListFragment mContactsFragment = null;
84 private DialingFragment mDialingFragment = null;
85 private CallElementListFragment mCallElementList = null;
86 private HistoryFragment mHistorySectionFragment = null;
alisionf76de3b2013-04-16 15:35:22 -040087
alision9f7a6ec2013-05-24 16:26:26 -040088 Fragment fMenu;
alisionf76de3b2013-04-16 15:35:22 -040089
alision9f7a6ec2013-05-24 16:26:26 -040090 private boolean mBound = false;
91 private ISipService service;
alisionf76de3b2013-04-16 15:35:22 -040092
alision9f7a6ec2013-05-24 16:26:26 -040093 private CharSequence mDrawerTitle;
94 private CharSequence mTitle;
alisionf76de3b2013-04-16 15:35:22 -040095
alision9f7a6ec2013-05-24 16:26:26 -040096 private static final int REQUEST_CODE_PREFERENCES = 1;
97 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -040098
alision9f7a6ec2013-05-24 16:26:26 -040099 private static final int ACTION_BAR_TAB_DIALING = 0;
100 private static final int ACTION_BAR_TAB_CALL = 1;
101 private static final int ACTION_BAR_TAB_HISTORY = 2;
alisionf76de3b2013-04-16 15:35:22 -0400102
alision0b553832013-05-30 09:31:06 -0400103 RelativeLayout mSliderButton;
alision9f7a6ec2013-05-24 16:26:26 -0400104 CustomSlidingDrawer mDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400105 private DrawerLayout mDrawerLayout;
alision9f7a6ec2013-05-24 16:26:26 -0400106 private ActionBarDrawerToggle mDrawerToggle;
107 /**
108 * The {@link ViewPager} that will host the section contents.
109 */
110 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400111
alision84813a12013-05-27 17:40:39 -0400112 CallReceiver receiver;
113
alision3c5c2a92013-05-30 09:50:47 -0400114
115 private TabHost mTabHost;
alisionf76de3b2013-04-16 15:35:22 -0400116
alision9f7a6ec2013-05-24 16:26:26 -0400117 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
118
119 /* called before activity is killed, e.g. rotation */
120 @Override
121 protected void onSaveInstanceState(Bundle bundle) {
122 super.onSaveInstanceState(bundle);
123 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
124 try {
125 getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i));
126 } catch (IllegalStateException e) {
127 Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i));
128 }
129 }
130
131 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
132 Log.w(TAG, "onSaveInstanceState()");
133 }
134
135 @Override
136 public void onCreate(Bundle savedInstanceState) {
137 super.onCreate(savedInstanceState);
138
alision84813a12013-05-27 17:40:39 -0400139 receiver = new CallReceiver(this);
140
alision9f7a6ec2013-05-24 16:26:26 -0400141 String libraryPath = getApplicationInfo().dataDir + "/lib";
142 Log.i(TAG, libraryPath);
143
144 // Bind to LocalService
145 if (!mBound) {
146 Log.i(TAG, "onStart: Binding service...");
147 Intent intent = new Intent(this, SipService.class);
148 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
149 }
150
151 setContentView(R.layout.activity_sflphone_home);
152
153 if (mSectionsPagerAdapter == null) {
154 mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager());
155 }
156
157 /* getFragment(Bundle, String) */
158 if (savedInstanceState != null) {
159 Log.w(TAG, "Activity restarted, recreating PagerAdapter...");
160 /* getFragment (Bundle bundle, String key) */
161 mDialingFragment = (DialingFragment) getFragmentManager().getFragment(savedInstanceState,
162 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_DIALING));
163 mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState,
164 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL));
165 mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState,
166 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY));
167 }
168
169 if (mDialingFragment == null) {
170 mDialingFragment = new DialingFragment();
alision7297bdb2013-05-21 11:56:55 -0400171 Log.w(TAG, "Recreated mDialingFragment=" + mDialingFragment);
alision9f7a6ec2013-05-24 16:26:26 -0400172 }
alisionf76de3b2013-04-16 15:35:22 -0400173
alision9f7a6ec2013-05-24 16:26:26 -0400174 if (mContactsFragment == null) {
175 mContactsFragment = new ContactListFragment();
176 Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment);
177 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
178 }
179 if (mCallElementList == null) {
180 mCallElementList = new CallElementListFragment();
181 Log.w(TAG, "Recreated mCallElementList=" + mCallElementList);
182 }
183 if (mHistorySectionFragment == null) {
184 mHistorySectionFragment = new HistoryFragment();
185 Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment);
186 }
187
188 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400189
alision84813a12013-05-27 17:40:39 -0400190 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400191
192 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400193
alisionf76de3b2013-04-16 15:35:22 -0400194
alision9f7a6ec2013-05-24 16:26:26 -0400195 // Set up the ViewPager with the sections adapter.
196 mViewPager = (ViewPager) findViewById(R.id.pager);
197 mViewPager.setAdapter(mSectionsPagerAdapter);
alisionf76de3b2013-04-16 15:35:22 -0400198
alision9f7a6ec2013-05-24 16:26:26 -0400199 mTitle = mDrawerTitle = getTitle();
200 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400201
alision0b553832013-05-30 09:31:06 -0400202 // set a custom shadow that overlays the main content when the drawer opens
alision9f7a6ec2013-05-24 16:26:26 -0400203 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400204
alision9f7a6ec2013-05-24 16:26:26 -0400205 getActionBar().setDisplayHomeAsUpEnabled(true);
206 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400207
alision9f7a6ec2013-05-24 16:26:26 -0400208 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 ) {
alision0b553832013-05-30 09:31:06 -0400214 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400215 public void onDrawerClosed(View view) {
216 getActionBar().setTitle(mTitle);
217 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
218 }
alisionf76de3b2013-04-16 15:35:22 -0400219
alision0b553832013-05-30 09:31:06 -0400220 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400221 public void onDrawerOpened(View drawerView) {
222 getActionBar().setTitle(mDrawerTitle);
223 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
224 }
225 };
alisionf76de3b2013-04-16 15:35:22 -0400226
alision3c5c2a92013-05-30 09:50:47 -0400227 mTabHost = (TabHost) findViewById(android.R.id.tabhost);
alision9f7a6ec2013-05-24 16:26:26 -0400228 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400229
alision9f7a6ec2013-05-24 16:26:26 -0400230 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
231 @Override
232 public void onPageSelected(int position) {
alision3c5c2a92013-05-30 09:50:47 -0400233 mTabHost.setCurrentTab(position);
alision9f7a6ec2013-05-24 16:26:26 -0400234 }
235 });
alisionf76de3b2013-04-16 15:35:22 -0400236
alision3c5c2a92013-05-30 09:50:47 -0400237 initialiseTabHost(savedInstanceState);
alisionf76de3b2013-04-16 15:35:22 -0400238
alision9f7a6ec2013-05-24 16:26:26 -0400239 fMenu = new MenuFragment();
240 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
241 }
alisionf76de3b2013-04-16 15:35:22 -0400242
alision3c5c2a92013-05-30 09:50:47 -0400243 private void initialiseTabHost(Bundle args) {
244
245
246 mTabHost.setup();
247 TabInfo tabInfo = null;
248 SFLPhoneHomeActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator(mSectionsPagerAdapter.getPageTitle(0),getResources().getDrawable(mSectionsPagerAdapter.getIconOf(0))), (tabInfo = new TabInfo("Tab1",
249 DialingFragment.class, args)));
250 this.mapTabInfo.put(tabInfo.tag, tabInfo);
251 SFLPhoneHomeActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator(mSectionsPagerAdapter.getPageTitle(1),getResources().getDrawable(mSectionsPagerAdapter.getIconOf(1))), (tabInfo = new TabInfo("Tab2",
252 CallElementListFragment.class, args)));
253 this.mapTabInfo.put(tabInfo.tag, tabInfo);
254 SFLPhoneHomeActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator(mSectionsPagerAdapter.getPageTitle(2),getResources().getDrawable(mSectionsPagerAdapter.getIconOf(2))), (tabInfo = new TabInfo("Tab3",
255 HistoryFragment.class, args)));
256 this.mapTabInfo.put(tabInfo.tag, tabInfo);
257
258 mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
259
260 @Override
261 public void onTabChanged(String tabId) {
262 int pos = mTabHost.getCurrentTab();
263 mViewPager.setCurrentItem(pos);
264
265 }
266 });
267 }
268
alision9f7a6ec2013-05-24 16:26:26 -0400269 @Override
270 protected void onStart() {
271 Log.i(TAG, "onStart");
272 super.onStart();
273 }
alisionf76de3b2013-04-16 15:35:22 -0400274
alision9f7a6ec2013-05-24 16:26:26 -0400275 /* user gets back to the activity, e.g. through task manager */
276 @Override
277 protected void onRestart() {
278 super.onRestart();
279 }
alisionf76de3b2013-04-16 15:35:22 -0400280
alision9f7a6ec2013-05-24 16:26:26 -0400281 /* activity gets back to the foreground and user input */
282 @Override
283 protected void onResume() {
284 Log.i(TAG, "onResume");
alision84813a12013-05-27 17:40:39 -0400285 IntentFilter intentFilter = new IntentFilter();
286 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
287 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
288 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
289 registerReceiver(receiver, intentFilter);
alision9f7a6ec2013-05-24 16:26:26 -0400290 super.onResume();
291 }
alisione2a38e12013-04-25 14:20:20 -0400292
alision9f7a6ec2013-05-24 16:26:26 -0400293 /* activity no more in foreground */
294 @Override
295 protected void onPause() {
296 super.onPause();
alision84813a12013-05-27 17:40:39 -0400297 unregisterReceiver(receiver);
alision9f7a6ec2013-05-24 16:26:26 -0400298 }
alisionf76de3b2013-04-16 15:35:22 -0400299
alision9f7a6ec2013-05-24 16:26:26 -0400300 /* activity is no longer visible */
301 @Override
302 protected void onStop() {
303 super.onStop();
304 }
alisionf76de3b2013-04-16 15:35:22 -0400305
alision9f7a6ec2013-05-24 16:26:26 -0400306 /* activity finishes itself or is being killed by the system */
307 @Override
308 protected void onDestroy() {
309 /* stop the service, if no other bound user, no need to check if it is running */
310 if (mBound) {
311 Log.i(TAG, "onDestroy: Unbinding service...");
312 unbindService(mConnection);
313 mBound = false;
314 }
alision371b77e2013-04-23 14:51:26 -0400315
alision9f7a6ec2013-05-24 16:26:26 -0400316 super.onDestroy();
317 }
alision73424b62013-04-26 11:49:18 -0400318
alisionfde875f2013-05-28 17:01:54 -0400319 public void launchCallActivity(SipCall infos, String action) {
alision9f7a6ec2013-05-24 16:26:26 -0400320 Log.i(TAG, "Launch Call Activity");
321 Bundle bundle = new Bundle();
alision84813a12013-05-27 17:40:39 -0400322 bundle.putString("action", action);
alision9f7a6ec2013-05-24 16:26:26 -0400323 bundle.putParcelable("CallInfo", infos);
324 Intent intent = new Intent().setClass(this, CallActivity.class);
325 intent.putExtras(bundle);
326 startActivityForResult(intent, REQUEST_CODE_CALL);
327 }
alisionf76de3b2013-04-16 15:35:22 -0400328
alision9f7a6ec2013-05-24 16:26:26 -0400329 /** Defines callbacks for service binding, passed to bindService() */
330 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400331
alision9f7a6ec2013-05-24 16:26:26 -0400332 @Override
333 public void onServiceConnected(ComponentName className, IBinder binder) {
334 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400335
alision9f7a6ec2013-05-24 16:26:26 -0400336 mBound = true;
337 mCallElementList.onServiceSipBinded(service);
338 mHistorySectionFragment.onServiceSipBinded(service);
339 mDialingFragment.onServiceSipBinded(service);
340 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400341
alision9f7a6ec2013-05-24 16:26:26 -0400342 }
alision5f899632013-04-22 17:26:56 -0400343
alision9f7a6ec2013-05-24 16:26:26 -0400344 @Override
345 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400346
alision9f7a6ec2013-05-24 16:26:26 -0400347 mBound = false;
348 Log.d(TAG, "Service disconnected service=" + service);
349 }
350 };
alision5f899632013-04-22 17:26:56 -0400351
alision9f7a6ec2013-05-24 16:26:26 -0400352 @Override
353 public boolean onOptionsItemSelected(MenuItem item) {
354 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400355
alision9f7a6ec2013-05-24 16:26:26 -0400356 if (mDrawerToggle.onOptionsItemSelected(item)) {
357 return true;
358 }
alision5f899632013-04-22 17:26:56 -0400359
alision9f7a6ec2013-05-24 16:26:26 -0400360 return super.onOptionsItemSelected(item);
361 }
alisionf76de3b2013-04-16 15:35:22 -0400362
alision9f7a6ec2013-05-24 16:26:26 -0400363 @Override
364 public void onActivityResult(int requestCode, int resultCode, Intent data) {
365 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400366
367 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400368 case REQUEST_CODE_PREFERENCES:
369 mCallElementList.onServiceSipBinded(service);
370 break;
371 case REQUEST_CODE_CALL:
alision84813a12013-05-27 17:40:39 -0400372
alision9f7a6ec2013-05-24 16:26:26 -0400373 break;
374 }
alisionf76de3b2013-04-16 15:35:22 -0400375
alision9f7a6ec2013-05-24 16:26:26 -0400376 }
alisionf76de3b2013-04-16 15:35:22 -0400377
alisionf76de3b2013-04-16 15:35:22 -0400378
alision9f7a6ec2013-05-24 16:26:26 -0400379 @Override
380 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
381 }
alisionf76de3b2013-04-16 15:35:22 -0400382
alision9f7a6ec2013-05-24 16:26:26 -0400383 @Override
384 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
385 // When the given tab is selected, switch to the corresponding page in the ViewPager.
alision0b553832013-05-30 09:31:06 -0400386 mViewPager.setCurrentItem(tab.getPosition());
alision9f7a6ec2013-05-24 16:26:26 -0400387 }
alisionf76de3b2013-04-16 15:35:22 -0400388
alision9f7a6ec2013-05-24 16:26:26 -0400389 @Override
390 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
391 // Log.d(TAG, "onTabReselected");
392 }
alisionf76de3b2013-04-16 15:35:22 -0400393
alision9f7a6ec2013-05-24 16:26:26 -0400394 @Override
395 public void onCallSelected(SipCall c) {
alision84813a12013-05-27 17:40:39 -0400396 // launchCallActivity(c.mCallInfo);
alisionf76de3b2013-04-16 15:35:22 -0400397
alision9f7a6ec2013-05-24 16:26:26 -0400398 }
alisionf76de3b2013-04-16 15:35:22 -0400399
alision9f7a6ec2013-05-24 16:26:26 -0400400 @Override
401 public ISipService getService() {
402 return service;
403 }
alisionf76de3b2013-04-16 15:35:22 -0400404
alision84813a12013-05-27 17:40:39 -0400405 /**
406 * Interface implemented to handle incoming events
407 */
alision9f7a6ec2013-05-24 16:26:26 -0400408 @Override
alision84813a12013-05-27 17:40:39 -0400409 public void incomingCall(Intent call) {
410 Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show();
alisionfde875f2013-05-28 17:01:54 -0400411 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400412
alisionfde875f2013-05-28 17:01:54 -0400413 mCallElementList.addCall(infos);
414
alision84813a12013-05-27 17:40:39 -0400415 launchCallActivity(infos, CallManagerCallBack.INCOMING_CALL);
416
417 }
418
419 @Override
420 public void callStateChanged(Intent callState) {
421 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
422 String cID = b.getString("CallID");
423 String state = b.getString("State");
424 Log.i(TAG, "callStateChanged" + cID + " " + state);
425 mCallElementList.updateCall(cID, state);
426
427 }
428
429 @Override
430 public void incomingText(Intent msg) {
431 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
432 b.getString("CallID");
433 String from = b.getString("From");
434 String mess = b.getString("Msg");
435 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
436 }
437
438 @Override
439 public void onContactSelected(CallContact c) {
alisionfde875f2013-05-28 17:01:54 -0400440
441 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
alision84813a12013-05-27 17:40:39 -0400442 try {
alision0b553832013-05-30 09:31:06 -0400443 callBuilder.startCallCreation().setAccountID(service.getAccountList().get(0).toString()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
alisionfde875f2013-05-28 17:01:54 -0400444 } catch (RemoteException e1) {
alisiond45da712013-05-30 09:18:49 -0400445 Log.e(TAG, e1.toString());
alisionfde875f2013-05-28 17:01:54 -0400446 }
447 callBuilder.addContact(c);
448
449 try {
450 launchCallActivity(callBuilder.build(), "call");
451 } catch (Exception e) {
alision84813a12013-05-27 17:40:39 -0400452 Log.e(TAG, e.toString());
453 }
alision84813a12013-05-27 17:40:39 -0400454
455 }
456
457 @Override
458 public void onCallDialed(String accountID, String to) {
alision84813a12013-05-27 17:40:39 -0400459
alisionfde875f2013-05-28 17:01:54 -0400460 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
461 callBuilder.startCallCreation().setAccountID(accountID).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
462 callBuilder.addContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400463
alisionfde875f2013-05-28 17:01:54 -0400464 try {
465 launchCallActivity(callBuilder.build(), "call");
466 } catch (Exception e) {
467 Log.e(TAG, e.toString());
468 }
alision84813a12013-05-27 17:40:39 -0400469
alision9f7a6ec2013-05-24 16:26:26 -0400470 }
alision371b77e2013-04-23 14:51:26 -0400471
alisiond45da712013-05-30 09:18:49 -0400472 @Override
473 public void onContactDragged() {
474
475 mDrawer.close();
476 getActionBar().setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
477
478 }
479
480 private HashMap<String, TabInfo> mapTabInfo = new HashMap<String, SFLPhoneHomeActivity.TabInfo>();
481
482 /**
483 * A simple factory that returns dummy views to the Tabhost
484 *
485 * @author mwho
486 */
487 class TabFactory implements TabContentFactory {
488
489 private final Context mContext;
490
491 /**
492 * @param context
493 */
494 public TabFactory(Context context) {
495 mContext = context;
496 }
497
498 /**
499 * (non-Javadoc)
500 *
501 * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)
502 */
503 public View createTabContent(String tag) {
504 View v = new View(mContext);
505 v.setMinimumWidth(0);
506 v.setMinimumHeight(0);
507 return v;
508 }
509
510 }
511
512 /**
513 *
514 * @author mwho Maintains extrinsic info of a tab's construct
515 */
516 private class TabInfo {
517 private String tag;
518 private Class<?> clss;
519 private Bundle args;
520 private Fragment fragment;
521
522 TabInfo(String tag, Class<?> clazz, Bundle args) {
523 this.tag = tag;
524 this.clss = clazz;
525 this.args = args;
526 }
527
528 }
529
530 private static void AddTab(SFLPhoneHomeActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
531 // Attach a Tab view factory to the spec
532 tabSpec.setContent(activity.new TabFactory(activity));
533 tabHost.addTab(tabSpec);
534 }
535
alisionf76de3b2013-04-16 15:35:22 -0400536}