]> sjero.net Git - linphone/blob - tutorials/TutorialRegistrationActivity.java
Fix armv6 loadling liblinphone issue
[linphone] / tutorials / TutorialRegistrationActivity.java
1 /*
2 TutorialRegistrationActivity.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.os.Bundle;
25 import android.os.Handler;
26 import android.view.View;
27 import android.widget.Button;
28 import android.widget.TextView;
29
30 /**
31  * Activity for displaying and starting the registration example on Android phone.
32  * 
33  * @author Guillaume Beraudo
34  *
35  */
36 public class TutorialRegistrationActivity extends TutorialHelloWorldActivity {
37
38         private static final String defaultSipAddress = "sip:";
39         private static final String defaultSipPassword = "";
40         private TextView sipAddressWidget;
41         private TextView sipPasswordWidget;
42         private TutorialRegistration tutorial;
43         private Button buttonCall;
44         private Handler mHandler =  new Handler();
45         private TextView outputText;
46
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                 sipPasswordWidget = (TextView) findViewById(R.id.Password);
55                 sipPasswordWidget.setVisibility(TextView.VISIBLE);
56                 sipPasswordWidget.setText(defaultSipPassword);
57
58                 // Output text to the outputText widget
59                 outputText = (TextView) findViewById(R.id.OutputText);
60                 final TutorialNotifier notifier = new AndroidTutorialNotifier(mHandler, outputText);
61
62                 
63                 // Create Tutorial object
64                 tutorial = new TutorialRegistration(notifier);
65
66                 
67                 
68                 // Assign call action to call button
69                 buttonCall = (Button) findViewById(R.id.CallButton);
70                 buttonCall.setText("Register");
71                 buttonCall.setOnClickListener(new View.OnClickListener() {
72                         public void onClick(View v) {
73                                 TutorialLaunchingThread thread = new TutorialLaunchingThread();
74                                 buttonCall.setEnabled(false);
75                                 thread.start();
76                         }
77                 });
78
79
80                 Button buttonStop = (Button) findViewById(R.id.ButtonStop);
81                 buttonStop.setOnClickListener(new View.OnClickListener() {
82                         public void onClick(View v) {
83                                 tutorial.stopMainLoop();
84                         }
85                 });
86         }
87         
88         
89         private class TutorialLaunchingThread extends Thread {
90                 @Override
91                 public void run() {
92                         super.run();
93                         try {
94                                 tutorial.launchTutorial(
95                                                 sipAddressWidget.getText().toString(),
96                                                 sipPasswordWidget.getText().toString());
97                         } catch (LinphoneCoreException e) {
98                                 e.printStackTrace();
99                                 outputText.setText(e.getMessage() +"\n"+outputText.getText());
100                         }
101                 }
102         }
103 }