1 package org.pileus.spades;
3 import android.app.Activity;
4 import android.content.Intent;
5 import android.os.Bundle;
6 import android.os.Handler;
7 import android.os.Messenger;
8 import android.text.method.ScrollingMovementMethod;
9 import android.view.View;
10 import android.widget.Button;
11 import android.widget.EditText;
12 import android.widget.LinearLayout;
13 import android.widget.TextView;
14 import android.widget.ScrollView;
15 import android.widget.TabHost;
16 import android.widget.TabWidget;
18 public class Main extends Activity
21 private Handler handler;
22 private Messenger messenger;
28 private TabHost window;
29 private TabWidget tabs;
30 private LinearLayout chat;
32 private EditText input;
34 private TextView spades;
35 private TextView debug;
37 private ScrollView lscroll;
38 private ScrollView dscroll;
41 public void onRegister(Object obj)
43 Os.debug("Main: onRegister");
44 this.task = (Task)obj;
47 public void onMessage(Object obj)
49 Message msg = (Message)obj;
51 this.debug.append("> " + msg.line + "\n");
52 this.dscroll.smoothScrollTo(0, this.debug.getBottom());
54 if (msg.cmd.equals("PRIVMSG")) {
55 this.log.append(msg.from + ": " + msg.msg + "\n");
56 this.lscroll.smoothScrollTo(0, this.log.getBottom());
60 private void startService()
62 Os.debug("Main: startService");
63 startService(new Intent(this, Task.class)
64 .putExtra("Messenger", this.messenger));
67 private void stopService()
69 Os.debug("Main: stopService");
70 stopService(new Intent(this, Task.class));
73 /* Widget callback functions */
74 public void onSend(View btn)
76 if (this.task == null)
78 String txt = this.input.getText().toString();
79 Message msg = this.task.send(txt);
82 this.input.setText("");
83 this.log.append(msg.from + ": " + msg.msg + "\n");
86 /* Activity Methods */
88 public void onCreate(Bundle savedInstanceState)
91 super.onCreate(savedInstanceState);
92 Os.debug("Main: onCreate");
95 this.setContentView(R.layout.main);
97 // Setup communication
98 this.handler = new MainHandler();
99 this.messenger = new Messenger(this.handler);
102 this.window = (TabHost) findViewById(android.R.id.tabhost);
103 this.tabs = (TabWidget) findViewById(android.R.id.tabs);
104 this.chat = (LinearLayout) findViewById(R.id.chat);
105 this.log = (TextView) findViewById(R.id.log);
106 this.input = (EditText) findViewById(R.id.input);
107 this.send = (Button) findViewById(R.id.send);
108 this.spades = (TextView) findViewById(R.id.spades);
109 this.debug = (TextView) findViewById(R.id.debug);
111 this.lscroll = (ScrollView) findViewById(R.id.log_scroll);
112 this.dscroll = (ScrollView) findViewById(R.id.debug_scroll);
117 this.window.addTab(this.window
119 .setIndicator("Chat")
120 .setContent(R.id.chat));
121 this.window.addTab(this.window
122 .newTabSpec("spades")
123 .setIndicator("Spades")
124 .setContent(R.id.spades));
125 this.window.addTab(this.window
127 .setIndicator("Debug")
128 .setContent(R.id.debug));
133 } catch (Exception e) {
134 Os.debug("Error setting content view", e);
140 public void onStart()
143 Os.debug("Main: onStart");
147 public void onResume()
150 Os.debug("Main: onResume");
154 public void onPause()
157 Os.debug("Main: onPause");
164 Os.debug("Main: onStop");
168 public void onRestart()
171 Os.debug("Main: onRestart");
175 public void onDestroy()
178 Os.debug("Main: onDestroy");
182 class MainHandler extends Handler
184 public void handleMessage(android.os.Message msg)
188 Main.this.onRegister(msg.obj);
191 Main.this.onMessage(msg.obj);
194 Os.debug("Main: unknown message - " + msg.what);