blob: 8550aa8d2425abd6ede1c8fb9218c1ec07e5b226 [file] [log] [blame]
alisionf76de3b2013-04-16 15:35:22 -04001/*
alision2ec64f92013-06-17 17:28:58 -04002 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
alisionf76de3b2013-04-16 15:35:22 -04003 *
4 * Author: Adrien Beraud <adrien.beraud@gmail.com>
alision11e8e162013-05-28 10:33:14 -04005 * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
alisionf76de3b2013-04-16 15:35:22 -04006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * Additional permission under GNU GPL version 3 section 7:
22 *
23 * If you modify this program, or any covered work, by linking or
24 * combining it with the OpenSSL project's OpenSSL library (or a
25 * modified version of that library), containing parts covered by the
26 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
27 * grants you additional permission to convey the resulting work.
28 * Corresponding Source for a non-source form of such a combination
29 * shall include the source code for the parts of OpenSSL used as well
30 * as that of the covered work.
31 */
Alexandre Lision064e1e02013-10-01 16:18:42 -040032package org.sflphone.client;
alisionf76de3b2013-04-16 15:35:22 -040033
Alexandre Lision5ed2c972013-10-11 15:36:33 -040034import java.io.InvalidObjectException;
alisionbd45a822013-06-06 17:35:35 -040035import java.util.Timer;
36import java.util.TimerTask;
alision84813a12013-05-27 17:40:39 -040037
Alexandre Lision064e1e02013-10-01 16:18:42 -040038import org.sflphone.R;
39import org.sflphone.adapters.SectionsPagerAdapter;
40import org.sflphone.fragments.ContactListFragment;
41import org.sflphone.fragments.DialingFragment;
42import org.sflphone.fragments.HistoryFragment;
43import org.sflphone.fragments.HomeFragment;
44import org.sflphone.fragments.MenuFragment;
45import org.sflphone.interfaces.CallInterface;
46import org.sflphone.loaders.LoaderConstants;
47import org.sflphone.model.CallContact;
48import org.sflphone.model.Conference;
49import org.sflphone.model.SipCall;
50import org.sflphone.receivers.CallReceiver;
51import org.sflphone.service.CallManagerCallBack;
52import org.sflphone.service.ISipService;
53import org.sflphone.service.SipService;
54import org.sflphone.views.CustomSlidingDrawer;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -040055import org.sflphone.views.CustomSlidingDrawer.OnDrawerScrollListener;
Alexandre Lisione5b66022013-10-30 11:34:15 -040056import org.sflphone.views.PagerSlidingTabStrip;
Alexandre Lision064e1e02013-10-01 16:18:42 -040057
alisionf76de3b2013-04-16 15:35:22 -040058import android.app.Activity;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040059import android.app.AlertDialog;
alisionf76de3b2013-04-16 15:35:22 -040060import android.content.ComponentName;
61import android.content.Context;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040062import android.content.DialogInterface;
alisionf76de3b2013-04-16 15:35:22 -040063import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040064import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040065import android.content.ServiceConnection;
alisionf57d8a62013-07-02 09:37:12 -040066import android.content.res.Configuration;
alision55c36cb2013-06-14 14:57:38 -040067import android.database.Cursor;
Alexandre Lisionc59685a2013-10-04 16:36:36 -040068import android.net.Uri;
alisionf76de3b2013-04-16 15:35:22 -040069import android.os.Bundle;
70import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040071import android.os.RemoteException;
Alexandre Lisionc59685a2013-10-04 16:36:36 -040072import android.provider.ContactsContract;
alision55c36cb2013-06-14 14:57:38 -040073import android.provider.ContactsContract.CommonDataKinds.Phone;
74import android.provider.ContactsContract.CommonDataKinds.SipAddress;
alision9f7a6ec2013-05-24 16:26:26 -040075import android.support.v4.app.ActionBarDrawerToggle;
76import android.support.v4.view.GravityCompat;
alisionf76de3b2013-04-16 15:35:22 -040077import android.support.v4.view.ViewPager;
alision9f7a6ec2013-05-24 16:26:26 -040078import android.support.v4.widget.DrawerLayout;
alisionf76de3b2013-04-16 15:35:22 -040079import android.util.Log;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040080import android.view.Gravity;
alision9f7a6ec2013-05-24 16:26:26 -040081import android.view.MenuItem;
82import android.view.View;
Alexandre Lision68900052013-11-01 11:34:56 -040083import android.widget.ImageView;
alision7297bdb2013-05-21 11:56:55 -040084import android.widget.RelativeLayout;
alision04a00182013-05-10 17:05:29 -040085import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040086
Alexandre Lision4ab53972013-11-04 16:59:18 -050087public class HomeActivity extends Activity implements DialingFragment.Callbacks, ContactListFragment.Callbacks, HomeFragment.Callbacks,
alision907bde72013-06-20 14:40:37 -040088 HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks {
alisionfde875f2013-05-28 17:01:54 -040089
alision9f7a6ec2013-05-24 16:26:26 -040090 SectionsPagerAdapter mSectionsPagerAdapter = null;
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;
Alexandre Lision68900052013-11-01 11:34:56 -0400106 CustomSlidingDrawer mContactDrawer;
107 private DrawerLayout mNavigationDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400108 private ActionBarDrawerToggle mDrawerToggle;
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400109 ImageView mShadow;
alision9f7a6ec2013-05-24 16:26:26 -0400110 /**
111 * The {@link ViewPager} that will host the section contents.
112 */
113 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400114
alision58356b72013-06-03 17:13:36 -0400115 CallReceiver callReceiver;
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
Alexandre Lision68900052013-11-01 11:34:56 -0400153 mContactDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400154
Alexandre Lision68900052013-11-01 11:34:56 -0400155 mContactDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400156
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 Lisionc87763a2013-11-01 12:53:38 -0400165 if (!mContactDrawer.isOpened()) {
166 mShadow.setAlpha(0f);
167 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400168 }
169
170 @Override
171 public void onScroll(int offset) {
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400172
173 float relativeOffset = offset + getResources().getDimension(R.dimen.contact_drawer_handle_height);
174 float alpha = 1 - (((float) relativeOffset) / ((float) getResources().getDisplayMetrics().heightPixels));
175 mShadow.setAlpha(alpha);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400176 if (offset < 400) {
177 getActionBar().hide();
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400178 // mNavigationDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400179 } else if (offset > 450) {
180 getActionBar().show();
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400181 // mNavigationDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400182 }
183 }
184 });
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400185
alision84813a12013-05-27 17:40:39 -0400186 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
Alexandre Lisionc87763a2013-11-01 12:53:38 -0400187 mShadow = (ImageView) findViewById(R.id.overall_shadow);
Alexandre Lision68900052013-11-01 11:34:56 -0400188 mContactDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400189
alision9f7a6ec2013-05-24 16:26:26 -0400190 // Set up the ViewPager with the sections adapter.
191 mViewPager = (ViewPager) findViewById(R.id.pager);
alision55c36cb2013-06-14 14:57:38 -0400192 mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f));
alisionf76de3b2013-04-16 15:35:22 -0400193
alision9f7a6ec2013-05-24 16:26:26 -0400194 mTitle = mDrawerTitle = getTitle();
Alexandre Lision68900052013-11-01 11:34:56 -0400195 mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400196
alision0b553832013-05-30 09:31:06 -0400197 // set a custom shadow that overlays the main content when the drawer opens
Alexandre Lision68900052013-11-01 11:34:56 -0400198 mNavigationDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400199
alision9f7a6ec2013-05-24 16:26:26 -0400200 getActionBar().setDisplayHomeAsUpEnabled(true);
201 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400202
alision9f7a6ec2013-05-24 16:26:26 -0400203 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
Alexandre Lision68900052013-11-01 11:34:56 -0400204 mNavigationDrawer, /* DrawerLayout object */
alision9f7a6ec2013-05-24 16:26:26 -0400205 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
206 R.string.drawer_open, /* "open drawer" description for accessibility */
207 R.string.drawer_close /* "close drawer" description for accessibility */
208 ) {
alision0b553832013-05-30 09:31:06 -0400209 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400210 public void onDrawerClosed(View view) {
211 getActionBar().setTitle(mTitle);
212 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
213 }
alisionf76de3b2013-04-16 15:35:22 -0400214
alision0b553832013-05-30 09:31:06 -0400215 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400216 public void onDrawerOpened(View drawerView) {
217 getActionBar().setTitle(mDrawerTitle);
218 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
219 }
220 };
alisionf76de3b2013-04-16 15:35:22 -0400221
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400222 // mTabHost = (TabHost) findViewById(android.R.id.tabhost);
Alexandre Lision68900052013-11-01 11:34:56 -0400223 mNavigationDrawer.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400224
alision9f7a6ec2013-05-24 16:26:26 -0400225 }
alisionf76de3b2013-04-16 15:35:22 -0400226
alisionf57d8a62013-07-02 09:37:12 -0400227 @Override
228 protected void onPostCreate(Bundle savedInstanceState) {
229 super.onPostCreate(savedInstanceState);
230 // Sync the toggle state after onRestoreInstanceState has occurred.
231 mDrawerToggle.syncState();
Alexandre Lision68900052013-11-01 11:34:56 -0400232 if (mContactDrawer.isOpened()) {
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400233 getActionBar().hide();
234 }
alisionf57d8a62013-07-02 09:37:12 -0400235 }
alision465ceba2013-07-04 09:24:30 -0400236
alisionf57d8a62013-07-02 09:37:12 -0400237 @Override
238 public void onConfigurationChanged(Configuration newConfig) {
239 super.onConfigurationChanged(newConfig);
240 mDrawerToggle.onConfigurationChanged(newConfig);
241 }
alision3c5c2a92013-05-30 09:50:47 -0400242
alision9f7a6ec2013-05-24 16:26:26 -0400243 @Override
244 protected void onStart() {
245 Log.i(TAG, "onStart");
246 super.onStart();
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400247
alision9f7a6ec2013-05-24 16:26:26 -0400248 }
alisionf76de3b2013-04-16 15:35:22 -0400249
alision9f7a6ec2013-05-24 16:26:26 -0400250 /* user gets back to the activity, e.g. through task manager */
251 @Override
252 protected void onRestart() {
253 super.onRestart();
254 }
alisionf76de3b2013-04-16 15:35:22 -0400255
alision9f7a6ec2013-05-24 16:26:26 -0400256 /* activity gets back to the foreground and user input */
257 @Override
258 protected void onResume() {
alision58356b72013-06-03 17:13:36 -0400259 super.onResume();
alision84813a12013-05-27 17:40:39 -0400260 IntentFilter intentFilter = new IntentFilter();
261 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
262 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
263 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
alision58356b72013-06-03 17:13:36 -0400264 registerReceiver(callReceiver, intentFilter);
alision907bde72013-06-20 14:40:37 -0400265
alision9f7a6ec2013-05-24 16:26:26 -0400266 }
alision907bde72013-06-20 14:40:37 -0400267
alisionbd45a822013-06-06 17:35:35 -0400268 private boolean isClosing = false;
269 private Timer t = new Timer();
alision907bde72013-06-20 14:40:37 -0400270
alisionbd45a822013-06-06 17:35:35 -0400271 @Override
272 public void onBackPressed() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400273
Alexandre Lision68900052013-11-01 11:34:56 -0400274 if (mNavigationDrawer.isDrawerVisible(Gravity.LEFT)) {
275 mNavigationDrawer.closeDrawer(Gravity.LEFT);
Alexandre Lision68855472013-10-10 16:20:46 -0400276 return;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400277 }
alision907bde72013-06-20 14:40:37 -0400278 if (getActionBar().getCustomView() != null) {
alision2ec64f92013-06-17 17:28:58 -0400279 getActionBar().setDisplayShowCustomEnabled(false);
280 getActionBar().setCustomView(null);
281 // Display all the contacts again
282 getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, mContactsFragment);
283 return;
284 }
alision907bde72013-06-20 14:40:37 -0400285
Alexandre Lision68900052013-11-01 11:34:56 -0400286 if (mContactDrawer.isOpened()) {
287 mContactDrawer.animateClose();
alisionbd45a822013-06-06 17:35:35 -0400288 return;
289 }
alision2ec64f92013-06-17 17:28:58 -0400290
alisionbd45a822013-06-06 17:35:35 -0400291 if (isClosing) {
292 super.onBackPressed();
293 t.cancel();
294 finish();
295 } else {
296
297 t.schedule(new TimerTask() {
298 @Override
299 public void run() {
300 isClosing = false;
301 }
302 }, 3000);
303 Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show();
304 isClosing = true;
305 }
306 }
alisione2a38e12013-04-25 14:20:20 -0400307
alision9f7a6ec2013-05-24 16:26:26 -0400308 /* activity no more in foreground */
309 @Override
310 protected void onPause() {
311 super.onPause();
alision58356b72013-06-03 17:13:36 -0400312 unregisterReceiver(callReceiver);
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400313 if (mBound) {
314 unbindService(mConnection);
315 mBound = false;
316 }
alision9f7a6ec2013-05-24 16:26:26 -0400317 }
alisionf76de3b2013-04-16 15:35:22 -0400318
alision9f7a6ec2013-05-24 16:26:26 -0400319 /* activity finishes itself or is being killed by the system */
320 @Override
321 protected void onDestroy() {
alision9f7a6ec2013-05-24 16:26:26 -0400322 super.onDestroy();
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400323 Log.i(TAG, "onDestroy: destroying service...");
324 Intent sipServiceIntent = new Intent(this, SipService.class);
325 stopService(sipServiceIntent);
alision9f7a6ec2013-05-24 16:26:26 -0400326 }
alision73424b62013-04-26 11:49:18 -0400327
alision55c36cb2013-06-14 14:57:38 -0400328 public void launchCallActivity(SipCall infos) {
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400329
alision9f7a6ec2013-05-24 16:26:26 -0400330 Bundle bundle = new Bundle();
alisiondf1dac92013-06-27 17:35:53 -0400331 Conference tmp = new Conference("-1");
alision465ceba2013-07-04 09:24:30 -0400332
alisiondf1dac92013-06-27 17:35:53 -0400333 tmp.getParticipants().add(infos);
alision465ceba2013-07-04 09:24:30 -0400334
alisiondf1dac92013-06-27 17:35:53 -0400335 bundle.putParcelable("conference", tmp);
alision9f7a6ec2013-05-24 16:26:26 -0400336 Intent intent = new Intent().setClass(this, CallActivity.class);
alisiondf1dac92013-06-27 17:35:53 -0400337 intent.putExtra("resuming", false);
alision9f7a6ec2013-05-24 16:26:26 -0400338 intent.putExtras(bundle);
339 startActivityForResult(intent, REQUEST_CODE_CALL);
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400340
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400341 // overridePendingTransition(R.anim.slide_down, R.anim.slide_up);
alision9f7a6ec2013-05-24 16:26:26 -0400342 }
alisionf76de3b2013-04-16 15:35:22 -0400343
alision9f7a6ec2013-05-24 16:26:26 -0400344 /** Defines callbacks for service binding, passed to bindService() */
345 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400346
alision9f7a6ec2013-05-24 16:26:26 -0400347 @Override
348 public void onServiceConnected(ComponentName className, IBinder binder) {
349 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400350
alision2cb99562013-05-30 17:02:20 -0400351 try {
alision58356b72013-06-03 17:13:36 -0400352
alision907bde72013-06-20 14:40:37 -0400353 fMenu = new MenuFragment();
354 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
Alexandre Lision4ab53972013-11-04 16:59:18 -0500355 mSectionsPagerAdapter = new SectionsPagerAdapter(HomeActivity.this, getFragmentManager());
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400356
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400357 // initialiseTabHost(null);
alisiondf1dac92013-06-27 17:35:53 -0400358 mViewPager.setOffscreenPageLimit(2);
alision58356b72013-06-03 17:13:36 -0400359 mViewPager.setAdapter(mSectionsPagerAdapter);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400360 mViewPager.setCurrentItem(1);
Alexandre Lisione5b66022013-10-30 11:34:15 -0400361
362 final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(findViewById(R.id.pts_main));
363
Alexandre Lision68900052013-11-01 11:34:56 -0400364 // strip.setBackgroundColor(getResources().getColor(R.color.sfl_blue_0));
Alexandre Lisione5b66022013-10-30 11:34:15 -0400365 strip.setViewPager(mViewPager);
366
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400367 // mTabHost.setCurrentTab(1);
alision2cb99562013-05-30 17:02:20 -0400368 service.destroyNotification();
alision58356b72013-06-03 17:13:36 -0400369 // mAdapter = new AccountSelectionAdapter(SFLPhoneHomeActivity.this, service, new ArrayList<Account>());
370 // spinnerAccounts.setAdapter(mAdapter);
alision2cb99562013-05-30 17:02:20 -0400371 } catch (RemoteException e) {
372 Log.e(TAG, e.toString());
373 }
alision9f7a6ec2013-05-24 16:26:26 -0400374 mBound = true;
alision9f7a6ec2013-05-24 16:26:26 -0400375 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400376
alision9f7a6ec2013-05-24 16:26:26 -0400377 }
alision5f899632013-04-22 17:26:56 -0400378
alision9f7a6ec2013-05-24 16:26:26 -0400379 @Override
380 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400381
alision9f7a6ec2013-05-24 16:26:26 -0400382 mBound = false;
383 Log.d(TAG, "Service disconnected service=" + service);
384 }
385 };
alision5f899632013-04-22 17:26:56 -0400386
alision9f7a6ec2013-05-24 16:26:26 -0400387 @Override
388 public boolean onOptionsItemSelected(MenuItem item) {
389 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400390
alision9f7a6ec2013-05-24 16:26:26 -0400391 if (mDrawerToggle.onOptionsItemSelected(item)) {
392 return true;
393 }
alision5f899632013-04-22 17:26:56 -0400394
alision9f7a6ec2013-05-24 16:26:26 -0400395 return super.onOptionsItemSelected(item);
396 }
alisionf76de3b2013-04-16 15:35:22 -0400397
alision9f7a6ec2013-05-24 16:26:26 -0400398 @Override
399 public void onActivityResult(int requestCode, int resultCode, Intent data) {
400 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400401
402 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400403 case REQUEST_CODE_PREFERENCES:
Alexandre Lisione5b66022013-10-30 11:34:15 -0400404 if (fMenu != null)
Alexandre Lision933ef0a2013-10-15 17:28:40 -0400405 fMenu.updateAllAccounts();
alision9f7a6ec2013-05-24 16:26:26 -0400406 break;
407 case REQUEST_CODE_CALL:
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400408 if (resultCode == CallActivity.RESULT_FAILURE) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400409 Log.w(TAG, "Call Failed");
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400410 }
411 // if (mSectionsPagerAdapter != null && mSectionsPagerAdapter.getItem(2) != null)
412 // getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, (HistoryFragment) mSectionsPagerAdapter.getItem(2));
alision9f7a6ec2013-05-24 16:26:26 -0400413 break;
414 }
alisionf76de3b2013-04-16 15:35:22 -0400415
alision9f7a6ec2013-05-24 16:26:26 -0400416 }
alisionf76de3b2013-04-16 15:35:22 -0400417
alision9f7a6ec2013-05-24 16:26:26 -0400418 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400419 public ISipService getService() {
420 return service;
421 }
alisionf76de3b2013-04-16 15:35:22 -0400422
alision84813a12013-05-27 17:40:39 -0400423 /**
424 * Interface implemented to handle incoming events
425 */
alision9f7a6ec2013-05-24 16:26:26 -0400426 @Override
alision84813a12013-05-27 17:40:39 -0400427 public void incomingCall(Intent call) {
alisionfde875f2013-05-28 17:01:54 -0400428 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400429
alision58356b72013-06-03 17:13:36 -0400430 // mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400431
alision55c36cb2013-06-14 14:57:38 -0400432 launchCallActivity(infos);
alision84813a12013-05-27 17:40:39 -0400433
434 }
435
436 @Override
437 public void callStateChanged(Intent callState) {
438 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
439 String cID = b.getString("CallID");
440 String state = b.getString("State");
441 Log.i(TAG, "callStateChanged" + cID + " " + state);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400442 mSectionsPagerAdapter.updateHome();
alision84813a12013-05-27 17:40:39 -0400443
444 }
445
446 @Override
447 public void incomingText(Intent msg) {
448 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
449 b.getString("CallID");
450 String from = b.getString("From");
451 String mess = b.getString("Msg");
452 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
453 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400454
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400455 @Override
456 public void onTextContact(final CallContact c) {
457 // TODO
458 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400459
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400460 @Override
461 public void onEditContact(final CallContact c) {
462 Intent intent = new Intent(Intent.ACTION_VIEW);
463 Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId()));
464 intent.setData(uri);
465 startActivity(intent);
466 }
alision84813a12013-05-27 17:40:39 -0400467
468 @Override
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400469 public void onCallContact(final CallContact c) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400470
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400471 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400472 createAccountDialog().show();
473 return;
474 }
alisionfde875f2013-05-28 17:01:54 -0400475
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400476 if (!fMenu.getSelectedAccount().isRegistered()) {
477 createNotRegisteredDialog().show();
478 return;
479 }
480
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400481 getActionBar().show();
alision55c36cb2013-06-14 14:57:38 -0400482 Thread launcher = new Thread(new Runnable() {
alision907bde72013-06-20 14:40:37 -0400483
alision55c36cb2013-06-14 14:57:38 -0400484 final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
485 final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
alision907bde72013-06-20 14:40:37 -0400486
alision55c36cb2013-06-14 14:57:38 -0400487 @Override
488 public void run() {
489 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
490 try {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400491 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
alision907bde72013-06-20 14:40:37 -0400492 Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(),
493 null, null);
alision55c36cb2013-06-14 14:57:38 -0400494
alision907bde72013-06-20 14:40:37 -0400495 while (cPhones.moveToNext()) {
496 c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE)));
497 }
498 cPhones.close();
499
500 Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null,
501 null);
502
503 while (cSip.moveToNext()) {
504 c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE)));
505 }
506 cSip.close();
507 callBuilder.setContact(c);
alision55c36cb2013-06-14 14:57:38 -0400508 launchCallActivity(callBuilder.build());
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400509 } catch (InvalidObjectException e) {
510 e.printStackTrace();
alision55c36cb2013-06-14 14:57:38 -0400511 }
alision907bde72013-06-20 14:40:37 -0400512
alision55c36cb2013-06-14 14:57:38 -0400513 }
514 });
515 launcher.start();
Alexandre Lision4ab53972013-11-04 16:59:18 -0500516 mContactDrawer.animateClose();
alision84813a12013-05-27 17:40:39 -0400517
518 }
519
520 @Override
alision907bde72013-06-20 14:40:37 -0400521 public void onCallDialed(String to) {
alision84813a12013-05-27 17:40:39 -0400522
alisiondf1dac92013-06-27 17:35:53 -0400523 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400524 createAccountDialog().show();
alisiondf1dac92013-06-27 17:35:53 -0400525 return;
526 }
527
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400528 if (fMenu.getSelectedAccount().isRegistered()) {
529 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
530 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
531 callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400532
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400533 try {
534 launchCallActivity(callBuilder.build());
535 } catch (Exception e) {
536 Log.e(TAG, e.toString());
537 }
538 } else {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400539 createNotRegisteredDialog().show();
540 ;
alisionfde875f2013-05-28 17:01:54 -0400541 }
alision84813a12013-05-27 17:40:39 -0400542
alision9f7a6ec2013-05-24 16:26:26 -0400543 }
alision371b77e2013-04-23 14:51:26 -0400544
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400545 private AlertDialog createNotRegisteredDialog() {
546 final Activity ownerActivity = this;
547 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
548
549 builder.setMessage(getResources().getString(R.string.cannot_pass_sipcall))
550 .setTitle(getResources().getString(R.string.cannot_pass_sipcall_title))
551 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
552 public void onClick(DialogInterface dialog, int whichButton) {
Alexandre Lision5ed2c972013-10-11 15:36:33 -0400553
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400554 }
555 });
556
557 AlertDialog alertDialog = builder.create();
558 alertDialog.setOwnerActivity(ownerActivity);
559
560 return alertDialog;
561 }
562
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400563 private AlertDialog createAccountDialog() {
564 final Activity ownerActivity = this;
565 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
566
567 builder.setMessage(getResources().getString(R.string.create_new_account_dialog))
568 .setTitle(getResources().getString(R.string.create_new_account_dialog_title))
569 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
570 public void onClick(DialogInterface dialog, int whichButton) {
571 Intent in = new Intent();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400572 in.setClass(ownerActivity, AccountWizard.class);
Alexandre Lision4ab53972013-11-04 16:59:18 -0500573 ownerActivity.startActivityForResult(in, HomeActivity.REQUEST_CODE_PREFERENCES);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400574 }
575 }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
576 public void onClick(DialogInterface dialog, int whichButton) {
577 dialog.dismiss();
578 }
579 });
580
581 AlertDialog alertDialog = builder.create();
582 alertDialog.setOwnerActivity(ownerActivity);
583
584 return alertDialog;
585 }
586
alisiond45da712013-05-30 09:18:49 -0400587 @Override
588 public void onContactDragged() {
Alexandre Lision4ab53972013-11-04 16:59:18 -0500589 mContactDrawer.animateClose();
alisiond45da712013-05-30 09:18:49 -0400590 }
591
alision58356b72013-06-03 17:13:36 -0400592 @Override
593 public void openDrawer() {
Alexandre Lision68900052013-11-01 11:34:56 -0400594 mContactDrawer.animateOpen();
alision58356b72013-06-03 17:13:36 -0400595 }
596
alision806e18e2013-06-21 15:30:17 -0400597 @Override
598 public void confCreated(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 confRemoved(Intent intent) {
605 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400606
alision806e18e2013-06-21 15:30:17 -0400607 }
608
609 @Override
610 public void confChanged(Intent intent) {
611 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400612
613 }
614
615 @Override
616 public void recordingChanged(Intent intent) {
617 // TODO Auto-generated method stub
618
619 }
620
621 @Override
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400622 public void selectedCall(Conference c) {
alisiondf1dac92013-06-27 17:35:53 -0400623 Intent intent = new Intent().setClass(this, CallActivity.class);
624 intent.putExtra("resuming", true);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400625 intent.putExtra("conference", c);
alisiondf1dac92013-06-27 17:35:53 -0400626 startActivityForResult(intent, REQUEST_CODE_CALL);
alision806e18e2013-06-21 15:30:17 -0400627 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400628
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400629 private class ZoomOutPageTransformer implements ViewPager.PageTransformer {
630 private static final float MIN_ALPHA = .6f;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400631
632 // private final float scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400633
634 public ZoomOutPageTransformer(float scalingStart) {
635 super();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400636 // this.scalingStart = 1 - scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400637 }
638
639 @Override
640 public void transformPage(View page, float position) {
641 // page.setRotationY(position * -30);
642 final float normalizedposition = Math.abs(Math.abs(position) - 1);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400643 page.setAlpha(MIN_ALPHA + (1.f - MIN_ALPHA) * normalizedposition);
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400644 }
645 }
alision806e18e2013-06-21 15:30:17 -0400646
alisionf76de3b2013-04-16 15:35:22 -0400647}