Browse Source

Lint fixes and code cleanup

master
Anthony Restaino 10 years ago
parent
commit
fa1994c8b2
  1. 24
      .idea/misc.xml
  2. 4
      app/src/main/AndroidManifest.xml
  3. 4
      app/src/main/java/acr/browser/lightning/activity/AdvancedSettingsActivity.java
  4. 12
      app/src/main/java/acr/browser/lightning/activity/BookmarkActivity.java
  5. 85
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  6. 2
      app/src/main/java/acr/browser/lightning/activity/PrivacySettingsActivity.java
  7. 25
      app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java
  8. 2
      app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java
  9. 6
      app/src/main/java/acr/browser/lightning/activity/ThemableActivity.java
  10. 6
      app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java
  11. 1
      app/src/main/java/acr/browser/lightning/constant/Constants.java
  12. 42
      app/src/main/java/acr/browser/lightning/controller/BrowserController.java
  13. 95
      app/src/main/java/acr/browser/lightning/database/BookmarkManager.java
  14. 7
      app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java
  15. 8
      app/src/main/java/acr/browser/lightning/database/HistoryItem.java
  16. 2
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  17. 15
      app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java
  18. 2
      app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java
  19. 2
      app/src/main/java/acr/browser/lightning/download/WebAddress.java
  20. 30
      app/src/main/java/acr/browser/lightning/object/SearchAdapter.java
  21. 11
      app/src/main/java/acr/browser/lightning/reading/ArticleTextExtractor.java
  22. 13
      app/src/main/java/acr/browser/lightning/reading/Converter.java
  23. 8
      app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java
  24. 14
      app/src/main/java/acr/browser/lightning/reading/ImageResult.java
  25. 2
      app/src/main/java/acr/browser/lightning/reading/JResult.java
  26. 2
      app/src/main/java/acr/browser/lightning/reading/OutputFormatter.java
  27. 2
      app/src/main/java/acr/browser/lightning/reading/SHelper.java
  28. 2
      app/src/main/java/acr/browser/lightning/utils/AdBlock.java
  29. 2
      app/src/main/java/acr/browser/lightning/utils/IntentUtils.java
  30. 9
      app/src/main/java/acr/browser/lightning/utils/Utils.java
  31. 45
      app/src/main/java/acr/browser/lightning/view/LightningView.java

24
.idea/misc.xml

@ -3,5 +3,29 @@ @@ -3,5 +3,29 @@
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="org.jetbrains.annotations.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK" />
</project>

4
app/src/main/AndroidManifest.xml

@ -24,10 +24,6 @@ @@ -24,10 +24,6 @@
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="22" />
<application
android:name=".activity.BrowserApp"
android:allowBackup="true"

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

