[Android] Fix SnackBar not shown properly

Geoffrey Métais git at videolan.org
Wed Jul 19 19:45:39 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Jul 19 19:33:30 2017 +0200| [4ed4be4993645a30d7fc2f3d6d88b39072b60810] | committer: Geoffrey Métais

Fix SnackBar not shown properly

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

 .../src/org/videolan/vlc/gui/PlaylistActivity.java      |  2 +-
 .../vlc/gui/audio/AudioAlbumsSongsFragment.java         |  2 +-
 .../src/org/videolan/vlc/gui/helpers/UiTools.java       | 17 +++++++++++++----
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
index 23ded9d57..58f23ede5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.java
@@ -321,7 +321,7 @@ public class PlaylistActivity extends AudioPlayerContainerActivity implements IE
             return true;
         } else if (id == R.id.audio_list_browser_delete) {
             mAdapter.remove(media);
-            UiTools.snackerWithCancel(getWindow().getDecorView(), getString(R.string.file_deleted), new Runnable() {
+            UiTools.snackerWithCancel(mBinding.getRoot(), getString(R.string.file_deleted), new Runnable() {
                 @Override
                 public void run() {
                     deleteMedia(media);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index ac4367eea..34796f6bd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -222,7 +222,7 @@ public class AudioAlbumsSongsFragment extends BaseAudioBrowser implements SwipeR
 
             adapter.remove(mediaItem);
 
-            UiTools.snackerWithCancel(getView(), getString(R.string.file_deleted), new Runnable() {
+            UiTools.snackerWithCancel(mViewPager, getString(R.string.file_deleted), new Runnable() {
                 @Override
                 public void run() {
                     deleteMedia(mediaItem, true);
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index 33a891ed6..34baca22f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -23,6 +23,7 @@
 
 package org.videolan.vlc.gui.helpers;
 
+import android.annotation.TargetApi;
 import android.app.Activity;
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -58,6 +59,7 @@ import android.view.inputmethod.InputMethodManager;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.vlc.BuildConfig;
@@ -86,8 +88,12 @@ public class UiTools {
     }
 
     /** Print an on-screen message to alert the user */
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
     public static void snacker(@NonNull View view, @NonNull String message) {
-        Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
+        Snackbar snack = Snackbar.make(view, message, Snackbar.LENGTH_SHORT);
+        if (AndroidUtil.isLolliPopOrLater)
+            snack.getView().setElevation(view.getResources().getDimensionPixelSize(R.dimen.audio_player_elevation));
+        snack.show();
     }
 
     /** Print an on-screen message to alert the user, with undo action */
@@ -96,8 +102,9 @@ public class UiTools {
     }
 
     /** Print an on-screen message to alert the user, with undo action */
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
     public static void snackerWithCancel(@NonNull View view, @NonNull String message, @Nullable final Runnable action, @Nullable final Runnable cancelAction) {
-        Snackbar.make(view, message, DELETE_DURATION)
+        Snackbar snack = Snackbar.make(view, message, DELETE_DURATION)
                 .setAction(android.R.string.cancel, new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
@@ -106,8 +113,10 @@ public class UiTools {
                         if (cancelAction != null)
                             cancelAction.run();
                     }
-                })
-                .show();
+                });
+        if (AndroidUtil.isLolliPopOrLater)
+            snack.getView().setElevation(view.getResources().getDimensionPixelSize(R.dimen.audio_player_elevation));
+        snack.show();
         if (action != null)
             sHandler.postDelayed(action, DELETE_DURATION);
     }



More information about the Android mailing list