blob: 7cd295ffef9ddcd88dae9ceb0948e8d874b1a80d [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 Lision064e1e02013-10-01 16:18:42 -040056
alisionf76de3b2013-04-16 15:35:22 -040057import android.app.Activity;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040058import android.app.AlertDialog;
alisionf76de3b2013-04-16 15:35:22 -040059import android.content.ComponentName;
60import android.content.Context;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040061import android.content.DialogInterface;
alisionf76de3b2013-04-16 15:35:22 -040062import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040063import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040064import android.content.ServiceConnection;
alisionf57d8a62013-07-02 09:37:12 -040065import android.content.res.Configuration;
alision55c36cb2013-06-14 14:57:38 -040066import android.database.Cursor;
Alexandre Lisionc59685a2013-10-04 16:36:36 -040067import android.net.Uri;
alisionf76de3b2013-04-16 15:35:22 -040068import android.os.Bundle;
69import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040070import android.os.RemoteException;
Alexandre Lisionc59685a2013-10-04 16:36:36 -040071import android.provider.ContactsContract;
alision55c36cb2013-06-14 14:57:38 -040072import android.provider.ContactsContract.CommonDataKinds.Phone;
73import android.provider.ContactsContract.CommonDataKinds.SipAddress;
alision9f7a6ec2013-05-24 16:26:26 -040074import android.support.v4.app.ActionBarDrawerToggle;
75import android.support.v4.view.GravityCompat;
Alexandre Lisionf41a3a82013-09-05 17:15:15 -040076import android.support.v4.view.PagerTabStrip;
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 Lisionf41a3a82013-09-05 17:15:15 -040080import android.util.TypedValue;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040081import android.view.Gravity;
alision9f7a6ec2013-05-24 16:26:26 -040082import android.view.MenuItem;
83import android.view.View;
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
alision907bde72013-06-20 14:40:37 -040087public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Callbacks, ContactListFragment.Callbacks, HomeFragment.Callbacks,
88 HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks {
alisionfde875f2013-05-28 17:01:54 -040089
alision9f7a6ec2013-05-24 16:26:26 -040090 SectionsPagerAdapter mSectionsPagerAdapter = null;
alision84813a12013-05-27 17:40:39 -040091 static final String TAG = "SFLPhoneHomeActivity";
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;
alision9f7a6ec2013-05-24 16:26:26 -0400106 CustomSlidingDrawer mDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400107 private DrawerLayout mDrawerLayout;
alision9f7a6ec2013-05-24 16:26:26 -0400108 private ActionBarDrawerToggle mDrawerToggle;
109 /**
110 * The {@link ViewPager} that will host the section contents.
111 */
112 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400113
alision58356b72013-06-03 17:13:36 -0400114 CallReceiver callReceiver;
alision84813a12013-05-27 17:40:39 -0400115
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400116 // private TabHost mTabHost;
alisionf76de3b2013-04-16 15:35:22 -0400117
alision9f7a6ec2013-05-24 16:26:26 -0400118 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
119
120 /* called before activity is killed, e.g. rotation */
121 @Override
122 protected void onSaveInstanceState(Bundle bundle) {
123 super.onSaveInstanceState(bundle);
alision9f7a6ec2013-05-24 16:26:26 -0400124 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
125 Log.w(TAG, "onSaveInstanceState()");
126 }
127
128 @Override
129 public void onCreate(Bundle savedInstanceState) {
130 super.onCreate(savedInstanceState);
131
alision58356b72013-06-03 17:13:36 -0400132 callReceiver = new CallReceiver(this);
alision907bde72013-06-20 14:40:37 -0400133
alision58356b72013-06-03 17:13:36 -0400134 setContentView(R.layout.activity_sflphone_home);
135
alision9f7a6ec2013-05-24 16:26:26 -0400136 // Bind to LocalService
137 if (!mBound) {
138 Log.i(TAG, "onStart: Binding service...");
139 Intent intent = new Intent(this, SipService.class);
140 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
141 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400142
143 if (savedInstanceState != null) {
Alexandre Lision23628c12013-09-24 11:17:05 -0400144 mContactsFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, "ContactsListFragment");
145 }
alision9f7a6ec2013-05-24 16:26:26 -0400146 if (mContactsFragment == null) {
147 mContactsFragment = new ContactListFragment();
alision9f7a6ec2013-05-24 16:26:26 -0400148 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
149 }
alision2ec64f92013-06-17 17:28:58 -0400150
alision9f7a6ec2013-05-24 16:26:26 -0400151 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400152
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400153 mDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {
154
155 @Override
156 public void onScrollStarted() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400157 // getActionBar().hide();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400158
159 }
160
161 @Override
162 public void onScrollEnded() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400163 // getActionBar().show();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400164
165 }
166
167 @Override
168 public void onScroll(int offset) {
169 if (offset < 400) {
170 getActionBar().hide();
171 } else if (offset > 450) {
172 getActionBar().show();
173 }
174 }
175 });
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400176
alision84813a12013-05-27 17:40:39 -0400177 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400178
179 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400180
alision9f7a6ec2013-05-24 16:26:26 -0400181 // Set up the ViewPager with the sections adapter.
182 mViewPager = (ViewPager) findViewById(R.id.pager);
alision55c36cb2013-06-14 14:57:38 -0400183 mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f));
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400184 final PagerTabStrip strip = PagerTabStrip.class.cast(mViewPager.findViewById(R.id.pts_main));
185 strip.setDrawFullUnderline(false);
186 strip.setTabIndicatorColor(getResources().getColor(R.color.holo_blue_dark));
187 strip.setBackgroundColor(getResources().getColor(R.color.darker_gray));
188 strip.setNonPrimaryAlpha(0.5f);
189 strip.setTextSpacing(25);
190 strip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
alisionf76de3b2013-04-16 15:35:22 -0400191
alision9f7a6ec2013-05-24 16:26:26 -0400192 mTitle = mDrawerTitle = getTitle();
193 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400194
alision0b553832013-05-30 09:31:06 -0400195 // set a custom shadow that overlays the main content when the drawer opens
alision9f7a6ec2013-05-24 16:26:26 -0400196 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400197
alision9f7a6ec2013-05-24 16:26:26 -0400198 getActionBar().setDisplayHomeAsUpEnabled(true);
199 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400200
alision9f7a6ec2013-05-24 16:26:26 -0400201 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
202 mDrawerLayout, /* DrawerLayout object */
203 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
204 R.string.drawer_open, /* "open drawer" description for accessibility */
205 R.string.drawer_close /* "close drawer" description for accessibility */
206 ) {
alision0b553832013-05-30 09:31:06 -0400207 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400208 public void onDrawerClosed(View view) {
209 getActionBar().setTitle(mTitle);
210 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
211 }
alisionf76de3b2013-04-16 15:35:22 -0400212
alision0b553832013-05-30 09:31:06 -0400213 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400214 public void onDrawerOpened(View drawerView) {
215 getActionBar().setTitle(mDrawerTitle);
216 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
217 }
218 };
alisionf76de3b2013-04-16 15:35:22 -0400219
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400220 // mTabHost = (TabHost) findViewById(android.R.id.tabhost);
alision9f7a6ec2013-05-24 16:26:26 -0400221 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400222
alision9f7a6ec2013-05-24 16:26:26 -0400223 }
alisionf76de3b2013-04-16 15:35:22 -0400224
alisionf57d8a62013-07-02 09:37:12 -0400225 @Override
226 protected void onPostCreate(Bundle savedInstanceState) {
227 super.onPostCreate(savedInstanceState);
228 // Sync the toggle state after onRestoreInstanceState has occurred.
229 mDrawerToggle.syncState();
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400230 if (mDrawer.isOpened()) {
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400231 getActionBar().hide();
232 }
alisionf57d8a62013-07-02 09:37:12 -0400233 }
alision465ceba2013-07-04 09:24:30 -0400234
alisionf57d8a62013-07-02 09:37:12 -0400235 @Override
236 public void onConfigurationChanged(Configuration newConfig) {
237 super.onConfigurationChanged(newConfig);
238 mDrawerToggle.onConfigurationChanged(newConfig);
239 }
alision3c5c2a92013-05-30 09:50:47 -0400240
alision9f7a6ec2013-05-24 16:26:26 -0400241 @Override
242 protected void onStart() {
243 Log.i(TAG, "onStart");
244 super.onStart();
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400245
alision9f7a6ec2013-05-24 16:26:26 -0400246 }
alisionf76de3b2013-04-16 15:35:22 -0400247
alision9f7a6ec2013-05-24 16:26:26 -0400248 /* user gets back to the activity, e.g. through task manager */
249 @Override
250 protected void onRestart() {
251 super.onRestart();
252 }
alisionf76de3b2013-04-16 15:35:22 -0400253
alision9f7a6ec2013-05-24 16:26:26 -0400254 /* activity gets back to the foreground and user input */
255 @Override
256 protected void onResume() {
alision58356b72013-06-03 17:13:36 -0400257 super.onResume();
alision84813a12013-05-27 17:40:39 -0400258 IntentFilter intentFilter = new IntentFilter();
259 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
260 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
261 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
alision58356b72013-06-03 17:13:36 -0400262 registerReceiver(callReceiver, intentFilter);
alision907bde72013-06-20 14:40:37 -0400263
alision9f7a6ec2013-05-24 16:26:26 -0400264 }
alision907bde72013-06-20 14:40:37 -0400265
alisionbd45a822013-06-06 17:35:35 -0400266 private boolean isClosing = false;
267 private Timer t = new Timer();
alision907bde72013-06-20 14:40:37 -0400268
alisionbd45a822013-06-06 17:35:35 -0400269 @Override
270 public void onBackPressed() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400271
272 if (mDrawerLayout.isDrawerVisible(Gravity.LEFT)) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400273 mDrawerLayout.closeDrawer(Gravity.LEFT);
Alexandre Lision68855472013-10-10 16:20:46 -0400274 return;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400275 }
alision907bde72013-06-20 14:40:37 -0400276 if (getActionBar().getCustomView() != null) {
alision2ec64f92013-06-17 17:28:58 -0400277 getActionBar().setDisplayShowCustomEnabled(false);
278 getActionBar().setCustomView(null);
279 // Display all the contacts again
280 getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, mContactsFragment);
281 return;
282 }
alision907bde72013-06-20 14:40:37 -0400283
alisionbd45a822013-06-06 17:35:35 -0400284 if (mDrawer.isOpened()) {
alision55c36cb2013-06-14 14:57:38 -0400285 mDrawer.animateClose();
alisionbd45a822013-06-06 17:35:35 -0400286 return;
287 }
alision2ec64f92013-06-17 17:28:58 -0400288
alisionbd45a822013-06-06 17:35:35 -0400289 if (isClosing) {
290 super.onBackPressed();
291 t.cancel();
292 finish();
293 } else {
294
295 t.schedule(new TimerTask() {
296 @Override
297 public void run() {
298 isClosing = false;
299 }
300 }, 3000);
301 Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show();
302 isClosing = true;
303 }
304 }
alisione2a38e12013-04-25 14:20:20 -0400305
alision9f7a6ec2013-05-24 16:26:26 -0400306 /* activity no more in foreground */
307 @Override
308 protected void onPause() {
309 super.onPause();
alision58356b72013-06-03 17:13:36 -0400310 unregisterReceiver(callReceiver);
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400311 if (mBound) {
312 unbindService(mConnection);
313 mBound = false;
314 }
alision9f7a6ec2013-05-24 16:26:26 -0400315 }
alisionf76de3b2013-04-16 15:35:22 -0400316
alision9f7a6ec2013-05-24 16:26:26 -0400317 /* activity finishes itself or is being killed by the system */
318 @Override
319 protected void onDestroy() {
alision9f7a6ec2013-05-24 16:26:26 -0400320 super.onDestroy();
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400321 Log.i(TAG, "onDestroy: destroying service...");
322 Intent sipServiceIntent = new Intent(this, SipService.class);
323 stopService(sipServiceIntent);
alision9f7a6ec2013-05-24 16:26:26 -0400324 }
alision73424b62013-04-26 11:49:18 -0400325
alision55c36cb2013-06-14 14:57:38 -0400326 public void launchCallActivity(SipCall infos) {
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400327
alision9f7a6ec2013-05-24 16:26:26 -0400328 Bundle bundle = new Bundle();
alisiondf1dac92013-06-27 17:35:53 -0400329 Conference tmp = new Conference("-1");
alision465ceba2013-07-04 09:24:30 -0400330
alisiondf1dac92013-06-27 17:35:53 -0400331 tmp.getParticipants().add(infos);
alision465ceba2013-07-04 09:24:30 -0400332
alisiondf1dac92013-06-27 17:35:53 -0400333 bundle.putParcelable("conference", tmp);
alision9f7a6ec2013-05-24 16:26:26 -0400334 Intent intent = new Intent().setClass(this, CallActivity.class);
alisiondf1dac92013-06-27 17:35:53 -0400335 intent.putExtra("resuming", false);
alision9f7a6ec2013-05-24 16:26:26 -0400336 intent.putExtras(bundle);
337 startActivityForResult(intent, REQUEST_CODE_CALL);
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400338
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400339 // overridePendingTransition(R.anim.slide_down, R.anim.slide_up);
alision9f7a6ec2013-05-24 16:26:26 -0400340 }
alisionf76de3b2013-04-16 15:35:22 -0400341
alision9f7a6ec2013-05-24 16:26:26 -0400342 /** Defines callbacks for service binding, passed to bindService() */
343 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400344
alision9f7a6ec2013-05-24 16:26:26 -0400345 @Override
346 public void onServiceConnected(ComponentName className, IBinder binder) {
347 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400348
alision2cb99562013-05-30 17:02:20 -0400349 try {
alision58356b72013-06-03 17:13:36 -0400350
alision907bde72013-06-20 14:40:37 -0400351 fMenu = new MenuFragment();
352 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
alision58356b72013-06-03 17:13:36 -0400353 mSectionsPagerAdapter = new SectionsPagerAdapter(SFLPhoneHomeActivity.this, getFragmentManager());
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400354
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400355 // initialiseTabHost(null);
alisiondf1dac92013-06-27 17:35:53 -0400356 mViewPager.setOffscreenPageLimit(2);
alision58356b72013-06-03 17:13:36 -0400357 mViewPager.setAdapter(mSectionsPagerAdapter);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400358 mViewPager.setCurrentItem(1);
359 // mTabHost.setCurrentTab(1);
alision2cb99562013-05-30 17:02:20 -0400360 service.destroyNotification();
alision58356b72013-06-03 17:13:36 -0400361 // mAdapter = new AccountSelectionAdapter(SFLPhoneHomeActivity.this, service, new ArrayList<Account>());
362 // spinnerAccounts.setAdapter(mAdapter);
alision2cb99562013-05-30 17:02:20 -0400363 } catch (RemoteException e) {
364 Log.e(TAG, e.toString());
365 }
alision9f7a6ec2013-05-24 16:26:26 -0400366 mBound = true;
alision9f7a6ec2013-05-24 16:26:26 -0400367 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400368
alision9f7a6ec2013-05-24 16:26:26 -0400369 }
alision5f899632013-04-22 17:26:56 -0400370
alision9f7a6ec2013-05-24 16:26:26 -0400371 @Override
372 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400373
alision9f7a6ec2013-05-24 16:26:26 -0400374 mBound = false;
375 Log.d(TAG, "Service disconnected service=" + service);
376 }
377 };
alision5f899632013-04-22 17:26:56 -0400378
alision9f7a6ec2013-05-24 16:26:26 -0400379 @Override
380 public boolean onOptionsItemSelected(MenuItem item) {
381 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400382
alision9f7a6ec2013-05-24 16:26:26 -0400383 if (mDrawerToggle.onOptionsItemSelected(item)) {
384 return true;
385 }
alision5f899632013-04-22 17:26:56 -0400386
alision9f7a6ec2013-05-24 16:26:26 -0400387 return super.onOptionsItemSelected(item);
388 }
alisionf76de3b2013-04-16 15:35:22 -0400389
alision9f7a6ec2013-05-24 16:26:26 -0400390 @Override
391 public void onActivityResult(int requestCode, int resultCode, Intent data) {
392 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400393
394 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400395 case REQUEST_CODE_PREFERENCES:
alision907bde72013-06-20 14:40:37 -0400396 Log.w(TAG, "In Activity");
397 fMenu.updateAllAccounts();
alision9f7a6ec2013-05-24 16:26:26 -0400398 break;
399 case REQUEST_CODE_CALL:
alision2cb99562013-05-30 17:02:20 -0400400 Log.w(TAG, "Result out of CallActivity");
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400401 if (resultCode == CallActivity.RESULT_FAILURE) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400402 Log.w(TAG, "Call Failed");
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400403 }
404 // if (mSectionsPagerAdapter != null && mSectionsPagerAdapter.getItem(2) != null)
405 // getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, (HistoryFragment) mSectionsPagerAdapter.getItem(2));
alision9f7a6ec2013-05-24 16:26:26 -0400406 break;
407 }
alisionf76de3b2013-04-16 15:35:22 -0400408
alision9f7a6ec2013-05-24 16:26:26 -0400409 }
alisionf76de3b2013-04-16 15:35:22 -0400410
alision9f7a6ec2013-05-24 16:26:26 -0400411 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400412 public ISipService getService() {
413 return service;
414 }
alisionf76de3b2013-04-16 15:35:22 -0400415
alision84813a12013-05-27 17:40:39 -0400416 /**
417 * Interface implemented to handle incoming events
418 */
alision9f7a6ec2013-05-24 16:26:26 -0400419 @Override
alision84813a12013-05-27 17:40:39 -0400420 public void incomingCall(Intent call) {
421 Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show();
alisionfde875f2013-05-28 17:01:54 -0400422 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400423
alision58356b72013-06-03 17:13:36 -0400424 // mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400425
alision55c36cb2013-06-14 14:57:38 -0400426 launchCallActivity(infos);
alision84813a12013-05-27 17:40:39 -0400427
428 }
429
430 @Override
431 public void callStateChanged(Intent callState) {
432 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
433 String cID = b.getString("CallID");
434 String state = b.getString("State");
435 Log.i(TAG, "callStateChanged" + cID + " " + state);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400436 mSectionsPagerAdapter.updateHome();
alision84813a12013-05-27 17:40:39 -0400437
438 }
439
440 @Override
441 public void incomingText(Intent msg) {
442 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
443 b.getString("CallID");
444 String from = b.getString("From");
445 String mess = b.getString("Msg");
446 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
447 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400448
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400449 @Override
450 public void onTextContact(final CallContact c) {
451 // TODO
452 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400453
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400454 @Override
455 public void onEditContact(final CallContact c) {
456 Intent intent = new Intent(Intent.ACTION_VIEW);
457 Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId()));
458 intent.setData(uri);
459 startActivity(intent);
460 }
alision84813a12013-05-27 17:40:39 -0400461
462 @Override
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400463 public void onCallContact(final CallContact c) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400464
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400465 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400466 createAccountDialog().show();
467 return;
468 }
alisionfde875f2013-05-28 17:01:54 -0400469
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400470 if (!fMenu.getSelectedAccount().isRegistered()) {
471 createNotRegisteredDialog().show();
472 return;
473 }
474
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400475 getActionBar().show();
alision55c36cb2013-06-14 14:57:38 -0400476 Thread launcher = new Thread(new Runnable() {
alision907bde72013-06-20 14:40:37 -0400477
alision55c36cb2013-06-14 14:57:38 -0400478 final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
479 final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
alision907bde72013-06-20 14:40:37 -0400480
alision55c36cb2013-06-14 14:57:38 -0400481 @Override
482 public void run() {
483 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
484 try {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400485 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
alision907bde72013-06-20 14:40:37 -0400486 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());
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400503 } catch (InvalidObjectException e) {
504 e.printStackTrace();
alision55c36cb2013-06-14 14:57:38 -0400505 }
alision907bde72013-06-20 14:40:37 -0400506
alision55c36cb2013-06-14 14:57:38 -0400507 }
508 });
509 launcher.start();
510 mDrawer.close();
alision84813a12013-05-27 17:40:39 -0400511
512 }
513
514 @Override
alision907bde72013-06-20 14:40:37 -0400515 public void onCallDialed(String to) {
alision84813a12013-05-27 17:40:39 -0400516
alisiondf1dac92013-06-27 17:35:53 -0400517 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400518 createAccountDialog().show();
alisiondf1dac92013-06-27 17:35:53 -0400519 return;
520 }
521
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400522 if (fMenu.getSelectedAccount().isRegistered()) {
523 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
524 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
525 callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400526
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400527 try {
528 launchCallActivity(callBuilder.build());
529 } catch (Exception e) {
530 Log.e(TAG, e.toString());
531 }
532 } else {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400533 createNotRegisteredDialog().show();
534 ;
alisionfde875f2013-05-28 17:01:54 -0400535 }
alision84813a12013-05-27 17:40:39 -0400536
alision9f7a6ec2013-05-24 16:26:26 -0400537 }
alision371b77e2013-04-23 14:51:26 -0400538
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400539 private AlertDialog createNotRegisteredDialog() {
540 final Activity ownerActivity = this;
541 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
542
543 builder.setMessage(getResources().getString(R.string.cannot_pass_sipcall))
544 .setTitle(getResources().getString(R.string.cannot_pass_sipcall_title))
545 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
546 public void onClick(DialogInterface dialog, int whichButton) {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400547
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400548 }
549 });
550
551 AlertDialog alertDialog = builder.create();
552 alertDialog.setOwnerActivity(ownerActivity);
553
554 return alertDialog;
555 }
556
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400557 private AlertDialog createAccountDialog() {
558 final Activity ownerActivity = this;
559 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
560
561 builder.setMessage(getResources().getString(R.string.create_new_account_dialog))
562 .setTitle(getResources().getString(R.string.create_new_account_dialog_title))
563 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
564 public void onClick(DialogInterface dialog, int whichButton) {
565 Intent in = new Intent();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400566 in.setClass(ownerActivity, AccountWizard.class);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400567 ownerActivity.startActivityForResult(in, SFLPhoneHomeActivity.REQUEST_CODE_PREFERENCES);
568 }
569 }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
570 public void onClick(DialogInterface dialog, int whichButton) {
571 dialog.dismiss();
572 }
573 });
574
575 AlertDialog alertDialog = builder.create();
576 alertDialog.setOwnerActivity(ownerActivity);
577
578 return alertDialog;
579 }
580
alisiond45da712013-05-30 09:18:49 -0400581 @Override
582 public void onContactDragged() {
alisiond45da712013-05-30 09:18:49 -0400583 mDrawer.close();
alisiond45da712013-05-30 09:18:49 -0400584 }
585
alision58356b72013-06-03 17:13:36 -0400586 @Override
587 public void openDrawer() {
alision55c36cb2013-06-14 14:57:38 -0400588 mDrawer.animateOpen();
alision58356b72013-06-03 17:13:36 -0400589 }
590
alision806e18e2013-06-21 15:30:17 -0400591 @Override
592 public void confCreated(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 confRemoved(Intent intent) {
599 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400600
alision806e18e2013-06-21 15:30:17 -0400601 }
602
603 @Override
604 public void confChanged(Intent intent) {
605 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400606
607 }
608
609 @Override
610 public void recordingChanged(Intent intent) {
611 // TODO Auto-generated method stub
612
613 }
614
615 @Override
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400616 public void selectedCall(Conference c) {
alisiondf1dac92013-06-27 17:35:53 -0400617 Intent intent = new Intent().setClass(this, CallActivity.class);
618 intent.putExtra("resuming", true);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400619 intent.putExtra("conference", c);
alisiondf1dac92013-06-27 17:35:53 -0400620 startActivityForResult(intent, REQUEST_CODE_CALL);
alision806e18e2013-06-21 15:30:17 -0400621 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400622
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400623 private class ZoomOutPageTransformer implements ViewPager.PageTransformer {
624 private static final float MIN_ALPHA = .6f;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400625
626 // private final float scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400627
628 public ZoomOutPageTransformer(float scalingStart) {
629 super();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400630 // this.scalingStart = 1 - scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400631 }
632
633 @Override
634 public void transformPage(View page, float position) {
635 // page.setRotationY(position * -30);
636 final float normalizedposition = Math.abs(Math.abs(position) - 1);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400637 page.setAlpha(MIN_ALPHA + (1.f - MIN_ALPHA) * normalizedposition);
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400638 }
639 }
alision806e18e2013-06-21 15:30:17 -0400640
alisionf76de3b2013-04-16 15:35:22 -0400641}