blob: d3bd1ae859179c1cb8e09e329592adb1cdd18d34 [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;
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;
Alexandre Savardf17e3172012-10-25 16:09:09 -040092 private SFLPhoneHome mHome = this;
Emeric Vigier6119d782012-09-21 18:04:14 -040093 private ISipService service;
Alexandre Savard6b8d1df2012-10-23 16:44:43 -040094 public AccountList mAccountList = new AccountList();
Alexandre Savard73bc56f2012-10-25 13:35:54 -040095 public CallList mCallList = new CallList(this);
Adrien Béraudffd32412012-08-07 18:39:23 -040096
Alexandre Savard48240e82012-10-26 10:36:03 -040097 private static final int ACTION_BAR_TAB_CONTACT = 0;
98 private static final int ACTION_BAR_TAB_CALL = 1;
99 private static final int ACTION_BAR_TAB_HISTORY = 2;
100
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400101 /**
102 * The {@link ViewPager} that will host the section contents.
103 */
104 ViewPager mViewPager;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400105
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400106 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 -0400107
Alexandre Savard817dc502012-10-22 11:47:29 -0400108 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
109
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400110 @Override
111 public void onCreate(Bundle savedInstanceState)
112 {
113 super.onCreate(savedInstanceState);
Alexandre Savard817dc502012-10-22 11:47:29 -0400114
115 if (!serviceIsOn) {
116 Log.i(TAG, "starting SipService");
117 startSipService();
118 }
119
120 // Bind to LocalService
121 if (!mBound) {
122 Log.i(TAG, "onStart: Binding service...");
123 Intent intent = new Intent(this, SipService.class);
124 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
125 }
126
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400127 setContentView(R.layout.activity_sflphone_home);
Adrien Béraudffd32412012-08-07 18:39:23 -0400128
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400129 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
Adrien Béraudffd32412012-08-07 18:39:23 -0400130
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400131 final ActionBar actionBar = getActionBar();
132 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
133 // final ActionBar actionBar = getActionBar();
Adrien Béraudffd32412012-08-07 18:39:23 -0400134
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400135 // Set up the ViewPager with the sections adapter.
136 mViewPager = (ViewPager) findViewById(R.id.pager);
137 mViewPager.setAdapter(mSectionsPagerAdapter);
Adrien Béraudffd32412012-08-07 18:39:23 -0400138
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400139 // When swiping between different sections, select the corresponding tab.
140 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
141 // Tab.
142 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
143 {
144 @Override
145 public void onPageSelected(int position)
146 {
147 actionBar.setSelectedNavigationItem(position);
148 }
149 });
Emeric Vigier383b2a22012-08-27 14:20:05 -0400150
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400151 // For each of the sections in the app, add a tab to the action bar.
152 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
153 // Create a tab with text corresponding to the page title defined by the adapter.
154 // Also specify this Activity object, which implements the TabListener interface, as the
155 // listener for when this tab is selected.
156 Log.i(TAG, "adding tab: " + i);
157 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
158 }
Emeric Vigier383b2a22012-08-27 14:20:05 -0400159
Alexandre Savard48240e82012-10-26 10:36:03 -0400160 actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
Alexandre Savardcb66fa42012-10-26 10:06:16 -0400161
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400162 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
163 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400164
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400165 // Change alpha from fully visible to invisible
166 animation = new AlphaAnimation(1, 0);
167 // duration - half a second
168 animation.setDuration(500);
169 // do not alter animation rate
170 animation.setInterpolator(new LinearInterpolator());
171 // Repeat animation infinitely
172 animation.setRepeatCount(Animation.INFINITE);
173 // Reverse
174 animation.setRepeatMode(Animation.REVERSE);
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400175
176 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("new-call-created"));
177 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("call-state-changed"));
178 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("incoming-call"));
Alexandre Savarda949eec2012-10-25 17:30:49 -0400179
180 SipCall.setSFLPhoneHomeContext(this);
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400181 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400182
Emeric Vigier12d61d82012-09-19 15:08:18 -0400183 @Override
184 protected void onStart() {
185 Log.i(TAG, "onStart");
186 super.onStart();
187 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400188
Emeric Vigier6119d782012-09-21 18:04:14 -0400189 /* user gets back to the activity, e.g. through task manager */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400190 @Override
191 protected void onRestart() {
192 super.onRestart();
193 }
194
Emeric Vigier6119d782012-09-21 18:04:14 -0400195 /* activity gets back to the foreground and user input */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400196 @Override
197 protected void onResume() {
198 Log.i(TAG, "onResume");
199 super.onResume();
Emeric Vigier12d61d82012-09-19 15:08:18 -0400200 }
201
Emeric Vigier6119d782012-09-21 18:04:14 -0400202 /* activity no more in foreground */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400203 @Override
204 protected void onPause() {
Emeric Vigier12d61d82012-09-19 15:08:18 -0400205 super.onPause();
206 }
207
Emeric Vigier6119d782012-09-21 18:04:14 -0400208 /* activity is no longer visible */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400209 @Override
210 protected void onStop() {
211 super.onStop();
Alexandre Savard817dc502012-10-22 11:47:29 -0400212 }
213
214 /* activity finishes itself or is being killed by the system */
215 @Override
216 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400217 /* stop the service, if no other bound user, no need to check if it is running */
218 if (mBound) {
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400219 Log.i(TAG, "onStop: Unbinding service...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400220 unbindService(mConnection);
221 mBound = false;
222 }
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400223 Log.i(TAG, "onDestroy: stopping SipService...");
224 stopService(new Intent(this, SipService.class));
Emeric Vigier6119d782012-09-21 18:04:14 -0400225 serviceIsOn = false;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400226 super.onDestroy();
227 }
228
Emeric Vigier6119d782012-09-21 18:04:14 -0400229 /** Defines callbacks for service binding, passed to bindService() */
230 private ServiceConnection mConnection = new ServiceConnection() {
231
232 @Override
233 public void onServiceConnected(ComponentName className,
234 IBinder binder) {
235 service = ISipService.Stub.asInterface(binder);
236 mBound = true;
Alexandre Savard817dc502012-10-22 11:47:29 -0400237 mContactListFragment.setService(service);
238 mCallElementList.setService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400239 Log.d(TAG, "Service connected");
240 }
241
242 @Override
243 public void onServiceDisconnected(ComponentName arg0) {
244 mBound = false;
245 Log.d(TAG, "Service disconnected");
246 }
247 };
248
Emeric Vigier12d61d82012-09-19 15:08:18 -0400249 private void startSipService() {
250 Thread thread = new Thread("StartSFLphoneService") {
251 public void run() {
252 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
253 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
254 startService(sipServiceIntent);
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400255 serviceIsOn = true;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400256 };
257 };
258 try {
259 thread.start();
260 } catch (IllegalThreadStateException e) {
261 AlertDialog.Builder builder = new AlertDialog.Builder(this);
262 builder.setMessage("Cannot start SFLPhone SipService!");
263 AlertDialog alert = builder.create();
264 alert.show();
265 finish();
266 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400267 }
268
269 @Override
270 public boolean onOptionsItemSelected(MenuItem item) {
271 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400272 if(item.getItemId() != 0) {
273 // When the button is clicked, launch an activity through this intent
274 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400275
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400276 // Make it a subactivity so we know when it returns
277 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400278 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400279
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400280 return super.onOptionsItemSelected(item);
281 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400282
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400283 @Override
284 public boolean onCreateOptionsMenu(Menu menu)
285 {
286 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
287 return true;
288 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400289
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400290 @Override
291 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
292 {
293 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400294
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400295 @Override
296 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
297 {
298 // When the given tab is selected, switch to the corresponding page in the ViewPager.
299 mViewPager.setCurrentItem(tab.getPosition());
300 }
301
302 @Override
303 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
304 {
305 // Log.d(TAG, "onTabReselected");
306 }
307
Alexandre Savardf17e3172012-10-25 16:09:09 -0400308 public void onSelectedCallAction(SipCall call) {
Alexandre Savard27a51132012-10-25 18:35:14 -0400309 int callState = call.getCallStateInt();
310
311 if((callState == SipCall.CALL_STATE_NONE) ||
312 (callState == SipCall.CALL_STATE_CURRENT)) {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400313 buttonCall.setEnabled(false);
314 buttonHangup.setEnabled(true);
315 }
Alexandre Savard27a51132012-10-25 18:35:14 -0400316 else {
317 buttonCall.setEnabled(true);
318 buttonHangup.setEnabled(false);
319 }
Alexandre Savardf17e3172012-10-25 16:09:09 -0400320
321 buttonCall.setTag(call);
322 buttonHangup.setTag(call);
323 }
324
325 public void onUnselectedCallAction() {
326 buttonCall.setTag(null);
327 buttonCall.setTag(null);
Alexandre Savarda949eec2012-10-25 17:30:49 -0400328
329 buttonCall.setEnabled(true);
330 buttonHangup.setEnabled(false);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400331 }
332
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400333 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400334 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400335 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400336 buttonCall.startAnimation(animation);
337 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400338 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400339
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400340 /**
341 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
342 * one of the primary sections of the app.
343 */
344 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
345 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400346
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400347 public SectionsPagerAdapter(FragmentManager fm)
348 {
349 super(fm);
350 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400351
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400352 @Override
353 public Fragment getItem(int i)
354 {
355 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400356
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400357 switch (i) {
358 case 0:
Alexandre Savard817dc502012-10-22 11:47:29 -0400359 mContactListFragment = new ContactListFragment(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400360 fragment = mContactListFragment;
361 break;
362 case 1:
Alexandre Savardf17e3172012-10-25 16:09:09 -0400363 mCallElementList = new CallElementList(service, mHome);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400364 SipCall.setCallElementList(mCallElementList);
365 fragment = mCallElementList;
366 break;
367 case 2:
368 fragment = new DummySectionFragment();
369 break;
370 case 3:
371 fragment = new ButtonSectionFragment();
372 Log.i(TAG, "getItem: fragment is " + fragment);
373 break;
374 default:
375 Log.e(TAG, "getItem: unknown tab position " + i);
376 return null;
377 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400378
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400379 Bundle args = new Bundle();
380 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
381 fragment.setArguments(args);
382 return fragment;
383 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400384
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400385 @Override
386 public int getCount()
387 {
388 return 4;
389 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400390
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400391 @Override
392 public CharSequence getPageTitle(int position)
393 {
394 switch (position) {
395 case 0:
396 return getString(R.string.title_section0).toUpperCase();
397 case 1:
398 return getString(R.string.title_section1).toUpperCase();
399 case 2:
400 return getString(R.string.title_section2).toUpperCase();
401 case 3:
402 return getString(R.string.title_section3).toUpperCase();
403 default:
404 Log.e(TAG, "getPageTitle: unknown tab position " + position);
405 break;
406 }
407 return null;
408 }
409 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400410
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400411 /**
412 * A dummy fragment representing a section of the app, but that simply
413 * displays dummy text.
414 */
415 public static class DummySectionFragment extends Fragment
416 {
417 public DummySectionFragment()
418 {
419 setRetainInstance(true);
420 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400421
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400422 public static final String ARG_SECTION_NUMBER = "section_number";
423
424 @Override
425 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
426 {
427 TextView textView = new TextView(getActivity());
428 textView.setGravity(Gravity.CENTER);
429 Bundle args = getArguments();
430 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
431 textView.setText("java sucks");
432 return textView;
433 }
434 }
435
436 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400437 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400438 {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400439 Log.i(TAG, "onClic from SFLPhoneHome");
Alexandre Savard91052442012-10-25 16:14:26 -0400440 switch (view.getId()) {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400441 case R.id.buttonCall:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400442 processingNewCallAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400443 break;
444 case R.id.buttonHangUp:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400445 processingHangUpAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400446 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400447 default:
448 Log.w(TAG, "unknown button " + view.getId());
449 break;
Emeric Vigier6119d782012-09-21 18:04:14 -0400450 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400451 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400452
453 public void processingNewCallAction() {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400454 String accountID = mAccountList.currentAccountID;
Alexandre Savardcb66fa42012-10-26 10:06:16 -0400455 EditText editText = (EditText) findViewById(R.id.phoneNumberTextEntry);
456 String to = editText.getText().toString();
Alexandre Savard27a51132012-10-25 18:35:14 -0400457
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400458 Random random = new Random();
Alexandre Savard27a51132012-10-25 18:35:14 -0400459 String callID = Integer.toString(random.nextInt());
460 SipCall.CallInfo info = new SipCall.CallInfo();
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400461
Alexandre Savard27a51132012-10-25 18:35:14 -0400462 info.mCallID = callID;
463 info.mAccountID = accountID;
464 info.mDisplayName = "Cool Guy!";
465 info.mPhone = to;
466 info.mEmail = "coolGuy@coolGuy.com";
Alexandre Savard2f1ae542012-10-26 17:05:00 -0400467 info.mCallType = SipCall.CALL_TYPE_OUTGOING;
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400468
Alexandre Savard27a51132012-10-25 18:35:14 -0400469 SipCall call = CallList.getCallInstance(info);
470 call.launchCallActivity(this);
471 call.placeCallUpdateUi();
472 call.notifyServicePlaceCall(service);
473
474 onSelectedCallAction(call);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400475 }
476
477 public void processingHangUpAction() {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400478 SipCall call = (SipCall)buttonHangup.getTag();
479 if(call != null)
480 call.notifyServiceHangup(service);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400481 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400482}