blob: 694d6ac12b13e65f5a5799e53af38923f7ed245c [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;
Emeric Vigier6119d782012-09-21 18:04:14 -040044import android.content.ServiceConnection;
Adrien Béraudffd32412012-08-07 18:39:23 -040045import android.os.Bundle;
Emeric Vigier383b2a22012-08-27 14:20:05 -040046import android.os.Handler;
Emeric Vigier6119d782012-09-21 18:04:14 -040047import android.os.IBinder;
Emeric Vigier383b2a22012-08-27 14:20:05 -040048import android.os.Message;
Emeric Vigier6119d782012-09-21 18:04:14 -040049import android.os.RemoteException;
Adrien Béraudffd32412012-08-07 18:39:23 -040050import android.support.v13.app.FragmentStatePagerAdapter;
51import android.support.v4.view.ViewPager;
Emeric Vigier05e894e2012-08-20 13:53:02 -040052import android.util.Log;
Adrien Béraudffd32412012-08-07 18:39:23 -040053import android.view.Gravity;
54import android.view.LayoutInflater;
55import android.view.Menu;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040056import android.view.MenuItem;
Adrien Béraudffd32412012-08-07 18:39:23 -040057import android.view.View;
Emeric Vigier05e894e2012-08-20 13:53:02 -040058import android.view.View.OnClickListener;
Adrien Béraudffd32412012-08-07 18:39:23 -040059import android.view.ViewGroup;
Emeric Vigiera6bdb702012-08-31 15:34:53 -040060import android.view.animation.AlphaAnimation;
61import android.view.animation.Animation;
62import android.view.animation.LinearInterpolator;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040063import android.widget.Button;
Emeric Vigierd5c17f52012-08-29 09:29:33 -040064import android.widget.EditText;
Emeric Vigiere89b48b2012-08-30 14:16:46 -040065import android.widget.ImageButton;
Adrien Béraudffd32412012-08-07 18:39:23 -040066import android.widget.TextView;
67
68import com.savoirfairelinux.sflphone.R;
Emeric Vigier6119d782012-09-21 18:04:14 -040069import com.savoirfairelinux.sflphone.service.ISipService;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040070import com.savoirfairelinux.sflphone.service.SipService;
Adrien Béraudffd32412012-08-07 18:39:23 -040071
Alexandre Savard7a902bc2012-10-04 16:32:35 -040072import java.util.HashMap;
73
Emeric Vigier62ca14d2012-08-24 11:05:09 -040074public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
Adrien Béraudffd32412012-08-07 18:39:23 -040075{
Alexandre Savard6c0584e2012-09-20 09:42:59 -040076 SectionsPagerAdapter mSectionsPagerAdapter;
77 static final String TAG = "SFLPhoneHome";
78 private ButtonSectionFragment buttonFragment;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040079 /* default callID */
80 static String callID = "007";
81 static boolean callOnGoing = false;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040082 static boolean serviceIsOn = false;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040083 private String incomingCallID = "";
84 private static final int REQUEST_CODE_PREFERENCES = 1;
85 ImageButton buttonCall, buttonHangup;
86 Button buttonService;
Emeric Vigier419ba7b2012-09-19 14:55:14 -040087 static Animation animation;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040088 ContactListFragment mContactListFragment;
89 CallElementList mCallElementList;
Emeric Vigier6119d782012-09-21 18:04:14 -040090 private boolean mBound = false;
91 private ISipService service;
Adrien Béraudffd32412012-08-07 18:39:23 -040092
Alexandre Savard6c0584e2012-09-20 09:42:59 -040093 /**
94 * The {@link ViewPager} that will host the section contents.
95 */
96 ViewPager mViewPager;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -040097
Alexandre Savard6c0584e2012-09-20 09:42:59 -040098 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 -040099
Alexandre Savard817dc502012-10-22 11:47:29 -0400100 // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
101
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400102 @Override
103 public void onCreate(Bundle savedInstanceState)
104 {
105 super.onCreate(savedInstanceState);
Alexandre Savard817dc502012-10-22 11:47:29 -0400106
107 if (!serviceIsOn) {
108 Log.i(TAG, "starting SipService");
109 startSipService();
110 }
111
112 // Bind to LocalService
113 if (!mBound) {
114 Log.i(TAG, "onStart: Binding service...");
115 Intent intent = new Intent(this, SipService.class);
116 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
117 }
118
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400119 setContentView(R.layout.activity_sflphone_home);
Adrien Béraudffd32412012-08-07 18:39:23 -0400120
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400121 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
Adrien Béraudffd32412012-08-07 18:39:23 -0400122
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400123 final ActionBar actionBar = getActionBar();
124 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
125 // final ActionBar actionBar = getActionBar();
Adrien Béraudffd32412012-08-07 18:39:23 -0400126
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400127 // Set up the ViewPager with the sections adapter.
128 mViewPager = (ViewPager) findViewById(R.id.pager);
129 mViewPager.setAdapter(mSectionsPagerAdapter);
Adrien Béraudffd32412012-08-07 18:39:23 -0400130
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400131 // When swiping between different sections, select the corresponding tab.
132 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
133 // Tab.
134 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
135 {
136 @Override
137 public void onPageSelected(int position)
138 {
139 actionBar.setSelectedNavigationItem(position);
140 }
141 });
Emeric Vigier383b2a22012-08-27 14:20:05 -0400142
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400143 // For each of the sections in the app, add a tab to the action bar.
144 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
145 // Create a tab with text corresponding to the page title defined by the adapter.
146 // Also specify this Activity object, which implements the TabListener interface, as the
147 // listener for when this tab is selected.
148 Log.i(TAG, "adding tab: " + i);
149 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
150 }
Emeric Vigier383b2a22012-08-27 14:20:05 -0400151
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400152 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
153 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400154
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400155 // Change alpha from fully visible to invisible
156 animation = new AlphaAnimation(1, 0);
157 // duration - half a second
158 animation.setDuration(500);
159 // do not alter animation rate
160 animation.setInterpolator(new LinearInterpolator());
161 // Repeat animation infinitely
162 animation.setRepeatCount(Animation.INFINITE);
163 // Reverse
164 animation.setRepeatMode(Animation.REVERSE);
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400165 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400166
Emeric Vigier12d61d82012-09-19 15:08:18 -0400167 @Override
168 protected void onStart() {
169 Log.i(TAG, "onStart");
170 super.onStart();
171 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400172
Emeric Vigier6119d782012-09-21 18:04:14 -0400173 /* user gets back to the activity, e.g. through task manager */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400174 @Override
175 protected void onRestart() {
176 super.onRestart();
177 }
178
Emeric Vigier6119d782012-09-21 18:04:14 -0400179 /* activity gets back to the foreground and user input */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400180 @Override
181 protected void onResume() {
182 Log.i(TAG, "onResume");
183 super.onResume();
Emeric Vigier12d61d82012-09-19 15:08:18 -0400184 }
185
Emeric Vigier6119d782012-09-21 18:04:14 -0400186 /* activity no more in foreground */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400187 @Override
188 protected void onPause() {
Emeric Vigier12d61d82012-09-19 15:08:18 -0400189 super.onPause();
190 }
191
Emeric Vigier6119d782012-09-21 18:04:14 -0400192 /* activity is no longer visible */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400193 @Override
194 protected void onStop() {
195 super.onStop();
Alexandre Savard817dc502012-10-22 11:47:29 -0400196 }
197
198 /* activity finishes itself or is being killed by the system */
199 @Override
200 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400201 /* stop the service, if no other bound user, no need to check if it is running */
202 if (mBound) {
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400203 Log.i(TAG, "onStop: Unbinding service...");
Emeric Vigier6119d782012-09-21 18:04:14 -0400204 unbindService(mConnection);
205 mBound = false;
206 }
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400207 Log.i(TAG, "onDestroy: stopping SipService...");
208 stopService(new Intent(this, SipService.class));
Emeric Vigier6119d782012-09-21 18:04:14 -0400209 serviceIsOn = false;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400210 super.onDestroy();
211 }
212
Emeric Vigier6119d782012-09-21 18:04:14 -0400213 /** Defines callbacks for service binding, passed to bindService() */
214 private ServiceConnection mConnection = new ServiceConnection() {
215
216 @Override
217 public void onServiceConnected(ComponentName className,
218 IBinder binder) {
219 service = ISipService.Stub.asInterface(binder);
220 mBound = true;
Alexandre Savard817dc502012-10-22 11:47:29 -0400221 mContactListFragment.setService(service);
222 mCallElementList.setService(service);
Emeric Vigier6119d782012-09-21 18:04:14 -0400223 Log.d(TAG, "Service connected");
224 }
225
226 @Override
227 public void onServiceDisconnected(ComponentName arg0) {
228 mBound = false;
229 Log.d(TAG, "Service disconnected");
230 }
231 };
232
Emeric Vigier12d61d82012-09-19 15:08:18 -0400233 private void startSipService() {
234 Thread thread = new Thread("StartSFLphoneService") {
235 public void run() {
236 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
237 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
238 startService(sipServiceIntent);
Emeric Vigierfae29bd2012-09-24 11:32:03 -0400239 serviceIsOn = true;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400240 };
241 };
242 try {
243 thread.start();
244 } catch (IllegalThreadStateException e) {
245 AlertDialog.Builder builder = new AlertDialog.Builder(this);
246 builder.setMessage("Cannot start SFLPhone SipService!");
247 AlertDialog alert = builder.create();
248 alert.show();
249 finish();
250 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400251 }
252
253 @Override
254 public boolean onOptionsItemSelected(MenuItem item) {
255 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400256 if(item.getItemId() != 0) {
257 // When the button is clicked, launch an activity through this intent
258 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400259
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400260 // Make it a subactivity so we know when it returns
261 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400262 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400263
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400264 return super.onOptionsItemSelected(item);
265 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400266
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400267 @Override
268 public boolean onCreateOptionsMenu(Menu menu)
269 {
270 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
271 return true;
272 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400273
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400274 @Override
275 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
276 {
277 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400278
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400279 @Override
280 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
281 {
282 // When the given tab is selected, switch to the corresponding page in the ViewPager.
283 mViewPager.setCurrentItem(tab.getPosition());
284 }
285
286 @Override
287 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
288 {
289 // Log.d(TAG, "onTabReselected");
290 }
291
292 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400293 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400294 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400295 buttonCall.startAnimation(animation);
296 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400297 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400298
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400299 /**
300 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
301 * one of the primary sections of the app.
302 */
303 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
304 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400305
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400306 public SectionsPagerAdapter(FragmentManager fm)
307 {
308 super(fm);
309 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400310
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400311 @Override
312 public Fragment getItem(int i)
313 {
314 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400315
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400316 switch (i) {
317 case 0:
Alexandre Savard817dc502012-10-22 11:47:29 -0400318 mContactListFragment = new ContactListFragment(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400319 fragment = mContactListFragment;
320 break;
321 case 1:
Alexandre Savard817dc502012-10-22 11:47:29 -0400322 mCallElementList = new CallElementList(service);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400323 SipCall.setCallElementList(mCallElementList);
324 fragment = mCallElementList;
325 break;
326 case 2:
327 fragment = new DummySectionFragment();
328 break;
329 case 3:
330 fragment = new ButtonSectionFragment();
331 Log.i(TAG, "getItem: fragment is " + fragment);
332 break;
333 default:
334 Log.e(TAG, "getItem: unknown tab position " + i);
335 return null;
336 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400337
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400338 Bundle args = new Bundle();
339 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
340 fragment.setArguments(args);
341 return fragment;
342 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400343
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400344 @Override
345 public int getCount()
346 {
347 return 4;
348 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400349
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400350 @Override
351 public CharSequence getPageTitle(int position)
352 {
353 switch (position) {
354 case 0:
355 return getString(R.string.title_section0).toUpperCase();
356 case 1:
357 return getString(R.string.title_section1).toUpperCase();
358 case 2:
359 return getString(R.string.title_section2).toUpperCase();
360 case 3:
361 return getString(R.string.title_section3).toUpperCase();
362 default:
363 Log.e(TAG, "getPageTitle: unknown tab position " + position);
364 break;
365 }
366 return null;
367 }
368 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400369
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400370 /**
371 * A dummy fragment representing a section of the app, but that simply
372 * displays dummy text.
373 */
374 public static class DummySectionFragment extends Fragment
375 {
376 public DummySectionFragment()
377 {
378 setRetainInstance(true);
379 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400380
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400381 public static final String ARG_SECTION_NUMBER = "section_number";
382
383 @Override
384 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
385 {
386 TextView textView = new TextView(getActivity());
387 textView.setGravity(Gravity.CENTER);
388 Bundle args = getArguments();
389 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
390 textView.setText("java sucks");
391 return textView;
392 }
393 }
394
395 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400396 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400397 {
Alexandre Savard2c50e692012-09-24 11:18:31 -0400398 Log.i("SFLPhoneHome", "onClic from SFLPhoneHome");
399
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400400 buttonService = (Button) findViewById(R.id.buttonService);
Emeric Vigier6119d782012-09-21 18:04:14 -0400401
402 try {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400403 switch (view.getId()) {
404 case R.id.buttonCall:
405 TextView textView = (TextView) findViewById(R.id.editAccountID);
406 String accountID = textView.getText().toString();
407 EditText editText;
408 Random random = new Random();
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400409
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400410 if (incomingCallID != "") {
411 buttonCall.clearAnimation();
412 service.accept(incomingCallID);
413 callID = incomingCallID;
414 incomingCallID="";
415 callOnGoing = true;
416 buttonCall.setEnabled(false);
417 buttonHangup.setEnabled(true);
418 } else {
419 if (callOnGoing == false) {
420 editText = (EditText) findViewById(R.id.editTo);
421 String to = editText.getText().toString();
422 if (to == null) {
423 Log.e(TAG, "to string is " + to);
424 break;
425 }
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400426
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400427 callID = Integer.toString(random.nextInt());
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400428
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400429 Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
430 service.placeCall(accountID, callID, to);
431 callOnGoing = true;
432 buttonCall.setEnabled(false);
433 buttonHangup.setEnabled(true);
434 }
435 }
436 break;
437 case R.id.buttonHangUp:
438 if (incomingCallID != "") {
439 buttonCall.clearAnimation();
440 Log.d(TAG, "service.refuse(" + incomingCallID + ");");
441 service.refuse(incomingCallID);
442 incomingCallID="";
443 buttonCall.setEnabled(true);
444 buttonHangup.setEnabled(true);
445 } else {
446 if (callOnGoing == true) {
447 Log.d(TAG, "service.hangUp(" + callID + ");");
448 service.hangUp(callID);
449 callOnGoing = false;
450 buttonCall.setEnabled(true);
451 buttonHangup.setEnabled(false);
452 }
453 }
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400454
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400455 buttonCall.setImageResource(R.drawable.ic_call);
456 break;
457 case R.id.buttonInit:
458 Log.i(TAG, "R.id.buttonInit");
Alexandre Savard7a902bc2012-10-04 16:32:35 -0400459 // String audioPlugin = service.getCurrentAudioOutputPlugin();
460 HashMap<String, String> map = (HashMap<String, String>)service.getAccountDetails("Account:1345153770");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400461 break;
462 case R.id.buttonService:
463 if (!serviceIsOn) {
464 startService(new Intent(this, SipService.class));
465 serviceIsOn = true;
466 buttonService.setText("disable Service");
467 }
468 else {
469 stopService(new Intent(this, SipService.class));
470 serviceIsOn = false;
471 buttonService.setText("enable Service");
472 }
473 break;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400474 default:
475 Log.w(TAG, "unknown button " + view.getId());
476 break;
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400477 }
Emeric Vigier6119d782012-09-21 18:04:14 -0400478 } catch (RemoteException e) {
479 Log.e(TAG, "Cannot call service method", e);
480 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400481 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400482}