import android.widget.ScrollView;
import android.widget.TabHost;
import android.widget.TabWidget;
+import android.widget.Toast;
public class Main extends Activity
{
/* Private data */
private Task task;
+ private Toast toast;
private boolean ready;
/* Widgets */
private ScrollView lscroll;
private ScrollView dscroll;
- /* Private methods */
- public void onRegister(Object obj)
+ /* Private handler methods */
+ private void onRegister(Object obj)
{
Os.debug("Main: onRegister");
this.task = (Task)obj;
}
- public void onMessage(Object obj)
+ private void onMessage(Object obj)
{
Message msg = (Message)obj;
}
}
+ private void onNotify(String text)
+ {
+ Os.debug("Main: onNotify - " + text);
+ this.toast.setText(text);
+ this.toast.show();
+ }
+
+ /* Private service methods */
private void startService()
{
Os.debug("Main: startService");
// Setup main layout
this.setContentView(R.layout.main);
+ // Setup toast
+ this.toast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
+
// Setup communication
this.handler = new MainHandler();
this.messenger = new Messenger(this.handler);
case Task.DISCONNECT:
Main.this.ready = false;
break;
+ case Task.NOTIFY:
+ Main.this.onNotify((String)msg.obj);
+ break;
default:
Os.debug("Main: unknown message - " + msg.what);
break;
import android.os.IBinder;
import android.os.Looper;
import android.os.Messenger;
-import android.widget.Toast;
public class Task extends Service implements Runnable
{
public static final int MESSAGE = 1;
public static final int CONNECT = 2;
public static final int DISCONNECT = 3;
+ public static final int NOTIFY = 4;
/* Configuration */
private String server = "irc.freenode.net";
private Messenger messenger = null;
private Thread thread = null;
private Client client = null;
- private Toast toast = null;
/* Private methods */
private void command(int cmd, Object value)
private void notify(String text, int icon)
{
- // Log
- Os.debug("Task: notify - " + text);
+ // Notify Main
+ this.command(NOTIFY, text);
- // Toast
- this.toast.setText(text);
- this.toast.show();
-
- // Notify
+ // Notification bar
Notification note = new Notification(icon, null, 0);
Intent intent = new Intent(this, Main.class);
PendingIntent pend = PendingIntent.getActivity(this, 0, intent, 0);
{
Os.debug("Task: thread run");
- // Android Toast setup
- Looper.prepare();
-
// Setup notification bar
this.notify("Connecting..", android.R.drawable.presence_invisible);
Os.debug("Task: onCreate");
super.onCreate();
- // Setup toast
- Context context = this.getApplicationContext();
- this.toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
-
// Create the client
this.client = new Client();
}