Browse Source

Fixing deprecated API usage and lint warnings

master
Anthony Restaino 8 years ago
parent
commit
8ae8f58cc6
  1. 4
      app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java
  2. 1
      app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java
  3. 6
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  4. 4
      app/src/main/java/acr/browser/lightning/database/BookmarkLocalSync.java
  5. 2
      app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java
  6. 3
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  7. 1
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  8. 31
      app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java
  9. 31
      app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java
  10. 78
      app/src/main/java/acr/browser/lightning/reading/MapEntry.java
  11. 1
      app/src/main/java/acr/browser/lightning/receiver/NetworkReceiver.java
  12. 2
      app/src/main/java/acr/browser/lightning/search/Suggestions.java
  13. 4
      app/src/main/java/acr/browser/lightning/utils/KeyboardHelper.java
  14. 2
      app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java
  15. 5
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  16. 17
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

4
app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java

@ -49,7 +49,7 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
* Called by onWindowFocusChanged only if * Called by onWindowFocusChanged only if
* onResume has been called. * onResume has been called.
*/ */
public void onWindowVisibleToUserAfterResume() { void onWindowVisibleToUserAfterResume() {
} }
@ -68,7 +68,7 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE; return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
} }
protected void restart() { void restart() {
finish(); finish();
startActivity(new Intent(this, getClass())); startActivity(new Intent(this, getClass()));
} }

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

@ -1,7 +1,6 @@
package acr.browser.lightning.async; package acr.browser.lightning.async;
import android.app.Application; import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;

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

