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 {
private static final String BUNDLE_STORAGE = "SAVED_TABS.parcel"; private static final String BUNDLE_STORAGE = "SAVED_TABS.parcel";
private final List<LightningView> mTabList = new ArrayList<>(1); private final List<LightningView> mTabList = new ArrayList<>(1);
private LightningView mCurrentTab; @Nullable private LightningView mCurrentTab;
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferenceManager;
@Inject Bus mEventBus; @Inject Bus mEventBus;

5
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.app.Application;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
@ -15,7 +16,7 @@ import dagger.Provides;
@Module @Module
public class AppModule { public class AppModule {
private final BrowserApp mApp; private final BrowserApp mApp;
private final Bus mBus; @NonNull private final Bus mBus;
public AppModule(BrowserApp app) { public AppModule(BrowserApp app) {
this.mApp = app; this.mApp = app;
@ -32,11 +33,13 @@ public class AppModule {
return mApp.getApplicationContext(); return mApp.getApplicationContext();
} }
@NonNull
@Provides @Provides
public Bus provideBus() { public Bus provideBus() {
return mBus; return mBus;
} }
@NonNull
@Provides @Provides
@Singleton @Singleton
public I2PAndroidHelper provideI2PAndroidHelper() { public I2PAndroidHelper provideI2PAndroidHelper() {

7
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.app.Application;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull;
import com.squareup.leakcanary.LeakCanary; import com.squareup.leakcanary.LeakCanary;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
@ -26,7 +27,8 @@ public class BrowserApp extends Application {
LeakCanary.install(this); LeakCanary.install(this);
} }
public static BrowserApp get(Context context) { @NonNull
public static BrowserApp get(@NonNull Context context) {
return (BrowserApp) context.getApplicationContext(); return (BrowserApp) context.getApplicationContext();
} }
@ -34,11 +36,12 @@ public class BrowserApp extends Application {
return mAppComponent; return mAppComponent;
} }
@NonNull
public static Executor getIOThread() { public static Executor getIOThread() {
return mIOThread; return mIOThread;
} }
public static Bus getBus(Context context) { public static Bus getBus(@NonNull Context context) {
return get(context).mBus; return get(context).mBus;
} }

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

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

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

@ -6,6 +6,7 @@ import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import android.widget.ImageView; import android.widget.ImageView;
@ -25,10 +26,10 @@ public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
private static final String TAG = ImageDownloadTask.class.getSimpleName(); private static final String TAG = ImageDownloadTask.class.getSimpleName();
private final File mCacheDir; private final File mCacheDir;
private final WeakReference<ImageView> mFaviconImage; @NonNull private final WeakReference<ImageView> mFaviconImage;
private final HistoryItem mWeb; @NonNull private final HistoryItem mWeb;
private final String mUrl; private final String mUrl;
private final Bitmap mDefaultBitmap; @NonNull private final Bitmap mDefaultBitmap;
public ImageDownloadTask(@NonNull ImageView bmImage, public ImageDownloadTask(@NonNull ImageView bmImage,
@NonNull HistoryItem web, @NonNull HistoryItem web,
@ -44,6 +45,7 @@ public class ImageDownloadTask extends AsyncTask<Void, Void, Bitmap> {
this.mCacheDir = BrowserApp.get(context).getCacheDir(); this.mCacheDir = BrowserApp.get(context).getCacheDir();
} }
@Nullable
@Override @Override
protected Bitmap doInBackground(Void... params) { protected Bitmap doInBackground(Void... params) {
Bitmap mIcon = null; Bitmap mIcon = null;

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

@ -1,5 +1,6 @@
package acr.browser.lightning.bus; package acr.browser.lightning.bus;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
public final class BrowserEvents { public final class BrowserEvents {
@ -53,7 +54,7 @@ public final class BrowserEvents {
* Notify the Browser to display a SnackBar in the main activity * Notify the Browser to display a SnackBar in the main activity
*/ */
public static class ShowSnackBarMessage { public static class ShowSnackBarMessage {
public final String message; @Nullable public final String message;
@StringRes @StringRes
public final int 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;
import android.app.Application; import android.app.Application;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -62,11 +64,11 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
private final File mCacheDir; private final File mCacheDir;
private final BookmarkManager mManager; private final BookmarkManager mManager;
private final WeakReference<LightningView> mTabReference; @NonNull private final WeakReference<LightningView> mTabReference;
private final Bitmap mFolderIcon; 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(); mFilesDir = app.getFilesDir();
mCacheDir = app.getCacheDir(); mCacheDir = app.getCacheDir();
mTitle = app.getString(R.string.action_bookmarks); mTitle = app.getString(R.string.action_bookmarks);
@ -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 List<HistoryItem> list = manager.getBookmarksFromFolder(folder, true);
final File bookmarkWebPage; final File bookmarkWebPage;
if (folder == null || folder.isEmpty()) { 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;
import android.app.Application; import android.app.Application;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -39,20 +40,21 @@ public class HistoryPage extends AsyncTask<Void, Void, Void> {
private static final String END = "</div></body></html>"; 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 File mFilesDir;
private final String mTitle; @NonNull private final String mTitle;
private final HistoryDatabase mHistoryDatabase; 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); mTabReference = new WeakReference<>(tab);
mFilesDir = app.getFilesDir(); mFilesDir = app.getFilesDir();
mTitle = app.getString(R.string.action_history); mTitle = app.getString(R.string.action_history);
mHistoryDatabase = database; mHistoryDatabase = database;
} }
@Nullable
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
mHistoryUrl = getHistoryPage(); mHistoryUrl = getHistoryPage();

10
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.app.Application;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -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 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 File mFilesDir;
private final WeakReference<LightningView> mTabReference; @NonNull private final WeakReference<LightningView> mTabReference;
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferenceManager;
private String mStartpageUrl; private String mStartpageUrl;
public StartPage(LightningView tab, Application app) { public StartPage(LightningView tab, @NonNull Application app) {
BrowserApp.getAppComponent().inject(this); BrowserApp.getAppComponent().inject(this);
mTitle = app.getString(R.string.home); mTitle = app.getString(R.string.home);
mFilesDir = app.getFilesDir(); mFilesDir = app.getFilesDir();
mTabReference = new WeakReference<>(tab); mTabReference = new WeakReference<>(tab);
} }
@Nullable
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
mStartpageUrl = getHomepage(); mStartpageUrl = getHomepage();
@ -88,6 +91,7 @@ public class StartPage extends AsyncTask<Void, Void, Void> {
* *
* @return the URL to load * @return the URL to load
*/ */
@NonNull
private String getHomepage() { private String getHomepage() {
StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2); StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2);
String icon; String icon;

2
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_URL = "url";
private static final String COLUMN_BOOKMARK = "bookmark"; private static final String COLUMN_BOOKMARK = "bookmark";
private final Context mContext; @NonNull private final Context mContext;
public BookmarkLocalSync(@NonNull Context context) { public BookmarkLocalSync(@NonNull Context context) {
mContext = context; mContext = context;

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

@ -29,7 +29,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
// Empty constructor // Empty constructor
public HistoryItem() {} public HistoryItem() {}
public HistoryItem(HistoryItem item) { public HistoryItem(@NonNull HistoryItem item) {
this.mUrl = item.mUrl; this.mUrl = item.mUrl;
this.mTitle = item.mTitle; this.mTitle = item.mTitle;
this.mFolder = item.mFolder; this.mFolder = item.mFolder;
@ -64,7 +64,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
mBitmap = image; mBitmap = image;
} }
public void setFolder(String folder) { public void setFolder(@Nullable String folder) {
mFolder = (folder == null) ? "" : folder; mFolder = (folder == null) ? "" : folder;
} }
@ -76,31 +76,35 @@ public class HistoryItem implements Comparable<HistoryItem> {
return mOrder; return mOrder;
} }
@NonNull
public String getFolder() { public String getFolder() {
return mFolder; return mFolder;
} }
@Nullable
public Bitmap getBitmap() { public Bitmap getBitmap() {
return mBitmap; return mBitmap;
} }
// getting name // getting name
@NonNull
public String getUrl() { public String getUrl() {
return this.mUrl; return this.mUrl;
} }
// setting name // setting name
public void setUrl(String url) { public void setUrl(@Nullable String url) {
this.mUrl = (url == null) ? "" : url; this.mUrl = (url == null) ? "" : url;
} }
// getting phone number // getting phone number
@NonNull
public String getTitle() { public String getTitle() {
return this.mTitle; return this.mTitle;
} }
// setting phone number // setting phone number
public void setTitle(String title) { public void setTitle(@Nullable String title) {
this.mTitle = (title == null) ? "" : title; this.mTitle = (title == null) ? "" : title;
} }
@ -112,6 +116,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
return mIsFolder; return mIsFolder;
} }
@NonNull
@Override @Override
public String toString() { public String toString() {
return mTitle; return mTitle;
@ -127,7 +132,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
} }
@Override @Override
public boolean equals(Object object) { public boolean equals(@Nullable Object object) {
if (this == object) return true; if (this == object) return true;
if (object == null) return false; if (object == null) return false;

14
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 context used to show the dialog
* @param url the long pressed url * @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; final HistoryItem item;
if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) { if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) {
// TODO hacky, make a better bookmark mechanism in the future // 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 = final DialogInterface.OnClickListener dialogClickListener =
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
@ -111,7 +111,7 @@ public class LightningDialogBuilder {
.show(); .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); final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(context);
editBookmarkDialog.setTitle(R.string.title_edit_bookmark); editBookmarkDialog.setTitle(R.string.title_edit_bookmark);
final View dialogLayout = View.inflate(context, R.layout.dialog_edit_bookmark, null); final View dialogLayout = View.inflate(context, R.layout.dialog_edit_bookmark, null);
@ -146,7 +146,7 @@ public class LightningDialogBuilder {
editBookmarkDialog.show(); 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(); // assert item.isFolder();
final DialogInterface.OnClickListener dialogClickListener = final DialogInterface.OnClickListener dialogClickListener =
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@ -175,7 +175,7 @@ public class LightningDialogBuilder {
.show(); .show();
} }
private void showRenameFolderDialog(final Context context, final HistoryItem item) { private void showRenameFolderDialog(@NonNull final Context context, @NonNull final HistoryItem item) {
// assert item.isFolder(); // assert item.isFolder();
final AlertDialog.Builder editFolderDialog = new AlertDialog.Builder(context); final AlertDialog.Builder editFolderDialog = new AlertDialog.Builder(context);
editFolderDialog.setTitle(R.string.title_rename_folder); editFolderDialog.setTitle(R.string.title_rename_folder);
@ -208,7 +208,7 @@ public class LightningDialogBuilder {
editFolderDialog.show(); 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() { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -270,7 +270,7 @@ public class LightningDialogBuilder {
.show(); .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() { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { 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;
import android.content.Context; import android.content.Context;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -40,7 +42,7 @@ public class AdBlock {
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferenceManager;
@Inject @Inject
public AdBlock(Context context) { public AdBlock(@NonNull Context context) {
BrowserApp.getAppComponent().inject(this); BrowserApp.getAppComponent().inject(this);
if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) { if (mBlockedDomainsList.isEmpty() && Constants.FULL_VERSION) {
loadHostsFile(context); loadHostsFile(context);
@ -52,7 +54,7 @@ public class AdBlock {
mBlockAds = mPreferenceManager.getAdBlockEnabled(); mBlockAds = mPreferenceManager.getAdBlockEnabled();
} }
private void loadBlockedDomainsList(final Context context) { private void loadBlockedDomainsList(@NonNull final Context context) {
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@Override @Override
@ -85,7 +87,7 @@ public class AdBlock {
* @param url the URL to check for being an ad * @param url the URL to check for being an ad
* @return true if it is an ad, false if it is not 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) { if (!mBlockAds || url == null) {
return false; return false;
} }
@ -112,7 +114,8 @@ public class AdBlock {
* @return returns the domain * @return returns the domain
* @throws URISyntaxException throws an exception if the string cannot form a URI * @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); int index = url.indexOf('/', 8);
if (index != -1) { if (index != -1) {
url = url.substring(0, index); url = url.substring(0, index);
@ -136,7 +139,7 @@ public class AdBlock {
* *
* @param context the context needed to read the file * @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() { Thread thread = new Thread(new Runnable() {
@Override @Override

5
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.app.Application;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
@ -29,7 +30,7 @@ public class FileUtils {
* @param bundle the bundle to store in persistent storage. * @param bundle the bundle to store in persistent storage.
* @param name the name of the file to store the bundle in. * @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); File outputFile = new File(app.getFilesDir(), name);
FileOutputStream outputStream = null; FileOutputStream outputStream = null;
try { try {
@ -58,7 +59,7 @@ public class FileUtils {
* or null if the method was unable to read the Bundle from storage. * or null if the method was unable to read the Bundle from storage.
*/ */
@Nullable @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); File inputFile = new File(app.getFilesDir(), name);
FileInputStream inputStream = null; FileInputStream inputStream = null;
try { try {

9
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.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; 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 * If Orbot/Tor or I2P is installed, prompt the user if they want to enable
* proxying for this session * proxying for this session
*/ */
public void checkForProxy(final Activity activity) { public void checkForProxy(@NonNull final Activity activity) {
boolean useProxy = mPreferences.getUseProxy(); boolean useProxy = mPreferences.getUseProxy();
final boolean orbotInstalled = OrbotHelper.isOrbotInstalled(activity); final boolean orbotInstalled = OrbotHelper.isOrbotInstalled(activity);
@ -102,7 +103,7 @@ public class ProxyUtils {
/* /*
* Initialize WebKit Proxying * Initialize WebKit Proxying
*/ */
private void initializeProxy(Activity activity) { private void initializeProxy(@NonNull Activity activity) {
String host; String host;
int port; int port;
@ -154,7 +155,7 @@ public class ProxyUtils {
return true; return true;
} }
public void updateProxySettings(Activity activity) { public void updateProxySettings(@NonNull Activity activity) {
if (mPreferences.getUseProxy()) { if (mPreferences.getUseProxy()) {
initializeProxy(activity); initializeProxy(activity);
} else { } 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) { switch (choice) {
case Constants.PROXY_ORBOT: case Constants.PROXY_ORBOT:
if (!OrbotHelper.isOrbotInstalled(activity)) { if (!OrbotHelper.isOrbotInstalled(activity)) {

7
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); 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); int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
icon.setColorFilter(color, PorterDuff.Mode.SRC_IN); 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); int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
Bitmap sourceBitmap = BitmapFactory.decodeResource(context.getResources(), res); Bitmap sourceBitmap = BitmapFactory.decodeResource(context.getResources(), res);
Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(), Bitmap.Config.ARGB_8888); Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(), Bitmap.Config.ARGB_8888);
@ -94,13 +94,14 @@ public class ThemeUtils {
return drawable; return drawable;
} }
@NonNull
public static ColorDrawable getSelectedBackground(@NonNull Context context, boolean dark) { public static ColorDrawable getSelectedBackground(@NonNull Context context, boolean dark) {
@ColorInt final int color = (dark) ? ContextCompat.getColor(context, R.color.selected_dark) : @ColorInt final int color = (dark) ? ContextCompat.getColor(context, R.color.selected_dark) :
ContextCompat.getColor(context, R.color.selected_light); ContextCompat.getColor(context, R.color.selected_light);
return new ColorDrawable(color); return new ColorDrawable(color);
} }
public static int getTextColor(Context context) { public static int getTextColor(@NonNull Context context) {
return getColor(context, android.R.attr.editTextColor); 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 {
* @param title the title of the dialog. * @param title the title of the dialog.
* @param message the message 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); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(title); builder.setTitle(title);
builder.setMessage(message) builder.setMessage(message)
@ -170,6 +170,7 @@ public final class Utils {
* could not be extracted. The domain name may include * could not be extracted. The domain name may include
* HTTPS if the URL is an SSL supported URL. * HTTPS if the URL is an SSL supported URL.
*/ */
@Nullable
public static String getDomainName(@Nullable String url) { public static String getDomainName(@Nullable String url) {
if (url == null || url.isEmpty()) return ""; if (url == null || url.isEmpty()) return "";
@ -198,11 +199,11 @@ public final class Utils {
return domain.startsWith("www.") ? domain.substring(4) : domain; 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); return input.split(Constants.SEPARATOR);
} }
public static void trimCache(Context context) { public static void trimCache(@NonNull Context context) {
try { try {
File dir = context.getCacheDir(); 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()) { if (dir != null && dir.isDirectory()) {
String[] children = dir.list(); String[] children = dir.list();
for (String aChildren : children) { for (String aChildren : children) {
@ -235,7 +236,7 @@ public final class Utils {
* @param bitmap is the bitmap to pad. * @param bitmap is the bitmap to pad.
* @return the padded bitmap. * @return the padded bitmap.
*/ */
public static Bitmap padFavicon(Bitmap bitmap) { public static Bitmap padFavicon(@NonNull Bitmap bitmap) {
int padding = Utils.dpToPx(4); int padding = Utils.dpToPx(4);
Bitmap paddedBitmap = Bitmap.createBitmap(bitmap.getWidth() + padding, bitmap.getHeight() 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 * @param context the context needed to obtain the PackageManager
* @return true if flash is installed, false otherwise * @return true if flash is installed, false otherwise
*/ */
public static boolean isFlashInstalled(Context context) { public static boolean isFlashInstalled(@NonNull Context context) {
try { try {
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0); ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
@ -315,7 +316,7 @@ public final class Utils {
* *
* @param closeable the object to close * @param closeable the object to close
*/ */
public static void close(Closeable closeable) { public static void close(@Nullable Closeable closeable) {
if (closeable == null) if (closeable == null)
return; return;
try { try {
@ -332,7 +333,7 @@ public final class Utils {
* *
* @param cursor the cursor to close * @param cursor the cursor to close
*/ */
public static void close(Cursor cursor) { public static void close(@Nullable Cursor cursor) {
if (cursor == null) { if (cursor == null) {
return; return;
} }
@ -350,7 +351,7 @@ public final class Utils {
* @param canvas the canvas to draw upon * @param canvas the canvas to draw upon
* @param color the color to use to draw the tab * @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 paint = new Paint();
paint.setColor(color); paint.setColor(color);

5
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.content.Context;
import android.os.Build; import android.os.Build;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.CookieSyncManager; import android.webkit.CookieSyncManager;
import android.webkit.WebIconDatabase; import android.webkit.WebIconDatabase;
@ -33,7 +34,7 @@ public class WebUtils {
WebStorage.getInstance().deleteAllData(); WebStorage.getInstance().deleteAllData();
} }
public static void clearHistory(@NonNull Context context, HistoryDatabase historyDatabase) { public static void clearHistory(@NonNull Context context, @NonNull HistoryDatabase historyDatabase) {
historyDatabase.deleteHistory(); historyDatabase.deleteHistory();
WebViewDatabase m = WebViewDatabase.getInstance(context); WebViewDatabase m = WebViewDatabase.getInstance(context);
m.clearFormData(); m.clearFormData();
@ -47,7 +48,7 @@ public class WebUtils {
Utils.trimCache(context); Utils.trimCache(context);
} }
public static void clearCache(WebView view) { public static void clearCache(@Nullable WebView view) {
if (view == null) return; if (view == null) return;
view.clearCache(true); view.clearCache(true);
} }

18
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"; public static final String HEADER_WAP_PROFILE = "X-Wap-Profile";
private static final String HEADER_DNT = "DNT"; private static final String HEADER_DNT = "DNT";
private final LightningViewTitle mTitle; @NonNull private final LightningViewTitle mTitle;
private WebView mWebView; @Nullable private WebView mWebView;
private final boolean mIsIncognitoTab; private final boolean mIsIncognitoTab;
private final UIController mUIController; @NonNull private final UIController mUIController;
private final GestureDetector mGestureDetector; @NonNull private final GestureDetector mGestureDetector;
private final Activity mActivity; @NonNull private final Activity mActivity;
private static String mHomepage; private static String mHomepage;
private static String mDefaultUserAgent; private static String mDefaultUserAgent;
private final Paint mPaint = new Paint(); private final Paint mPaint = new Paint();
@ -99,7 +99,7 @@ public class LightningView {
@Inject BookmarkManager mBookmarkManager; @Inject BookmarkManager mBookmarkManager;
@SuppressLint("NewApi") @SuppressLint("NewApi")
public LightningView(Activity activity, String url, boolean isIncognito) { public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) {
BrowserApp.getAppComponent().inject(this); BrowserApp.getAppComponent().inject(this);
mActivity = activity; mActivity = activity;
mUIController = (UIController) activity; mUIController = (UIController) activity;
@ -984,7 +984,7 @@ public class LightningView {
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@Override @Override
public boolean onTouch(View view, MotionEvent arg1) { public boolean onTouch(@Nullable View view, @NonNull MotionEvent arg1) {
if (view == null) if (view == null)
return false; return false;
@ -1076,14 +1076,14 @@ public class LightningView {
*/ */
private static class WebViewHandler extends Handler { private static class WebViewHandler extends Handler {
private final WeakReference<LightningView> mReference; @NonNull private final WeakReference<LightningView> mReference;
public WebViewHandler(LightningView view) { public WebViewHandler(LightningView view) {
mReference = new WeakReference<>(view); mReference = new WeakReference<>(view);
} }
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg); super.handleMessage(msg);
final String url = msg.getData().getString("url"); final String url = msg.getData().getString("url");
LightningView view = mReference.get(); LightningView view = mReference.get();

Loading…
Cancel
Save