blob: 64abea21b502947379aac3f77c5ebd7c3421810e [file] [log] [blame]
alisionf76de3b2013-04-16 15:35:22 -04001/*
alision2ec64f92013-06-17 17:28:58 -04002 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
alisionf76de3b2013-04-16 15:35:22 -04003 *
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
alision806e18e2013-06-21 15:30:17 -040034import java.util.ArrayList;
alisiond45da712013-05-30 09:18:49 -040035import java.util.HashMap;
alisionbd45a822013-06-06 17:35:35 -040036import java.util.Timer;
37import java.util.TimerTask;
alision84813a12013-05-27 17:40:39 -040038
alisionf76de3b2013-04-16 15:35:22 -040039import android.app.Activity;
alisionf76de3b2013-04-16 15:35:22 -040040import 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;
alision55c36cb2013-06-14 14:57:38 -040045import android.database.Cursor;
alisionf76de3b2013-04-16 15:35:22 -040046import android.os.Bundle;
47import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040048import android.os.RemoteException;
alision55c36cb2013-06-14 14:57:38 -040049import android.provider.ContactsContract.CommonDataKinds.Phone;
50import android.provider.ContactsContract.CommonDataKinds.SipAddress;
alision9f7a6ec2013-05-24 16:26:26 -040051import android.support.v4.app.ActionBarDrawerToggle;
52import android.support.v4.view.GravityCompat;
alisionf76de3b2013-04-16 15:35:22 -040053import android.support.v4.view.ViewPager;
alision9f7a6ec2013-05-24 16:26:26 -040054import android.support.v4.widget.DrawerLayout;
alisionf76de3b2013-04-16 15:35:22 -040055import android.util.Log;
alision9f7a6ec2013-05-24 16:26:26 -040056import android.view.MenuItem;
57import android.view.View;
alision7297bdb2013-05-21 11:56:55 -040058import android.widget.RelativeLayout;
alisiond45da712013-05-30 09:18:49 -040059import android.widget.TabHost;
alision3c5c2a92013-05-30 09:50:47 -040060import android.widget.TabHost.OnTabChangeListener;
alisiond45da712013-05-30 09:18:49 -040061import android.widget.TabHost.TabContentFactory;
alision04a00182013-05-10 17:05:29 -040062import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040063
64import com.savoirfairelinux.sflphone.R;
alision9f7a6ec2013-05-24 16:26:26 -040065import com.savoirfairelinux.sflphone.adapters.SectionsPagerAdapter;
alisionf76de3b2013-04-16 15:35:22 -040066import com.savoirfairelinux.sflphone.fragments.ContactListFragment;
alision7297bdb2013-05-21 11:56:55 -040067import com.savoirfairelinux.sflphone.fragments.DialingFragment;
alisiond9e29442013-04-17 16:10:18 -040068import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
alision55c36cb2013-06-14 14:57:38 -040069import com.savoirfairelinux.sflphone.fragments.HomeFragment;
alision9f7a6ec2013-05-24 16:26:26 -040070import com.savoirfairelinux.sflphone.fragments.MenuFragment;
alision84813a12013-05-27 17:40:39 -040071import com.savoirfairelinux.sflphone.interfaces.CallInterface;
alision2ec64f92013-06-17 17:28:58 -040072import com.savoirfairelinux.sflphone.loaders.LoaderConstants;
alision84813a12013-05-27 17:40:39 -040073import com.savoirfairelinux.sflphone.model.CallContact;
alisionf76de3b2013-04-16 15:35:22 -040074import com.savoirfairelinux.sflphone.model.SipCall;
alisioncc7bb422013-06-06 15:31:39 -040075import com.savoirfairelinux.sflphone.receivers.CallReceiver;
alision84813a12013-05-27 17:40:39 -040076import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
alisionf76de3b2013-04-16 15:35:22 -040077import com.savoirfairelinux.sflphone.service.ISipService;
78import com.savoirfairelinux.sflphone.service.SipService;
alision7297bdb2013-05-21 11:56:55 -040079import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer;
alisionf76de3b2013-04-16 15:35:22 -040080
alision907bde72013-06-20 14:40:37 -040081public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Callbacks, ContactListFragment.Callbacks, HomeFragment.Callbacks,
82 HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks {
alisionfde875f2013-05-28 17:01:54 -040083
alision9f7a6ec2013-05-24 16:26:26 -040084 SectionsPagerAdapter mSectionsPagerAdapter = null;
alision84813a12013-05-27 17:40:39 -040085 static final String TAG = "SFLPhoneHomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040086
alision2cb99562013-05-30 17:02:20 -040087 /**
88 * Fragments used
89 */
alision9f7a6ec2013-05-24 16:26:26 -040090 private ContactListFragment mContactsFragment = null;
alision58356b72013-06-03 17:13:36 -040091 // private DialingFragment mDialingFragment = null;
92 // private CallElementListFragment mCallElementList = null;
93 // private HistoryFragment mHistorySectionFragment = null;
alision907bde72013-06-20 14:40:37 -040094 private MenuFragment fMenu;
alisionf76de3b2013-04-16 15:35:22 -040095
alision9f7a6ec2013-05-24 16:26:26 -040096 private boolean mBound = false;
97 private ISipService service;
alisionf76de3b2013-04-16 15:35:22 -040098
alision9f7a6ec2013-05-24 16:26:26 -040099 private CharSequence mDrawerTitle;
100 private CharSequence mTitle;
alisionf76de3b2013-04-16 15:35:22 -0400101
alision907bde72013-06-20 14:40:37 -0400102 // AccountSelectionAdapter mAdapter;
103 // private Spinner spinnerAccounts;
alision58356b72013-06-03 17:13:36 -0400104
alision2cb99562013-05-30 17:02:20 -0400105 public static final int REQUEST_CODE_PREFERENCES = 1;
alision9f7a6ec2013-05-24 16:26:26 -0400106 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -0400107
alision0b553832013-05-30 09:31:06 -0400108 RelativeLayout mSliderButton;
alision9f7a6ec2013-05-24 16:26:26 -0400109 CustomSlidingDrawer mDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400110 private DrawerLayout mDrawerLayout;
alision9f7a6ec2013-05-24 16:26:26 -0400111 private ActionBarDrawerToggle mDrawerToggle;
112 /**
113 * The {@link ViewPager} that will host the section contents.
114 */
115 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400116
alision58356b72013-06-03 17:13:36 -0400117 CallReceiver callReceiver;
alision84813a12013-05-27 17:40:39 -0400118
alision3c5c2a92013-05-30 09:50:47 -0400119 private TabHost mTabHost;
alisionf76de3b2013-04-16 15:35:22 -0400120
alision9f7a6ec2013-05-24 16:26:26 -0400121 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
122
123 /* called before activity is killed, e.g. rotation */
124 @Override
125 protected void onSaveInstanceState(Bundle bundle) {
126 super.onSaveInstanceState(bundle);
127 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
128 try {
129 getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i));
130 } catch (IllegalStateException e) {
131 Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i));
132 }
133 }
134
135 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
136 Log.w(TAG, "onSaveInstanceState()");
137 }
138
139 @Override
140 public void onCreate(Bundle savedInstanceState) {
141 super.onCreate(savedInstanceState);
142
alision58356b72013-06-03 17:13:36 -0400143 callReceiver = new CallReceiver(this);
alision907bde72013-06-20 14:40:37 -0400144
alision2cb99562013-05-30 17:02:20 -0400145 // String libraryPath = getApplicationInfo().dataDir + "/lib";
146 // Log.i(TAG, libraryPath);
alision9f7a6ec2013-05-24 16:26:26 -0400147
alision58356b72013-06-03 17:13:36 -0400148 setContentView(R.layout.activity_sflphone_home);
149
alision9f7a6ec2013-05-24 16:26:26 -0400150 // Bind to LocalService
151 if (!mBound) {
152 Log.i(TAG, "onStart: Binding service...");
153 Intent intent = new Intent(this, SipService.class);
154 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
155 }
156
alision9f7a6ec2013-05-24 16:26:26 -0400157 if (mContactsFragment == null) {
158 mContactsFragment = new ContactListFragment();
159 Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment);
160 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
161 }
alision2ec64f92013-06-17 17:28:58 -0400162
alision9f7a6ec2013-05-24 16:26:26 -0400163 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400164
alision84813a12013-05-27 17:40:39 -0400165 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400166
167 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400168
alision9f7a6ec2013-05-24 16:26:26 -0400169 // Set up the ViewPager with the sections adapter.
170 mViewPager = (ViewPager) findViewById(R.id.pager);
alision55c36cb2013-06-14 14:57:38 -0400171 mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f));
alisionf76de3b2013-04-16 15:35:22 -0400172
alision9f7a6ec2013-05-24 16:26:26 -0400173 mTitle = mDrawerTitle = getTitle();
174 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400175
alision0b553832013-05-30 09:31:06 -0400176 // set a custom shadow that overlays the main content when the drawer opens
alision9f7a6ec2013-05-24 16:26:26 -0400177 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400178
alision9f7a6ec2013-05-24 16:26:26 -0400179 getActionBar().setDisplayHomeAsUpEnabled(true);
180 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400181
alision9f7a6ec2013-05-24 16:26:26 -0400182 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
183 mDrawerLayout, /* DrawerLayout object */
184 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
185 R.string.drawer_open, /* "open drawer" description for accessibility */
186 R.string.drawer_close /* "close drawer" description for accessibility */
187 ) {
alision0b553832013-05-30 09:31:06 -0400188 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400189 public void onDrawerClosed(View view) {
190 getActionBar().setTitle(mTitle);
191 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
192 }
alisionf76de3b2013-04-16 15:35:22 -0400193
alision0b553832013-05-30 09:31:06 -0400194 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400195 public void onDrawerOpened(View drawerView) {
196 getActionBar().setTitle(mDrawerTitle);
197 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
198 }
199 };
alisionf76de3b2013-04-16 15:35:22 -0400200
alision3c5c2a92013-05-30 09:50:47 -0400201 mTabHost = (TabHost) findViewById(android.R.id.tabhost);
alision9f7a6ec2013-05-24 16:26:26 -0400202 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400203
alision9f7a6ec2013-05-24 16:26:26 -0400204 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
205 @Override
206 public void onPageSelected(int position) {
alision3c5c2a92013-05-30 09:50:47 -0400207 mTabHost.setCurrentTab(position);
alision9f7a6ec2013-05-24 16:26:26 -0400208 }
209 });
alisionf76de3b2013-04-16 15:35:22 -0400210
alision9f7a6ec2013-05-24 16:26:26 -0400211 }
alisionf76de3b2013-04-16 15:35:22 -0400212
alision3c5c2a92013-05-30 09:50:47 -0400213 private void initialiseTabHost(Bundle args) {
214
alision3c5c2a92013-05-30 09:50:47 -0400215 mTabHost.setup();
216 TabInfo tabInfo = null;
alision2cb99562013-05-30 17:02:20 -0400217 SFLPhoneHomeActivity
218 .AddTab(this,
219 this.mTabHost,
220 this.mTabHost.newTabSpec("Tab1").setIndicator(mSectionsPagerAdapter.getPageTitle(0),
221 getResources().getDrawable(mSectionsPagerAdapter.getIconOf(0))), (tabInfo = new TabInfo("Tab1",
222 DialingFragment.class, args)));
alision3c5c2a92013-05-30 09:50:47 -0400223 this.mapTabInfo.put(tabInfo.tag, tabInfo);
alision2cb99562013-05-30 17:02:20 -0400224 SFLPhoneHomeActivity.AddTab(
225 this,
226 this.mTabHost,
227 this.mTabHost.newTabSpec("Tab2").setIndicator(mSectionsPagerAdapter.getPageTitle(1),
alision907bde72013-06-20 14:40:37 -0400228 getResources().getDrawable(mSectionsPagerAdapter.getIconOf(1))), (tabInfo = new TabInfo("Tab2", HomeFragment.class, args)));
alision3c5c2a92013-05-30 09:50:47 -0400229 this.mapTabInfo.put(tabInfo.tag, tabInfo);
alision2cb99562013-05-30 17:02:20 -0400230 SFLPhoneHomeActivity
231 .AddTab(this,
232 this.mTabHost,
233 this.mTabHost.newTabSpec("Tab3").setIndicator(mSectionsPagerAdapter.getPageTitle(2),
234 getResources().getDrawable(mSectionsPagerAdapter.getIconOf(2))), (tabInfo = new TabInfo("Tab3",
235 HistoryFragment.class, args)));
alision3c5c2a92013-05-30 09:50:47 -0400236 this.mapTabInfo.put(tabInfo.tag, tabInfo);
237
238 mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
239
240 @Override
241 public void onTabChanged(String tabId) {
242 int pos = mTabHost.getCurrentTab();
243 mViewPager.setCurrentItem(pos);
244
245 }
246 });
247 }
248
alision9f7a6ec2013-05-24 16:26:26 -0400249 @Override
250 protected void onStart() {
251 Log.i(TAG, "onStart");
252 super.onStart();
253 }
alisionf76de3b2013-04-16 15:35:22 -0400254
alision9f7a6ec2013-05-24 16:26:26 -0400255 /* user gets back to the activity, e.g. through task manager */
256 @Override
257 protected void onRestart() {
258 super.onRestart();
259 }
alisionf76de3b2013-04-16 15:35:22 -0400260
alision9f7a6ec2013-05-24 16:26:26 -0400261 /* activity gets back to the foreground and user input */
262 @Override
263 protected void onResume() {
alision58356b72013-06-03 17:13:36 -0400264 super.onResume();
alision84813a12013-05-27 17:40:39 -0400265 IntentFilter intentFilter = new IntentFilter();
266 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
267 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
268 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
alision58356b72013-06-03 17:13:36 -0400269 registerReceiver(callReceiver, intentFilter);
alision907bde72013-06-20 14:40:37 -0400270
alision9f7a6ec2013-05-24 16:26:26 -0400271 }
alision907bde72013-06-20 14:40:37 -0400272
alisionbd45a822013-06-06 17:35:35 -0400273 private boolean isClosing = false;
274 private Timer t = new Timer();
alision907bde72013-06-20 14:40:37 -0400275
alisionbd45a822013-06-06 17:35:35 -0400276 @Override
277 public void onBackPressed() {
alision907bde72013-06-20 14:40:37 -0400278
279 if (getActionBar().getCustomView() != null) {
alision2ec64f92013-06-17 17:28:58 -0400280 getActionBar().setDisplayShowCustomEnabled(false);
281 getActionBar().setCustomView(null);
282 // Display all the contacts again
283 getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, mContactsFragment);
284 return;
285 }
alision907bde72013-06-20 14:40:37 -0400286
alisionbd45a822013-06-06 17:35:35 -0400287 if (mDrawer.isOpened()) {
alision55c36cb2013-06-14 14:57:38 -0400288 mDrawer.animateClose();
alisionbd45a822013-06-06 17:35:35 -0400289 return;
290 }
alision2ec64f92013-06-17 17:28:58 -0400291
alisionbd45a822013-06-06 17:35:35 -0400292 if (isClosing) {
293 super.onBackPressed();
294 t.cancel();
295 finish();
296 } else {
297
298 t.schedule(new TimerTask() {
299 @Override
300 public void run() {
301 isClosing = false;
302 }
303 }, 3000);
304 Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show();
305 isClosing = true;
306 }
307 }
alisione2a38e12013-04-25 14:20:20 -0400308
alision9f7a6ec2013-05-24 16:26:26 -0400309 /* activity no more in foreground */
310 @Override
311 protected void onPause() {
312 super.onPause();
alision58356b72013-06-03 17:13:36 -0400313 unregisterReceiver(callReceiver);
alision55c36cb2013-06-14 14:57:38 -0400314 try {
315 service.createNotification();
316
317 } catch (RemoteException e) {
318 Log.e(TAG, e.toString());
319 }
alision2cb99562013-05-30 17:02:20 -0400320
alision9f7a6ec2013-05-24 16:26:26 -0400321 }
alisionf76de3b2013-04-16 15:35:22 -0400322
alision9f7a6ec2013-05-24 16:26:26 -0400323 /* activity is no longer visible */
324 @Override
325 protected void onStop() {
326 super.onStop();
alision2cb99562013-05-30 17:02:20 -0400327
alision9f7a6ec2013-05-24 16:26:26 -0400328 }
alisionf76de3b2013-04-16 15:35:22 -0400329
alision9f7a6ec2013-05-24 16:26:26 -0400330 /* activity finishes itself or is being killed by the system */
331 @Override
332 protected void onDestroy() {
333 /* stop the service, if no other bound user, no need to check if it is running */
334 if (mBound) {
335 Log.i(TAG, "onDestroy: Unbinding service...");
alision907bde72013-06-20 14:40:37 -0400336
alision9f7a6ec2013-05-24 16:26:26 -0400337 unbindService(mConnection);
338 mBound = false;
alision2cb99562013-05-30 17:02:20 -0400339
alision9f7a6ec2013-05-24 16:26:26 -0400340 }
alision371b77e2013-04-23 14:51:26 -0400341
alision9f7a6ec2013-05-24 16:26:26 -0400342 super.onDestroy();
343 }
alision73424b62013-04-26 11:49:18 -0400344
alision55c36cb2013-06-14 14:57:38 -0400345 public void launchCallActivity(SipCall infos) {
alision9f7a6ec2013-05-24 16:26:26 -0400346 Log.i(TAG, "Launch Call Activity");
347 Bundle bundle = new Bundle();
alision806e18e2013-06-21 15:30:17 -0400348 ArrayList<SipCall> tmp = new ArrayList<SipCall>();
349 tmp.add(infos);
350 bundle.putParcelableArrayList("CallsInfo", tmp);
alision9f7a6ec2013-05-24 16:26:26 -0400351 Intent intent = new Intent().setClass(this, CallActivity.class);
alision55c36cb2013-06-14 14:57:38 -0400352
alision9f7a6ec2013-05-24 16:26:26 -0400353 intent.putExtras(bundle);
354 startActivityForResult(intent, REQUEST_CODE_CALL);
355 }
alisionf76de3b2013-04-16 15:35:22 -0400356
alision9f7a6ec2013-05-24 16:26:26 -0400357 /** Defines callbacks for service binding, passed to bindService() */
358 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400359
alision9f7a6ec2013-05-24 16:26:26 -0400360 @Override
361 public void onServiceConnected(ComponentName className, IBinder binder) {
362 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400363
alision2cb99562013-05-30 17:02:20 -0400364 try {
alision58356b72013-06-03 17:13:36 -0400365
alision907bde72013-06-20 14:40:37 -0400366 fMenu = new MenuFragment();
367 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
alision58356b72013-06-03 17:13:36 -0400368 mSectionsPagerAdapter = new SectionsPagerAdapter(SFLPhoneHomeActivity.this, getFragmentManager());
369 initialiseTabHost(null);
370 mViewPager.setAdapter(mSectionsPagerAdapter);
371 mTabHost.setCurrentTab(1);
alision2cb99562013-05-30 17:02:20 -0400372 service.destroyNotification();
alision58356b72013-06-03 17:13:36 -0400373 // mAdapter = new AccountSelectionAdapter(SFLPhoneHomeActivity.this, service, new ArrayList<Account>());
374 // spinnerAccounts.setAdapter(mAdapter);
alision2cb99562013-05-30 17:02:20 -0400375 } catch (RemoteException e) {
376 Log.e(TAG, e.toString());
377 }
alision9f7a6ec2013-05-24 16:26:26 -0400378 mBound = true;
alision9f7a6ec2013-05-24 16:26:26 -0400379 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400380
alision9f7a6ec2013-05-24 16:26:26 -0400381 }
alision5f899632013-04-22 17:26:56 -0400382
alision9f7a6ec2013-05-24 16:26:26 -0400383 @Override
384 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400385
alision9f7a6ec2013-05-24 16:26:26 -0400386 mBound = false;
387 Log.d(TAG, "Service disconnected service=" + service);
388 }
389 };
alision5f899632013-04-22 17:26:56 -0400390
alision9f7a6ec2013-05-24 16:26:26 -0400391 @Override
392 public boolean onOptionsItemSelected(MenuItem item) {
393 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400394
alision9f7a6ec2013-05-24 16:26:26 -0400395 if (mDrawerToggle.onOptionsItemSelected(item)) {
396 return true;
397 }
alision5f899632013-04-22 17:26:56 -0400398
alision9f7a6ec2013-05-24 16:26:26 -0400399 return super.onOptionsItemSelected(item);
400 }
alisionf76de3b2013-04-16 15:35:22 -0400401
alision9f7a6ec2013-05-24 16:26:26 -0400402 @Override
403 public void onActivityResult(int requestCode, int resultCode, Intent data) {
404 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400405
406 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400407 case REQUEST_CODE_PREFERENCES:
alision907bde72013-06-20 14:40:37 -0400408 Log.w(TAG, "In Activity");
409 fMenu.updateAllAccounts();
alision9f7a6ec2013-05-24 16:26:26 -0400410 break;
411 case REQUEST_CODE_CALL:
alision2cb99562013-05-30 17:02:20 -0400412 Log.w(TAG, "Result out of CallActivity");
alision1005ba12013-06-19 13:52:44 -0400413
alision9f7a6ec2013-05-24 16:26:26 -0400414 break;
415 }
alisionf76de3b2013-04-16 15:35:22 -0400416
alision9f7a6ec2013-05-24 16:26:26 -0400417 }
alisionf76de3b2013-04-16 15:35:22 -0400418
alision9f7a6ec2013-05-24 16:26:26 -0400419 @Override
420 public void onCallSelected(SipCall c) {
alision55c36cb2013-06-14 14:57:38 -0400421 launchCallActivity(c);
alisionf76de3b2013-04-16 15:35:22 -0400422
alision9f7a6ec2013-05-24 16:26:26 -0400423 }
alisionf76de3b2013-04-16 15:35:22 -0400424
alision9f7a6ec2013-05-24 16:26:26 -0400425 @Override
426 public ISipService getService() {
427 return service;
428 }
alisionf76de3b2013-04-16 15:35:22 -0400429
alision84813a12013-05-27 17:40:39 -0400430 /**
431 * Interface implemented to handle incoming events
432 */
alision9f7a6ec2013-05-24 16:26:26 -0400433 @Override
alision84813a12013-05-27 17:40:39 -0400434 public void incomingCall(Intent call) {
435 Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show();
alisionfde875f2013-05-28 17:01:54 -0400436 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400437
alision58356b72013-06-03 17:13:36 -0400438 // mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400439
alision55c36cb2013-06-14 14:57:38 -0400440 launchCallActivity(infos);
alision84813a12013-05-27 17:40:39 -0400441
442 }
443
444 @Override
445 public void callStateChanged(Intent callState) {
446 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
447 String cID = b.getString("CallID");
448 String state = b.getString("State");
449 Log.i(TAG, "callStateChanged" + cID + " " + state);
alision58356b72013-06-03 17:13:36 -0400450 // mCallElementList.updateCall(cID, state);
alision84813a12013-05-27 17:40:39 -0400451
452 }
453
454 @Override
455 public void incomingText(Intent msg) {
456 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
457 b.getString("CallID");
458 String from = b.getString("From");
459 String mess = b.getString("Msg");
460 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
461 }
462
463 @Override
alision55c36cb2013-06-14 14:57:38 -0400464 public void onContactSelected(final CallContact c) {
alisionfde875f2013-05-28 17:01:54 -0400465
alision55c36cb2013-06-14 14:57:38 -0400466 Thread launcher = new Thread(new Runnable() {
alision907bde72013-06-20 14:40:37 -0400467
alision55c36cb2013-06-14 14:57:38 -0400468 final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
469 final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
alision907bde72013-06-20 14:40:37 -0400470
alision55c36cb2013-06-14 14:57:38 -0400471 @Override
472 public void run() {
473 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
474 try {
alision907bde72013-06-20 14:40:37 -0400475 callBuilder.startCallCreation().setAccountID(service.getAccountList().get(1).toString())
476 .setCallType(SipCall.state.CALL_TYPE_OUTGOING);
477 Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(),
478 null, null);
alision55c36cb2013-06-14 14:57:38 -0400479
alision907bde72013-06-20 14:40:37 -0400480 while (cPhones.moveToNext()) {
481 c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE)));
482 }
483 cPhones.close();
484
485 Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null,
486 null);
487
488 while (cSip.moveToNext()) {
489 c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE)));
490 }
491 cSip.close();
492 callBuilder.setContact(c);
alision55c36cb2013-06-14 14:57:38 -0400493 launchCallActivity(callBuilder.build());
494 } catch (RemoteException e1) {
495 Log.e(TAG, e1.toString());
496 } catch (Exception e) {
497 Log.e(TAG, e.toString());
498 }
alision907bde72013-06-20 14:40:37 -0400499
alision55c36cb2013-06-14 14:57:38 -0400500 }
501 });
502 launcher.start();
503 mDrawer.close();
alision84813a12013-05-27 17:40:39 -0400504
505 }
506
507 @Override
alision907bde72013-06-20 14:40:37 -0400508 public void onCallDialed(String to) {
alision84813a12013-05-27 17:40:39 -0400509
alisionfde875f2013-05-28 17:01:54 -0400510 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
alision907bde72013-06-20 14:40:37 -0400511 callBuilder.startCallCreation().setAccountID(fMenu.getSelectedAccount().getAccountID()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
512 callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400513
alisionfde875f2013-05-28 17:01:54 -0400514 try {
alision55c36cb2013-06-14 14:57:38 -0400515 launchCallActivity(callBuilder.build());
alisionfde875f2013-05-28 17:01:54 -0400516 } catch (Exception e) {
517 Log.e(TAG, e.toString());
518 }
alision84813a12013-05-27 17:40:39 -0400519
alision9f7a6ec2013-05-24 16:26:26 -0400520 }
alision371b77e2013-04-23 14:51:26 -0400521
alisiond45da712013-05-30 09:18:49 -0400522 @Override
523 public void onContactDragged() {
524
525 mDrawer.close();
alision2cb99562013-05-30 17:02:20 -0400526 mTabHost.setCurrentTab(1);
alisiond45da712013-05-30 09:18:49 -0400527
528 }
529
530 private HashMap<String, TabInfo> mapTabInfo = new HashMap<String, SFLPhoneHomeActivity.TabInfo>();
531
532 /**
533 * A simple factory that returns dummy views to the Tabhost
534 *
535 * @author mwho
536 */
537 class TabFactory implements TabContentFactory {
538
539 private final Context mContext;
540
541 /**
542 * @param context
543 */
544 public TabFactory(Context context) {
545 mContext = context;
546 }
547
548 /**
549 * (non-Javadoc)
550 *
551 * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)
552 */
553 public View createTabContent(String tag) {
554 View v = new View(mContext);
555 v.setMinimumWidth(0);
556 v.setMinimumHeight(0);
557 return v;
558 }
559
560 }
561
562 /**
563 *
564 * @author mwho Maintains extrinsic info of a tab's construct
565 */
566 private class TabInfo {
567 private String tag;
alisiond45da712013-05-30 09:18:49 -0400568
569 TabInfo(String tag, Class<?> clazz, Bundle args) {
570 this.tag = tag;
alisiond45da712013-05-30 09:18:49 -0400571 }
572
573 }
574
575 private static void AddTab(SFLPhoneHomeActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
576 // Attach a Tab view factory to the spec
577 tabSpec.setContent(activity.new TabFactory(activity));
578 tabHost.addTab(tabSpec);
579 }
580
alision58356b72013-06-03 17:13:36 -0400581 @Override
582 public void openDrawer() {
alision55c36cb2013-06-14 14:57:38 -0400583 mDrawer.animateOpen();
alision58356b72013-06-03 17:13:36 -0400584 }
585
alision806e18e2013-06-21 15:30:17 -0400586 @Override
587 public void confCreated(Intent intent) {
588 // TODO Auto-generated method stub
589
590 }
591
592 @Override
593 public void confRemoved(Intent intent) {
594 // TODO Auto-generated method stub
595
596 }
597
598 @Override
599 public void confChanged(Intent intent) {
600 // TODO Auto-generated method stub
601
602 }
603
alisionf76de3b2013-04-16 15:35:22 -0400604}