blob: 96333bc37c61a4889a14515777ea84a1a006c261 [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;
54
alisionf76de3b2013-04-16 15:35:22 -040055import android.app.Activity;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040056import android.app.AlertDialog;
alisionf76de3b2013-04-16 15:35:22 -040057import android.content.ComponentName;
58import android.content.Context;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040059import android.content.DialogInterface;
alisionf76de3b2013-04-16 15:35:22 -040060import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040061import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040062import android.content.ServiceConnection;
alisionf57d8a62013-07-02 09:37:12 -040063import android.content.res.Configuration;
alision55c36cb2013-06-14 14:57:38 -040064import android.database.Cursor;
alisionf76de3b2013-04-16 15:35:22 -040065import android.os.Bundle;
66import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040067import android.os.RemoteException;
alision55c36cb2013-06-14 14:57:38 -040068import android.provider.ContactsContract.CommonDataKinds.Phone;
69import android.provider.ContactsContract.CommonDataKinds.SipAddress;
alision9f7a6ec2013-05-24 16:26:26 -040070import android.support.v4.app.ActionBarDrawerToggle;
71import android.support.v4.view.GravityCompat;
Alexandre Lisionf41a3a82013-09-05 17:15:15 -040072import android.support.v4.view.PagerTabStrip;
alisionf76de3b2013-04-16 15:35:22 -040073import android.support.v4.view.ViewPager;
alision9f7a6ec2013-05-24 16:26:26 -040074import android.support.v4.widget.DrawerLayout;
alisionf76de3b2013-04-16 15:35:22 -040075import android.util.Log;
Alexandre Lisionf41a3a82013-09-05 17:15:15 -040076import android.util.TypedValue;
alision9f7a6ec2013-05-24 16:26:26 -040077import android.view.MenuItem;
78import android.view.View;
alision7297bdb2013-05-21 11:56:55 -040079import android.widget.RelativeLayout;
alision04a00182013-05-10 17:05:29 -040080import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040081
alision907bde72013-06-20 14:40:37 -040082public class SFLPhoneHomeActivity extends Activity implements DialingFragment.Callbacks, ContactListFragment.Callbacks, HomeFragment.Callbacks,
83 HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks {
alisionfde875f2013-05-28 17:01:54 -040084
alision9f7a6ec2013-05-24 16:26:26 -040085 SectionsPagerAdapter mSectionsPagerAdapter = null;
alision84813a12013-05-27 17:40:39 -040086 static final String TAG = "SFLPhoneHomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040087
alision9f7a6ec2013-05-24 16:26:26 -040088 private ContactListFragment mContactsFragment = null;
alision907bde72013-06-20 14:40:37 -040089 private MenuFragment fMenu;
alisionf76de3b2013-04-16 15:35:22 -040090
alision9f7a6ec2013-05-24 16:26:26 -040091 private boolean mBound = false;
92 private ISipService service;
alisionf76de3b2013-04-16 15:35:22 -040093
alision9f7a6ec2013-05-24 16:26:26 -040094 private CharSequence mDrawerTitle;
95 private CharSequence mTitle;
alisionf76de3b2013-04-16 15:35:22 -040096
alision2cb99562013-05-30 17:02:20 -040097 public static final int REQUEST_CODE_PREFERENCES = 1;
alision9f7a6ec2013-05-24 16:26:26 -040098 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -040099
alision0b553832013-05-30 09:31:06 -0400100 RelativeLayout mSliderButton;
alision9f7a6ec2013-05-24 16:26:26 -0400101 CustomSlidingDrawer mDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400102 private DrawerLayout mDrawerLayout;
alision9f7a6ec2013-05-24 16:26:26 -0400103 private ActionBarDrawerToggle mDrawerToggle;
104 /**
105 * The {@link ViewPager} that will host the section contents.
106 */
107 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400108
alision58356b72013-06-03 17:13:36 -0400109 CallReceiver callReceiver;
alision84813a12013-05-27 17:40:39 -0400110
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400111 // private TabHost mTabHost;
alisionf76de3b2013-04-16 15:35:22 -0400112
alision9f7a6ec2013-05-24 16:26:26 -0400113 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
114
115 /* called before activity is killed, e.g. rotation */
116 @Override
117 protected void onSaveInstanceState(Bundle bundle) {
118 super.onSaveInstanceState(bundle);
Alexandre Lision23628c12013-09-24 11:17:05 -0400119// for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
120// try {
121// getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i));
122// } catch (IllegalStateException e) {
123// Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i));
124// }
125// }
alision9f7a6ec2013-05-24 16:26:26 -0400126
127 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
128 Log.w(TAG, "onSaveInstanceState()");
129 }
130
131 @Override
132 public void onCreate(Bundle savedInstanceState) {
133 super.onCreate(savedInstanceState);
134
alision58356b72013-06-03 17:13:36 -0400135 callReceiver = new CallReceiver(this);
alision907bde72013-06-20 14:40:37 -0400136
alision2cb99562013-05-30 17:02:20 -0400137 // String libraryPath = getApplicationInfo().dataDir + "/lib";
138 // Log.i(TAG, libraryPath);
alision9f7a6ec2013-05-24 16:26:26 -0400139
alision58356b72013-06-03 17:13:36 -0400140 setContentView(R.layout.activity_sflphone_home);
141
alision9f7a6ec2013-05-24 16:26:26 -0400142 // Bind to LocalService
143 if (!mBound) {
144 Log.i(TAG, "onStart: Binding service...");
145 Intent intent = new Intent(this, SipService.class);
146 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
147 }
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400148
Alexandre Lision23628c12013-09-24 11:17:05 -0400149 if(savedInstanceState != null){
150 mContactsFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, "ContactsListFragment");
151 }
alision9f7a6ec2013-05-24 16:26:26 -0400152 if (mContactsFragment == null) {
153 mContactsFragment = new ContactListFragment();
154 Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment);
155 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
156 }
alision2ec64f92013-06-17 17:28:58 -0400157
alision9f7a6ec2013-05-24 16:26:26 -0400158 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400159
alision84813a12013-05-27 17:40:39 -0400160 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400161
162 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400163
alision9f7a6ec2013-05-24 16:26:26 -0400164 // Set up the ViewPager with the sections adapter.
165 mViewPager = (ViewPager) findViewById(R.id.pager);
alision55c36cb2013-06-14 14:57:38 -0400166 mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f));
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400167 final PagerTabStrip strip = PagerTabStrip.class.cast(mViewPager.findViewById(R.id.pts_main));
168 strip.setDrawFullUnderline(false);
169 strip.setTabIndicatorColor(getResources().getColor(R.color.holo_blue_dark));
170 strip.setBackgroundColor(getResources().getColor(R.color.darker_gray));
171 strip.setNonPrimaryAlpha(0.5f);
172 strip.setTextSpacing(25);
173 strip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
alisionf76de3b2013-04-16 15:35:22 -0400174
alision9f7a6ec2013-05-24 16:26:26 -0400175 mTitle = mDrawerTitle = getTitle();
176 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
alisionf76de3b2013-04-16 15:35:22 -0400177
alision0b553832013-05-30 09:31:06 -0400178 // set a custom shadow that overlays the main content when the drawer opens
alision9f7a6ec2013-05-24 16:26:26 -0400179 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
alisionf76de3b2013-04-16 15:35:22 -0400180
alision9f7a6ec2013-05-24 16:26:26 -0400181 getActionBar().setDisplayHomeAsUpEnabled(true);
182 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400183
alision9f7a6ec2013-05-24 16:26:26 -0400184 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
185 mDrawerLayout, /* DrawerLayout object */
186 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
187 R.string.drawer_open, /* "open drawer" description for accessibility */
188 R.string.drawer_close /* "close drawer" description for accessibility */
189 ) {
alision0b553832013-05-30 09:31:06 -0400190 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400191 public void onDrawerClosed(View view) {
192 getActionBar().setTitle(mTitle);
193 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
194 }
alisionf76de3b2013-04-16 15:35:22 -0400195
alision0b553832013-05-30 09:31:06 -0400196 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400197 public void onDrawerOpened(View drawerView) {
198 getActionBar().setTitle(mDrawerTitle);
199 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
200 }
201 };
alisionf76de3b2013-04-16 15:35:22 -0400202
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400203 // mTabHost = (TabHost) findViewById(android.R.id.tabhost);
alision9f7a6ec2013-05-24 16:26:26 -0400204 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400205
alision9f7a6ec2013-05-24 16:26:26 -0400206 }
alisionf76de3b2013-04-16 15:35:22 -0400207
alisionf57d8a62013-07-02 09:37:12 -0400208 @Override
209 protected void onPostCreate(Bundle savedInstanceState) {
210 super.onPostCreate(savedInstanceState);
211 // Sync the toggle state after onRestoreInstanceState has occurred.
212 mDrawerToggle.syncState();
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400213
214// Toast.makeText(this, "Mini Buff:"+AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT), Toast.LENGTH_LONG).show();
alisionf57d8a62013-07-02 09:37:12 -0400215 }
alision465ceba2013-07-04 09:24:30 -0400216
alisionf57d8a62013-07-02 09:37:12 -0400217 @Override
218 public void onConfigurationChanged(Configuration newConfig) {
219 super.onConfigurationChanged(newConfig);
220 mDrawerToggle.onConfigurationChanged(newConfig);
221 }
alision3c5c2a92013-05-30 09:50:47 -0400222
alision9f7a6ec2013-05-24 16:26:26 -0400223 @Override
224 protected void onStart() {
225 Log.i(TAG, "onStart");
226 super.onStart();
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400227
alision9f7a6ec2013-05-24 16:26:26 -0400228 }
alisionf76de3b2013-04-16 15:35:22 -0400229
alision9f7a6ec2013-05-24 16:26:26 -0400230 /* user gets back to the activity, e.g. through task manager */
231 @Override
232 protected void onRestart() {
233 super.onRestart();
234 }
alisionf76de3b2013-04-16 15:35:22 -0400235
alision9f7a6ec2013-05-24 16:26:26 -0400236 /* activity gets back to the foreground and user input */
237 @Override
238 protected void onResume() {
alision58356b72013-06-03 17:13:36 -0400239 super.onResume();
alision84813a12013-05-27 17:40:39 -0400240 IntentFilter intentFilter = new IntentFilter();
241 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
242 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
243 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
alision58356b72013-06-03 17:13:36 -0400244 registerReceiver(callReceiver, intentFilter);
alision907bde72013-06-20 14:40:37 -0400245
alision9f7a6ec2013-05-24 16:26:26 -0400246 }
alision907bde72013-06-20 14:40:37 -0400247
alisionbd45a822013-06-06 17:35:35 -0400248 private boolean isClosing = false;
249 private Timer t = new Timer();
alision907bde72013-06-20 14:40:37 -0400250
alisionbd45a822013-06-06 17:35:35 -0400251 @Override
252 public void onBackPressed() {
alision907bde72013-06-20 14:40:37 -0400253
254 if (getActionBar().getCustomView() != null) {
alision2ec64f92013-06-17 17:28:58 -0400255 getActionBar().setDisplayShowCustomEnabled(false);
256 getActionBar().setCustomView(null);
257 // Display all the contacts again
258 getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, mContactsFragment);
259 return;
260 }
alision907bde72013-06-20 14:40:37 -0400261
alisionbd45a822013-06-06 17:35:35 -0400262 if (mDrawer.isOpened()) {
alision55c36cb2013-06-14 14:57:38 -0400263 mDrawer.animateClose();
alisionbd45a822013-06-06 17:35:35 -0400264 return;
265 }
alision2ec64f92013-06-17 17:28:58 -0400266
alisionbd45a822013-06-06 17:35:35 -0400267 if (isClosing) {
268 super.onBackPressed();
269 t.cancel();
270 finish();
271 } else {
272
273 t.schedule(new TimerTask() {
274 @Override
275 public void run() {
276 isClosing = false;
277 }
278 }, 3000);
279 Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show();
280 isClosing = true;
281 }
282 }
alisione2a38e12013-04-25 14:20:20 -0400283
alision9f7a6ec2013-05-24 16:26:26 -0400284 /* activity no more in foreground */
285 @Override
286 protected void onPause() {
287 super.onPause();
alision58356b72013-06-03 17:13:36 -0400288 unregisterReceiver(callReceiver);
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400289 if (mBound) {
290 unbindService(mConnection);
291 mBound = false;
292 }
alision9f7a6ec2013-05-24 16:26:26 -0400293 }
alisionf76de3b2013-04-16 15:35:22 -0400294
alision9f7a6ec2013-05-24 16:26:26 -0400295 /* activity finishes itself or is being killed by the system */
296 @Override
297 protected void onDestroy() {
alision9f7a6ec2013-05-24 16:26:26 -0400298 super.onDestroy();
Alexandre Lisionb4a9e392013-10-01 14:39:43 -0400299 Log.i(TAG, "onDestroy: destroying service...");
300 Intent sipServiceIntent = new Intent(this, SipService.class);
301 stopService(sipServiceIntent);
alision9f7a6ec2013-05-24 16:26:26 -0400302 }
alision73424b62013-04-26 11:49:18 -0400303
alision55c36cb2013-06-14 14:57:38 -0400304 public void launchCallActivity(SipCall infos) {
alision9f7a6ec2013-05-24 16:26:26 -0400305 Log.i(TAG, "Launch Call Activity");
306 Bundle bundle = new Bundle();
alisiondf1dac92013-06-27 17:35:53 -0400307 Conference tmp = new Conference("-1");
alision465ceba2013-07-04 09:24:30 -0400308
alisiondf1dac92013-06-27 17:35:53 -0400309 tmp.getParticipants().add(infos);
alision465ceba2013-07-04 09:24:30 -0400310
alisiondf1dac92013-06-27 17:35:53 -0400311 bundle.putParcelable("conference", tmp);
alision9f7a6ec2013-05-24 16:26:26 -0400312 Intent intent = new Intent().setClass(this, CallActivity.class);
alisiondf1dac92013-06-27 17:35:53 -0400313 intent.putExtra("resuming", false);
alision9f7a6ec2013-05-24 16:26:26 -0400314 intent.putExtras(bundle);
315 startActivityForResult(intent, REQUEST_CODE_CALL);
Alexandre Lision0a300ff2013-09-23 14:22:34 -0400316// overridePendingTransition(R.anim.slide_down, R.anim.slide_up);
alision9f7a6ec2013-05-24 16:26:26 -0400317 }
alisionf76de3b2013-04-16 15:35:22 -0400318
alision9f7a6ec2013-05-24 16:26:26 -0400319 /** Defines callbacks for service binding, passed to bindService() */
320 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400321
alision9f7a6ec2013-05-24 16:26:26 -0400322 @Override
323 public void onServiceConnected(ComponentName className, IBinder binder) {
324 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400325
alision2cb99562013-05-30 17:02:20 -0400326 try {
alision58356b72013-06-03 17:13:36 -0400327
alision907bde72013-06-20 14:40:37 -0400328 fMenu = new MenuFragment();
329 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
alision58356b72013-06-03 17:13:36 -0400330 mSectionsPagerAdapter = new SectionsPagerAdapter(SFLPhoneHomeActivity.this, getFragmentManager());
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400331
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400332
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400333
334 // initialiseTabHost(null);
alisiondf1dac92013-06-27 17:35:53 -0400335 mViewPager.setOffscreenPageLimit(2);
alision58356b72013-06-03 17:13:36 -0400336 mViewPager.setAdapter(mSectionsPagerAdapter);
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400337 mViewPager.setCurrentItem(1);
338 // mTabHost.setCurrentTab(1);
alision2cb99562013-05-30 17:02:20 -0400339 service.destroyNotification();
alision58356b72013-06-03 17:13:36 -0400340 // mAdapter = new AccountSelectionAdapter(SFLPhoneHomeActivity.this, service, new ArrayList<Account>());
341 // spinnerAccounts.setAdapter(mAdapter);
alision2cb99562013-05-30 17:02:20 -0400342 } catch (RemoteException e) {
343 Log.e(TAG, e.toString());
344 }
alision9f7a6ec2013-05-24 16:26:26 -0400345 mBound = true;
alision9f7a6ec2013-05-24 16:26:26 -0400346 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400347
alision9f7a6ec2013-05-24 16:26:26 -0400348 }
alision5f899632013-04-22 17:26:56 -0400349
alision9f7a6ec2013-05-24 16:26:26 -0400350 @Override
351 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400352
alision9f7a6ec2013-05-24 16:26:26 -0400353 mBound = false;
354 Log.d(TAG, "Service disconnected service=" + service);
355 }
356 };
alision5f899632013-04-22 17:26:56 -0400357
alision9f7a6ec2013-05-24 16:26:26 -0400358 @Override
359 public boolean onOptionsItemSelected(MenuItem item) {
360 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400361
alision9f7a6ec2013-05-24 16:26:26 -0400362 if (mDrawerToggle.onOptionsItemSelected(item)) {
363 return true;
364 }
alision5f899632013-04-22 17:26:56 -0400365
alision9f7a6ec2013-05-24 16:26:26 -0400366 return super.onOptionsItemSelected(item);
367 }
alisionf76de3b2013-04-16 15:35:22 -0400368
alision9f7a6ec2013-05-24 16:26:26 -0400369 @Override
370 public void onActivityResult(int requestCode, int resultCode, Intent data) {
371 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400372
373 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400374 case REQUEST_CODE_PREFERENCES:
alision907bde72013-06-20 14:40:37 -0400375 Log.w(TAG, "In Activity");
376 fMenu.updateAllAccounts();
alision9f7a6ec2013-05-24 16:26:26 -0400377 break;
378 case REQUEST_CODE_CALL:
alision2cb99562013-05-30 17:02:20 -0400379 Log.w(TAG, "Result out of CallActivity");
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400380 if (resultCode == CallActivity.RESULT_FAILURE) {
381 Log.w(TAG, "CALL FAILEEEED");
382 }
383 // if (mSectionsPagerAdapter != null && mSectionsPagerAdapter.getItem(2) != null)
384 // getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, (HistoryFragment) mSectionsPagerAdapter.getItem(2));
alision9f7a6ec2013-05-24 16:26:26 -0400385 break;
386 }
alisionf76de3b2013-04-16 15:35:22 -0400387
alision9f7a6ec2013-05-24 16:26:26 -0400388 }
alisionf76de3b2013-04-16 15:35:22 -0400389
alision9f7a6ec2013-05-24 16:26:26 -0400390 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400391 public ISipService getService() {
392 return service;
393 }
alisionf76de3b2013-04-16 15:35:22 -0400394
alision84813a12013-05-27 17:40:39 -0400395 /**
396 * Interface implemented to handle incoming events
397 */
alision9f7a6ec2013-05-24 16:26:26 -0400398 @Override
alision84813a12013-05-27 17:40:39 -0400399 public void incomingCall(Intent call) {
400 Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show();
alisionfde875f2013-05-28 17:01:54 -0400401 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400402
alision58356b72013-06-03 17:13:36 -0400403 // mCallElementList.addCall(infos);
alisionfde875f2013-05-28 17:01:54 -0400404
alision55c36cb2013-06-14 14:57:38 -0400405 launchCallActivity(infos);
alision84813a12013-05-27 17:40:39 -0400406
407 }
408
409 @Override
410 public void callStateChanged(Intent callState) {
411 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
412 String cID = b.getString("CallID");
413 String state = b.getString("State");
414 Log.i(TAG, "callStateChanged" + cID + " " + state);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400415 mSectionsPagerAdapter.updateHome();
alision84813a12013-05-27 17:40:39 -0400416
417 }
418
419 @Override
420 public void incomingText(Intent msg) {
421 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
422 b.getString("CallID");
423 String from = b.getString("From");
424 String mess = b.getString("Msg");
425 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
426 }
427
428 @Override
alision55c36cb2013-06-14 14:57:38 -0400429 public void onContactSelected(final CallContact c) {
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400430
431 if (fMenu.getSelectedAccount() == null) {
432 // Toast.makeText(this, "No Account Selected", Toast.LENGTH_SHORT).show();
433 createAccountDialog().show();
434 return;
435 }
alisionfde875f2013-05-28 17:01:54 -0400436
alision55c36cb2013-06-14 14:57:38 -0400437 Thread launcher = new Thread(new Runnable() {
alision907bde72013-06-20 14:40:37 -0400438
alision55c36cb2013-06-14 14:57:38 -0400439 final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE };
440 final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE };
alision907bde72013-06-20 14:40:37 -0400441
alision55c36cb2013-06-14 14:57:38 -0400442 @Override
443 public void run() {
444 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
445 try {
Alexandre Lisionf0b993d2013-09-12 13:25:10 -0400446 callBuilder.startCallCreation().setAccountID(fMenu.getSelectedAccount().getAccountID())
alision907bde72013-06-20 14:40:37 -0400447 .setCallType(SipCall.state.CALL_TYPE_OUTGOING);
448 Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(),
449 null, null);
alision55c36cb2013-06-14 14:57:38 -0400450
alision907bde72013-06-20 14:40:37 -0400451 while (cPhones.moveToNext()) {
452 c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE)));
453 }
454 cPhones.close();
455
456 Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null,
457 null);
458
459 while (cSip.moveToNext()) {
460 c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE)));
461 }
462 cSip.close();
463 callBuilder.setContact(c);
alision55c36cb2013-06-14 14:57:38 -0400464 launchCallActivity(callBuilder.build());
465 } catch (RemoteException e1) {
466 Log.e(TAG, e1.toString());
467 } catch (Exception e) {
468 Log.e(TAG, e.toString());
469 }
alision907bde72013-06-20 14:40:37 -0400470
alision55c36cb2013-06-14 14:57:38 -0400471 }
472 });
473 launcher.start();
474 mDrawer.close();
alision84813a12013-05-27 17:40:39 -0400475
476 }
477
478 @Override
alision907bde72013-06-20 14:40:37 -0400479 public void onCallDialed(String to) {
alision84813a12013-05-27 17:40:39 -0400480
alisiondf1dac92013-06-27 17:35:53 -0400481 if (fMenu.getSelectedAccount() == null) {
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400482 // Toast.makeText(this, "No Account Selected", Toast.LENGTH_SHORT).show();
483 createAccountDialog().show();
alisiondf1dac92013-06-27 17:35:53 -0400484 return;
485 }
486
alisionfde875f2013-05-28 17:01:54 -0400487 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
alision907bde72013-06-20 14:40:37 -0400488 callBuilder.startCallCreation().setAccountID(fMenu.getSelectedAccount().getAccountID()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
489 callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400490
alisionfde875f2013-05-28 17:01:54 -0400491 try {
alision55c36cb2013-06-14 14:57:38 -0400492 launchCallActivity(callBuilder.build());
alisionfde875f2013-05-28 17:01:54 -0400493 } catch (Exception e) {
494 Log.e(TAG, e.toString());
495 }
alision84813a12013-05-27 17:40:39 -0400496
alision9f7a6ec2013-05-24 16:26:26 -0400497 }
alision371b77e2013-04-23 14:51:26 -0400498
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400499 private AlertDialog createAccountDialog() {
500 final Activity ownerActivity = this;
501 AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity);
502
503 builder.setMessage(getResources().getString(R.string.create_new_account_dialog))
504 .setTitle(getResources().getString(R.string.create_new_account_dialog_title))
505 .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
506 public void onClick(DialogInterface dialog, int whichButton) {
507 Intent in = new Intent();
508 in.setClass(ownerActivity, SFLPhonePreferenceActivity.class);
509 ownerActivity.startActivityForResult(in, SFLPhoneHomeActivity.REQUEST_CODE_PREFERENCES);
510 }
511 }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
512 public void onClick(DialogInterface dialog, int whichButton) {
513 dialog.dismiss();
514 }
515 });
516
517 AlertDialog alertDialog = builder.create();
518 alertDialog.setOwnerActivity(ownerActivity);
519
520 return alertDialog;
521 }
522
alisiond45da712013-05-30 09:18:49 -0400523 @Override
524 public void onContactDragged() {
525
526 mDrawer.close();
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400527 // mTabHost.setCurrentTab(1);
alisiond45da712013-05-30 09:18:49 -0400528
529 }
530
alision58356b72013-06-03 17:13:36 -0400531 @Override
532 public void openDrawer() {
alision55c36cb2013-06-14 14:57:38 -0400533 mDrawer.animateOpen();
alision58356b72013-06-03 17:13:36 -0400534 }
535
alision806e18e2013-06-21 15:30:17 -0400536 @Override
537 public void confCreated(Intent intent) {
538 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400539
alision806e18e2013-06-21 15:30:17 -0400540 }
541
542 @Override
543 public void confRemoved(Intent intent) {
544 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400545
alision806e18e2013-06-21 15:30:17 -0400546 }
547
548 @Override
549 public void confChanged(Intent intent) {
550 // TODO Auto-generated method stub
alisiondf1dac92013-06-27 17:35:53 -0400551
552 }
553
554 @Override
555 public void recordingChanged(Intent intent) {
556 // TODO Auto-generated method stub
557
558 }
559
560 @Override
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400561 public void selectedCall(Conference c) {
alisiondf1dac92013-06-27 17:35:53 -0400562 Intent intent = new Intent().setClass(this, CallActivity.class);
563 intent.putExtra("resuming", true);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400564 intent.putExtra("conference", c);
alisiondf1dac92013-06-27 17:35:53 -0400565 startActivityForResult(intent, REQUEST_CODE_CALL);
alision806e18e2013-06-21 15:30:17 -0400566 }
Alexandre Lisionee37f7c2013-09-25 17:36:39 -0400567
568 private class ZoomOutPageTransformer implements ViewPager.PageTransformer {
569 private static final float MIN_ALPHA = .6f;
570// private final float scalingStart;
571
572 public ZoomOutPageTransformer(float scalingStart) {
573 super();
574// this.scalingStart = 1 - scalingStart;
575 }
576
577 @Override
578 public void transformPage(View page, float position) {
579 // page.setRotationY(position * -30);
580 final float normalizedposition = Math.abs(Math.abs(position) - 1);
581 page.setAlpha(MIN_ALPHA + (1.f-MIN_ALPHA)*normalizedposition);
582 }
583 }
alision806e18e2013-06-21 15:30:17 -0400584
alisionf76de3b2013-04-16 15:35:22 -0400585}