2 TutorialBuddyStatusActivity.java
3 Copyright (C) 2010 Belledonne Communications, Grenoble, France
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package org.linphone.core.tutorials;
21 import org.linphone.R;
22 import org.linphone.core.LinphoneCoreException;
24 import android.app.Activity;
25 import android.os.Bundle;
26 import android.os.Handler;
27 import android.view.View;
28 import android.widget.Button;
29 import android.widget.TextView;
32 * Activity for displaying and starting the BuddyStatus example on Android phone.
34 * @author Guillaume Beraudo
37 public class TutorialBuddyStatusActivity extends Activity {
39 private static final String defaultSipAddress = "sip:";
40 private TextView sipAddressWidget;
41 private TextView mySipAddressWidget;
42 private TextView mySipPasswordWidget;
44 private TutorialBuddyStatus tutorial;
45 private Handler mHandler = new Handler() ;
46 private Button buttonCall;
49 protected void onCreate(Bundle savedInstanceState) {
50 super.onCreate(savedInstanceState);
51 setContentView(R.layout.hello_world);
52 sipAddressWidget = (TextView) findViewById(R.id.AddressId);
53 sipAddressWidget.setText(defaultSipAddress);
55 mySipAddressWidget = (TextView) findViewById(R.id.MyAddressId);
56 mySipAddressWidget.setVisibility(View.VISIBLE);
57 mySipPasswordWidget = (TextView) findViewById(R.id.Password);
58 mySipPasswordWidget.setVisibility(TextView.VISIBLE);
61 // Output text to the outputText widget
62 final TextView outputText = (TextView) findViewById(R.id.OutputText);
63 final TutorialNotifier notifier = new AndroidTutorialNotifier(mHandler, outputText);
66 // Create BuddyStatus object
67 tutorial = new TutorialBuddyStatus(notifier);
71 // Assign call action to call button
72 buttonCall = (Button) findViewById(R.id.CallButton);
73 buttonCall.setOnClickListener(new View.OnClickListener() {
74 public void onClick(View v) {
75 TutorialLaunchingThread thread = new TutorialLaunchingThread();
76 buttonCall.setEnabled(false);
81 // Assign stop action to stop button
82 Button buttonStop = (Button) findViewById(R.id.ButtonStop);
83 buttonStop.setOnClickListener(new View.OnClickListener() {
84 public void onClick(View v) {
85 tutorial.stopMainLoop();
91 private class TutorialLaunchingThread extends Thread {
96 String myIdentity = mySipAddressWidget.getText().length()>0?mySipAddressWidget.getText().toString():null;
97 String myPassword = mySipPasswordWidget.getText().length()>0?mySipPasswordWidget.getText().toString():null;
98 tutorial.launchTutorial(sipAddressWidget.getText().toString(), myIdentity, myPassword);
99 mHandler.post(new Runnable() {
101 buttonCall.setEnabled(true);
104 } catch (LinphoneCoreException e) {