Browse Source

Snackbar >>>>>>> Toast

master
Anthony Restaino 10 years ago
parent
commit
f061a35472
  1. 8
      app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java
  2. 14
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  3. 24
      app/src/main/java/acr/browser/lightning/database/BookmarkManager.java
  4. 2
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  5. 13
      app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java
  6. 14
      app/src/main/java/acr/browser/lightning/utils/Utils.java
  7. 4
      app/src/main/java/acr/browser/lightning/view/LightningView.java

8
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 (mPreferences.getProxyChoice() == Constants.PROXY_I2P) {
if (!mI2PHelper.isI2PAndroidRunning()) { if (!mI2PHelper.isI2PAndroidRunning()) {
Utils.showToast(context, context.getString(R.string.i2p_not_running)); Utils.showSnackbar(activity, R.string.i2p_not_running);
return false; return false;
} else if (!mI2PHelper.areTunnelsActive()) { } 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; return false;
} }
} }
@ -203,7 +203,7 @@ public class ProxyUtils {
case Constants.PROXY_ORBOT: case Constants.PROXY_ORBOT:
if (!OrbotHelper.isOrbotInstalled(activity)) { if (!OrbotHelper.isOrbotInstalled(activity)) {
choice = Constants.NO_PROXY; choice = Constants.NO_PROXY;
Utils.showToast(activity, activity.getResources().getString(R.string.install_orbot)); Utils.showSnackbar(activity, R.string.install_orbot);
} }
break; break;

14
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() ClipData clip = ClipData.newPlainText("label", mSearch.getText()
.toString()); .toString());
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
Utils.showToast( Utils.showSnackbar(mActivity, R.string.message_text_copied);
mActivity,
mActivity.getResources().getString(
R.string.message_text_copied));
} else { } else {
refreshOrStop(); refreshOrStop();
} }
@ -598,7 +595,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
url = getIntent().getDataString(); url = getIntent().getDataString();
if (url != null) { if (url != null) {
if (url.startsWith(Constants.FILE)) { 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; url = null;
} }
} }
@ -784,8 +781,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl()); ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl());
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
Utils.showToast(mActivity, Utils.showSnackbar(mActivity, R.string.message_link_copied);
mActivity.getResources().getString(R.string.message_link_copied));
} }
return true; return true;
case R.id.action_settings: case R.id.action_settings:
@ -1113,7 +1109,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
mCurrentView.loadUrl(url); mCurrentView.loadUrl(url);
} else if (url != null) { } else if (url != null) {
if (url.startsWith(Constants.FILE)) { 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; url = null;
} }
newTab(url, true); newTab(url, true);
@ -1146,7 +1142,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
synchronized boolean newTab(String url, boolean show) { synchronized boolean newTab(String url, boolean show) {
// Limit number of tabs for limited version of app // Limit number of tabs for limited version of app
if (!Constants.FULL_VERSION && mWebViewList.size() >= 10) { 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; return false;
} }
mIsNewIntent = false; mIsNewIntent = false;

24
app/src/main/java/acr/browser/lightning/database/BookmarkManager.java

@ -1,5 +1,6 @@
package acr.browser.lightning.database; package acr.browser.lightning.database;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.os.Environment; import android.os.Environment;
@ -320,7 +321,7 @@ public class BookmarkManager {
* This method imports all bookmarks that are included in the device's * This method imports all bookmarks that are included in the device's
* permanent bookmark storage * permanent bookmark storage
*/ */
public synchronized void importBookmarksFromBrowser(Context context) { public synchronized void importBookmarksFromBrowser(Activity activity) {
if (PreferenceManager.getInstance().getSystemBrowserPresent()) { if (PreferenceManager.getInstance().getSystemBrowserPresent()) {
List<HistoryItem> bookmarkList = new ArrayList<>(); List<HistoryItem> bookmarkList = new ArrayList<>();
@ -348,12 +349,11 @@ public class BookmarkManager {
cursor.close(); cursor.close();
addBookmarkList(bookmarkList); addBookmarkList(bookmarkList);
Utils.showToast(context, Utils.showSnackbar(activity, number + " " + mContext.getResources().getString(R.string.message_import));
number + " " + mContext.getResources().getString(R.string.message_import));
} else { } else {
Utils.createInformativeDialog(context, String title = activity.getResources().getString(R.string.title_error);
mContext.getResources().getString(R.string.title_error), mContext String message = activity.getResources().getString(R.string.dialog_import_error);
.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 * @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) { if (file == null) {
return; return;
} }
@ -384,13 +384,13 @@ public class BookmarkManager {
number++; number++;
} }
addBookmarkList(list); addBookmarkList(list);
Utils.showToast(context, String message = activity.getResources().getString(R.string.message_import);
number + " " + mContext.getResources().getString(R.string.message_import)); Utils.showSnackbar(activity, number + " " + message);
} catch (IOException | JSONException e) { } catch (IOException | JSONException e) {
e.printStackTrace(); e.printStackTrace();
Utils.createInformativeDialog(context, String title = activity.getResources().getString(R.string.title_error);
mContext.getResources().getString(R.string.title_error), mContext String message = activity.getResources().getString(R.string.import_bookmark_error);
.getResources().getString(R.string.import_bookmark_error)); Utils.createInformativeDialog(activity, title, message);
} finally { } finally {
Utils.close(bookmarksReader); Utils.close(bookmarksReader);
} }

2
app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

@ -200,7 +200,7 @@ public class DownloadHandler {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Probably got a bad URL or something // Probably got a bad URL or something
e.printStackTrace(); e.printStackTrace();
Utils.showToast(activity, R.string.cannot_download); Utils.showSnackbar(activity, R.string.cannot_download);
} }
} }
}.start(); }.start();

