2 TutorialRegistrationActivity.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.os.Bundle;
25 import android.os.Handler;
26 import android.view.View;
27 import android.widget.Button;
28 import android.widget.TextView;
31 * Activity for displaying and starting the registration example on Android phone.
33 * @author Guillaume Beraudo
36 public class TutorialRegistrationActivity extends TutorialHelloWorldActivity {
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;
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);
58 // Output text to the outputText widget
59 outputText = (TextView) findViewById(R.id.OutputText);
60 final TutorialNotifier notifier = new AndroidTutorialNotifier(mHandler, outputText);
63 // Create Tutorial object
64 tutorial = new TutorialRegistration(notifier);
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);
80 Button buttonStop = (Button) findViewById(R.id.ButtonStop);
81 buttonStop.setOnClickListener(new View.OnClickListener() {
82 public void onClick(View v) {
83 tutorial.stopMainLoop();
89 private class TutorialLaunchingThread extends Thread {
94 tutorial.launchTutorial(
95 sipAddressWidget.getText().toString(),
96 sipPasswordWidget.getText().toString());
97 } catch (LinphoneCoreException e) {
99 outputText.setText(e.getMessage() +"\n"+outputText.getText());