[Android] Replace some Toasts by Snackbars

Geoffrey Métais git at videolan.org
Fri Jun 5 11:12:48 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun  5 11:12:23 2015 +0200| [3dad7481ef5e64ec32ae4d3e48b8b034b90c219c] | committer: Geoffrey Métais

Replace some Toasts by Snackbars

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

 .../src/org/videolan/vlc/gui/DebugLogActivity.java    |   17 ++++++-----------
 .../src/org/videolan/vlc/gui/PreferencesActivity.java |    7 +++----
 .../videolan/vlc/gui/audio/AudioBrowserFragment.java  |    3 ---
 .../videolan/vlc/gui/browser/FileBrowserFragment.java |    4 ++--
 .../videolan/vlc/gui/video/VideoPlayerActivity.java   |    1 -
 vlc-android/src/org/videolan/vlc/util/Util.java       |   12 +++++++++---
 6 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/DebugLogActivity.java b/vlc-android/src/org/videolan/vlc/gui/DebugLogActivity.java
index b36ff4e..30e53a7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DebugLogActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DebugLogActivity.java
@@ -26,10 +26,10 @@ import android.view.View;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.ListView;
-import android.widget.Toast;
 
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
+import org.videolan.vlc.util.Util;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -132,7 +132,7 @@ public class DebugLogActivity extends Activity implements DebugLogService.Client
             android.text.ClipboardManager clipboard = (android.text.ClipboardManager)VLCApplication.getAppContext().getSystemService(CLIPBOARD_SERVICE);
             clipboard.setText(buffer);
 
-            Toast.makeText(DebugLogActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
+            Util.snacker(v.getRootView(), R.string.copied_to_clipboard);
         }
     };
 
@@ -168,16 +168,11 @@ public class DebugLogActivity extends Activity implements DebugLogService.Client
     @Override
     public void onSaved(boolean success, String path) {
         if (success) {
-            Toast.makeText(
-                    this,
-                    String.format(
-                            VLCApplication.getAppResources().getString(R.string.dump_logcat_success),
-                            path), Toast.LENGTH_LONG)
-                    .show();
+            Util.snacker(getWindow().getDecorView().findViewById(android.R.id.content), String.format(
+                    VLCApplication.getAppResources().getString(R.string.dump_logcat_success),
+                    path));
         } else {
-            Toast.makeText(this,
-                    R.string.dump_logcat_failure,
-                    Toast.LENGTH_LONG).show();
+            Util.snacker(getWindow().getDecorView().findViewById(android.R.id.content), R.string.dump_logcat_failure);
         }
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 4702767..38fedc8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -48,7 +48,6 @@ import android.view.ViewGroup;
 import android.view.Window;
 import android.widget.LinearLayout;
 import android.widget.ListView;
-import android.widget.Toast;
 
 import org.videolan.libvlc.util.HWDecoderUtil;
 import org.videolan.libvlc.LibVLC;
@@ -191,7 +190,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                         BitmapCache.getInstance().clear();
                         AudioUtil.clearCacheFolders();
                         setResult(RESULT_RESCAN);
-                        Toast.makeText(getBaseContext(), R.string.media_db_cleared, Toast.LENGTH_SHORT).show();
+                        Util.snacker(getWindow().getDecorView().findViewById(android.R.id.content), R.string.media_db_cleared);
                         return true;
                     }
                 });
@@ -257,7 +256,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
 
             @Override
             public boolean onPreferenceChange(Preference preference, Object newValue) {
-                Toast.makeText(getBaseContext(), R.string.set_locale_popup, Toast.LENGTH_SHORT).show();
+                Util.snacker(getWindow().getDecorView().findViewById(android.R.id.content), R.string.set_locale_popup);
                 return true;
             }
         });