13
app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java

@ -4,7 +4,6 @@
package acr.browser.lightning.fragment; package acr.browser.lightning.fragment;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -110,9 +109,9 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
private static class MessageHandler extends Handler { private static class MessageHandler extends Handler {
final Context mHandlerContext; final Activity mHandlerContext;
public MessageHandler(Context context) { public MessageHandler(Activity context) {
this.mHandlerContext = context; this.mHandlerContext = context;
} }
@ -120,12 +119,10 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
switch (msg.what) { switch (msg.what) {
case 1: case 1:
Utils.showToast(mHandlerContext, mHandlerContext.getResources() Utils.showSnackbar(mHandlerContext, R.string.message_clear_history);
.getString(R.string.message_clear_history));
break; break;
case 2: case 2:
Utils.showToast(mHandlerContext, mHandlerContext.getResources().getString( Utils.showSnackbar(mHandlerContext, R.string.message_cookies_cleared);
R.string.message_cookies_cleared));
break; break;
} }
super.handleMessage(msg); super.handleMessage(msg);
@ -203,7 +200,7 @@ public class PrivacySettingsFragment extends PreferenceFragment implements Prefe
WebView webView = new WebView(mActivity); WebView webView = new WebView(mActivity);
webView.clearCache(true); webView.clearCache(true);
webView.destroy(); webView.destroy();
Utils.showToast(mActivity, getResources().getString(R.string.message_cache_cleared)); Utils.showSnackbar(mActivity, R.string.message_cache_cleared);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

14
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(); Toast.makeText(context, resource, Toast.LENGTH_SHORT).show();
} }
public static void showSnackBar(View view, String message) { public static void showSnackbar(Activity activity, @StringRes int resource) {
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show(); 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) { public static void showSnackbar(Activity activity, String message) {
Snackbar.make(view, resource, Snackbar.LENGTH_SHORT).show(); if (activity == null) return;
View view = activity.findViewById(android.R.id.content);
if (view == null) return;
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
} }
/** /**

4
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -1105,11 +1105,7 @@ public class LightningView {
} else if (mAction == MotionEvent.ACTION_UP) { } else if (mAction == MotionEvent.ACTION_UP) {
final float distance = (mY - mLocation); final float distance = (mY - mLocation);
if (distance > SCROLL_UP_THRESHOLD && view.getScrollY() < SCROLL_UP_THRESHOLD) { if (distance > SCROLL_UP_THRESHOLD && view.getScrollY() < SCROLL_UP_THRESHOLD) {
// if (mWebView.getScrollY() != 0) {
mBrowserController.showActionBar(); mBrowserController.showActionBar();
// } else {
// mBrowserController.toggleActionBar();
// }
} else if (distance < -SCROLL_UP_THRESHOLD) { } else if (distance < -SCROLL_UP_THRESHOLD) {
mBrowserController.hideActionBar(); mBrowserController.hideActionBar();
} }

Loading…
Cancel
Save