blob: 854420f8ff560f7bb6e4560383e2336b511b9fed [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;
Alexandre Lision064e1e02013-10-01 16:18:42 -040046import org.sflphone.model.CallContact;
47import org.sflphone.model.Conference;
48import org.sflphone.model.SipCall;
49import org.sflphone.receivers.CallReceiver;
50import org.sflphone.service.CallManagerCallBack;
51import org.sflphone.service.ISipService;
52import org.sflphone.service.SipService;
Alexandre Lisione5b66022013-10-30 11:34:15 -040053import org.sflphone.views.PagerSlidingTabStrip;
Alexandre Lision450458a2013-11-22 11:33:12 -050054import org.sflphone.views.SlidingUpPanelLayout;
55import org.sflphone.views.SlidingUpPanelLayout.PanelSlideListener;
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 Lision450458a2013-11-22 11:33:12 -050067import android.graphics.Color;
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 Lision450458a2013-11-22 11:33:12 -0500106 SlidingUpPanelLayout mContactDrawer;
Alexandre Lision68900052013-11-01 11:34:56 -0400107 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
alision9f7a6ec2013-05-24 16:26:26 -0400119 /* called before activity is killed, e.g. rotation */
120 @Override
121 protected void onSaveInstanceState(Bundle bundle) {
122 super.onSaveInstanceState(bundle);
alision9f7a6ec2013-05-24 16:26:26 -0400123 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
124 Log.w(TAG, "onSaveInstanceState()");
125 }
126
127 @Override
128 public void onCreate(Bundle savedInstanceState) {
129 super.onCreate(savedInstanceState);
130
alision58356b72013-06-03 17:13:36 -0400131 callReceiver = new CallReceiver(this);
alision907bde72013-06-20 14:40:37 -0400132
alision58356b72013-06-03 17:13:36 -0400133 setContentView(R.layout.activity_sflphone_home);
134
alision9f7a6ec2013-05-24 16:26:26 -0400135 // Bind to LocalService
136 if (!mBound) {
137 Log.i(TAG, "onStart: Binding service...");
138 Intent intent = new Intent(this, SipService.class);
Alexandre Lision0f550ee2013-10-25 15:34:38 -0400139 startService(intent);
alision9f7a6ec2013-05-24 16:26:26 -0400140 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
Alexandre Lision450458a2013-11-22 11:33:12 -0500151 mContactDrawer = (SlidingUpPanelLayout) findViewById(R.id.contact_panel);
152 // mContactDrawer.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow));
153 mContactDrawer.setAnchorPoint(0.3f);
154 mContactDrawer.setDragView(findViewById(R.id.contacts_frame));
155 mContactDrawer.setEnableDragViewTouchEvents(true);
156// mContactDrawer.setCoveredFadeColor(0xff000000);
157 mContactDrawer.setPanelSlideListener(new PanelSlideListener() {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400158
159 @Override
Alexandre Lision450458a2013-11-22 11:33:12 -0500160 public void onPanelSlide(View panel, float slideOffset) {
161 if (slideOffset < 0.2) {
162 if (getActionBar().isShowing()) {
163 getActionBar().hide();
164 }
165 } else {
166 if (!getActionBar().isShowing()) {
167 getActionBar().show();
168 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400169 }
170 }
Alexandre Lision450458a2013-11-22 11:33:12 -0500171
172 @Override
173 public void onPanelExpanded(View panel) {
174
175 }
176
177 @Override
178 public void onPanelCollapsed(View panel) {
179
180 }
181
182 @Override
183 public void onPanelAnchored(View panel) {
184
185 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400186 });
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400187
Alexandre Lision450458a2013-11-22 11:33:12 -0500188 // TODO
189 // mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400190 mShadow = (ImageView) findViewById(R.id.overall_shadow);
alisionf76de3b2013-04-16 15:35:22 -0400191
alision9f7a6ec2013-05-24 16:26:26 -0400192 // Set up the ViewPager with the sections adapter.
193 mViewPager = (ViewPager) findViewById(R.id.pager);
alision55c36cb2013-06-14 14:57:38 -0400194 mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f));
alisionf76de3b2013-04-16 15:35:22 -0400195
alision9f7a6ec2013-05-24 16:26:26 -0400196 mTitle = mDrawerTitle = getTitle();
Alexandre Lision68900052013-11-01 11:34:56 -0400197 mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400198
alision0b553832013-05-30 09:31:06 -0400199 // set a custom shadow that overlays the main content when the drawer opens
Alexandre Lision68900052013-11-01 11:34:56 -0400200 mNavigationDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400201
alision9f7a6ec2013-05-24 16:26:26 -0400202 getActionBar().setDisplayHomeAsUpEnabled(true);
203 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400204
alision9f7a6ec2013-05-24 16:26:26 -0400205 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
Alexandre Lision68900052013-11-01 11:34:56 -0400206 mNavigationDrawer, /* DrawerLayout object */
alision9f7a6ec2013-05-24 16:26:26 -0400207 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
208 R.string.drawer_open, /* "open drawer" description for accessibility */
209 R.string.drawer_close /* "close drawer" description for accessibility */
210 ) {
alision0b553832013-05-30 09:31:06 -0400211 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400212 public void onDrawerClosed(View view) {
213 getActionBar().setTitle(mTitle);
214 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
215 }
alisionf76de3b2013-04-16 15:35:22 -0400216
alision0b553832013-05-30 09:31:06 -0400217 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400218 public void onDrawerOpened(View drawerView) {
219 getActionBar().setTitle(mDrawerTitle);
220 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
221 }
222 };
alisionf76de3b2013-04-16 15:35:22 -0400223
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400224 // mTabHost = (TabHost) findViewById(android.R.id.tabhost);
Alexandre Lision68900052013-11-01 11:34:56 -0400225 mNavigationDrawer.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400226
alision9f7a6ec2013-05-24 16:26:26 -0400227 }
alisionf76de3b2013-04-16 15:35:22 -0400228
alisionf57d8a62013-07-02 09:37:12 -0400229 @Override
230 protected void onPostCreate(Bundle savedInstanceState) {
231 super.onPostCreate(savedInstanceState);
232 // Sync the toggle state after onRestoreInstanceState has occurred.
233 mDrawerToggle.syncState();
Alexandre Lision450458a2013-11-22 11:33:12 -0500234 if (mContactDrawer.isExpanded()) {
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400235 getActionBar().hide();
236 }
alisionf57d8a62013-07-02 09:37:12 -0400237 }
alision465ceba2013-07-04 09:24:30 -0400238
alisionf57d8a62013-07-02 09:37:12 -0400239 @Override
240 public void onConfigurationChanged(Configuration newConfig) {
241 super.onConfigurationChanged(newConfig);
242 mDrawerToggle.onConfigurationChanged(newConfig);
243 }
alision3c5c2a92013-05-30 09:50:47 -0400244
alision9f7a6ec2013-05-24 16:26:26 -0400245 @Override
246 protected void onStart() {
247 Log.i(TAG, "onStart");
248 super.onStart();
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400249
alision9f7a6ec2013-05-24 16:26:26 -0400250 }
alisionf76de3b2013-04-16 15:35:22 -0400251
alision9f7a6ec2013-05-24 16:26:26 -0400252 /* user gets back to the activity, e.g. through task manager */
253 @Override
254 protected void onRestart() {
255 super.onRestart();
256 }
alisionf76de3b2013-04-16 15:35:22 -0400257
alision9f7a6ec2013-05-24 16:26:26 -0400258 /* activity gets back to the foreground and user input */
259 @Override
260 protected void onResume() {
alision58356b72013-06-03 17:13:36 -0400261 super.onResume();
alision84813a12013-05-27 17:40:39 -0400262 IntentFilter intentFilter = new IntentFilter();
263 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
264 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
265 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
alision58356b72013-06-03 17:13:36 -0400266 registerReceiver(callReceiver, intentFilter);
alision907bde72013-06-20 14:40:37 -0400267
alision9f7a6ec2013-05-24 16:26:26 -0400268 }
alision907bde72013-06-20 14:40:37 -0400269
alisionbd45a822013-06-06 17:35:35 -0400270 @Override
271 public void onBackPressed() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400272
Alexandre Lision68900052013-11-01 11:34:56 -0400273 if (mNavigationDrawer.isDrawerVisible(Gravity.LEFT)) {
274 mNavigationDrawer.closeDrawer(Gravity.LEFT);
Alexandre Lision68855472013-10-10 16:20:46 -0400275 return;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400276 }
alision907bde72013-06-20 14:40:37 -0400277
Alexandre Lision450458a2013-11-22 11:33:12 -0500278 if (mContactDrawer.isExpanded() || mContactDrawer.isAnchored()) {
279 mContactDrawer.collapsePane();
alisionbd45a822013-06-06 17:35:35 -0400280 return;
281 }
alision2ec64f92013-06-17 17:28:58 -0400282
alisionbd45a822013-06-06 17:35:35 -0400283 if (isClosing) {
284 super.onBackPressed();
285 t.cancel();
286 finish();
287 } else {
288
289 t.schedule(new TimerTask() {
290 @Override
291 public void run() {
292 isClosing = false;
293 }
294 }, 3000);
295 Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show();
296 isClosing = true;
297 }
298 }
alisione2a38e12013-04-25 14:20:20 -0400299
alision9f7a6ec2013-05-24 16:26:26 -0400300 /* activity no more in foreground */
301 @Override
302 protected void onPause() {
303 super.onPause();
alision58356b72013-06-03 17:13:36 -0400304 unregisterReceiver(callReceiver);
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400305 if (mBound) {
306 unbindService(mConnection);
307 mBound = false;
308 }
alision9f7a6ec2013-05-24 16:26:26 -0400309 }
alisionf76de3b2013-04-16 15:35:22 -0400310
alision9f7a6ec2013-05-24 16:26:26 -0400311 /* activity finishes itself or is being killed by the system */
312 @Override
313 protected void onDestroy() {
alision9f7a6ec2013-05-24 16:26:26 -0400314 super.onDestroy();
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400315 Log.i(TAG, "onDestroy: destroying service...");
316 Intent sipServiceIntent = new Intent(this, SipService.class);
317 stopService(sipServiceIntent);
alision9f7a6ec2013-05-24 16:26:26 -0400318 }
alision73424b62013-04-26 11:49:18 -0400319
alision55c36cb2013-06-14 14:57:38 -0400320 public void launchCallActivity(SipCall infos) {
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400321
alision9f7a6ec2013-05-24 16:26:26 -0400322 Bundle bundle = new Bundle();
alisiondf1dac92013-06-27 17:35:53 -0400323 Conference tmp = new Conference("-1");
alision465ceba2013-07-04 09:24:30 -0400324
alisiondf1dac92013-06-27 17:35:53 -0400325 tmp.getParticipants().add(infos);
alision465ceba2013-07-04 09:24:30 -0400326
alisiondf1dac92013-06-27 17:35:53 -0400327 bundle.putParcelable("conference", tmp);
alision9f7a6ec2013-05-24 16:26:26 -0400328 Intent intent = new Intent().setClass(this, CallActivity.class);
alisiondf1dac92013-06-27 17:35:53 -0400329 intent.putExtra("resuming", false);
alision9f7a6ec2013-05-24 16:26:26 -0400330 intent.putExtras(bundle);
331 startActivityForResult(intent, REQUEST_CODE_CALL);
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400332
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400333 // overridePendingTransition(R.anim.slide_down, R.anim.slide_up);
alision9f7a6ec2013-05-24 16:26:26 -0400334 }
alisionf76de3b2013-04-16 15:35:22 -0400335
alision9f7a6ec2013-05-24 16:26:26 -0400336 /** Defines callbacks for service binding, passed to bindService() */
337 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400338
alision9f7a6ec2013-05-24 16:26:26 -0400339 @Override
340 public void onServiceConnected(ComponentName className, IBinder binder) {
341 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400342
alision2cb99562013-05-30 17:02:20 -0400343 try {
alision58356b72013-06-03 17:13:36 -0400344
alision907bde72013-06-20 14:40:37 -0400345 fMenu = new MenuFragment();
346 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
Alexandre Lision4ab53972013-11-04 16:59:18 -0500347 mSectionsPagerAdapter = new SectionsPagerAdapter(HomeActivity.this, getFragmentManager());
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400348
alisiondf1dac92013-06-27 17:35:53 -0400349 mViewPager.setOffscreenPageLimit(2);
alision58356b72013-06-03 17:13:36 -0400350 mViewPager.setAdapter(mSectionsPagerAdapter);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400351 mViewPager.setCurrentItem(1);
Alexandre Lisione5b66022013-10-30 11:34:15 -0400352
353 final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(findViewById(R.id.pts_main));
354
Alexandre Lisione5b66022013-10-30 11:34:15 -0400355 strip.setViewPager(mViewPager);
alision2cb99562013-05-30 17:02:20 -0400356 service.destroyNotification();
357 } catch (RemoteException e) {
358 Log.e(TAG, e.toString());
359 }
alision9f7a6ec2013-05-24 16:26:26 -0400360 mBound = true;
alision9f7a6ec2013-05-24 16:26:26 -0400361 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400362
alision9f7a6ec2013-05-24 16:26:26 -0400363 }
alision5f899632013-04-22 17:26:56 -0400364
alision9f7a6ec2013-05-24 16:26:26 -0400365 @Override
366 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400367
alision9f7a6ec2013-05-24 16:26:26 -0400368 mBound = false;
369 Log.d(TAG, "Service disconnected service=" + service);
370 }
371 };
alision5f899632013-04-22 17:26:56 -0400372
alision9f7a6ec2013-05-24 16:26:26 -0400373 @Override
374 public boolean onOptionsItemSelected(MenuItem item) {
375 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400376
alision9f7a6ec2013-05-24 16:26:26 -0400377 if (mDrawerToggle.onOptionsItemSelected(item)) {
378 return true;
379 }
alision5f899632013-04-22 17:26:56 -0400380
alision9f7a6ec2013-05-24 16:26:26 -0400381 return super.onOptionsItemSelected(item);
382 }
alisionf76de3b2013-04-16 15:35:22 -0400383
alision9f7a6ec2013-05-24 16:26:26 -0400384 @Override
385 public void onActivityResult(int requestCode, int resultCode, Intent data) {
386 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400387
388 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400389 case REQUEST_CODE_PREFERENCES:
Alexandre Lisione5b66022013-10-30 11:34:15 -0400390 if (fMenu != null)
Alexandre Lision933ef0a2013-10-15 17:28:40 -0400391 fMenu.updateAllAccounts();
alision9f7a6ec2013-05-24 16:26:26 -0400392 break;
393 case REQUEST_CODE_CALL:
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400394 if (resultCode == CallActivity.RESULT_FAILURE) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400395 Log.w(TAG, "Call Failed");
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400396 }
397 // if (mSectionsPagerAdapter != null && mSectionsPagerAdapter.getItem(2) != null)
398 // getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, (HistoryFragment) mSectionsPagerAdapter.getItem(2));
alision9f7a6ec2013-05-24 16:26:26 -0400399 break;
400 }
alisionf76de3b2013-04-16 15:35:22 -0400401
alision9f7a6ec2013-05-24 16:26:26 -0400402 }
alisionf76de3b2013-04-16 15:35:22 -0400403
alision9f7a6ec2013-05-24 16:26:26 -0400404 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400405 public ISipService getService() {
406 return service;
407 }
alisionf76de3b2013-04-16 15:35:22 -0400408
alision84813a12013-05-27 17:40:39 -0400409 /**
410 * Interface implemented to handle incoming events
411 */
alision9f7a6ec2013-05-24 16:26:26 -0400412 @Override
alision84813a12013-05-27 17:40:39 -0400413 public void incomingCall(Intent call) {
alisionfde875f2013-05-28 17:01:54 -0400414 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400415
alision58356b72013-06-03 17:13:36 -0400416 // mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400417
alision55c36cb2013-06-14 14:57:38 -0400418 launchCallActivity(infos);
alision84813a12013-05-27 17:40:39 -0400419
420 }
421
422 @Override
423 public void callStateChanged(Intent callState) {
424 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
425 String cID = b.getString("CallID");
426 String state = b.getString("State");
427 Log.i(TAG, "callStateChanged" + cID + " " + state);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400428 mSectionsPagerAdapter.updateHome();
alision84813a12013-05-27 17:40:39 -0400429
430 }
431
432 @Override
433 public void incomingText(Intent msg) {
434 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
435 b.getString("CallID");
436 String from = b.getString("From");
437 String mess = b.getString("Msg");
438 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
439 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400440
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400441 @Override
442 public void onTextContact(final CallContact c) {
443 // TODO
444 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400445
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400446 @Override
447 public void onEditContact(final CallContact c) {
448 Intent intent = new Intent(Intent.ACTION_VIEW);
449 Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId()));
450 intent.setData(uri);
451 startActivity(intent);
452 }
alision84813a12013-05-27 17:40:39 -0400453
454 @Override
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400455 public void onCallContact(final CallContact c) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400456
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400457 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400458 createAccountDialog().show();
459 return;
460 }
alisionfde875f2013-05-28 17:01:54 -0400461
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400462 if (!fMenu.getSelectedAccount().isRegistered()) {
463 createNotRegisteredDialog().show();
464 return;
465 }
466
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400467 getActionBar().show();
alision55c36cb2013-06-14 14:57:38 -0400468 Thread launcher = new Thread(new Runnable() {
alision907bde72013-06-20 14:40:37 -0400469
alision55c36cb2013-06-14 14:57:38 -0400470 final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
471 final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
alision907bde72013-06-20 14:40:37 -0400472
alision55c36cb2013-06-14 14:57:38 -0400473 @Override
474 public void run() {
475 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
476 try {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400477 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
alision907bde72013-06-20 14:40:37 -0400478 Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(),
479 null, null);
alision55c36cb2013-06-14 14:57:38 -0400480
alision907bde72013-06-20 14:40:37 -0400481 while (cPhones.moveToNext()) {
482 c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE)));
483 }
484 cPhones.close();
485
486 Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null,
487 null);
488
489 while (cSip.moveToNext()) {
490 c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE)));
491 }
492 cSip.close();
493 callBuilder.setContact(c);
alision55c36cb2013-06-14 14:57:38 -0400494 launchCallActivity(callBuilder.build());
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400495 } catch (InvalidObjectException e) {
496 e.printStackTrace();
alision55c36cb2013-06-14 14:57:38 -0400497 }
alision907bde72013-06-20 14:40:37 -0400498
alision55c36cb2013-06-14 14:57:38 -0400499 }
500 });
501 launcher.start();
Alexandre Lision450458a2013-11-22 11:33:12 -0500502 mContactDrawer.collapsePane();
alision84813a12013-05-27 17:40:39 -0400503
504 }
505
506 @Override
alision907bde72013-06-20 14:40:37 -0400507 public void onCallDialed(String to) {
alision84813a12013-05-27 17:40:39 -0400508
alisiondf1dac92013-06-27 17:35:53 -0400509 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400510 createAccountDialog().show();
alisiondf1dac92013-06-27 17:35:53 -0400511 return;
512 }
513
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400514 if (fMenu.getSelectedAccount().isRegistered()) {
515 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
516 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
517 callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400518
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400519 try {
520 launchCallActivity(callBuilder.build());
521 } catch (Exception e) {
522 Log.e(TAG, e.toString());
523 }
524 } else {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400525 createNotRegisteredDialog().show();
526 ;
alisionfde875f2013-05-28 17:01:54 -0400527 }
alision84813a12013-05-27 17:40:39 -0400528
alision9f7a6ec2013-05-24 16:26:26 -0400529 }
alision371b77e2013-04-23 14:51:26 -0400530
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400531 private AlertDialog createNotRegisteredDialog() {
532 final Activity ownerActivity = this;
533 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
534
535 builder.setMessage(getResources().getString(R.string.cannot_pass_sipcall))
536 .setTitle(getResources().getString(R.string.cannot_pass_sipcall_title))
537 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
538 public void onClick(DialogInterface dialog, int whichButton) {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400539
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400540 }
541 });
542
543 AlertDialog alertDialog = builder.create();
544 alertDialog.setOwnerActivity(ownerActivity);
545
546 return alertDialog;
547 }
548
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400549 private AlertDialog createAccountDialog() {
550 final Activity ownerActivity = this;
551 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
552
553 builder.setMessage(getResources().getString(R.string.create_new_account_dialog))
554 .setTitle(getResources().getString(R.string.create_new_account_dialog_title))
555 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
556 public void onClick(DialogInterface dialog, int whichButton) {
557 Intent in = new Intent();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400558 in.setClass(ownerActivity, AccountWizard.class);
Alexandre Lision4ab53972013-11-04 16:59:18 -0500559 ownerActivity.startActivityForResult(in, HomeActivity.REQUEST_CODE_PREFERENCES);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400560 }
561 }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
562 public void onClick(DialogInterface dialog, int whichButton) {
563 dialog.dismiss();
564 }
565 });
566
567 AlertDialog alertDialog = builder.create();
568 alertDialog.setOwnerActivity(ownerActivity);
569
570 return alertDialog;
571 }
572
alisiond45da712013-05-30 09:18:49 -0400573 @Override
574 public void onContactDragged() {
Alexandre Lision450458a2013-11-22 11:33:12 -0500575 mContactDrawer.collapsePane();
alisiond45da712013-05-30 09:18:49 -0400576 }
577
alision58356b72013-06-03 17:13:36 -0400578 @Override
579 public void openDrawer() {
Alexandre Lision450458a2013-11-22 11:33:12 -0500580 mContactDrawer.expandPane();
alision58356b72013-06-03 17:13:36 -0400581 }
582
alision806e18e2013-06-21 15:30:17 -0400583 @Override
584 public void confCreated(Intent intent) {
585 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400586
alision806e18e2013-06-21 15:30:17 -0400587 }
588
589 @Override
590 public void confRemoved(Intent intent) {
591 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400592
alision806e18e2013-06-21 15:30:17 -0400593 }
594
595 @Override
596 public void confChanged(Intent intent) {
597 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400598
599 }
600
601 @Override
602 public void recordingChanged(Intent intent) {
603 // TODO Auto-generated method stub
604
605 }
606
607 @Override
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400608 public void selectedCall(Conference c) {
alisiondf1dac92013-06-27 17:35:53 -0400609 Intent intent = new Intent().setClass(this, CallActivity.class);
610 intent.putExtra("resuming", true);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400611 intent.putExtra("conference", c);
alisiondf1dac92013-06-27 17:35:53 -0400612 startActivityForResult(intent, REQUEST_CODE_CALL);
alision806e18e2013-06-21 15:30:17 -0400613 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400614
Alexandre Lision3f1aa682013-11-18 10:49:28 -0500615 public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400616 private static final float MIN_ALPHA = .6f;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400617
618 // private final float scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400619
620 public ZoomOutPageTransformer(float scalingStart) {
621 super();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400622 // this.scalingStart = 1 - scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400623 }
624
625 @Override
626 public void transformPage(View page, float position) {
627 // page.setRotationY(position * -30);
628 final float normalizedposition = Math.abs(Math.abs(position) - 1);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400629 page.setAlpha(MIN_ALPHA + (1.f - MIN_ALPHA) * normalizedposition);
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400630 }
631 }
alision806e18e2013-06-21 15:30:17 -0400632
alisionf76de3b2013-04-16 15:35:22 -0400633}