@ -163,7 +163,7 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity { @@ -163,7 +163,7 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
}
public void renderPicker() {
private void renderPicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
picker.setTitle(getResources().getString(R.string.rendering_mode));
@ -206,7 +206,7 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity { @@ -206,7 +206,7 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
picker.show();
}
public void urlBoxPicker() {
private void urlBoxPicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
picker.setTitle(getResources().getString(R.string.url_contents));

12
app/src/main/java/acr/browser/lightning/activity/BookmarkActivity.java

@ -24,8 +24,6 @@ import acr.browser.lightning.R; @@ -24,8 +24,6 @@ import acr.browser.lightning.R;
public class BookmarkActivity extends ThemableSettingsActivity implements OnClickListener {
private BookmarkManager mBookmarkManager;
private PreferenceManager mPreferences;
private boolean mSystemBrowser;
private File[] mFileList;
private String[] mFileNameList;
private static final File mPath = new File(Environment.getExternalStorageDirectory().toString());
@ -48,15 +46,15 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic @@ -48,15 +46,15 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
TextView importBookmarks = (TextView) findViewById(R.id.isImportBrowserAvailable);
mBookmarkManager = BookmarkManager.getInstance(getApplicationContext());
mPreferences = PreferenceManager.getInstance();
PreferenceManager mPreferences = PreferenceManager.getInstance();
mSystemBrowser = mPreferences.getSystemBrowserPresent();
boolean systemBrowser = mPreferences.getSystemBrowserPresent();
exportBackup.setOnClickListener(this);
importBackup.setOnClickListener(this);
importFromBrowser.setOnClickListener(this);
if (mSystemBrowser) {
if (systemBrowser) {
importBookmarks.setText(getResources().getString(R.string.stock_browser_available));
} else {
importBookmarks.setText(getResources().getString(R.string.stock_browser_unavailable));
@ -116,7 +114,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic @@ -116,7 +114,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
}
}
public class SortName implements Comparator<File> {
private class SortName implements Comparator<File> {
@Override
public int compare(File a, File b) {
@ -137,7 +135,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic @@ -137,7 +135,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
}
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
Dialog dialog;
final AlertDialog.Builder builder = new Builder(this);
switch (id) {

85
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -96,19 +96,16 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -96,19 +96,16 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
private FullscreenHolder mFullscreenContainer;
private ListView mDrawerListLeft, mDrawerListRight;
private LinearLayout mDrawerLeft, mDrawerRight, mUiLayout, mToolbarLayout;
private RelativeLayout mNewTab, mSearchBar;
private RelativeLayout mSearchBar;
// List
private final List<LightningView> mWebViews = new ArrayList<LightningView>();
private final List<LightningView> mWebViews = new ArrayList<>();
private List<HistoryItem> mBookmarkList;
private LightningView mCurrentView;
// View
private ActionBar mActionBar;
private AnimatedProgressBar mProgressBar;
private AutoCompleteTextView mSearch;
private ImageView mArrowImage;
private Toolbar mToolbar;
private VideoView mVideoView;
private View mCustomView, mVideoProgressView;
@ -160,9 +157,9 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -160,9 +157,9 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@SuppressWarnings("deprecation")
private synchronized void initialize() {
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mActionBar = getSupportActionBar();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
mPreferences = PreferenceManager.getInstance();
mDarkTheme = mPreferences.getUseDarkTheme() || isIncognito();
@ -177,7 +174,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -177,7 +174,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mUiLayout = (LinearLayout) findViewById(R.id.ui_layout);
mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
mNewTab = (RelativeLayout) findViewById(R.id.new_tab_button);
RelativeLayout newTab = (RelativeLayout) findViewById(R.id.new_tab_button);
mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer);
// Drawer stutters otherwise
mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null);
@ -205,22 +202,22 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -205,22 +202,22 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext());
// set display options of the ActionBar
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowCustomEnabled(true);
mActionBar.setCustomView(R.layout.toolbar_content);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.toolbar_content);
View v = mActionBar.getCustomView();
View v = actionBar.getCustomView();
LayoutParams lp = v.getLayoutParams();
lp.width = LayoutParams.MATCH_PARENT;
v.setLayoutParams(lp);
mArrowDrawable = new DrawerArrowDrawable(this);
mArrowImage = (ImageView) mActionBar.getCustomView().findViewById(R.id.arrow);
mArrowImage = (ImageView) actionBar.getCustomView().findViewById(R.id.arrow);
// Use hardware acceleration for the animation
mArrowImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mArrowImage.setImageDrawable(mArrowDrawable);
LinearLayout arrowButton = (LinearLayout) mActionBar.getCustomView().findViewById(
LinearLayout arrowButton = (LinearLayout) actionBar.getCustomView().findViewById(
R.id.arrow_button);
arrowButton.setOnClickListener(this);
@ -231,8 +228,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -231,8 +228,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
forward.setOnClickListener(this);
// create the search EditText in the ToolBar
mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search);
mUntitledTitle = (String) getString(R.string.untitled);
mSearch = (AutoCompleteTextView) actionBar.getCustomView().findViewById(R.id.search);
mUntitledTitle = getString(R.string.untitled);
mBackgroundColor = getResources().getColor(R.color.primary_color);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete);
@ -283,8 +280,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -283,8 +280,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
});
initialize.run();
mNewTab.setOnClickListener(this);
mNewTab.setOnLongClickListener(new OnLongClickListener() {
newTab.setOnClickListener(this);
newTab.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
@ -500,7 +497,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -500,7 +497,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
* If Orbot/Tor is installed, prompt the user if they want to enable
* proxying for this session
*/
public boolean checkForTor() {
private boolean checkForTor() {
boolean useProxy = mPreferences.getUseProxy();
OrbotHelper oh = new OrbotHelper(this);
@ -538,7 +535,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -538,7 +535,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
/*
* Initialize WebKit Proxying for Tor
*/
public void initializeTor() {
private void initializeTor() {
OrbotHelper oh = new OrbotHelper(this);
if (!oh.isOrbotRunning()) {
@ -617,12 +614,12 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -617,12 +614,12 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mPreferences.setMemoryUrl("");
String[] array = Utils.getArray(mem);
int count = 0;
for (int n = 0; n < array.length; n++) {
if (array[n].length() > 0) {
if (url != null && url.compareTo(array[n]) == 0) {
for (String urlString : array) {
if (urlString.length() > 0) {
if (url != null && url.compareTo(urlString) == 0) {
url = null;
}
newTab(array[n], true);
newTab(urlString, true);
count++;
}
}
@ -1459,13 +1456,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1459,13 +1456,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
public class LightningViewAdapter extends ArrayAdapter<LightningView> {
Context context;
final Context context;
ColorMatrix colorMatrix;
ColorMatrixColorFilter filter;
Paint paint;
int layoutResourceId;
final int layoutResourceId;
List<LightningView> data = null;
CloseTabListener mExitListener;
final CloseTabListener mExitListener;
public LightningViewAdapter(Context context, int layoutResourceId, List<LightningView> data) {
super(context, layoutResourceId, data);
@ -1478,7 +1475,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1478,7 +1475,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
LightningViewHolder holder = null;
LightningViewHolder holder;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
@ -1591,11 +1588,11 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1591,11 +1588,11 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
public static boolean isColorTooDark(int color) {
final byte RED_CHANNEL = 16;
final byte GREEN_CHANNEL = 8;
final byte BLUE_CHANNEL = 0;
//final byte BLUE_CHANNEL = 0;
int r = ((int) ((float) (color >> RED_CHANNEL & 0xff) * 0.3f)) & 0xff;
int g = ((int) ((float) (color >> GREEN_CHANNEL & 0xff) * 0.59)) & 0xff;
int b = ((int) ((float) (color >> BLUE_CHANNEL & 0xff) * 0.11)) & 0xff;
int b = ((int) ((float) (color & 0xff) * 0.11)) & 0xff;
int gr = (r + g + b) & 0xff;
int gray = gr + (gr << GREEN_CHANNEL) + (gr << RED_CHANNEL);
@ -1606,7 +1603,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1606,7 +1603,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
final byte ALPHA_CHANNEL = 24;
final byte RED_CHANNEL = 16;
final byte GREEN_CHANNEL = 8;
final byte BLUE_CHANNEL = 0;
//final byte BLUE_CHANNEL = 0;
final float inverseAmount = 1.0f - amount;
@ -1614,14 +1611,14 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1614,14 +1611,14 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
int g = ((int) (((float) (color1 >> GREEN_CHANNEL & 0xff) * amount) + ((float) (color2 >> GREEN_CHANNEL & 0xff) * inverseAmount))) & 0xff;
int b = ((int) (((float) (color1 & 0xff) * amount) + ((float) (color2 & 0xff) * inverseAmount))) & 0xff;
return 0xff << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL;
return 0xff << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b;
}
public class BookmarkViewAdapter extends ArrayAdapter<HistoryItem> {
Context context;
final Context context;
List<HistoryItem> data = null;
int layoutResourceId;
final int layoutResourceId;
public BookmarkViewAdapter(Context context, int layoutResourceId, List<HistoryItem> data) {
super(context, layoutResourceId, data);
@ -1633,7 +1630,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1633,7 +1630,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
BookmarkViewHolder holder = null;
BookmarkViewHolder holder;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
@ -1670,8 +1667,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1670,8 +1667,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
HistoryItem mWeb;
final ImageView bmImage;
final HistoryItem mWeb;
public DownloadImageTask(ImageView bmImage, HistoryItem web) {
this.bmImage = bmImage;
@ -1852,14 +1849,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1852,14 +1849,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
public boolean getSystemBrowser() {
Cursor c = null;
String[] columns = new String[] { "url", "title" };
boolean browserFlag = false;
boolean browserFlag;
try {
Uri bookmarks = Browser.BOOKMARKS_URI;
c = getContentResolver().query(bookmarks, columns, null, null, null);
} catch (SQLiteException ignored) {
} catch (IllegalStateException ignored) {
} catch (NullPointerException ignored) {
} catch (SQLiteException | IllegalStateException | NullPointerException e) {
e.printStackTrace();
}
if (c != null) {
@ -1871,7 +1867,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1871,7 +1867,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
}
if (c != null) {
c.close();
c = null;
}
mPreferences.setSystemBrowserPresent(browserFlag);
return browserFlag;
@ -1899,7 +1894,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -1899,7 +1894,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
getUrl.setText(url);
}
searchTheWeb(url);
url = null;
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
if (mCurrentView != null) {
@ -2045,7 +2039,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll @@ -2045,7 +2039,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mFilePathCallback.onReceiveValue(results);
mFilePathCallback = null;
return;
}
@Override

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

@ -144,7 +144,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity { @@ -144,7 +144,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
private static class MessageHandler extends Handler {
Context mHandlerContext;
final Context mHandlerContext;
public MessageHandler(Context context) {
this.mHandlerContext = context;

25
app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java

@ -1,14 +1,5 @@ @@ -1,14 +1,5 @@
package acr.browser.lightning.activity;
import java.util.ArrayList;
import java.util.List;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.R;
import acr.browser.lightning.utils.Utils;
import acr.browser.lightning.reading.HtmlFetcher;
import acr.browser.lightning.reading.JResult;
import android.animation.ObjectAnimator;
import android.app.AlertDialog;
import android.app.ProgressDialog;
@ -18,7 +9,7 @@ import android.content.DialogInterface.OnClickListener; @@ -18,7 +9,7 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
@ -28,7 +19,17 @@ import android.widget.SeekBar; @@ -28,7 +19,17 @@ import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
public class ReadingActivity extends ActionBarActivity {
import java.util.ArrayList;
import java.util.List;
import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.reading.HtmlFetcher;
import acr.browser.lightning.reading.JResult;
import acr.browser.lightning.utils.Utils;
public class ReadingActivity extends AppCompatActivity {
private TextView mTitle;
private TextView mBody;
@ -114,7 +115,7 @@ public class ReadingActivity extends ActionBarActivity { @@ -114,7 +115,7 @@ public class ReadingActivity extends ActionBarActivity {
private class PageLoader extends AsyncTask<String, Void, Void> {
private Context mContext;
private final Context mContext;
private ProgressDialog mProgressDialog;
private String mTitleText;
private List<String> mBodyText;

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

@ -32,7 +32,7 @@ import info.guardianproject.onionkit.ui.OrbotHelper; @@ -32,7 +32,7 @@ import info.guardianproject.onionkit.ui.OrbotHelper;
public class SettingsActivity extends ThemableSettingsActivity {
private static int API = android.os.Build.VERSION.SDK_INT;
private static final int API = android.os.Build.VERSION.SDK_INT;
private PreferenceManager mPreferences;
private Context mContext;
private Activity mActivity;

6
app/src/main/java/acr/browser/lightning/activity/ThemableActivity.java

@ -2,12 +2,12 @@ package acr.browser.lightning.activity; @@ -2,12 +2,12 @@ package acr.browser.lightning.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.R;
import acr.browser.lightning.preference.PreferenceManager;
public abstract class ThemableActivity extends ActionBarActivity {
public abstract class ThemableActivity extends AppCompatActivity {
private boolean mDark;

6
app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java

@ -2,12 +2,12 @@ package acr.browser.lightning.activity; @@ -2,12 +2,12 @@ package acr.browser.lightning.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.R;
import acr.browser.lightning.preference.PreferenceManager;
public abstract class ThemableSettingsActivity extends ActionBarActivity {
public abstract class ThemableSettingsActivity extends AppCompatActivity {
private boolean mDark;

1
app/src/main/java/acr/browser/lightning/constant/Constants.java

@ -14,7 +14,6 @@ public final class Constants { @@ -14,7 +14,6 @@ public final class Constants {
public static final String DESKTOP_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36";
public static final String MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; U; Android 4.4; en-us; Nexus 4 Build/JOP24G) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";
public static final int API = android.os.Build.VERSION.SDK_INT;
public static final String YAHOO_SEARCH = "https://search.yahoo.com/search?p=";
public static final String GOOGLE_SEARCH = "https://www.google.com/search?client=lightning&ie=UTF-8&oe=UTF-8&q=";
public static final String BING_SEARCH = "https://www.bing.com/search?q=";

42
app/src/main/java/acr/browser/lightning/controller/BrowserController.java

@ -14,45 +14,45 @@ import android.webkit.WebView; @@ -14,45 +14,45 @@ import android.webkit.WebView;
public interface BrowserController {
public void updateUrl(String title, boolean shortUrl);
void updateUrl(String title, boolean shortUrl);
public void updateProgress(int n);
void updateProgress(int n);
public void updateHistory(String title, String url);
void updateHistory(String title, String url);
public void openFileChooser(ValueCallback<Uri> uploadMsg);
void openFileChooser(ValueCallback<Uri> uploadMsg);
public void update();
void update();
public void onLongPress();
void onLongPress();
public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback);
void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback);
public void onHideCustomView();
void onHideCustomView();
public Bitmap getDefaultVideoPoster();
Bitmap getDefaultVideoPoster();
public View getVideoLoadingProgressView();
View getVideoLoadingProgressView();
public void onCreateWindow(boolean isUserGesture, Message resultMsg);
void onCreateWindow(boolean isUserGesture, Message resultMsg);
public Activity getActivity();
Activity getActivity();
public void hideActionBar();
void hideActionBar();
public void showActionBar();
void showActionBar();
public void toggleActionBar();
void toggleActionBar();
public void longClickPage(String url);
void longClickPage(String url);
public void openBookmarkPage(WebView view);
void openBookmarkPage(WebView view);
public void showFileChooser(ValueCallback<Uri[]> filePathCallback);
void showFileChooser(ValueCallback<Uri[]> filePathCallback);
public void closeEmptyTab();
void closeEmptyTab();
public boolean isIncognito();
boolean isIncognito();
public int getMenu();
int getMenu();
}

95
app/src/main/java/acr/browser/lightning/database/BookmarkManager.java

@ -1,9 +1,17 @@ @@ -1,9 +1,17 @@
package acr.browser.lightning.database;
import android.content.Context;
import android.database.Cursor;
import android.os.Environment;
import android.provider.Browser;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@ -15,15 +23,6 @@ import java.util.Locale; @@ -15,15 +23,6 @@ import java.util.Locale;
import java.util.SortedMap;
import java.util.TreeMap;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.database.Cursor;
import android.os.Environment;
import android.provider.Browser;
import android.widget.Toast;
import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
@ -31,13 +30,13 @@ import acr.browser.lightning.utils.Utils; @@ -31,13 +30,13 @@ import acr.browser.lightning.utils.Utils;
public class BookmarkManager {
private Context mContext;
private final Context mContext;
private static final String TITLE = "title";
private static final String URL = "url";
private static final String FOLDER = "folder";
private static final String ORDER = "order";
private static final String FILE_BOOKMARKS = "bookmarks.dat";
private static SortedMap<String, Integer> mBookmarkMap = new TreeMap<String, Integer>(
private static SortedMap<String, Integer> mBookmarkMap = new TreeMap<>(
String.CASE_INSENSITIVE_ORDER);
private static BookmarkManager mInstance;
@ -74,9 +73,7 @@ public class BookmarkManager { @@ -74,9 +73,7 @@ public class BookmarkManager {
bookmarkWriter.newLine();
bookmarkWriter.close();
mBookmarkMap.put(item.getUrl(), 1);
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return true;
@ -104,9 +101,7 @@ public class BookmarkManager { @@ -104,9 +101,7 @@ public class BookmarkManager {
}
}
bookmarkWriter.close();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
}
}
@ -117,7 +112,7 @@ public class BookmarkManager { @@ -117,7 +112,7 @@ public class BookmarkManager {
* @param url
*/
public synchronized boolean deleteBookmark(String url) {
List<HistoryItem> list = new ArrayList<HistoryItem>();
List<HistoryItem> list;
if (url == null) {
return false;
}
@ -141,9 +136,7 @@ public class BookmarkManager { @@ -141,9 +136,7 @@ public class BookmarkManager {
}
}
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return bookmarkDeleted;
@ -182,9 +175,7 @@ public class BookmarkManager { @@ -182,9 +175,7 @@ public class BookmarkManager {
mContext,
mContext.getString(R.string.bookmark_export_path) + " "
+ bookmarksExport.getPath(), Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
}
@ -196,7 +187,7 @@ public class BookmarkManager { @@ -196,7 +187,7 @@ public class BookmarkManager {
* @return
*/
public synchronized List<HistoryItem> getBookmarks(boolean sort) {
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
List<HistoryItem> bookmarks = new ArrayList<>();
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
try {
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
@ -212,11 +203,7 @@ public class BookmarkManager { @@ -212,11 +203,7 @@ public class BookmarkManager {
bookmarks.add(item);
}
bookmarksReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
}
if (sort) {
@ -232,7 +219,7 @@ public class BookmarkManager { @@ -232,7 +219,7 @@ public class BookmarkManager {
* @return
*/
public synchronized List<HistoryItem> getBookmarksFromFolder(String folder) {
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
List<HistoryItem> bookmarks = new ArrayList<>();
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
try {
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
@ -250,11 +237,7 @@ public class BookmarkManager { @@ -250,11 +237,7 @@ public class BookmarkManager {
}
}
bookmarksReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return bookmarks;
@ -266,7 +249,7 @@ public class BookmarkManager { @@ -266,7 +249,7 @@ public class BookmarkManager {
* @return
*/
private synchronized SortedMap<String, Integer> getBookmarkUrls() {
SortedMap<String, Integer> map = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
SortedMap<String, Integer> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
try {
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
@ -276,11 +259,7 @@ public class BookmarkManager { @@ -276,11 +259,7 @@ public class BookmarkManager {
map.put(object.getString(URL), 1);
}
bookmarksReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (JSONException | IOException e) {
e.printStackTrace();
}
return map;
@ -292,8 +271,8 @@ public class BookmarkManager { @@ -292,8 +271,8 @@ public class BookmarkManager {
* @return
*/
public synchronized List<HistoryItem> getFolders() {
List<HistoryItem> folders = new ArrayList<HistoryItem>();
SortedMap<String, Integer> folderMap = new TreeMap<String, Integer>(
List<HistoryItem> folders = new ArrayList<>();
SortedMap<String, Integer> folderMap = new TreeMap<>(
String.CASE_INSENSITIVE_ORDER);
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
try {
@ -311,11 +290,7 @@ public class BookmarkManager { @@ -311,11 +290,7 @@ public class BookmarkManager {
}
}
bookmarksReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return folders;
@ -328,7 +303,7 @@ public class BookmarkManager { @@ -328,7 +303,7 @@ public class BookmarkManager {
public synchronized void importBookmarksFromBrowser(Context context) {
if (PreferenceManager.getInstance().getSystemBrowserPresent()) {
List<HistoryItem> bookmarkList = new ArrayList<HistoryItem>();
List<HistoryItem> bookmarkList = new ArrayList<>();
String[] columns = new String[] { Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL };
String selection = Browser.BookmarkColumns.BOOKMARK + " = 1";
@ -372,7 +347,7 @@ public class BookmarkManager { @@ -372,7 +347,7 @@ public class BookmarkManager {
if (file == null) {
return;
}
List<HistoryItem> list = new ArrayList<HistoryItem>();
List<HistoryItem> list = new ArrayList<>();
try {
BufferedReader bookmarksReader = new BufferedReader(new FileReader(file));
String line;
@ -391,17 +366,7 @@ public class BookmarkManager { @@ -391,17 +366,7 @@ public class BookmarkManager {
addBookmarkList(list);
Utils.showToast(mContext,
number + " " + mContext.getResources().getString(R.string.message_import));
} catch (FileNotFoundException e) {
e.printStackTrace();
Utils.createInformativeDialog(context,
mContext.getResources().getString(R.string.title_error), mContext
.getResources().getString(R.string.import_bookmark_error));
} catch (IOException e) {
e.printStackTrace();
Utils.createInformativeDialog(context,
mContext.getResources().getString(R.string.title_error), mContext
.getResources().getString(R.string.import_bookmark_error));
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
Utils.createInformativeDialog(context,
mContext.getResources().getString(R.string.title_error), mContext
@ -430,9 +395,7 @@ public class BookmarkManager { @@ -430,9 +395,7 @@ public class BookmarkManager {
bookmarkWriter.newLine();
}
bookmarkWriter.close();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
} catch (IOException | JSONException e) {
e.printStackTrace();
}
}

7
app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java

@ -92,6 +92,7 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -92,6 +92,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
} else {
addHistoryItem(new HistoryItem(url, title));
}
q.close();
}
public synchronized void addHistoryItem(HistoryItem item) {
@ -116,7 +117,7 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -116,7 +117,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
}
public List<HistoryItem> findItemsContaining(String search) {
List<HistoryItem> itemList = new ArrayList<HistoryItem>();
List<HistoryItem> itemList = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " WHERE " + KEY_TITLE + " LIKE '%"
+ search + "%' OR " + KEY_URL + " LIKE '%" + search + "%' " + "ORDER BY "
+ KEY_TIME_VISITED + " DESC LIMIT 5";
@ -139,7 +140,7 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -139,7 +140,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
}
public List<HistoryItem> getLastHundredItems() {
List<HistoryItem> itemList = new ArrayList<HistoryItem>();
List<HistoryItem> itemList = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
+ " DESC";
@ -161,7 +162,7 @@ public class HistoryDatabase extends SQLiteOpenHelper { @@ -161,7 +162,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
}
public List<HistoryItem> getAllHistoryItems() {
List<HistoryItem> itemList = new ArrayList<HistoryItem>();
List<HistoryItem> itemList = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
+ " DESC";

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

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
package acr.browser.lightning.database;
import android.graphics.Bitmap;
import android.support.annotation.NonNull;
public class HistoryItem implements Comparable<HistoryItem> {
@ -112,7 +113,7 @@ public class HistoryItem implements Comparable<HistoryItem> { @@ -112,7 +113,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
}
@Override
public int compareTo(HistoryItem another) {
public int compareTo(@NonNull HistoryItem another) {
return mTitle.compareTo(another.mTitle);
}
@ -137,10 +138,7 @@ public class HistoryItem implements Comparable<HistoryItem> { @@ -137,10 +138,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
if (mBitmap != null ? !mBitmap.equals(that.mBitmap) : that.mBitmap != null) {
return false;
}
if (!mTitle.equals(that.mTitle)) {
return false;
}
return mUrl.equals(that.mUrl);
return mTitle.equals(that.mTitle) && mUrl.equals(that.mUrl);
}
@Override

2
app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

@ -131,7 +131,7 @@ public class DownloadHandler { @@ -131,7 +131,7 @@ public class DownloadHandler {
* If the request is coming from a private browsing tab.
*/
/* package */
static void onDownloadStartNoStream(Activity activity, String url, String userAgent,
private static void onDownloadStartNoStream(Activity activity, String url, String userAgent,
String contentDisposition, String mimetype, boolean privateBrowsing) {
String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);

15
app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java

@ -26,15 +26,15 @@ import acr.browser.lightning.R; @@ -26,15 +26,15 @@ import acr.browser.lightning.R;
*/
public class FetchUrlMimeType extends Thread {
private Context mContext;
private final Context mContext;
private DownloadManager.Request mRequest;
private final DownloadManager.Request mRequest;
private String mUri;
private final String mUri;
private String mCookies;
private final String mCookies;
private String mUserAgent;
private final String mUserAgent;
public FetchUrlMimeType(Context context, DownloadManager.Request request, String uri,
String cookies, String userAgent) {
@ -78,10 +78,7 @@ public class FetchUrlMimeType extends Thread { @@ -78,10 +78,7 @@ public class FetchUrlMimeType extends Thread {
contentDisposition = contentDispositionHeader;
}
}
} catch (IllegalArgumentException ex) {
if (connection != null)
connection.disconnect();
} catch (IOException ex) {
} catch (IllegalArgumentException | IOException ex) {
if (connection != null)
connection.disconnect();
} finally {

2
app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java

@ -16,7 +16,7 @@ import acr.browser.lightning.download.DownloadHandler; @@ -16,7 +16,7 @@ import acr.browser.lightning.download.DownloadHandler;
public class LightningDownloadListener implements DownloadListener {
private Activity mActivity;
private final Activity mActivity;
public LightningDownloadListener(Activity activity) {
mActivity = activity;

2
app/src/main/java/acr/browser/lightning/download/WebAddress.java

@ -32,7 +32,7 @@ public class WebAddress { @@ -32,7 +32,7 @@ public class WebAddress {
static final int MATCH_GROUP_HOST = 3;
static final int MATCH_GROUP_PORT = 4;
static final int MATCH_GROUP_PATH = 5;
static Pattern sAddressPattern = Pattern.compile(
static final Pattern sAddressPattern = Pattern.compile(
/* scheme */"(?:(http|https|file)\\:\\/\\/)?" +
/* authority */"(?:([-A-Za-z0-9$_.+!*'(),;?&=]+(?:\\:[-A-Za-z0-9$_.+!*'(),;?&=]+)?)@)?" +
/* host */"([" + GOOD_IRI_CHAR + "%_-][" + GOOD_IRI_CHAR + "%_\\.-]*|\\[[0-9a-fA-F:\\.]+\\])?" +

30
app/src/main/java/acr/browser/lightning/object/SearchAdapter.java

@ -50,26 +50,26 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -50,26 +50,26 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private List<HistoryItem> mFilteredList;
private List<HistoryItem> mAllBookmarks;
private HistoryDatabase mDatabaseHandler;
private Context mContext;
private final Context mContext;
private boolean mUseGoogle = true;
private boolean mIsExecuting = false;
private boolean mDarkTheme;
private boolean mIncognito;
private BookmarkManager mBookmarkManager;
private final boolean mDarkTheme;
private final boolean mIncognito;
private final BookmarkManager mBookmarkManager;
private static final String ENCODING = "ISO-8859-1";
private static final long INTERVAL_DAY = 86400000;
private String mSearchSubtitle;
private final String mSearchSubtitle;
private static final int API = Build.VERSION.SDK_INT;
private Theme mTheme;
private final Theme mTheme;
private SearchFilter mFilter;
public SearchAdapter(Context context, boolean dark, boolean incognito) {
mDatabaseHandler = HistoryDatabase.getInstance(context.getApplicationContext());
mTheme = context.getTheme();
mFilteredList = new ArrayList<HistoryItem>();
mHistory = new ArrayList<HistoryItem>();
mBookmarks = new ArrayList<HistoryItem>();
mSuggestions = new ArrayList<HistoryItem>();
mFilteredList = new ArrayList<>();
mHistory = new ArrayList<>();
mBookmarks = new ArrayList<>();
mSuggestions = new ArrayList<>();
mBookmarkManager = BookmarkManager.getInstance(context.getApplicationContext());
mAllBookmarks = mBookmarkManager.getBookmarks(true);
mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled();
@ -146,7 +146,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -146,7 +146,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
SuggestionHolder holder = null;
SuggestionHolder holder;
if (row == null) {
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
@ -228,7 +228,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -228,7 +228,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if (constraint == null || constraint.toString() == null) {
if (constraint == null) {
return results;
}
String query = constraint.toString().toLowerCase(Locale.getDefault());
@ -237,7 +237,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -237,7 +237,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
}
int counter = 0;
mBookmarks = new ArrayList<HistoryItem>();
mBookmarks = new ArrayList<>();
for (int n = 0; n < mAllBookmarks.size(); n++) {
if (counter >= 5) {
break;
@ -289,7 +289,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -289,7 +289,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
protected List<HistoryItem> doInBackground(String... arg0) {
mIsExecuting = true;
List<HistoryItem> filter = new ArrayList<HistoryItem>();
List<HistoryItem> filter = new ArrayList<>();
String query = arg0[0];
try {
query = query.replace(" ", "+");
@ -397,7 +397,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { @@ -397,7 +397,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
}
public List<HistoryItem> getSuggestions() {
List<HistoryItem> filteredList = new ArrayList<HistoryItem>();
List<HistoryItem> filteredList = new ArrayList<>();
int suggestionsSize = (mSuggestions == null) ? 0 : mSuggestions.size();
int historySize = (mHistory == null) ? 0 : mHistory.size();

11
app/src/main/java/acr/browser/lightning/reading/ArticleTextExtractor.java

@ -153,7 +153,7 @@ public class ArticleTextExtractor { @@ -153,7 +153,7 @@ public class ArticleTextExtractor {
}
if (bestMatchElement != null) {
List<ImageResult> images = new ArrayList<ImageResult>();
List<ImageResult> images = new ArrayList<>();
Element imgEl = determineImageSource(bestMatchElement, images);
if (imgEl != null) {
res.setImageUrl(SHelper.replaceSpaces(imgEl.attr("src")));
@ -321,7 +321,7 @@ public class ArticleTextExtractor { @@ -321,7 +321,7 @@ public class ArticleTextExtractor {
protected int weightChildNodes(Element rootEl) {
int weight = 0;
Element caption = null;
List<Element> pEls = new ArrayList<Element>(5);
List<Element> pEls = new ArrayList<>(5);
for (Element child : rootEl.children()) {
String ownText = child.ownText();
int ownTextLength = ownText.length();
@ -373,6 +373,7 @@ public class ArticleTextExtractor { @@ -373,6 +373,7 @@ public class ArticleTextExtractor {
try {
old = Integer.parseInt(el.attr("gravityScore"));
} catch (Exception ex) {
ex.printStackTrace();
}
return old;
}
@ -444,6 +445,7 @@ public class ArticleTextExtractor { @@ -444,6 +445,7 @@ public class ArticleTextExtractor {
else
weight -= 20;
} catch (Exception ex) {
ex.printStackTrace();
}
int width = 0;
@ -454,6 +456,7 @@ public class ArticleTextExtractor { @@ -454,6 +456,7 @@ public class ArticleTextExtractor {
else
weight -= 20;
} catch (Exception ex) {
ex.printStackTrace();
}
String alt = e.attr("alt");
if (alt.length() > 35)
@ -463,7 +466,7 @@ public class ArticleTextExtractor { @@ -463,7 +466,7 @@ public class ArticleTextExtractor {
if (title.length() > 35)
weight += 20;
String rel = null;
String rel;
boolean noFollow = false;
if (e.parent() != null) {
rel = e.parent().attr("rel");
@ -561,7 +564,7 @@ public class ArticleTextExtractor { @@ -561,7 +564,7 @@ public class ArticleTextExtractor {
* @return a set of all important nodes
*/
public Collection<Element> getNodes(Document doc) {
Set<Element> nodes = new HashSet<Element>(64);
Set<Element> nodes = new HashSet<>(64);
int score = 100;
for (Element el : doc.select("body").select("*")) {
if (NODES.matcher(el.tagName()).matches()) {

13
app/src/main/java/acr/browser/lightning/reading/Converter.java

@ -15,13 +15,17 @@ @@ -15,13 +15,17 @@
*/
package acr.browser.lightning.reading;
import java.io.*;
import java.net.SocketTimeoutException;
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Locale;
import acr.browser.lightning.constant.Constants;
import android.util.Log;
/**
* This class is not thread safe. Use one new instance every time due to
@ -156,8 +160,6 @@ public class Converter { @@ -156,8 +160,6 @@ public class Converter {
}
return output.toString(encoding);
} catch (SocketTimeoutException e) {
Log.e(Constants.TAG, e.toString() + " url:" + url);
} catch (IOException e) {
Log.e(Constants.TAG, e.toString() + " url:" + url);
} finally {
@ -165,6 +167,7 @@ public class Converter { @@ -165,6 +167,7 @@ public class Converter {
try {
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

8
app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java

@ -51,8 +51,8 @@ public class HtmlFetcher { @@ -51,8 +51,8 @@ public class HtmlFetcher {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("urls.txt"));
String line = null;
Set<String> existing = new LinkedHashSet<String>();
String line;
Set<String> existing = new LinkedHashSet<>();
while ((line = reader.readLine()) != null) {
int index1 = line.indexOf("\"");
int index2 = line.indexOf("\"", index1 + 1);
@ -81,10 +81,10 @@ public class HtmlFetcher { @@ -81,10 +81,10 @@ public class HtmlFetcher {
private String accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
private String charset = "UTF-8";
private SCache cache;
private AtomicInteger cacheCounter = new AtomicInteger(0);
private final AtomicInteger cacheCounter = new AtomicInteger(0);
private int maxTextLength = -1;
private ArticleTextExtractor extractor = new ArticleTextExtractor();
private Set<String> furtherResolveNecessary = new LinkedHashSet<String>() {
private final Set<String> furtherResolveNecessary = new LinkedHashSet<String>() {
{
add("bit.ly");
add("cli.gs");

14
app/src/main/java/acr/browser/lightning/reading/ImageResult.java

@ -9,13 +9,13 @@ import org.jsoup.nodes.Element; @@ -9,13 +9,13 @@ import org.jsoup.nodes.Element;
*/
public class ImageResult {
public String src;
public Integer weight;
public String title;
public int height;
public int width;
public String alt;
public boolean noFollow;
public final String src;
public final Integer weight;
public final String title;
public final int height;
public final int width;
public final String alt;
public final boolean noFollow;
public Element element;
public ImageResult(String src, Integer weight, String title, int height, int width, String alt,

2
app/src/main/java/acr/browser/lightning/reading/JResult.java

@ -133,7 +133,7 @@ public class JResult implements Serializable { @@ -133,7 +133,7 @@ public class JResult implements Serializable {
public List<String> getTextList() {
if (this.textList == null)
return new ArrayList<String>();
return new ArrayList<>();
return this.textList;
}

2
app/src/main/java/acr/browser/lightning/reading/OutputFormatter.java

@ -74,7 +74,7 @@ public class OutputFormatter { @@ -74,7 +74,7 @@ public class OutputFormatter {
* Takes an element and returns a list of texts extracted from the P tags
*/
public List<String> getTextList(Element topNode) {
List<String> texts = new ArrayList<String>();
List<String> texts = new ArrayList<>();
for (Element element : topNode.select(this.nodesToKeepCssSelector)) {
if (element.hasText()) {
texts.add(element.text());

2
app/src/main/java/acr/browser/lightning/reading/SHelper.java

@ -279,7 +279,6 @@ public class SHelper { @@ -279,7 +279,6 @@ public class SHelper {
if (url.startsWith("http://www.google.com/url?")) {
url = url.substring("http://www.google.com/url?".length());
String arr[] = urlDecode(url).split("\\&");
if (arr != null)
for (String str : arr) {
if (str.startsWith("q="))
return str.substring("q=".length());
@ -382,6 +381,7 @@ public class SHelper { @@ -382,6 +381,7 @@ public class SHelper {
try {
day = Integer.parseInt(str);
} catch (Exception ex) {
ex.printStackTrace();
}
if (day < 1 || day > 31) {
day = -1;

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

@ -20,7 +20,7 @@ public class AdBlock { @@ -20,7 +20,7 @@ public class AdBlock {
private static final String TAG = "AdBlock";
private static final String BLOCKED_DOMAINS_LIST_FILE_NAME = "hosts.txt";
private static final Set<String> mBlockedDomainsList = new HashSet<String>();
private static final Set<String> mBlockedDomainsList = new HashSet<>();
private boolean mBlockAds;
private static final Locale mLocale = Locale.getDefault();
private static AdBlock mInstance;

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

@ -19,7 +19,7 @@ import acr.browser.lightning.controller.BrowserController; @@ -19,7 +19,7 @@ import acr.browser.lightning.controller.BrowserController;
public class IntentUtils {
private Activity mActivity;
private final Activity mActivity;
static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile("(?i)"
+ // switch on case insensitive matching

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

@ -115,7 +115,7 @@ public final class Utils { @@ -115,7 +115,7 @@ public final class Utils {
}
public static List<HistoryItem> getOldBookmarks(Context context) {
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
List<HistoryItem> bookmarks = new ArrayList<>();
File bookUrl = new File(context.getFilesDir(), "bookurl");
File book = new File(context.getFilesDir(), "bookmarks");
try {
@ -128,8 +128,8 @@ public final class Utils { @@ -128,8 +128,8 @@ public final class Utils {
}
readBook.close();
readUrl.close();
} catch (FileNotFoundException ignored) {
} catch (IOException ignored) {
} catch (IOException e) {
e.printStackTrace();
}
return bookmarks;
}
@ -192,11 +192,10 @@ public final class Utils { @@ -192,11 +192,10 @@ public final class Utils {
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File imageFile = File.createTempFile(imageFileName, /* prefix */
return File.createTempFile(imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
return imageFile;
}
public static Bitmap getWebpageBitmap(Resources resources, boolean dark) {

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

@ -4,14 +4,6 @@ @@ -4,14 +4,6 @@
package acr.browser.lightning.view;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URISyntaxException;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
@ -28,6 +20,7 @@ import android.net.Uri; @@ -28,6 +20,7 @@ import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Message;
import android.support.annotation.NonNull;
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.util.Log;
@ -52,29 +45,36 @@ import android.webkit.WebViewClient; @@ -52,29 +45,36 @@ import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.LinearLayout;
import acr.browser.lightning.controller.BrowserController;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URISyntaxException;
import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.constant.StartPage;
import acr.browser.lightning.controller.BrowserController;
import acr.browser.lightning.download.LightningDownloadListener;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.R;
import acr.browser.lightning.utils.AdBlock;
import acr.browser.lightning.utils.IntentUtils;
import acr.browser.lightning.utils.Utils;
public class LightningView {
private Title mTitle;
private final Title mTitle;
private WebView mWebView;
private BrowserController mBrowserController;
private GestureDetector mGestureDetector;
private Activity mActivity;
private final Activity mActivity;
private WebSettings mSettings;
private static String mHomepage;
private static String mDefaultUserAgent;
private static Bitmap mWebpageBitmap;
private static PreferenceManager mPreferences;
private AdBlock mAdBlock;
private final AdBlock mAdBlock;
private IntentUtils mIntentUtils;
private final Paint mPaint = new Paint();
private boolean isForegroundTab;
@ -195,6 +195,7 @@ public class LightningView { @@ -195,6 +195,7 @@ public class LightningView {
icon = "file:///android_asset/startpage.png";
// "https://startpage.com/graphics/startp_logo.gif";
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
break;
case 7:
// DUCK_SEARCH;
icon = "file:///android_asset/duckduckgo.png";
@ -539,8 +540,6 @@ public class LightningView { @@ -539,8 +540,6 @@ public class LightningView {
icon.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
@ -637,7 +636,7 @@ public class LightningView { @@ -637,7 +636,7 @@ public class LightningView {
public class LightningWebClient extends WebViewClient {
Context mActivity;
final Context mActivity;
LightningWebClient(Context context) {
mActivity = context;
@ -690,7 +689,7 @@ public class LightningView { @@ -690,7 +689,7 @@ public class LightningView {
}
@Override
public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler,
public void onReceivedHttpAuthRequest(final WebView view, @NonNull final HttpAuthHandler handler,
final String host, final String realm) {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
@ -760,7 +759,7 @@ public class LightningView { @@ -760,7 +759,7 @@ public class LightningView {
}
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
public void onReceivedSslError(WebView view, @NonNull final SslErrorHandler handler, SslError error) {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mActivity.getString(R.string.title_warning));
builder.setMessage(mActivity.getString(R.string.message_untrusted_certificate))
@ -789,7 +788,7 @@ public class LightningView { @@ -789,7 +788,7 @@ public class LightningView {
}
@Override
public void onFormResubmission(WebView view, final Message dontResend, final Message resend) {
public void onFormResubmission(WebView view, @NonNull final Message dontResend, final Message resend) {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mActivity.getString(R.string.title_form_resubmission));
builder.setMessage(mActivity.getString(R.string.message_form_resubmission))
@ -830,7 +829,7 @@ public class LightningView { @@ -830,7 +829,7 @@ public class LightningView {
view.reload();
return true;
} else if (url.startsWith("intent://")) {
Intent intent = null;
Intent intent;
try {
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
} catch (URISyntaxException ex) {
@ -851,7 +850,7 @@ public class LightningView { @@ -851,7 +850,7 @@ public class LightningView {
public class LightningChromeClient extends WebChromeClient {
Context mActivity;
final Context mActivity;
LightningChromeClient(Context context) {
mActivity = context;
@ -888,7 +887,7 @@ public class LightningView { @@ -888,7 +887,7 @@ public class LightningView {
final boolean remember = true;
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mActivity.getString(R.string.location));
String org = null;
String org;
if (origin.length() > 50) {
org = origin.subSequence(0, 50) + "...";
} else {
@ -1012,7 +1011,7 @@ public class LightningView { @@ -1012,7 +1011,7 @@ public class LightningView {
private Bitmap mFavicon;
private String mTitle;
private Bitmap mDefaultIcon;
private final Bitmap mDefaultIcon;
public Title(Context context, boolean darkTheme) {
mDefaultIcon = Utils.getWebpageBitmap(context.getResources(), darkTheme);

Loading…
Cancel
Save