[Android] src: add a VLCCallbackTask to make threading easier

Edward Wang git at videolan.org
Wed Jun 20 22:53:28 CEST 2012


android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Wed Jun 20 16:51:50 2012 -0400| [9357ae33fedb126bd5cea6bd1d961ec50a924441] | committer: Edward Wang

src: add a VLCCallbackTask to make threading easier

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=9357ae33fedb126bd5cea6bd1d961ec50a924441
---

 .../src/org/videolan/vlc/VLCCallbackTask.java      |   64 ++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/VLCCallbackTask.java b/vlc-android/src/org/videolan/vlc/VLCCallbackTask.java
new file mode 100644
index 0000000..304f97f
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/VLCCallbackTask.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * VLCCallbackTask.java
+ *****************************************************************************
+ * Copyright © 2012 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+package org.videolan.vlc;
+
+/**
+ * A small callback helper class to make running callbacks in threads easier
+ */
+public class VLCCallbackTask implements Runnable {
+    private final CallbackListener callback;
+    private final Object user;
+
+    /**
+     * The callback interface. Implement callback() to run as the main thread,
+     * and implement callback_object() to run when the main thread completes.
+     */
+    public interface CallbackListener {
+        public abstract void callback();
+        public abstract void callback_object(Object o);
+    }
+
+    /**
+     * @param _callback The CallbackListener as described above
+     * @param _user Any user object you want to pass
+     */
+    public VLCCallbackTask(CallbackListener _callback, Object _user) {
+      this.callback = _callback;
+      this.user = _user;
+    }
+
+    /**
+     * A version of VLCCallbackTask if you are not using the user parameter
+     *
+     * @param _callback The CallbackListener as described above
+     */
+    public VLCCallbackTask(CallbackListener _callback) {
+        this.callback = _callback;
+        this.user = null;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Runnable#run()
+     */
+    public void run() {
+      callback.callback();
+      callback.callback_object(user);
+    }
+}



More information about the Android mailing list