[Android] Delay the appearance of the progress bar to avoid flickering

Ludovic Fauvet git at videolan.org
Wed May 29 12:24:47 CEST 2013


vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Wed May 29 12:12:40 2013 +0200| [e4b4c02b0d550cdd13012e25b78587959f2ff960] | committer: Ludovic Fauvet

Delay the appearance of the progress bar to avoid flickering

Do not show the progress bar if visible for less than 300msec. In most
cases the bar is enabled for less than 150msec or way more than a
second. The latter being the most interesting from a user perspective.

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

 vlc-android/res/layout/main.xml                    |    2 +-
 .../src/org/videolan/vlc/gui/MainActivity.java     |   28 +++++++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/vlc-android/res/layout/main.xml b/vlc-android/res/layout/main.xml
index 0d6d219..0ce8f64 100644
--- a/vlc-android/res/layout/main.xml
+++ b/vlc-android/res/layout/main.xml
@@ -12,7 +12,7 @@
         android:id="@+id/info_layout"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
-        android:visibility="visible">
+        android:visibility="gone">
         <ProgressBar
             android:id="@+id/info_progress"
             style="?android:attr/progressBarStyleHorizontal"
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index cb12ee8..dc40881 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -20,6 +20,7 @@
 
 package org.videolan.vlc.gui;
 
+import android.os.Message;
 import org.videolan.libvlc.LibVlcException;
 import org.videolan.libvlc.LibVlcUtil;
 import org.videolan.vlc.AudioService;
@@ -87,6 +88,7 @@ public class MainActivity extends SherlockFragmentActivity {
     private static final String PREF_FIRST_RUN = "first_run";
 
     private static final int ACTIVITY_RESULT_PREFERENCES = 1;
+    private static final int ACTIVITY_SHOW_INFOLAYOUT = 2;
 
     private ActionBar mActionBar;
     private SlidingMenu mMenu;
@@ -597,7 +599,31 @@ public class MainActivity extends SherlockFragmentActivity {
                 mInfoText.setText(info);
                 mInfoProgress.setMax(max);
                 mInfoProgress.setProgress(progress);
-                mInfoLayout.setVisibility(info != null ? View.VISIBLE : View.GONE);
+
+                if (info == null) {
+                    /* Cancel any upcoming visibility change */
+                    mHandler.removeMessages(ACTIVITY_SHOW_INFOLAYOUT);
+                    mInfoLayout.setVisibility(View.GONE);
+                }
+                else {
+                    /* Slightly delay the appearance of the progress bar to avoid unnecessary flickering */
+                    if (!mHandler.hasMessages(ACTIVITY_SHOW_INFOLAYOUT)) {
+                        Message m = new Message();
+                        m.what = ACTIVITY_SHOW_INFOLAYOUT;
+                        mHandler.sendMessageDelayed(m, 300);
+                    }
+                }
+            }
+        }
+    };
+
+    private final Handler mHandler = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case ACTIVITY_SHOW_INFOLAYOUT:
+                    mInfoLayout.setVisibility(View.VISIBLE);
+                    break;
             }
         }
     };



More information about the Android mailing list