[Android] AudioService: use the pre-existing handler to show the Toasts

Ludovic Fauvet git at videolan.org
Thu May 23 11:43:09 CEST 2013


vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Thu May 23 11:40:28 2013 +0200| [ade6e8d454e048c3b6d483f8394d99c29f956e5c] | committer: Ludovic Fauvet

AudioService: use the pre-existing handler to show the Toasts

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=ade6e8d454e048c3b6d483f8394d99c29f956e5c
---

 vlc-android/src/org/videolan/vlc/AudioService.java |   20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index f917490..2746ba9 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -80,6 +80,7 @@ public class AudioService extends Service {
     private static final String TAG = "VLC/AudioService";
 
     private static final int SHOW_PROGRESS = 0;
+    private static final int SHOW_TOAST = 1;
     public static final String START_FROM_NOTIFICATION = "from_notification";
     public static final String ACTION_REMOTE_GENERIC = "org.videolan.vlc.remote.";
     public static final String ACTION_REMOTE_BACKWARD = "org.videolan.vlc.remote.Backward";
@@ -495,6 +496,12 @@ public class AudioService extends Service {
                         sendEmptyMessageDelayed(SHOW_PROGRESS, 1000);
                     }
                     break;
+                case SHOW_TOAST:
+                    final Bundle bundle = msg.getData();
+                    final String text = bundle.getString("text");
+                    final int duration = bundle.getInt("duration");
+                    Toast.makeText(VLCApplication.getAppContext(), text, duration).show();
+                    break;
             }
         }
     };
@@ -1145,16 +1152,7 @@ public class AudioService extends Service {
         bundle.putString("text", text);
         bundle.putInt("duration", duration);
         msg.setData(bundle);
-        toastHandler.sendMessage(msg);
+        msg.what = SHOW_TOAST;
+        mHandler.sendMessage(msg);
     }
-
-    private WeakHandler<AudioService> toastHandler = new WeakHandler<AudioService>(this) {
-        @Override
-        public void handleMessage(Message msg) {
-            final Bundle bundle = msg.getData();
-            final String text = bundle.getString("text");
-            final int duration = bundle.getInt("duration");
-            Toast.makeText(VLCApplication.getAppContext(), text, duration).show();
-        }
-    };
 }



More information about the Android mailing list