blob: 5b3b187ca728b6d10604b7dab117ae2599747d71 [file] [log] [blame]
alisionf76de3b2013-04-16 15:35:22 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
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 */
32package com.savoirfairelinux.sflphone.client;
33
alision84813a12013-05-27 17:40:39 -040034import java.util.Random;
35
alisionf76de3b2013-04-16 15:35:22 -040036import android.app.ActionBar;
37import android.app.Activity;
38import android.app.Fragment;
alisionf76de3b2013-04-16 15:35:22 -040039import android.app.FragmentTransaction;
40import android.content.ComponentName;
41import android.content.Context;
42import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040043import android.content.IntentFilter;
alisionf76de3b2013-04-16 15:35:22 -040044import android.content.ServiceConnection;
45import android.os.Bundle;
46import android.os.IBinder;
alision5f899632013-04-22 17:26:56 -040047import android.os.RemoteException;
alision9f7a6ec2013-05-24 16:26:26 -040048import android.support.v4.app.ActionBarDrawerToggle;
49import android.support.v4.view.GravityCompat;
alisionf76de3b2013-04-16 15:35:22 -040050import android.support.v4.view.ViewPager;
alision9f7a6ec2013-05-24 16:26:26 -040051import android.support.v4.widget.DrawerLayout;
alisionf76de3b2013-04-16 15:35:22 -040052import android.util.Log;
alision9f7a6ec2013-05-24 16:26:26 -040053import android.view.MenuItem;
54import android.view.View;
alision7297bdb2013-05-21 11:56:55 -040055import android.widget.RelativeLayout;
alision04a00182013-05-10 17:05:29 -040056import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040057
58import com.savoirfairelinux.sflphone.R;
alision9f7a6ec2013-05-24 16:26:26 -040059import com.savoirfairelinux.sflphone.adapters.SectionsPagerAdapter;
alision84813a12013-05-27 17:40:39 -040060import com.savoirfairelinux.sflphone.client.receiver.CallReceiver;
alisionf76de3b2013-04-16 15:35:22 -040061import com.savoirfairelinux.sflphone.fragments.CallElementListFragment;
62import com.savoirfairelinux.sflphone.fragments.ContactListFragment;
alision7297bdb2013-05-21 11:56:55 -040063import com.savoirfairelinux.sflphone.fragments.DialingFragment;
alisiond9e29442013-04-17 16:10:18 -040064import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
alision9f7a6ec2013-05-24 16:26:26 -040065import com.savoirfairelinux.sflphone.fragments.MenuFragment;
alision84813a12013-05-27 17:40:39 -040066import com.savoirfairelinux.sflphone.interfaces.CallInterface;
67import com.savoirfairelinux.sflphone.model.CallContact;
68import com.savoirfairelinux.sflphone.model.CallContact.ContactBuilder;
alisionf76de3b2013-04-16 15:35:22 -040069import com.savoirfairelinux.sflphone.model.SipCall;
alision84813a12013-05-27 17:40:39 -040070import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
alisionf76de3b2013-04-16 15:35:22 -040071import com.savoirfairelinux.sflphone.service.ISipService;
72import com.savoirfairelinux.sflphone.service.SipService;
alision7297bdb2013-05-21 11:56:55 -040073import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer;
alisionf76de3b2013-04-16 15:35:22 -040074
alision84813a12013-05-27 17:40:39 -040075public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, DialingFragment.Callbacks, ContactListFragment.Callbacks,
76 CallElementListFragment.Callbacks, HistoryFragment.Callbacks, CallInterface {
alisionfde875f2013-05-28 17:01:54 -040077
alision9f7a6ec2013-05-24 16:26:26 -040078 SectionsPagerAdapter mSectionsPagerAdapter = null;
alision84813a12013-05-27 17:40:39 -040079 static final String TAG = "SFLPhoneHomeActivity";
alisionf76de3b2013-04-16 15:35:22 -040080
alision9f7a6ec2013-05-24 16:26:26 -040081 private ContactListFragment mContactsFragment = null;
82 private DialingFragment mDialingFragment = null;
83 private CallElementListFragment mCallElementList = null;
84 private HistoryFragment mHistorySectionFragment = null;
alisionf76de3b2013-04-16 15:35:22 -040085
alision9f7a6ec2013-05-24 16:26:26 -040086 Fragment fMenu;
alisionf76de3b2013-04-16 15:35:22 -040087
alision9f7a6ec2013-05-24 16:26:26 -040088 private boolean mBound = false;
89 private ISipService service;
alisionf76de3b2013-04-16 15:35:22 -040090
alision9f7a6ec2013-05-24 16:26:26 -040091 private CharSequence mDrawerTitle;
92 private CharSequence mTitle;
alisionf76de3b2013-04-16 15:35:22 -040093
alision9f7a6ec2013-05-24 16:26:26 -040094 private static final int REQUEST_CODE_PREFERENCES = 1;
95 private static final int REQUEST_CODE_CALL = 2;
alisionf76de3b2013-04-16 15:35:22 -040096
alision9f7a6ec2013-05-24 16:26:26 -040097 private static final int ACTION_BAR_TAB_DIALING = 0;
98 private static final int ACTION_BAR_TAB_CALL = 1;
99 private static final int ACTION_BAR_TAB_HISTORY = 2;
alisionf76de3b2013-04-16 15:35:22 -0400100
alision9f7a6ec2013-05-24 16:26:26 -0400101 RelativeLayout mSliderButton;
102 CustomSlidingDrawer mDrawer;
alision9f7a6ec2013-05-24 16:26:26 -0400103 private DrawerLayout mDrawerLayout;
alision9f7a6ec2013-05-24 16:26:26 -0400104 private ActionBarDrawerToggle mDrawerToggle;
105 /**
106 * The {@link ViewPager} that will host the section contents.
107 */
108 ViewPager mViewPager;
alisionf76de3b2013-04-16 15:35:22 -0400109
alision84813a12013-05-27 17:40:39 -0400110 CallReceiver receiver;
111
alision9f7a6ec2013-05-24 16:26:26 -0400112 final private int[] icon_res_id = { R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history };
alisionf76de3b2013-04-16 15:35:22 -0400113
alision9f7a6ec2013-05-24 16:26:26 -0400114 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
115
116 /* called before activity is killed, e.g. rotation */
117 @Override
118 protected void onSaveInstanceState(Bundle bundle) {
119 super.onSaveInstanceState(bundle);
120 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
121 try {
122 getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i));
123 } catch (IllegalStateException e) {
124 Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i));
125 }
126 }
127
128 getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment);
129 Log.w(TAG, "onSaveInstanceState()");
130 }
131
132 @Override
133 public void onCreate(Bundle savedInstanceState) {
134 super.onCreate(savedInstanceState);
135
alision84813a12013-05-27 17:40:39 -0400136 receiver = new CallReceiver(this);
137
alision9f7a6ec2013-05-24 16:26:26 -0400138 String libraryPath = getApplicationInfo().dataDir + "/lib";
139 Log.i(TAG, libraryPath);
140
141 // Bind to LocalService
142 if (!mBound) {
143 Log.i(TAG, "onStart: Binding service...");
144 Intent intent = new Intent(this, SipService.class);
145 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
146 }
147
148 setContentView(R.layout.activity_sflphone_home);
149
150 if (mSectionsPagerAdapter == null) {
151 mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager());
152 }
153
154 /* getFragment(Bundle, String) */
155 if (savedInstanceState != null) {
156 Log.w(TAG, "Activity restarted, recreating PagerAdapter...");
157 /* getFragment (Bundle bundle, String key) */
158 mDialingFragment = (DialingFragment) getFragmentManager().getFragment(savedInstanceState,
159 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_DIALING));
160 mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState,
161 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL));
162 mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState,
163 mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY));
164 }
165
166 if (mDialingFragment == null) {
167 mDialingFragment = new DialingFragment();
alision7297bdb2013-05-21 11:56:55 -0400168 Log.w(TAG, "Recreated mDialingFragment=" + mDialingFragment);
alision9f7a6ec2013-05-24 16:26:26 -0400169 }
alisionf76de3b2013-04-16 15:35:22 -0400170
alision9f7a6ec2013-05-24 16:26:26 -0400171 if (mContactsFragment == null) {
172 mContactsFragment = new ContactListFragment();
173 Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment);
174 getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit();
175 }
176 if (mCallElementList == null) {
177 mCallElementList = new CallElementListFragment();
178 Log.w(TAG, "Recreated mCallElementList=" + mCallElementList);
179 }
180 if (mHistorySectionFragment == null) {
181 mHistorySectionFragment = new HistoryFragment();
182 Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment);
183 }
184
185 mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer);
alision7297bdb2013-05-21 11:56:55 -0400186
alision84813a12013-05-27 17:40:39 -0400187 mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button));
alision7297bdb2013-05-21 11:56:55 -0400188
189 mDrawer.setmTrackHandle(findViewById(R.id.handle_title));
alisionf76de3b2013-04-16 15:35:22 -0400190
alision9f7a6ec2013-05-24 16:26:26 -0400191 final ActionBar actionBar = getActionBar();
192 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
alisionf76de3b2013-04-16 15:35:22 -0400193
alision9f7a6ec2013-05-24 16:26:26 -0400194 // Set up the ViewPager with the sections adapter.
195 mViewPager = (ViewPager) findViewById(R.id.pager);
196 mViewPager.setAdapter(mSectionsPagerAdapter);
alisionf76de3b2013-04-16 15:35:22 -0400197
alision9f7a6ec2013-05-24 16:26:26 -0400198 mTitle = mDrawerTitle = getTitle();
199 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
200 // mDrawerList = (ListView) findViewById(R.id.left_drawer);
alisionf76de3b2013-04-16 15:35:22 -0400201
alision9f7a6ec2013-05-24 16:26:26 -0400202 // set a custom shadow that overlays the main content when the drawer opens
203 mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
204 // set up the drawer's list view with items and click listener
205 // mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles));
206 // mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
alisionf76de3b2013-04-16 15:35:22 -0400207
alision9f7a6ec2013-05-24 16:26:26 -0400208 getActionBar().setDisplayHomeAsUpEnabled(true);
209 getActionBar().setHomeButtonEnabled(true);
alisionf76de3b2013-04-16 15:35:22 -0400210
alision9f7a6ec2013-05-24 16:26:26 -0400211 mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
212 mDrawerLayout, /* DrawerLayout object */
213 R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
214 R.string.drawer_open, /* "open drawer" description for accessibility */
215 R.string.drawer_close /* "close drawer" description for accessibility */
216 ) {
217 public void onDrawerClosed(View view) {
218 getActionBar().setTitle(mTitle);
219 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
220 }
alisionf76de3b2013-04-16 15:35:22 -0400221
alision9f7a6ec2013-05-24 16:26:26 -0400222 public void onDrawerOpened(View drawerView) {
223 getActionBar().setTitle(mDrawerTitle);
224 invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
225 }
226 };
alisionf76de3b2013-04-16 15:35:22 -0400227
alision9f7a6ec2013-05-24 16:26:26 -0400228 mDrawerLayout.setDrawerListener(mDrawerToggle);
alisionf76de3b2013-04-16 15:35:22 -0400229
alision9f7a6ec2013-05-24 16:26:26 -0400230 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
231 @Override
232 public void onPageSelected(int position) {
233 actionBar.setSelectedNavigationItem(position);
234 }
235 });
alisionf76de3b2013-04-16 15:35:22 -0400236
alision9f7a6ec2013-05-24 16:26:26 -0400237 // For each of the sections in the app, add a tab to the action bar.
238 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
alisionf76de3b2013-04-16 15:35:22 -0400239
alision9f7a6ec2013-05-24 16:26:26 -0400240 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
241 }
alisionf76de3b2013-04-16 15:35:22 -0400242
alision9f7a6ec2013-05-24 16:26:26 -0400243 actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
alisionf76de3b2013-04-16 15:35:22 -0400244
alision9f7a6ec2013-05-24 16:26:26 -0400245 fMenu = new MenuFragment();
246 getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit();
247 }
alisionf76de3b2013-04-16 15:35:22 -0400248
alision9f7a6ec2013-05-24 16:26:26 -0400249 @Override
250 protected void onStart() {
251 Log.i(TAG, "onStart");
252 super.onStart();
253 }
alisionf76de3b2013-04-16 15:35:22 -0400254
alision9f7a6ec2013-05-24 16:26:26 -0400255 /* user gets back to the activity, e.g. through task manager */
256 @Override
257 protected void onRestart() {
258 super.onRestart();
259 }
alisionf76de3b2013-04-16 15:35:22 -0400260
alision9f7a6ec2013-05-24 16:26:26 -0400261 /* activity gets back to the foreground and user input */
262 @Override
263 protected void onResume() {
264 Log.i(TAG, "onResume");
alision84813a12013-05-27 17:40:39 -0400265 IntentFilter intentFilter = new IntentFilter();
266 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
267 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
268 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
269 registerReceiver(receiver, intentFilter);
alision9f7a6ec2013-05-24 16:26:26 -0400270 super.onResume();
271 }
alisione2a38e12013-04-25 14:20:20 -0400272
alision9f7a6ec2013-05-24 16:26:26 -0400273 /* activity no more in foreground */
274 @Override
275 protected void onPause() {
276 super.onPause();
alision84813a12013-05-27 17:40:39 -0400277 unregisterReceiver(receiver);
alision9f7a6ec2013-05-24 16:26:26 -0400278 }
alisionf76de3b2013-04-16 15:35:22 -0400279
alision9f7a6ec2013-05-24 16:26:26 -0400280 /* activity is no longer visible */
281 @Override
282 protected void onStop() {
283 super.onStop();
284 }
alisionf76de3b2013-04-16 15:35:22 -0400285
alision9f7a6ec2013-05-24 16:26:26 -0400286 /* activity finishes itself or is being killed by the system */
287 @Override
288 protected void onDestroy() {
289 /* stop the service, if no other bound user, no need to check if it is running */
290 if (mBound) {
291 Log.i(TAG, "onDestroy: Unbinding service...");
292 unbindService(mConnection);
293 mBound = false;
294 }
alision371b77e2013-04-23 14:51:26 -0400295
alision9f7a6ec2013-05-24 16:26:26 -0400296 super.onDestroy();
297 }
alision73424b62013-04-26 11:49:18 -0400298
alisionfde875f2013-05-28 17:01:54 -0400299 public void launchCallActivity(SipCall infos, String action) {
alision9f7a6ec2013-05-24 16:26:26 -0400300 Log.i(TAG, "Launch Call Activity");
301 Bundle bundle = new Bundle();
alision84813a12013-05-27 17:40:39 -0400302 bundle.putString("action", action);
alision9f7a6ec2013-05-24 16:26:26 -0400303 bundle.putParcelable("CallInfo", infos);
304 Intent intent = new Intent().setClass(this, CallActivity.class);
305 intent.putExtras(bundle);
306 startActivityForResult(intent, REQUEST_CODE_CALL);
307 }
alisionf76de3b2013-04-16 15:35:22 -0400308
alision9f7a6ec2013-05-24 16:26:26 -0400309 /** Defines callbacks for service binding, passed to bindService() */
310 private ServiceConnection mConnection = new ServiceConnection() {
alision371b77e2013-04-23 14:51:26 -0400311
alision9f7a6ec2013-05-24 16:26:26 -0400312 @Override
313 public void onServiceConnected(ComponentName className, IBinder binder) {
314 service = ISipService.Stub.asInterface(binder);
alisione2a38e12013-04-25 14:20:20 -0400315
alision9f7a6ec2013-05-24 16:26:26 -0400316 mBound = true;
317 mCallElementList.onServiceSipBinded(service);
318 mHistorySectionFragment.onServiceSipBinded(service);
319 mDialingFragment.onServiceSipBinded(service);
320 Log.d(TAG, "Service connected service=" + service);
alision371b77e2013-04-23 14:51:26 -0400321
alision9f7a6ec2013-05-24 16:26:26 -0400322 }
alision5f899632013-04-22 17:26:56 -0400323
alision9f7a6ec2013-05-24 16:26:26 -0400324 @Override
325 public void onServiceDisconnected(ComponentName arg0) {
alision5f899632013-04-22 17:26:56 -0400326
alision9f7a6ec2013-05-24 16:26:26 -0400327 mBound = false;
328 Log.d(TAG, "Service disconnected service=" + service);
329 }
330 };
alision5f899632013-04-22 17:26:56 -0400331
alision9f7a6ec2013-05-24 16:26:26 -0400332 @Override
333 public boolean onOptionsItemSelected(MenuItem item) {
334 Log.i(TAG, "onOptionsItemSelected " + item.getItemId());
alision5f899632013-04-22 17:26:56 -0400335
alision9f7a6ec2013-05-24 16:26:26 -0400336 if (mDrawerToggle.onOptionsItemSelected(item)) {
337 return true;
338 }
alision5f899632013-04-22 17:26:56 -0400339
alision9f7a6ec2013-05-24 16:26:26 -0400340 return super.onOptionsItemSelected(item);
341 }
alisionf76de3b2013-04-16 15:35:22 -0400342
alision9f7a6ec2013-05-24 16:26:26 -0400343 @Override
344 public void onActivityResult(int requestCode, int resultCode, Intent data) {
345 super.onActivityResult(requestCode, resultCode, data);
alision84813a12013-05-27 17:40:39 -0400346
347 switch (requestCode) {
alision9f7a6ec2013-05-24 16:26:26 -0400348 case REQUEST_CODE_PREFERENCES:
349 mCallElementList.onServiceSipBinded(service);
350 break;
351 case REQUEST_CODE_CALL:
alision84813a12013-05-27 17:40:39 -0400352
alision9f7a6ec2013-05-24 16:26:26 -0400353 break;
354 }
alisionf76de3b2013-04-16 15:35:22 -0400355
alision9f7a6ec2013-05-24 16:26:26 -0400356 }
alisionf76de3b2013-04-16 15:35:22 -0400357
alision9f7a6ec2013-05-24 16:26:26 -0400358 // @Override
359 // public boolean onCreateOptionsMenu(Menu menu) {
360 // getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
361 // return true;
362 // }
alisionf76de3b2013-04-16 15:35:22 -0400363
alision9f7a6ec2013-05-24 16:26:26 -0400364 @Override
365 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
366 }
alisionf76de3b2013-04-16 15:35:22 -0400367
alision9f7a6ec2013-05-24 16:26:26 -0400368 @Override
369 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
370 // When the given tab is selected, switch to the corresponding page in the ViewPager.
371 mViewPager.setCurrentItem(tab.getPosition());
372 }
alisionf76de3b2013-04-16 15:35:22 -0400373
alision9f7a6ec2013-05-24 16:26:26 -0400374 @Override
375 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
376 // Log.d(TAG, "onTabReselected");
377 }
alisionf76de3b2013-04-16 15:35:22 -0400378
alision9f7a6ec2013-05-24 16:26:26 -0400379 @Override
380 public void onCallSelected(SipCall c) {
alision84813a12013-05-27 17:40:39 -0400381 // launchCallActivity(c.mCallInfo);
alisionf76de3b2013-04-16 15:35:22 -0400382
alision9f7a6ec2013-05-24 16:26:26 -0400383 }
alisionf76de3b2013-04-16 15:35:22 -0400384
alision9f7a6ec2013-05-24 16:26:26 -0400385 @Override
386 public ISipService getService() {
387 return service;
388 }
alisionf76de3b2013-04-16 15:35:22 -0400389
alision84813a12013-05-27 17:40:39 -0400390 /**
391 * Interface implemented to handle incoming events
392 */
alision9f7a6ec2013-05-24 16:26:26 -0400393 @Override
alision84813a12013-05-27 17:40:39 -0400394 public void incomingCall(Intent call) {
395 Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show();
alisionfde875f2013-05-28 17:01:54 -0400396 SipCall infos = call.getParcelableExtra("newcall");
alision84813a12013-05-27 17:40:39 -0400397
alisionfde875f2013-05-28 17:01:54 -0400398 mCallElementList.addCall(infos);
399
alision84813a12013-05-27 17:40:39 -0400400 launchCallActivity(infos, CallManagerCallBack.INCOMING_CALL);
401
402 }
403
404 @Override
405 public void callStateChanged(Intent callState) {
406 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
407 String cID = b.getString("CallID");
408 String state = b.getString("State");
409 Log.i(TAG, "callStateChanged" + cID + " " + state);
410 mCallElementList.updateCall(cID, state);
411
412 }
413
414 @Override
415 public void incomingText(Intent msg) {
416 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
417 b.getString("CallID");
418 String from = b.getString("From");
419 String mess = b.getString("Msg");
420 Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
421 }
422
423 @Override
424 public void onContactSelected(CallContact c) {
alisionfde875f2013-05-28 17:01:54 -0400425
426 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
alision84813a12013-05-27 17:40:39 -0400427 try {
alisionfde875f2013-05-28 17:01:54 -0400428 callBuilder.startCallCreation().setAccountID(service.getAccountList().get(1).toString()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
429 } catch (RemoteException e1) {
430 Log.e(TAG,e1.toString());
431 }
432 callBuilder.addContact(c);
433
434 try {
435 launchCallActivity(callBuilder.build(), "call");
436 } catch (Exception e) {
alision84813a12013-05-27 17:40:39 -0400437 Log.e(TAG, e.toString());
438 }
alision84813a12013-05-27 17:40:39 -0400439
440 }
441
442 @Override
443 public void onCallDialed(String accountID, String to) {
alision84813a12013-05-27 17:40:39 -0400444
alisionfde875f2013-05-28 17:01:54 -0400445 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
446 callBuilder.startCallCreation().setAccountID(accountID).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
447 callBuilder.addContact(CallContact.ContactBuilder.buildUnknownContact(to));
alision84813a12013-05-27 17:40:39 -0400448
alisionfde875f2013-05-28 17:01:54 -0400449 try {
450 launchCallActivity(callBuilder.build(), "call");
451 } catch (Exception e) {
452 Log.e(TAG, e.toString());
453 }
alision84813a12013-05-27 17:40:39 -0400454
alision9f7a6ec2013-05-24 16:26:26 -0400455 }
alision371b77e2013-04-23 14:51:26 -0400456
alisionf76de3b2013-04-16 15:35:22 -0400457}