blob: d3131c26384bfe7158391c58e30389629a130d83 [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 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 Savarda949eec2012-10-25 17:30:49 -0400174
175 SipCall.setSFLPhoneHomeContext(this);
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400176 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400177
Emeric Vigier12d61d82012-09-19 15:08:18 -0400178 @Override
179 protected void onStart() {
180 Log.i(TAG, "onStart");
181 super.onStart();
182 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400183
Emeric Vigier6119d782012-09-21 18:04:14 -0400184 /* user gets back to the activity, e.g. through task manager */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400185 @Override
186 protected void onRestart() {
187 super.onRestart();
188 }
189
Emeric Vigier6119d782012-09-21 18:04:14 -0400190 /* activity gets back to the foreground and user input */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400191 @Override
192 protected void onResume() {
193 Log.i(TAG, "onResume");
194 super.onResume();
Emeric Vigier12d61d82012-09-19 15:08:18 -0400195 }
196
Emeric Vigier6119d782012-09-21 18:04:14 -0400197 /* activity no more in foreground */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400198 @Override
199 protected void onPause() {
Emeric Vigier12d61d82012-09-19 15:08:18 -0400200 super.onPause();
201 }
202
Emeric Vigier6119d782012-09-21 18:04:14 -0400203 /* activity is no longer visible */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400204 @Override
205 protected void onStop() {
206 super.onStop();
Alexandre Savard817dc502012-10-22 11:47:29 -0400207 }
208
209 /* activity finishes itself or is being killed by the system */
210 @Override
211 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400212 /* stop the service, if no other bound user, no need to check if it is running */
213 if (mBound) {
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400214 Log.i(TAG, "onStop: Unbinding service...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400215 unbindService(mConnection);
216 mBound = false;
217 }
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400218 Log.i(TAG, "onDestroy: stopping SipService...");
219 stopService(new Intent(this, SipService.class));
Emeric Vigier6119d782012-09-21 18:04:14 -0400220 serviceIsOn = false;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400221 super.onDestroy();
222 }
223
Emeric Vigier6119d782012-09-21 18:04:14 -0400224 /** Defines callbacks for service binding, passed to bindService() */
225 private ServiceConnection mConnection = new ServiceConnection() {
226
227 @Override
228 public void onServiceConnected(ComponentName className,
229 IBinder binder) {
230 service = ISipService.Stub.asInterface(binder);
231 mBound = true;
Alexandre Savard817dc502012-10-22 11:47:29 -0400232 mContactListFragment.setService(service);
233 mCallElementList.setService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400234 Log.d(TAG, "Service connected");
235 }
236
237 @Override
238 public void onServiceDisconnected(ComponentName arg0) {
239 mBound = false;
240 Log.d(TAG, "Service disconnected");
241 }
242 };
243
Emeric Vigier12d61d82012-09-19 15:08:18 -0400244 private void startSipService() {
245 Thread thread = new Thread("StartSFLphoneService") {
246 public void run() {
247 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
248 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
249 startService(sipServiceIntent);
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400250 serviceIsOn = true;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400251 };
252 };
253 try {
254 thread.start();
255 } catch (IllegalThreadStateException e) {
256 AlertDialog.Builder builder = new AlertDialog.Builder(this);
257 builder.setMessage("Cannot start SFLPhone SipService!");
258 AlertDialog alert = builder.create();
259 alert.show();
260 finish();
261 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400262 }
263
264 @Override
265 public boolean onOptionsItemSelected(MenuItem item) {
266 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400267 if(item.getItemId() != 0) {
268 // When the button is clicked, launch an activity through this intent
269 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400270
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400271 // Make it a subactivity so we know when it returns
272 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400273 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400274
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400275 return super.onOptionsItemSelected(item);
276 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400277
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400278 @Override
279 public boolean onCreateOptionsMenu(Menu menu)
280 {
281 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
282 return true;
283 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400284
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400285 @Override
286 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
287 {
288 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400289
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400290 @Override
291 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
292 {
293 // When the given tab is selected, switch to the corresponding page in the ViewPager.
294 mViewPager.setCurrentItem(tab.getPosition());
295 }
296
297 @Override
298 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
299 {
300 // Log.d(TAG, "onTabReselected");
301 }
302
Alexandre Savardf17e3172012-10-25 16:09:09 -0400303 public void onSelectedCallAction(SipCall call) {
Alexandre Savard27a51132012-10-25 18:35:14 -0400304 int callState = call.getCallStateInt();
305
306 if((callState == SipCall.CALL_STATE_NONE) ||
307 (callState == SipCall.CALL_STATE_CURRENT)) {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400308 buttonCall.setEnabled(false);
309 buttonHangup.setEnabled(true);
310 }
Alexandre Savard27a51132012-10-25 18:35:14 -0400311 else {
312 buttonCall.setEnabled(true);
313 buttonHangup.setEnabled(false);
314 }
Alexandre Savardf17e3172012-10-25 16:09:09 -0400315
316 buttonCall.setTag(call);
317 buttonHangup.setTag(call);
318 }
319
320 public void onUnselectedCallAction() {
321 buttonCall.setTag(null);
322 buttonCall.setTag(null);
Alexandre Savarda949eec2012-10-25 17:30:49 -0400323
324 buttonCall.setEnabled(true);
325 buttonHangup.setEnabled(false);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400326 }
327
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400328 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400329 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400330 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400331 buttonCall.startAnimation(animation);
332 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400333 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400334
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400335 /**
336 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
337 * one of the primary sections of the app.
338 */
339 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
340 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400341
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400342 public SectionsPagerAdapter(FragmentManager fm)
343 {
344 super(fm);
345 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400346
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400347 @Override
348 public Fragment getItem(int i)
349 {
350 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400351
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400352 switch (i) {
353 case 0:
Alexandre Savard817dc502012-10-22 11:47:29 -0400354 mContactListFragment = new ContactListFragment(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400355 fragment = mContactListFragment;
356 break;
357 case 1:
Alexandre Savardf17e3172012-10-25 16:09:09 -0400358 mCallElementList = new CallElementList(service, mHome);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400359 SipCall.setCallElementList(mCallElementList);
360 fragment = mCallElementList;
361 break;
362 case 2:
363 fragment = new DummySectionFragment();
364 break;
365 case 3:
366 fragment = new ButtonSectionFragment();
367 Log.i(TAG, "getItem: fragment is " + fragment);
368 break;
369 default:
370 Log.e(TAG, "getItem: unknown tab position " + i);
371 return null;
372 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400373
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400374 Bundle args = new Bundle();
375 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
376 fragment.setArguments(args);
377 return fragment;
378 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400379
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400380 @Override
381 public int getCount()
382 {
383 return 4;
384 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400385
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400386 @Override
387 public CharSequence getPageTitle(int position)
388 {
389 switch (position) {
390 case 0:
391 return getString(R.string.title_section0).toUpperCase();
392 case 1:
393 return getString(R.string.title_section1).toUpperCase();
394 case 2:
395 return getString(R.string.title_section2).toUpperCase();
396 case 3:
397 return getString(R.string.title_section3).toUpperCase();
398 default:
399 Log.e(TAG, "getPageTitle: unknown tab position " + position);
400 break;
401 }
402 return null;
403 }
404 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400405
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400406 /**
407 * A dummy fragment representing a section of the app, but that simply
408 * displays dummy text.
409 */
410 public static class DummySectionFragment extends Fragment
411 {
412 public DummySectionFragment()
413 {
414 setRetainInstance(true);
415 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400416
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400417 public static final String ARG_SECTION_NUMBER = "section_number";
418
419 @Override
420 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
421 {
422 TextView textView = new TextView(getActivity());
423 textView.setGravity(Gravity.CENTER);
424 Bundle args = getArguments();
425 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
426 textView.setText("java sucks");
427 return textView;
428 }
429 }
430
431 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400432 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400433 {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400434 Log.i(TAG, "onClic from SFLPhoneHome");
Alexandre Savard91052442012-10-25 16:14:26 -0400435 switch (view.getId()) {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400436 case R.id.buttonCall:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400437 processingNewCallAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400438 break;
439 case R.id.buttonHangUp:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400440 processingHangUpAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400441 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400442 default:
443 Log.w(TAG, "unknown button " + view.getId());
444 break;
Emeric Vigier6119d782012-09-21 18:04:14 -0400445 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400446 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400447
448 public void processingNewCallAction() {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400449 String accountID = mAccountList.currentAccountID;
Alexandre Savard27a51132012-10-25 18:35:14 -0400450 EditText editText = (EditText) findViewById(R.id.editTo);
451 String to = "147"; // editText.getText().toString();
452
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400453 Random random = new Random();
Alexandre Savard27a51132012-10-25 18:35:14 -0400454 String callID = Integer.toString(random.nextInt());
455 SipCall.CallInfo info = new SipCall.CallInfo();
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400456
Alexandre Savard27a51132012-10-25 18:35:14 -0400457 info.mCallID = callID;
458 info.mAccountID = accountID;
459 info.mDisplayName = "Cool Guy!";
460 info.mPhone = to;
461 info.mEmail = "coolGuy@coolGuy.com";
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400462
Alexandre Savard27a51132012-10-25 18:35:14 -0400463 SipCall call = CallList.getCallInstance(info);
464 call.launchCallActivity(this);
465 call.placeCallUpdateUi();
466 call.notifyServicePlaceCall(service);
467
468 onSelectedCallAction(call);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400469 }
470
471 public void processingHangUpAction() {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400472 SipCall call = (SipCall)buttonHangup.getTag();
473 if(call != null)
474 call.notifyServiceHangup(service);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400475 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400476}