blob: aebf60eca4194e3206bb874a1a91138a8f5a82fd [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;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040041import android.content.Intent;
Emeric Vigier7a255aa2012-08-29 09:49:18 -040042import android.content.pm.PackageInfo;
43import android.content.pm.PackageManager;
44import android.content.pm.PackageManager.NameNotFoundException;
Adrien Béraudffd32412012-08-07 18:39:23 -040045import android.os.Bundle;
Emeric Vigier383b2a22012-08-27 14:20:05 -040046import android.os.Handler;
47import android.os.Message;
Adrien Béraudffd32412012-08-07 18:39:23 -040048import android.support.v13.app.FragmentStatePagerAdapter;
49import android.support.v4.view.ViewPager;
Emeric Vigier05e894e2012-08-20 13:53:02 -040050import android.util.Log;
Adrien Béraudffd32412012-08-07 18:39:23 -040051import android.view.Gravity;
52import android.view.LayoutInflater;
53import android.view.Menu;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040054import android.view.MenuItem;
Adrien Béraudffd32412012-08-07 18:39:23 -040055import android.view.View;
Emeric Vigier05e894e2012-08-20 13:53:02 -040056import android.view.View.OnClickListener;
Adrien Béraudffd32412012-08-07 18:39:23 -040057import android.view.ViewGroup;
Emeric Vigiera6bdb702012-08-31 15:34:53 -040058import android.view.animation.AlphaAnimation;
59import android.view.animation.Animation;
60import android.view.animation.LinearInterpolator;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040061import android.widget.Button;
Emeric Vigierd5c17f52012-08-29 09:29:33 -040062import android.widget.EditText;
Emeric Vigiere89b48b2012-08-30 14:16:46 -040063import android.widget.ImageButton;
Adrien Béraudffd32412012-08-07 18:39:23 -040064import android.widget.TextView;
65
66import com.savoirfairelinux.sflphone.R;
Emeric Vigier12d61d82012-09-19 15:08:18 -040067import com.savoirfairelinux.sflphone.service.ServiceConstants;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040068import com.savoirfairelinux.sflphone.service.SipService;
Adrien Béraudffd32412012-08-07 18:39:23 -040069
Emeric Vigier62ca14d2012-08-24 11:05:09 -040070public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener
Adrien Béraudffd32412012-08-07 18:39:23 -040071{
72 SectionsPagerAdapter mSectionsPagerAdapter;
Emeric Vigier62ca14d2012-08-24 11:05:09 -040073 static final String TAG = "SFLPhoneHome";
Emeric Vigiera6bdb702012-08-31 15:34:53 -040074 private ButtonSectionFragment buttonFragment;
Emeric Vigier383b2a22012-08-27 14:20:05 -040075 Handler callbackHandler;
Emeric Vigier9701e032012-09-12 12:38:01 -040076 private Manager manager;
Emeric Vigier78a53e92012-08-29 18:15:34 -040077 /* default callID */
78 static String callID = "007";
Emeric Vigiere89b48b2012-08-30 14:16:46 -040079 static boolean callOnGoing = false;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040080 static boolean serviceIsOn = false;
Emeric Vigiera6bdb702012-08-31 15:34:53 -040081 private String incomingCallID = "";
Alexandre Savard1bcaf532012-09-05 16:23:02 -040082 private static final int REQUEST_CODE_PREFERENCES = 1;
Emeric Vigier090ab602012-09-17 11:09:46 -040083 ImageButton buttonCall, buttonHangup;
Emeric Vigiereaf2c492012-09-19 14:38:20 -040084 Button buttonService;
Emeric Vigier419ba7b2012-09-19 14:55:14 -040085 static Animation animation;
Adrien Béraudffd32412012-08-07 18:39:23 -040086
87 /**
88 * The {@link ViewPager} that will host the section contents.
89 */
90 ViewPager mViewPager;
91
Alexandre Savarda04c5202012-09-18 17:19:53 -040092 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 -040093
94 @Override
95 public void onCreate(Bundle savedInstanceState)
96 {
97 super.onCreate(savedInstanceState);
98 setContentView(R.layout.activity_sflphone_home);
99
100 mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
101
102 final ActionBar actionBar = getActionBar();
103 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400104 // final ActionBar actionBar = getActionBar();
Adrien Béraudffd32412012-08-07 18:39:23 -0400105
106 // Set up the ViewPager with the sections adapter.
107 mViewPager = (ViewPager) findViewById(R.id.pager);
108 mViewPager.setAdapter(mSectionsPagerAdapter);
109
110 // When swiping between different sections, select the corresponding tab.
111 // We can also use ActionBar.Tab#select() to do this if we have a reference to the
112 // Tab.
113 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
114 {
115 @Override
116 public void onPageSelected(int position)
117 {
118 actionBar.setSelectedNavigationItem(position);
119 }
120 });
121
122 // For each of the sections in the app, add a tab to the action bar.
123 for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
124 // Create a tab with text corresponding to the page title defined by the adapter.
125 // Also specify this Activity object, which implements the TabListener interface, as the
126 // listener for when this tab is selected.
Alexandre Savarda04c5202012-09-18 17:19:53 -0400127 Log.i(TAG, "adding tab: " + i);
Adrien Béraudffd32412012-08-07 18:39:23 -0400128 actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
129 }
Emeric Vigier383b2a22012-08-27 14:20:05 -0400130
131 // FIXME
132 callbackHandler = new Handler() {
133 public void handleMessage(Message msg) {
134 Bundle b = msg.getData();
135 TextView callVoidText;
136
Emeric Vigierc411ce32012-08-29 09:28:28 -0400137 Log.i(TAG, "handleMessage");
Emeric Vigier383b2a22012-08-27 14:20:05 -0400138
139 callVoidText = buttonFragment.getcallVoidText();
140 if (callVoidText == null)
141 Log.e(TAG, "SFLPhoneHome: callVoidText is " + callVoidText);
142 callVoidText.setText(b.getString("callback_string"));
143
Emeric Vigierc411ce32012-08-29 09:28:28 -0400144 Log.i(TAG, "handleMessage: " + b.getString("callback_string"));
Emeric Vigier383b2a22012-08-27 14:20:05 -0400145 }
146 };
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400147
148 buttonCall = (ImageButton) findViewById(R.id.buttonCall);
149 buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp);
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400150
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400151 // Change alpha from fully visible to invisible
152 animation = new AlphaAnimation(1, 0);
153 // duration - half a second
154 animation.setDuration(500);
155 // do not alter animation rate
156 animation.setInterpolator(new LinearInterpolator());
157 // Repeat animation infinitely
158 animation.setRepeatCount(Animation.INFINITE);
159 // Reverse
160 animation.setRepeatMode(Animation.REVERSE);
Adrien Béraudffd32412012-08-07 18:39:23 -0400161 }
162
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400163 // FIXME
164 static {
165 System.loadLibrary("gnustl_shared");
166 System.loadLibrary("expat");
167 System.loadLibrary("yaml");
168 System.loadLibrary("ccgnu2");
169 System.loadLibrary("crypto");
170 System.loadLibrary("ssl");
171 System.loadLibrary("ccrtp1");
172 System.loadLibrary("dbus");
173 System.loadLibrary("dbus-c++-1");
174 System.loadLibrary("samplerate");
175 System.loadLibrary("codec_ulaw");
176 System.loadLibrary("codec_alaw");
177 System.loadLibrary("speexresampler");
178 System.loadLibrary("sflphone");
179 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400180
Emeric Vigier12d61d82012-09-19 15:08:18 -0400181 @Override
182 protected void onStart() {
183 Log.i(TAG, "onStart");
184 super.onStart();
185 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400186
Emeric Vigier12d61d82012-09-19 15:08:18 -0400187 @Override
188 protected void onRestart() {
189 super.onRestart();
190 }
191
192 @Override
193 protected void onResume() {
194 Log.i(TAG, "onResume");
195 super.onResume();
196
197 Log.i(TAG, "starting SipService");
198 startSipService();
199 }
200
201 @Override
202 protected void onPause() {
203 /* stop the service, no need to check if it is running */
204 stopService(new Intent(this, SipService.class));
205 serviceIsOn = false;
206 super.onPause();
207 }
208
209 @Override
210 protected void onStop() {
211 super.onStop();
212 }
213
214 @Override
215 protected void onDestroy() {
216 super.onDestroy();
217 }
218
219 private void startSipService() {
220 Thread thread = new Thread("StartSFLphoneService") {
221 public void run() {
222 Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class);
223 //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class));
224 startService(sipServiceIntent);
225 };
226 };
227 try {
228 thread.start();
229 } catch (IllegalThreadStateException e) {
230 AlertDialog.Builder builder = new AlertDialog.Builder(this);
231 builder.setMessage("Cannot start SFLPhone SipService!");
232 AlertDialog alert = builder.create();
233 alert.show();
234 finish();
235 }
236
237 // FIXME
238 callbackHandler = new Handler() {
239 public void handleMessage(Message msg) {
240 Bundle b = msg.getData();
241 TextView callVoidText;
242
243 Log.i(TAG, "handleMessage");
244
245 callVoidText = buttonFragment.getcallVoidText();
246 if (callVoidText == null)
247 Log.e(TAG, "SFLPhoneHome: callVoidText is " + callVoidText);
248 callVoidText.setText(b.getString("callback_string"));
249
250 Log.i(TAG, "handleMessage: " + b.getString("callback_string"));
251 }
252 };
253
254 manager = new Manager(callbackHandler);
255 Log.i(TAG, "ManagerImpl::instance() = " + Manager.managerImpl);
256 Manager.setActivity(this);
257 /* set static AppPath before calling manager.init */
258 Manager.managerImpl.setPath(getAppPath());
259 Log.i(TAG, "manager created with callbackHandler " + callbackHandler);
260 }
261
262 @Override
263 public boolean onOptionsItemSelected(MenuItem item) {
264 Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId());
Alexandre Savardebc94432012-09-13 14:30:55 -0400265 if(item.getItemId() != 0) {
266 // When the button is clicked, launch an activity through this intent
267 Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400268
Alexandre Savardebc94432012-09-13 14:30:55 -0400269 // Make it a subactivity so we know when it returns
270 startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES);
271 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400272
273 return super.onOptionsItemSelected(item);
274 }
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400275
Adrien Béraudffd32412012-08-07 18:39:23 -0400276 @Override
277 public boolean onCreateOptionsMenu(Menu menu)
278 {
279 getMenuInflater().inflate(R.menu.activity_sflphone_home, menu);
280 return true;
281 }
282
283 @Override
284 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
285 {
286 }
287
288 @Override
289 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
290 {
291 // When the given tab is selected, switch to the corresponding page in the ViewPager.
292 mViewPager.setCurrentItem(tab.getPosition());
293 }
294
295 @Override
296 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
297 {
Emeric Vigier05e894e2012-08-20 13:53:02 -0400298// Log.d(TAG, "onTabReselected");
Adrien Béraudffd32412012-08-07 18:39:23 -0400299 }
300
Emeric Vigier419ba7b2012-09-19 14:55:14 -0400301 public void setIncomingCallID(String accountID, String callID, String from) {
302 Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")");
303 incomingCallID = callID;
304 buttonCall.startAnimation(animation);
305 buttonCall.setImageResource(R.drawable.ic_incomingcall);
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400306 }
307
Adrien Béraudffd32412012-08-07 18:39:23 -0400308 /**
309 * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
310 * one of the primary sections of the app.
311 */
312 public class SectionsPagerAdapter extends FragmentStatePagerAdapter
313 {
314
315 public SectionsPagerAdapter(FragmentManager fm)
316 {
317 super(fm);
318 }
319
320 @Override
321 public Fragment getItem(int i)
322 {
323 Fragment fragment;
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400324
Emeric Vigier05e894e2012-08-20 13:53:02 -0400325 switch (i) {
Alexandre Savarda04c5202012-09-18 17:19:53 -0400326 case 0:
Alexandre Savard23240c12012-09-19 18:23:44 -0400327 fragment = new ContactListFragment(manager);
Alexandre Savarda04c5202012-09-18 17:19:53 -0400328 break;
329 case 1:
Adrien Béraudffd32412012-08-07 18:39:23 -0400330 fragment = new CallElementList();
Emeric Vigier05e894e2012-08-20 13:53:02 -0400331 break;
Alexandre Savarda04c5202012-09-18 17:19:53 -0400332 case 2:
Adrien Béraudffd32412012-08-07 18:39:23 -0400333 fragment = new DummySectionFragment();
Emeric Vigier05e894e2012-08-20 13:53:02 -0400334 break;
Alexandre Savarda04c5202012-09-18 17:19:53 -0400335 case 3:
Alexandre Savarddef3bfa2012-09-12 16:20:06 -0400336 fragment = new ButtonSectionFragment();
337 Log.i(TAG, "getItem: fragment is " + fragment);
Emeric Vigier05e894e2012-08-20 13:53:02 -0400338 break;
339 default:
340 Log.e(TAG, "getItem: unknown tab position " + i);
341 return null;
342 }
343
Adrien Béraudffd32412012-08-07 18:39:23 -0400344 Bundle args = new Bundle();
345 args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
346 fragment.setArguments(args);
347 return fragment;
348 }
349
350 @Override
351 public int getCount()
352 {
Alexandre Savarda04c5202012-09-18 17:19:53 -0400353 return 4;
Adrien Béraudffd32412012-08-07 18:39:23 -0400354 }
355
356 @Override
357 public CharSequence getPageTitle(int position)
358 {
359 switch (position) {
Alexandre Savarda04c5202012-09-18 17:19:53 -0400360 case 0:
361 return getString(R.string.title_section0).toUpperCase();
Adrien Béraudffd32412012-08-07 18:39:23 -0400362 case 1:
Alexandre Savarda04c5202012-09-18 17:19:53 -0400363 return getString(R.string.title_section1).toUpperCase();
Emeric Vigier05e894e2012-08-20 13:53:02 -0400364 case 2:
Alexandre Savarda04c5202012-09-18 17:19:53 -0400365 return getString(R.string.title_section2).toUpperCase();
366 case 3:
Emeric Vigier05e894e2012-08-20 13:53:02 -0400367 return getString(R.string.title_section3).toUpperCase();
368 default:
369 Log.e(TAG, "getPageTitle: unknown tab position " + position);
370 break;
Adrien Béraudffd32412012-08-07 18:39:23 -0400371 }
372 return null;
373 }
374 }
375
376 /**
377 * A dummy fragment representing a section of the app, but that simply
378 * displays dummy text.
379 */
380 public static class DummySectionFragment extends Fragment
381 {
382 public DummySectionFragment()
383 {
384 setRetainInstance(true);
385 }
386
387 public static final String ARG_SECTION_NUMBER = "section_number";
388
389 @Override
Emeric Vigier05e894e2012-08-20 13:53:02 -0400390 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
Adrien Béraudffd32412012-08-07 18:39:23 -0400391 {
392 TextView textView = new TextView(getActivity());
393 textView.setGravity(Gravity.CENTER);
394 Bundle args = getArguments();
395 textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
Emeric Vigier05e894e2012-08-20 13:53:02 -0400396 textView.setText("java sucks");
Adrien Béraudffd32412012-08-07 18:39:23 -0400397 return textView;
398 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400399 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400400
Emeric Vigier7a255aa2012-08-29 09:49:18 -0400401 public String getAppPath() {
402 PackageManager pkgMng = getPackageManager();
403 String pkgName = getPackageName();
404
405 try {
406 PackageInfo pkgInfo = pkgMng.getPackageInfo(pkgName, 0);
407 pkgName = pkgInfo.applicationInfo.dataDir;
408 } catch (NameNotFoundException e) {
409 Log.w(TAG, "Error Package name not found ", e);
410 }
411
412 Log.d(TAG, "Application path: " + pkgName);
413 return pkgName;
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400414 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400415
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400416 @Override
417 public void onClick(View view)
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400418 {
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400419 buttonService = (Button) findViewById(R.id.buttonService);
420
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400421 switch (view.getId()) {
Emeric Vigierd5c17f52012-08-29 09:29:33 -0400422 case R.id.buttonCall:
Emeric Vigier39a11fa2012-08-29 15:25:09 -0400423 TextView textView = (TextView) findViewById(R.id.editAccountID);
424 String accountID = textView.getText().toString();
425 EditText editText;
Emeric Vigier78a53e92012-08-29 18:15:34 -0400426 Random random = new Random();
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400427
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400428 if (incomingCallID != "") {
429 buttonCall.clearAnimation();
Emeric Vigier9380ae52012-09-14 17:40:39 -0400430// manager.managerImpl.answerCall(incomingCallID);
431 manager.callmanagerJNI.accept(incomingCallID);
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400432 callID = incomingCallID;
433 incomingCallID="";
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400434 callOnGoing = true;
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400435 buttonCall.setEnabled(false);
436 buttonHangup.setEnabled(true);
437 } else {
438 if (callOnGoing == false) {
439 editText = (EditText) findViewById(R.id.editTo);
440 String to = editText.getText().toString();
441 if (to == null) {
442 Log.e(TAG, "to string is " + to);
443 break;
444 }
445
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400446 callID = Integer.toString(random.nextInt());
447
Emeric Vigier9701e032012-09-12 12:38:01 -0400448 Log.d(TAG, "manager.managerImpl.placeCall(" + accountID + ", " + callID + ", " + to + ");");
Emeric Vigier9380ae52012-09-14 17:40:39 -0400449// manager.managerImpl.outgoingCall(accountID, callID, to);
450 manager.callmanagerJNI.placeCall(accountID, callID, to);
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400451 callOnGoing = true;
452 buttonCall.setEnabled(false);
453 buttonHangup.setEnabled(true);
454 }
Emeric Vigierd5c17f52012-08-29 09:29:33 -0400455 }
Emeric Vigierd5c17f52012-08-29 09:29:33 -0400456 break;
Emeric Vigier78a53e92012-08-29 18:15:34 -0400457 case R.id.buttonHangUp:
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400458 if (incomingCallID != "") {
459 buttonCall.clearAnimation();
Emeric Vigier9380ae52012-09-14 17:40:39 -0400460// manager.managerImpl.refuseCall(incomingCallID);
461 manager.callmanagerJNI.refuse(incomingCallID);
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400462 incomingCallID="";
463 buttonCall.setEnabled(true);
464 buttonHangup.setEnabled(true);
465 } else {
466 if (callOnGoing == true) {
Emeric Vigier9701e032012-09-12 12:38:01 -0400467 Log.d(TAG, "manager.managerImpl.hangUp(" + callID + ");");
Emeric Vigier9380ae52012-09-14 17:40:39 -0400468// manager.managerImpl.hangupCall(callID);
469 manager.callmanagerJNI.hangUp(callID);
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400470 callOnGoing = false;
471 buttonCall.setEnabled(true);
472 buttonHangup.setEnabled(false);
473 }
Emeric Vigiere89b48b2012-08-30 14:16:46 -0400474 }
Emeric Vigiera6bdb702012-08-31 15:34:53 -0400475
476 buttonCall.setImageResource(R.drawable.ic_call);
Emeric Vigier78a53e92012-08-29 18:15:34 -0400477 break;
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400478 case R.id.buttonInit:
Emeric Vigier9701e032012-09-12 12:38:01 -0400479 Manager.managerImpl.setPath("");
480 Manager.managerImpl.init("");
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400481 break;
Emeric Vigiereaf2c492012-09-19 14:38:20 -0400482 case R.id.buttonService:
483 if (!serviceIsOn) {
484 startService(new Intent(this, SipService.class));
485 serviceIsOn = true;
486 buttonService.setText("disable Service");
487 }
488 else {
489 stopService(new Intent(this, SipService.class));
490 serviceIsOn = false;
491 buttonService.setText("enable Service");
492 }
493 break;
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400494 case R.id.buttonCallVoid:
Emeric Vigier9701e032012-09-12 12:38:01 -0400495 Manager.callVoid();
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400496 break;
497 case R.id.buttonGetNewData:
Emeric Vigier9701e032012-09-12 12:38:01 -0400498 Data d = Manager.getNewData(42, "foo");
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400499 if (d != null)
500 buttonFragment.getNewDataText().setText("getNewData(42, \"foo\") == Data(" + d.i + ", \"" + d.s + "\")");
501 break;
502 case R.id.buttonGetDataString:
Emeric Vigier383b2a22012-08-27 14:20:05 -0400503 Data daita = new Data(43, "bar");
Emeric Vigier9701e032012-09-12 12:38:01 -0400504 String s = Manager.getDataString(daita);
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400505 if (s != "") {
Emeric Vigier383b2a22012-08-27 14:20:05 -0400506 buttonFragment.getDataStringText().setText("getDataString(Data(43, \"bar\")) == \"" + s + "\"");
Emeric Vigier62ca14d2012-08-24 11:05:09 -0400507 }
508 break;
509 default:
510 Log.w(TAG, "unknown button " + view.getId());
511 break;
Emeric Vigier05e894e2012-08-20 13:53:02 -0400512 }
Emeric Vigier05e894e2012-08-20 13:53:02 -0400513 }
Adrien Béraudffd32412012-08-07 18:39:23 -0400514}