From 088e16defac8f22d795dc208791e0031eceb1d46 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sat, 13 Apr 2013 02:02:31 +0000 Subject: [PATCH] Move toasts to Main --- src/org/pileus/spades/Main.java | 22 +++++++++++++++++++--- src/org/pileus/spades/Task.java | 20 ++++---------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/org/pileus/spades/Main.java b/src/org/pileus/spades/Main.java index cf0baed..ebca439 100644 --- a/src/org/pileus/spades/Main.java +++ b/src/org/pileus/spades/Main.java @@ -17,6 +17,7 @@ import android.widget.TextView; import android.widget.ScrollView; import android.widget.TabHost; import android.widget.TabWidget; +import android.widget.Toast; public class Main extends Activity { @@ -26,6 +27,7 @@ public class Main extends Activity /* Private data */ private Task task; + private Toast toast; private boolean ready; /* Widgets */ @@ -41,14 +43,14 @@ public class Main extends Activity 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; @@ -61,6 +63,14 @@ public class Main extends Activity } } + 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"); @@ -97,6 +107,9 @@ public class Main extends Activity // 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); @@ -230,6 +243,9 @@ public class Main extends Activity 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; diff --git a/src/org/pileus/spades/Task.java b/src/org/pileus/spades/Task.java index 2ed5961..2b5be04 100644 --- a/src/org/pileus/spades/Task.java +++ b/src/org/pileus/spades/Task.java @@ -8,7 +8,6 @@ import android.content.Intent; import android.os.IBinder; import android.os.Looper; import android.os.Messenger; -import android.widget.Toast; public class Task extends Service implements Runnable { @@ -17,6 +16,7 @@ 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"; @@ -27,7 +27,6 @@ public class Task extends Service implements Runnable 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) @@ -44,14 +43,10 @@ public class Task extends Service implements Runnable 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); @@ -77,9 +72,6 @@ public class Task extends Service implements Runnable { Os.debug("Task: thread run"); - // Android Toast setup - Looper.prepare(); - // Setup notification bar this.notify("Connecting..", android.R.drawable.presence_invisible); @@ -134,10 +126,6 @@ public class Task extends Service implements Runnable 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(); } -- 2.43.2