summaryrefslogtreecommitdiff
path: root/client/activity-demo/Piztor/src/com/example/piztor/MainActivity.java
blob: 38c6938d5c7ecf96c60279302e41005af47dff6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.example.piztor;

import java.io.PrintStream;
import java.util.Vector;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
	PrintStream cout = System.out;
	Button b;
	EditText username, password, ip, port;
	Login login;
	Controller c;
	boolean flag = false;
	public final static String SER_KEY = "CONTROL";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		login = new Login(this);
		c = new Controller();
		b = (Button) findViewById(R.id.login);
		
		b.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if(flag==false){
				 Vector<Object> r = new Vector<Object>();
				 r.add(0);
				 r.add(username.getText().toString());
				 r.add(password.getText().toString());
				 Transam t = new Transam(ip.getText().toString(), Integer
				 .parseInt(port.getText().toString()), new Myrequest(r),
				 login);
				 new Thread(t).run();
				 flag = true;
				}
				else{
					 Vector<Object> r = new Vector<Object>();
					 r.add(3);
					 r.add(login.tk);
					 r.add(1);
					 Transam t = new Transam(ip.getText().toString(), Integer
					 .parseInt(port.getText().toString()), new Myrequest(r),
					 c);
					 new Thread(t).run();
				}
			}
		});
		username = (EditText) findViewById(R.id.username);
		password = (EditText) findViewById(R.id.password);
		ip = (EditText) findViewById(R.id.ip);
		port = (EditText) findViewById(R.id.port);
		cout.println("onCreate!");
	}

	void start() {
		Intent i = new Intent();
		i.setClass(MainActivity.this, Running.class);
		startActivity(i);
	}

	@Override
	protected void onStart() {
		super.onStart();
		ip.setText("69.85.86.42");
		port.setText("9990");
		username.setText("hello");
		password.setText("world");
		cout.println("onStart!");
	}

	@Override
	protected void onRestart() {
		super.onRestart();
		cout.println("onRestart!");
	}

	@Override
	protected void onResume() {
		super.onResume();
		// cout.println("onResume!");
		// v.drawString("!!!!!");
	}

	@Override
	protected void onPause() {
		super.onPause();
		cout.println("onPause!");
	}

	@Override
	protected void onStop() {
		super.onStop();
		cout.println("onStop!");
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		cout.println("onDestroy!");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}