Browse Source

Infer nullity

master
Anthony Restaino 9 years ago
parent
commit
4eb292f40f
  1. 2
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  2. 5
      app/src/main/java/acr/browser/lightning/app/AppModule.java
  3. 7
      app/src/main/java/acr/browser/lightning/app/BrowserApp.java
  4. 1
      app/src/main/java/acr/browser/lightning/async/AsyncExecutor.java
  5. 8
      app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java
  6. 3
      app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java
  7. 10
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  8. 10
      app/src/main/java/acr/browser/lightning/constant/HistoryPage.java
  9. 10
      app/src/main/java/acr/browser/lightning/constant/StartPage.java
  10. 2
      app/src/main/java/acr/browser/lightning/database/BookmarkLocalSync.java
  11. 15
      app/src/main/java/acr/browser/lightning/database/HistoryItem.java
  12. 14
      app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java
  13. 13
      app/src/main/java/acr/browser/lightning/utils/AdBlock.java
  14. 5
      app/src/main/java/acr/browser/lightning/utils/FileUtils.java
  15. 9
      app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java
  16. 7
      app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java
  17. 19
      app/src/main/java/acr/browser/lightning/utils/Utils.java
  18. 5
      app/src/main/java/acr/browser/lightning/utils/WebUtils.java
  19. 18
      app/src/main/java/acr/browser/lightning/view/LightningView.java

