blob: 24a9bff3134ad5bc14a1ce333561243c0e93392d [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
Emeric Vigier62ca14d2012-08-24 11:05:09 -040072public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
Adrien Béraudffd32412012-08-07 18:39:23 -040073{
Alexandre Savard6c0584e2012-09-20 09:42:59 -040074 SectionsPagerAdapter mSectionsPagerAdapter;
75 static final String TAG = "SFLPhoneHome";
76 private ButtonSectionFragment buttonFragment;
77 Handler callbackHandler;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040078 /* default callID */
79 static String callID = "007";
80 static boolean callOnGoing = false;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040081 static boolean serviceIsOn = false;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040082 private String incomingCallID = "";
83 private static final int REQUEST_CODE_PREFERENCES = 1;
84 ImageButton buttonCall, buttonHangup;
85 Button buttonService;
Emeric Vigier419ba7b2012-09-19 14:55:14 -040086 static Animation animation;
Alexandre Savard6c0584e2012-09-20 09:42:59 -040087 ContactListFragment mContactListFragment;
88 CallElementList mCallElementList;
Emeric Vigier6119d782012-09-21 18:04:14 -040089 private boolean mBound = false;
90 private ISipService service;
Adrien Béraudffd32412012-08-07 18:39:23 -040091
Alexandre Savard6c0584e2012-09-20 09:42:59 -040092 /**
93 * The {@link ViewPager} that will host the section contents.
94 */
95 ViewPager mViewPager;
Emeric Vigierbbde1ae2012-09-21 18:13:56 -040096
Alexandre Savard6c0584e2012-09-20 09:42:59 -040097 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 -040098
Alexandre Savard6c0584e2012-09-20 09:42:59 -040099 @Override
100 public void onCreate(Bundle savedInstanceState)
101 {
102 super.onCreate(savedInstanceState);
103 setContentView(R.layout.activity_sflphone_home);
Adrien Béraudffd32412012-08-07 18:39:23 -0400104
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400105 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
Adrien Béraudffd32412012-08-07 18:39:23 -0400106
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400107 final ActionBar actionBar = getActionBar();
108 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
109 // final ActionBar actionBar = getActionBar();
Adrien Béraudffd32412012-08-07 18:39:23 -0400110
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400111 // Set up the ViewPager with the sections adapter.
112 mViewPager = (ViewPager) findViewById(R.id.pager);
113 mViewPager.setAdapter(mSectionsPagerAdapter);
Adrien Béraudffd32412012-08-07 18:39:23 -0400114
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400115 // When swiping between different sections, select the corresponding tab.
116 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
117 // Tab.
118 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
119 {
120 @Override
121 public void onPageSelected(int position)
122 {
123 actionBar.setSelectedNavigationItem(position);
124 }
125 });
Emeric Vigier383b2a22012-08-27 14:20:05 -0400126
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400127 // For each of the sections in the app, add a tab to the action bar.
128 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
129 // Create a tab with text corresponding to the page title defined by the adapter.
130 // Also specify this Activity object, which implements the TabListener interface, as the
131 // listener for when this tab is selected.
132 Log.i(TAG, "adding tab: " + i);
133 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
134 }
Emeric Vigier383b2a22012-08-27 14:20:05 -0400135
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400136 // FIXME
137 callbackHandler = new Handler() {
138 public void handleMessage(Message msg) {
139 Bundle b = msg.getData();
140 TextView callVoidText;
Emeric Vigier383b2a22012-08-27 14:20:05 -0400141
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400142 Log.i(TAG, "handleMessage");
Emeric Vigier383b2a22012-08-27 14:20:05 -0400143
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400144 callVoidText = buttonFragment.getcallVoidText();
145 if (callVoidText == null)
146 Log.e(TAG, "SFLPhoneHome: callVoidText is " + callVoidText);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400147 callVoidText.setText(b.getString("callback_string"));
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400148
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400149 Log.i(TAG, "handleMessage: " + b.getString("callback_string"));
150 }
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400151 };
152
153 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
154 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400155
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400156 // Change alpha from fully visible to invisible
157 animation = new AlphaAnimation(1, 0);
158 // duration - half a second
159 animation.setDuration(500);
160 // do not alter animation rate
161 animation.setInterpolator(new LinearInterpolator());
162 // Repeat animation infinitely
163 animation.setRepeatCount(Animation.INFINITE);
164 // Reverse
165 animation.setRepeatMode(Animation.REVERSE);
Adrien Béraudffd32412012-08-07 18:39:23 -0400166
Emeric Vigier6119d782012-09-21 18:04:14 -0400167 /* startService() can be called any number of times without harm */
168 Log.i(TAG, "starting SipService");
169 startSipService();
Alexandre Savard6c0584e2012-09-20 09:42:59 -0400170 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400171
Emeric Vigier12d61d82012-09-19 15:08:18 -0400172 @Override
173 protected void onStart() {
174 Log.i(TAG, "onStart");
175 super.onStart();
Emeric Vigier6119d782012-09-21 18:04:14 -0400176 // Bind to LocalService
177 if (!mBound) {
178 Log.d(TAG, "Binding service...");
179 Intent intent = new Intent(this, SipService.class);
180 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
181 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400182 }
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();
Emeric Vigier6119d782012-09-21 18:04:14 -0400207 /* stop the service, if no other bound user, no need to check if it is running */
208 if (mBound) {
209 Log.d(TAG, "Unbinding service...");
210 unbindService(mConnection);
211 mBound = false;
212 }
Emeric Vigier12d61d82012-09-19 15:08:18 -0400213 }
214
Emeric Vigier6119d782012-09-21 18:04:14 -0400215 /* activity finishes itself or is being killed by the system */
Emeric Vigier12d61d82012-09-19 15:08:18 -0400216 @Override
217 protected void onDestroy() {
Emeric Vigier6119d782012-09-21 18:04:14 -0400218 serviceIsOn = false;
Emeric Vigier12d61d82012-09-19 15:08:18 -0400219 super.onDestroy();
220 }
221
Emeric Vigier6119d782012-09-21 18:04:14 -0400222 /** Defines callbacks for service binding, passed to bindService() */
223 private ServiceConnection mConnection = new ServiceConnection() {
224
225 @Override
226 public void onServiceConnected(ComponentName className,
227 IBinder binder) {
228 service = ISipService.Stub.asInterface(binder);
229 mBound = true;
230 Log.d(TAG, "Service connected");
231 }
232
233 @Override
234 public void onServiceDisconnected(ComponentName arg0) {
235 mBound = false;
236 Log.d(TAG, "Service disconnected");
237 }
238 };
239
Emeric Vigier12d61d82012-09-19 15:08:18 -0400240 private void startSipService() {
241 Thread thread = new Thread("StartSFLphoneService") {
242 public void run() {
243 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
244 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
245 startService(sipServiceIntent);
246 };
247 };
248 try {
249 thread.start();
250 } catch (IllegalThreadStateException e) {
251 AlertDialog.Builder builder = new AlertDialog.Builder(this);
252 builder.setMessage("Cannot start SFLPhone SipService!");
253 AlertDialog alert = builder.create();
254 alert.show();
255 finish();
256 }
257
258 // FIXME
259 callbackHandler = new Handler() {
260 public void handleMessage(Message msg) {
261 Bundle b = msg.getData();
262 TextView callVoidText;
263
264 Log.i(TAG, "handleMessage");
265
266 callVoidText = buttonFragment.getcallVoidText();
267 if (callVoidText == null)
268 Log.e(TAG, "SFLPhoneHome: callVoidText is " + callVoidText);
269 callVoidText.setText(b.getString("callback_string"));
270
271 Log.i(TAG, "handleMessage: " + b.getString("callback_string"));
272 }
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
315 public void setIncomingCallID(String accountID, String callID, String from) {
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400316 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400317 incomingCallID = callID;
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400318 buttonCall.startAnimation(animation);
319 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400320 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400321
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400322 /**
323 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
324 * one of the primary sections of the app.
325 */
326 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
327 {
Adrien Béraudffd32412012-08-07 18:39:23 -0400328
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400329 public SectionsPagerAdapter(FragmentManager fm)
330 {
331 super(fm);
332 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400333
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400334 @Override
335 public Fragment getItem(int i)
336 {
337 Fragment fragment;
Adrien Béraudffd32412012-08-07 18:39:23 -0400338
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400339 switch (i) {
340 case 0:
341 mContactListFragment = new ContactListFragment();
342 fragment = mContactListFragment;
343 break;
344 case 1:
345 mCallElementList = new CallElementList();
346 SipCall.setCallElementList(mCallElementList);
347 fragment = mCallElementList;
348 break;
349 case 2:
350 fragment = new DummySectionFragment();
351 break;
352 case 3:
353 fragment = new ButtonSectionFragment();
354 Log.i(TAG, "getItem: fragment is " + fragment);
355 break;
356 default:
357 Log.e(TAG, "getItem: unknown tab position " + i);
358 return null;
359 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400360
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400361 Bundle args = new Bundle();
362 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
363 fragment.setArguments(args);
364 return fragment;
365 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400366
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400367 @Override
368 public int getCount()
369 {
370 return 4;
371 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400372
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400373 @Override
374 public CharSequence getPageTitle(int position)
375 {
376 switch (position) {
377 case 0:
378 return getString(R.string.title_section0).toUpperCase();
379 case 1:
380 return getString(R.string.title_section1).toUpperCase();
381 case 2:
382 return getString(R.string.title_section2).toUpperCase();
383 case 3:
384 return getString(R.string.title_section3).toUpperCase();
385 default:
386 Log.e(TAG, "getPageTitle: unknown tab position " + position);
387 break;
388 }
389 return null;
390 }
391 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400392
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400393 /**
394 * A dummy fragment representing a section of the app, but that simply
395 * displays dummy text.
396 */
397 public static class DummySectionFragment extends Fragment
398 {
399 public DummySectionFragment()
400 {
401 setRetainInstance(true);
402 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400403
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400404 public static final String ARG_SECTION_NUMBER = "section_number";
405
406 @Override
407 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
408 {
409 TextView textView = new TextView(getActivity());
410 textView.setGravity(Gravity.CENTER);
411 Bundle args = getArguments();
412 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
413 textView.setText("java sucks");
414 return textView;
415 }
416 }
417
418 @Override
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400419 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400420 {
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400421 buttonService = (Button) findViewById(R.id.buttonService);
Emeric Vigier6119d782012-09-21 18:04:14 -0400422
423 try {
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400424 switch (view.getId()) {
425 case R.id.buttonCall:
426 TextView textView = (TextView) findViewById(R.id.editAccountID);
427 String accountID = textView.getText().toString();
428 EditText editText;
429 Random random = new Random();
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400430
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400431 if (incomingCallID != "") {
432 buttonCall.clearAnimation();
433 service.accept(incomingCallID);
434 callID = incomingCallID;
435 incomingCallID="";
436 callOnGoing = true;
437 buttonCall.setEnabled(false);
438 buttonHangup.setEnabled(true);
439 } else {
440 if (callOnGoing == false) {
441 editText = (EditText) findViewById(R.id.editTo);
442 String to = editText.getText().toString();
443 if (to == null) {
444 Log.e(TAG, "to string is " + to);
445 break;
446 }
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400447
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400448 callID = Integer.toString(random.nextInt());
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400449
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400450 Log.d(TAG, "service.placeCall(" + accountID + ", " + callID + ", " + to + ");");
451 service.placeCall(accountID, callID, to);
452 callOnGoing = true;
453 buttonCall.setEnabled(false);
454 buttonHangup.setEnabled(true);
455 }
456 }
457 break;
458 case R.id.buttonHangUp:
459 if (incomingCallID != "") {
460 buttonCall.clearAnimation();
461 Log.d(TAG, "service.refuse(" + incomingCallID + ");");
462 service.refuse(incomingCallID);
463 incomingCallID="";
464 buttonCall.setEnabled(true);
465 buttonHangup.setEnabled(true);
466 } else {
467 if (callOnGoing == true) {
468 Log.d(TAG, "service.hangUp(" + callID + ");");
469 service.hangUp(callID);
470 callOnGoing = false;
471 buttonCall.setEnabled(true);
472 buttonHangup.setEnabled(false);
473 }
474 }
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400475
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400476 buttonCall.setImageResource(R.drawable.ic_call);
477 break;
478 case R.id.buttonInit:
479 Log.i(TAG, "R.id.buttonInit");
480 break;
481 case R.id.buttonService:
482 if (!serviceIsOn) {
483 startService(new Intent(this, SipService.class));
484 serviceIsOn = true;
485 buttonService.setText("disable Service");
486 }
487 else {
488 stopService(new Intent(this, SipService.class));
489 serviceIsOn = false;
490 buttonService.setText("enable Service");
491 }
492 break;
493 case R.id.buttonCallVoid:
494 Manager.callVoid();
495 break;
496 case R.id.buttonGetNewData:
497 Data d = Manager.getNewData(42, "foo");
498 if (d != null)
499 buttonFragment.getNewDataText().setText("getNewData(42, \"foo\") == Data(" + d.i + ", \"" + d.s + "\")");
500 break;
501 case R.id.buttonGetDataString:
502 Data daita = new Data(43, "bar");
503 String s = Manager.getDataString(daita);
504 if (s != "") {
505 buttonFragment.getDataStringText().setText("getDataString(Data(43, \"bar\")) == \"" + s + "\"");
506 }
507 break;
508 default:
509 Log.w(TAG, "unknown button " + view.getId());
510 break;
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400511 }
Emeric Vigier6119d782012-09-21 18:04:14 -0400512 } catch (RemoteException e) {
513 Log.e(TAG, "Cannot call service method", e);
514 }
Emeric Vigierbbde1ae2012-09-21 18:13:56 -0400515 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400516}