Browse Source

Snackbar >>>>>>> Toast

master
Anthony Restaino 9 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 { @@ -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 { @@ -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;

14
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -506,10 +506,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -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 @@ -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 @@ -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 @@ -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 @@ -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;

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

@ -1,5 +1,6 @@ @@ -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 { @@ -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<HistoryItem> bookmarkList = new ArrayList<>();
@ -348,12 +349,11 @@ public class BookmarkManager { @@ -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 { @@ -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 { @@ -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);
}

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

@ -200,7 +200,7 @@ public class DownloadHandler { @@ -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();

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

@ -4,7 +4,6 @@ @@ -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 @@ -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 @@ -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 @@ -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")

14
app/src/main/java/acr/browser/lightning/utils/Utils.java

@ -84,12 +84,18 @@ public final class Utils { @@ -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();
}
/**

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

@ -1105,11 +1105,7 @@ public class LightningView { @@ -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();
}

Loading…
Cancel
Save