blob: 098b7232d3ec38ed140e7c0b35fc625114df1d7a [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
alisiond45da712013-05-30 09:18:49 -040034import java.util.HashMap;
alisionbd45a822013-06-06 17:35:35 -040035import java.util.Timer;
36import java.util.TimerTask;
alision84813a12013-05-27 17:40:39 -040037
alisionf76de3b2013-04-16 15:35:22 -040038import android.app.Activity;
alisionf76de3b2013-04-16 15:35:22 -040039import android.content.ComponentName;
40import android.content.Context;
41import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040042import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040043import android.content.ServiceConnection;
alisionf57d8a62013-07-02 09:37:12 -040044import android.content.res.Configuration;
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;
alisiondf1dac92013-06-27 17:35:53 -040074import com.savoirfairelinux.sflphone.model.Conference;
alisionf76de3b2013-04-16 15:35:22 -040075import com.savoirfairelinux.sflphone.model.SipCall;
alisioncc7bb422013-06-06 15:31:39 -040076import com.savoirfairelinux.sflphone.receivers.CallReceiver;
alision84813a12013-05-27 17:40:39 -040077import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
alisionf76de3b2013-04-16 15:35:22 -040078import com.savoirfairelinux.sflphone.service.ISipService;
79import com.savoirfairelinux.sflphone.service.SipService;
alision7297bdb2013-05-21 11:56:55 -040080import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer;
alisionf76de3b2013-04-16 15:35:22 -040081
alision907bde72013-06-20 14:40:37 -040082public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Callbacks, ContactListFragment.Callbacks, HomeFragment.Callbacks,
83 HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks {
alisionfde875f2013-05-28 17:01:54 -040084
alision9f7a6ec2013-05-24 16:26:26 -040085 SectionsPagerAdapter mSectionsPagerAdapter = null;
alision84813a12013-05-27 17:40:39 -040086 static final String TAG = "SFLPhoneHomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040087
alision2cb99562013-05-30 17:02:20 -040088 /**
89 * Fragments used
90 */
alision9f7a6ec2013-05-24 16:26:26 -040091 private ContactListFragment mContactsFragment = null;
alision58356b72013-06-03 17:13:36 -040092 // private DialingFragment mDialingFragment = null;
93 // private CallElementListFragment mCallElementList = null;
94 // private HistoryFragment mHistorySectionFragment = null;
alision907bde72013-06-20 14:40:37 -040095 private MenuFragment fMenu;
alisionf76de3b2013-04-16 15:35:22 -040096
alision9f7a6ec2013-05-24 16:26:26 -040097 private boolean mBound = false;
98 private ISipService service;
alisionf76de3b2013-04-16 15:35:22 -040099
alision9f7a6ec2013-05-24 16:26:26 -0400100 private CharSequence mDrawerTitle;
101 private CharSequence mTitle;
alisionf76de3b2013-04-16 15:35:22 -0400102
alision907bde72013-06-20 14:40:37 -0400103 // AccountSelectionAdapter mAdapter;
104 // private Spinner spinnerAccounts;
alision58356b72013-06-03 17:13:36 -0400105
alision2cb99562013-05-30 17:02:20 -0400106 public static final int REQUEST_CODE_PREFERENCES = 1;
alision9f7a6ec2013-05-24 16:26:26 -0400107 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -0400108
alision0b553832013-05-30 09:31:06 -0400109 RelativeLayout mSliderButton;
alision9f7a6ec2013-05-24 16:26:26 -0400110 CustomSlidingDrawer mDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400111 private DrawerLayout mDrawerLayout;
alision9f7a6ec2013-05-24 16:26:26 -0400112 private ActionBarDrawerToggle mDrawerToggle;
113 /**
114 * The {@link ViewPager} that will host the section contents.
115 */
116 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400117
alision58356b72013-06-03 17:13:36 -0400118 CallReceiver callReceiver;
alision84813a12013-05-27 17:40:39 -0400119
alision3c5c2a92013-05-30 09:50:47 -0400120 private TabHost mTabHost;
alisionf76de3b2013-04-16 15:35:22 -0400121
alision9f7a6ec2013-05-24 16:26:26 -0400122 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
123
124 /* called before activity is killed, e.g. rotation */
125 @Override
126 protected void onSaveInstanceState(Bundle bundle) {
127 super.onSaveInstanceState(bundle);
128 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
129 try {
130 getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i));
131 } catch (IllegalStateException e) {
132 Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i));
133 }
134 }
135
136 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
137 Log.w(TAG, "onSaveInstanceState()");
138 }
139
140 @Override
141 public void onCreate(Bundle savedInstanceState) {
142 super.onCreate(savedInstanceState);
143
alision58356b72013-06-03 17:13:36 -0400144 callReceiver = new CallReceiver(this);
alision907bde72013-06-20 14:40:37 -0400145
alision2cb99562013-05-30 17:02:20 -0400146 // String libraryPath = getApplicationInfo().dataDir + "/lib";
147 // Log.i(TAG, libraryPath);
alision9f7a6ec2013-05-24 16:26:26 -0400148
alision58356b72013-06-03 17:13:36 -0400149 setContentView(R.layout.activity_sflphone_home);
150
alision9f7a6ec2013-05-24 16:26:26 -0400151 // Bind to LocalService
152 if (!mBound) {
153 Log.i(TAG, "onStart: Binding service...");
154 Intent intent = new Intent(this, SipService.class);
155 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
156 }
157
alision9f7a6ec2013-05-24 16:26:26 -0400158 if (mContactsFragment == null) {
159 mContactsFragment = new ContactListFragment();
160 Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment);
161 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
162 }
alision2ec64f92013-06-17 17:28:58 -0400163
alision9f7a6ec2013-05-24 16:26:26 -0400164 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400165
alision84813a12013-05-27 17:40:39 -0400166 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400167
168 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400169
alision9f7a6ec2013-05-24 16:26:26 -0400170 // Set up the ViewPager with the sections adapter.
171 mViewPager = (ViewPager) findViewById(R.id.pager);
alision55c36cb2013-06-14 14:57:38 -0400172 mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f));
alisionf76de3b2013-04-16 15:35:22 -0400173
alision9f7a6ec2013-05-24 16:26:26 -0400174 mTitle = mDrawerTitle = getTitle();
175 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400176
alision0b553832013-05-30 09:31:06 -0400177 // set a custom shadow that overlays the main content when the drawer opens
alision9f7a6ec2013-05-24 16:26:26 -0400178 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400179
alision9f7a6ec2013-05-24 16:26:26 -0400180 getActionBar().setDisplayHomeAsUpEnabled(true);
181 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400182
alision9f7a6ec2013-05-24 16:26:26 -0400183 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
184 mDrawerLayout, /* DrawerLayout object */
185 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
186 R.string.drawer_open, /* "open drawer" description for accessibility */
187 R.string.drawer_close /* "close drawer" description for accessibility */
188 ) {
alision0b553832013-05-30 09:31:06 -0400189 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400190 public void onDrawerClosed(View view) {
191 getActionBar().setTitle(mTitle);
192 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
193 }
alisionf76de3b2013-04-16 15:35:22 -0400194
alision0b553832013-05-30 09:31:06 -0400195 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400196 public void onDrawerOpened(View drawerView) {
197 getActionBar().setTitle(mDrawerTitle);
198 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
199 }
200 };
alisionf76de3b2013-04-16 15:35:22 -0400201
alision3c5c2a92013-05-30 09:50:47 -0400202 mTabHost = (TabHost) findViewById(android.R.id.tabhost);
alision9f7a6ec2013-05-24 16:26:26 -0400203 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400204
alision9f7a6ec2013-05-24 16:26:26 -0400205 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
206 @Override
207 public void onPageSelected(int position) {
alision3c5c2a92013-05-30 09:50:47 -0400208 mTabHost.setCurrentTab(position);
alision9f7a6ec2013-05-24 16:26:26 -0400209 }
210 });
alisionf76de3b2013-04-16 15:35:22 -0400211
alision9f7a6ec2013-05-24 16:26:26 -0400212 }
alisionf76de3b2013-04-16 15:35:22 -0400213
alision3c5c2a92013-05-30 09:50:47 -0400214 private void initialiseTabHost(Bundle args) {
215
alision3c5c2a92013-05-30 09:50:47 -0400216 mTabHost.setup();
217 TabInfo tabInfo = null;
alision2cb99562013-05-30 17:02:20 -0400218 SFLPhoneHomeActivity
219 .AddTab(this,
220 this.mTabHost,
221 this.mTabHost.newTabSpec("Tab1").setIndicator(mSectionsPagerAdapter.getPageTitle(0),
222 getResources().getDrawable(mSectionsPagerAdapter.getIconOf(0))), (tabInfo = new TabInfo("Tab1",
223 DialingFragment.class, args)));
alision3c5c2a92013-05-30 09:50:47 -0400224 this.mapTabInfo.put(tabInfo.tag, tabInfo);
alision2cb99562013-05-30 17:02:20 -0400225 SFLPhoneHomeActivity.AddTab(
226 this,
227 this.mTabHost,
228 this.mTabHost.newTabSpec("Tab2").setIndicator(mSectionsPagerAdapter.getPageTitle(1),
alision907bde72013-06-20 14:40:37 -0400229 getResources().getDrawable(mSectionsPagerAdapter.getIconOf(1))), (tabInfo = new TabInfo("Tab2", HomeFragment.class, args)));
alision3c5c2a92013-05-30 09:50:47 -0400230 this.mapTabInfo.put(tabInfo.tag, tabInfo);
alision2cb99562013-05-30 17:02:20 -0400231 SFLPhoneHomeActivity
232 .AddTab(this,
233 this.mTabHost,
234 this.mTabHost.newTabSpec("Tab3").setIndicator(mSectionsPagerAdapter.getPageTitle(2),
235 getResources().getDrawable(mSectionsPagerAdapter.getIconOf(2))), (tabInfo = new TabInfo("Tab3",
236 HistoryFragment.class, args)));
alision3c5c2a92013-05-30 09:50:47 -0400237 this.mapTabInfo.put(tabInfo.tag, tabInfo);
238
239 mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
240
241 @Override
242 public void onTabChanged(String tabId) {
243 int pos = mTabHost.getCurrentTab();
244 mViewPager.setCurrentItem(pos);
245
246 }
247 });
248 }
alisionf57d8a62013-07-02 09:37:12 -0400249
250 @Override
251 protected void onPostCreate(Bundle savedInstanceState) {
252 super.onPostCreate(savedInstanceState);
253 // Sync the toggle state after onRestoreInstanceState has occurred.
254 mDrawerToggle.syncState();
255 }
256
257 @Override
258 public void onConfigurationChanged(Configuration newConfig) {
259 super.onConfigurationChanged(newConfig);
260 mDrawerToggle.onConfigurationChanged(newConfig);
261 }
alision3c5c2a92013-05-30 09:50:47 -0400262
alision9f7a6ec2013-05-24 16:26:26 -0400263 @Override
264 protected void onStart() {
265 Log.i(TAG, "onStart");
266 super.onStart();
267 }
alisionf76de3b2013-04-16 15:35:22 -0400268
alision9f7a6ec2013-05-24 16:26:26 -0400269 /* user gets back to the activity, e.g. through task manager */
270 @Override
271 protected void onRestart() {
272 super.onRestart();
273 }
alisionf76de3b2013-04-16 15:35:22 -0400274
alision9f7a6ec2013-05-24 16:26:26 -0400275 /* activity gets back to the foreground and user input */
276 @Override
277 protected void onResume() {
alision58356b72013-06-03 17:13:36 -0400278 super.onResume();
alision84813a12013-05-27 17:40:39 -0400279 IntentFilter intentFilter = new IntentFilter();
280 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
281 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
282 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
alision58356b72013-06-03 17:13:36 -0400283 registerReceiver(callReceiver, intentFilter);
alision907bde72013-06-20 14:40:37 -0400284
alision9f7a6ec2013-05-24 16:26:26 -0400285 }
alision907bde72013-06-20 14:40:37 -0400286
alisionbd45a822013-06-06 17:35:35 -0400287 private boolean isClosing = false;
288 private Timer t = new Timer();
alision907bde72013-06-20 14:40:37 -0400289
alisionbd45a822013-06-06 17:35:35 -0400290 @Override
291 public void onBackPressed() {
alision907bde72013-06-20 14:40:37 -0400292
293 if (getActionBar().getCustomView() != null) {
alision2ec64f92013-06-17 17:28:58 -0400294 getActionBar().setDisplayShowCustomEnabled(false);
295 getActionBar().setCustomView(null);
296 // Display all the contacts again
297 getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, mContactsFragment);
298 return;
299 }
alision907bde72013-06-20 14:40:37 -0400300
alisionbd45a822013-06-06 17:35:35 -0400301 if (mDrawer.isOpened()) {
alision55c36cb2013-06-14 14:57:38 -0400302 mDrawer.animateClose();
alisionbd45a822013-06-06 17:35:35 -0400303 return;
304 }
alision2ec64f92013-06-17 17:28:58 -0400305
alisionbd45a822013-06-06 17:35:35 -0400306 if (isClosing) {
307 super.onBackPressed();
308 t.cancel();
309 finish();
310 } else {
311
312 t.schedule(new TimerTask() {
313 @Override
314 public void run() {
315 isClosing = false;
316 }
317 }, 3000);
318 Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show();
319 isClosing = true;
320 }
321 }
alisione2a38e12013-04-25 14:20:20 -0400322
alision9f7a6ec2013-05-24 16:26:26 -0400323 /* activity no more in foreground */
324 @Override
325 protected void onPause() {
326 super.onPause();
alision58356b72013-06-03 17:13:36 -0400327 unregisterReceiver(callReceiver);
alision55c36cb2013-06-14 14:57:38 -0400328 try {
329 service.createNotification();
330
331 } catch (RemoteException e) {
332 Log.e(TAG, e.toString());
333 }
alision2cb99562013-05-30 17:02:20 -0400334
alision9f7a6ec2013-05-24 16:26:26 -0400335 }
alisionf76de3b2013-04-16 15:35:22 -0400336
alision9f7a6ec2013-05-24 16:26:26 -0400337 /* activity is no longer visible */
338 @Override
339 protected void onStop() {
340 super.onStop();
alision2cb99562013-05-30 17:02:20 -0400341
alision9f7a6ec2013-05-24 16:26:26 -0400342 }
alisionf76de3b2013-04-16 15:35:22 -0400343
alision9f7a6ec2013-05-24 16:26:26 -0400344 /* activity finishes itself or is being killed by the system */
345 @Override
346 protected void onDestroy() {
347 /* stop the service, if no other bound user, no need to check if it is running */
348 if (mBound) {
349 Log.i(TAG, "onDestroy: Unbinding service...");
alision907bde72013-06-20 14:40:37 -0400350
alision9f7a6ec2013-05-24 16:26:26 -0400351 unbindService(mConnection);
352 mBound = false;
alision2cb99562013-05-30 17:02:20 -0400353
alision9f7a6ec2013-05-24 16:26:26 -0400354 }
alision371b77e2013-04-23 14:51:26 -0400355
alision9f7a6ec2013-05-24 16:26:26 -0400356 super.onDestroy();
357 }
alision73424b62013-04-26 11:49:18 -0400358
alision55c36cb2013-06-14 14:57:38 -0400359 public void launchCallActivity(SipCall infos) {
alision9f7a6ec2013-05-24 16:26:26 -0400360 Log.i(TAG, "Launch Call Activity");
361 Bundle bundle = new Bundle();
alisiondf1dac92013-06-27 17:35:53 -0400362 Conference tmp = new Conference("-1");
363 tmp.getParticipants().add(infos);
364 bundle.putParcelable("conference", tmp);
alision9f7a6ec2013-05-24 16:26:26 -0400365 Intent intent = new Intent().setClass(this, CallActivity.class);
alisiondf1dac92013-06-27 17:35:53 -0400366 intent.putExtra("resuming", false);
alision9f7a6ec2013-05-24 16:26:26 -0400367 intent.putExtras(bundle);
368 startActivityForResult(intent, REQUEST_CODE_CALL);
369 }
alisionf76de3b2013-04-16 15:35:22 -0400370
alision9f7a6ec2013-05-24 16:26:26 -0400371 /** Defines callbacks for service binding, passed to bindService() */
372 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400373
alision9f7a6ec2013-05-24 16:26:26 -0400374 @Override
375 public void onServiceConnected(ComponentName className, IBinder binder) {
376 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400377
alision2cb99562013-05-30 17:02:20 -0400378 try {
alision58356b72013-06-03 17:13:36 -0400379
alision907bde72013-06-20 14:40:37 -0400380 fMenu = new MenuFragment();
381 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
alision58356b72013-06-03 17:13:36 -0400382 mSectionsPagerAdapter = new SectionsPagerAdapter(SFLPhoneHomeActivity.this, getFragmentManager());
383 initialiseTabHost(null);
alisiondf1dac92013-06-27 17:35:53 -0400384 mViewPager.setOffscreenPageLimit(2);
alision58356b72013-06-03 17:13:36 -0400385 mViewPager.setAdapter(mSectionsPagerAdapter);
386 mTabHost.setCurrentTab(1);
alision2cb99562013-05-30 17:02:20 -0400387 service.destroyNotification();
alision58356b72013-06-03 17:13:36 -0400388 // mAdapter = new AccountSelectionAdapter(SFLPhoneHomeActivity.this, service, new ArrayList<Account>());
389 // spinnerAccounts.setAdapter(mAdapter);
alision2cb99562013-05-30 17:02:20 -0400390 } catch (RemoteException e) {
391 Log.e(TAG, e.toString());
392 }
alision9f7a6ec2013-05-24 16:26:26 -0400393 mBound = true;
alision9f7a6ec2013-05-24 16:26:26 -0400394 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400395
alision9f7a6ec2013-05-24 16:26:26 -0400396 }
alision5f899632013-04-22 17:26:56 -0400397
alision9f7a6ec2013-05-24 16:26:26 -0400398 @Override
399 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400400
alision9f7a6ec2013-05-24 16:26:26 -0400401 mBound = false;
402 Log.d(TAG, "Service disconnected service=" + service);
403 }
404 };
alision5f899632013-04-22 17:26:56 -0400405
alision9f7a6ec2013-05-24 16:26:26 -0400406 @Override
407 public boolean onOptionsItemSelected(MenuItem item) {
408 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400409
alision9f7a6ec2013-05-24 16:26:26 -0400410 if (mDrawerToggle.onOptionsItemSelected(item)) {
411 return true;
412 }
alision5f899632013-04-22 17:26:56 -0400413
alision9f7a6ec2013-05-24 16:26:26 -0400414 return super.onOptionsItemSelected(item);
415 }
alisionf76de3b2013-04-16 15:35:22 -0400416
alision9f7a6ec2013-05-24 16:26:26 -0400417 @Override
418 public void onActivityResult(int requestCode, int resultCode, Intent data) {
419 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400420
421 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400422 case REQUEST_CODE_PREFERENCES:
alision907bde72013-06-20 14:40:37 -0400423 Log.w(TAG, "In Activity");
424 fMenu.updateAllAccounts();
alision9f7a6ec2013-05-24 16:26:26 -0400425 break;
426 case REQUEST_CODE_CALL:
alision2cb99562013-05-30 17:02:20 -0400427 Log.w(TAG, "Result out of CallActivity");
alisiondf1dac92013-06-27 17:35:53 -0400428 getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, (HistoryFragment) mSectionsPagerAdapter.getItem(2));
alision9f7a6ec2013-05-24 16:26:26 -0400429 break;
430 }
alisionf76de3b2013-04-16 15:35:22 -0400431
alision9f7a6ec2013-05-24 16:26:26 -0400432 }
alisionf76de3b2013-04-16 15:35:22 -0400433
alision9f7a6ec2013-05-24 16:26:26 -0400434 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400435 public ISipService getService() {
436 return service;
437 }
alisionf76de3b2013-04-16 15:35:22 -0400438
alision84813a12013-05-27 17:40:39 -0400439 /**
440 * Interface implemented to handle incoming events
441 */
alision9f7a6ec2013-05-24 16:26:26 -0400442 @Override
alision84813a12013-05-27 17:40:39 -0400443 public void incomingCall(Intent call) {
444 Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show();
alisionfde875f2013-05-28 17:01:54 -0400445 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400446
alision58356b72013-06-03 17:13:36 -0400447 // mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400448
alision55c36cb2013-06-14 14:57:38 -0400449 launchCallActivity(infos);
alision84813a12013-05-27 17:40:39 -0400450
451 }
452
453 @Override
454 public void callStateChanged(Intent callState) {
455 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
456 String cID = b.getString("CallID");
457 String state = b.getString("State");
458 Log.i(TAG, "callStateChanged" + cID + " " + state);
alision58356b72013-06-03 17:13:36 -0400459 // mCallElementList.updateCall(cID, state);
alision84813a12013-05-27 17:40:39 -0400460
461 }
462
463 @Override
464 public void incomingText(Intent msg) {
465 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
466 b.getString("CallID");
467 String from = b.getString("From");
468 String mess = b.getString("Msg");
469 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
470 }
471
472 @Override
alision55c36cb2013-06-14 14:57:38 -0400473 public void onContactSelected(final CallContact c) {
alisionfde875f2013-05-28 17:01:54 -0400474
alision55c36cb2013-06-14 14:57:38 -0400475 Thread launcher = new Thread(new Runnable() {
alision907bde72013-06-20 14:40:37 -0400476
alision55c36cb2013-06-14 14:57:38 -0400477 final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
478 final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
alision907bde72013-06-20 14:40:37 -0400479
alision55c36cb2013-06-14 14:57:38 -0400480 @Override
481 public void run() {
482 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
483 try {
alision907bde72013-06-20 14:40:37 -0400484 callBuilder.startCallCreation().setAccountID(service.getAccountList().get(1).toString())
485 .setCallType(SipCall.state.CALL_TYPE_OUTGOING);
486 Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(),
487 null, null);
alision55c36cb2013-06-14 14:57:38 -0400488
alision907bde72013-06-20 14:40:37 -0400489 while (cPhones.moveToNext()) {
490 c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE)));
491 }
492 cPhones.close();
493
494 Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null,
495 null);
496
497 while (cSip.moveToNext()) {
498 c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE)));
499 }
500 cSip.close();
501 callBuilder.setContact(c);
alision55c36cb2013-06-14 14:57:38 -0400502 launchCallActivity(callBuilder.build());
503 } catch (RemoteException e1) {
504 Log.e(TAG, e1.toString());
505 } catch (Exception e) {
506 Log.e(TAG, e.toString());
507 }
alision907bde72013-06-20 14:40:37 -0400508
alision55c36cb2013-06-14 14:57:38 -0400509 }
510 });
511 launcher.start();
512 mDrawer.close();
alision84813a12013-05-27 17:40:39 -0400513
514 }
515
516 @Override
alision907bde72013-06-20 14:40:37 -0400517 public void onCallDialed(String to) {
alision84813a12013-05-27 17:40:39 -0400518
alisiondf1dac92013-06-27 17:35:53 -0400519 if (fMenu.getSelectedAccount() == null) {
520 Toast.makeText(this, "No Account Selected", Toast.LENGTH_SHORT).show();
521 return;
522 }
523
alisionfde875f2013-05-28 17:01:54 -0400524 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
alision907bde72013-06-20 14:40:37 -0400525 callBuilder.startCallCreation().setAccountID(fMenu.getSelectedAccount().getAccountID()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
526 callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400527
alisionfde875f2013-05-28 17:01:54 -0400528 try {
alision55c36cb2013-06-14 14:57:38 -0400529 launchCallActivity(callBuilder.build());
alisionfde875f2013-05-28 17:01:54 -0400530 } catch (Exception e) {
531 Log.e(TAG, e.toString());
532 }
alision84813a12013-05-27 17:40:39 -0400533
alision9f7a6ec2013-05-24 16:26:26 -0400534 }
alision371b77e2013-04-23 14:51:26 -0400535
alisiond45da712013-05-30 09:18:49 -0400536 @Override
537 public void onContactDragged() {
538
539 mDrawer.close();
alision2cb99562013-05-30 17:02:20 -0400540 mTabHost.setCurrentTab(1);
alisiond45da712013-05-30 09:18:49 -0400541
542 }
543
544 private HashMap<String, TabInfo> mapTabInfo = new HashMap<String, SFLPhoneHomeActivity.TabInfo>();
545
546 /**
547 * A simple factory that returns dummy views to the Tabhost
548 *
549 * @author mwho
550 */
551 class TabFactory implements TabContentFactory {
552
553 private final Context mContext;
554
555 /**
556 * @param context
557 */
558 public TabFactory(Context context) {
559 mContext = context;
560 }
561
562 /**
563 * (non-Javadoc)
564 *
565 * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)
566 */
567 public View createTabContent(String tag) {
568 View v = new View(mContext);
569 v.setMinimumWidth(0);
570 v.setMinimumHeight(0);
571 return v;
572 }
573
574 }
575
576 /**
577 *
578 * @author mwho Maintains extrinsic info of a tab's construct
579 */
580 private class TabInfo {
581 private String tag;
alisiond45da712013-05-30 09:18:49 -0400582
583 TabInfo(String tag, Class<?> clazz, Bundle args) {
584 this.tag = tag;
alisiond45da712013-05-30 09:18:49 -0400585 }
586
587 }
588
589 private static void AddTab(SFLPhoneHomeActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {
590 // Attach a Tab view factory to the spec
591 tabSpec.setContent(activity.new TabFactory(activity));
592 tabHost.addTab(tabSpec);
593 }
594
alision58356b72013-06-03 17:13:36 -0400595 @Override
596 public void openDrawer() {
alision55c36cb2013-06-14 14:57:38 -0400597 mDrawer.animateOpen();
alision58356b72013-06-03 17:13:36 -0400598 }
599
alision806e18e2013-06-21 15:30:17 -0400600 @Override
601 public void confCreated(Intent intent) {
602 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400603
alision806e18e2013-06-21 15:30:17 -0400604 }
605
606 @Override
607 public void confRemoved(Intent intent) {
608 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400609
alision806e18e2013-06-21 15:30:17 -0400610 }
611
612 @Override
613 public void confChanged(Intent intent) {
614 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400615
616 }
617
618 @Override
619 public void recordingChanged(Intent intent) {
620 // TODO Auto-generated method stub
621
622 }
623
624 @Override
625 public void resumeCallActivity() {
626 Intent intent = new Intent().setClass(this, CallActivity.class);
627 intent.putExtra("resuming", true);
628 startActivityForResult(intent, REQUEST_CODE_CALL);
alision806e18e2013-06-21 15:30:17 -0400629 }
630
alisionf76de3b2013-04-16 15:35:22 -0400631}