Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
212 ligi 1
package org.ligi.android;
2
 
3
// Need the following import to get access to the app resources, since this
4
// class is in a sub-package.
5
 
6
 
7
import android.app.Activity;
8
import android.os.Bundle;
9
import android.view.View;
10
import android.widget.EditText;
11
import android.widget.Button;
12
import android.text.method.NumberKeyListener;
13
 
14
import          android.app.AlertDialog.*;
15
import          android.app.AlertDialog;
16
 
17
import android.content.SharedPreferences;
18
/**
19
 * Demonstrates wrapping a layout in a ScrollView.
20
 *
21
 */
22
public class ConnectionActivity extends Activity {
23
 
24
 
25
    EditText port_edit;
26
    EditText host_edit;
27
 
28
    Activity here;
29
 
30
    DUBwise root;
31
 
32
 
33
 
34
 
35
 
36
 
37
    @Override
38
    protected void onCreate(Bundle savedInstanceState) {
39
        super.onCreate(savedInstanceState);
40
        setContentView(R.layout.connection);
41
        here=this;
42
 
43
        SharedPreferences settings = getSharedPreferences("DUBwise", 0);
44
 
45
        port_edit=(EditText)findViewById( R.id.edit_port);
46
        host_edit=(EditText)findViewById( R.id.edit_host);
47
 
48
        port_edit.setKeyListener(new NumberKeyListener(){
49
                @Override
50
                    protected char[] getAcceptedChars() {
51
 
52
                    return new char[]{'1','2','3','4','5','6','7','8','9','0'};
53
                }
54
            });
55
 
56
        host_edit.setText(settings.getString("conn_host","10.0.2.2"));
57
        port_edit.setText(settings.getString("conn_port","54321"));
58
 
59
        Button save_btn=(Button)findViewById( R.id.save_btn);
60
 
61
        save_btn.setOnClickListener(new View.OnClickListener() {
62
             public void onClick(View v) {
63
                 // Perform action on click
64
 
65
 
66
                 java.net.Socket connection;
67
                 java.io.InputStream    reader;    
68
                 java.io.OutputStream writer;    
69
                 try {
70
                 connection = new java.net.Socket(host_edit.getText().toString(),Integer.parseInt(port_edit.getText().toString()));
71
 
72
 
73
                 SharedPreferences settings = getSharedPreferences("DUBwise", 0);
74
                 SharedPreferences.Editor editor = settings.edit();
75
                 editor.putString("conn_host", host_edit.getText().toString());
76
                 editor.putString("conn_port", port_edit.getText().toString());
77
 
78
                 // Don't forget to commit your edits!!!
79
                 editor.commit();
80
 
81
 
82
 
83
                 finish();
84
                 }
85
                 catch (Exception e) {
86
 
87
                     new AlertDialog.Builder(here).setTitle("Connection Problem").setMessage("" + e.toString()).setPositiveButton("OK",null).create().show();
88
 
89
                 }
90
             }
91
         });
92
 
93
 
94
        Button cancel_btn=(Button)findViewById( R.id.cancel_btn);
95
 
96
        cancel_btn.setOnClickListener(new View.OnClickListener() {
97
             public void onClick(View v) {
98
                 finish();
99
             }
100
         });
101
 
102
 
103
 
104
    }
105
}