blob: 906f44f749ec0cbbce893f6e0fbbf85c0b89510c [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) {
304 if(call.getCallStateInt() == SipCall.CALL_STATE_CURRENT) {
305 buttonCall.setEnabled(false);
306 buttonHangup.setEnabled(true);
307 }
308
309 buttonCall.setTag(call);
310 buttonHangup.setTag(call);
311 }
312
313 public void onUnselectedCallAction() {
314 buttonCall.setTag(null);
315 buttonCall.setTag(null);
Alexandre Savarda949eec2012-10-25 17:30:49 -0400316
317 buttonCall.setEnabled(true);
318 buttonHangup.setEnabled(false);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400319 }
320
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400321 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400322 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400323 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400324 buttonCall.startAnimation(animation);
325 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400326 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400327
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400328 /**
329 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
330 * one of the primary sections of the app.
331 */
332 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
333 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400334
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400335 public SectionsPagerAdapter(FragmentManager fm)
336 {
337 super(fm);
338 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400339
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400340 @Override
341 public Fragment getItem(int i)
342 {
343 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400344
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400345 switch (i) {
346 case 0:
Alexandre Savard817dc502012-10-22 11:47:29 -0400347 mContactListFragment = new ContactListFragment(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400348 fragment = mContactListFragment;
349 break;
350 case 1:
Alexandre Savardf17e3172012-10-25 16:09:09 -0400351 mCallElementList = new CallElementList(service, mHome);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400352 SipCall.setCallElementList(mCallElementList);
353 fragment = mCallElementList;
354 break;
355 case 2:
356 fragment = new DummySectionFragment();
357 break;
358 case 3:
359 fragment = new ButtonSectionFragment();
360 Log.i(TAG, "getItem: fragment is " + fragment);
361 break;
362 default:
363 Log.e(TAG, "getItem: unknown tab position " + i);
364 return null;
365 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400366
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400367 Bundle args = new Bundle();
368 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
369 fragment.setArguments(args);
370 return fragment;
371 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400372
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400373 @Override
374 public int getCount()
375 {
376 return 4;
377 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400378
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400379 @Override
380 public CharSequence getPageTitle(int position)
381 {
382 switch (position) {
383 case 0:
384 return getString(R.string.title_section0).toUpperCase();
385 case 1:
386 return getString(R.string.title_section1).toUpperCase();
387 case 2:
388 return getString(R.string.title_section2).toUpperCase();
389 case 3:
390 return getString(R.string.title_section3).toUpperCase();
391 default:
392 Log.e(TAG, "getPageTitle: unknown tab position " + position);
393 break;
394 }
395 return null;
396 }
397 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400398
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400399 /**
400 * A dummy fragment representing a section of the app, but that simply
401 * displays dummy text.
402 */
403 public static class DummySectionFragment extends Fragment
404 {
405 public DummySectionFragment()
406 {
407 setRetainInstance(true);
408 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400409
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400410 public static final String ARG_SECTION_NUMBER = "section_number";
411
412 @Override
413 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
414 {
415 TextView textView = new TextView(getActivity());
416 textView.setGravity(Gravity.CENTER);
417 Bundle args = getArguments();
418 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
419 textView.setText("java sucks");
420 return textView;
421 }
422 }
423
424 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400425 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400426 {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400427 Log.i(TAG, "onClic from SFLPhoneHome");
Alexandre Savard91052442012-10-25 16:14:26 -0400428 switch (view.getId()) {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400429 case R.id.buttonCall:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400430 processingNewCallAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400431 break;
432 case R.id.buttonHangUp:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400433 processingHangUpAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400434 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400435 default:
436 Log.w(TAG, "unknown button " + view.getId());
437 break;
Emeric Vigier6119d782012-09-21 18:04:14 -0400438 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400439 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400440
441 public void processingNewCallAction() {
Alexandre Savard14323be2012-10-24 10:02:13 -0400442 /*
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400443 Log.d(TAG, "ProcessingNewCallAction()");
444 TextView textView = (TextView) findViewById(R.id.editAccountID);
445 String accountID = mAccountList.currentAccountID;
446 // String accountID = textView.getText().toString();
447 // buttonCall.setImageResource(R.drawable.ic_call);
448 EditText editText;
449 Random random = new Random();
450
451 try {
452
453 if (incomingCallID != "") {
454 Log.d(TAG, "Incoming Call Branch");
455 buttonCall.clearAnimation();
456 service.accept(incomingCallID);
457 callID = incomingCallID;
458 incomingCallID="";
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400459 buttonCall.setEnabled(false);
460 buttonHangup.setEnabled(true);
461 } else {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400462 Log.d(TAG, "Outgoing Call Branch");
463 editText = (EditText) findViewById(R.id.editTo);
464 String to = "147"; // editText.getText().toString();
465 Log.d(TAG, "to string is " + to);
466 if (to == null) {
467 Log.e(TAG, "to string is " + to);
468 return;
469 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400470
Alexandre Savardf17e3172012-10-25 16:09:09 -0400471 callID = Integer.toString(random.nextInt());
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400472
Alexandre Savardf17e3172012-10-25 16:09:09 -0400473 Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
474 service.placeCall(accountID, callID, to);
475 buttonCall.setEnabled(false);
476 buttonHangup.setEnabled(true);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400477 }
478
479 } catch (RemoteException e) {
480 Log.e(TAG, "Cannot call service method", e);
481 }
Alexandre Savard14323be2012-10-24 10:02:13 -0400482 */
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400483 try {
484 String accountID = mAccountList.currentAccountID;
485 EditText editText = (EditText) findViewById(R.id.editTo);
486 String to = "147"; // editText.getText().toString();
487
488 Random random = new Random();
489 String callID = Integer.toString(random.nextInt());
490 SipCall.CallInfo info = new SipCall.CallInfo();
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400491
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400492 info.mCallID = callID;
493 info.mDisplayName = "Cool Guy!";
494 info.mPhone = to;
495 info.mEmail = "coolGuy@coolGuy.com";
496
497 SipCall call = CallList.getCallInstance(info);
Alexandre Savarddf544262012-10-25 14:24:08 -0400498 call.launchCallActivity(this);
Alexandre Savarda949eec2012-10-25 17:30:49 -0400499 call.placeCallUpdateUi();
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400500
501 Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
502 service.placeCall(accountID, callID, to);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400503
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400504 buttonCall.setEnabled(false);
505 buttonHangup.setEnabled(true);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400506
507 buttonCall.setTag(call);
508 buttonHangup.setTag(call);
509
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400510 } catch (RemoteException e) {
511 Log.e(TAG, "Cannot call service method", e);
512 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400513 }
514
515 public void processingHangUpAction() {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400516 /*
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400517 try {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400518 if (incomingCallID != "") {
519 buttonCall.clearAnimation();
520 Log.d(TAG, "service.refuse(" + incomingCallID + ");");
521 service.refuse(incomingCallID);
522 incomingCallID="";
523 buttonCall.setEnabled(true);
524 buttonHangup.setEnabled(true);
525 } else {
Alexandre Savardf17e3172012-10-25 16:09:09 -0400526 Log.d(TAG, "service.hangUp(" + callID + ");");
527 service.hangUp(callID);
528 callOnGoing = false;
529 buttonCall.setEnabled(true);
530 buttonHangup.setEnabled(false);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400531 }
532 } catch (RemoteException e) {
533 Log.e(TAG, "Cannot call service method", e);
534 }
535
536 buttonCall.setImageResource(R.drawable.ic_call);
Alexandre Savardf17e3172012-10-25 16:09:09 -0400537 */
538 SipCall call = (SipCall)buttonHangup.getTag();
539 if(call != null)
540 call.notifyServiceHangup(service);
541
542 buttonCall.setTag(null);
543 buttonHangup.setTag(null);
544
545 buttonCall.setEnabled(true);
546 buttonHangup.setEnabled(false);
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400547 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400548}