From 54026bf6ccf8ffb7f3d14ff11738936f5576c373 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Fri, 28 Apr 2017 22:24:21 -0400 Subject: [PATCH] Cleaning up unused code --- .../lightning/activity/BrowserActivity.java | 1 - .../lightning/activity/TabsManager.java | 11 --- .../lightning/database/HistoryDatabase.java | 1 - .../lightning/dialog/BrowserDialog.java | 22 ++--- .../download/LightningDownloadListener.java | 1 - .../lightning/favicon/FaviconModel.java | 1 - .../fragment/BookmarkSettingsFragment.java | 1 - .../browser/lightning/reading/Converter.java | 2 - .../lightning/search/SuggestionsManager.java | 2 - .../lightning/utils/DrawableUtils.java | 10 -- .../browser/lightning/utils/FileUtils.java | 1 - .../browser/lightning/utils/ThemeUtils.java | 2 - .../acr/browser/lightning/utils/UrlUtils.java | 94 +++---------------- 13 files changed, 17 insertions(+), 132 deletions(-) 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 096f606..d55dfa2 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -22,7 +22,6 @@ import android.media.MediaPlayer; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.os.Message; import android.provider.MediaStore; import android.support.annotation.ColorInt; diff --git a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java index 464449b..f72462a 100644 --- a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java +++ b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java @@ -528,17 +528,6 @@ public class TabsManager { }); } - /** - * Return the {@link WebView} associated to the current tab, - * or null if there is no current tab. - * - * @return a {@link WebView} or null if there is no current tab. - */ - @Nullable - public synchronized WebView getCurrentWebView() { - return mCurrentTab != null ? mCurrentTab.getWebView() : null; - } - /** * Returns the index of the current tab. * diff --git a/app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java b/app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java index 0b570f5..07ae7cc 100644 --- a/app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java +++ b/app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java @@ -20,7 +20,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; @Singleton @WorkerThread diff --git a/app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java b/app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java index 9a3f180..3d5da19 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java +++ b/app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java @@ -75,16 +75,11 @@ public class BrowserDialog { public abstract void onClick(); } - - public static void show(@NonNull Activity activity, @NonNull Item item, @Nullable Item... items) { - show(activity, null, item, items); - } - - public static void show(@NonNull Activity activity, @StringRes int title, @NonNull Item item, @Nullable Item... items) { - show(activity, activity.getString(title), item, items); + public static void show(@NonNull Activity activity, @StringRes int title, @NonNull Item... items) { + show(activity, activity.getString(title), items); } - public static void show(@NonNull Activity activity, @Nullable String title, @NonNull Item item, @Nullable Item... items) { + public static void show(@NonNull Activity activity, @Nullable String title, @NonNull Item... items) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); View layout = LayoutInflater.from(activity).inflate(R.layout.list_dialog, null); @@ -96,14 +91,9 @@ public class BrowserDialog { android.R.layout.simple_list_item_1); final List itemList = new ArrayList<>(1); - if (item.isConditionMet()) { - itemList.add(item); - } - if (items != null) { - for (Item it : items) { - if (it.isConditionMet()) { - itemList.add(it); - } + for (Item it : items) { + if (it.isConditionMet()) { + itemList.add(it); } } diff --git a/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java b/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java index c5a3aeb..28264b2 100644 --- a/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java +++ b/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java @@ -14,7 +14,6 @@ import android.webkit.URLUtil; import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; -import acr.browser.lightning.constant.Constants; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.preference.PreferenceManager; diff --git a/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java b/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java index 350e6b9..8900b18 100644 --- a/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java +++ b/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java @@ -20,7 +20,6 @@ import java.io.IOException; import javax.inject.Inject; import javax.inject.Singleton; -import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.utils.Utils; /** diff --git a/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java index f8e9081..e8c8da5 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java @@ -36,7 +36,6 @@ import javax.inject.Inject; import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; -import acr.browser.lightning.constant.Constants; import acr.browser.lightning.database.BookmarkLocalSync; import acr.browser.lightning.database.BookmarkLocalSync.Source; import acr.browser.lightning.database.BookmarkManager; diff --git a/app/src/main/java/acr/browser/lightning/reading/Converter.java b/app/src/main/java/acr/browser/lightning/reading/Converter.java index 5513342..6f35f8c 100644 --- a/app/src/main/java/acr/browser/lightning/reading/Converter.java +++ b/app/src/main/java/acr/browser/lightning/reading/Converter.java @@ -25,8 +25,6 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.Locale; -import acr.browser.lightning.constant.Constants; - /** * This class is not thread safe. Use one new instance every time due to * encoding variable. diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java index 0ee0aa0..2855f40 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java @@ -1,7 +1,6 @@ package acr.browser.lightning.search; import android.app.Application; -import android.content.Context; import android.support.annotation.NonNull; import com.anthonycr.bonsai.Single; @@ -10,7 +9,6 @@ import com.anthonycr.bonsai.SingleSubscriber; import java.util.List; -import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.database.HistoryItem; class SuggestionsManager { diff --git a/app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java b/app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java index 91d76a4..3bc3c12 100644 --- a/app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java @@ -78,16 +78,6 @@ public class DrawableUtils { (startB + (int) (fraction * (endB - startB))); } - public static Drawable resolveDrawableAttribute(@NonNull Context context, @AttrRes int res) { - int[] attribute = new int[]{res}; - int indexOfAttrTextSize = 0; - TypedValue typedValue = new TypedValue(); - TypedArray a = context.obtainStyledAttributes(typedValue.data, attribute); - Drawable drawable = a.getDrawable(indexOfAttrTextSize); - a.recycle(); - return drawable; - } - public static void setBackground(@NonNull View view, @Nullable Drawable drawable) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.setBackground(drawable); diff --git a/app/src/main/java/acr/browser/lightning/utils/FileUtils.java b/app/src/main/java/acr/browser/lightning/utils/FileUtils.java index e7b7c85..d099a03 100644 --- a/app/src/main/java/acr/browser/lightning/utils/FileUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/FileUtils.java @@ -19,7 +19,6 @@ import java.io.InputStreamReader; import java.io.PrintStream; import acr.browser.lightning.app.BrowserApp; -import acr.browser.lightning.constant.Constants; /** * A utility class containing helpful methods diff --git a/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java b/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java index df2f587..77bb8ca 100644 --- a/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java @@ -12,8 +12,6 @@ import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; import android.support.annotation.AttrRes; import android.support.annotation.ColorInt; import android.support.annotation.DrawableRes; diff --git a/app/src/main/java/acr/browser/lightning/utils/UrlUtils.java b/app/src/main/java/acr/browser/lightning/utils/UrlUtils.java index 2baa6bd..63ba798 100644 --- a/app/src/main/java/acr/browser/lightning/utils/UrlUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/UrlUtils.java @@ -33,44 +33,18 @@ import acr.browser.lightning.constant.StartPage; */ public class UrlUtils { private static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile( - "(?i)" + // switch on case insensitive matching - '(' + // begin group for schema - "(?:http|https|file)://" + - "|(?:inline|data|about|javascript):" + - "|(?:.*:.*@)" + - ')' + - "(.*)"); + "(?i)" + // switch on case insensitive matching + '(' + // begin group for schema + "(?:http|https|file)://" + + "|(?:inline|data|about|javascript):" + + "|(?:.*:.*@)" + + ')' + + "(.*)"); // Google search public final static String QUERY_PLACE_HOLDER = "%s"; - // Regular expression to strip http:// and optionally - // the trailing slash - private static final Pattern STRIP_URL_PATTERN = - Pattern.compile("^http://(.*?)/?$"); private UrlUtils() { /* cannot be instantiated */ } - /** - * Strips the provided url of preceding "http://" and any trailing "/". Does not - * strip "https://". If the provided string cannot be stripped, the original string - * is returned. - *

- * TODO: Put this in TextUtils to be used by other packages doing something similar. - * - * @param url a url to strip, like "http://www.google.com/" - * @return a stripped url like "www.google.com", or the original string if it could - * not be stripped - */ - @Nullable - public static String stripUrl(@Nullable String url) { - if (url == null) return null; - Matcher m = STRIP_URL_PATTERN.matcher(url); - if (m.matches()) { - return m.group(1); - } else { - return url; - } - } - /** * Attempts to determine whether user input is a URL or search * terms. Anything with a space is passed to search if canBeSearch is true. @@ -106,65 +80,19 @@ public class UrlUtils { } if (canBeSearch) { return URLUtil.composeSearchUrl(inUrl, - searchUrl, QUERY_PLACE_HOLDER); + searchUrl, QUERY_PLACE_HOLDER); } return ""; } - /* package */ - @NonNull - static String fixUrl(@NonNull String inUrl) { - // FIXME: Converting the url to lower case - // duplicates functionality in smartUrlFilter(). - // However, changing all current callers of fixUrl to - // call smartUrlFilter in addition may have unwanted - // consequences, and is deferred for now. - int colon = inUrl.indexOf(':'); - boolean allLower = true; - for (int index = 0; index < colon; index++) { - char ch = inUrl.charAt(index); - if (!Character.isLetter(ch)) { - break; - } - allLower &= Character.isLowerCase(ch); - if (index == colon - 1 && !allLower) { - inUrl = inUrl.substring(0, colon).toLowerCase() - + inUrl.substring(colon); - } - } - if (inUrl.startsWith("http://") || inUrl.startsWith("https://")) - return inUrl; - if (inUrl.startsWith("http:") || - inUrl.startsWith("https:")) { - if (inUrl.startsWith("http:/") || inUrl.startsWith("https:/")) { - inUrl = inUrl.replaceFirst("/", "//"); - } else inUrl = inUrl.replaceFirst(":", "://"); - } - return inUrl; - } - - // Returns the filtered URL. Cannot return null, but can return an empty string - /* package */ - @Nullable - static String filteredUrl(@Nullable String inUrl) { - if (inUrl == null) { - return ""; - } - if (inUrl.startsWith("content:") - || inUrl.startsWith("browser:")) { - return ""; - } - return inUrl; - } - /** * Returns whether the given url is the bookmarks/history page or a normal website */ public static boolean isSpecialUrl(@Nullable String url) { return url != null && url.startsWith(Constants.FILE) && - (url.endsWith(BookmarkPage.FILENAME) || - url.endsWith(HistoryPage.FILENAME) || - url.endsWith(StartPage.FILENAME)); + (url.endsWith(BookmarkPage.FILENAME) || + url.endsWith(HistoryPage.FILENAME) || + url.endsWith(StartPage.FILENAME)); } /**