blob: ac3e93830d91536cfc4b273755514cd61aa06adb [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 */
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);
Emeric Vigier1f1ced32012-11-02 16:56:32 -040096 private SFLphoneApplication mApplication;
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
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400116 mApplication = (SFLphoneApplication) getApplication();
117
118 if (!mApplication.isServiceRunning()) {
Alexandre Savard817dc502012-10-22 11:47:29 -0400119 Log.i(TAG, "starting SipService");
120 startSipService();
121 }
122
123 // Bind to LocalService
124 if (!mBound) {
125 Log.i(TAG, "onStart: Binding service...");
126 Intent intent = new Intent(this, SipService.class);
127 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
128 }
129
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400130 setContentView(R.layout.activity_sflphone_home);
Adrien Béraudffd32412012-08-07 18:39:23 -0400131
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400132 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
Adrien Béraudffd32412012-08-07 18:39:23 -0400133
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400134 final ActionBar actionBar = getActionBar();
135 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
136 // final ActionBar actionBar = getActionBar();
Adrien Béraudffd32412012-08-07 18:39:23 -0400137
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400138 // Set up the ViewPager with the sections adapter.
139 mViewPager = (ViewPager) findViewById(R.id.pager);
140 mViewPager.setAdapter(mSectionsPagerAdapter);
Adrien Béraudffd32412012-08-07 18:39:23 -0400141
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400142 // When swiping between different sections, select the corresponding tab.
143 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
144 // Tab.
145 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
146 {
147 @Override
148 public void onPageSelected(int position)
149 {
150 actionBar.setSelectedNavigationItem(position);
151 }
152 });
Emeric Vigier383b2a22012-08-27 14:20:05 -0400153
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400154 // For each of the sections in the app, add a tab to the action bar.
155 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
156 // Create a tab with text corresponding to the page title defined by the adapter.
157 // Also specify this Activity object, which implements the TabListener interface, as the
158 // listener for when this tab is selected.
159 Log.i(TAG, "adding tab: " + i);
160 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
161 }
Emeric Vigier383b2a22012-08-27 14:20:05 -0400162
Alexandre Savard48240e82012-10-26 10:36:03 -0400163 actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL);
Alexandre Savardcb66fa42012-10-26 10:06:16 -0400164
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400165 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
166 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400167
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400168 // Change alpha from fully visible to invisible
169 animation = new AlphaAnimation(1, 0);
170 // duration - half a second
171 animation.setDuration(500);
172 // do not alter animation rate
173 animation.setInterpolator(new LinearInterpolator());
174 // Repeat animation infinitely
175 animation.setRepeatCount(Animation.INFINITE);
176 // Reverse
177 animation.setRepeatMode(Animation.REVERSE);
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400178
179 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("new-call-created"));
180 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("call-state-changed"));
181 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("incoming-call"));
Alexandre Savarda949eec2012-10-25 17:30:49 -0400182
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400183 LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, new IntentFilter("accounts-changed"));
184 LocalBroadcastManager.getInstance(this).registerReceiver(mAccountList, new IntentFilter("account-state-changed"));
185
Alexandre Savarda949eec2012-10-25 17:30:49 -0400186 SipCall.setSFLPhoneHomeContext(this);
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400187 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400188
Emeric Vigier12d61d82012-09-19 15:08:18 -0400189 @Override
190 protected void onStart() {
191 Log.i(TAG, "onStart");
192 super.onStart();
193 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400194
Emeric Vigier6119d782012-09-21 18:04:14 -0400195 /* user gets back to the activity, e.g. through task manager */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400196 @Override
197 protected void onRestart() {
198 super.onRestart();
199 }
200
Emeric Vigier6119d782012-09-21 18:04:14 -0400201 /* activity gets back to the foreground and user input */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400202 @Override
203 protected void onResume() {
204 Log.i(TAG, "onResume");
205 super.onResume();
Emeric Vigier12d61d82012-09-19 15:08:18 -0400206 }
207
Emeric Vigier6119d782012-09-21 18:04:14 -0400208 /* activity no more in foreground */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400209 @Override
210 protected void onPause() {
Emeric Vigier12d61d82012-09-19 15:08:18 -0400211 super.onPause();
212 }
213
Emeric Vigier6119d782012-09-21 18:04:14 -0400214 /* activity is no longer visible */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400215 @Override
216 protected void onStop() {
217 super.onStop();
Alexandre Savard817dc502012-10-22 11:47:29 -0400218 }
219
220 /* activity finishes itself or is being killed by the system */
221 @Override
222 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400223 /* stop the service, if no other bound user, no need to check if it is running */
224 if (mBound) {
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400225 Log.i(TAG, "onStop: Unbinding service...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400226 unbindService(mConnection);
227 mBound = false;
228 }
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400229 Log.i(TAG, "onDestroy: stopping SipService...");
230 stopService(new Intent(this, SipService.class));
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400231 mApplication.setServiceRunning(false);
Emeric Vigier12d61d82012-09-19 15:08:18 -0400232 super.onDestroy();
233 }
234
Emeric Vigier6119d782012-09-21 18:04:14 -0400235 /** Defines callbacks for service binding, passed to bindService() */
236 private ServiceConnection mConnection = new ServiceConnection() {
237
238 @Override
239 public void onServiceConnected(ComponentName className,
240 IBinder binder) {
241 service = ISipService.Stub.asInterface(binder);
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400242 mApplication.setSipService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400243 mBound = true;
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400244 mAccountList.setSipService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400245 Log.d(TAG, "Service connected");
246 }
247
248 @Override
249 public void onServiceDisconnected(ComponentName arg0) {
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400250 mApplication.setSipService(null);
Emeric Vigier6119d782012-09-21 18:04:14 -0400251 mBound = false;
252 Log.d(TAG, "Service disconnected");
253 }
254 };
255
Emeric Vigier12d61d82012-09-19 15:08:18 -0400256 private void startSipService() {
257 Thread thread = new Thread("StartSFLphoneService") {
258 public void run() {
259 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
260 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
261 startService(sipServiceIntent);
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400262 mApplication.setServiceRunning(true);
Emeric Vigier12d61d82012-09-19 15:08:18 -0400263 };
264 };
265 try {
266 thread.start();
267 } catch (IllegalThreadStateException e) {
268 AlertDialog.Builder builder = new AlertDialog.Builder(this);
269 builder.setMessage("Cannot start SFLPhone SipService!");
270 AlertDialog alert = builder.create();
271 alert.show();
272 finish();
273 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400274 }
275
276 @Override
277 public boolean onOptionsItemSelected(MenuItem item) {
278 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400279 if(item.getItemId() != 0) {
280 // When the button is clicked, launch an activity through this intent
281 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400282
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400283 // Make it a subactivity so we know when it returns
284 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400285 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400286
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400287 return super.onOptionsItemSelected(item);
288 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400289
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400290 @Override
291 public boolean onCreateOptionsMenu(Menu menu)
292 {
293 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
294 return true;
295 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400296
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400297 @Override
298 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
299 {
300 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400301
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400302 @Override
303 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
304 {
305 // When the given tab is selected, switch to the corresponding page in the ViewPager.
306 mViewPager.setCurrentItem(tab.getPosition());
307 }
308
309 @Override
310 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
311 {
312 // Log.d(TAG, "onTabReselected");
313 }
314
Alexandre Savardf17e3172012-10-25 16:09:09 -0400315 public void onSelectedCallAction(SipCall call) {
Alexandre Savard27a51132012-10-25 18:35:14 -0400316 int callState = call.getCallStateInt();
317
318 if((callState == SipCall.CALL_STATE_NONE) ||
319 (callState == SipCall.CALL_STATE_CURRENT)) {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400320 buttonCall.setEnabled(false);
321 buttonHangup.setEnabled(true);
322 }
Alexandre Savard27a51132012-10-25 18:35:14 -0400323 else {
324 buttonCall.setEnabled(true);
325 buttonHangup.setEnabled(false);
326 }
Alexandre Savardf17e3172012-10-25 16:09:09 -0400327
328 buttonCall.setTag(call);
329 buttonHangup.setTag(call);
330 }
331
332 public void onUnselectedCallAction() {
333 buttonCall.setTag(null);
334 buttonCall.setTag(null);
Alexandre Savarda949eec2012-10-25 17:30:49 -0400335
336 buttonCall.setEnabled(true);
337 buttonHangup.setEnabled(false);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400338 }
339
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400340 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400341 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400342 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400343 buttonCall.startAnimation(animation);
344 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400345 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400346
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400347 /**
348 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
349 * one of the primary sections of the app.
350 */
351 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
352 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400353
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400354 public SectionsPagerAdapter(FragmentManager fm)
355 {
356 super(fm);
357 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400358
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400359 @Override
360 public Fragment getItem(int i)
361 {
362 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400363
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400364 switch (i) {
365 case 0:
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400366 mContactListFragment = new ContactListFragment();
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400367 mContactListFragment.setAccountList(mAccountList);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400368 fragment = mContactListFragment;
369 break;
370 case 1:
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400371 mCallElementList = new CallElementList();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400372 SipCall.setCallElementList(mCallElementList);
Alexandre Savardbb6f1872012-11-01 17:25:55 -0400373 mCallElementList.setAccountList(mAccountList);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400374 fragment = mCallElementList;
375 break;
376 case 2:
377 fragment = new DummySectionFragment();
378 break;
379 case 3:
380 fragment = new ButtonSectionFragment();
381 Log.i(TAG, "getItem: fragment is " + fragment);
382 break;
383 default:
384 Log.e(TAG, "getItem: unknown tab position " + i);
385 return null;
386 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400387
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400388 Bundle args = new Bundle();
389 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
390 fragment.setArguments(args);
391 return fragment;
392 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400393
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400394 @Override
395 public int getCount()
396 {
397 return 4;
398 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400399
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400400 @Override
401 public CharSequence getPageTitle(int position)
402 {
403 switch (position) {
404 case 0:
405 return getString(R.string.title_section0).toUpperCase();
406 case 1:
407 return getString(R.string.title_section1).toUpperCase();
408 case 2:
409 return getString(R.string.title_section2).toUpperCase();
410 case 3:
411 return getString(R.string.title_section3).toUpperCase();
412 default:
413 Log.e(TAG, "getPageTitle: unknown tab position " + position);
414 break;
415 }
416 return null;
417 }
418 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400419
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400420 /**
421 * A dummy fragment representing a section of the app, but that simply
422 * displays dummy text.
423 */
424 public static class DummySectionFragment extends Fragment
425 {
426 public DummySectionFragment()
427 {
428 setRetainInstance(true);
429 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400430
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400431 public static final String ARG_SECTION_NUMBER = "section_number";
432
433 @Override
434 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
435 {
436 TextView textView = new TextView(getActivity());
437 textView.setGravity(Gravity.CENTER);
438 Bundle args = getArguments();
439 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
440 textView.setText("java sucks");
441 return textView;
442 }
443 }
444
445 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400446 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400447 {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400448 Log.i(TAG, "onClic from SFLPhoneHome");
Alexandre Savard91052442012-10-25 16:14:26 -0400449 switch (view.getId()) {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400450 case R.id.buttonCall:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400451 processingNewCallAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400452 break;
453 case R.id.buttonHangUp:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400454 processingHangUpAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400455 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400456 default:
457 Log.w(TAG, "unknown button " + view.getId());
458 break;
Emeric Vigier6119d782012-09-21 18:04:14 -0400459 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400460 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400461
462 public void processingNewCallAction() {
Alexandre Savard60f0f1c2012-11-01 09:40:34 -0400463 // String accountID = mAccountList.currentAccountID;
464 String accountID = mCallElementList.getSelectedAccount();
Alexandre Savardcb66fa42012-10-26 10:06:16 -0400465 EditText editText = (EditText) findViewById(R.id.phoneNumberTextEntry);
466 String to = editText.getText().toString();
Alexandre Savard27a51132012-10-25 18:35:14 -0400467
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400468 Random random = new Random();
Alexandre Savard27a51132012-10-25 18:35:14 -0400469 String callID = Integer.toString(random.nextInt());
470 SipCall.CallInfo info = new SipCall.CallInfo();
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400471
Alexandre Savard27a51132012-10-25 18:35:14 -0400472 info.mCallID = callID;
473 info.mAccountID = accountID;
474 info.mDisplayName = "Cool Guy!";
475 info.mPhone = to;
476 info.mEmail = "coolGuy@coolGuy.com";
Alexandre Savard2f1ae542012-10-26 17:05:00 -0400477 info.mCallType = SipCall.CALL_TYPE_OUTGOING;
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400478
Alexandre Savard27a51132012-10-25 18:35:14 -0400479 SipCall call = CallList.getCallInstance(info);
480 call.launchCallActivity(this);
481 call.placeCallUpdateUi();
482 call.notifyServicePlaceCall(service);
483
484 onSelectedCallAction(call);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400485 }
486
487 public void processingHangUpAction() {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400488 SipCall call = (SipCall)buttonHangup.getTag();
489 if(call != null)
490 call.notifyServiceHangup(service);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400491 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400492}