blob: 8bb21f5d64c3d74509eb64b53f2d1b5509def384 [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
alisionbd45a822013-06-06 17:35:35 -040034import java.util.Timer;
35import java.util.TimerTask;
alision84813a12013-05-27 17:40:39 -040036
Alexandre Lision064e1e02013-10-01 16:18:42 -040037import org.sflphone.R;
38import org.sflphone.adapters.SectionsPagerAdapter;
39import org.sflphone.fragments.ContactListFragment;
40import org.sflphone.fragments.DialingFragment;
41import org.sflphone.fragments.HistoryFragment;
42import org.sflphone.fragments.HomeFragment;
43import org.sflphone.fragments.MenuFragment;
44import org.sflphone.interfaces.CallInterface;
45import org.sflphone.loaders.LoaderConstants;
46import 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;
53import org.sflphone.views.CustomSlidingDrawer;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -040054import org.sflphone.views.CustomSlidingDrawer.OnDrawerScrollListener;
Alexandre Lision064e1e02013-10-01 16:18:42 -040055
alisionf76de3b2013-04-16 15:35:22 -040056import android.app.Activity;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040057import android.app.AlertDialog;
alisionf76de3b2013-04-16 15:35:22 -040058import android.content.ComponentName;
59import android.content.Context;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040060import android.content.DialogInterface;
alisionf76de3b2013-04-16 15:35:22 -040061import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040062import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040063import android.content.ServiceConnection;
alisionf57d8a62013-07-02 09:37:12 -040064import android.content.res.Configuration;
alision55c36cb2013-06-14 14:57:38 -040065import android.database.Cursor;
Alexandre Lisionc59685a2013-10-04 16:36:36 -040066import android.net.Uri;
alisionf76de3b2013-04-16 15:35:22 -040067import android.os.Bundle;
68import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040069import android.os.RemoteException;
Alexandre Lisionc59685a2013-10-04 16:36:36 -040070import android.provider.ContactsContract;
alision55c36cb2013-06-14 14:57:38 -040071import android.provider.ContactsContract.CommonDataKinds.Phone;
72import android.provider.ContactsContract.CommonDataKinds.SipAddress;
alision9f7a6ec2013-05-24 16:26:26 -040073import android.support.v4.app.ActionBarDrawerToggle;
74import android.support.v4.view.GravityCompat;
Alexandre Lisionf41a3a82013-09-05 17:15:15 -040075import android.support.v4.view.PagerTabStrip;
alisionf76de3b2013-04-16 15:35:22 -040076import android.support.v4.view.ViewPager;
alision9f7a6ec2013-05-24 16:26:26 -040077import android.support.v4.widget.DrawerLayout;
alisionf76de3b2013-04-16 15:35:22 -040078import android.util.Log;
Alexandre Lisionf41a3a82013-09-05 17:15:15 -040079import android.util.TypedValue;
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;
alision7297bdb2013-05-21 11:56:55 -040083import android.widget.RelativeLayout;
alision04a00182013-05-10 17:05:29 -040084import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040085
alision907bde72013-06-20 14:40:37 -040086public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Callbacks, ContactListFragment.Callbacks, HomeFragment.Callbacks,
87 HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks {
alisionfde875f2013-05-28 17:01:54 -040088
alision9f7a6ec2013-05-24 16:26:26 -040089 SectionsPagerAdapter mSectionsPagerAdapter = null;
alision84813a12013-05-27 17:40:39 -040090 static final String TAG = "SFLPhoneHomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040091
alision9f7a6ec2013-05-24 16:26:26 -040092 private ContactListFragment mContactsFragment = null;
alision907bde72013-06-20 14:40:37 -040093 private MenuFragment fMenu;
alisionf76de3b2013-04-16 15:35:22 -040094
alision9f7a6ec2013-05-24 16:26:26 -040095 private boolean mBound = false;
96 private ISipService service;
alisionf76de3b2013-04-16 15:35:22 -040097
alision9f7a6ec2013-05-24 16:26:26 -040098 private CharSequence mDrawerTitle;
99 private CharSequence mTitle;
alisionf76de3b2013-04-16 15:35:22 -0400100
alision2cb99562013-05-30 17:02:20 -0400101 public static final int REQUEST_CODE_PREFERENCES = 1;
alision9f7a6ec2013-05-24 16:26:26 -0400102 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -0400103
alision0b553832013-05-30 09:31:06 -0400104 RelativeLayout mSliderButton;
alision9f7a6ec2013-05-24 16:26:26 -0400105 CustomSlidingDrawer mDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400106 private DrawerLayout mDrawerLayout;
alision9f7a6ec2013-05-24 16:26:26 -0400107 private ActionBarDrawerToggle mDrawerToggle;
108 /**
109 * The {@link ViewPager} that will host the section contents.
110 */
111 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400112
alision58356b72013-06-03 17:13:36 -0400113 CallReceiver callReceiver;
alision84813a12013-05-27 17:40:39 -0400114
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400115 // private TabHost mTabHost;
alisionf76de3b2013-04-16 15:35:22 -0400116
alision9f7a6ec2013-05-24 16:26:26 -0400117 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
118
119 /* 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);
139 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
140 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400141
142 if (savedInstanceState != null) {
Alexandre Lision23628c12013-09-24 11:17:05 -0400143 mContactsFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, "ContactsListFragment");
144 }
alision9f7a6ec2013-05-24 16:26:26 -0400145 if (mContactsFragment == null) {
146 mContactsFragment = new ContactListFragment();
alision9f7a6ec2013-05-24 16:26:26 -0400147 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
148 }
alision2ec64f92013-06-17 17:28:58 -0400149
alision9f7a6ec2013-05-24 16:26:26 -0400150 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400151
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400152 mDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {
153
154 @Override
155 public void onScrollStarted() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400156 // getActionBar().hide();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400157
158 }
159
160 @Override
161 public void onScrollEnded() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400162 // getActionBar().show();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400163
164 }
165
166 @Override
167 public void onScroll(int offset) {
168 if (offset < 400) {
169 getActionBar().hide();
170 } else if (offset > 450) {
171 getActionBar().show();
172 }
173 }
174 });
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400175
alision84813a12013-05-27 17:40:39 -0400176 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400177
178 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400179
alision9f7a6ec2013-05-24 16:26:26 -0400180 // Set up the ViewPager with the sections adapter.
181 mViewPager = (ViewPager) findViewById(R.id.pager);
alision55c36cb2013-06-14 14:57:38 -0400182 mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f));
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400183 final PagerTabStrip strip = PagerTabStrip.class.cast(mViewPager.findViewById(R.id.pts_main));
184 strip.setDrawFullUnderline(false);
185 strip.setTabIndicatorColor(getResources().getColor(R.color.holo_blue_dark));
186 strip.setBackgroundColor(getResources().getColor(R.color.darker_gray));
187 strip.setNonPrimaryAlpha(0.5f);
188 strip.setTextSpacing(25);
189 strip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
alisionf76de3b2013-04-16 15:35:22 -0400190
alision9f7a6ec2013-05-24 16:26:26 -0400191 mTitle = mDrawerTitle = getTitle();
192 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400193
alision0b553832013-05-30 09:31:06 -0400194 // set a custom shadow that overlays the main content when the drawer opens
alision9f7a6ec2013-05-24 16:26:26 -0400195 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400196
alision9f7a6ec2013-05-24 16:26:26 -0400197 getActionBar().setDisplayHomeAsUpEnabled(true);
198 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400199
alision9f7a6ec2013-05-24 16:26:26 -0400200 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
201 mDrawerLayout, /* DrawerLayout object */
202 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
203 R.string.drawer_open, /* "open drawer" description for accessibility */
204 R.string.drawer_close /* "close drawer" description for accessibility */
205 ) {
alision0b553832013-05-30 09:31:06 -0400206 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400207 public void onDrawerClosed(View view) {
208 getActionBar().setTitle(mTitle);
209 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
210 }
alisionf76de3b2013-04-16 15:35:22 -0400211
alision0b553832013-05-30 09:31:06 -0400212 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400213 public void onDrawerOpened(View drawerView) {
214 getActionBar().setTitle(mDrawerTitle);
215 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
216 }
217 };
alisionf76de3b2013-04-16 15:35:22 -0400218
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400219 // mTabHost = (TabHost) findViewById(android.R.id.tabhost);
alision9f7a6ec2013-05-24 16:26:26 -0400220 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400221
alision9f7a6ec2013-05-24 16:26:26 -0400222 }
alisionf76de3b2013-04-16 15:35:22 -0400223
alisionf57d8a62013-07-02 09:37:12 -0400224 @Override
225 protected void onPostCreate(Bundle savedInstanceState) {
226 super.onPostCreate(savedInstanceState);
227 // Sync the toggle state after onRestoreInstanceState has occurred.
228 mDrawerToggle.syncState();
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400229 if(mDrawer.isOpened()){
230 getActionBar().hide();
231 }
alisionf57d8a62013-07-02 09:37:12 -0400232 }
alision465ceba2013-07-04 09:24:30 -0400233
alisionf57d8a62013-07-02 09:37:12 -0400234 @Override
235 public void onConfigurationChanged(Configuration newConfig) {
236 super.onConfigurationChanged(newConfig);
237 mDrawerToggle.onConfigurationChanged(newConfig);
238 }
alision3c5c2a92013-05-30 09:50:47 -0400239
alision9f7a6ec2013-05-24 16:26:26 -0400240 @Override
241 protected void onStart() {
242 Log.i(TAG, "onStart");
243 super.onStart();
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400244
alision9f7a6ec2013-05-24 16:26:26 -0400245 }
alisionf76de3b2013-04-16 15:35:22 -0400246
alision9f7a6ec2013-05-24 16:26:26 -0400247 /* user gets back to the activity, e.g. through task manager */
248 @Override
249 protected void onRestart() {
250 super.onRestart();
251 }
alisionf76de3b2013-04-16 15:35:22 -0400252
alision9f7a6ec2013-05-24 16:26:26 -0400253 /* activity gets back to the foreground and user input */
254 @Override
255 protected void onResume() {
alision58356b72013-06-03 17:13:36 -0400256 super.onResume();
alision84813a12013-05-27 17:40:39 -0400257 IntentFilter intentFilter = new IntentFilter();
258 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
259 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
260 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
alision58356b72013-06-03 17:13:36 -0400261 registerReceiver(callReceiver, intentFilter);
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400262
alision907bde72013-06-20 14:40:37 -0400263
alision9f7a6ec2013-05-24 16:26:26 -0400264 }
alision907bde72013-06-20 14:40:37 -0400265
alisionbd45a822013-06-06 17:35:35 -0400266 private boolean isClosing = false;
267 private Timer t = new Timer();
alision907bde72013-06-20 14:40:37 -0400268
alisionbd45a822013-06-06 17:35:35 -0400269 @Override
270 public void onBackPressed() {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400271
272 if (mDrawerLayout.isDrawerVisible(Gravity.LEFT)) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400273 mDrawerLayout.closeDrawer(Gravity.LEFT);
Alexandre Lision68855472013-10-10 16:20:46 -0400274 return;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400275 }
alision907bde72013-06-20 14:40:37 -0400276 if (getActionBar().getCustomView() != null) {
alision2ec64f92013-06-17 17:28:58 -0400277 getActionBar().setDisplayShowCustomEnabled(false);
278 getActionBar().setCustomView(null);
279 // Display all the contacts again
280 getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, mContactsFragment);
281 return;
282 }
alision907bde72013-06-20 14:40:37 -0400283
alisionbd45a822013-06-06 17:35:35 -0400284 if (mDrawer.isOpened()) {
alision55c36cb2013-06-14 14:57:38 -0400285 mDrawer.animateClose();
alisionbd45a822013-06-06 17:35:35 -0400286 return;
287 }
alision2ec64f92013-06-17 17:28:58 -0400288
alisionbd45a822013-06-06 17:35:35 -0400289 if (isClosing) {
290 super.onBackPressed();
291 t.cancel();
292 finish();
293 } else {
294
295 t.schedule(new TimerTask() {
296 @Override
297 public void run() {
298 isClosing = false;
299 }
300 }, 3000);
301 Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show();
302 isClosing = true;
303 }
304 }
alisione2a38e12013-04-25 14:20:20 -0400305
alision9f7a6ec2013-05-24 16:26:26 -0400306 /* activity no more in foreground */
307 @Override
308 protected void onPause() {
309 super.onPause();
alision58356b72013-06-03 17:13:36 -0400310 unregisterReceiver(callReceiver);
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400311 if (mBound) {
312 unbindService(mConnection);
313 mBound = false;
314 }
alision9f7a6ec2013-05-24 16:26:26 -0400315 }
alisionf76de3b2013-04-16 15:35:22 -0400316
alision9f7a6ec2013-05-24 16:26:26 -0400317 /* activity finishes itself or is being killed by the system */
318 @Override
319 protected void onDestroy() {
alision9f7a6ec2013-05-24 16:26:26 -0400320 super.onDestroy();
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400321 Log.i(TAG, "onDestroy: destroying service...");
322 Intent sipServiceIntent = new Intent(this, SipService.class);
323 stopService(sipServiceIntent);
alision9f7a6ec2013-05-24 16:26:26 -0400324 }
alision73424b62013-04-26 11:49:18 -0400325
alision55c36cb2013-06-14 14:57:38 -0400326 public void launchCallActivity(SipCall infos) {
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400327
alision9f7a6ec2013-05-24 16:26:26 -0400328 Bundle bundle = new Bundle();
alisiondf1dac92013-06-27 17:35:53 -0400329 Conference tmp = new Conference("-1");
alision465ceba2013-07-04 09:24:30 -0400330
alisiondf1dac92013-06-27 17:35:53 -0400331 tmp.getParticipants().add(infos);
alision465ceba2013-07-04 09:24:30 -0400332
alisiondf1dac92013-06-27 17:35:53 -0400333 bundle.putParcelable("conference", tmp);
alision9f7a6ec2013-05-24 16:26:26 -0400334 Intent intent = new Intent().setClass(this, CallActivity.class);
alisiondf1dac92013-06-27 17:35:53 -0400335 intent.putExtra("resuming", false);
alision9f7a6ec2013-05-24 16:26:26 -0400336 intent.putExtras(bundle);
337 startActivityForResult(intent, REQUEST_CODE_CALL);
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400338
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400339 // overridePendingTransition(R.anim.slide_down, R.anim.slide_up);
alision9f7a6ec2013-05-24 16:26:26 -0400340 }
alisionf76de3b2013-04-16 15:35:22 -0400341
alision9f7a6ec2013-05-24 16:26:26 -0400342 /** Defines callbacks for service binding, passed to bindService() */
343 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400344
alision9f7a6ec2013-05-24 16:26:26 -0400345 @Override
346 public void onServiceConnected(ComponentName className, IBinder binder) {
347 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400348
alision2cb99562013-05-30 17:02:20 -0400349 try {
alision58356b72013-06-03 17:13:36 -0400350
alision907bde72013-06-20 14:40:37 -0400351 fMenu = new MenuFragment();
352 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
alision58356b72013-06-03 17:13:36 -0400353 mSectionsPagerAdapter = new SectionsPagerAdapter(SFLPhoneHomeActivity.this, getFragmentManager());
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400354
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400355 // initialiseTabHost(null);
alisiondf1dac92013-06-27 17:35:53 -0400356 mViewPager.setOffscreenPageLimit(2);
alision58356b72013-06-03 17:13:36 -0400357 mViewPager.setAdapter(mSectionsPagerAdapter);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400358 mViewPager.setCurrentItem(1);
359 // mTabHost.setCurrentTab(1);
alision2cb99562013-05-30 17:02:20 -0400360 service.destroyNotification();
alision58356b72013-06-03 17:13:36 -0400361 // mAdapter = new AccountSelectionAdapter(SFLPhoneHomeActivity.this, service, new ArrayList<Account>());
362 // spinnerAccounts.setAdapter(mAdapter);
alision2cb99562013-05-30 17:02:20 -0400363 } catch (RemoteException e) {
364 Log.e(TAG, e.toString());
365 }
alision9f7a6ec2013-05-24 16:26:26 -0400366 mBound = true;
alision9f7a6ec2013-05-24 16:26:26 -0400367 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400368
alision9f7a6ec2013-05-24 16:26:26 -0400369 }
alision5f899632013-04-22 17:26:56 -0400370
alision9f7a6ec2013-05-24 16:26:26 -0400371 @Override
372 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400373
alision9f7a6ec2013-05-24 16:26:26 -0400374 mBound = false;
375 Log.d(TAG, "Service disconnected service=" + service);
376 }
377 };
alision5f899632013-04-22 17:26:56 -0400378
alision9f7a6ec2013-05-24 16:26:26 -0400379 @Override
380 public boolean onOptionsItemSelected(MenuItem item) {
381 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400382
alision9f7a6ec2013-05-24 16:26:26 -0400383 if (mDrawerToggle.onOptionsItemSelected(item)) {
384 return true;
385 }
alision5f899632013-04-22 17:26:56 -0400386
alision9f7a6ec2013-05-24 16:26:26 -0400387 return super.onOptionsItemSelected(item);
388 }
alisionf76de3b2013-04-16 15:35:22 -0400389
alision9f7a6ec2013-05-24 16:26:26 -0400390 @Override
391 public void onActivityResult(int requestCode, int resultCode, Intent data) {
392 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400393
394 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400395 case REQUEST_CODE_PREFERENCES:
alision907bde72013-06-20 14:40:37 -0400396 Log.w(TAG, "In Activity");
397 fMenu.updateAllAccounts();
alision9f7a6ec2013-05-24 16:26:26 -0400398 break;
399 case REQUEST_CODE_CALL:
alision2cb99562013-05-30 17:02:20 -0400400 Log.w(TAG, "Result out of CallActivity");
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400401 if (resultCode == CallActivity.RESULT_FAILURE) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400402 Log.w(TAG, "Call Failed");
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400403 }
404 // if (mSectionsPagerAdapter != null && mSectionsPagerAdapter.getItem(2) != null)
405 // getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, (HistoryFragment) mSectionsPagerAdapter.getItem(2));
alision9f7a6ec2013-05-24 16:26:26 -0400406 break;
407 }
alisionf76de3b2013-04-16 15:35:22 -0400408
alision9f7a6ec2013-05-24 16:26:26 -0400409 }
alisionf76de3b2013-04-16 15:35:22 -0400410
alision9f7a6ec2013-05-24 16:26:26 -0400411 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400412 public ISipService getService() {
413 return service;
414 }
alisionf76de3b2013-04-16 15:35:22 -0400415
alision84813a12013-05-27 17:40:39 -0400416 /**
417 * Interface implemented to handle incoming events
418 */
alision9f7a6ec2013-05-24 16:26:26 -0400419 @Override
alision84813a12013-05-27 17:40:39 -0400420 public void incomingCall(Intent call) {
421 Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show();
alisionfde875f2013-05-28 17:01:54 -0400422 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400423
alision58356b72013-06-03 17:13:36 -0400424 // mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400425
alision55c36cb2013-06-14 14:57:38 -0400426 launchCallActivity(infos);
alision84813a12013-05-27 17:40:39 -0400427
428 }
429
430 @Override
431 public void callStateChanged(Intent callState) {
432 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
433 String cID = b.getString("CallID");
434 String state = b.getString("State");
435 Log.i(TAG, "callStateChanged" + cID + " " + state);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400436 mSectionsPagerAdapter.updateHome();
alision84813a12013-05-27 17:40:39 -0400437
438 }
439
440 @Override
441 public void incomingText(Intent msg) {
442 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
443 b.getString("CallID");
444 String from = b.getString("From");
445 String mess = b.getString("Msg");
446 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
447 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400448
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400449 @Override
450 public void onTextContact(final CallContact c) {
451 // TODO
452 }
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400453
Alexandre Lisionc59685a2013-10-04 16:36:36 -0400454 @Override
455 public void onEditContact(final CallContact c) {
456 Intent intent = new Intent(Intent.ACTION_VIEW);
457 Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId()));
458 intent.setData(uri);
459 startActivity(intent);
460 }
alision84813a12013-05-27 17:40:39 -0400461
462 @Override
Alexandre Lisione1c96db2013-10-04 14:34:21 -0400463 public void onCallContact(final CallContact c) {
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400464
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400465 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400466 createAccountDialog().show();
467 return;
468 }
alisionfde875f2013-05-28 17:01:54 -0400469
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400470 if (!fMenu.getSelectedAccount().isRegistered()) {
471 createNotRegisteredDialog().show();
472 return;
473 }
474
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400475 getActionBar().show();
alision55c36cb2013-06-14 14:57:38 -0400476 Thread launcher = new Thread(new Runnable() {
alision907bde72013-06-20 14:40:37 -0400477
alision55c36cb2013-06-14 14:57:38 -0400478 final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
479 final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
alision907bde72013-06-20 14:40:37 -0400480
alision55c36cb2013-06-14 14:57:38 -0400481 @Override
482 public void run() {
483 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
484 try {
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400485 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
alision907bde72013-06-20 14:40:37 -0400486 Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(),
487 null, null);
alision55c36cb2013-06-14 14:57:38 -0400488
alision907bde72013-06-20 14:40:37 -0400489 while (cPhones.moveToNext()) {
490 c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE)));
491 }
492 cPhones.close();
493
494 Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null,
495 null);
496
497 while (cSip.moveToNext()) {
498 c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE)));
499 }
500 cSip.close();
501 callBuilder.setContact(c);
alision55c36cb2013-06-14 14:57:38 -0400502 launchCallActivity(callBuilder.build());
503 } catch (RemoteException e1) {
504 Log.e(TAG, e1.toString());
505 } catch (Exception e) {
506 Log.e(TAG, e.toString());
507 }
alision907bde72013-06-20 14:40:37 -0400508
alision55c36cb2013-06-14 14:57:38 -0400509 }
510 });
511 launcher.start();
512 mDrawer.close();
alision84813a12013-05-27 17:40:39 -0400513
514 }
515
516 @Override
alision907bde72013-06-20 14:40:37 -0400517 public void onCallDialed(String to) {
alision84813a12013-05-27 17:40:39 -0400518
alisiondf1dac92013-06-27 17:35:53 -0400519 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400520 createAccountDialog().show();
alisiondf1dac92013-06-27 17:35:53 -0400521 return;
522 }
523
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400524 if (fMenu.getSelectedAccount().isRegistered()) {
525 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
526 callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
527 callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400528
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400529 try {
530 launchCallActivity(callBuilder.build());
531 } catch (Exception e) {
532 Log.e(TAG, e.toString());
533 }
534 } else {
535 createNotRegisteredDialog().show();;
alisionfde875f2013-05-28 17:01:54 -0400536 }
alision84813a12013-05-27 17:40:39 -0400537
alision9f7a6ec2013-05-24 16:26:26 -0400538 }
alision371b77e2013-04-23 14:51:26 -0400539
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400540 private AlertDialog createNotRegisteredDialog() {
541 final Activity ownerActivity = this;
542 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
543
544 builder.setMessage(getResources().getString(R.string.cannot_pass_sipcall))
545 .setTitle(getResources().getString(R.string.cannot_pass_sipcall_title))
546 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
547 public void onClick(DialogInterface dialog, int whichButton) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400548
Alexandre Lisiond588bff2013-10-08 12:43:01 -0400549 }
550 });
551
552 AlertDialog alertDialog = builder.create();
553 alertDialog.setOwnerActivity(ownerActivity);
554
555 return alertDialog;
556 }
557
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400558 private AlertDialog createAccountDialog() {
559 final Activity ownerActivity = this;
560 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
561
562 builder.setMessage(getResources().getString(R.string.create_new_account_dialog))
563 .setTitle(getResources().getString(R.string.create_new_account_dialog_title))
564 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
565 public void onClick(DialogInterface dialog, int whichButton) {
566 Intent in = new Intent();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400567 in.setClass(ownerActivity, AccountWizard.class);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400568 ownerActivity.startActivityForResult(in, SFLPhoneHomeActivity.REQUEST_CODE_PREFERENCES);
569 }
570 }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
571 public void onClick(DialogInterface dialog, int whichButton) {
572 dialog.dismiss();
573 }
574 });
575
576 AlertDialog alertDialog = builder.create();
577 alertDialog.setOwnerActivity(ownerActivity);
578
579 return alertDialog;
580 }
581
alisiond45da712013-05-30 09:18:49 -0400582 @Override
583 public void onContactDragged() {
alisiond45da712013-05-30 09:18:49 -0400584 mDrawer.close();
alisiond45da712013-05-30 09:18:49 -0400585 }
586
alision58356b72013-06-03 17:13:36 -0400587 @Override
588 public void openDrawer() {
alision55c36cb2013-06-14 14:57:38 -0400589 mDrawer.animateOpen();
alision58356b72013-06-03 17:13:36 -0400590 }
591
alision806e18e2013-06-21 15:30:17 -0400592 @Override
593 public void confCreated(Intent intent) {
594 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400595
alision806e18e2013-06-21 15:30:17 -0400596 }
597
598 @Override
599 public void confRemoved(Intent intent) {
600 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400601
alision806e18e2013-06-21 15:30:17 -0400602 }
603
604 @Override
605 public void confChanged(Intent intent) {
606 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400607
608 }
609
610 @Override
611 public void recordingChanged(Intent intent) {
612 // TODO Auto-generated method stub
613
614 }
615
616 @Override
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400617 public void selectedCall(Conference c) {
alisiondf1dac92013-06-27 17:35:53 -0400618 Intent intent = new Intent().setClass(this, CallActivity.class);
619 intent.putExtra("resuming", true);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400620 intent.putExtra("conference", c);
alisiondf1dac92013-06-27 17:35:53 -0400621 startActivityForResult(intent, REQUEST_CODE_CALL);
alision806e18e2013-06-21 15:30:17 -0400622 }
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400623
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400624 private class ZoomOutPageTransformer implements ViewPager.PageTransformer {
625 private static final float MIN_ALPHA = .6f;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400626
627 // private final float scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400628
629 public ZoomOutPageTransformer(float scalingStart) {
630 super();
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400631 // this.scalingStart = 1 - scalingStart;
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400632 }
633
634 @Override
635 public void transformPage(View page, float position) {
636 // page.setRotationY(position * -30);
637 final float normalizedposition = Math.abs(Math.abs(position) - 1);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400638 page.setAlpha(MIN_ALPHA + (1.f - MIN_ALPHA) * normalizedposition);
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400639 }
640 }
alision806e18e2013-06-21 15:30:17 -0400641
alisionf76de3b2013-04-16 15:35:22 -0400642}