@ -62,6 +62,8 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
private static final String END = "</div></body></html>"; private static final String END = "</div></body></html>";
private static final String FOLDER_ICON = "folder.png";
private File mFilesDir; private File mFilesDir;
private File mCacheDir; private File mCacheDir;
@ -101,7 +103,7 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
private void cacheDefaultFolderIcon() { private void cacheDefaultFolderIcon() {
FileOutputStream outputStream = null; FileOutputStream outputStream = null;
File image = new File(mCacheDir, "folder.png"); File image = new File(mCacheDir, FOLDER_ICON);
try { try {
outputStream = new FileOutputStream(image); outputStream = new FileOutputStream(image);
mFolderIcon.compress(Bitmap.CompressFormat.PNG, 100, outputStream); mFolderIcon.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
@ -123,7 +125,7 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
} }
final StringBuilder bookmarkBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2); final StringBuilder bookmarkBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2);
final String folderIconPath = Constants.FILE + mCacheDir + "/folder.png"; final String folderIconPath = Constants.FILE + mCacheDir + '/' + FOLDER_ICON;
for (int n = 0, size = list.size(); n < size; n++) { for (int n = 0, size = list.size(); n < size; n++) {
final HistoryItem item = list.get(n); final HistoryItem item = list.get(n);
bookmarkBuilder.append(PART1); bookmarkBuilder.append(PART1);

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

@ -42,7 +42,7 @@ public class BookmarkLocalSync {
mContext = context; mContext = context;
} }
public List<HistoryItem> getBookmarksFromContentUri(String contentUri) { private List<HistoryItem> getBookmarksFromContentUri(String contentUri) {
List<HistoryItem> list = new ArrayList<>(); List<HistoryItem> list = new ArrayList<>();
Cursor cursor = getBrowserCursor(contentUri); Cursor cursor = getBrowserCursor(contentUri);
try { try {
@ -186,7 +186,7 @@ public class BookmarkLocalSync {
printColumns(STOCK_BOOKMARKS_CONTENT); printColumns(STOCK_BOOKMARKS_CONTENT);
} }
public void printColumns(String contentProvider) { private void printColumns(String contentProvider) {
Cursor cursor = null; Cursor cursor = null;
Log.e(TAG, contentProvider); Log.e(TAG, contentProvider);
Uri uri = Uri.parse(contentProvider); Uri uri = Uri.parse(contentProvider);

2
app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java

@ -54,7 +54,7 @@ public class BrowserDialog {
public static abstract class Item { public static abstract class Item {
private int mTitle; private final int mTitle;
private boolean mCondition = true; private boolean mCondition = true;
public Item(@StringRes int title, boolean condition) { public Item(@StringRes int title, boolean condition) {

3
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -374,8 +374,9 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
this.context = context; this.context = context;
} }
@NonNull
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View row = convertView; View row = convertView;
BookmarkViewHolder holder; BookmarkViewHolder holder;

1
app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

@ -26,7 +26,6 @@ import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.dialog.BrowserDialog;
import acr.browser.lightning.download.DownloadHandler; import acr.browser.lightning.download.DownloadHandler;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.ThemeUtils;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;

31
app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java

@ -39,23 +39,26 @@ import java.util.List;
public class HorizontalItemAnimator extends SimpleItemAnimator { public class HorizontalItemAnimator extends SimpleItemAnimator {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private ArrayList<ViewHolder> mPendingRemovals = new ArrayList<>(); private final ArrayList<ViewHolder> mPendingRemovals = new ArrayList<>();
private ArrayList<ViewHolder> mPendingAdditions = new ArrayList<>(); private final ArrayList<ViewHolder> mPendingAdditions = new ArrayList<>();
private ArrayList<MoveInfo> mPendingMoves = new ArrayList<>(); private final ArrayList<MoveInfo> mPendingMoves = new ArrayList<>();
private ArrayList<ChangeInfo> mPendingChanges = new ArrayList<>(); private final ArrayList<ChangeInfo> mPendingChanges = new ArrayList<>();
private ArrayList<ArrayList<ViewHolder>> mAdditionsList = new ArrayList<>(); private final ArrayList<ArrayList<ViewHolder>> mAdditionsList = new ArrayList<>();
private ArrayList<ArrayList<MoveInfo>> mMovesList = new ArrayList<>(); private final ArrayList<ArrayList<MoveInfo>> mMovesList = new ArrayList<>();
private ArrayList<ArrayList<ChangeInfo>> mChangesList = new ArrayList<>(); private final ArrayList<ArrayList<ChangeInfo>> mChangesList = new ArrayList<>();
private ArrayList<ViewHolder> mAddAnimations = new ArrayList<>(); private final ArrayList<ViewHolder> mAddAnimations = new ArrayList<>();
private ArrayList<ViewHolder> mMoveAnimations = new ArrayList<>(); private final ArrayList<ViewHolder> mMoveAnimations = new ArrayList<>();
private ArrayList<ViewHolder> mRemoveAnimations = new ArrayList<>(); private final ArrayList<ViewHolder> mRemoveAnimations = new ArrayList<>();
private ArrayList<ViewHolder> mChangeAnimations = new ArrayList<>(); private final ArrayList<ViewHolder> mChangeAnimations = new ArrayList<>();
private static class MoveInfo { private static class MoveInfo {
public ViewHolder holder; public final ViewHolder holder;
public int fromX, fromY, toX, toY; public final int fromX;
public final int fromY;
public final int toX;
public final int toY;
private MoveInfo(ViewHolder holder, int fromX, int fromY, int toX, int toY) { private MoveInfo(ViewHolder holder, int fromX, int fromY, int toX, int toY) {
this.holder = holder; this.holder = holder;
@ -656,7 +659,7 @@ public class HorizontalItemAnimator extends SimpleItemAnimator {
dispatchAnimationsFinished(); dispatchAnimationsFinished();
} }
static void cancelAll(List<ViewHolder> viewHolders) { private static void cancelAll(List<ViewHolder> viewHolders) {
for (int i = viewHolders.size() - 1; i >= 0; i--) { for (int i = viewHolders.size() - 1; i >= 0; i--) {
ViewCompat.animate(viewHolders.get(i).itemView).cancel(); ViewCompat.animate(viewHolders.get(i).itemView).cancel();
} }

31
app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java

@ -39,23 +39,26 @@ import java.util.List;
public class VerticalItemAnimator extends SimpleItemAnimator { public class VerticalItemAnimator extends SimpleItemAnimator {
private static final boolean DEBUG = false; private static final boolean DEBUG = false;
private ArrayList<ViewHolder> mPendingRemovals = new ArrayList<>(); private final ArrayList<ViewHolder> mPendingRemovals = new ArrayList<>();
private ArrayList<ViewHolder> mPendingAdditions = new ArrayList<>(); private final ArrayList<ViewHolder> mPendingAdditions = new ArrayList<>();
private ArrayList<MoveInfo> mPendingMoves = new ArrayList<>(); private final ArrayList<MoveInfo> mPendingMoves = new ArrayList<>();
private ArrayList<ChangeInfo> mPendingChanges = new ArrayList<>(); private final ArrayList<ChangeInfo> mPendingChanges = new ArrayList<>();
private ArrayList<ArrayList<ViewHolder>> mAdditionsList = new ArrayList<>(); private final ArrayList<ArrayList<ViewHolder>> mAdditionsList = new ArrayList<>();
private ArrayList<ArrayList<MoveInfo>> mMovesList = new ArrayList<>(); private final ArrayList<ArrayList<MoveInfo>> mMovesList = new ArrayList<>();
private ArrayList<ArrayList<ChangeInfo>> mChangesList = new ArrayList<>(); private final ArrayList<ArrayList<ChangeInfo>> mChangesList = new ArrayList<>();
private ArrayList<ViewHolder> mAddAnimations = new ArrayList<>(); private final ArrayList<ViewHolder> mAddAnimations = new ArrayList<>();
private ArrayList<ViewHolder> mMoveAnimations = new ArrayList<>(); private final ArrayList<ViewHolder> mMoveAnimations = new ArrayList<>();
private ArrayList<ViewHolder> mRemoveAnimations = new ArrayList<>(); private final ArrayList<ViewHolder> mRemoveAnimations = new ArrayList<>();
private ArrayList<ViewHolder> mChangeAnimations = new ArrayList<>(); private final ArrayList<ViewHolder> mChangeAnimations = new ArrayList<>();
private static class MoveInfo { private static class MoveInfo {
public ViewHolder holder; public final ViewHolder holder;
public int fromX, fromY, toX, toY; public final int fromX;
public final int fromY;
public final int toX;
public final int toY;
private MoveInfo(ViewHolder holder, int fromX, int fromY, int toX, int toY) { private MoveInfo(ViewHolder holder, int fromX, int fromY, int toX, int toY) {
this.holder = holder; this.holder = holder;
@ -655,7 +658,7 @@ public class VerticalItemAnimator extends SimpleItemAnimator {
dispatchAnimationsFinished(); dispatchAnimationsFinished();
} }
static void cancelAll(List<ViewHolder> viewHolders) { private static void cancelAll(List<ViewHolder> viewHolders) {
for (int i = viewHolders.size() - 1; i >= 0; i--) { for (int i = viewHolders.size() - 1; i >= 0; i--) {
ViewCompat.animate(viewHolders.get(i).itemView).cancel(); ViewCompat.animate(viewHolders.get(i).itemView).cancel();
} }

78
app/src/main/java/acr/browser/lightning/reading/MapEntry.java

@ -1,78 +0,0 @@
/**
* Copyright (C) 2010 Peter Karich <>
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package acr.browser.lightning.reading;
import java.io.Serializable;
import java.util.Map;
/**
* Simple impl of Map.Entry. So that we can have ordered maps.
*
* @author Peter Karich, peat_hal at users dot sourceforge dot
* net
*/
public class MapEntry<K, V> implements Map.Entry<K, V>, Serializable {
private static final long serialVersionUID = 1L;
private final K key;
private V value;
public MapEntry(K key, V value) {
this.key = key;
this.value = value;
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return value;
}
@Override
public V setValue(V value) {
this.value = value;
return value;
}
@Override
public String toString() {
return key + ", " + value;
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (!(obj instanceof Map<?, ?>))
return false;
final MapEntry<?, ?> other = (MapEntry<?, ?>) obj;
return !(this.key != other.key && (this.key == null || !this.key.equals(other.key))) &&
!(this.value != other.value && (this.value == null || !this.value.equals(other.value)));
}
@Override
public int hashCode() {
int hash = 7;
hash = 19 * hash + (this.key != null ? this.key.hashCode() : 0);
hash = 19 * hash + (this.value != null ? this.value.hashCode() : 0);
return hash;
}
}

1
app/src/main/java/acr/browser/lightning/receiver/NetworkReceiver.java

@ -6,7 +6,6 @@ import android.content.Intent;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.util.Log;
public abstract class NetworkReceiver extends BroadcastReceiver { public abstract class NetworkReceiver extends BroadcastReceiver {

2
app/src/main/java/acr/browser/lightning/search/Suggestions.java

@ -72,7 +72,7 @@ public class Suggestions extends BaseAdapter implements Filterable {
private final boolean mDarkTheme; private final boolean mDarkTheme;
private boolean mIsIncognito = true; private boolean mIsIncognito = true;
@NonNull private final Context mContext; @NonNull private final Context mContext;
PreferenceManager.Suggestion mSuggestionChoice; private PreferenceManager.Suggestion mSuggestionChoice;
public Suggestions(@NonNull Context context, boolean dark, boolean incognito) { public Suggestions(@NonNull Context context, boolean dark, boolean incognito) {
super(); super();

4
app/src/main/java/acr/browser/lightning/utils/KeyboardHelper.java

@ -5,9 +5,9 @@ import android.support.annotation.NonNull;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
public class KeyboardHelper { class KeyboardHelper {
public interface KeyboardListener { interface KeyboardListener {
/** /**
* Called when the visibility of the keyboard changes. * Called when the visibility of the keyboard changes.
* Parameter tells whether the keyboard has been shown * Parameter tells whether the keyboard has been shown

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

@ -78,7 +78,7 @@ public class ThemeUtils {
// http://stackoverflow.com/a/38244327/1499541 // http://stackoverflow.com/a/38244327/1499541
@NonNull @NonNull
public static Bitmap getBitmapFromVectorDrawable(@NonNull Context context, int drawableId) { private static Bitmap getBitmapFromVectorDrawable(@NonNull Context context, int drawableId) {
Drawable drawable = getVectorDrawable(context, drawableId); Drawable drawable = getVectorDrawable(context, drawableId);
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),

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

@ -50,11 +50,13 @@ import acr.browser.lightning.database.BookmarkManager;
import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.download.LightningDownloadListener; import acr.browser.lightning.download.LightningDownloadListener;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import com.anthonycr.bonsai.Action; import com.anthonycr.bonsai.Action;
import com.anthonycr.bonsai.Observable; import com.anthonycr.bonsai.Observable;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.bonsai.Subscriber; import com.anthonycr.bonsai.Subscriber;
import com.anthonycr.bonsai.OnSubscribe; import com.anthonycr.bonsai.OnSubscribe;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.UrlUtils; import acr.browser.lightning.utils.UrlUtils;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
@ -416,18 +418,21 @@ public class LightningView {
public void onComplete() {} public void onComplete() {}
}); });
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
getPathObservable("geolocation") getPathObservable("geolocation")
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(Schedulers.main()) .observeOn(Schedulers.main())
.subscribe(new OnSubscribe<File>() { .subscribe(new OnSubscribe<File>() {
@Override @Override
public void onNext(File item) { public void onNext(File item) {
//noinspection deprecation
settings.setGeolocationDatabasePath(item.getPath()); settings.setGeolocationDatabasePath(item.getPath());
} }
@Override @Override
public void onComplete() {} public void onComplete() {}
}); });
}
getPathObservable("databases") getPathObservable("databases")
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())

17
app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

@ -278,8 +278,19 @@ public class LightningWebClient extends WebViewClient {
BrowserDialog.setDialogSize(mActivity, alert); BrowserDialog.setDialogSize(mActivity, alert);
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return shouldOverrideLoading(view, request.getUrl().toString()) || super.shouldOverrideUrlLoading(view, request);
}
@SuppressWarnings("deprecation")
@Override @Override
public boolean shouldOverrideUrlLoading(@NonNull WebView view, @NonNull String url) { public boolean shouldOverrideUrlLoading(@NonNull WebView view, @NonNull String url) {
return shouldOverrideLoading(view, url) || super.shouldOverrideUrlLoading(view, url);
}
private boolean shouldOverrideLoading(WebView view, String url) {
// Check if configured proxy is available // Check if configured proxy is available
if (!mProxyUtils.isProxyReady()) { if (!mProxyUtils.isProxyReady()) {
// User has been notified // User has been notified
@ -293,11 +304,11 @@ public class LightningWebClient extends WebViewClient {
if (headers.isEmpty()) { if (headers.isEmpty()) {
if (mLightningView.isIncognito()) { if (mLightningView.isIncognito()) {
// If we are in incognito, immediately load, we don't want the url to leave the app // If we are in incognito, immediately load, we don't want the url to leave the app
return super.shouldOverrideUrlLoading(view, url); return false;
} }
if (url.startsWith(Constants.ABOUT)) { if (url.startsWith(Constants.ABOUT)) {
// If this is an about page, immediately load, we don't need to leave the app // If this is an about page, immediately load, we don't need to leave the app
return super.shouldOverrideUrlLoading(view, url); return false;
} }
if (isMailOrIntent(url, view) || mIntentUtils.startActivityForUrl(view, url)) { if (isMailOrIntent(url, view) || mIntentUtils.startActivityForUrl(view, url)) {
@ -326,7 +337,7 @@ public class LightningWebClient extends WebViewClient {
} }
} }
// If none of those instances was true, revert back to the old way of loading // If none of those instances was true, revert back to the old way of loading
return super.shouldOverrideUrlLoading(view, url); return false;
} }
private boolean isMailOrIntent(@NonNull String url, @NonNull WebView view) { private boolean isMailOrIntent(@NonNull String url, @NonNull WebView view) {

Loading…
Cancel
Save