blob: 9745636401b92ace1de023b31ce9eb40b72492b5 [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;
Emeric Vigier05e894e2012-08-20 13:53:02 -040060import android.view.View.OnClickListener;
Adrien Béraudffd32412012-08-07 18:39:23 -040061import android.view.ViewGroup;
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 */
84 static String callID = "007";
85 static boolean callOnGoing = false;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040086 static boolean serviceIsOn = false;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040087 private String incomingCallID = "";
88 private static final int REQUEST_CODE_PREFERENCES = 1;
89 ImageButton buttonCall, buttonHangup;
90 Button buttonService;
Emeric Vigier419ba7b2012-09-19 14:55:14 -040091 static Animation animation;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040092 ContactListFragment mContactListFragment;
93 CallElementList mCallElementList;
Emeric Vigier6119d782012-09-21 18:04:14 -040094 private boolean mBound = false;
95 private ISipService service;
Alexandre Savard6b8d1df2012-10-23 16:44:43 -040096 public AccountList mAccountList = new AccountList();
Alexandre Savard73bc56f2012-10-25 13:35:54 -040097 public CallList mCallList = new CallList(this);
Adrien Béraudffd32412012-08-07 18:39:23 -040098
Alexandre Savard6c0584e2012-09-20 09:42:59 -040099 /**
100 * The {@link ViewPager} that will host the section contents.
101 */
102 ViewPager mViewPager;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400103
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400104 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 -0400105
Alexandre Savard817dc502012-10-22 11:47:29 -0400106 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
107
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400108 @Override
109 public void onCreate(Bundle savedInstanceState)
110 {
111 super.onCreate(savedInstanceState);
Alexandre Savard817dc502012-10-22 11:47:29 -0400112
113 if (!serviceIsOn) {
114 Log.i(TAG, "starting SipService");
115 startSipService();
116 }
117
118 // Bind to LocalService
119 if (!mBound) {
120 Log.i(TAG, "onStart: Binding service...");
121 Intent intent = new Intent(this, SipService.class);
122 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
123 }
124
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400125 setContentView(R.layout.activity_sflphone_home);
Adrien Béraudffd32412012-08-07 18:39:23 -0400126
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400127 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
Adrien Béraudffd32412012-08-07 18:39:23 -0400128
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400129 final ActionBar actionBar = getActionBar();
130 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
131 // final ActionBar actionBar = getActionBar();
Adrien Béraudffd32412012-08-07 18:39:23 -0400132
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400133 // Set up the ViewPager with the sections adapter.
134 mViewPager = (ViewPager) findViewById(R.id.pager);
135 mViewPager.setAdapter(mSectionsPagerAdapter);
Adrien Béraudffd32412012-08-07 18:39:23 -0400136
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400137 // When swiping between different sections, select the corresponding tab.
138 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
139 // Tab.
140 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
141 {
142 @Override
143 public void onPageSelected(int position)
144 {
145 actionBar.setSelectedNavigationItem(position);
146 }
147 });
Emeric Vigier383b2a22012-08-27 14:20:05 -0400148
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400149 // For each of the sections in the app, add a tab to the action bar.
150 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
151 // Create a tab with text corresponding to the page title defined by the adapter.
152 // Also specify this Activity object, which implements the TabListener interface, as the
153 // listener for when this tab is selected.
154 Log.i(TAG, "adding tab: " + i);
155 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
156 }
Emeric Vigier383b2a22012-08-27 14:20:05 -0400157
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400158 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
159 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400160
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400161 // Change alpha from fully visible to invisible
162 animation = new AlphaAnimation(1, 0);
163 // duration - half a second
164 animation.setDuration(500);
165 // do not alter animation rate
166 animation.setInterpolator(new LinearInterpolator());
167 // Repeat animation infinitely
168 animation.setRepeatCount(Animation.INFINITE);
169 // Reverse
170 animation.setRepeatMode(Animation.REVERSE);
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400171
172 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("new-call-created"));
173 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("call-state-changed"));
174 LocalBroadcastManager.getInstance(this).registerReceiver(mCallList, new IntentFilter("incoming-call"));
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400175 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400176
Emeric Vigier12d61d82012-09-19 15:08:18 -0400177 @Override
178 protected void onStart() {
179 Log.i(TAG, "onStart");
180 super.onStart();
181 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400182
Emeric Vigier6119d782012-09-21 18:04:14 -0400183 /* user gets back to the activity, e.g. through task manager */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400184 @Override
185 protected void onRestart() {
186 super.onRestart();
187 }
188
Emeric Vigier6119d782012-09-21 18:04:14 -0400189 /* activity gets back to the foreground and user input */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400190 @Override
191 protected void onResume() {
192 Log.i(TAG, "onResume");
193 super.onResume();
Emeric Vigier12d61d82012-09-19 15:08:18 -0400194 }
195
Emeric Vigier6119d782012-09-21 18:04:14 -0400196 /* activity no more in foreground */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400197 @Override
198 protected void onPause() {
Emeric Vigier12d61d82012-09-19 15:08:18 -0400199 super.onPause();
200 }
201
Emeric Vigier6119d782012-09-21 18:04:14 -0400202 /* activity is no longer visible */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400203 @Override
204 protected void onStop() {
205 super.onStop();
Alexandre Savard817dc502012-10-22 11:47:29 -0400206 }
207
208 /* activity finishes itself or is being killed by the system */
209 @Override
210 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400211 /* stop the service, if no other bound user, no need to check if it is running */
212 if (mBound) {
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400213 Log.i(TAG, "onStop: Unbinding service...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400214 unbindService(mConnection);
215 mBound = false;
216 }
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400217 Log.i(TAG, "onDestroy: stopping SipService...");
218 stopService(new Intent(this, SipService.class));
Emeric Vigier6119d782012-09-21 18:04:14 -0400219 serviceIsOn = false;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400220 super.onDestroy();
221 }
222
Emeric Vigier6119d782012-09-21 18:04:14 -0400223 /** Defines callbacks for service binding, passed to bindService() */
224 private ServiceConnection mConnection = new ServiceConnection() {
225
226 @Override
227 public void onServiceConnected(ComponentName className,
228 IBinder binder) {
229 service = ISipService.Stub.asInterface(binder);
230 mBound = true;
Alexandre Savard817dc502012-10-22 11:47:29 -0400231 mContactListFragment.setService(service);
232 mCallElementList.setService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400233 Log.d(TAG, "Service connected");
234 }
235
236 @Override
237 public void onServiceDisconnected(ComponentName arg0) {
238 mBound = false;
239 Log.d(TAG, "Service disconnected");
240 }
241 };
242
Emeric Vigier12d61d82012-09-19 15:08:18 -0400243 private void startSipService() {
244 Thread thread = new Thread("StartSFLphoneService") {
245 public void run() {
246 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
247 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
248 startService(sipServiceIntent);
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400249 serviceIsOn = true;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400250 };
251 };
252 try {
253 thread.start();
254 } catch (IllegalThreadStateException e) {
255 AlertDialog.Builder builder = new AlertDialog.Builder(this);
256 builder.setMessage("Cannot start SFLPhone SipService!");
257 AlertDialog alert = builder.create();
258 alert.show();
259 finish();
260 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400261 }
262
263 @Override
264 public boolean onOptionsItemSelected(MenuItem item) {
265 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400266 if(item.getItemId() != 0) {
267 // When the button is clicked, launch an activity through this intent
268 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400269
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400270 // Make it a subactivity so we know when it returns
271 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400272 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400273
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400274 return super.onOptionsItemSelected(item);
275 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400276
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400277 @Override
278 public boolean onCreateOptionsMenu(Menu menu)
279 {
280 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
281 return true;
282 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400283
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400284 @Override
285 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
286 {
287 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400288
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400289 @Override
290 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
291 {
292 // When the given tab is selected, switch to the corresponding page in the ViewPager.
293 mViewPager.setCurrentItem(tab.getPosition());
294 }
295
296 @Override
297 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
298 {
299 // Log.d(TAG, "onTabReselected");
300 }
301
302 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400303 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400304 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400305 buttonCall.startAnimation(animation);
306 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400307 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400308
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400309 /**
310 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
311 * one of the primary sections of the app.
312 */
313 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
314 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400315
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400316 public SectionsPagerAdapter(FragmentManager fm)
317 {
318 super(fm);
319 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400320
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400321 @Override
322 public Fragment getItem(int i)
323 {
324 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400325
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400326 switch (i) {
327 case 0:
Alexandre Savard817dc502012-10-22 11:47:29 -0400328 mContactListFragment = new ContactListFragment(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400329 fragment = mContactListFragment;
330 break;
331 case 1:
Alexandre Savard817dc502012-10-22 11:47:29 -0400332 mCallElementList = new CallElementList(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400333 SipCall.setCallElementList(mCallElementList);
334 fragment = mCallElementList;
335 break;
336 case 2:
337 fragment = new DummySectionFragment();
338 break;
339 case 3:
340 fragment = new ButtonSectionFragment();
341 Log.i(TAG, "getItem: fragment is " + fragment);
342 break;
343 default:
344 Log.e(TAG, "getItem: unknown tab position " + i);
345 return null;
346 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400347
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400348 Bundle args = new Bundle();
349 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
350 fragment.setArguments(args);
351 return fragment;
352 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400353
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400354 @Override
355 public int getCount()
356 {
357 return 4;
358 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400359
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400360 @Override
361 public CharSequence getPageTitle(int position)
362 {
363 switch (position) {
364 case 0:
365 return getString(R.string.title_section0).toUpperCase();
366 case 1:
367 return getString(R.string.title_section1).toUpperCase();
368 case 2:
369 return getString(R.string.title_section2).toUpperCase();
370 case 3:
371 return getString(R.string.title_section3).toUpperCase();
372 default:
373 Log.e(TAG, "getPageTitle: unknown tab position " + position);
374 break;
375 }
376 return null;
377 }
378 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400379
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400380 /**
381 * A dummy fragment representing a section of the app, but that simply
382 * displays dummy text.
383 */
384 public static class DummySectionFragment extends Fragment
385 {
386 public DummySectionFragment()
387 {
388 setRetainInstance(true);
389 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400390
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400391 public static final String ARG_SECTION_NUMBER = "section_number";
392
393 @Override
394 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
395 {
396 TextView textView = new TextView(getActivity());
397 textView.setGravity(Gravity.CENTER);
398 Bundle args = getArguments();
399 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
400 textView.setText("java sucks");
401 return textView;
402 }
403 }
404
405 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400406 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400407 {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400408 Log.i(TAG, "onClic from SFLPhoneHome");
Alexandre Savard2c50e692012-09-24 11:18:31 -0400409
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400410 buttonService = (Button) findViewById(R.id.buttonService);
Emeric Vigier6119d782012-09-21 18:04:14 -0400411
412 try {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400413 switch (view.getId()) {
414 case R.id.buttonCall:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400415 Log.i(TAG, "Processing new call action");
416 processingNewCallAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400417 break;
418 case R.id.buttonHangUp:
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400419 Log.i(TAG, "Processing hangup action");
420 processingHangUpAction();
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400421 break;
422 case R.id.buttonInit:
423 Log.i(TAG, "R.id.buttonInit");
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400424 // String audioPlugin = service.getCurrentAudioOutputPlugin();
425 HashMap<String, String> map = (HashMap<String, String>)service.getAccountDetails("Account:1345153770");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400426 break;
427 case R.id.buttonService:
428 if (!serviceIsOn) {
429 startService(new Intent(this, SipService.class));
430 serviceIsOn = true;
431 buttonService.setText("disable Service");
432 }
433 else {
434 stopService(new Intent(this, SipService.class));
435 serviceIsOn = false;
436 buttonService.setText("enable Service");
437 }
438 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400439 default:
440 Log.w(TAG, "unknown button " + view.getId());
441 break;
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400442 }
Emeric Vigier6119d782012-09-21 18:04:14 -0400443 } catch (RemoteException e) {
444 Log.e(TAG, "Cannot call service method", e);
445 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400446 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400447
448 public void processingNewCallAction() {
Alexandre Savard14323be2012-10-24 10:02:13 -0400449 /*
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400450 Log.d(TAG, "ProcessingNewCallAction()");
451 TextView textView = (TextView) findViewById(R.id.editAccountID);
452 String accountID = mAccountList.currentAccountID;
453 // String accountID = textView.getText().toString();
454 // buttonCall.setImageResource(R.drawable.ic_call);
455 EditText editText;
456 Random random = new Random();
457
458 try {
459
460 if (incomingCallID != "") {
461 Log.d(TAG, "Incoming Call Branch");
462 buttonCall.clearAnimation();
463 service.accept(incomingCallID);
464 callID = incomingCallID;
465 incomingCallID="";
466 callOnGoing = true;
467 buttonCall.setEnabled(false);
468 buttonHangup.setEnabled(true);
469 } else {
470 //if (callOnGoing == false) {
471 Log.d(TAG, "Outgoing Call Branch");
472 editText = (EditText) findViewById(R.id.editTo);
473 String to = "147"; // editText.getText().toString();
474 Log.d(TAG, "to string is " + to);
475 if (to == null) {
476 Log.e(TAG, "to string is " + to);
477 return;
478 }
479
480 callID = Integer.toString(random.nextInt());
481
482 Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
483 service.placeCall(accountID, callID, to);
484 callOnGoing = true;
485 buttonCall.setEnabled(false);
486 buttonHangup.setEnabled(true);
487 //}
488 }
489
490 } catch (RemoteException e) {
491 Log.e(TAG, "Cannot call service method", e);
492 }
Alexandre Savard14323be2012-10-24 10:02:13 -0400493 */
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400494 try {
495 String accountID = mAccountList.currentAccountID;
496 EditText editText = (EditText) findViewById(R.id.editTo);
497 String to = "147"; // editText.getText().toString();
498
499 Random random = new Random();
500 String callID = Integer.toString(random.nextInt());
501 SipCall.CallInfo info = new SipCall.CallInfo();
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400502
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400503 info.mCallID = callID;
504 info.mDisplayName = "Cool Guy!";
505 info.mPhone = to;
506 info.mEmail = "coolGuy@coolGuy.com";
507
508 SipCall call = CallList.getCallInstance(info);
Alexandre Savard73bc56f2012-10-25 13:35:54 -0400509 // call.launchCallActivity(this);
510 call.printCallInfo();
511 call.placeCall();
Alexandre Savardc58c0fd2012-10-25 10:44:08 -0400512
513 Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
514 service.placeCall(accountID, callID, to);
515 callOnGoing = true;
516 buttonCall.setEnabled(false);
517 buttonHangup.setEnabled(true);
518 } catch (RemoteException e) {
519 Log.e(TAG, "Cannot call service method", e);
520 }
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400521 }
522
523 public void processingHangUpAction() {
Alexandre Savard74c1cad2012-10-24 16:39:00 -0400524 try {
Alexandre Savard6b8d1df2012-10-23 16:44:43 -0400525 if (incomingCallID != "") {
526 buttonCall.clearAnimation();
527 Log.d(TAG, "service.refuse(" + incomingCallID + ");");
528 service.refuse(incomingCallID);
529 incomingCallID="";
530 buttonCall.setEnabled(true);
531 buttonHangup.setEnabled(true);
532 } else {
533 if (callOnGoing == true) {
534 Log.d(TAG, "service.hangUp(" + callID + ");");
535 service.hangUp(callID);
536 callOnGoing = false;
537 buttonCall.setEnabled(true);
538 buttonHangup.setEnabled(false);
539 }
540 }
541 } catch (RemoteException e) {
542 Log.e(TAG, "Cannot call service method", e);
543 }
544
545 buttonCall.setImageResource(R.drawable.ic_call);
546 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400547}