[Android] Hack to cancel BackgroundManager animations

Geoffrey Métais git at videolan.org
Tue Jul 18 15:34:53 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 18 15:34:14 2017 +0200| [af736959b3c2beadafc5d81a2afc1100e500bd66] | committer: Geoffrey Métais

Hack to cancel BackgroundManager animations

See https://issuetracker.google.com/issues/37135111

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

 .../src/org/videolan/vlc/gui/tv/MainTvActivity.java     |  2 +-
 .../videolan/vlc/gui/tv/MediaItemDetailsFragment.java   |  2 +-
 vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.java     | 17 +++++++++++++++++
 .../vlc/gui/tv/browser/MediaLibBrowserFragment.java     |  2 +-
 .../vlc/gui/tv/browser/SortedBrowserFragment.java       |  2 +-
 5 files changed, 21 insertions(+), 4 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 a5595916a..e37d4203f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -233,7 +233,7 @@ public class MainTvActivity extends BaseTvActivity implements OnItemViewSelected
         if (mService != null)
             mService.removeCallback(this);
         mMediaLibrary.removeMediaUpdatedCb();
-        mBackgroundManager.release();
+        TvUtil.releaseBackgroundManager(mBackgroundManager);
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
index 0c83ac753..a1753af4d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
@@ -92,7 +92,7 @@ public class MediaItemDetailsFragment extends DetailsFragment implements Playbac
     }
 
     public void onPause() {
-        mBackgroundManager.release();
+        TvUtil.releaseBackgroundManager(mBackgroundManager);
         super.onPause();
         if (mService != null && mService.isPlaying())
             mService.stop();
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.java b/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.java
index 7cbc2922c..d99a29bf3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.java
@@ -20,6 +20,8 @@
  *****************************************************************************/
 package org.videolan.vlc.gui.tv;
 
+import android.animation.ValueAnimator;
+import android.annotation.TargetApi;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
@@ -46,6 +48,7 @@ import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
 import org.videolan.vlc.gui.tv.browser.VerticalGridActivity;
 import org.videolan.vlc.media.MediaUtils;
 
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Arrays;
 
@@ -53,6 +56,7 @@ import static org.videolan.vlc.gui.tv.browser.MusicFragment.AUDIO_CATEGORY;
 import static org.videolan.vlc.gui.tv.browser.MusicFragment.AUDIO_ITEM;
 import static org.videolan.vlc.gui.tv.browser.MusicFragment.CATEGORY_ALBUMS;
 
+ at TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 public class TvUtil {
 
     public static void applyOverscanMargin(Activity activity) {
@@ -169,4 +173,17 @@ public class TvUtil {
         bm.setColor(ContextCompat.getColor(VLCApplication.getAppContext(), R.color.tv_bg));
         bm.setDrawable(null);
     }
+
+    //See https://issuetracker.google.com/issues/37135111
+    public static void releaseBackgroundManager(BackgroundManager backgroundManager) {
+        Field field;
+        try {
+            field = backgroundManager.getClass().getDeclaredField("mAnimator");
+            field.setAccessible(true);
+            ValueAnimator valueAnimator = (ValueAnimator) field.get(backgroundManager);
+            if (valueAnimator != null && valueAnimator.isStarted())
+                valueAnimator.cancel();
+        } catch (Exception ignored) {}
+        backgroundManager.release();
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java
index 412f44e7b..6ba2565f1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.java
@@ -75,7 +75,7 @@ public abstract class MediaLibBrowserFragment extends GridFragment implements On
     @Override
     public void onPause() {
         super.onPause();
-        mBackgroundManager.release();
+        TvUtil.releaseBackgroundManager(mBackgroundManager);
     }
 
     public void refresh() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java
index 08a840353..3e6d9c927 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/SortedBrowserFragment.java
@@ -130,7 +130,7 @@ public abstract class SortedBrowserFragment extends BrowseFragment implements Br
     @Override
     public void onPause() {
         super.onPause();
-        mBackgroundManager.release();
+        TvUtil.releaseBackgroundManager(mBackgroundManager);
     }
 
     @Override



More information about the Android mailing list