blob: e34696e693f81d3f2a6e4776028a25e330f0d7b9 [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;
60import android.view.ViewGroup;
Alexandre Savarda949eec2012-10-25 17:30:49 -040061import android.view.View.OnClickListener;
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 Savardcb66fa42012-10-26 10:06:16 -0400157 actionBar.setSelectedNavigationItem(1);
158
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400159 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
160 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400161
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400162 // Change alpha from fully visible to invisible
163 animation = new AlphaAnimation(1, 0);
164 // duration - half a second
165 animation.setDuration(500);
166 // do not alter animation rate
167 animation.setInterpolator(new LinearInterpolator());
168 // Repeat animation infinitely
169 animation.setRepeatCount(Animation.INFINITE);
170 // Reverse
171 animation.setRepeatMode(Animation.REVERSE);
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400172
173 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("new-call-created"));
174 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("call-state-changed"));
175 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("incoming-call"));
Alexandre Savarda949eec2012-10-25 17:30:49 -0400176
177 SipCall.setSFLPhoneHomeContext(this);
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400178 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400179
Emeric Vigier12d61d82012-09-19 15:08:18 -0400180 @Override
181 protected void onStart() {
182 Log.i(TAG, "onStart");
183 super.onStart();
184 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400185
Emeric Vigier6119d782012-09-21 18:04:14 -0400186 /* user gets back to the activity, e.g. through task manager */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400187 @Override
188 protected void onRestart() {
189 super.onRestart();
190 }
191
Emeric Vigier6119d782012-09-21 18:04:14 -0400192 /* activity gets back to the foreground and user input */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400193 @Override
194 protected void onResume() {
195 Log.i(TAG, "onResume");
196 super.onResume();
Emeric Vigier12d61d82012-09-19 15:08:18 -0400197 }
198
Emeric Vigier6119d782012-09-21 18:04:14 -0400199 /* activity no more in foreground */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400200 @Override
201 protected void onPause() {
Emeric Vigier12d61d82012-09-19 15:08:18 -0400202 super.onPause();
203 }
204
Emeric Vigier6119d782012-09-21 18:04:14 -0400205 /* activity is no longer visible */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400206 @Override
207 protected void onStop() {
208 super.onStop();
Alexandre Savard817dc502012-10-22 11:47:29 -0400209 }
210
211 /* activity finishes itself or is being killed by the system */
212 @Override
213 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400214 /* stop the service, if no other bound user, no need to check if it is running */
215 if (mBound) {
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400216 Log.i(TAG, "onStop: Unbinding service...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400217 unbindService(mConnection);
218 mBound = false;
219 }
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400220 Log.i(TAG, "onDestroy: stopping SipService...");
221 stopService(new Intent(this, SipService.class));
Emeric Vigier6119d782012-09-21 18:04:14 -0400222 serviceIsOn = false;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400223 super.onDestroy();
224 }
225
Emeric Vigier6119d782012-09-21 18:04:14 -0400226 /** Defines callbacks for service binding, passed to bindService() */
227 private ServiceConnection mConnection = new ServiceConnection() {
228
229 @Override
230 public void onServiceConnected(ComponentName className,
231 IBinder binder) {
232 service = ISipService.Stub.asInterface(binder);
233 mBound = true;
Alexandre Savard817dc502012-10-22 11:47:29 -0400234 mContactListFragment.setService(service);
235 mCallElementList.setService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400236 Log.d(TAG, "Service connected");
237 }
238
239 @Override
240 public void onServiceDisconnected(ComponentName arg0) {
241 mBound = false;
242 Log.d(TAG, "Service disconnected");
243 }
244 };
245
Emeric Vigier12d61d82012-09-19 15:08:18 -0400246 private void startSipService() {
247 Thread thread = new Thread("StartSFLphoneService") {
248 public void run() {
249 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
250 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
251 startService(sipServiceIntent);
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400252 serviceIsOn = true;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400253 };
254 };
255 try {
256 thread.start();
257 } catch (IllegalThreadStateException e) {
258 AlertDialog.Builder builder = new AlertDialog.Builder(this);
259 builder.setMessage("Cannot start SFLPhone SipService!");
260 AlertDialog alert = builder.create();
261 alert.show();
262 finish();
263 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400264 }
265
266 @Override
267 public boolean onOptionsItemSelected(MenuItem item) {
268 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400269 if(item.getItemId() != 0) {
270 // When the button is clicked, launch an activity through this intent
271 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400272
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400273 // Make it a subactivity so we know when it returns
274 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400275 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400276
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400277 return super.onOptionsItemSelected(item);
278 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400279
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400280 @Override
281 public boolean onCreateOptionsMenu(Menu menu)
282 {
283 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
284 return true;
285 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400286
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400287 @Override
288 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
289 {
290 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400291
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400292 @Override
293 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
294 {
295 // When the given tab is selected, switch to the corresponding page in the ViewPager.
296 mViewPager.setCurrentItem(tab.getPosition());
297 }
298
299 @Override
300 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
301 {
302 // Log.d(TAG, "onTabReselected");
303 }
304
Alexandre Savardf17e3172012-10-25 16:09:09 -0400305 public void onSelectedCallAction(SipCall call) {
Alexandre Savard27a51132012-10-25 18:35:14 -0400306 int callState = call.getCallStateInt();
307
308 if((callState == SipCall.CALL_STATE_NONE) ||
309 (callState == SipCall.CALL_STATE_CURRENT)) {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400310 buttonCall.setEnabled(false);
311 buttonHangup.setEnabled(true);
312 }
Alexandre Savard27a51132012-10-25 18:35:14 -0400313 else {
314 buttonCall.setEnabled(true);
315 buttonHangup.setEnabled(false);
316 }
Alexandre Savardf17e3172012-10-25 16:09:09 -0400317
318 buttonCall.setTag(call);
319 buttonHangup.setTag(call);
320 }
321
322 public void onUnselectedCallAction() {
323 buttonCall.setTag(null);
324 buttonCall.setTag(null);
Alexandre Savarda949eec2012-10-25 17:30:49 -0400325
326 buttonCall.setEnabled(true);
327 buttonHangup.setEnabled(false);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400328 }
329
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400330 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400331 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400332 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400333 buttonCall.startAnimation(animation);
334 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400335 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400336
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400337 /**
338 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
339 * one of the primary sections of the app.
340 */
341 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
342 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400343
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400344 public SectionsPagerAdapter(FragmentManager fm)
345 {
346 super(fm);
347 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400348
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400349 @Override
350 public Fragment getItem(int i)
351 {
352 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400353
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400354 switch (i) {
355 case 0:
Alexandre Savard817dc502012-10-22 11:47:29 -0400356 mContactListFragment = new ContactListFragment(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400357 fragment = mContactListFragment;
358 break;
359 case 1:
Alexandre Savardf17e3172012-10-25 16:09:09 -0400360 mCallElementList = new CallElementList(service, mHome);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400361 SipCall.setCallElementList(mCallElementList);
362 fragment = mCallElementList;
363 break;
364 case 2:
365 fragment = new DummySectionFragment();
366 break;
367 case 3:
368 fragment = new ButtonSectionFragment();
369 Log.i(TAG, "getItem: fragment is " + fragment);
370 break;
371 default:
372 Log.e(TAG, "getItem: unknown tab position " + i);
373 return null;
374 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400375
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400376 Bundle args = new Bundle();
377 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
378 fragment.setArguments(args);
379 return fragment;
380 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400381
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400382 @Override
383 public int getCount()
384 {
385 return 4;
386 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400387
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400388 @Override
389 public CharSequence getPageTitle(int position)
390 {
391 switch (position) {
392 case 0:
393 return getString(R.string.title_section0).toUpperCase();
394 case 1:
395 return getString(R.string.title_section1).toUpperCase();
396 case 2:
397 return getString(R.string.title_section2).toUpperCase();
398 case 3:
399 return getString(R.string.title_section3).toUpperCase();
400 default:
401 Log.e(TAG, "getPageTitle: unknown tab position " + position);
402 break;
403 }
404 return null;
405 }
406 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400407
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400408 /**
409 * A dummy fragment representing a section of the app, but that simply
410 * displays dummy text.
411 */
412 public static class DummySectionFragment extends Fragment
413 {
414 public DummySectionFragment()
415 {
416 setRetainInstance(true);
417 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400418
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400419 public static final String ARG_SECTION_NUMBER = "section_number";
420
421 @Override
422 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
423 {
424 TextView textView = new TextView(getActivity());
425 textView.setGravity(Gravity.CENTER);
426 Bundle args = getArguments();
427 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
428 textView.setText("java sucks");
429 return textView;
430 }
431 }
432
433 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400434 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400435 {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400436 Log.i(TAG, "onClic from SFLPhoneHome");
Alexandre Savard91052442012-10-25 16:14:26 -0400437 switch (view.getId()) {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400438 case R.id.buttonCall:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400439 processingNewCallAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400440 break;
441 case R.id.buttonHangUp:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400442 processingHangUpAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400443 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400444 default:
445 Log.w(TAG, "unknown button " + view.getId());
446 break;
Emeric Vigier6119d782012-09-21 18:04:14 -0400447 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400448 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400449
450 public void processingNewCallAction() {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400451 String accountID = mAccountList.currentAccountID;
Alexandre Savardcb66fa42012-10-26 10:06:16 -0400452 EditText editText = (EditText) findViewById(R.id.phoneNumberTextEntry);
453 String to = editText.getText().toString();
Alexandre Savard27a51132012-10-25 18:35:14 -0400454
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400455 Random random = new Random();
Alexandre Savard27a51132012-10-25 18:35:14 -0400456 String callID = Integer.toString(random.nextInt());
457 SipCall.CallInfo info = new SipCall.CallInfo();
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400458
Alexandre Savard27a51132012-10-25 18:35:14 -0400459 info.mCallID = callID;
460 info.mAccountID = accountID;
461 info.mDisplayName = "Cool Guy!";
462 info.mPhone = to;
463 info.mEmail = "coolGuy@coolGuy.com";
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400464
Alexandre Savard27a51132012-10-25 18:35:14 -0400465 SipCall call = CallList.getCallInstance(info);
466 call.launchCallActivity(this);
467 call.placeCallUpdateUi();
468 call.notifyServicePlaceCall(service);
469
470 onSelectedCallAction(call);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400471 }
472
473 public void processingHangUpAction() {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400474 SipCall call = (SipCall)buttonHangup.getTag();
475 if(call != null)
476 call.notifyServiceHangup(service);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400477 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400478}