]> sjero.net Git - linphone/blob - tutorials/TutorialBuddyStatusActivity.java
Fix armv6 loadling liblinphone issue
[linphone] / tutorials / TutorialBuddyStatusActivity.java
1 /*
2 TutorialBuddyStatusActivity.java
3 Copyright (C) 2010  Belledonne Communications, Grenoble, France
4
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.
9
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.
14
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.
18 */
19 package org.linphone.core.tutorials;
20
21 import org.linphone.R;
22 import org.linphone.core.LinphoneCoreException;
23
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;
30
31 /**
32  * Activity for displaying and starting the BuddyStatus example on Android phone.
33  *
34  * @author Guillaume Beraudo
35  *
36  */
37 public class TutorialBuddyStatusActivity extends Activity {
38
39         private static final String defaultSipAddress = "sip:";
40         private TextView sipAddressWidget;
41         private TextView mySipAddressWidget;
42         private TextView mySipPasswordWidget;
43         
44         private TutorialBuddyStatus tutorial;
45         private Handler mHandler =  new Handler() ;
46         private Button buttonCall;
47
48         @Override
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);
54
55                 mySipAddressWidget = (TextView) findViewById(R.id.MyAddressId);
56                 mySipAddressWidget.setVisibility(View.VISIBLE);
57                 mySipPasswordWidget = (TextView) findViewById(R.id.Password);
58                 mySipPasswordWidget.setVisibility(TextView.VISIBLE);
59                 
60                 
61                 // Output text to the outputText widget
62                 final TextView outputText = (TextView) findViewById(R.id.OutputText);
63                 final TutorialNotifier notifier = new AndroidTutorialNotifier(mHandler, outputText);
64
65                 
66                 // Create BuddyStatus object
67                 tutorial = new TutorialBuddyStatus(notifier);
68
69                 
70                 
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);
77                                 thread.start();
78                         }
79                 });
80
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();
86                         }
87                 });
88         }
89         
90         
91         private class TutorialLaunchingThread extends Thread {
92                 @Override
93                 public void run() {
94                         super.run();
95                         try {
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() {
100                                         public void run() {
101                                                 buttonCall.setEnabled(true);
102                                         }
103                                 });
104                         } catch (LinphoneCoreException e) {
105                                 e.printStackTrace();
106                         }
107                 }
108         }
109 }