blob: 8de08a227525c9413ffc9e4b3168b38c1fe299a0 [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;
Alexandre Savardbb6f1872012-11-01 17:25:55 -040075import com.savoirfairelinux.sflphone.utils.AccountList;
Adrien Béraudffd32412012-08-07 18:39:23 -040076
Alexandre Savard7a902bc2012-10-04 16:32:35 -040077import java.util.HashMap;
78
Emeric Vigier62ca14d2012-08-24 11:05:09 -040079public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
Adrien Béraudffd32412012-08-07 18:39:23 -040080{
Alexandre Savard6c0584e2012-09-20 09:42:59 -040081 SectionsPagerAdapter mSectionsPagerAdapter;
82 static final String TAG = "SFLPhoneHome";
83 private ButtonSectionFragment buttonFragment;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040084 /* default callID */
Emeric Vigiereaf2c492012-09-19 14:38:20 -040085 static boolean serviceIsOn = false;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040086 private String incomingCallID = "";
87 private static final int REQUEST_CODE_PREFERENCES = 1;
88 ImageButton buttonCall, buttonHangup;
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 Savard48240e82012-10-26 10:36:03 -040098 private static final int ACTION_BAR_TAB_CONTACT = 0;
99 private static final int ACTION_BAR_TAB_CALL = 1;
100 private static final int ACTION_BAR_TAB_HISTORY = 2;
101
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400102 /**
103 * The {@link ViewPager} that will host the section contents.
104 */
105 ViewPager mViewPager;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400106
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400107 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 -0400108
Alexandre Savard817dc502012-10-22 11:47:29 -0400109 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
110
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400111 @Override
112 public void onCreate(Bundle savedInstanceState)
113 {
114 super.onCreate(savedInstanceState);
Alexandre Savard817dc502012-10-22 11:47:29 -0400115
116 if (!serviceIsOn) {
117 Log.i(TAG, "starting SipService");
118 startSipService();
119 }
120
121 // Bind to LocalService
122 if (!mBound) {
123 Log.i(TAG, "onStart: Binding service...");
124 Intent intent = new Intent(this, SipService.class);
125 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
126 }
127
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400128 setContentView(R.layout.activity_sflphone_home);
Adrien Béraudffd32412012-08-07 18:39:23 -0400129
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400130 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
Adrien Béraudffd32412012-08-07 18:39:23 -0400131
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400132 final ActionBar actionBar = getActionBar();
133 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
134 // final ActionBar actionBar = getActionBar();
Adrien Béraudffd32412012-08-07 18:39:23 -0400135
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400136 // Set up the ViewPager with the sections adapter.
137 mViewPager = (ViewPager) findViewById(R.id.pager);
138 mViewPager.setAdapter(mSectionsPagerAdapter);
Adrien Béraudffd32412012-08-07 18:39:23 -0400139
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400140 // When swiping between different sections, select the corresponding tab.
141 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
142 // Tab.
143 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
144 {
145 @Override
146 public void onPageSelected(int position)
147 {
148 actionBar.setSelectedNavigationItem(position);
149 }
150 });
Emeric Vigier383b2a22012-08-27 14:20:05 -0400151
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400152 // For each of the sections in the app, add a tab to the action bar.
153 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
154 // Create a tab with text corresponding to the page title defined by the adapter.
155 // Also specify this Activity object, which implements the TabListener interface, as the
156 // listener for when this tab is selected.
157 Log.i(TAG, "adding tab: " + i);
158 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
159 }
Emeric Vigier383b2a22012-08-27 14:20:05 -0400160
Alexandre Savard48240e82012-10-26 10:36:03 -0400161 actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
Alexandre Savardcb66fa42012-10-26 10:06:16 -0400162
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400163 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
164 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400165
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400166 // Change alpha from fully visible to invisible
167 animation = new AlphaAnimation(1, 0);
168 // duration - half a second
169 animation.setDuration(500);
170 // do not alter animation rate
171 animation.setInterpolator(new LinearInterpolator());
172 // Repeat animation infinitely
173 animation.setRepeatCount(Animation.INFINITE);
174 // Reverse
175 animation.setRepeatMode(Animation.REVERSE);
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400176
177 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("new-call-created"));
178 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("call-state-changed"));
179 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("incoming-call"));
Alexandre Savarda949eec2012-10-25 17:30:49 -0400180
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400181 LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, new IntentFilter("accounts-changed"));
182 LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, new IntentFilter("account-state-changed"));
183
Alexandre Savarda949eec2012-10-25 17:30:49 -0400184 SipCall.setSFLPhoneHomeContext(this);
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400185 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400186
Emeric Vigier12d61d82012-09-19 15:08:18 -0400187 @Override
188 protected void onStart() {
189 Log.i(TAG, "onStart");
190 super.onStart();
191 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400192
Emeric Vigier6119d782012-09-21 18:04:14 -0400193 /* user gets back to the activity, e.g. through task manager */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400194 @Override
195 protected void onRestart() {
196 super.onRestart();
197 }
198
Emeric Vigier6119d782012-09-21 18:04:14 -0400199 /* activity gets back to the foreground and user input */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400200 @Override
201 protected void onResume() {
202 Log.i(TAG, "onResume");
203 super.onResume();
Emeric Vigier12d61d82012-09-19 15:08:18 -0400204 }
205
Emeric Vigier6119d782012-09-21 18:04:14 -0400206 /* activity no more in foreground */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400207 @Override
208 protected void onPause() {
Emeric Vigier12d61d82012-09-19 15:08:18 -0400209 super.onPause();
210 }
211
Emeric Vigier6119d782012-09-21 18:04:14 -0400212 /* activity is no longer visible */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400213 @Override
214 protected void onStop() {
215 super.onStop();
Alexandre Savard817dc502012-10-22 11:47:29 -0400216 }
217
218 /* activity finishes itself or is being killed by the system */
219 @Override
220 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400221 /* stop the service, if no other bound user, no need to check if it is running */
222 if (mBound) {
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400223 Log.i(TAG, "onStop: Unbinding service...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400224 unbindService(mConnection);
225 mBound = false;
226 }
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400227 Log.i(TAG, "onDestroy: stopping SipService...");
228 stopService(new Intent(this, SipService.class));
Emeric Vigier6119d782012-09-21 18:04:14 -0400229 serviceIsOn = false;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400230 super.onDestroy();
231 }
232
Emeric Vigier6119d782012-09-21 18:04:14 -0400233 /** Defines callbacks for service binding, passed to bindService() */
234 private ServiceConnection mConnection = new ServiceConnection() {
235
236 @Override
237 public void onServiceConnected(ComponentName className,
238 IBinder binder) {
239 service = ISipService.Stub.asInterface(binder);
240 mBound = true;
Alexandre Savard817dc502012-10-22 11:47:29 -0400241 mContactListFragment.setService(service);
242 mCallElementList.setService(service);
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400243 mAccountList.setSipService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400244 Log.d(TAG, "Service connected");
245 }
246
247 @Override
248 public void onServiceDisconnected(ComponentName arg0) {
249 mBound = false;
250 Log.d(TAG, "Service disconnected");
251 }
252 };
253
Emeric Vigier12d61d82012-09-19 15:08:18 -0400254 private void startSipService() {
255 Thread thread = new Thread("StartSFLphoneService") {
256 public void run() {
257 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
258 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
259 startService(sipServiceIntent);
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400260 serviceIsOn = true;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400261 };
262 };
263 try {
264 thread.start();
265 } catch (IllegalThreadStateException e) {
266 AlertDialog.Builder builder = new AlertDialog.Builder(this);
267 builder.setMessage("Cannot start SFLPhone SipService!");
268 AlertDialog alert = builder.create();
269 alert.show();
270 finish();
271 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400272 }
273
274 @Override
275 public boolean onOptionsItemSelected(MenuItem item) {
276 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400277 if(item.getItemId() != 0) {
278 // When the button is clicked, launch an activity through this intent
279 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400280
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400281 // Make it a subactivity so we know when it returns
282 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400283 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400284
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400285 return super.onOptionsItemSelected(item);
286 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400287
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400288 @Override
289 public boolean onCreateOptionsMenu(Menu menu)
290 {
291 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
292 return true;
293 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400294
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400295 @Override
296 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
297 {
298 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400299
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400300 @Override
301 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
302 {
303 // When the given tab is selected, switch to the corresponding page in the ViewPager.
304 mViewPager.setCurrentItem(tab.getPosition());
305 }
306
307 @Override
308 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
309 {
310 // Log.d(TAG, "onTabReselected");
311 }
312
Alexandre Savardf17e3172012-10-25 16:09:09 -0400313 public void onSelectedCallAction(SipCall call) {
Alexandre Savard27a51132012-10-25 18:35:14 -0400314 int callState = call.getCallStateInt();
315
316 if((callState == SipCall.CALL_STATE_NONE) ||
317 (callState == SipCall.CALL_STATE_CURRENT)) {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400318 buttonCall.setEnabled(false);
319 buttonHangup.setEnabled(true);
320 }
Alexandre Savard27a51132012-10-25 18:35:14 -0400321 else {
322 buttonCall.setEnabled(true);
323 buttonHangup.setEnabled(false);
324 }
Alexandre Savardf17e3172012-10-25 16:09:09 -0400325
326 buttonCall.setTag(call);
327 buttonHangup.setTag(call);
328 }
329
330 public void onUnselectedCallAction() {
331 buttonCall.setTag(null);
332 buttonCall.setTag(null);
Alexandre Savarda949eec2012-10-25 17:30:49 -0400333
334 buttonCall.setEnabled(true);
335 buttonHangup.setEnabled(false);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400336 }
337
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400338 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400339 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400340 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400341 buttonCall.startAnimation(animation);
342 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400343 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400344
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400345 /**
346 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
347 * one of the primary sections of the app.
348 */
349 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
350 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400351
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400352 public SectionsPagerAdapter(FragmentManager fm)
353 {
354 super(fm);
355 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400356
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400357 @Override
358 public Fragment getItem(int i)
359 {
360 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400361
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400362 switch (i) {
363 case 0:
Alexandre Savard817dc502012-10-22 11:47:29 -0400364 mContactListFragment = new ContactListFragment(service);
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400365 mContactListFragment.setAccountList(mAccountList);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400366 fragment = mContactListFragment;
367 break;
368 case 1:
Alexandre Savardf17e3172012-10-25 16:09:09 -0400369 mCallElementList = new CallElementList(service, mHome);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400370 SipCall.setCallElementList(mCallElementList);
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400371 mCallElementList.setAccountList(mAccountList);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400372 fragment = mCallElementList;
373 break;
374 case 2:
375 fragment = new DummySectionFragment();
376 break;
377 case 3:
378 fragment = new ButtonSectionFragment();
379 Log.i(TAG, "getItem: fragment is " + fragment);
380 break;
381 default:
382 Log.e(TAG, "getItem: unknown tab position " + i);
383 return null;
384 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400385
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400386 Bundle args = new Bundle();
387 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
388 fragment.setArguments(args);
389 return fragment;
390 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400391
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400392 @Override
393 public int getCount()
394 {
395 return 4;
396 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400397
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400398 @Override
399 public CharSequence getPageTitle(int position)
400 {
401 switch (position) {
402 case 0:
403 return getString(R.string.title_section0).toUpperCase();
404 case 1:
405 return getString(R.string.title_section1).toUpperCase();
406 case 2:
407 return getString(R.string.title_section2).toUpperCase();
408 case 3:
409 return getString(R.string.title_section3).toUpperCase();
410 default:
411 Log.e(TAG, "getPageTitle: unknown tab position " + position);
412 break;
413 }
414 return null;
415 }
416 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400417
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400418 /**
419 * A dummy fragment representing a section of the app, but that simply
420 * displays dummy text.
421 */
422 public static class DummySectionFragment extends Fragment
423 {
424 public DummySectionFragment()
425 {
426 setRetainInstance(true);
427 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400428
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400429 public static final String ARG_SECTION_NUMBER = "section_number";
430
431 @Override
432 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
433 {
434 TextView textView = new TextView(getActivity());
435 textView.setGravity(Gravity.CENTER);
436 Bundle args = getArguments();
437 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
438 textView.setText("java sucks");
439 return textView;
440 }
441 }
442
443 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400444 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400445 {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400446 Log.i(TAG, "onClic from SFLPhoneHome");
Alexandre Savard91052442012-10-25 16:14:26 -0400447 switch (view.getId()) {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400448 case R.id.buttonCall:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400449 processingNewCallAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400450 break;
451 case R.id.buttonHangUp:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400452 processingHangUpAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400453 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400454 default:
455 Log.w(TAG, "unknown button " + view.getId());
456 break;
Emeric Vigier6119d782012-09-21 18:04:14 -0400457 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400458 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400459
460 public void processingNewCallAction() {
Alexandre Savard60f0f1c2012-11-01 09:40:34 -0400461 // String accountID = mAccountList.currentAccountID;
462 String accountID = mCallElementList.getSelectedAccount();
Alexandre Savardcb66fa42012-10-26 10:06:16 -0400463 EditText editText = (EditText) findViewById(R.id.phoneNumberTextEntry);
464 String to = editText.getText().toString();
Alexandre Savard27a51132012-10-25 18:35:14 -0400465
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400466 Random random = new Random();
Alexandre Savard27a51132012-10-25 18:35:14 -0400467 String callID = Integer.toString(random.nextInt());
468 SipCall.CallInfo info = new SipCall.CallInfo();
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400469
Alexandre Savard27a51132012-10-25 18:35:14 -0400470 info.mCallID = callID;
471 info.mAccountID = accountID;
472 info.mDisplayName = "Cool Guy!";
473 info.mPhone = to;
474 info.mEmail = "coolGuy@coolGuy.com";
Alexandre Savard2f1ae542012-10-26 17:05:00 -0400475 info.mCallType = SipCall.CALL_TYPE_OUTGOING;
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400476
Alexandre Savard27a51132012-10-25 18:35:14 -0400477 SipCall call = CallList.getCallInstance(info);
478 call.launchCallActivity(this);
479 call.placeCallUpdateUi();
480 call.notifyServicePlaceCall(service);
481
482 onSelectedCallAction(call);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400483 }
484
485 public void processingHangUpAction() {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400486 SipCall call = (SipCall)buttonHangup.getTag();
487 if(call != null)
488 call.notifyServiceHangup(service);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400489 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400490}