From f061a35472e1adcaff09fdab45d3fbde4e7e9527 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Sun, 19 Jul 2015 16:49:55 -0400 Subject: [PATCH] Snackbar >>>>>>> Toast --- .../browser/lightning/utils/ProxyUtils.java | 8 +++---- .../lightning/activity/BrowserActivity.java | 14 ++++------- .../lightning/database/BookmarkManager.java | 24 +++++++++---------- .../lightning/download/DownloadHandler.java | 2 +- .../fragment/PrivacySettingsFragment.java | 13 ++++------ .../acr/browser/lightning/utils/Utils.java | 14 +++++++---- .../browser/lightning/view/LightningView.java | 4 ---- 7 files changed, 37 insertions(+), 42 deletions(-) diff --git a/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java b/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java index 18cbd5a..10cf99f 100644 --- a/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java +++ b/app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java @@ -144,13 +144,13 @@ public class ProxyUtils { } - public boolean isProxyReady(Context context) { + public boolean isProxyReady(Activity activity) { if (mPreferences.getProxyChoice() == Constants.PROXY_I2P) { if (!mI2PHelper.isI2PAndroidRunning()) { - Utils.showToast(context, context.getString(R.string.i2p_not_running)); + Utils.showSnackbar(activity, R.string.i2p_not_running); return false; } else if (!mI2PHelper.areTunnelsActive()) { - Utils.showToast(context, context.getString(R.string.i2p_tunnels_not_ready)); + Utils.showSnackbar(activity, R.string.i2p_tunnels_not_ready); return false; } } @@ -203,7 +203,7 @@ public class ProxyUtils { case Constants.PROXY_ORBOT: if (!OrbotHelper.isOrbotInstalled(activity)) { choice = Constants.NO_PROXY; - Utils.showToast(activity, activity.getResources().getString(R.string.install_orbot)); + Utils.showSnackbar(activity, R.string.install_orbot); } break; diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index debe836..5eaae65 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -506,10 +506,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse ClipData clip = ClipData.newPlainText("label", mSearch.getText() .toString()); clipboard.setPrimaryClip(clip); - Utils.showToast( - mActivity, - mActivity.getResources().getString( - R.string.message_text_copied)); + Utils.showSnackbar(mActivity, R.string.message_text_copied); } else { refreshOrStop(); } @@ -598,7 +595,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse url = getIntent().getDataString(); if (url != null) { if (url.startsWith(Constants.FILE)) { - Utils.showToast(this, getResources().getString(R.string.message_blocked_local)); + Utils.showSnackbar(this, R.string.message_blocked_local); url = null; } } @@ -784,8 +781,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl()); clipboard.setPrimaryClip(clip); - Utils.showToast(mActivity, - mActivity.getResources().getString(R.string.message_link_copied)); + Utils.showSnackbar(mActivity, R.string.message_link_copied); } return true; case R.id.action_settings: @@ -1113,7 +1109,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse mCurrentView.loadUrl(url); } else if (url != null) { if (url.startsWith(Constants.FILE)) { - Utils.showToast(this, getResources().getString(R.string.message_blocked_local)); + Utils.showSnackbar(this, R.string.message_blocked_local); url = null; } newTab(url, true); @@ -1146,7 +1142,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse synchronized boolean newTab(String url, boolean show) { // Limit number of tabs for limited version of app if (!Constants.FULL_VERSION && mWebViewList.size() >= 10) { - Utils.showToast(this, this.getString(R.string.max_tabs)); + Utils.showSnackbar(this, R.string.max_tabs); return false; } mIsNewIntent = false; diff --git a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java index 3cdeef4..7dec8ad 100644 --- a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java +++ b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java @@ -1,5 +1,6 @@ package acr.browser.lightning.database; +import android.app.Activity; import android.content.Context; import android.database.Cursor; import android.os.Environment; @@ -320,7 +321,7 @@ public class BookmarkManager { * This method imports all bookmarks that are included in the device's * permanent bookmark storage */ - public synchronized void importBookmarksFromBrowser(Context context) { + public synchronized void importBookmarksFromBrowser(Activity activity) { if (PreferenceManager.getInstance().getSystemBrowserPresent()) { List bookmarkList = new ArrayList<>(); @@ -348,12 +349,11 @@ public class BookmarkManager { cursor.close(); addBookmarkList(bookmarkList); - Utils.showToast(context, - number + " " + mContext.getResources().getString(R.string.message_import)); + Utils.showSnackbar(activity, number + " " + mContext.getResources().getString(R.string.message_import)); } else { - Utils.createInformativeDialog(context, - mContext.getResources().getString(R.string.title_error), mContext - .getResources().getString(R.string.dialog_import_error)); + String title = activity.getResources().getString(R.string.title_error); + String message = activity.getResources().getString(R.string.dialog_import_error); + Utils.createInformativeDialog(activity, title, message); } } @@ -363,7 +363,7 @@ public class BookmarkManager { * * @param file the file to attempt to import bookmarks from */ - public synchronized void importBookmarksFromFile(File file, Context context) { + public synchronized void importBookmarksFromFile(File file, Activity activity) { if (file == null) { return; } @@ -384,13 +384,13 @@ public class BookmarkManager { number++; } addBookmarkList(list); - Utils.showToast(context, - number + " " + mContext.getResources().getString(R.string.message_import)); + String message = activity.getResources().getString(R.string.message_import); + Utils.showSnackbar(activity, number + " " + message); } catch (IOException | JSONException e) { e.printStackTrace(); - Utils.createInformativeDialog(context, - mContext.getResources().getString(R.string.title_error), mContext - .getResources().getString(R.string.import_bookmark_error)); + String title = activity.getResources().getString(R.string.title_error); + String message = activity.getResources().getString(R.string.import_bookmark_error); + Utils.createInformativeDialog(activity, title, message); } finally { Utils.close(bookmarksReader); } diff --git a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java index 41b6529..ffa30a3 100644 --- a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java +++ b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java @@ -200,7 +200,7 @@ public class DownloadHandler { } catch (IllegalArgumentException e) { // Probably got a bad URL or something e.printStackTrace(); - Utils.showToast(activity, R.string.cannot_download); + Utils.showSnackbar(activity, R.string.cannot_download); } } }.start(); diff --git a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java index 9e9b685..40229e8 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java @@ -4,7 +4,6 @@ package acr.browser.lightning.fragment; import android.app.Activity; -import android.content.Context; import android.content.DialogInterface; import android.os.Build; import android.os.Bundle; @@ -110,9 +109,9 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe private static class MessageHandler extends Handler { - final Context mHandlerContext; + final Activity mHandlerContext; - public MessageHandler(Context context) { + public MessageHandler(Activity context) { this.mHandlerContext = context; } @@ -120,12 +119,10 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe public void handleMessage(Message msg) { switch (msg.what) { case 1: - Utils.showToast(mHandlerContext, mHandlerContext.getResources() - .getString(R.string.message_clear_history)); + Utils.showSnackbar(mHandlerContext, R.string.message_clear_history); break; case 2: - Utils.showToast(mHandlerContext, mHandlerContext.getResources().getString( - R.string.message_cookies_cleared)); + Utils.showSnackbar(mHandlerContext, R.string.message_cookies_cleared); break; } super.handleMessage(msg); @@ -203,7 +200,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe WebView webView = new WebView(mActivity); webView.clearCache(true); webView.destroy(); - Utils.showToast(mActivity, getResources().getString(R.string.message_cache_cleared)); + Utils.showSnackbar(mActivity, R.string.message_cache_cleared); } @SuppressWarnings("deprecation") diff --git a/app/src/main/java/acr/browser/lightning/utils/Utils.java b/app/src/main/java/acr/browser/lightning/utils/Utils.java index 06eb6ac..fd44d63 100644 --- a/app/src/main/java/acr/browser/lightning/utils/Utils.java +++ b/app/src/main/java/acr/browser/lightning/utils/Utils.java @@ -84,12 +84,18 @@ public final class Utils { Toast.makeText(context, resource, Toast.LENGTH_SHORT).show(); } - public static void showSnackBar(View view, String message) { - Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); + public static void showSnackbar(Activity activity, @StringRes int resource) { + if (activity == null) return; + View view = activity.findViewById(android.R.id.content); + if (view == null) return; + Snackbar.make(view, resource, Snackbar.LENGTH_SHORT).show(); } - public static void showSnackBar(View view, @StringRes int resource) { - Snackbar.make(view, resource, Snackbar.LENGTH_SHORT).show(); + public static void showSnackbar(Activity activity, String message) { + if (activity == null) return; + View view = activity.findViewById(android.R.id.content); + if (view == null) return; + Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); } /** diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index 80ea1ea..953837f 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -1105,11 +1105,7 @@ public class LightningView { } else if (mAction == MotionEvent.ACTION_UP) { final float distance = (mY - mLocation); if (distance > SCROLL_UP_THRESHOLD && view.getScrollY() < SCROLL_UP_THRESHOLD) { -// if (mWebView.getScrollY() != 0) { mBrowserController.showActionBar(); -// } else { -// mBrowserController.toggleActionBar(); -// } } else if (distance < -SCROLL_UP_THRESHOLD) { mBrowserController.hideActionBar(); }