blob: a395c5c3aa2593ba408e37288d3a9b34703fe3f0 [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;
alisiond45da712013-05-30 09:18:49 -040057import android.widget.TabHost.TabContentFactory;
alision04a00182013-05-10 17:05:29 -040058import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040059
60import com.savoirfairelinux.sflphone.R;
alision9f7a6ec2013-05-24 16:26:26 -040061import com.savoirfairelinux.sflphone.adapters.SectionsPagerAdapter;
alision84813a12013-05-27 17:40:39 -040062import com.savoirfairelinux.sflphone.client.receiver.CallReceiver;
alisionf76de3b2013-04-16 15:35:22 -040063import com.savoirfairelinux.sflphone.fragments.CallElementListFragment;
64import com.savoirfairelinux.sflphone.fragments.ContactListFragment;
alision7297bdb2013-05-21 11:56:55 -040065import com.savoirfairelinux.sflphone.fragments.DialingFragment;
alisiond9e29442013-04-17 16:10:18 -040066import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
alision9f7a6ec2013-05-24 16:26:26 -040067import com.savoirfairelinux.sflphone.fragments.MenuFragment;
alision84813a12013-05-27 17:40:39 -040068import com.savoirfairelinux.sflphone.interfaces.CallInterface;
69import com.savoirfairelinux.sflphone.model.CallContact;
alisionf76de3b2013-04-16 15:35:22 -040070import com.savoirfairelinux.sflphone.model.SipCall;
alision84813a12013-05-27 17:40:39 -040071import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
alisionf76de3b2013-04-16 15:35:22 -040072import com.savoirfairelinux.sflphone.service.ISipService;
73import com.savoirfairelinux.sflphone.service.SipService;
alision7297bdb2013-05-21 11:56:55 -040074import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer;
alisionf76de3b2013-04-16 15:35:22 -040075
alision84813a12013-05-27 17:40:39 -040076public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, DialingFragment.Callbacks, ContactListFragment.Callbacks,
77 CallElementListFragment.Callbacks, HistoryFragment.Callbacks, CallInterface {
alisionfde875f2013-05-28 17:01:54 -040078
alision9f7a6ec2013-05-24 16:26:26 -040079 SectionsPagerAdapter mSectionsPagerAdapter = null;
alision84813a12013-05-27 17:40:39 -040080 static final String TAG = "SFLPhoneHomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040081
alision9f7a6ec2013-05-24 16:26:26 -040082 private ContactListFragment mContactsFragment = null;
83 private DialingFragment mDialingFragment = null;
84 private CallElementListFragment mCallElementList = null;
85 private HistoryFragment mHistorySectionFragment = null;
alisionf76de3b2013-04-16 15:35:22 -040086
alision9f7a6ec2013-05-24 16:26:26 -040087 Fragment fMenu;
alisionf76de3b2013-04-16 15:35:22 -040088
alision9f7a6ec2013-05-24 16:26:26 -040089 private boolean mBound = false;
90 private ISipService service;
alisionf76de3b2013-04-16 15:35:22 -040091
alision9f7a6ec2013-05-24 16:26:26 -040092 private CharSequence mDrawerTitle;
93 private CharSequence mTitle;
alisionf76de3b2013-04-16 15:35:22 -040094
alision9f7a6ec2013-05-24 16:26:26 -040095 private static final int REQUEST_CODE_PREFERENCES = 1;
96 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -040097
alision9f7a6ec2013-05-24 16:26:26 -040098 private static final int ACTION_BAR_TAB_DIALING = 0;
99 private static final int ACTION_BAR_TAB_CALL = 1;
100 private static final int ACTION_BAR_TAB_HISTORY = 2;
alisionf76de3b2013-04-16 15:35:22 -0400101
alision0b553832013-05-30 09:31:06 -0400102 RelativeLayout mSliderButton;
alision9f7a6ec2013-05-24 16:26:26 -0400103 CustomSlidingDrawer mDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400104 private DrawerLayout mDrawerLayout;
alision9f7a6ec2013-05-24 16:26:26 -0400105 private ActionBarDrawerToggle mDrawerToggle;
106 /**
107 * The {@link ViewPager} that will host the section contents.
108 */
109 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400110
alision84813a12013-05-27 17:40:39 -0400111 CallReceiver receiver;
112
alision9f7a6ec2013-05-24 16:26:26 -0400113 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 -0400114
alision9f7a6ec2013-05-24 16:26:26 -0400115 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
116
117 /* called before activity is killed, e.g. rotation */
118 @Override
119 protected void onSaveInstanceState(Bundle bundle) {
120 super.onSaveInstanceState(bundle);
121 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
122 try {
123 getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i));
124 } catch (IllegalStateException e) {
125 Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i));
126 }
127 }
128
129 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
130 Log.w(TAG, "onSaveInstanceState()");
131 }
132
133 @Override
134 public void onCreate(Bundle savedInstanceState) {
135 super.onCreate(savedInstanceState);
136
alision84813a12013-05-27 17:40:39 -0400137 receiver = new CallReceiver(this);
138
alision9f7a6ec2013-05-24 16:26:26 -0400139 String libraryPath = getApplicationInfo().dataDir + "/lib";
140 Log.i(TAG, libraryPath);
141
142 // Bind to LocalService
143 if (!mBound) {
144 Log.i(TAG, "onStart: Binding service...");
145 Intent intent = new Intent(this, SipService.class);
146 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
147 }
148
149 setContentView(R.layout.activity_sflphone_home);
150
151 if (mSectionsPagerAdapter == null) {
152 mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager());
153 }
154
155 /* getFragment(Bundle, String) */
156 if (savedInstanceState != null) {
157 Log.w(TAG, "Activity restarted, recreating PagerAdapter...");
158 /* getFragment (Bundle bundle, String key) */
159 mDialingFragment = (DialingFragment) getFragmentManager().getFragment(savedInstanceState,
160 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_DIALING));
161 mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState,
162 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL));
163 mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState,
164 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY));
165 }
166
167 if (mDialingFragment == null) {
168 mDialingFragment = new DialingFragment();
alision7297bdb2013-05-21 11:56:55 -0400169 Log.w(TAG, "Recreated mDialingFragment=" + mDialingFragment);
alision9f7a6ec2013-05-24 16:26:26 -0400170 }
alisionf76de3b2013-04-16 15:35:22 -0400171
alision9f7a6ec2013-05-24 16:26:26 -0400172 if (mContactsFragment == null) {
173 mContactsFragment = new ContactListFragment();
174 Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment);
175 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
176 }
177 if (mCallElementList == null) {
178 mCallElementList = new CallElementListFragment();
179 Log.w(TAG, "Recreated mCallElementList=" + mCallElementList);
180 }
181 if (mHistorySectionFragment == null) {
182 mHistorySectionFragment = new HistoryFragment();
183 Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment);
184 }
185
186 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400187
alision84813a12013-05-27 17:40:39 -0400188 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400189
190 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400191
alision9f7a6ec2013-05-24 16:26:26 -0400192 final ActionBar actionBar = getActionBar();
alision0b553832013-05-30 09:31:06 -0400193 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
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);
alision0b553832013-05-30 09:31:06 -0400201 // mDrawerList = (ListView) findViewById(R.id.left_drawer);
alisionf76de3b2013-04-16 15:35:22 -0400202
alision0b553832013-05-30 09:31:06 -0400203 // set a custom shadow that overlays the main content when the drawer opens
alision9f7a6ec2013-05-24 16:26:26 -0400204 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alision0b553832013-05-30 09:31:06 -0400205 // set up the drawer's list view with items and click listener
206 // mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
207 // mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
alisionf76de3b2013-04-16 15:35:22 -0400208
alision9f7a6ec2013-05-24 16:26:26 -0400209 getActionBar().setDisplayHomeAsUpEnabled(true);
210 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400211
alision9f7a6ec2013-05-24 16:26:26 -0400212 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
213 mDrawerLayout, /* DrawerLayout object */
214 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
215 R.string.drawer_open, /* "open drawer" description for accessibility */
216 R.string.drawer_close /* "close drawer" description for accessibility */
217 ) {
alision0b553832013-05-30 09:31:06 -0400218 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400219 public void onDrawerClosed(View view) {
220 getActionBar().setTitle(mTitle);
221 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
222 }
alisionf76de3b2013-04-16 15:35:22 -0400223
alision0b553832013-05-30 09:31:06 -0400224 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400225 public void onDrawerOpened(View drawerView) {
226 getActionBar().setTitle(mDrawerTitle);
227 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
228 }
229 };
alisionf76de3b2013-04-16 15:35:22 -0400230
alision9f7a6ec2013-05-24 16:26:26 -0400231 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400232
alision9f7a6ec2013-05-24 16:26:26 -0400233 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
234 @Override
235 public void onPageSelected(int position) {
alision0b553832013-05-30 09:31:06 -0400236 actionBar.setSelectedNavigationItem(position);
alision9f7a6ec2013-05-24 16:26:26 -0400237 }
238 });
alisionf76de3b2013-04-16 15:35:22 -0400239
alision9f7a6ec2013-05-24 16:26:26 -0400240 // For each of the sections in the app, add a tab to the action bar.
alision0b553832013-05-30 09:31:06 -0400241 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
alisionf76de3b2013-04-16 15:35:22 -0400242
alision0b553832013-05-30 09:31:06 -0400243 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
244 }
alisionf76de3b2013-04-16 15:35:22 -0400245
alision0b553832013-05-30 09:31:06 -0400246 actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
alisionf76de3b2013-04-16 15:35:22 -0400247
alision9f7a6ec2013-05-24 16:26:26 -0400248 fMenu = new MenuFragment();
249 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
250 }
alisionf76de3b2013-04-16 15:35:22 -0400251
alision9f7a6ec2013-05-24 16:26:26 -0400252 @Override
253 protected void onStart() {
254 Log.i(TAG, "onStart");
255 super.onStart();
256 }
alisionf76de3b2013-04-16 15:35:22 -0400257
alision9f7a6ec2013-05-24 16:26:26 -0400258 /* user gets back to the activity, e.g. through task manager */
259 @Override
260 protected void onRestart() {
261 super.onRestart();
262 }
alisionf76de3b2013-04-16 15:35:22 -0400263
alision9f7a6ec2013-05-24 16:26:26 -0400264 /* activity gets back to the foreground and user input */
265 @Override
266 protected void onResume() {
267 Log.i(TAG, "onResume");
alision84813a12013-05-27 17:40:39 -0400268 IntentFilter intentFilter = new IntentFilter();
269 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
270 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
271 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
272 registerReceiver(receiver, intentFilter);
alision9f7a6ec2013-05-24 16:26:26 -0400273 super.onResume();
274 }
alisione2a38e12013-04-25 14:20:20 -0400275
alision9f7a6ec2013-05-24 16:26:26 -0400276 /* activity no more in foreground */
277 @Override
278 protected void onPause() {
279 super.onPause();
alision84813a12013-05-27 17:40:39 -0400280 unregisterReceiver(receiver);
alision9f7a6ec2013-05-24 16:26:26 -0400281 }
alisionf76de3b2013-04-16 15:35:22 -0400282
alision9f7a6ec2013-05-24 16:26:26 -0400283 /* activity is no longer visible */
284 @Override
285 protected void onStop() {
286 super.onStop();
287 }
alisionf76de3b2013-04-16 15:35:22 -0400288
alision9f7a6ec2013-05-24 16:26:26 -0400289 /* activity finishes itself or is being killed by the system */
290 @Override
291 protected void onDestroy() {
292 /* stop the service, if no other bound user, no need to check if it is running */
293 if (mBound) {
294 Log.i(TAG, "onDestroy: Unbinding service...");
295 unbindService(mConnection);
296 mBound = false;
297 }
alision371b77e2013-04-23 14:51:26 -0400298
alision9f7a6ec2013-05-24 16:26:26 -0400299 super.onDestroy();
300 }
alision73424b62013-04-26 11:49:18 -0400301
alisionfde875f2013-05-28 17:01:54 -0400302 public void launchCallActivity(SipCall infos, String action) {
alision9f7a6ec2013-05-24 16:26:26 -0400303 Log.i(TAG, "Launch Call Activity");
304 Bundle bundle = new Bundle();
alision84813a12013-05-27 17:40:39 -0400305 bundle.putString("action", action);
alision9f7a6ec2013-05-24 16:26:26 -0400306 bundle.putParcelable("CallInfo", infos);
307 Intent intent = new Intent().setClass(this, CallActivity.class);
308 intent.putExtras(bundle);
309 startActivityForResult(intent, REQUEST_CODE_CALL);
310 }
alisionf76de3b2013-04-16 15:35:22 -0400311
alision9f7a6ec2013-05-24 16:26:26 -0400312 /** Defines callbacks for service binding, passed to bindService() */
313 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400314
alision9f7a6ec2013-05-24 16:26:26 -0400315 @Override
316 public void onServiceConnected(ComponentName className, IBinder binder) {
317 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400318
alision9f7a6ec2013-05-24 16:26:26 -0400319 mBound = true;
320 mCallElementList.onServiceSipBinded(service);
321 mHistorySectionFragment.onServiceSipBinded(service);
322 mDialingFragment.onServiceSipBinded(service);
323 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400324
alision9f7a6ec2013-05-24 16:26:26 -0400325 }
alision5f899632013-04-22 17:26:56 -0400326
alision9f7a6ec2013-05-24 16:26:26 -0400327 @Override
328 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400329
alision9f7a6ec2013-05-24 16:26:26 -0400330 mBound = false;
331 Log.d(TAG, "Service disconnected service=" + service);
332 }
333 };
alision5f899632013-04-22 17:26:56 -0400334
alision9f7a6ec2013-05-24 16:26:26 -0400335 @Override
336 public boolean onOptionsItemSelected(MenuItem item) {
337 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400338
alision9f7a6ec2013-05-24 16:26:26 -0400339 if (mDrawerToggle.onOptionsItemSelected(item)) {
340 return true;
341 }
alision5f899632013-04-22 17:26:56 -0400342
alision9f7a6ec2013-05-24 16:26:26 -0400343 return super.onOptionsItemSelected(item);
344 }
alisionf76de3b2013-04-16 15:35:22 -0400345
alision9f7a6ec2013-05-24 16:26:26 -0400346 @Override
347 public void onActivityResult(int requestCode, int resultCode, Intent data) {
348 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400349
350 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400351 case REQUEST_CODE_PREFERENCES:
352 mCallElementList.onServiceSipBinded(service);
353 break;
354 case REQUEST_CODE_CALL:
alision84813a12013-05-27 17:40:39 -0400355
alision9f7a6ec2013-05-24 16:26:26 -0400356 break;
357 }
alisionf76de3b2013-04-16 15:35:22 -0400358
alision9f7a6ec2013-05-24 16:26:26 -0400359 }
alisionf76de3b2013-04-16 15:35:22 -0400360
alision9f7a6ec2013-05-24 16:26:26 -0400361 // @Override
362 // public boolean onCreateOptionsMenu(Menu menu) {
363 // getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
364 // return true;
365 // }
alisionf76de3b2013-04-16 15:35:22 -0400366
alision9f7a6ec2013-05-24 16:26:26 -0400367 @Override
368 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
369 }
alisionf76de3b2013-04-16 15:35:22 -0400370
alision9f7a6ec2013-05-24 16:26:26 -0400371 @Override
372 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
373 // When the given tab is selected, switch to the corresponding page in the ViewPager.
alision0b553832013-05-30 09:31:06 -0400374 mViewPager.setCurrentItem(tab.getPosition());
alision9f7a6ec2013-05-24 16:26:26 -0400375 }
alisionf76de3b2013-04-16 15:35:22 -0400376
alision9f7a6ec2013-05-24 16:26:26 -0400377 @Override
378 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
379 // Log.d(TAG, "onTabReselected");
380 }
alisionf76de3b2013-04-16 15:35:22 -0400381
alision9f7a6ec2013-05-24 16:26:26 -0400382 @Override
383 public void onCallSelected(SipCall c) {
alision84813a12013-05-27 17:40:39 -0400384 // launchCallActivity(c.mCallInfo);
alisionf76de3b2013-04-16 15:35:22 -0400385
alision9f7a6ec2013-05-24 16:26:26 -0400386 }
alisionf76de3b2013-04-16 15:35:22 -0400387
alision9f7a6ec2013-05-24 16:26:26 -0400388 @Override
389 public ISipService getService() {
390 return service;
391 }
alisionf76de3b2013-04-16 15:35:22 -0400392
alision84813a12013-05-27 17:40:39 -0400393 /**
394 * Interface implemented to handle incoming events
395 */
alision9f7a6ec2013-05-24 16:26:26 -0400396 @Override
alision84813a12013-05-27 17:40:39 -0400397 public void incomingCall(Intent call) {
398 Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show();
alisionfde875f2013-05-28 17:01:54 -0400399 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400400
alisionfde875f2013-05-28 17:01:54 -0400401 mCallElementList.addCall(infos);
402
alision84813a12013-05-27 17:40:39 -0400403 launchCallActivity(infos, CallManagerCallBack.INCOMING_CALL);
404
405 }
406
407 @Override
408 public void callStateChanged(Intent callState) {
409 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
410 String cID = b.getString("CallID");
411 String state = b.getString("State");
412 Log.i(TAG, "callStateChanged" + cID + " " + state);
413 mCallElementList.updateCall(cID, state);
414
415 }
416
417 @Override
418 public void incomingText(Intent msg) {
419 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
420 b.getString("CallID");
421 String from = b.getString("From");
422 String mess = b.getString("Msg");
423 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
424 }
425
426 @Override
427 public void onContactSelected(CallContact c) {
alisionfde875f2013-05-28 17:01:54 -0400428
429 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
alision84813a12013-05-27 17:40:39 -0400430 try {
alision0b553832013-05-30 09:31:06 -0400431 callBuilder.startCallCreation().setAccountID(service.getAccountList().get(0).toString()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
alisionfde875f2013-05-28 17:01:54 -0400432 } catch (RemoteException e1) {
alisiond45da712013-05-30 09:18:49 -0400433 Log.e(TAG, e1.toString());
alisionfde875f2013-05-28 17:01:54 -0400434 }
435 callBuilder.addContact(c);
436
437 try {
438 launchCallActivity(callBuilder.build(), "call");
439 } catch (Exception e) {
alision84813a12013-05-27 17:40:39 -0400440 Log.e(TAG, e.toString());
441 }
alision84813a12013-05-27 17:40:39 -0400442
443 }
444
445 @Override
446 public void onCallDialed(String accountID, String to) {
alision84813a12013-05-27 17:40:39 -0400447
alisionfde875f2013-05-28 17:01:54 -0400448 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
449 callBuilder.startCallCreation().setAccountID(accountID).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
450 callBuilder.addContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400451
alisionfde875f2013-05-28 17:01:54 -0400452 try {
453 launchCallActivity(callBuilder.build(), "call");
454 } catch (Exception e) {
455 Log.e(TAG, e.toString());
456 }
alision84813a12013-05-27 17:40:39 -0400457
alision9f7a6ec2013-05-24 16:26:26 -0400458 }
alision371b77e2013-04-23 14:51:26 -0400459
alisiond45da712013-05-30 09:18:49 -0400460 @Override
461 public void onContactDragged() {
462
463 mDrawer.close();
464 getActionBar().setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
465
466 }
467
468 private HashMap<String, TabInfo> mapTabInfo = new HashMap<String, SFLPhoneHomeActivity.TabInfo>();
469
470 /**
471 * A simple factory that returns dummy views to the Tabhost
472 *
473 * @author mwho
474 */
475 class TabFactory implements TabContentFactory {
476
477 private final Context mContext;
478
479 /**
480 * @param context
481 */
482 public TabFactory(Context context) {
483 mContext = context;
484 }
485
486 /**
487 * (non-Javadoc)
488 *
489 * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)
490 */
491 public View createTabContent(String tag) {
492 View v = new View(mContext);
493 v.setMinimumWidth(0);
494 v.setMinimumHeight(0);
495 return v;
496 }
497
498 }
499
500 /**
501 *
502 * @author mwho Maintains extrinsic info of a tab's construct
503 */
504 private class TabInfo {
505 private String tag;
506 private Class<?> clss;
507 private Bundle args;
508 private Fragment fragment;
509
510 TabInfo(String tag, Class<?> clazz, Bundle args) {
511 this.tag = tag;
512 this.clss = clazz;
513 this.args = args;
514 }
515
516 }
517
518 private static void AddTab(SFLPhoneHomeActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
519 // Attach a Tab view factory to the spec
520 tabSpec.setContent(activity.new TabFactory(activity));
521 tabHost.addTab(tabSpec);
522 }
523
alisionf76de3b2013-04-16 15:35:22 -0400524}