[Android] TV: Nicer external devices management

Geoffrey Métais git at videolan.org
Fri Mar 11 14:17:43 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar 11 12:44:28 2016 +0100| [fca7bc36c3dc795fc135beb53e3019b3be7b0153] | committer: Geoffrey Métais

TV: Nicer external devices management

> https://code.videolan.org/videolan/vlc-android/commit/fca7bc36c3dc795fc135beb53e3019b3be7b0153
---

 .../src/org/videolan/vlc/gui/tv/MainTvActivity.java        |  5 +++++
 .../org/videolan/vlc/gui/tv/browser/BaseTvActivity.java    | 14 ++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index b935f8f..4c64ea8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -555,6 +555,11 @@ public class MainTvActivity extends BaseTvActivity implements IVideoBrowser, OnI
     }
 
     @Override
+    protected void onExternelDeviceChange() {
+        updateBrowsers();
+    }
+
+    @Override
     public void updateProgress(){}
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
index 3d77804..592a934 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
@@ -38,10 +38,10 @@ import android.os.Message;
 import android.preference.PreferenceManager;
 import android.view.KeyEvent;
 
-import org.videolan.vlc.media.MediaLibrary;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.PlaybackServiceActivity;
 import org.videolan.vlc.gui.tv.SearchActivity;
+import org.videolan.vlc.media.MediaLibrary;
 import org.videolan.vlc.util.WeakHandler;
 
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@@ -63,7 +63,8 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
         IntentFilter networkFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
 
         IntentFilter storageFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED);
-        storageFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
+        storageFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
+        storageFilter.addAction(Intent.ACTION_MEDIA_EJECT);
         storageFilter.addDataScheme("file");
 
         registerReceiver(mExternalDevicesReceiver, networkFilter);
@@ -87,6 +88,7 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
 
     protected abstract void refresh();
     protected abstract void onNetworkUpdated();
+    protected void onExternelDeviceChange() {};
 
     protected final BroadcastReceiver mExternalDevicesReceiver = new BroadcastReceiver() {
         boolean connected = true;
@@ -110,9 +112,9 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
                 }
 
             } else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_MOUNTED)) {
-                mStorageHandlerHandler.sendEmptyMessage(ACTION_MEDIA_MOUNTED);
-            } else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_UNMOUNTED)) {
-                mStorageHandlerHandler.sendEmptyMessageDelayed(ACTION_MEDIA_UNMOUNTED, 100); //Delay to cancel it in case of MOUNT
+                mStorageHandlerHandler.sendEmptyMessageDelayed(ACTION_MEDIA_MOUNTED, 500);
+            } else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_EJECT) || action.equalsIgnoreCase(Intent.ACTION_MEDIA_REMOVED)) {
+                mStorageHandlerHandler.sendEmptyMessageDelayed(ACTION_MEDIA_UNMOUNTED, 2000); //Delay to cancel it in case of MOUNT
             }
         }
     };
@@ -136,7 +138,7 @@ public abstract class BaseTvActivity extends PlaybackServiceActivity {
                 case ACTION_MEDIA_MOUNTED:
                     removeMessages(ACTION_MEDIA_UNMOUNTED);
                 case ACTION_MEDIA_UNMOUNTED:
-                    getOwner().refresh();
+                    getOwner().onExternelDeviceChange();
                     break;
             }
         }



More information about the Android mailing list