blob: 942b251139849dce5d9b6e37dddd016852fb6741 [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;
Alexandre Savard74c1cad2012-10-24 16:39:00 -040044import android.content.IntentFilter;
Emeric Vigier6119d782012-09-21 18:04:14 -040045import android.content.ServiceConnection;
Adrien Béraudffd32412012-08-07 18:39:23 -040046import android.os.Bundle;
Emeric Vigier383b2a22012-08-27 14:20:05 -040047import android.os.Handler;
Emeric Vigier6119d782012-09-21 18:04:14 -040048import android.os.IBinder;
Emeric Vigier383b2a22012-08-27 14:20:05 -040049import android.os.Message;
Emeric Vigier6119d782012-09-21 18:04:14 -040050import android.os.RemoteException;
Adrien Béraudffd32412012-08-07 18:39:23 -040051import android.support.v13.app.FragmentStatePagerAdapter;
52import android.support.v4.view.ViewPager;
Alexandre Savard74c1cad2012-10-24 16:39:00 -040053import android.support.v4.content.LocalBroadcastManager;
Emeric Vigier05e894e2012-08-20 13:53:02 -040054import android.util.Log;
Adrien Béraudffd32412012-08-07 18:39:23 -040055import android.view.Gravity;
56import android.view.LayoutInflater;
57import android.view.Menu;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040058import android.view.MenuItem;
Adrien Béraudffd32412012-08-07 18:39:23 -040059import android.view.View;
Emeric Vigier05e894e2012-08-20 13:53:02 -040060import android.view.View.OnClickListener;
Adrien Béraudffd32412012-08-07 18:39:23 -040061import android.view.ViewGroup;
Emeric Vigiera6bdb702012-08-31 15:34:53 -040062import android.view.animation.AlphaAnimation;
63import android.view.animation.Animation;
64import android.view.animation.LinearInterpolator;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040065import android.widget.Button;
Emeric Vigierd5c17f52012-08-29 09:29:33 -040066import android.widget.EditText;
Emeric Vigiere89b48b2012-08-30 14:16:46 -040067import android.widget.ImageButton;
Adrien Béraudffd32412012-08-07 18:39:23 -040068import android.widget.TextView;
69
70import com.savoirfairelinux.sflphone.R;
Emeric Vigier6119d782012-09-21 18:04:14 -040071import com.savoirfairelinux.sflphone.service.ISipService;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040072import com.savoirfairelinux.sflphone.service.SipService;
Alexandre Savard6b8d1df2012-10-23 16:44:43 -040073import com.savoirfairelinux.sflphone.utils.AccountList;
Alexandre Savard74c1cad2012-10-24 16:39:00 -040074import com.savoirfairelinux.sflphone.utils.CallList;
Adrien Béraudffd32412012-08-07 18:39:23 -040075
Alexandre Savard7a902bc2012-10-04 16:32:35 -040076import java.util.HashMap;
77
Emeric Vigier62ca14d2012-08-24 11:05:09 -040078public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
Adrien Béraudffd32412012-08-07 18:39:23 -040079{
Alexandre Savard6c0584e2012-09-20 09:42:59 -040080 SectionsPagerAdapter mSectionsPagerAdapter;
81 static final String TAG = "SFLPhoneHome";
82 private ButtonSectionFragment buttonFragment;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040083 /* default callID */
Emeric Vigiereaf2c492012-09-19 14:38:20 -040084 static boolean serviceIsOn = false;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040085 private String incomingCallID = "";
86 private static final int REQUEST_CODE_PREFERENCES = 1;
87 ImageButton buttonCall, buttonHangup;
88 Button buttonService;
Emeric Vigier419ba7b2012-09-19 14:55:14 -040089 static Animation animation;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040090 ContactListFragment mContactListFragment;
91 CallElementList mCallElementList;
Emeric Vigier6119d782012-09-21 18:04:14 -040092 private boolean mBound = false;
Alexandre Savardf17e3172012-10-25 16:09:09 -040093 private SFLPhoneHome mHome = this;
Emeric Vigier6119d782012-09-21 18:04:14 -040094 private ISipService service;
Alexandre Savard6b8d1df2012-10-23 16:44:43 -040095 public AccountList mAccountList = new AccountList();
Alexandre Savard73bc56f2012-10-25 13:35:54 -040096 public CallList mCallList = new CallList(this);
Adrien Béraudffd32412012-08-07 18:39:23 -040097
Alexandre Savard6c0584e2012-09-20 09:42:59 -040098 /**
99 * The {@link ViewPager} that will host the section contents.
100 */
101 ViewPager mViewPager;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400102
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400103 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 -0400104
Alexandre Savard817dc502012-10-22 11:47:29 -0400105 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
106
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400107 @Override
108 public void onCreate(Bundle savedInstanceState)
109 {
110 super.onCreate(savedInstanceState);
Alexandre Savard817dc502012-10-22 11:47:29 -0400111
112 if (!serviceIsOn) {
113 Log.i(TAG, "starting SipService");
114 startSipService();
115 }
116
117 // Bind to LocalService
118 if (!mBound) {
119 Log.i(TAG, "onStart: Binding service...");
120 Intent intent = new Intent(this, SipService.class);
121 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
122 }
123
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400124 setContentView(R.layout.activity_sflphone_home);
Adrien Béraudffd32412012-08-07 18:39:23 -0400125
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400126 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
Adrien Béraudffd32412012-08-07 18:39:23 -0400127
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400128 final ActionBar actionBar = getActionBar();
129 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
130 // final ActionBar actionBar = getActionBar();
Adrien Béraudffd32412012-08-07 18:39:23 -0400131
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400132 // Set up the ViewPager with the sections adapter.
133 mViewPager = (ViewPager) findViewById(R.id.pager);
134 mViewPager.setAdapter(mSectionsPagerAdapter);
Adrien Béraudffd32412012-08-07 18:39:23 -0400135
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400136 // When swiping between different sections, select the corresponding tab.
137 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
138 // Tab.
139 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
140 {
141 @Override
142 public void onPageSelected(int position)
143 {
144 actionBar.setSelectedNavigationItem(position);
145 }
146 });
Emeric Vigier383b2a22012-08-27 14:20:05 -0400147
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400148 // For each of the sections in the app, add a tab to the action bar.
149 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
150 // Create a tab with text corresponding to the page title defined by the adapter.
151 // Also specify this Activity object, which implements the TabListener interface, as the
152 // listener for when this tab is selected.
153 Log.i(TAG, "adding tab: " + i);
154 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
155 }
Emeric Vigier383b2a22012-08-27 14:20:05 -0400156
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400157 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
158 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400159
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400160 // Change alpha from fully visible to invisible
161 animation = new AlphaAnimation(1, 0);
162 // duration - half a second
163 animation.setDuration(500);
164 // do not alter animation rate
165 animation.setInterpolator(new LinearInterpolator());
166 // Repeat animation infinitely
167 animation.setRepeatCount(Animation.INFINITE);
168 // Reverse
169 animation.setRepeatMode(Animation.REVERSE);
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400170
171 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("new-call-created"));
172 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("call-state-changed"));
173 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("incoming-call"));
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400174 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400175
Emeric Vigier12d61d82012-09-19 15:08:18 -0400176 @Override
177 protected void onStart() {
178 Log.i(TAG, "onStart");
179 super.onStart();
180 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400181
Emeric Vigier6119d782012-09-21 18:04:14 -0400182 /* user gets back to the activity, e.g. through task manager */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400183 @Override
184 protected void onRestart() {
185 super.onRestart();
186 }
187
Emeric Vigier6119d782012-09-21 18:04:14 -0400188 /* activity gets back to the foreground and user input */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400189 @Override
190 protected void onResume() {
191 Log.i(TAG, "onResume");
192 super.onResume();
Emeric Vigier12d61d82012-09-19 15:08:18 -0400193 }
194
Emeric Vigier6119d782012-09-21 18:04:14 -0400195 /* activity no more in foreground */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400196 @Override
197 protected void onPause() {
Emeric Vigier12d61d82012-09-19 15:08:18 -0400198 super.onPause();
199 }
200
Emeric Vigier6119d782012-09-21 18:04:14 -0400201 /* activity is no longer visible */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400202 @Override
203 protected void onStop() {
204 super.onStop();
Alexandre Savard817dc502012-10-22 11:47:29 -0400205 }
206
207 /* activity finishes itself or is being killed by the system */
208 @Override
209 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400210 /* stop the service, if no other bound user, no need to check if it is running */
211 if (mBound) {
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400212 Log.i(TAG, "onStop: Unbinding service...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400213 unbindService(mConnection);
214 mBound = false;
215 }
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400216 Log.i(TAG, "onDestroy: stopping SipService...");
217 stopService(new Intent(this, SipService.class));
Emeric Vigier6119d782012-09-21 18:04:14 -0400218 serviceIsOn = false;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400219 super.onDestroy();
220 }
221
Emeric Vigier6119d782012-09-21 18:04:14 -0400222 /** Defines callbacks for service binding, passed to bindService() */
223 private ServiceConnection mConnection = new ServiceConnection() {
224
225 @Override
226 public void onServiceConnected(ComponentName className,
227 IBinder binder) {
228 service = ISipService.Stub.asInterface(binder);
229 mBound = true;
Alexandre Savard817dc502012-10-22 11:47:29 -0400230 mContactListFragment.setService(service);
231 mCallElementList.setService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400232 Log.d(TAG, "Service connected");
233 }
234
235 @Override
236 public void onServiceDisconnected(ComponentName arg0) {
237 mBound = false;
238 Log.d(TAG, "Service disconnected");
239 }
240 };
241
Emeric Vigier12d61d82012-09-19 15:08:18 -0400242 private void startSipService() {
243 Thread thread = new Thread("StartSFLphoneService") {
244 public void run() {
245 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
246 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
247 startService(sipServiceIntent);
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400248 serviceIsOn = true;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400249 };
250 };
251 try {
252 thread.start();
253 } catch (IllegalThreadStateException e) {
254 AlertDialog.Builder builder = new AlertDialog.Builder(this);
255 builder.setMessage("Cannot start SFLPhone SipService!");
256 AlertDialog alert = builder.create();
257 alert.show();
258 finish();
259 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400260 }
261
262 @Override
263 public boolean onOptionsItemSelected(MenuItem item) {
264 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400265 if(item.getItemId() != 0) {
266 // When the button is clicked, launch an activity through this intent
267 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400268
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400269 // Make it a subactivity so we know when it returns
270 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400271 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400272
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400273 return super.onOptionsItemSelected(item);
274 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400275
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400276 @Override
277 public boolean onCreateOptionsMenu(Menu menu)
278 {
279 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
280 return true;
281 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400282
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400283 @Override
284 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
285 {
286 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400287
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400288 @Override
289 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
290 {
291 // When the given tab is selected, switch to the corresponding page in the ViewPager.
292 mViewPager.setCurrentItem(tab.getPosition());
293 }
294
295 @Override
296 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
297 {
298 // Log.d(TAG, "onTabReselected");
299 }
300
Alexandre Savardf17e3172012-10-25 16:09:09 -0400301 public void onSelectedCallAction(SipCall call) {
302 if(call.getCallStateInt() == SipCall.CALL_STATE_CURRENT) {
303 buttonCall.setEnabled(false);
304 buttonHangup.setEnabled(true);
305 }
306
307 buttonCall.setTag(call);
308 buttonHangup.setTag(call);
309 }
310
311 public void onUnselectedCallAction() {
312 buttonCall.setTag(null);
313 buttonCall.setTag(null);
314 }
315
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400316 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400317 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400318 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400319 buttonCall.startAnimation(animation);
320 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400321 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400322
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400323 /**
324 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
325 * one of the primary sections of the app.
326 */
327 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
328 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400329
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400330 public SectionsPagerAdapter(FragmentManager fm)
331 {
332 super(fm);
333 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400334
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400335 @Override
336 public Fragment getItem(int i)
337 {
338 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400339
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400340 switch (i) {
341 case 0:
Alexandre Savard817dc502012-10-22 11:47:29 -0400342 mContactListFragment = new ContactListFragment(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400343 fragment = mContactListFragment;
344 break;
345 case 1:
Alexandre Savardf17e3172012-10-25 16:09:09 -0400346 mCallElementList = new CallElementList(service, mHome);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400347 SipCall.setCallElementList(mCallElementList);
348 fragment = mCallElementList;
349 break;
350 case 2:
351 fragment = new DummySectionFragment();
352 break;
353 case 3:
354 fragment = new ButtonSectionFragment();
355 Log.i(TAG, "getItem: fragment is " + fragment);
356 break;
357 default:
358 Log.e(TAG, "getItem: unknown tab position " + i);
359 return null;
360 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400361
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400362 Bundle args = new Bundle();
363 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
364 fragment.setArguments(args);
365 return fragment;
366 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400367
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400368 @Override
369 public int getCount()
370 {
371 return 4;
372 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400373
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400374 @Override
375 public CharSequence getPageTitle(int position)
376 {
377 switch (position) {
378 case 0:
379 return getString(R.string.title_section0).toUpperCase();
380 case 1:
381 return getString(R.string.title_section1).toUpperCase();
382 case 2:
383 return getString(R.string.title_section2).toUpperCase();
384 case 3:
385 return getString(R.string.title_section3).toUpperCase();
386 default:
387 Log.e(TAG, "getPageTitle: unknown tab position " + position);
388 break;
389 }
390 return null;
391 }
392 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400393
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400394 /**
395 * A dummy fragment representing a section of the app, but that simply
396 * displays dummy text.
397 */
398 public static class DummySectionFragment extends Fragment
399 {
400 public DummySectionFragment()
401 {
402 setRetainInstance(true);
403 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400404
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400405 public static final String ARG_SECTION_NUMBER = "section_number";
406
407 @Override
408 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
409 {
410 TextView textView = new TextView(getActivity());
411 textView.setGravity(Gravity.CENTER);
412 Bundle args = getArguments();
413 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
414 textView.setText("java sucks");
415 return textView;
416 }
417 }
418
419 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400420 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400421 {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400422 Log.i(TAG, "onClic from SFLPhoneHome");
Alexandre Savard91052442012-10-25 16:14:26 -0400423 switch (view.getId()) {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400424 case R.id.buttonCall:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400425 processingNewCallAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400426 break;
427 case R.id.buttonHangUp:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400428 processingHangUpAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400429 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400430 default:
431 Log.w(TAG, "unknown button " + view.getId());
432 break;
Emeric Vigier6119d782012-09-21 18:04:14 -0400433 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400434 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400435
436 public void processingNewCallAction() {
Alexandre Savard14323be2012-10-24 10:02:13 -0400437 /*
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400438 Log.d(TAG, "ProcessingNewCallAction()");
439 TextView textView = (TextView) findViewById(R.id.editAccountID);
440 String accountID = mAccountList.currentAccountID;
441 // String accountID = textView.getText().toString();
442 // buttonCall.setImageResource(R.drawable.ic_call);
443 EditText editText;
444 Random random = new Random();
445
446 try {
447
448 if (incomingCallID != "") {
449 Log.d(TAG, "Incoming Call Branch");
450 buttonCall.clearAnimation();
451 service.accept(incomingCallID);
452 callID = incomingCallID;
453 incomingCallID="";
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400454 buttonCall.setEnabled(false);
455 buttonHangup.setEnabled(true);
456 } else {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400457 Log.d(TAG, "Outgoing Call Branch");
458 editText = (EditText) findViewById(R.id.editTo);
459 String to = "147"; // editText.getText().toString();
460 Log.d(TAG, "to string is " + to);
461 if (to == null) {
462 Log.e(TAG, "to string is " + to);
463 return;
464 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400465
Alexandre Savardf17e3172012-10-25 16:09:09 -0400466 callID = Integer.toString(random.nextInt());
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400467
Alexandre Savardf17e3172012-10-25 16:09:09 -0400468 Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
469 service.placeCall(accountID, callID, to);
470 buttonCall.setEnabled(false);
471 buttonHangup.setEnabled(true);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400472 }
473
474 } catch (RemoteException e) {
475 Log.e(TAG, "Cannot call service method", e);
476 }
Alexandre Savard14323be2012-10-24 10:02:13 -0400477 */
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400478 try {
479 String accountID = mAccountList.currentAccountID;
480 EditText editText = (EditText) findViewById(R.id.editTo);
481 String to = "147"; // editText.getText().toString();
482
483 Random random = new Random();
484 String callID = Integer.toString(random.nextInt());
485 SipCall.CallInfo info = new SipCall.CallInfo();
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400486
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400487 info.mCallID = callID;
488 info.mDisplayName = "Cool Guy!";
489 info.mPhone = to;
490 info.mEmail = "coolGuy@coolGuy.com";
491
492 SipCall call = CallList.getCallInstance(info);
Alexandre Savarddf544262012-10-25 14:24:08 -0400493 call.launchCallActivity(this);
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400494 call.printCallInfo();
495 call.placeCall();
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400496
497 Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
498 service.placeCall(accountID, callID, to);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400499
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400500 buttonCall.setEnabled(false);
501 buttonHangup.setEnabled(true);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400502
503 buttonCall.setTag(call);
504 buttonHangup.setTag(call);
505
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400506 } catch (RemoteException e) {
507 Log.e(TAG, "Cannot call service method", e);
508 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400509 }
510
511 public void processingHangUpAction() {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400512 /*
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400513 try {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400514 if (incomingCallID != "") {
515 buttonCall.clearAnimation();
516 Log.d(TAG, "service.refuse(" + incomingCallID + ");");
517 service.refuse(incomingCallID);
518 incomingCallID="";
519 buttonCall.setEnabled(true);
520 buttonHangup.setEnabled(true);
521 } else {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400522 Log.d(TAG, "service.hangUp(" + callID + ");");
523 service.hangUp(callID);
524 callOnGoing = false;
525 buttonCall.setEnabled(true);
526 buttonHangup.setEnabled(false);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400527 }
528 } catch (RemoteException e) {
529 Log.e(TAG, "Cannot call service method", e);
530 }
531
532 buttonCall.setImageResource(R.drawable.ic_call);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400533 */
534 SipCall call = (SipCall)buttonHangup.getTag();
535 if(call != null)
536 call.notifyServiceHangup(service);
537
538 buttonCall.setTag(null);
539 buttonHangup.setTag(null);
540
541 buttonCall.setEnabled(true);
542 buttonHangup.setEnabled(false);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400543 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400544}