]> sjero.net Git - linphone/blob - tutorials/TutorialHelloWorldActivity.java
Fix armv6 loadling liblinphone issue
[linphone] / tutorials / TutorialHelloWorldActivity.java
1 /*
2 TutorialHelloWorldActivity.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 HelloWorld example on Android phone.
33  *
34  * @author Guillaume Beraudo
35  *
36  */
37 public class TutorialHelloWorldActivity extends Activity {
38
39         private static final String defaultSipAddress = "sip:";
40         private TextView sipAddressWidget;
41         private TutorialHelloWorld tutorial;
42         private Handler mHandler =  new Handler() ;
43         private Button buttonCall;
44
45         @Override
46         protected void onCreate(Bundle savedInstanceState) {
47                 super.onCreate(savedInstanceState);
48                 setContentView(R.layout.hello_world);
49                 sipAddressWidget = (TextView) findViewById(R.id.AddressId);
50                 sipAddressWidget.setText(defaultSipAddress);
51
52                 // Output text to the outputText widget
53                 final TextView outputText = (TextView) findViewById(R.id.OutputText);
54                 final TutorialNotifier notifier = new AndroidTutorialNotifier(mHandler, outputText);
55
56                 
57                 // Create HelloWorld object
58                 tutorial = new TutorialHelloWorld(notifier);
59
60                 
61                 
62                 // Assign call action to call button
63                 buttonCall = (Button) findViewById(R.id.CallButton);
64                 buttonCall.setOnClickListener(new View.OnClickListener() {
65                         public void onClick(View v) {
66                                 TutorialLaunchingThread thread = new TutorialLaunchingThread();
67                                 buttonCall.setEnabled(false);
68                                 thread.start();
69                         }
70                 });
71
72                 // Assign stop action to stop button
73                 Button buttonStop = (Button) findViewById(R.id.ButtonStop);
74                 buttonStop.setOnClickListener(new View.OnClickListener() {
75                         public void onClick(View v) {
76                                 tutorial.stopMainLoop();
77                         }
78                 });
79         }
80         
81         
82         private class TutorialLaunchingThread extends Thread {
83                 @Override
84                 public void run() {
85                         super.run();
86                         try {
87                                 tutorial.launchTutorial(sipAddressWidget.getText().toString());
88                                 mHandler.post(new Runnable() {
89                                         public void run() {
90                                                 buttonCall.setEnabled(true);
91                                         }
92                                 });
93                         } catch (LinphoneCoreException e) {
94                                 e.printStackTrace();
95                         }
96                 }
97         }
98 }