@@ -363,7 +362,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                 if (dialog!=null) {
                     Window window = dialog.getWindow();
                     if (window != null) {
-                        ConstantState state = this.getWindow().getDecorView().getBackground().getConstantState();
+                        ConstantState state = this.getWindow().getDecorView().findViewById(android.R.id.content).getBackground().getConstantState();
                         if (state != null)
                             window.getDecorView().setBackgroundDrawable(state.newDrawable());
                     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 4aeb121..9febc3a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -47,7 +47,6 @@ import android.widget.ListView;
 import android.widget.PopupMenu;
 import android.widget.PopupMenu.OnMenuItemClickListener;
 import android.widget.TextView;
-import android.widget.Toast;
 
 import com.android.widget.SlidingTabLayout;
 
@@ -664,7 +663,6 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
                     MediaWrapper mw = fragment.mSongsAdapter.getItem(msg.arg1).mMediaList.get(0);
                     final String path = mw.getUri().getPath();
                     //Let's keep this toast while duration is not set correctly
-                    Toast.makeText(fragment.getActivity(), "deleting file", Toast.LENGTH_SHORT).show();
                     new Thread(new Runnable() {
                         public void run() {
                             Util.recursiveDelete(VLCApplication.getAppContext(), new File(path));
@@ -676,7 +674,6 @@ public class AudioBrowserFragment extends MediaBrowserFragment implements SwipeR
                 case DELETE_PLAYLIST:
                     AudioBrowserListAdapter.ListItem listItem = fragment.mPlaylistAdapter.getItem(msg.arg1);
                     //Let's keep this toast while duration is not set correctly
-                    Toast.makeText(fragment.getActivity(), "deleting playlist "+listItem.mTitle, Toast.LENGTH_SHORT).show();
                     if (!MediaDatabase.getInstance().playlistExists(listItem.mTitle)) { //File playlist
                         MediaWrapper media = listItem.mMediaList.get(0);
                         fragment.mMediaLibrary.getMediaItems().remove(media);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
index 1a6d635..29713bb 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.java
@@ -36,7 +36,6 @@ import android.support.v7.widget.AppCompatEditText;
 import android.text.InputType;
 import android.text.TextUtils;
 import android.view.MenuItem;
-import android.widget.Toast;
 
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.MediaDatabase;
@@ -44,6 +43,7 @@ import org.videolan.vlc.MediaWrapper;
 import org.videolan.vlc.R;
 import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.CustomDirectories;
+import org.videolan.vlc.util.Util;
 
 import java.io.File;
 
@@ -172,7 +172,7 @@ public class FileBrowserFragment extends BaseBrowserFragment {
                 String path = input.getText().toString().trim();
                 File f = new File(path);
                 if (!f.exists() || !f.isDirectory()) {
-                    Toast.makeText(context, getString(R.string.directorynotfound, path), Toast.LENGTH_SHORT).show();
+                    Util.snacker(getView(), getString(R.string.directorynotfound, path));
                     return;
                 }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 55b883f..5fccf63 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2073,7 +2073,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
                 mTime.setText(Strings.millisToString(progress));
                 showInfo(Strings.millisToString(progress));
             }
-
         }
     };
 
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 068b0e0..e32d9f6 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -31,11 +31,12 @@ import android.content.res.TypedArray;
 import android.net.Uri;
 import android.os.Build;
 import android.provider.MediaStore;
+import android.support.design.widget.Snackbar;
 import android.text.TextUtils.TruncateAt;
 import android.util.DisplayMetrics;
 import android.util.TypedValue;
+import android.view.View;
 import android.widget.TextView;
-import android.widget.Toast;
 
 import org.videolan.libvlc.LibVLC;
 import org.videolan.libvlc.Media;
@@ -64,8 +65,13 @@ public class Util {
     public static final String ACTION_SCAN_STOP = "org.videolan.vlc.gui.ScanStop";
 
     /** Print an on-screen message to alert the user */
-    public static void toaster(Context context, int stringId) {
-        Toast.makeText(context, stringId, Toast.LENGTH_SHORT).show();
+    public static void snacker(View view, int stringId) {
+        Snackbar.make(view, stringId, Snackbar.LENGTH_SHORT).show();
+    }
+
+    /** Print an on-screen message to alert the user */
+    public static void snacker(View view, String message) {
+        Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
     }
 
     public static int convertPxToDp(int px) {



More information about the Android mailing list