blob: 5f430168a41ca798d9fef3798464e01807adfebc [file] [log] [blame]
Adrien Béraudffd32412012-08-07 18:39:23 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
4 * Author: Adrien Beraud <adrien.beraud@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31package com.savoirfairelinux.sflphone.client;
32
Emeric Vigiere89b48b2012-08-30 14:16:46 -040033import java.util.Random;
34
Adrien Béraudffd32412012-08-07 18:39:23 -040035import android.app.ActionBar;
36import android.app.Activity;
Emeric Vigier12d61d82012-09-19 15:08:18 -040037import android.app.AlertDialog;
Adrien Béraudffd32412012-08-07 18:39:23 -040038import android.app.Fragment;
39import android.app.FragmentManager;
40import android.app.FragmentTransaction;
Emeric Vigier6119d782012-09-21 18:04:14 -040041import android.content.ComponentName;
42import android.content.Context;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040043import android.content.Intent;
Emeric Vigier6119d782012-09-21 18:04:14 -040044import android.content.ServiceConnection;
Adrien Béraudffd32412012-08-07 18:39:23 -040045import android.os.Bundle;
Emeric Vigier383b2a22012-08-27 14:20:05 -040046import android.os.Handler;
Emeric Vigier6119d782012-09-21 18:04:14 -040047import android.os.IBinder;
Emeric Vigier383b2a22012-08-27 14:20:05 -040048import android.os.Message;
Emeric Vigier6119d782012-09-21 18:04:14 -040049import android.os.RemoteException;
Adrien Béraudffd32412012-08-07 18:39:23 -040050import android.support.v13.app.FragmentStatePagerAdapter;
51import android.support.v4.view.ViewPager;
Emeric Vigier05e894e2012-08-20 13:53:02 -040052import android.util.Log;
Adrien Béraudffd32412012-08-07 18:39:23 -040053import android.view.Gravity;
54import android.view.LayoutInflater;
55import android.view.Menu;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040056import android.view.MenuItem;
Adrien Béraudffd32412012-08-07 18:39:23 -040057import android.view.View;
Emeric Vigier05e894e2012-08-20 13:53:02 -040058import android.view.View.OnClickListener;
Adrien Béraudffd32412012-08-07 18:39:23 -040059import android.view.ViewGroup;
Emeric Vigiera6bdb702012-08-31 15:34:53 -040060import android.view.animation.AlphaAnimation;
61import android.view.animation.Animation;
62import android.view.animation.LinearInterpolator;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040063import android.widget.Button;
Emeric Vigierd5c17f52012-08-29 09:29:33 -040064import android.widget.EditText;
Emeric Vigiere89b48b2012-08-30 14:16:46 -040065import android.widget.ImageButton;
Adrien Béraudffd32412012-08-07 18:39:23 -040066import android.widget.TextView;
67
68import com.savoirfairelinux.sflphone.R;
Emeric Vigier6119d782012-09-21 18:04:14 -040069import com.savoirfairelinux.sflphone.service.ISipService;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040070import com.savoirfairelinux.sflphone.service.SipService;
Alexandre Savard6b8d1df2012-10-23 16:44:43 -040071import com.savoirfairelinux.sflphone.utils.AccountList;
Adrien Béraudffd32412012-08-07 18:39:23 -040072
Alexandre Savard7a902bc2012-10-04 16:32:35 -040073import java.util.HashMap;
74
Emeric Vigier62ca14d2012-08-24 11:05:09 -040075public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
Adrien Béraudffd32412012-08-07 18:39:23 -040076{
Alexandre Savard6c0584e2012-09-20 09:42:59 -040077 SectionsPagerAdapter mSectionsPagerAdapter;
78 static final String TAG = "SFLPhoneHome";
79 private ButtonSectionFragment buttonFragment;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040080 /* default callID */
81 static String callID = "007";
82 static boolean callOnGoing = false;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040083 static boolean serviceIsOn = false;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040084 private String incomingCallID = "";
85 private static final int REQUEST_CODE_PREFERENCES = 1;
86 ImageButton buttonCall, buttonHangup;
87 Button buttonService;
Emeric Vigier419ba7b2012-09-19 14:55:14 -040088 static Animation animation;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040089 ContactListFragment mContactListFragment;
90 CallElementList mCallElementList;
Emeric Vigier6119d782012-09-21 18:04:14 -040091 private boolean mBound = false;
92 private ISipService service;
Alexandre Savard6b8d1df2012-10-23 16:44:43 -040093 public AccountList mAccountList = new AccountList();
Adrien Béraudffd32412012-08-07 18:39:23 -040094
Alexandre Savard6c0584e2012-09-20 09:42:59 -040095 /**
96 * The {@link ViewPager} that will host the section contents.
97 */
98 ViewPager mViewPager;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -040099
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400100 final private int[] icon_res_id = {R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history, R.drawable.ic_tab_play_selected};
Adrien Béraudffd32412012-08-07 18:39:23 -0400101
Alexandre Savard817dc502012-10-22 11:47:29 -0400102 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
103
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400104 @Override
105 public void onCreate(Bundle savedInstanceState)
106 {
107 super.onCreate(savedInstanceState);
Alexandre Savard817dc502012-10-22 11:47:29 -0400108
109 if (!serviceIsOn) {
110 Log.i(TAG, "starting SipService");
111 startSipService();
112 }
113
114 // Bind to LocalService
115 if (!mBound) {
116 Log.i(TAG, "onStart: Binding service...");
117 Intent intent = new Intent(this, SipService.class);
118 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
119 }
120
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400121 setContentView(R.layout.activity_sflphone_home);
Adrien Béraudffd32412012-08-07 18:39:23 -0400122
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400123 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
Adrien Béraudffd32412012-08-07 18:39:23 -0400124
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400125 final ActionBar actionBar = getActionBar();
126 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
127 // final ActionBar actionBar = getActionBar();
Adrien Béraudffd32412012-08-07 18:39:23 -0400128
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400129 // Set up the ViewPager with the sections adapter.
130 mViewPager = (ViewPager) findViewById(R.id.pager);
131 mViewPager.setAdapter(mSectionsPagerAdapter);
Adrien Béraudffd32412012-08-07 18:39:23 -0400132
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400133 // When swiping between different sections, select the corresponding tab.
134 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
135 // Tab.
136 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
137 {
138 @Override
139 public void onPageSelected(int position)
140 {
141 actionBar.setSelectedNavigationItem(position);
142 }
143 });
Emeric Vigier383b2a22012-08-27 14:20:05 -0400144
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400145 // For each of the sections in the app, add a tab to the action bar.
146 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
147 // Create a tab with text corresponding to the page title defined by the adapter.
148 // Also specify this Activity object, which implements the TabListener interface, as the
149 // listener for when this tab is selected.
150 Log.i(TAG, "adding tab: " + i);
151 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
152 }
Emeric Vigier383b2a22012-08-27 14:20:05 -0400153
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400154 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
155 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400156
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400157 // Change alpha from fully visible to invisible
158 animation = new AlphaAnimation(1, 0);
159 // duration - half a second
160 animation.setDuration(500);
161 // do not alter animation rate
162 animation.setInterpolator(new LinearInterpolator());
163 // Repeat animation infinitely
164 animation.setRepeatCount(Animation.INFINITE);
165 // Reverse
166 animation.setRepeatMode(Animation.REVERSE);
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400167 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400168
Emeric Vigier12d61d82012-09-19 15:08:18 -0400169 @Override
170 protected void onStart() {
171 Log.i(TAG, "onStart");
172 super.onStart();
173 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400174
Emeric Vigier6119d782012-09-21 18:04:14 -0400175 /* user gets back to the activity, e.g. through task manager */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400176 @Override
177 protected void onRestart() {
178 super.onRestart();
179 }
180
Emeric Vigier6119d782012-09-21 18:04:14 -0400181 /* activity gets back to the foreground and user input */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400182 @Override
183 protected void onResume() {
184 Log.i(TAG, "onResume");
185 super.onResume();
Emeric Vigier12d61d82012-09-19 15:08:18 -0400186 }
187
Emeric Vigier6119d782012-09-21 18:04:14 -0400188 /* activity no more in foreground */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400189 @Override
190 protected void onPause() {
Emeric Vigier12d61d82012-09-19 15:08:18 -0400191 super.onPause();
192 }
193
Emeric Vigier6119d782012-09-21 18:04:14 -0400194 /* activity is no longer visible */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400195 @Override
196 protected void onStop() {
197 super.onStop();
Alexandre Savard817dc502012-10-22 11:47:29 -0400198 }
199
200 /* activity finishes itself or is being killed by the system */
201 @Override
202 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400203 /* stop the service, if no other bound user, no need to check if it is running */
204 if (mBound) {
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400205 Log.i(TAG, "onStop: Unbinding service...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400206 unbindService(mConnection);
207 mBound = false;
208 }
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400209 Log.i(TAG, "onDestroy: stopping SipService...");
210 stopService(new Intent(this, SipService.class));
Emeric Vigier6119d782012-09-21 18:04:14 -0400211 serviceIsOn = false;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400212 super.onDestroy();
213 }
214
Emeric Vigier6119d782012-09-21 18:04:14 -0400215 /** Defines callbacks for service binding, passed to bindService() */
216 private ServiceConnection mConnection = new ServiceConnection() {
217
218 @Override
219 public void onServiceConnected(ComponentName className,
220 IBinder binder) {
221 service = ISipService.Stub.asInterface(binder);
222 mBound = true;
Alexandre Savard817dc502012-10-22 11:47:29 -0400223 mContactListFragment.setService(service);
224 mCallElementList.setService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400225 Log.d(TAG, "Service connected");
226 }
227
228 @Override
229 public void onServiceDisconnected(ComponentName arg0) {
230 mBound = false;
231 Log.d(TAG, "Service disconnected");
232 }
233 };
234
Emeric Vigier12d61d82012-09-19 15:08:18 -0400235 private void startSipService() {
236 Thread thread = new Thread("StartSFLphoneService") {
237 public void run() {
238 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
239 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
240 startService(sipServiceIntent);
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400241 serviceIsOn = true;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400242 };
243 };
244 try {
245 thread.start();
246 } catch (IllegalThreadStateException e) {
247 AlertDialog.Builder builder = new AlertDialog.Builder(this);
248 builder.setMessage("Cannot start SFLPhone SipService!");
249 AlertDialog alert = builder.create();
250 alert.show();
251 finish();
252 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400253 }
254
255 @Override
256 public boolean onOptionsItemSelected(MenuItem item) {
257 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400258 if(item.getItemId() != 0) {
259 // When the button is clicked, launch an activity through this intent
260 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400261
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400262 // Make it a subactivity so we know when it returns
263 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400264 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400265
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400266 return super.onOptionsItemSelected(item);
267 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400268
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400269 @Override
270 public boolean onCreateOptionsMenu(Menu menu)
271 {
272 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
273 return true;
274 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400275
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400276 @Override
277 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
278 {
279 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400280
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400281 @Override
282 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
283 {
284 // When the given tab is selected, switch to the corresponding page in the ViewPager.
285 mViewPager.setCurrentItem(tab.getPosition());
286 }
287
288 @Override
289 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
290 {
291 // Log.d(TAG, "onTabReselected");
292 }
293
294 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400295 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400296 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400297 buttonCall.startAnimation(animation);
298 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400299 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400300
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400301 /**
302 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
303 * one of the primary sections of the app.
304 */
305 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
306 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400307
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400308 public SectionsPagerAdapter(FragmentManager fm)
309 {
310 super(fm);
311 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400312
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400313 @Override
314 public Fragment getItem(int i)
315 {
316 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400317
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400318 switch (i) {
319 case 0:
Alexandre Savard817dc502012-10-22 11:47:29 -0400320 mContactListFragment = new ContactListFragment(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400321 fragment = mContactListFragment;
322 break;
323 case 1:
Alexandre Savard817dc502012-10-22 11:47:29 -0400324 mCallElementList = new CallElementList(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400325 SipCall.setCallElementList(mCallElementList);
326 fragment = mCallElementList;
327 break;
328 case 2:
329 fragment = new DummySectionFragment();
330 break;
331 case 3:
332 fragment = new ButtonSectionFragment();
333 Log.i(TAG, "getItem: fragment is " + fragment);
334 break;
335 default:
336 Log.e(TAG, "getItem: unknown tab position " + i);
337 return null;
338 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400339
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400340 Bundle args = new Bundle();
341 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
342 fragment.setArguments(args);
343 return fragment;
344 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400345
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400346 @Override
347 public int getCount()
348 {
349 return 4;
350 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400351
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400352 @Override
353 public CharSequence getPageTitle(int position)
354 {
355 switch (position) {
356 case 0:
357 return getString(R.string.title_section0).toUpperCase();
358 case 1:
359 return getString(R.string.title_section1).toUpperCase();
360 case 2:
361 return getString(R.string.title_section2).toUpperCase();
362 case 3:
363 return getString(R.string.title_section3).toUpperCase();
364 default:
365 Log.e(TAG, "getPageTitle: unknown tab position " + position);
366 break;
367 }
368 return null;
369 }
370 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400371
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400372 /**
373 * A dummy fragment representing a section of the app, but that simply
374 * displays dummy text.
375 */
376 public static class DummySectionFragment extends Fragment
377 {
378 public DummySectionFragment()
379 {
380 setRetainInstance(true);
381 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400382
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400383 public static final String ARG_SECTION_NUMBER = "section_number";
384
385 @Override
386 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
387 {
388 TextView textView = new TextView(getActivity());
389 textView.setGravity(Gravity.CENTER);
390 Bundle args = getArguments();
391 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
392 textView.setText("java sucks");
393 return textView;
394 }
395 }
396
397 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400398 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400399 {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400400 Log.i(TAG, "onClic from SFLPhoneHome");
Alexandre Savard2c50e692012-09-24 11:18:31 -0400401
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400402 buttonService = (Button) findViewById(R.id.buttonService);
Emeric Vigier6119d782012-09-21 18:04:14 -0400403
404 try {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400405 switch (view.getId()) {
406 case R.id.buttonCall:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400407 Log.i(TAG, "Processing new call action");
408 processingNewCallAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400409 break;
410 case R.id.buttonHangUp:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400411 Log.i(TAG, "Processing hangup action");
412 processingHangUpAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400413 break;
414 case R.id.buttonInit:
415 Log.i(TAG, "R.id.buttonInit");
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400416 // String audioPlugin = service.getCurrentAudioOutputPlugin();
417 HashMap<String, String> map = (HashMap<String, String>)service.getAccountDetails("Account:1345153770");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400418 break;
419 case R.id.buttonService:
420 if (!serviceIsOn) {
421 startService(new Intent(this, SipService.class));
422 serviceIsOn = true;
423 buttonService.setText("disable Service");
424 }
425 else {
426 stopService(new Intent(this, SipService.class));
427 serviceIsOn = false;
428 buttonService.setText("enable Service");
429 }
430 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400431 default:
432 Log.w(TAG, "unknown button " + view.getId());
433 break;
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400434 }
Emeric Vigier6119d782012-09-21 18:04:14 -0400435 } catch (RemoteException e) {
436 Log.e(TAG, "Cannot call service method", e);
437 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400438 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400439
440 public void processingNewCallAction() {
Alexandre Savard14323be2012-10-24 10:02:13 -0400441 /*
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400442 Log.d(TAG, "ProcessingNewCallAction()");
443 TextView textView = (TextView) findViewById(R.id.editAccountID);
444 String accountID = mAccountList.currentAccountID;
445 // String accountID = textView.getText().toString();
446 // buttonCall.setImageResource(R.drawable.ic_call);
447 EditText editText;
448 Random random = new Random();
449
450 try {
451
452 if (incomingCallID != "") {
453 Log.d(TAG, "Incoming Call Branch");
454 buttonCall.clearAnimation();
455 service.accept(incomingCallID);
456 callID = incomingCallID;
457 incomingCallID="";
458 callOnGoing = true;
459 buttonCall.setEnabled(false);
460 buttonHangup.setEnabled(true);
461 } else {
462 //if (callOnGoing == false) {
463 Log.d(TAG, "Outgoing Call Branch");
464 editText = (EditText) findViewById(R.id.editTo);
465 String to = "147"; // editText.getText().toString();
466 Log.d(TAG, "to string is " + to);
467 if (to == null) {
468 Log.e(TAG, "to string is " + to);
469 return;
470 }
471
472 callID = Integer.toString(random.nextInt());
473
474 Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
475 service.placeCall(accountID, callID, to);
476 callOnGoing = true;
477 buttonCall.setEnabled(false);
478 buttonHangup.setEnabled(true);
Alexandre Savard14323be2012-10-24 10:02:13 -0400479 launchCallActivity();
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400480 //}
481 }
482
483 } catch (RemoteException e) {
484 Log.e(TAG, "Cannot call service method", e);
485 }
Alexandre Savard14323be2012-10-24 10:02:13 -0400486 */
Alexandre Savard6d54bbc2012-10-24 11:04:23 -0400487 SipCall call = new SipCall();
488 launchCallActivity(call);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400489 }
490
491 public void processingHangUpAction() {
492 try {
493 if (incomingCallID != "") {
494 buttonCall.clearAnimation();
495 Log.d(TAG, "service.refuse(" + incomingCallID + ");");
496 service.refuse(incomingCallID);
497 incomingCallID="";
498 buttonCall.setEnabled(true);
499 buttonHangup.setEnabled(true);
500 } else {
501 if (callOnGoing == true) {
502 Log.d(TAG, "service.hangUp(" + callID + ");");
503 service.hangUp(callID);
504 callOnGoing = false;
505 buttonCall.setEnabled(true);
506 buttonHangup.setEnabled(false);
507 }
508 }
509 } catch (RemoteException e) {
510 Log.e(TAG, "Cannot call service method", e);
511 }
512
513 buttonCall.setImageResource(R.drawable.ic_call);
514 }
Alexandre Savard14323be2012-10-24 10:02:13 -0400515
Alexandre Savard6d54bbc2012-10-24 11:04:23 -0400516 private void launchCallActivity(SipCall call)
Alexandre Savard14323be2012-10-24 10:02:13 -0400517 {
518 Log.i(TAG, "Launch Call Activity");
Alexandre Savard6d54bbc2012-10-24 11:04:23 -0400519 Bundle bundle = new Bundle();
520 bundle.putString("CallID", call.mCallInfo.mCallID);
Alexandre Savard14323be2012-10-24 10:02:13 -0400521 Intent intent = new Intent().setClass(this, CallActivity.class);
522 startActivity(intent);
523 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400524}