From 4eb292f40f81df5c19d2740adafb1811c12c233a Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Wed, 27 Jan 2016 20:49:27 -0500 Subject: [PATCH] Infer nullity --- .../lightning/activity/TabsManager.java | 2 +- .../acr/browser/lightning/app/AppModule.java | 5 ++++- .../acr/browser/lightning/app/BrowserApp.java | 7 +++++-- .../lightning/async/AsyncExecutor.java | 1 + .../lightning/async/ImageDownloadTask.java | 8 +++++--- .../browser/lightning/bus/BrowserEvents.java | 3 ++- .../lightning/constant/BookmarkPage.java | 10 ++++++---- .../lightning/constant/HistoryPage.java | 10 ++++++---- .../browser/lightning/constant/StartPage.java | 10 +++++++--- .../lightning/database/BookmarkLocalSync.java | 2 +- .../lightning/database/HistoryItem.java | 15 ++++++++++----- .../dialog/LightningDialogBuilder.java | 14 +++++++------- .../acr/browser/lightning/utils/AdBlock.java | 13 ++++++++----- .../browser/lightning/utils/FileUtils.java | 5 +++-- .../browser/lightning/utils/ProxyUtils.java | 9 +++++---- .../browser/lightning/utils/ThemeUtils.java | 7 ++++--- .../acr/browser/lightning/utils/Utils.java | 19 ++++++++++--------- .../acr/browser/lightning/utils/WebUtils.java | 5 +++-- .../browser/lightning/view/LightningView.java | 18 +++++++++--------- 19 files changed, 97 insertions(+), 66 deletions(-) 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 ae3c21a..405752d 100644 --- a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java +++ b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java @@ -39,7 +39,7 @@ public class TabsManager { private static final String BUNDLE_STORAGE = "SAVED_TABS.parcel"; private final List mTabList = new ArrayList<>(1); - private LightningView mCurrentTab; + @Nullable private LightningView mCurrentTab; @Inject PreferenceManager mPreferenceManager; @Inject Bus mEventBus; diff --git a/app/src/main/java/acr/browser/lightning/app/AppModule.java b/app/src/main/java/acr/browser/lightning/app/AppModule.java index 701b10d..9a4811e 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppModule.java +++ b/app/src/main/java/acr/browser/lightning/app/AppModule.java @@ -2,6 +2,7 @@ package acr.browser.lightning.app; import android.app.Application; import android.content.Context; +import android.support.annotation.NonNull; import com.squareup.otto.Bus; @@ -15,7 +16,7 @@ import dagger.Provides; @Module public class AppModule { private final BrowserApp mApp; - private final Bus mBus; + @NonNull private final Bus mBus; public AppModule(BrowserApp app) { this.mApp = app; @@ -32,11 +33,13 @@ public class AppModule { return mApp.getApplicationContext(); } + @NonNull @Provides public Bus provideBus() { return mBus; } + @NonNull @Provides @Singleton public I2PAndroidHelper provideI2PAndroidHelper() { diff --git a/app/src/main/java/acr/browser/lightning/app/BrowserApp.java b/app/src/main/java/acr/browser/lightning/app/BrowserApp.java index be3905f..8075ea1 100644 --- a/app/src/main/java/acr/browser/lightning/app/BrowserApp.java +++ b/app/src/main/java/acr/browser/lightning/app/BrowserApp.java @@ -2,6 +2,7 @@ package acr.browser.lightning.app; import android.app.Application; import android.content.Context; +import android.support.annotation.NonNull; import com.squareup.leakcanary.LeakCanary; import com.squareup.otto.Bus; @@ -26,7 +27,8 @@ public class BrowserApp extends Application { LeakCanary.install(this); } - public static BrowserApp get(Context context) { + @NonNull + public static BrowserApp get(@NonNull Context context) { return (BrowserApp) context.getApplicationContext(); } @@ -34,11 +36,12 @@ public class BrowserApp extends Application { return mAppComponent; } + @NonNull public static Executor getIOThread() { return mIOThread; } - public static Bus getBus(Context context) { + public static Bus getBus(@NonNull Context context) { return get(context).mBus; } diff --git a/app/src/main/java/acr/browser/lightning/async/AsyncExecutor.java b/app/src/main/java/acr/browser/lightning/async/AsyncExecutor.java index 5dec5a2..7dea224 100644 --- a/app/src/main/java/acr/browser/lightning/async/AsyncExecutor.java +++ b/app/src/main/java/acr/browser/lightning/async/AsyncExecutor.java @@ -22,6 +22,7 @@ public class AsyncExecutor implements Executor { private AsyncExecutor() {} + @NonNull public static AsyncExecutor getInstance() { return INSTANCE; } diff --git a/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java b/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java index 23aafdb..1a2fd6c 100644 --- a/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java +++ b/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java @@ -6,6 +6,7 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.AsyncTask; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.Log; import android.widget.ImageView; @@ -25,10 +26,10 @@ public class ImageDownloadTask extends AsyncTask { private static final String TAG = ImageDownloadTask.class.getSimpleName(); private final File mCacheDir; - private final WeakReference mFaviconImage; - private final HistoryItem mWeb; + @NonNull private final WeakReference mFaviconImage; + @NonNull private final HistoryItem mWeb; private final String mUrl; - private final Bitmap mDefaultBitmap; + @NonNull private final Bitmap mDefaultBitmap; public ImageDownloadTask(@NonNull ImageView bmImage, @NonNull HistoryItem web, @@ -44,6 +45,7 @@ public class ImageDownloadTask extends AsyncTask { this.mCacheDir = BrowserApp.get(context).getCacheDir(); } + @Nullable @Override protected Bitmap doInBackground(Void... params) { Bitmap mIcon = null; diff --git a/app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java b/app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java index 67949c4..4354244 100644 --- a/app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java +++ b/app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java @@ -1,5 +1,6 @@ package acr.browser.lightning.bus; +import android.support.annotation.Nullable; import android.support.annotation.StringRes; public final class BrowserEvents { @@ -53,7 +54,7 @@ public final class BrowserEvents { * Notify the Browser to display a SnackBar in the main activity */ public static class ShowSnackBarMessage { - public final String message; + @Nullable public final String message; @StringRes public final int stringRes; diff --git a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java index 7f75839..3bdcec4 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -6,6 +6,8 @@ package acr.browser.lightning.constant; import android.app.Application; import android.graphics.Bitmap; import android.os.AsyncTask; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import java.io.File; import java.io.FileNotFoundException; @@ -62,11 +64,11 @@ public final class BookmarkPage extends AsyncTask { private final File mCacheDir; private final BookmarkManager mManager; - private final WeakReference mTabReference; + @NonNull private final WeakReference mTabReference; private final Bitmap mFolderIcon; - private final String mTitle; + @NonNull private final String mTitle; - public BookmarkPage(LightningView tab, Application app, BookmarkManager manager, Bitmap folderIcon) { + public BookmarkPage(LightningView tab, @NonNull Application app, BookmarkManager manager, Bitmap folderIcon) { mFilesDir = app.getFilesDir(); mCacheDir = app.getCacheDir(); mTitle = app.getString(R.string.action_bookmarks); @@ -106,7 +108,7 @@ public final class BookmarkPage extends AsyncTask { } } - private void buildBookmarkPage(final String folder, final BookmarkManager manager) { + private void buildBookmarkPage(@Nullable final String folder, @NonNull final BookmarkManager manager) { final List list = manager.getBookmarksFromFolder(folder, true); final File bookmarkWebPage; if (folder == null || folder.isEmpty()) { diff --git a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java index 6069173..fc4b75e 100644 --- a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java @@ -6,6 +6,7 @@ package acr.browser.lightning.constant; import android.app.Application; import android.os.AsyncTask; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import java.io.File; import java.io.FileWriter; @@ -39,20 +40,21 @@ public class HistoryPage extends AsyncTask { private static final String END = ""; - private final WeakReference mTabReference; + @NonNull private final WeakReference mTabReference; private final File mFilesDir; - private final String mTitle; + @NonNull private final String mTitle; private final HistoryDatabase mHistoryDatabase; - private String mHistoryUrl = null; + @Nullable private String mHistoryUrl = null; - public HistoryPage(LightningView tab, Application app, HistoryDatabase database) { + public HistoryPage(LightningView tab, @NonNull Application app, HistoryDatabase database) { mTabReference = new WeakReference<>(tab); mFilesDir = app.getFilesDir(); mTitle = app.getString(R.string.action_history); mHistoryDatabase = database; } + @Nullable @Override protected Void doInBackground(Void... params) { mHistoryUrl = getHistoryPage(); diff --git a/app/src/main/java/acr/browser/lightning/constant/StartPage.java b/app/src/main/java/acr/browser/lightning/constant/StartPage.java index b575b56..423fc67 100644 --- a/app/src/main/java/acr/browser/lightning/constant/StartPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/StartPage.java @@ -5,6 +5,8 @@ package acr.browser.lightning.constant; import android.app.Application; import android.os.AsyncTask; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import java.io.File; import java.io.FileWriter; @@ -52,21 +54,22 @@ public class StartPage extends AsyncTask { private static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}"; - private final String mTitle; + @NonNull private final String mTitle; private final File mFilesDir; - private final WeakReference mTabReference; + @NonNull private final WeakReference mTabReference; @Inject PreferenceManager mPreferenceManager; private String mStartpageUrl; - public StartPage(LightningView tab, Application app) { + public StartPage(LightningView tab, @NonNull Application app) { BrowserApp.getAppComponent().inject(this); mTitle = app.getString(R.string.home); mFilesDir = app.getFilesDir(); mTabReference = new WeakReference<>(tab); } + @Nullable @Override protected Void doInBackground(Void... params) { mStartpageUrl = getHomepage(); @@ -88,6 +91,7 @@ public class StartPage extends AsyncTask { * * @return the URL to load */ + @NonNull private String getHomepage() { StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2); String icon; diff --git a/app/src/main/java/acr/browser/lightning/database/BookmarkLocalSync.java b/app/src/main/java/acr/browser/lightning/database/BookmarkLocalSync.java index 468210d..0dc5bed 100644 --- a/app/src/main/java/acr/browser/lightning/database/BookmarkLocalSync.java +++ b/app/src/main/java/acr/browser/lightning/database/BookmarkLocalSync.java @@ -26,7 +26,7 @@ public class BookmarkLocalSync { private static final String COLUMN_URL = "url"; private static final String COLUMN_BOOKMARK = "bookmark"; - private final Context mContext; + @NonNull private final Context mContext; public BookmarkLocalSync(@NonNull Context context) { mContext = context; diff --git a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java index dcc8bc1..f3436ec 100644 --- a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java +++ b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java @@ -29,7 +29,7 @@ public class HistoryItem implements Comparable { // Empty constructor public HistoryItem() {} - public HistoryItem(HistoryItem item) { + public HistoryItem(@NonNull HistoryItem item) { this.mUrl = item.mUrl; this.mTitle = item.mTitle; this.mFolder = item.mFolder; @@ -64,7 +64,7 @@ public class HistoryItem implements Comparable { mBitmap = image; } - public void setFolder(String folder) { + public void setFolder(@Nullable String folder) { mFolder = (folder == null) ? "" : folder; } @@ -76,31 +76,35 @@ public class HistoryItem implements Comparable { return mOrder; } + @NonNull public String getFolder() { return mFolder; } + @Nullable public Bitmap getBitmap() { return mBitmap; } // getting name + @NonNull public String getUrl() { return this.mUrl; } // setting name - public void setUrl(String url) { + public void setUrl(@Nullable String url) { this.mUrl = (url == null) ? "" : url; } // getting phone number + @NonNull public String getTitle() { return this.mTitle; } // setting phone number - public void setTitle(String title) { + public void setTitle(@Nullable String title) { this.mTitle = (title == null) ? "" : title; } @@ -112,6 +116,7 @@ public class HistoryItem implements Comparable { return mIsFolder; } + @NonNull @Override public String toString() { return mTitle; @@ -127,7 +132,7 @@ public class HistoryItem implements Comparable { } @Override - public boolean equals(Object object) { + public boolean equals(@Nullable Object object) { if (this == object) return true; if (object == null) return false; diff --git a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java index e86d3cb..25279f0 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java +++ b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java @@ -56,7 +56,7 @@ public class LightningDialogBuilder { * @param context used to show the dialog * @param url the long pressed url */ - public void showLongPressedDialogForBookmarkUrl(final Context context, final String url) { + public void showLongPressedDialogForBookmarkUrl(@NonNull final Context context, @NonNull final String url) { final HistoryItem item; if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) { // TODO hacky, make a better bookmark mechanism in the future @@ -80,7 +80,7 @@ public class LightningDialogBuilder { } } - public void showLongPressedDialogForBookmarkUrl(final Context context, final HistoryItem item) { + public void showLongPressedDialogForBookmarkUrl(@NonNull final Context context, @NonNull final HistoryItem item) { final DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override @@ -111,7 +111,7 @@ public class LightningDialogBuilder { .show(); } - private void showEditBookmarkDialog(final Context context, final HistoryItem item) { + private void showEditBookmarkDialog(@NonNull final Context context, @NonNull final HistoryItem item) { final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(context); editBookmarkDialog.setTitle(R.string.title_edit_bookmark); final View dialogLayout = View.inflate(context, R.layout.dialog_edit_bookmark, null); @@ -146,7 +146,7 @@ public class LightningDialogBuilder { editBookmarkDialog.show(); } - public void showBookmarkFolderLongPressedDialog(final Context context, final HistoryItem item) { + public void showBookmarkFolderLongPressedDialog(@NonNull final Context context, @NonNull final HistoryItem item) { // assert item.isFolder(); final DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @@ -175,7 +175,7 @@ public class LightningDialogBuilder { .show(); } - private void showRenameFolderDialog(final Context context, final HistoryItem item) { + private void showRenameFolderDialog(@NonNull final Context context, @NonNull final HistoryItem item) { // assert item.isFolder(); final AlertDialog.Builder editFolderDialog = new AlertDialog.Builder(context); editFolderDialog.setTitle(R.string.title_rename_folder); @@ -208,7 +208,7 @@ public class LightningDialogBuilder { editFolderDialog.show(); } - public void showLongPressedHistoryLinkDialog(final Context context, final String url) { + public void showLongPressedHistoryLinkDialog(final Context context, @NonNull final String url) { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -270,7 +270,7 @@ public class LightningDialogBuilder { .show(); } - public void showLongPressLinkDialog(final Context context, final String url) { + public void showLongPressLinkDialog(@NonNull final Context context, final String url) { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/app/src/main/java/acr/browser/lightning/utils/AdBlock.java b/app/src/main/java/acr/browser/lightning/utils/AdBlock.java index a568d1e..74eed5e 100644 --- a/app/src/main/java/acr/browser/lightning/utils/AdBlock.java +++ b/app/src/main/java/acr/browser/lightning/utils/AdBlock.java @@ -2,6 +2,8 @@ package acr.browser.lightning.utils; import android.content.Context; import android.content.res.AssetManager; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.Log; import java.io.BufferedReader; @@ -40,7 +42,7 @@ public class AdBlock { @Inject PreferenceManager mPreferenceManager; @Inject - public AdBlock(Context context) { + public AdBlock(@NonNull Context context) { BrowserApp.getAppComponent().inject(this); if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) { loadHostsFile(context); @@ -52,7 +54,7 @@ public class AdBlock { mBlockAds = mPreferenceManager.getAdBlockEnabled(); } - private void loadBlockedDomainsList(final Context context) { + private void loadBlockedDomainsList(@NonNull final Context context) { Thread thread = new Thread(new Runnable() { @Override @@ -85,7 +87,7 @@ public class AdBlock { * @param url the URL to check for being an ad * @return true if it is an ad, false if it is not an ad */ - public boolean isAd(String url) { + public boolean isAd(@Nullable String url) { if (!mBlockAds || url == null) { return false; } @@ -112,7 +114,8 @@ public class AdBlock { * @return returns the domain * @throws URISyntaxException throws an exception if the string cannot form a URI */ - private static String getDomainName(String url) throws URISyntaxException { + @NonNull + private static String getDomainName(@NonNull String url) throws URISyntaxException { int index = url.indexOf('/', 8); if (index != -1) { url = url.substring(0, index); @@ -136,7 +139,7 @@ public class AdBlock { * * @param context the context needed to read the file */ - private void loadHostsFile(final Context context) { + private void loadHostsFile(@NonNull final Context context) { Thread thread = new Thread(new Runnable() { @Override 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 294b643..d1287ec 100644 --- a/app/src/main/java/acr/browser/lightning/utils/FileUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/FileUtils.java @@ -3,6 +3,7 @@ package acr.browser.lightning.utils; import android.app.Application; import android.os.Bundle; import android.os.Parcel; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; @@ -29,7 +30,7 @@ public class FileUtils { * @param bundle the bundle to store in persistent storage. * @param name the name of the file to store the bundle in. */ - public static void writeBundleToStorage(Application app, Bundle bundle, String name) { + public static void writeBundleToStorage(@NonNull Application app, Bundle bundle, @NonNull String name) { File outputFile = new File(app.getFilesDir(), name); FileOutputStream outputStream = null; try { @@ -58,7 +59,7 @@ public class FileUtils { * or null if the method was unable to read the Bundle from storage. */ @Nullable - public static Bundle readBundleFromStorage(Application app, String name) { + public static Bundle readBundleFromStorage(@NonNull Application app, @NonNull String name) { File inputFile = new File(app.getFilesDir(), name); FileInputStream inputStream = null; try { diff --git a/app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java b/app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java index 3463568..a703737 100644 --- a/app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java @@ -2,6 +2,7 @@ package acr.browser.lightning.utils; import android.app.Activity; import android.content.DialogInterface; +import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; import android.util.Log; @@ -39,7 +40,7 @@ public class ProxyUtils { * If Orbot/Tor or I2P is installed, prompt the user if they want to enable * proxying for this session */ - public void checkForProxy(final Activity activity) { + public void checkForProxy(@NonNull final Activity activity) { boolean useProxy = mPreferences.getUseProxy(); final boolean orbotInstalled = OrbotHelper.isOrbotInstalled(activity); @@ -102,7 +103,7 @@ public class ProxyUtils { /* * Initialize WebKit Proxying */ - private void initializeProxy(Activity activity) { + private void initializeProxy(@NonNull Activity activity) { String host; int port; @@ -154,7 +155,7 @@ public class ProxyUtils { return true; } - public void updateProxySettings(Activity activity) { + public void updateProxySettings(@NonNull Activity activity) { if (mPreferences.getUseProxy()) { initializeProxy(activity); } else { @@ -187,7 +188,7 @@ public class ProxyUtils { } } - public static int setProxyChoice(int choice, Activity activity) { + public static int setProxyChoice(int choice, @NonNull Activity activity) { switch (choice) { case Constants.PROXY_ORBOT: if (!OrbotHelper.isOrbotInstalled(activity)) { 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 c12ff69..047be39 100644 --- a/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java @@ -55,12 +55,12 @@ public class ThemeUtils { return ContextCompat.getColor(context, R.color.icon_dark_theme); } - public static void themeImageView(ImageView icon, Context context, boolean dark) { + public static void themeImageView(@NonNull ImageView icon, @NonNull Context context, boolean dark) { int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context); icon.setColorFilter(color, PorterDuff.Mode.SRC_IN); } - public static Bitmap getThemedBitmap(Context context, @DrawableRes int res, boolean dark) { + public static Bitmap getThemedBitmap(@NonNull Context context, @DrawableRes int res, boolean dark) { int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context); Bitmap sourceBitmap = BitmapFactory.decodeResource(context.getResources(), res); Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(), Bitmap.Config.ARGB_8888); @@ -94,13 +94,14 @@ public class ThemeUtils { return drawable; } + @NonNull public static ColorDrawable getSelectedBackground(@NonNull Context context, boolean dark) { @ColorInt final int color = (dark) ? ContextCompat.getColor(context, R.color.selected_dark) : ContextCompat.getColor(context, R.color.selected_light); return new ColorDrawable(color); } - public static int getTextColor(Context context) { + public static int getTextColor(@NonNull Context context) { return getColor(context, android.R.attr.editTextColor); } } 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 d02ddc0..70458c1 100644 --- a/app/src/main/java/acr/browser/lightning/utils/Utils.java +++ b/app/src/main/java/acr/browser/lightning/utils/Utils.java @@ -112,7 +112,7 @@ public final class Utils { * @param title the title of the dialog. * @param message the message of the dialog. */ - public static void createInformativeDialog(Activity activity, @StringRes int title, @StringRes int message) { + public static void createInformativeDialog(@NonNull Activity activity, @StringRes int title, @StringRes int message) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(title); builder.setMessage(message) @@ -170,6 +170,7 @@ public final class Utils { * could not be extracted. The domain name may include * HTTPS if the URL is an SSL supported URL. */ + @Nullable public static String getDomainName(@Nullable String url) { if (url == null || url.isEmpty()) return ""; @@ -198,11 +199,11 @@ public final class Utils { return domain.startsWith("www.") ? domain.substring(4) : domain; } - public static String[] getArray(String input) { + public static String[] getArray(@NonNull String input) { return input.split(Constants.SEPARATOR); } - public static void trimCache(Context context) { + public static void trimCache(@NonNull Context context) { try { File dir = context.getCacheDir(); @@ -214,7 +215,7 @@ public final class Utils { } } - private static boolean deleteDir(File dir) { + private static boolean deleteDir(@Nullable File dir) { if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (String aChildren : children) { @@ -235,7 +236,7 @@ public final class Utils { * @param bitmap is the bitmap to pad. * @return the padded bitmap. */ - public static Bitmap padFavicon(Bitmap bitmap) { + public static Bitmap padFavicon(@NonNull Bitmap bitmap) { int padding = Utils.dpToPx(4); Bitmap paddedBitmap = Bitmap.createBitmap(bitmap.getWidth() + padding, bitmap.getHeight() @@ -296,7 +297,7 @@ public final class Utils { * @param context the context needed to obtain the PackageManager * @return true if flash is installed, false otherwise */ - public static boolean isFlashInstalled(Context context) { + public static boolean isFlashInstalled(@NonNull Context context) { try { PackageManager pm = context.getPackageManager(); ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0); @@ -315,7 +316,7 @@ public final class Utils { * * @param closeable the object to close */ - public static void close(Closeable closeable) { + public static void close(@Nullable Closeable closeable) { if (closeable == null) return; try { @@ -332,7 +333,7 @@ public final class Utils { * * @param cursor the cursor to close */ - public static void close(Cursor cursor) { + public static void close(@Nullable Cursor cursor) { if (cursor == null) { return; } @@ -350,7 +351,7 @@ public final class Utils { * @param canvas the canvas to draw upon * @param color the color to use to draw the tab */ - public static void drawTrapezoid(Canvas canvas, int color, boolean withShader) { + public static void drawTrapezoid(@NonNull Canvas canvas, int color, boolean withShader) { Paint paint = new Paint(); paint.setColor(color); diff --git a/app/src/main/java/acr/browser/lightning/utils/WebUtils.java b/app/src/main/java/acr/browser/lightning/utils/WebUtils.java index 9bb3f20..1d165d4 100644 --- a/app/src/main/java/acr/browser/lightning/utils/WebUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/WebUtils.java @@ -3,6 +3,7 @@ package acr.browser.lightning.utils; import android.content.Context; import android.os.Build; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; import android.webkit.WebIconDatabase; @@ -33,7 +34,7 @@ public class WebUtils { WebStorage.getInstance().deleteAllData(); } - public static void clearHistory(@NonNull Context context, HistoryDatabase historyDatabase) { + public static void clearHistory(@NonNull Context context, @NonNull HistoryDatabase historyDatabase) { historyDatabase.deleteHistory(); WebViewDatabase m = WebViewDatabase.getInstance(context); m.clearFormData(); @@ -47,7 +48,7 @@ public class WebUtils { Utils.trimCache(context); } - public static void clearCache(WebView view) { + public static void clearCache(@Nullable WebView view) { if (view == null) return; view.clearCache(true); } 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 383c541..a2ccaa9 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -68,12 +68,12 @@ public class LightningView { public static final String HEADER_WAP_PROFILE = "X-Wap-Profile"; private static final String HEADER_DNT = "DNT"; - private final LightningViewTitle mTitle; - private WebView mWebView; + @NonNull private final LightningViewTitle mTitle; + @Nullable private WebView mWebView; private final boolean mIsIncognitoTab; - private final UIController mUIController; - private final GestureDetector mGestureDetector; - private final Activity mActivity; + @NonNull private final UIController mUIController; + @NonNull private final GestureDetector mGestureDetector; + @NonNull private final Activity mActivity; private static String mHomepage; private static String mDefaultUserAgent; private final Paint mPaint = new Paint(); @@ -99,7 +99,7 @@ public class LightningView { @Inject BookmarkManager mBookmarkManager; @SuppressLint("NewApi") - public LightningView(Activity activity, String url, boolean isIncognito) { + public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) { BrowserApp.getAppComponent().inject(this); mActivity = activity; mUIController = (UIController) activity; @@ -984,7 +984,7 @@ public class LightningView { @SuppressLint("ClickableViewAccessibility") @Override - public boolean onTouch(View view, MotionEvent arg1) { + public boolean onTouch(@Nullable View view, @NonNull MotionEvent arg1) { if (view == null) return false; @@ -1076,14 +1076,14 @@ public class LightningView { */ private static class WebViewHandler extends Handler { - private final WeakReference mReference; + @NonNull private final WeakReference mReference; public WebViewHandler(LightningView view) { mReference = new WeakReference<>(view); } @Override - public void handleMessage(Message msg) { + public void handleMessage(@NonNull Message msg) { super.handleMessage(msg); final String url = msg.getData().getString("url"); LightningView view = mReference.get();