blob: 8e9833b46cfa4fb00652bb4b224ebff859ba6e9f [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 */
Alexandre Lision064e1e02013-10-01 16:18:42 -040032package org.sflphone.client;
alisionf76de3b2013-04-16 15:35:22 -040033
Alexandre Lision5ed2c972013-10-11 15:36:33 -040034import java.io.InvalidObjectException;
alisionbd45a822013-06-06 17:35:35 -040035import java.util.Timer;
36import java.util.TimerTask;
alision84813a12013-05-27 17:40:39 -040037
Alexandre Lision064e1e02013-10-01 16:18:42 -040038import org.sflphone.R;
39import org.sflphone.adapters.SectionsPagerAdapter;
40import org.sflphone.fragments.ContactListFragment;
41import org.sflphone.fragments.DialingFragment;
42import org.sflphone.fragments.HistoryFragment;
43import org.sflphone.fragments.HomeFragment;
44import org.sflphone.fragments.MenuFragment;
45import org.sflphone.interfaces.CallInterface;
46import org.sflphone.loaders.LoaderConstants;
47import org.sflphone.model.CallContact;
48import org.sflphone.model.Conference;
49import org.sflphone.model.SipCall;
50import org.sflphone.receivers.CallReceiver;
51import org.sflphone.service.CallManagerCallBack;
52import org.sflphone.service.ISipService;
53import org.sflphone.service.SipService;
54import org.sflphone.views.CustomSlidingDrawer;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -040055import org.sflphone.views.CustomSlidingDrawer.OnDrawerScrollListener;
Alexandre Lisione5b66022013-10-30 11:34:15 -040056import org.sflphone.views.PagerSlidingTabStrip;
Alexandre Lision064e1e02013-10-01 16:18:42 -040057
alisionf76de3b2013-04-16 15:35:22 -040058import android.app.Activity;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040059import android.app.AlertDialog;
alisionf76de3b2013-04-16 15:35:22 -040060import android.content.ComponentName;
61import android.content.Context;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040062import android.content.DialogInterface;
alisionf76de3b2013-04-16 15:35:22 -040063import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040064import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040065import android.content.ServiceConnection;
alisionf57d8a62013-07-02 09:37:12 -040066import android.content.res.Configuration;
alision55c36cb2013-06-14 14:57:38 -040067import android.database.Cursor;
Alexandre Lisionc59685a2013-10-04 16:36:36 -040068import android.net.Uri;
alisionf76de3b2013-04-16 15:35:22 -040069import android.os.Bundle;
70import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040071import android.os.RemoteException;
Alexandre Lisionc59685a2013-10-04 16:36:36 -040072import android.provider.ContactsContract;
alision55c36cb2013-06-14 14:57:38 -040073import android.provider.ContactsContract.CommonDataKinds.Phone;
74import android.provider.ContactsContract.CommonDataKinds.SipAddress;
alision9f7a6ec2013-05-24 16:26:26 -040075import android.support.v4.app.ActionBarDrawerToggle;
76import android.support.v4.view.GravityCompat;
alisionf76de3b2013-04-16 15:35:22 -040077import android.support.v4.view.ViewPager;
alision9f7a6ec2013-05-24 16:26:26 -040078import android.support.v4.widget.DrawerLayout;
alisionf76de3b2013-04-16 15:35:22 -040079import android.util.Log;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040080import android.view.Gravity;
alision9f7a6ec2013-05-24 16:26:26 -040081import android.view.MenuItem;
82import android.view.View;
Alexandre Lision68900052013-11-01 11:34:56 -040083import android.widget.ImageView;
alision7297bdb2013-05-21 11:56:55 -040084import android.widget.RelativeLayout;
alision04a00182013-05-10 17:05:29 -040085import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040086
Alexandre Lision4ab53972013-11-04 16:59:18 -050087public class HomeActivity extends Activity implements DialingFragment.Callbacks, ContactListFragment.Callbacks, HomeFragment.Callbacks,
alision907bde72013-06-20 14:40:37 -040088 HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks {
alisionfde875f2013-05-28 17:01:54 -040089
alision9f7a6ec2013-05-24 16:26:26 -040090 SectionsPagerAdapter mSectionsPagerAdapter = null;
Alexandre Lision9d052a12013-11-06 15:13:34 -050091 static final String TAG = "HomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040092
alision9f7a6ec2013-05-24 16:26:26 -040093 private ContactListFragment mContactsFragment = 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
alision2cb99562013-05-30 17:02:20 -0400102 public static final int REQUEST_CODE_PREFERENCES = 1;
alision9f7a6ec2013-05-24 16:26:26 -0400103 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -0400104
alision0b553832013-05-30 09:31:06 -0400105 RelativeLayout mSliderButton;
Alexandre Lision68900052013-11-01 11:34:56 -0400106 CustomSlidingDrawer mContactDrawer;
107 private DrawerLayout mNavigationDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400108 private ActionBarDrawerToggle mDrawerToggle;
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400109 ImageView mShadow;
alision9f7a6ec2013-05-24 16:26:26 -0400110 /**
111 * The {@link ViewPager} that will host the section contents.
112 */
113 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400114
alision58356b72013-06-03 17:13:36 -0400115 CallReceiver callReceiver;
Alexandre Lision9d052a12013-11-06 15:13:34 -0500116 private boolean isClosing = false;
117 private Timer t = new Timer();
alision84813a12013-05-27 17:40:39 -0400118
Alexandre Lisionc51ccb12013-09-11 16:00:30 -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);
alision9f7a6ec2013-05-24 16:26:26 -0400127 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
128 Log.w(TAG, "onSaveInstanceState()");
129 }
130
131 @Override
132 public void onCreate(Bundle savedInstanceState) {
133 super.onCreate(savedInstanceState);
134
alision58356b72013-06-03 17:13:36 -0400135 callReceiver = new CallReceiver(this);
alision907bde72013-06-20 14:40:37 -0400136
alision58356b72013-06-03 17:13:36 -0400137 setContentView(R.layout.activity_sflphone_home);
138
alision9f7a6ec2013-05-24 16:26:26 -0400139 // Bind to LocalService
140 if (!mBound) {
141 Log.i(TAG, "onStart: Binding service...");
142 Intent intent = new Intent(this, SipService.class);
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400143 startService(intent);
alision9f7a6ec2013-05-24 16:26:26 -0400144 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
145 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400146
147 if (savedInstanceState != null) {
Alexandre Lision23628c12013-09-24 11:17:05 -0400148 mContactsFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, "ContactsListFragment");
149 }
alision9f7a6ec2013-05-24 16:26:26 -0400150 if (mContactsFragment == null) {
151 mContactsFragment = new ContactListFragment();
alision9f7a6ec2013-05-24 16:26:26 -0400152 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
153 }
alision2ec64f92013-06-17 17:28:58 -0400154
Alexandre Lision68900052013-11-01 11:34:56 -0400155 mContactDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400156
Alexandre Lision68900052013-11-01 11:34:56 -0400157 mContactDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400158
159 @Override
160 public void onScrollStarted() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400161 // getActionBar().hide();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400162
163 }
164
165 @Override
166 public void onScrollEnded() {
Alexandre Lision15d87932013-11-08 15:16:14 -0500167
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400168 }
169
170 @Override
171 public void onScroll(int offset) {
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400172
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400173 if (offset < 400) {
174 getActionBar().hide();
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400175 // mNavigationDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400176 } else if (offset > 450) {
177 getActionBar().show();
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400178 // mNavigationDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400179 }
180 }
181 });
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400182
alision84813a12013-05-27 17:40:39 -0400183 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400184 mShadow = (ImageView) findViewById(R.id.overall_shadow);
Alexandre Lision711fde92013-11-07 15:08:26 -0500185 mContactDrawer.setmTrackHandle(findViewById(R.id.slider_button));
alisionf76de3b2013-04-16 15:35:22 -0400186
alision9f7a6ec2013-05-24 16:26:26 -0400187 // Set up the ViewPager with the sections adapter.
188 mViewPager = (ViewPager) findViewById(R.id.pager);
alision55c36cb2013-06-14 14:57:38 -0400189 mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f));
alisionf76de3b2013-04-16 15:35:22 -0400190
alision9f7a6ec2013-05-24 16:26:26 -0400191 mTitle = mDrawerTitle = getTitle();
Alexandre Lision68900052013-11-01 11:34:56 -0400192 mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400193
alision0b553832013-05-30 09:31:06 -0400194 // set a custom shadow that overlays the main content when the drawer opens
Alexandre Lision68900052013-11-01 11:34:56 -0400195 mNavigationDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400196
alision9f7a6ec2013-05-24 16:26:26 -0400197 getActionBar().setDisplayHomeAsUpEnabled(true);
198 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400199
alision9f7a6ec2013-05-24 16:26:26 -0400200 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
Alexandre Lision68900052013-11-01 11:34:56 -0400201 mNavigationDrawer, /* DrawerLayout object */
alision9f7a6ec2013-05-24 16:26:26 -0400202 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
203 R.string.drawer_open, /* "open drawer" description for accessibility */
204 R.string.drawer_close /* "close drawer" description for accessibility */
205 ) {
alision0b553832013-05-30 09:31:06 -0400206 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400207 public void onDrawerClosed(View view) {
208 getActionBar().setTitle(mTitle);
209 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
210 }
alisionf76de3b2013-04-16 15:35:22 -0400211
alision0b553832013-05-30 09:31:06 -0400212 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400213 public void onDrawerOpened(View drawerView) {
214 getActionBar().setTitle(mDrawerTitle);
215 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
216 }
217 };
alisionf76de3b2013-04-16 15:35:22 -0400218
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400219 // mTabHost = (TabHost) findViewById(android.R.id.tabhost);
Alexandre Lision68900052013-11-01 11:34:56 -0400220 mNavigationDrawer.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400221
alision9f7a6ec2013-05-24 16:26:26 -0400222 }
alisionf76de3b2013-04-16 15:35:22 -0400223
alisionf57d8a62013-07-02 09:37:12 -0400224 @Override
225 protected void onPostCreate(Bundle savedInstanceState) {
226 super.onPostCreate(savedInstanceState);
227 // Sync the toggle state after onRestoreInstanceState has occurred.
228 mDrawerToggle.syncState();
Alexandre Lision68900052013-11-01 11:34:56 -0400229 if (mContactDrawer.isOpened()) {
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400230 getActionBar().hide();
231 }
alisionf57d8a62013-07-02 09:37:12 -0400232 }
alision465ceba2013-07-04 09:24:30 -0400233
alisionf57d8a62013-07-02 09:37:12 -0400234 @Override
235 public void onConfigurationChanged(Configuration newConfig) {
236 super.onConfigurationChanged(newConfig);
237 mDrawerToggle.onConfigurationChanged(newConfig);
238 }
alision3c5c2a92013-05-30 09:50:47 -0400239
alision9f7a6ec2013-05-24 16:26:26 -0400240 @Override
241 protected void onStart() {
242 Log.i(TAG, "onStart");
243 super.onStart();
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400244
alision9f7a6ec2013-05-24 16:26:26 -0400245 }
alisionf76de3b2013-04-16 15:35:22 -0400246
alision9f7a6ec2013-05-24 16:26:26 -0400247 /* user gets back to the activity, e.g. through task manager */
248 @Override
249 protected void onRestart() {
250 super.onRestart();
251 }
alisionf76de3b2013-04-16 15:35:22 -0400252
alision9f7a6ec2013-05-24 16:26:26 -0400253 /* activity gets back to the foreground and user input */
254 @Override
255 protected void onResume() {
alision58356b72013-06-03 17:13:36 -0400256 super.onResume();
alision84813a12013-05-27 17:40:39 -0400257 IntentFilter intentFilter = new IntentFilter();
258 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
259 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
260 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
alision58356b72013-06-03 17:13:36 -0400261 registerReceiver(callReceiver, intentFilter);
alision907bde72013-06-20 14:40:37 -0400262
alision9f7a6ec2013-05-24 16:26:26 -0400263 }
alision907bde72013-06-20 14:40:37 -0400264
alisionbd45a822013-06-06 17:35:35 -0400265 @Override
266 public void onBackPressed() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400267
Alexandre Lision68900052013-11-01 11:34:56 -0400268 if (mNavigationDrawer.isDrawerVisible(Gravity.LEFT)) {
269 mNavigationDrawer.closeDrawer(Gravity.LEFT);
Alexandre Lision68855472013-10-10 16:20:46 -0400270 return;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400271 }
alision907bde72013-06-20 14:40:37 -0400272 if (getActionBar().getCustomView() != null) {
alision2ec64f92013-06-17 17:28:58 -0400273 getActionBar().setDisplayShowCustomEnabled(false);
274 getActionBar().setCustomView(null);
275 // Display all the contacts again
276 getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, mContactsFragment);
277 return;
278 }
alision907bde72013-06-20 14:40:37 -0400279
Alexandre Lision68900052013-11-01 11:34:56 -0400280 if (mContactDrawer.isOpened()) {
281 mContactDrawer.animateClose();
alisionbd45a822013-06-06 17:35:35 -0400282 return;
283 }
alision2ec64f92013-06-17 17:28:58 -0400284
alisionbd45a822013-06-06 17:35:35 -0400285 if (isClosing) {
286 super.onBackPressed();
287 t.cancel();
288 finish();
289 } else {
290
291 t.schedule(new TimerTask() {
292 @Override
293 public void run() {
294 isClosing = false;
295 }
296 }, 3000);
297 Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show();
298 isClosing = true;
299 }
300 }
alisione2a38e12013-04-25 14:20:20 -0400301
alision9f7a6ec2013-05-24 16:26:26 -0400302 /* activity no more in foreground */
303 @Override
304 protected void onPause() {
305 super.onPause();
alision58356b72013-06-03 17:13:36 -0400306 unregisterReceiver(callReceiver);
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400307 if (mBound) {
308 unbindService(mConnection);
309 mBound = false;
310 }
alision9f7a6ec2013-05-24 16:26:26 -0400311 }
alisionf76de3b2013-04-16 15:35:22 -0400312
alision9f7a6ec2013-05-24 16:26:26 -0400313 /* activity finishes itself or is being killed by the system */
314 @Override
315 protected void onDestroy() {
alision9f7a6ec2013-05-24 16:26:26 -0400316 super.onDestroy();
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400317 Log.i(TAG, "onDestroy: destroying service...");
318 Intent sipServiceIntent = new Intent(this, SipService.class);
319 stopService(sipServiceIntent);
alision9f7a6ec2013-05-24 16:26:26 -0400320 }
alision73424b62013-04-26 11:49:18 -0400321
alision55c36cb2013-06-14 14:57:38 -0400322 public void launchCallActivity(SipCall infos) {
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400323
alision9f7a6ec2013-05-24 16:26:26 -0400324 Bundle bundle = new Bundle();
alisiondf1dac92013-06-27 17:35:53 -0400325 Conference tmp = new Conference("-1");
alision465ceba2013-07-04 09:24:30 -0400326
alisiondf1dac92013-06-27 17:35:53 -0400327 tmp.getParticipants().add(infos);
alision465ceba2013-07-04 09:24:30 -0400328
alisiondf1dac92013-06-27 17:35:53 -0400329 bundle.putParcelable("conference", tmp);
alision9f7a6ec2013-05-24 16:26:26 -0400330 Intent intent = new Intent().setClass(this, CallActivity.class);
alisiondf1dac92013-06-27 17:35:53 -0400331 intent.putExtra("resuming", false);
alision9f7a6ec2013-05-24 16:26:26 -0400332 intent.putExtras(bundle);
333 startActivityForResult(intent, REQUEST_CODE_CALL);
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400334
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400335 // overridePendingTransition(R.anim.slide_down, R.anim.slide_up);
alision9f7a6ec2013-05-24 16:26:26 -0400336 }
alisionf76de3b2013-04-16 15:35:22 -0400337
alision9f7a6ec2013-05-24 16:26:26 -0400338 /** Defines callbacks for service binding, passed to bindService() */
339 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400340
alision9f7a6ec2013-05-24 16:26:26 -0400341 @Override
342 public void onServiceConnected(ComponentName className, IBinder binder) {
343 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400344
alision2cb99562013-05-30 17:02:20 -0400345 try {
alision58356b72013-06-03 17:13:36 -0400346
alision907bde72013-06-20 14:40:37 -0400347 fMenu = new MenuFragment();
348 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
Alexandre Lision4ab53972013-11-04 16:59:18 -0500349 mSectionsPagerAdapter = new SectionsPagerAdapter(HomeActivity.this, getFragmentManager());
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400350
alisiondf1dac92013-06-27 17:35:53 -0400351 mViewPager.setOffscreenPageLimit(2);
alision58356b72013-06-03 17:13:36 -0400352 mViewPager.setAdapter(mSectionsPagerAdapter);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400353 mViewPager.setCurrentItem(1);
Alexandre Lisione5b66022013-10-30 11:34:15 -0400354
355 final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(findViewById(R.id.pts_main));
356
Alexandre Lisione5b66022013-10-30 11:34:15 -0400357 strip.setViewPager(mViewPager);
alision2cb99562013-05-30 17:02:20 -0400358 service.destroyNotification();
359 } catch (RemoteException e) {
360 Log.e(TAG, e.toString());
361 }
alision9f7a6ec2013-05-24 16:26:26 -0400362 mBound = true;
alision9f7a6ec2013-05-24 16:26:26 -0400363 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400364
alision9f7a6ec2013-05-24 16:26:26 -0400365 }
alision5f899632013-04-22 17:26:56 -0400366
alision9f7a6ec2013-05-24 16:26:26 -0400367 @Override
368 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400369
alision9f7a6ec2013-05-24 16:26:26 -0400370 mBound = false;
371 Log.d(TAG, "Service disconnected service=" + service);
372 }
373 };
alision5f899632013-04-22 17:26:56 -0400374
alision9f7a6ec2013-05-24 16:26:26 -0400375 @Override
376 public boolean onOptionsItemSelected(MenuItem item) {
377 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400378
alision9f7a6ec2013-05-24 16:26:26 -0400379 if (mDrawerToggle.onOptionsItemSelected(item)) {
380 return true;
381 }
alision5f899632013-04-22 17:26:56 -0400382
alision9f7a6ec2013-05-24 16:26:26 -0400383 return super.onOptionsItemSelected(item);
384 }
alisionf76de3b2013-04-16 15:35:22 -0400385
alision9f7a6ec2013-05-24 16:26:26 -0400386 @Override
387 public void onActivityResult(int requestCode, int resultCode, Intent data) {
388 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400389
390 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400391 case REQUEST_CODE_PREFERENCES:
Alexandre Lisione5b66022013-10-30 11:34:15 -0400392 if (fMenu != null)
Alexandre Lision933ef0a2013-10-15 17:28:40 -0400393 fMenu.updateAllAccounts();
alision9f7a6ec2013-05-24 16:26:26 -0400394 break;
395 case REQUEST_CODE_CALL:
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400396 if (resultCode == CallActivity.RESULT_FAILURE) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400397 Log.w(TAG, "Call Failed");
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400398 }
399 // if (mSectionsPagerAdapter != null && mSectionsPagerAdapter.getItem(2) != null)
400 // getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, (HistoryFragment) mSectionsPagerAdapter.getItem(2));
alision9f7a6ec2013-05-24 16:26:26 -0400401 break;
402 }
alisionf76de3b2013-04-16 15:35:22 -0400403
alision9f7a6ec2013-05-24 16:26:26 -0400404 }
alisionf76de3b2013-04-16 15:35:22 -0400405
alision9f7a6ec2013-05-24 16:26:26 -0400406 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400407 public ISipService getService() {
408 return service;
409 }
alisionf76de3b2013-04-16 15:35:22 -0400410
alision84813a12013-05-27 17:40:39 -0400411 /**
412 * Interface implemented to handle incoming events
413 */
alision9f7a6ec2013-05-24 16:26:26 -0400414 @Override
alision84813a12013-05-27 17:40:39 -0400415 public void incomingCall(Intent call) {
alisionfde875f2013-05-28 17:01:54 -0400416 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400417
alision58356b72013-06-03 17:13:36 -0400418 // mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400419
alision55c36cb2013-06-14 14:57:38 -0400420 launchCallActivity(infos);
alision84813a12013-05-27 17:40:39 -0400421
422 }
423
424 @Override
425 public void callStateChanged(Intent callState) {
426 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
427 String cID = b.getString("CallID");
428 String state = b.getString("State");
429 Log.i(TAG, "callStateChanged" + cID + " " + state);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400430 mSectionsPagerAdapter.updateHome();
alision84813a12013-05-27 17:40:39 -0400431
432 }
433
434 @Override
435 public void incomingText(Intent msg) {
436 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
437 b.getString("CallID");
438 String from = b.getString("From");
439 String mess = b.getString("Msg");
440 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
441 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400442
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400443 @Override
444 public void onTextContact(final CallContact c) {
445 // TODO
446 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400447
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400448 @Override
449 public void onEditContact(final CallContact c) {
450 Intent intent = new Intent(Intent.ACTION_VIEW);
451 Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId()));
452 intent.setData(uri);
453 startActivity(intent);
454 }
alision84813a12013-05-27 17:40:39 -0400455
456 @Override
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400457 public void onCallContact(final CallContact c) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400458
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400459 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400460 createAccountDialog().show();
461 return;
462 }
alisionfde875f2013-05-28 17:01:54 -0400463
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400464 if (!fMenu.getSelectedAccount().isRegistered()) {
465 createNotRegisteredDialog().show();
466 return;
467 }
468
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400469 getActionBar().show();
alision55c36cb2013-06-14 14:57:38 -0400470 Thread launcher = new Thread(new Runnable() {
alision907bde72013-06-20 14:40:37 -0400471
alision55c36cb2013-06-14 14:57:38 -0400472 final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
473 final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
alision907bde72013-06-20 14:40:37 -0400474
alision55c36cb2013-06-14 14:57:38 -0400475 @Override
476 public void run() {
477 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
478 try {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400479 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
alision907bde72013-06-20 14:40:37 -0400480 Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(),
481 null, null);
alision55c36cb2013-06-14 14:57:38 -0400482
alision907bde72013-06-20 14:40:37 -0400483 while (cPhones.moveToNext()) {
484 c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE)));
485 }
486 cPhones.close();
487
488 Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null,
489 null);
490
491 while (cSip.moveToNext()) {
492 c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE)));
493 }
494 cSip.close();
495 callBuilder.setContact(c);
alision55c36cb2013-06-14 14:57:38 -0400496 launchCallActivity(callBuilder.build());
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400497 } catch (InvalidObjectException e) {
498 e.printStackTrace();
alision55c36cb2013-06-14 14:57:38 -0400499 }
alision907bde72013-06-20 14:40:37 -0400500
alision55c36cb2013-06-14 14:57:38 -0400501 }
502 });
503 launcher.start();
Alexandre Lision4ab53972013-11-04 16:59:18 -0500504 mContactDrawer.animateClose();
alision84813a12013-05-27 17:40:39 -0400505
506 }
507
508 @Override
alision907bde72013-06-20 14:40:37 -0400509 public void onCallDialed(String to) {
alision84813a12013-05-27 17:40:39 -0400510
alisiondf1dac92013-06-27 17:35:53 -0400511 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400512 createAccountDialog().show();
alisiondf1dac92013-06-27 17:35:53 -0400513 return;
514 }
515
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400516 if (fMenu.getSelectedAccount().isRegistered()) {
517 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
518 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
519 callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400520
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400521 try {
522 launchCallActivity(callBuilder.build());
523 } catch (Exception e) {
524 Log.e(TAG, e.toString());
525 }
526 } else {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400527 createNotRegisteredDialog().show();
528 ;
alisionfde875f2013-05-28 17:01:54 -0400529 }
alision84813a12013-05-27 17:40:39 -0400530
alision9f7a6ec2013-05-24 16:26:26 -0400531 }
alision371b77e2013-04-23 14:51:26 -0400532
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400533 private AlertDialog createNotRegisteredDialog() {
534 final Activity ownerActivity = this;
535 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
536
537 builder.setMessage(getResources().getString(R.string.cannot_pass_sipcall))
538 .setTitle(getResources().getString(R.string.cannot_pass_sipcall_title))
539 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
540 public void onClick(DialogInterface dialog, int whichButton) {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400541
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400542 }
543 });
544
545 AlertDialog alertDialog = builder.create();
546 alertDialog.setOwnerActivity(ownerActivity);
547
548 return alertDialog;
549 }
550
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400551 private AlertDialog createAccountDialog() {
552 final Activity ownerActivity = this;
553 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
554
555 builder.setMessage(getResources().getString(R.string.create_new_account_dialog))
556 .setTitle(getResources().getString(R.string.create_new_account_dialog_title))
557 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
558 public void onClick(DialogInterface dialog, int whichButton) {
559 Intent in = new Intent();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400560 in.setClass(ownerActivity, AccountWizard.class);
Alexandre Lision4ab53972013-11-04 16:59:18 -0500561 ownerActivity.startActivityForResult(in, HomeActivity.REQUEST_CODE_PREFERENCES);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400562 }
563 }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
564 public void onClick(DialogInterface dialog, int whichButton) {
565 dialog.dismiss();
566 }
567 });
568
569 AlertDialog alertDialog = builder.create();
570 alertDialog.setOwnerActivity(ownerActivity);
571
572 return alertDialog;
573 }
574
alisiond45da712013-05-30 09:18:49 -0400575 @Override
576 public void onContactDragged() {
Alexandre Lision4ab53972013-11-04 16:59:18 -0500577 mContactDrawer.animateClose();
alisiond45da712013-05-30 09:18:49 -0400578 }
579
alision58356b72013-06-03 17:13:36 -0400580 @Override
581 public void openDrawer() {
Alexandre Lision68900052013-11-01 11:34:56 -0400582 mContactDrawer.animateOpen();
alision58356b72013-06-03 17:13:36 -0400583 }
584
alision806e18e2013-06-21 15:30:17 -0400585 @Override
586 public void confCreated(Intent intent) {
587 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400588
alision806e18e2013-06-21 15:30:17 -0400589 }
590
591 @Override
592 public void confRemoved(Intent intent) {
593 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400594
alision806e18e2013-06-21 15:30:17 -0400595 }
596
597 @Override
598 public void confChanged(Intent intent) {
599 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400600
601 }
602
603 @Override
604 public void recordingChanged(Intent intent) {
605 // TODO Auto-generated method stub
606
607 }
608
609 @Override
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400610 public void selectedCall(Conference c) {
alisiondf1dac92013-06-27 17:35:53 -0400611 Intent intent = new Intent().setClass(this, CallActivity.class);
612 intent.putExtra("resuming", true);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400613 intent.putExtra("conference", c);
alisiondf1dac92013-06-27 17:35:53 -0400614 startActivityForResult(intent, REQUEST_CODE_CALL);
alision806e18e2013-06-21 15:30:17 -0400615 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400616
Alexandre Lision3f1aa682013-11-18 10:49:28 -0500617 public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400618 private static final float MIN_ALPHA = .6f;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400619
620 // private final float scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400621
622 public ZoomOutPageTransformer(float scalingStart) {
623 super();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400624 // this.scalingStart = 1 - scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400625 }
626
627 @Override
628 public void transformPage(View page, float position) {
629 // page.setRotationY(position * -30);
630 final float normalizedposition = Math.abs(Math.abs(position) - 1);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400631 page.setAlpha(MIN_ALPHA + (1.f - MIN_ALPHA) * normalizedposition);
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400632 }
633 }
alision806e18e2013-06-21 15:30:17 -0400634
alisionf76de3b2013-04-16 15:35:22 -0400635}