2
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -39,7 +39,7 @@ public class TabsManager { @@ -39,7 +39,7 @@ public class TabsManager {
private static final String BUNDLE_STORAGE = "SAVED_TABS.parcel";
private final List<LightningView> mTabList = new ArrayList<>(1);
private LightningView mCurrentTab;
@Nullable private LightningView mCurrentTab;
@Inject PreferenceManager mPreferenceManager;
@Inject Bus mEventBus;

5
app/src/main/java/acr/browser/lightning/app/AppModule.java

@ -2,6 +2,7 @@ package acr.browser.lightning.app; @@ -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; @@ -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 { @@ -32,11 +33,13 @@ public class AppModule {
return mApp.getApplicationContext();
}
@NonNull
@Provides
public Bus provideBus() {
return mBus;
}
@NonNull
@Provides
@Singleton
public I2PAndroidHelper provideI2PAndroidHelper() {

7
app/src/main/java/acr/browser/lightning/app/BrowserApp.java

@ -2,6 +2,7 @@ package acr.browser.lightning.app; @@ -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 { @@ -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 { @@ -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;
}

1
app/src/main/java/acr/browser/lightning/async/AsyncExecutor.java

@ -22,6 +22,7 @@ public class AsyncExecutor implements Executor { @@ -22,6 +22,7 @@ public class AsyncExecutor implements Executor {
private AsyncExecutor() {}
@NonNull
public static AsyncExecutor getInstance() {
return INSTANCE;
}

8
app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java

@ -6,6 +6,7 @@ import android.graphics.BitmapFactory; @@ -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<Void, Void, Bitmap> { @@ -25,10 +26,10 @@ public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
private static final String TAG = ImageDownloadTask.class.getSimpleName();
private final File mCacheDir;
private final WeakReference<ImageView> mFaviconImage;
private final HistoryItem mWeb;
@NonNull private final WeakReference<ImageView> 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<Void, Void, Bitmap> { @@ -44,6 +45,7 @@ public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
this.mCacheDir = BrowserApp.get(context).getCacheDir();
}
@Nullable
@Override
protected Bitmap doInBackground(Void... params) {
Bitmap mIcon = null;

3
app/src/main/java/acr/browser/lightning/bus/BrowserEvents.java

@ -1,5 +1,6 @@ @@ -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 { @@ -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;

10
app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java

@ -6,6 +6,8 @@ package acr.browser.lightning.constant; @@ -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<Void, Void, Void> { @@ -62,11 +64,11 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
private final File mCacheDir;
private final BookmarkManager mManager;
private final WeakReference<LightningView> mTabReference;
@NonNull private final WeakReference<LightningView> 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<Void, Void, Void> { @@ -106,7 +108,7 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
}
}
private void buildBookmarkPage(final String folder, final BookmarkManager manager) {
private void buildBookmarkPage(@Nullable final String folder, @NonNull final BookmarkManager manager) {
final List<HistoryItem> list = manager.getBookmarksFromFolder(folder, true);
final File bookmarkWebPage;
if (folder == null || folder.isEmpty()) {

10
app/src/main/java/acr/browser/lightning/constant/HistoryPage.java

@ -6,6 +6,7 @@ package acr.browser.lightning.constant; @@ -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<Void, Void, Void> { @@ -39,20 +40,21 @@ public class HistoryPage extends AsyncTask<Void, Void, Void> {
private static final String END = "</div></body></html>";
private final WeakReference<LightningView> mTabReference;
@NonNull private final WeakReference<LightningView> 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();

10
app/src/main/java/acr/browser/lightning/constant/StartPage.java

@ -5,6 +5,8 @@ package acr.browser.lightning.constant; @@ -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<Void, Void, Void> { @@ -52,21 +54,22 @@ public class StartPage extends AsyncTask<Void, Void, Void> {
private static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}</script></body></html>";
private final String mTitle;
@NonNull private final String mTitle;
private final File mFilesDir;
private final WeakReference<LightningView> mTabReference;
@NonNull private final WeakReference<LightningView> 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<Void, Void, Void> { @@ -88,6 +91,7 @@ public class StartPage extends AsyncTask<Void, Void, Void> {
*
* @return the URL to load
*/
@NonNull
private String getHomepage() {
StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2);
String icon;

2
app/src/main/java/acr/browser/lightning/database/BookmarkLocalSync.java

@ -26,7 +26,7 @@ public class BookmarkLocalSync { @@ -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;

15
app/src/main/java/acr/browser/lightning/database/HistoryItem.java

@ -29,7 +29,7 @@ public class HistoryItem implements Comparable<HistoryItem> { @@ -29,7 +29,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
// 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<HistoryItem> { @@ -64,7 +64,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
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<HistoryItem> { @@ -76,31 +76,35 @@ public class HistoryItem implements Comparable<HistoryItem> {
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<HistoryItem> { @@ -112,6 +116,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
return mIsFolder;
}
@NonNull
@Override
public String toString() {
return mTitle;
@ -127,7 +132,7 @@ public class HistoryItem implements Comparable<HistoryItem> { @@ -127,7 +132,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
}
@Override
public boolean equals(Object object) {
public boolean equals(@Nullable Object object) {
if (this == object) return true;
if (object == null) return false;

14
app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java

@ -56,7 +56,7 @@ public class LightningDialogBuilder { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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) {

13
app/src/main/java/acr/browser/lightning/utils/AdBlock.java

@ -2,6 +2,8 @@ package acr.browser.lightning.utils; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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

5
app/src/main/java/acr/browser/lightning/utils/FileUtils.java

@ -3,6 +3,7 @@ package acr.browser.lightning.utils; @@ -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 { @@ -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 { @@ -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 {

9
app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java

@ -2,6 +2,7 @@ package acr.browser.lightning.utils; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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)) {

7
app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java

@ -55,12 +55,12 @@ public class ThemeUtils { @@ -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 { @@ -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);
}
}

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

@ -112,7 +112,7 @@ public final class Utils { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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);

5
app/src/main/java/acr/browser/lightning/utils/WebUtils.java

@ -3,6 +3,7 @@ package acr.browser.lightning.utils; @@ -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 { @@ -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 { @@ -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);
}

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

@ -68,12 +68,12 @@ public class LightningView { @@ -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 { @@ -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 { @@ -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 { @@ -1076,14 +1076,14 @@ public class LightningView {
*/
private static class WebViewHandler extends Handler {
private final WeakReference<LightningView> mReference;
@NonNull private final WeakReference<LightningView> 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();

Loading…
Cancel
Save