blob: 500869a39335814ebc2913af8a3be06924b87ce8 [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;
Alexandre Lisionf41a3a82013-09-05 17:15:15 -040077import android.support.v4.view.PagerTabStrip;
alisionf76de3b2013-04-16 15:35:22 -040078import android.support.v4.view.ViewPager;
alision9f7a6ec2013-05-24 16:26:26 -040079import android.support.v4.widget.DrawerLayout;
alisionf76de3b2013-04-16 15:35:22 -040080import android.util.Log;
Alexandre Lisionf41a3a82013-09-05 17:15:15 -040081import android.util.TypedValue;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040082import android.view.Gravity;
alision9f7a6ec2013-05-24 16:26:26 -040083import android.view.MenuItem;
84import android.view.View;
alision7297bdb2013-05-21 11:56:55 -040085import android.widget.RelativeLayout;
alision04a00182013-05-10 17:05:29 -040086import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040087
alision907bde72013-06-20 14:40:37 -040088public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Callbacks, ContactListFragment.Callbacks, HomeFragment.Callbacks,
89 HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks {
alisionfde875f2013-05-28 17:01:54 -040090
alision9f7a6ec2013-05-24 16:26:26 -040091 SectionsPagerAdapter mSectionsPagerAdapter = null;
alision84813a12013-05-27 17:40:39 -040092 static final String TAG = "SFLPhoneHomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040093
alision9f7a6ec2013-05-24 16:26:26 -040094 private ContactListFragment mContactsFragment = 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
alision2cb99562013-05-30 17:02:20 -0400103 public static final int REQUEST_CODE_PREFERENCES = 1;
alision9f7a6ec2013-05-24 16:26:26 -0400104 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -0400105
alision0b553832013-05-30 09:31:06 -0400106 RelativeLayout mSliderButton;
alision9f7a6ec2013-05-24 16:26:26 -0400107 CustomSlidingDrawer mDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400108 private DrawerLayout mDrawerLayout;
alision9f7a6ec2013-05-24 16:26:26 -0400109 private ActionBarDrawerToggle mDrawerToggle;
110 /**
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;
alision84813a12013-05-27 17:40:39 -0400116
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400117 // private TabHost mTabHost;
alisionf76de3b2013-04-16 15:35:22 -0400118
alision9f7a6ec2013-05-24 16:26:26 -0400119 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
120
121 /* called before activity is killed, e.g. rotation */
122 @Override
123 protected void onSaveInstanceState(Bundle bundle) {
124 super.onSaveInstanceState(bundle);
alision9f7a6ec2013-05-24 16:26:26 -0400125 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
126 Log.w(TAG, "onSaveInstanceState()");
127 }
128
129 @Override
130 public void onCreate(Bundle savedInstanceState) {
131 super.onCreate(savedInstanceState);
132
alision58356b72013-06-03 17:13:36 -0400133 callReceiver = new CallReceiver(this);
alision907bde72013-06-20 14:40:37 -0400134
alision58356b72013-06-03 17:13:36 -0400135 setContentView(R.layout.activity_sflphone_home);
136
alision9f7a6ec2013-05-24 16:26:26 -0400137 // Bind to LocalService
138 if (!mBound) {
139 Log.i(TAG, "onStart: Binding service...");
140 Intent intent = new Intent(this, SipService.class);
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400141 startService(intent);
alision9f7a6ec2013-05-24 16:26:26 -0400142 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
143 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400144
145 if (savedInstanceState != null) {
Alexandre Lision23628c12013-09-24 11:17:05 -0400146 mContactsFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, "ContactsListFragment");
147 }
alision9f7a6ec2013-05-24 16:26:26 -0400148 if (mContactsFragment == null) {
149 mContactsFragment = new ContactListFragment();
alision9f7a6ec2013-05-24 16:26:26 -0400150 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
151 }
alision2ec64f92013-06-17 17:28:58 -0400152
alision9f7a6ec2013-05-24 16:26:26 -0400153 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400154
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400155 mDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {
156
157 @Override
158 public void onScrollStarted() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400159 // getActionBar().hide();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400160
161 }
162
163 @Override
164 public void onScrollEnded() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400165 // getActionBar().show();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400166
167 }
168
169 @Override
170 public void onScroll(int offset) {
171 if (offset < 400) {
172 getActionBar().hide();
173 } else if (offset > 450) {
174 getActionBar().show();
175 }
176 }
177 });
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400178
alision84813a12013-05-27 17:40:39 -0400179 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400180
181 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400182
alision9f7a6ec2013-05-24 16:26:26 -0400183 // Set up the ViewPager with the sections adapter.
184 mViewPager = (ViewPager) findViewById(R.id.pager);
alision55c36cb2013-06-14 14:57:38 -0400185 mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f));
alisionf76de3b2013-04-16 15:35:22 -0400186
alision9f7a6ec2013-05-24 16:26:26 -0400187 mTitle = mDrawerTitle = getTitle();
188 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400189
alision0b553832013-05-30 09:31:06 -0400190 // set a custom shadow that overlays the main content when the drawer opens
alision9f7a6ec2013-05-24 16:26:26 -0400191 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400192
alision9f7a6ec2013-05-24 16:26:26 -0400193 getActionBar().setDisplayHomeAsUpEnabled(true);
194 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400195
alision9f7a6ec2013-05-24 16:26:26 -0400196 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
197 mDrawerLayout, /* DrawerLayout object */
198 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
199 R.string.drawer_open, /* "open drawer" description for accessibility */
200 R.string.drawer_close /* "close drawer" description for accessibility */
201 ) {
alision0b553832013-05-30 09:31:06 -0400202 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400203 public void onDrawerClosed(View view) {
204 getActionBar().setTitle(mTitle);
205 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
206 }
alisionf76de3b2013-04-16 15:35:22 -0400207
alision0b553832013-05-30 09:31:06 -0400208 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400209 public void onDrawerOpened(View drawerView) {
210 getActionBar().setTitle(mDrawerTitle);
211 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
212 }
213 };
alisionf76de3b2013-04-16 15:35:22 -0400214
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400215 // mTabHost = (TabHost) findViewById(android.R.id.tabhost);
alision9f7a6ec2013-05-24 16:26:26 -0400216 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400217
alision9f7a6ec2013-05-24 16:26:26 -0400218 }
alisionf76de3b2013-04-16 15:35:22 -0400219
alisionf57d8a62013-07-02 09:37:12 -0400220 @Override
221 protected void onPostCreate(Bundle savedInstanceState) {
222 super.onPostCreate(savedInstanceState);
223 // Sync the toggle state after onRestoreInstanceState has occurred.
224 mDrawerToggle.syncState();
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400225 if (mDrawer.isOpened()) {
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400226 getActionBar().hide();
227 }
alisionf57d8a62013-07-02 09:37:12 -0400228 }
alision465ceba2013-07-04 09:24:30 -0400229
alisionf57d8a62013-07-02 09:37:12 -0400230 @Override
231 public void onConfigurationChanged(Configuration newConfig) {
232 super.onConfigurationChanged(newConfig);
233 mDrawerToggle.onConfigurationChanged(newConfig);
234 }
alision3c5c2a92013-05-30 09:50:47 -0400235
alision9f7a6ec2013-05-24 16:26:26 -0400236 @Override
237 protected void onStart() {
238 Log.i(TAG, "onStart");
239 super.onStart();
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400240
alision9f7a6ec2013-05-24 16:26:26 -0400241 }
alisionf76de3b2013-04-16 15:35:22 -0400242
alision9f7a6ec2013-05-24 16:26:26 -0400243 /* user gets back to the activity, e.g. through task manager */
244 @Override
245 protected void onRestart() {
246 super.onRestart();
247 }
alisionf76de3b2013-04-16 15:35:22 -0400248
alision9f7a6ec2013-05-24 16:26:26 -0400249 /* activity gets back to the foreground and user input */
250 @Override
251 protected void onResume() {
alision58356b72013-06-03 17:13:36 -0400252 super.onResume();
alision84813a12013-05-27 17:40:39 -0400253 IntentFilter intentFilter = new IntentFilter();
254 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
255 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
256 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
alision58356b72013-06-03 17:13:36 -0400257 registerReceiver(callReceiver, intentFilter);
alision907bde72013-06-20 14:40:37 -0400258
alision9f7a6ec2013-05-24 16:26:26 -0400259 }
alision907bde72013-06-20 14:40:37 -0400260
alisionbd45a822013-06-06 17:35:35 -0400261 private boolean isClosing = false;
262 private Timer t = new Timer();
alision907bde72013-06-20 14:40:37 -0400263
alisionbd45a822013-06-06 17:35:35 -0400264 @Override
265 public void onBackPressed() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400266
267 if (mDrawerLayout.isDrawerVisible(Gravity.LEFT)) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400268 mDrawerLayout.closeDrawer(Gravity.LEFT);
Alexandre Lision68855472013-10-10 16:20:46 -0400269 return;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400270 }
alision907bde72013-06-20 14:40:37 -0400271 if (getActionBar().getCustomView() != null) {
alision2ec64f92013-06-17 17:28:58 -0400272 getActionBar().setDisplayShowCustomEnabled(false);
273 getActionBar().setCustomView(null);
274 // Display all the contacts again
275 getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, mContactsFragment);
276 return;
277 }
alision907bde72013-06-20 14:40:37 -0400278
alisionbd45a822013-06-06 17:35:35 -0400279 if (mDrawer.isOpened()) {
alision55c36cb2013-06-14 14:57:38 -0400280 mDrawer.animateClose();
alisionbd45a822013-06-06 17:35:35 -0400281 return;
282 }
alision2ec64f92013-06-17 17:28:58 -0400283
alisionbd45a822013-06-06 17:35:35 -0400284 if (isClosing) {
285 super.onBackPressed();
286 t.cancel();
287 finish();
288 } else {
289
290 t.schedule(new TimerTask() {
291 @Override
292 public void run() {
293 isClosing = false;
294 }
295 }, 3000);
296 Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show();
297 isClosing = true;
298 }
299 }
alisione2a38e12013-04-25 14:20:20 -0400300
alision9f7a6ec2013-05-24 16:26:26 -0400301 /* activity no more in foreground */
302 @Override
303 protected void onPause() {
304 super.onPause();
alision58356b72013-06-03 17:13:36 -0400305 unregisterReceiver(callReceiver);
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400306 if (mBound) {
307 unbindService(mConnection);
308 mBound = false;
309 }
alision9f7a6ec2013-05-24 16:26:26 -0400310 }
alisionf76de3b2013-04-16 15:35:22 -0400311
alision9f7a6ec2013-05-24 16:26:26 -0400312 /* activity finishes itself or is being killed by the system */
313 @Override
314 protected void onDestroy() {
alision9f7a6ec2013-05-24 16:26:26 -0400315 super.onDestroy();
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400316 Log.i(TAG, "onDestroy: destroying service...");
317 Intent sipServiceIntent = new Intent(this, SipService.class);
318 stopService(sipServiceIntent);
alision9f7a6ec2013-05-24 16:26:26 -0400319 }
alision73424b62013-04-26 11:49:18 -0400320
alision55c36cb2013-06-14 14:57:38 -0400321 public void launchCallActivity(SipCall infos) {
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400322
alision9f7a6ec2013-05-24 16:26:26 -0400323 Bundle bundle = new Bundle();
alisiondf1dac92013-06-27 17:35:53 -0400324 Conference tmp = new Conference("-1");
alision465ceba2013-07-04 09:24:30 -0400325
alisiondf1dac92013-06-27 17:35:53 -0400326 tmp.getParticipants().add(infos);
alision465ceba2013-07-04 09:24:30 -0400327
alisiondf1dac92013-06-27 17:35:53 -0400328 bundle.putParcelable("conference", tmp);
alision9f7a6ec2013-05-24 16:26:26 -0400329 Intent intent = new Intent().setClass(this, CallActivity.class);
alisiondf1dac92013-06-27 17:35:53 -0400330 intent.putExtra("resuming", false);
alision9f7a6ec2013-05-24 16:26:26 -0400331 intent.putExtras(bundle);
332 startActivityForResult(intent, REQUEST_CODE_CALL);
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400333
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400334 // overridePendingTransition(R.anim.slide_down, R.anim.slide_up);
alision9f7a6ec2013-05-24 16:26:26 -0400335 }
alisionf76de3b2013-04-16 15:35:22 -0400336
alision9f7a6ec2013-05-24 16:26:26 -0400337 /** Defines callbacks for service binding, passed to bindService() */
338 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400339
alision9f7a6ec2013-05-24 16:26:26 -0400340 @Override
341 public void onServiceConnected(ComponentName className, IBinder binder) {
342 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400343
alision2cb99562013-05-30 17:02:20 -0400344 try {
alision58356b72013-06-03 17:13:36 -0400345
alision907bde72013-06-20 14:40:37 -0400346 fMenu = new MenuFragment();
347 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
alision58356b72013-06-03 17:13:36 -0400348 mSectionsPagerAdapter = new SectionsPagerAdapter(SFLPhoneHomeActivity.this, getFragmentManager());
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400349
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400350 // initialiseTabHost(null);
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
357// strip.setBackgroundColor(getResources().getColor(R.color.sfl_blue_0));
358 strip.setViewPager(mViewPager);
359
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400360 // mTabHost.setCurrentTab(1);
alision2cb99562013-05-30 17:02:20 -0400361 service.destroyNotification();
alision58356b72013-06-03 17:13:36 -0400362 // mAdapter = new AccountSelectionAdapter(SFLPhoneHomeActivity.this, service, new ArrayList<Account>());
363 // spinnerAccounts.setAdapter(mAdapter);
alision2cb99562013-05-30 17:02:20 -0400364 } catch (RemoteException e) {
365 Log.e(TAG, e.toString());
366 }
alision9f7a6ec2013-05-24 16:26:26 -0400367 mBound = true;
alision9f7a6ec2013-05-24 16:26:26 -0400368 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400369
alision9f7a6ec2013-05-24 16:26:26 -0400370 }
alision5f899632013-04-22 17:26:56 -0400371
alision9f7a6ec2013-05-24 16:26:26 -0400372 @Override
373 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400374
alision9f7a6ec2013-05-24 16:26:26 -0400375 mBound = false;
376 Log.d(TAG, "Service disconnected service=" + service);
377 }
378 };
alision5f899632013-04-22 17:26:56 -0400379
alision9f7a6ec2013-05-24 16:26:26 -0400380 @Override
381 public boolean onOptionsItemSelected(MenuItem item) {
382 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400383
alision9f7a6ec2013-05-24 16:26:26 -0400384 if (mDrawerToggle.onOptionsItemSelected(item)) {
385 return true;
386 }
alision5f899632013-04-22 17:26:56 -0400387
alision9f7a6ec2013-05-24 16:26:26 -0400388 return super.onOptionsItemSelected(item);
389 }
alisionf76de3b2013-04-16 15:35:22 -0400390
alision9f7a6ec2013-05-24 16:26:26 -0400391 @Override
392 public void onActivityResult(int requestCode, int resultCode, Intent data) {
393 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400394
395 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400396 case REQUEST_CODE_PREFERENCES:
Alexandre Lisione5b66022013-10-30 11:34:15 -0400397 if (fMenu != null)
Alexandre Lision933ef0a2013-10-15 17:28:40 -0400398 fMenu.updateAllAccounts();
alision9f7a6ec2013-05-24 16:26:26 -0400399 break;
400 case REQUEST_CODE_CALL:
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) {
alisionfde875f2013-05-28 17:01:54 -0400421 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400422
alision58356b72013-06-03 17:13:36 -0400423 // mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400424
alision55c36cb2013-06-14 14:57:38 -0400425 launchCallActivity(infos);
alision84813a12013-05-27 17:40:39 -0400426
427 }
428
429 @Override
430 public void callStateChanged(Intent callState) {
431 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
432 String cID = b.getString("CallID");
433 String state = b.getString("State");
434 Log.i(TAG, "callStateChanged" + cID + " " + state);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400435 mSectionsPagerAdapter.updateHome();
alision84813a12013-05-27 17:40:39 -0400436
437 }
438
439 @Override
440 public void incomingText(Intent msg) {
441 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
442 b.getString("CallID");
443 String from = b.getString("From");
444 String mess = b.getString("Msg");
445 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
446 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400447
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400448 @Override
449 public void onTextContact(final CallContact c) {
450 // TODO
451 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400452
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400453 @Override
454 public void onEditContact(final CallContact c) {
455 Intent intent = new Intent(Intent.ACTION_VIEW);
456 Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId()));
457 intent.setData(uri);
458 startActivity(intent);
459 }
alision84813a12013-05-27 17:40:39 -0400460
461 @Override
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400462 public void onCallContact(final CallContact c) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400463
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400464 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400465 createAccountDialog().show();
466 return;
467 }
alisionfde875f2013-05-28 17:01:54 -0400468
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400469 if (!fMenu.getSelectedAccount().isRegistered()) {
470 createNotRegisteredDialog().show();
471 return;
472 }
473
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400474 getActionBar().show();
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 {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400484 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
alision907bde72013-06-20 14:40:37 -0400485 Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(),
486 null, null);
alision55c36cb2013-06-14 14:57:38 -0400487
alision907bde72013-06-20 14:40:37 -0400488 while (cPhones.moveToNext()) {
489 c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE)));
490 }
491 cPhones.close();
492
493 Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null,
494 null);
495
496 while (cSip.moveToNext()) {
497 c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE)));
498 }
499 cSip.close();
500 callBuilder.setContact(c);
alision55c36cb2013-06-14 14:57:38 -0400501 launchCallActivity(callBuilder.build());
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400502 } catch (InvalidObjectException e) {
503 e.printStackTrace();
alision55c36cb2013-06-14 14:57:38 -0400504 }
alision907bde72013-06-20 14:40:37 -0400505
alision55c36cb2013-06-14 14:57:38 -0400506 }
507 });
508 launcher.start();
509 mDrawer.close();
alision84813a12013-05-27 17:40:39 -0400510
511 }
512
513 @Override
alision907bde72013-06-20 14:40:37 -0400514 public void onCallDialed(String to) {
alision84813a12013-05-27 17:40:39 -0400515
alisiondf1dac92013-06-27 17:35:53 -0400516 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400517 createAccountDialog().show();
alisiondf1dac92013-06-27 17:35:53 -0400518 return;
519 }
520
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400521 if (fMenu.getSelectedAccount().isRegistered()) {
522 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
523 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
524 callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400525
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400526 try {
527 launchCallActivity(callBuilder.build());
528 } catch (Exception e) {
529 Log.e(TAG, e.toString());
530 }
531 } else {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400532 createNotRegisteredDialog().show();
533 ;
alisionfde875f2013-05-28 17:01:54 -0400534 }
alision84813a12013-05-27 17:40:39 -0400535
alision9f7a6ec2013-05-24 16:26:26 -0400536 }
alision371b77e2013-04-23 14:51:26 -0400537
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400538 private AlertDialog createNotRegisteredDialog() {
539 final Activity ownerActivity = this;
540 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
541
542 builder.setMessage(getResources().getString(R.string.cannot_pass_sipcall))
543 .setTitle(getResources().getString(R.string.cannot_pass_sipcall_title))
544 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
545 public void onClick(DialogInterface dialog, int whichButton) {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400546
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400547 }
548 });
549
550 AlertDialog alertDialog = builder.create();
551 alertDialog.setOwnerActivity(ownerActivity);
552
553 return alertDialog;
554 }
555
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400556 private AlertDialog createAccountDialog() {
557 final Activity ownerActivity = this;
558 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
559
560 builder.setMessage(getResources().getString(R.string.create_new_account_dialog))
561 .setTitle(getResources().getString(R.string.create_new_account_dialog_title))
562 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
563 public void onClick(DialogInterface dialog, int whichButton) {
564 Intent in = new Intent();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400565 in.setClass(ownerActivity, AccountWizard.class);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400566 ownerActivity.startActivityForResult(in, SFLPhoneHomeActivity.REQUEST_CODE_PREFERENCES);
567 }
568 }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
569 public void onClick(DialogInterface dialog, int whichButton) {
570 dialog.dismiss();
571 }
572 });
573
574 AlertDialog alertDialog = builder.create();
575 alertDialog.setOwnerActivity(ownerActivity);
576
577 return alertDialog;
578 }
579
alisiond45da712013-05-30 09:18:49 -0400580 @Override
581 public void onContactDragged() {
alisiond45da712013-05-30 09:18:49 -0400582 mDrawer.close();
alisiond45da712013-05-30 09:18:49 -0400583 }
584
alision58356b72013-06-03 17:13:36 -0400585 @Override
586 public void openDrawer() {
alision55c36cb2013-06-14 14:57:38 -0400587 mDrawer.animateOpen();
alision58356b72013-06-03 17:13:36 -0400588 }
589
alision806e18e2013-06-21 15:30:17 -0400590 @Override
591 public void confCreated(Intent intent) {
592 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400593
alision806e18e2013-06-21 15:30:17 -0400594 }
595
596 @Override
597 public void confRemoved(Intent intent) {
598 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400599
alision806e18e2013-06-21 15:30:17 -0400600 }
601
602 @Override
603 public void confChanged(Intent intent) {
604 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400605
606 }
607
608 @Override
609 public void recordingChanged(Intent intent) {
610 // TODO Auto-generated method stub
611
612 }
613
614 @Override
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400615 public void selectedCall(Conference c) {
alisiondf1dac92013-06-27 17:35:53 -0400616 Intent intent = new Intent().setClass(this, CallActivity.class);
617 intent.putExtra("resuming", true);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400618 intent.putExtra("conference", c);
alisiondf1dac92013-06-27 17:35:53 -0400619 startActivityForResult(intent, REQUEST_CODE_CALL);
alision806e18e2013-06-21 15:30:17 -0400620 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400621
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400622 private class ZoomOutPageTransformer implements ViewPager.PageTransformer {
623 private static final float MIN_ALPHA = .6f;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400624
625 // private final float scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400626
627 public ZoomOutPageTransformer(float scalingStart) {
628 super();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400629 // this.scalingStart = 1 - scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400630 }
631
632 @Override
633 public void transformPage(View page, float position) {
634 // page.setRotationY(position * -30);
635 final float normalizedposition = Math.abs(Math.abs(position) - 1);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400636 page.setAlpha(MIN_ALPHA + (1.f - MIN_ALPHA) * normalizedposition);
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400637 }
638 }
alision806e18e2013-06-21 15:30:17 -0400639
alisionf76de3b2013-04-16 15:35:22 -0400640}