Lint fixes and code cleanup
This commit is contained in:
parent
cb27bf8afa
commit
fa1994c8b2
24
.idea/misc.xml
generated
24
.idea/misc.xml
generated
@ -3,5 +3,29 @@
|
|||||||
<component name="EntryPointsManager">
|
<component name="EntryPointsManager">
|
||||||
<entry_points version="2.0" />
|
<entry_points version="2.0" />
|
||||||
</component>
|
</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" />
|
<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>
|
</project>
|
@ -24,10 +24,6 @@
|
|||||||
android:name="android.hardware.touchscreen"
|
android:name="android.hardware.touchscreen"
|
||||||
android:required="false" />
|
android:required="false" />
|
||||||
|
|
||||||
<uses-sdk
|
|
||||||
android:minSdkVersion="14"
|
|
||||||
android:targetSdkVersion="22" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".activity.BrowserApp"
|
android:name=".activity.BrowserApp"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
@ -163,7 +163,7 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderPicker() {
|
private void renderPicker() {
|
||||||
|
|
||||||
AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
|
AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
|
||||||
picker.setTitle(getResources().getString(R.string.rendering_mode));
|
picker.setTitle(getResources().getString(R.string.rendering_mode));
|
||||||
@ -206,7 +206,7 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
|
|||||||
picker.show();
|
picker.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void urlBoxPicker() {
|
private void urlBoxPicker() {
|
||||||
|
|
||||||
AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
|
AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
|
||||||
picker.setTitle(getResources().getString(R.string.url_contents));
|
picker.setTitle(getResources().getString(R.string.url_contents));
|
||||||
|
@ -24,8 +24,6 @@ import acr.browser.lightning.R;
|
|||||||
public class BookmarkActivity extends ThemableSettingsActivity implements OnClickListener {
|
public class BookmarkActivity extends ThemableSettingsActivity implements OnClickListener {
|
||||||
|
|
||||||
private BookmarkManager mBookmarkManager;
|
private BookmarkManager mBookmarkManager;
|
||||||
private PreferenceManager mPreferences;
|
|
||||||
private boolean mSystemBrowser;
|
|
||||||
private File[] mFileList;
|
private File[] mFileList;
|
||||||
private String[] mFileNameList;
|
private String[] mFileNameList;
|
||||||
private static final File mPath = new File(Environment.getExternalStorageDirectory().toString());
|
private static final File mPath = new File(Environment.getExternalStorageDirectory().toString());
|
||||||
@ -48,15 +46,15 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
|
|||||||
TextView importBookmarks = (TextView) findViewById(R.id.isImportBrowserAvailable);
|
TextView importBookmarks = (TextView) findViewById(R.id.isImportBrowserAvailable);
|
||||||
|
|
||||||
mBookmarkManager = BookmarkManager.getInstance(getApplicationContext());
|
mBookmarkManager = BookmarkManager.getInstance(getApplicationContext());
|
||||||
mPreferences = PreferenceManager.getInstance();
|
PreferenceManager mPreferences = PreferenceManager.getInstance();
|
||||||
|
|
||||||
mSystemBrowser = mPreferences.getSystemBrowserPresent();
|
boolean systemBrowser = mPreferences.getSystemBrowserPresent();
|
||||||
|
|
||||||
exportBackup.setOnClickListener(this);
|
exportBackup.setOnClickListener(this);
|
||||||
importBackup.setOnClickListener(this);
|
importBackup.setOnClickListener(this);
|
||||||
importFromBrowser.setOnClickListener(this);
|
importFromBrowser.setOnClickListener(this);
|
||||||
|
|
||||||
if (mSystemBrowser) {
|
if (systemBrowser) {
|
||||||
importBookmarks.setText(getResources().getString(R.string.stock_browser_available));
|
importBookmarks.setText(getResources().getString(R.string.stock_browser_available));
|
||||||
} else {
|
} else {
|
||||||
importBookmarks.setText(getResources().getString(R.string.stock_browser_unavailable));
|
importBookmarks.setText(getResources().getString(R.string.stock_browser_unavailable));
|
||||||
@ -116,7 +114,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SortName implements Comparator<File> {
|
private class SortName implements Comparator<File> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(File a, File b) {
|
public int compare(File a, File b) {
|
||||||
@ -137,7 +135,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Dialog onCreateDialog(int id) {
|
protected Dialog onCreateDialog(int id) {
|
||||||
Dialog dialog = null;
|
Dialog dialog;
|
||||||
final AlertDialog.Builder builder = new Builder(this);
|
final AlertDialog.Builder builder = new Builder(this);
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
|
@ -96,19 +96,16 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
private FullscreenHolder mFullscreenContainer;
|
private FullscreenHolder mFullscreenContainer;
|
||||||
private ListView mDrawerListLeft, mDrawerListRight;
|
private ListView mDrawerListLeft, mDrawerListRight;
|
||||||
private LinearLayout mDrawerLeft, mDrawerRight, mUiLayout, mToolbarLayout;
|
private LinearLayout mDrawerLeft, mDrawerRight, mUiLayout, mToolbarLayout;
|
||||||
private RelativeLayout mNewTab, mSearchBar;
|
private RelativeLayout mSearchBar;
|
||||||
|
|
||||||
// List
|
// List
|
||||||
private final List<LightningView> mWebViews = new ArrayList<LightningView>();
|
private final List<LightningView> mWebViews = new ArrayList<>();
|
||||||
private List<HistoryItem> mBookmarkList;
|
private List<HistoryItem> mBookmarkList;
|
||||||
private LightningView mCurrentView;
|
private LightningView mCurrentView;
|
||||||
|
|
||||||
// View
|
|
||||||
private ActionBar mActionBar;
|
|
||||||
private AnimatedProgressBar mProgressBar;
|
private AnimatedProgressBar mProgressBar;
|
||||||
private AutoCompleteTextView mSearch;
|
private AutoCompleteTextView mSearch;
|
||||||
private ImageView mArrowImage;
|
private ImageView mArrowImage;
|
||||||
private Toolbar mToolbar;
|
|
||||||
private VideoView mVideoView;
|
private VideoView mVideoView;
|
||||||
private View mCustomView, mVideoProgressView;
|
private View mCustomView, mVideoProgressView;
|
||||||
|
|
||||||
@ -160,9 +157,9 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private synchronized void initialize() {
|
private synchronized void initialize() {
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
mToolbar = (Toolbar) findViewById(R.id.toolbar);
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(toolbar);
|
||||||
mActionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
|
||||||
mPreferences = PreferenceManager.getInstance();
|
mPreferences = PreferenceManager.getInstance();
|
||||||
mDarkTheme = mPreferences.getUseDarkTheme() || isIncognito();
|
mDarkTheme = mPreferences.getUseDarkTheme() || isIncognito();
|
||||||
@ -177,7 +174,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
|
|
||||||
mUiLayout = (LinearLayout) findViewById(R.id.ui_layout);
|
mUiLayout = (LinearLayout) findViewById(R.id.ui_layout);
|
||||||
mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
|
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);
|
mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer);
|
||||||
// Drawer stutters otherwise
|
// Drawer stutters otherwise
|
||||||
mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||||
@ -205,22 +202,22 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext());
|
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext());
|
||||||
|
|
||||||
// set display options of the ActionBar
|
// set display options of the ActionBar
|
||||||
mActionBar.setDisplayShowTitleEnabled(false);
|
actionBar.setDisplayShowTitleEnabled(false);
|
||||||
mActionBar.setDisplayShowHomeEnabled(false);
|
actionBar.setDisplayShowHomeEnabled(false);
|
||||||
mActionBar.setDisplayShowCustomEnabled(true);
|
actionBar.setDisplayShowCustomEnabled(true);
|
||||||
mActionBar.setCustomView(R.layout.toolbar_content);
|
actionBar.setCustomView(R.layout.toolbar_content);
|
||||||
|
|
||||||
View v = mActionBar.getCustomView();
|
View v = actionBar.getCustomView();
|
||||||
LayoutParams lp = v.getLayoutParams();
|
LayoutParams lp = v.getLayoutParams();
|
||||||
lp.width = LayoutParams.MATCH_PARENT;
|
lp.width = LayoutParams.MATCH_PARENT;
|
||||||
v.setLayoutParams(lp);
|
v.setLayoutParams(lp);
|
||||||
|
|
||||||
mArrowDrawable = new DrawerArrowDrawable(this);
|
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
|
// Use hardware acceleration for the animation
|
||||||
mArrowImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
mArrowImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||||
mArrowImage.setImageDrawable(mArrowDrawable);
|
mArrowImage.setImageDrawable(mArrowDrawable);
|
||||||
LinearLayout arrowButton = (LinearLayout) mActionBar.getCustomView().findViewById(
|
LinearLayout arrowButton = (LinearLayout) actionBar.getCustomView().findViewById(
|
||||||
R.id.arrow_button);
|
R.id.arrow_button);
|
||||||
arrowButton.setOnClickListener(this);
|
arrowButton.setOnClickListener(this);
|
||||||
|
|
||||||
@ -231,8 +228,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
forward.setOnClickListener(this);
|
forward.setOnClickListener(this);
|
||||||
|
|
||||||
// create the search EditText in the ToolBar
|
// create the search EditText in the ToolBar
|
||||||
mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search);
|
mSearch = (AutoCompleteTextView) actionBar.getCustomView().findViewById(R.id.search);
|
||||||
mUntitledTitle = (String) getString(R.string.untitled);
|
mUntitledTitle = getString(R.string.untitled);
|
||||||
mBackgroundColor = getResources().getColor(R.color.primary_color);
|
mBackgroundColor = getResources().getColor(R.color.primary_color);
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||||
mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete);
|
mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete);
|
||||||
@ -283,8 +280,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
});
|
});
|
||||||
initialize.run();
|
initialize.run();
|
||||||
|
|
||||||
mNewTab.setOnClickListener(this);
|
newTab.setOnClickListener(this);
|
||||||
mNewTab.setOnLongClickListener(new OnLongClickListener() {
|
newTab.setOnLongClickListener(new OnLongClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
@ -500,7 +497,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
* If Orbot/Tor is installed, prompt the user if they want to enable
|
* If Orbot/Tor is installed, prompt the user if they want to enable
|
||||||
* proxying for this session
|
* proxying for this session
|
||||||
*/
|
*/
|
||||||
public boolean checkForTor() {
|
private boolean checkForTor() {
|
||||||
boolean useProxy = mPreferences.getUseProxy();
|
boolean useProxy = mPreferences.getUseProxy();
|
||||||
|
|
||||||
OrbotHelper oh = new OrbotHelper(this);
|
OrbotHelper oh = new OrbotHelper(this);
|
||||||
@ -538,7 +535,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
/*
|
/*
|
||||||
* Initialize WebKit Proxying for Tor
|
* Initialize WebKit Proxying for Tor
|
||||||
*/
|
*/
|
||||||
public void initializeTor() {
|
private void initializeTor() {
|
||||||
|
|
||||||
OrbotHelper oh = new OrbotHelper(this);
|
OrbotHelper oh = new OrbotHelper(this);
|
||||||
if (!oh.isOrbotRunning()) {
|
if (!oh.isOrbotRunning()) {
|
||||||
@ -617,12 +614,12 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
mPreferences.setMemoryUrl("");
|
mPreferences.setMemoryUrl("");
|
||||||
String[] array = Utils.getArray(mem);
|
String[] array = Utils.getArray(mem);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int n = 0; n < array.length; n++) {
|
for (String urlString : array) {
|
||||||
if (array[n].length() > 0) {
|
if (urlString.length() > 0) {
|
||||||
if (url != null && url.compareTo(array[n]) == 0) {
|
if (url != null && url.compareTo(urlString) == 0) {
|
||||||
url = null;
|
url = null;
|
||||||
}
|
}
|
||||||
newTab(array[n], true);
|
newTab(urlString, true);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1459,13 +1456,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
|
|
||||||
public class LightningViewAdapter extends ArrayAdapter<LightningView> {
|
public class LightningViewAdapter extends ArrayAdapter<LightningView> {
|
||||||
|
|
||||||
Context context;
|
final Context context;
|
||||||
ColorMatrix colorMatrix;
|
ColorMatrix colorMatrix;
|
||||||
ColorMatrixColorFilter filter;
|
ColorMatrixColorFilter filter;
|
||||||
Paint paint;
|
Paint paint;
|
||||||
int layoutResourceId;
|
final int layoutResourceId;
|
||||||
List<LightningView> data = null;
|
List<LightningView> data = null;
|
||||||
CloseTabListener mExitListener;
|
final CloseTabListener mExitListener;
|
||||||
|
|
||||||
public LightningViewAdapter(Context context, int layoutResourceId, List<LightningView> data) {
|
public LightningViewAdapter(Context context, int layoutResourceId, List<LightningView> data) {
|
||||||
super(context, layoutResourceId, data);
|
super(context, layoutResourceId, data);
|
||||||
@ -1478,7 +1475,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
@Override
|
@Override
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
View row = convertView;
|
View row = convertView;
|
||||||
LightningViewHolder holder = null;
|
LightningViewHolder holder;
|
||||||
if (row == null) {
|
if (row == null) {
|
||||||
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||||||
row = inflater.inflate(layoutResourceId, parent, false);
|
row = inflater.inflate(layoutResourceId, parent, false);
|
||||||
@ -1591,11 +1588,11 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
public static boolean isColorTooDark(int color) {
|
public static boolean isColorTooDark(int color) {
|
||||||
final byte RED_CHANNEL = 16;
|
final byte RED_CHANNEL = 16;
|
||||||
final byte GREEN_CHANNEL = 8;
|
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 r = ((int) ((float) (color >> RED_CHANNEL & 0xff) * 0.3f)) & 0xff;
|
||||||
int g = ((int) ((float) (color >> GREEN_CHANNEL & 0xff) * 0.59)) & 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 gr = (r + g + b) & 0xff;
|
||||||
int gray = gr + (gr << GREEN_CHANNEL) + (gr << RED_CHANNEL);
|
int gray = gr + (gr << GREEN_CHANNEL) + (gr << RED_CHANNEL);
|
||||||
|
|
||||||
@ -1606,7 +1603,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
final byte ALPHA_CHANNEL = 24;
|
final byte ALPHA_CHANNEL = 24;
|
||||||
final byte RED_CHANNEL = 16;
|
final byte RED_CHANNEL = 16;
|
||||||
final byte GREEN_CHANNEL = 8;
|
final byte GREEN_CHANNEL = 8;
|
||||||
final byte BLUE_CHANNEL = 0;
|
//final byte BLUE_CHANNEL = 0;
|
||||||
|
|
||||||
final float inverseAmount = 1.0f - amount;
|
final float inverseAmount = 1.0f - amount;
|
||||||
|
|
||||||
@ -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 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;
|
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> {
|
public class BookmarkViewAdapter extends ArrayAdapter<HistoryItem> {
|
||||||
|
|
||||||
Context context;
|
final Context context;
|
||||||
List<HistoryItem> data = null;
|
List<HistoryItem> data = null;
|
||||||
int layoutResourceId;
|
final int layoutResourceId;
|
||||||
|
|
||||||
public BookmarkViewAdapter(Context context, int layoutResourceId, List<HistoryItem> data) {
|
public BookmarkViewAdapter(Context context, int layoutResourceId, List<HistoryItem> data) {
|
||||||
super(context, layoutResourceId, data);
|
super(context, layoutResourceId, data);
|
||||||
@ -1633,7 +1630,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View row = convertView;
|
View row = convertView;
|
||||||
BookmarkViewHolder holder = null;
|
BookmarkViewHolder holder;
|
||||||
|
|
||||||
if (row == null) {
|
if (row == null) {
|
||||||
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
|
||||||
@ -1670,8 +1667,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
|
|
||||||
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
|
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
|
||||||
|
|
||||||
ImageView bmImage;
|
final ImageView bmImage;
|
||||||
HistoryItem mWeb;
|
final HistoryItem mWeb;
|
||||||
|
|
||||||
public DownloadImageTask(ImageView bmImage, HistoryItem web) {
|
public DownloadImageTask(ImageView bmImage, HistoryItem web) {
|
||||||
this.bmImage = bmImage;
|
this.bmImage = bmImage;
|
||||||
@ -1852,14 +1849,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
public boolean getSystemBrowser() {
|
public boolean getSystemBrowser() {
|
||||||
Cursor c = null;
|
Cursor c = null;
|
||||||
String[] columns = new String[] { "url", "title" };
|
String[] columns = new String[] { "url", "title" };
|
||||||
boolean browserFlag = false;
|
boolean browserFlag;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Uri bookmarks = Browser.BOOKMARKS_URI;
|
Uri bookmarks = Browser.BOOKMARKS_URI;
|
||||||
c = getContentResolver().query(bookmarks, columns, null, null, null);
|
c = getContentResolver().query(bookmarks, columns, null, null, null);
|
||||||
} catch (SQLiteException ignored) {
|
} catch (SQLiteException | IllegalStateException | NullPointerException e) {
|
||||||
} catch (IllegalStateException ignored) {
|
e.printStackTrace();
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
@ -1871,7 +1867,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
}
|
}
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
c.close();
|
c.close();
|
||||||
c = null;
|
|
||||||
}
|
}
|
||||||
mPreferences.setSystemBrowserPresent(browserFlag);
|
mPreferences.setSystemBrowserPresent(browserFlag);
|
||||||
return browserFlag;
|
return browserFlag;
|
||||||
@ -1899,7 +1894,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
getUrl.setText(url);
|
getUrl.setText(url);
|
||||||
}
|
}
|
||||||
searchTheWeb(url);
|
searchTheWeb(url);
|
||||||
url = null;
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
|
||||||
if (mCurrentView != null) {
|
if (mCurrentView != null) {
|
||||||
@ -2045,7 +2039,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
|
|||||||
|
|
||||||
mFilePathCallback.onReceiveValue(results);
|
mFilePathCallback.onReceiveValue(results);
|
||||||
mFilePathCallback = null;
|
mFilePathCallback = null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -144,7 +144,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
|
|||||||
|
|
||||||
private static class MessageHandler extends Handler {
|
private static class MessageHandler extends Handler {
|
||||||
|
|
||||||
Context mHandlerContext;
|
final Context mHandlerContext;
|
||||||
|
|
||||||
public MessageHandler(Context context) {
|
public MessageHandler(Context context) {
|
||||||
this.mHandlerContext = context;
|
this.mHandlerContext = context;
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
package acr.browser.lightning.activity;
|
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.animation.ObjectAnimator;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
@ -18,7 +9,7 @@ import android.content.DialogInterface.OnClickListener;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -28,7 +19,17 @@ import android.widget.SeekBar;
|
|||||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||||
import android.widget.TextView;
|
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 mTitle;
|
||||||
private TextView mBody;
|
private TextView mBody;
|
||||||
@ -114,7 +115,7 @@ public class ReadingActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
private class PageLoader extends AsyncTask<String, Void, Void> {
|
private class PageLoader extends AsyncTask<String, Void, Void> {
|
||||||
|
|
||||||
private Context mContext;
|
private final Context mContext;
|
||||||
private ProgressDialog mProgressDialog;
|
private ProgressDialog mProgressDialog;
|
||||||
private String mTitleText;
|
private String mTitleText;
|
||||||
private List<String> mBodyText;
|
private List<String> mBodyText;
|
||||||
|
@ -32,7 +32,7 @@ import info.guardianproject.onionkit.ui.OrbotHelper;
|
|||||||
|
|
||||||
public class SettingsActivity extends ThemableSettingsActivity {
|
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 PreferenceManager mPreferences;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
|
@ -2,12 +2,12 @@ package acr.browser.lightning.activity;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
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.R;
|
||||||
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
|
|
||||||
public abstract class ThemableActivity extends ActionBarActivity {
|
public abstract class ThemableActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private boolean mDark;
|
private boolean mDark;
|
||||||
|
|
||||||
|
@ -2,12 +2,12 @@ package acr.browser.lightning.activity;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
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.R;
|
||||||
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
|
|
||||||
public abstract class ThemableSettingsActivity extends ActionBarActivity {
|
public abstract class ThemableSettingsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private boolean mDark;
|
private boolean mDark;
|
||||||
|
|
||||||
|
@ -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 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 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 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 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=";
|
public static final String BING_SEARCH = "https://www.bing.com/search?q=";
|
||||||
|
@ -14,45 +14,45 @@ import android.webkit.WebView;
|
|||||||
|
|
||||||
public interface BrowserController {
|
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();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
package acr.browser.lightning.database;
|
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.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -15,15 +23,6 @@ import java.util.Locale;
|
|||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
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.R;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
@ -31,13 +30,13 @@ import acr.browser.lightning.utils.Utils;
|
|||||||
|
|
||||||
public class BookmarkManager {
|
public class BookmarkManager {
|
||||||
|
|
||||||
private Context mContext;
|
private final Context mContext;
|
||||||
private static final String TITLE = "title";
|
private static final String TITLE = "title";
|
||||||
private static final String URL = "url";
|
private static final String URL = "url";
|
||||||
private static final String FOLDER = "folder";
|
private static final String FOLDER = "folder";
|
||||||
private static final String ORDER = "order";
|
private static final String ORDER = "order";
|
||||||
private static final String FILE_BOOKMARKS = "bookmarks.dat";
|
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);
|
String.CASE_INSENSITIVE_ORDER);
|
||||||
private static BookmarkManager mInstance;
|
private static BookmarkManager mInstance;
|
||||||
|
|
||||||
@ -74,9 +73,7 @@ public class BookmarkManager {
|
|||||||
bookmarkWriter.newLine();
|
bookmarkWriter.newLine();
|
||||||
bookmarkWriter.close();
|
bookmarkWriter.close();
|
||||||
mBookmarkMap.put(item.getUrl(), 1);
|
mBookmarkMap.put(item.getUrl(), 1);
|
||||||
} catch (IOException e) {
|
} catch (IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -104,9 +101,7 @@ public class BookmarkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bookmarkWriter.close();
|
bookmarkWriter.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +112,7 @@ public class BookmarkManager {
|
|||||||
* @param url
|
* @param url
|
||||||
*/
|
*/
|
||||||
public synchronized boolean deleteBookmark(String url) {
|
public synchronized boolean deleteBookmark(String url) {
|
||||||
List<HistoryItem> list = new ArrayList<HistoryItem>();
|
List<HistoryItem> list;
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -141,9 +136,7 @@ public class BookmarkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileWriter.close();
|
fileWriter.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return bookmarkDeleted;
|
return bookmarkDeleted;
|
||||||
@ -182,9 +175,7 @@ public class BookmarkManager {
|
|||||||
mContext,
|
mContext,
|
||||||
mContext.getString(R.string.bookmark_export_path) + " "
|
mContext.getString(R.string.bookmark_export_path) + " "
|
||||||
+ bookmarksExport.getPath(), Toast.LENGTH_SHORT).show();
|
+ bookmarksExport.getPath(), Toast.LENGTH_SHORT).show();
|
||||||
} catch (IOException e) {
|
} catch (IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +187,7 @@ public class BookmarkManager {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public synchronized List<HistoryItem> getBookmarks(boolean sort) {
|
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);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
try {
|
try {
|
||||||
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
|
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
|
||||||
@ -212,11 +203,7 @@ public class BookmarkManager {
|
|||||||
bookmarks.add(item);
|
bookmarks.add(item);
|
||||||
}
|
}
|
||||||
bookmarksReader.close();
|
bookmarksReader.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (sort) {
|
if (sort) {
|
||||||
@ -232,7 +219,7 @@ public class BookmarkManager {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public synchronized List<HistoryItem> getBookmarksFromFolder(String folder) {
|
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);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
try {
|
try {
|
||||||
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
|
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
|
||||||
@ -250,11 +237,7 @@ public class BookmarkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bookmarksReader.close();
|
bookmarksReader.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return bookmarks;
|
return bookmarks;
|
||||||
@ -266,7 +249,7 @@ public class BookmarkManager {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private synchronized SortedMap<String, Integer> getBookmarkUrls() {
|
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);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
try {
|
try {
|
||||||
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
|
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
|
||||||
@ -276,11 +259,7 @@ public class BookmarkManager {
|
|||||||
map.put(object.getString(URL), 1);
|
map.put(object.getString(URL), 1);
|
||||||
}
|
}
|
||||||
bookmarksReader.close();
|
bookmarksReader.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (JSONException | IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
@ -292,8 +271,8 @@ public class BookmarkManager {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public synchronized List<HistoryItem> getFolders() {
|
public synchronized List<HistoryItem> getFolders() {
|
||||||
List<HistoryItem> folders = new ArrayList<HistoryItem>();
|
List<HistoryItem> folders = new ArrayList<>();
|
||||||
SortedMap<String, Integer> folderMap = new TreeMap<String, Integer>(
|
SortedMap<String, Integer> folderMap = new TreeMap<>(
|
||||||
String.CASE_INSENSITIVE_ORDER);
|
String.CASE_INSENSITIVE_ORDER);
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
try {
|
try {
|
||||||
@ -311,11 +290,7 @@ public class BookmarkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bookmarksReader.close();
|
bookmarksReader.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return folders;
|
return folders;
|
||||||
@ -328,7 +303,7 @@ public class BookmarkManager {
|
|||||||
public synchronized void importBookmarksFromBrowser(Context context) {
|
public synchronized void importBookmarksFromBrowser(Context context) {
|
||||||
if (PreferenceManager.getInstance().getSystemBrowserPresent()) {
|
if (PreferenceManager.getInstance().getSystemBrowserPresent()) {
|
||||||
|
|
||||||
List<HistoryItem> bookmarkList = new ArrayList<HistoryItem>();
|
List<HistoryItem> bookmarkList = new ArrayList<>();
|
||||||
String[] columns = new String[] { Browser.BookmarkColumns.TITLE,
|
String[] columns = new String[] { Browser.BookmarkColumns.TITLE,
|
||||||
Browser.BookmarkColumns.URL };
|
Browser.BookmarkColumns.URL };
|
||||||
String selection = Browser.BookmarkColumns.BOOKMARK + " = 1";
|
String selection = Browser.BookmarkColumns.BOOKMARK + " = 1";
|
||||||
@ -372,7 +347,7 @@ public class BookmarkManager {
|
|||||||
if (file == null) {
|
if (file == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<HistoryItem> list = new ArrayList<HistoryItem>();
|
List<HistoryItem> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
BufferedReader bookmarksReader = new BufferedReader(new FileReader(file));
|
BufferedReader bookmarksReader = new BufferedReader(new FileReader(file));
|
||||||
String line;
|
String line;
|
||||||
@ -391,17 +366,7 @@ public class BookmarkManager {
|
|||||||
addBookmarkList(list);
|
addBookmarkList(list);
|
||||||
Utils.showToast(mContext,
|
Utils.showToast(mContext,
|
||||||
number + " " + mContext.getResources().getString(R.string.message_import));
|
number + " " + mContext.getResources().getString(R.string.message_import));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (IOException | JSONException 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) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Utils.createInformativeDialog(context,
|
Utils.createInformativeDialog(context,
|
||||||
mContext.getResources().getString(R.string.title_error), mContext
|
mContext.getResources().getString(R.string.title_error), mContext
|
||||||
@ -430,9 +395,7 @@ public class BookmarkManager {
|
|||||||
bookmarkWriter.newLine();
|
bookmarkWriter.newLine();
|
||||||
}
|
}
|
||||||
bookmarkWriter.close();
|
bookmarkWriter.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
} else {
|
} else {
|
||||||
addHistoryItem(new HistoryItem(url, title));
|
addHistoryItem(new HistoryItem(url, title));
|
||||||
}
|
}
|
||||||
|
q.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void addHistoryItem(HistoryItem item) {
|
public synchronized void addHistoryItem(HistoryItem item) {
|
||||||
@ -116,7 +117,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<HistoryItem> findItemsContaining(String search) {
|
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 '%"
|
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " WHERE " + KEY_TITLE + " LIKE '%"
|
||||||
+ search + "%' OR " + KEY_URL + " LIKE '%" + search + "%' " + "ORDER BY "
|
+ search + "%' OR " + KEY_URL + " LIKE '%" + search + "%' " + "ORDER BY "
|
||||||
+ KEY_TIME_VISITED + " DESC LIMIT 5";
|
+ KEY_TIME_VISITED + " DESC LIMIT 5";
|
||||||
@ -139,7 +140,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<HistoryItem> getLastHundredItems() {
|
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
|
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
|
||||||
+ " DESC";
|
+ " DESC";
|
||||||
|
|
||||||
@ -161,7 +162,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<HistoryItem> getAllHistoryItems() {
|
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
|
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
|
||||||
+ " DESC";
|
+ " DESC";
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package acr.browser.lightning.database;
|
package acr.browser.lightning.database;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
public class HistoryItem implements Comparable<HistoryItem> {
|
public class HistoryItem implements Comparable<HistoryItem> {
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(HistoryItem another) {
|
public int compareTo(@NonNull HistoryItem another) {
|
||||||
return mTitle.compareTo(another.mTitle);
|
return mTitle.compareTo(another.mTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,10 +138,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
|
|||||||
if (mBitmap != null ? !mBitmap.equals(that.mBitmap) : that.mBitmap != null) {
|
if (mBitmap != null ? !mBitmap.equals(that.mBitmap) : that.mBitmap != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!mTitle.equals(that.mTitle)) {
|
return mTitle.equals(that.mTitle) && mUrl.equals(that.mUrl);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mUrl.equals(that.mUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -131,8 +131,8 @@ public class DownloadHandler {
|
|||||||
* If the request is coming from a private browsing tab.
|
* If the request is coming from a private browsing tab.
|
||||||
*/
|
*/
|
||||||
/* package */
|
/* 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 contentDisposition, String mimetype, boolean privateBrowsing) {
|
||||||
|
|
||||||
String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
|
String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
|
||||||
|
|
||||||
|
@ -26,15 +26,15 @@ import acr.browser.lightning.R;
|
|||||||
*/
|
*/
|
||||||
public class FetchUrlMimeType extends Thread {
|
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,
|
public FetchUrlMimeType(Context context, DownloadManager.Request request, String uri,
|
||||||
String cookies, String userAgent) {
|
String cookies, String userAgent) {
|
||||||
@ -78,10 +78,7 @@ public class FetchUrlMimeType extends Thread {
|
|||||||
contentDisposition = contentDispositionHeader;
|
contentDisposition = contentDispositionHeader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException | IOException ex) {
|
||||||
if (connection != null)
|
|
||||||
connection.disconnect();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -16,7 +16,7 @@ import acr.browser.lightning.download.DownloadHandler;
|
|||||||
|
|
||||||
public class LightningDownloadListener implements DownloadListener {
|
public class LightningDownloadListener implements DownloadListener {
|
||||||
|
|
||||||
private Activity mActivity;
|
private final Activity mActivity;
|
||||||
|
|
||||||
public LightningDownloadListener(Activity activity) {
|
public LightningDownloadListener(Activity activity) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
|
@ -32,7 +32,7 @@ public class WebAddress {
|
|||||||
static final int MATCH_GROUP_HOST = 3;
|
static final int MATCH_GROUP_HOST = 3;
|
||||||
static final int MATCH_GROUP_PORT = 4;
|
static final int MATCH_GROUP_PORT = 4;
|
||||||
static final int MATCH_GROUP_PATH = 5;
|
static final int MATCH_GROUP_PATH = 5;
|
||||||
static Pattern sAddressPattern = Pattern.compile(
|
static final Pattern sAddressPattern = Pattern.compile(
|
||||||
/* scheme */"(?:(http|https|file)\\:\\/\\/)?" +
|
/* scheme */"(?:(http|https|file)\\:\\/\\/)?" +
|
||||||
/* authority */"(?:([-A-Za-z0-9$_.+!*'(),;?&=]+(?:\\:[-A-Za-z0-9$_.+!*'(),;?&=]+)?)@)?" +
|
/* authority */"(?:([-A-Za-z0-9$_.+!*'(),;?&=]+(?:\\:[-A-Za-z0-9$_.+!*'(),;?&=]+)?)@)?" +
|
||||||
/* host */"([" + GOOD_IRI_CHAR + "%_-][" + GOOD_IRI_CHAR + "%_\\.-]*|\\[[0-9a-fA-F:\\.]+\\])?" +
|
/* host */"([" + GOOD_IRI_CHAR + "%_-][" + GOOD_IRI_CHAR + "%_\\.-]*|\\[[0-9a-fA-F:\\.]+\\])?" +
|
||||||
|
@ -50,26 +50,26 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
private List<HistoryItem> mFilteredList;
|
private List<HistoryItem> mFilteredList;
|
||||||
private List<HistoryItem> mAllBookmarks;
|
private List<HistoryItem> mAllBookmarks;
|
||||||
private HistoryDatabase mDatabaseHandler;
|
private HistoryDatabase mDatabaseHandler;
|
||||||
private Context mContext;
|
private final Context mContext;
|
||||||
private boolean mUseGoogle = true;
|
private boolean mUseGoogle = true;
|
||||||
private boolean mIsExecuting = false;
|
private boolean mIsExecuting = false;
|
||||||
private boolean mDarkTheme;
|
private final boolean mDarkTheme;
|
||||||
private boolean mIncognito;
|
private final boolean mIncognito;
|
||||||
private BookmarkManager mBookmarkManager;
|
private final BookmarkManager mBookmarkManager;
|
||||||
private static final String ENCODING = "ISO-8859-1";
|
private static final String ENCODING = "ISO-8859-1";
|
||||||
private static final long INTERVAL_DAY = 86400000;
|
private static final long INTERVAL_DAY = 86400000;
|
||||||
private String mSearchSubtitle;
|
private final String mSearchSubtitle;
|
||||||
private static final int API = Build.VERSION.SDK_INT;
|
private static final int API = Build.VERSION.SDK_INT;
|
||||||
private Theme mTheme;
|
private final Theme mTheme;
|
||||||
private SearchFilter mFilter;
|
private SearchFilter mFilter;
|
||||||
|
|
||||||
public SearchAdapter(Context context, boolean dark, boolean incognito) {
|
public SearchAdapter(Context context, boolean dark, boolean incognito) {
|
||||||
mDatabaseHandler = HistoryDatabase.getInstance(context.getApplicationContext());
|
mDatabaseHandler = HistoryDatabase.getInstance(context.getApplicationContext());
|
||||||
mTheme = context.getTheme();
|
mTheme = context.getTheme();
|
||||||
mFilteredList = new ArrayList<HistoryItem>();
|
mFilteredList = new ArrayList<>();
|
||||||
mHistory = new ArrayList<HistoryItem>();
|
mHistory = new ArrayList<>();
|
||||||
mBookmarks = new ArrayList<HistoryItem>();
|
mBookmarks = new ArrayList<>();
|
||||||
mSuggestions = new ArrayList<HistoryItem>();
|
mSuggestions = new ArrayList<>();
|
||||||
mBookmarkManager = BookmarkManager.getInstance(context.getApplicationContext());
|
mBookmarkManager = BookmarkManager.getInstance(context.getApplicationContext());
|
||||||
mAllBookmarks = mBookmarkManager.getBookmarks(true);
|
mAllBookmarks = mBookmarkManager.getBookmarks(true);
|
||||||
mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled();
|
mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled();
|
||||||
@ -146,7 +146,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View row = convertView;
|
View row = convertView;
|
||||||
SuggestionHolder holder = null;
|
SuggestionHolder holder;
|
||||||
|
|
||||||
if (row == null) {
|
if (row == null) {
|
||||||
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
|
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
|
||||||
@ -228,7 +228,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
@Override
|
@Override
|
||||||
protected FilterResults performFiltering(CharSequence constraint) {
|
protected FilterResults performFiltering(CharSequence constraint) {
|
||||||
FilterResults results = new FilterResults();
|
FilterResults results = new FilterResults();
|
||||||
if (constraint == null || constraint.toString() == null) {
|
if (constraint == null) {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
String query = constraint.toString().toLowerCase(Locale.getDefault());
|
String query = constraint.toString().toLowerCase(Locale.getDefault());
|
||||||
@ -237,7 +237,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
mBookmarks = new ArrayList<HistoryItem>();
|
mBookmarks = new ArrayList<>();
|
||||||
for (int n = 0; n < mAllBookmarks.size(); n++) {
|
for (int n = 0; n < mAllBookmarks.size(); n++) {
|
||||||
if (counter >= 5) {
|
if (counter >= 5) {
|
||||||
break;
|
break;
|
||||||
@ -289,7 +289,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
protected List<HistoryItem> doInBackground(String... arg0) {
|
protected List<HistoryItem> doInBackground(String... arg0) {
|
||||||
mIsExecuting = true;
|
mIsExecuting = true;
|
||||||
|
|
||||||
List<HistoryItem> filter = new ArrayList<HistoryItem>();
|
List<HistoryItem> filter = new ArrayList<>();
|
||||||
String query = arg0[0];
|
String query = arg0[0];
|
||||||
try {
|
try {
|
||||||
query = query.replace(" ", "+");
|
query = query.replace(" ", "+");
|
||||||
@ -397,7 +397,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<HistoryItem> getSuggestions() {
|
public List<HistoryItem> getSuggestions() {
|
||||||
List<HistoryItem> filteredList = new ArrayList<HistoryItem>();
|
List<HistoryItem> filteredList = new ArrayList<>();
|
||||||
|
|
||||||
int suggestionsSize = (mSuggestions == null) ? 0 : mSuggestions.size();
|
int suggestionsSize = (mSuggestions == null) ? 0 : mSuggestions.size();
|
||||||
int historySize = (mHistory == null) ? 0 : mHistory.size();
|
int historySize = (mHistory == null) ? 0 : mHistory.size();
|
||||||
|
@ -153,7 +153,7 @@ public class ArticleTextExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bestMatchElement != null) {
|
if (bestMatchElement != null) {
|
||||||
List<ImageResult> images = new ArrayList<ImageResult>();
|
List<ImageResult> images = new ArrayList<>();
|
||||||
Element imgEl = determineImageSource(bestMatchElement, images);
|
Element imgEl = determineImageSource(bestMatchElement, images);
|
||||||
if (imgEl != null) {
|
if (imgEl != null) {
|
||||||
res.setImageUrl(SHelper.replaceSpaces(imgEl.attr("src")));
|
res.setImageUrl(SHelper.replaceSpaces(imgEl.attr("src")));
|
||||||
@ -321,7 +321,7 @@ public class ArticleTextExtractor {
|
|||||||
protected int weightChildNodes(Element rootEl) {
|
protected int weightChildNodes(Element rootEl) {
|
||||||
int weight = 0;
|
int weight = 0;
|
||||||
Element caption = null;
|
Element caption = null;
|
||||||
List<Element> pEls = new ArrayList<Element>(5);
|
List<Element> pEls = new ArrayList<>(5);
|
||||||
for (Element child : rootEl.children()) {
|
for (Element child : rootEl.children()) {
|
||||||
String ownText = child.ownText();
|
String ownText = child.ownText();
|
||||||
int ownTextLength = ownText.length();
|
int ownTextLength = ownText.length();
|
||||||
@ -373,6 +373,7 @@ public class ArticleTextExtractor {
|
|||||||
try {
|
try {
|
||||||
old = Integer.parseInt(el.attr("gravityScore"));
|
old = Integer.parseInt(el.attr("gravityScore"));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
@ -444,6 +445,7 @@ public class ArticleTextExtractor {
|
|||||||
else
|
else
|
||||||
weight -= 20;
|
weight -= 20;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
int width = 0;
|
int width = 0;
|
||||||
@ -454,6 +456,7 @@ public class ArticleTextExtractor {
|
|||||||
else
|
else
|
||||||
weight -= 20;
|
weight -= 20;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
String alt = e.attr("alt");
|
String alt = e.attr("alt");
|
||||||
if (alt.length() > 35)
|
if (alt.length() > 35)
|
||||||
@ -463,7 +466,7 @@ public class ArticleTextExtractor {
|
|||||||
if (title.length() > 35)
|
if (title.length() > 35)
|
||||||
weight += 20;
|
weight += 20;
|
||||||
|
|
||||||
String rel = null;
|
String rel;
|
||||||
boolean noFollow = false;
|
boolean noFollow = false;
|
||||||
if (e.parent() != null) {
|
if (e.parent() != null) {
|
||||||
rel = e.parent().attr("rel");
|
rel = e.parent().attr("rel");
|
||||||
@ -561,7 +564,7 @@ public class ArticleTextExtractor {
|
|||||||
* @return a set of all important nodes
|
* @return a set of all important nodes
|
||||||
*/
|
*/
|
||||||
public Collection<Element> getNodes(Document doc) {
|
public Collection<Element> getNodes(Document doc) {
|
||||||
Set<Element> nodes = new HashSet<Element>(64);
|
Set<Element> nodes = new HashSet<>(64);
|
||||||
int score = 100;
|
int score = 100;
|
||||||
for (Element el : doc.select("body").select("*")) {
|
for (Element el : doc.select("body").select("*")) {
|
||||||
if (NODES.matcher(el.tagName()).matches()) {
|
if (NODES.matcher(el.tagName()).matches()) {
|
||||||
|
@ -15,13 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
package acr.browser.lightning.reading;
|
package acr.browser.lightning.reading;
|
||||||
|
|
||||||
import java.io.*;
|
import android.util.Log;
|
||||||
import java.net.SocketTimeoutException;
|
|
||||||
|
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.nio.charset.Charset;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is not thread safe. Use one new instance every time due to
|
* This class is not thread safe. Use one new instance every time due to
|
||||||
@ -156,8 +160,6 @@ public class Converter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return output.toString(encoding);
|
return output.toString(encoding);
|
||||||
} catch (SocketTimeoutException e) {
|
|
||||||
Log.e(Constants.TAG, e.toString() + " url:" + url);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, e.toString() + " url:" + url);
|
Log.e(Constants.TAG, e.toString() + " url:" + url);
|
||||||
} finally {
|
} finally {
|
||||||
@ -165,6 +167,7 @@ public class Converter {
|
|||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ public class HtmlFetcher {
|
|||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
BufferedReader reader = new BufferedReader(new FileReader("urls.txt"));
|
BufferedReader reader = new BufferedReader(new FileReader("urls.txt"));
|
||||||
String line = null;
|
String line;
|
||||||
Set<String> existing = new LinkedHashSet<String>();
|
Set<String> existing = new LinkedHashSet<>();
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
int index1 = line.indexOf("\"");
|
int index1 = line.indexOf("\"");
|
||||||
int index2 = line.indexOf("\"", index1 + 1);
|
int index2 = line.indexOf("\"", index1 + 1);
|
||||||
@ -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 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 String charset = "UTF-8";
|
||||||
private SCache cache;
|
private SCache cache;
|
||||||
private AtomicInteger cacheCounter = new AtomicInteger(0);
|
private final AtomicInteger cacheCounter = new AtomicInteger(0);
|
||||||
private int maxTextLength = -1;
|
private int maxTextLength = -1;
|
||||||
private ArticleTextExtractor extractor = new ArticleTextExtractor();
|
private ArticleTextExtractor extractor = new ArticleTextExtractor();
|
||||||
private Set<String> furtherResolveNecessary = new LinkedHashSet<String>() {
|
private final Set<String> furtherResolveNecessary = new LinkedHashSet<String>() {
|
||||||
{
|
{
|
||||||
add("bit.ly");
|
add("bit.ly");
|
||||||
add("cli.gs");
|
add("cli.gs");
|
||||||
|
@ -9,13 +9,13 @@ import org.jsoup.nodes.Element;
|
|||||||
*/
|
*/
|
||||||
public class ImageResult {
|
public class ImageResult {
|
||||||
|
|
||||||
public String src;
|
public final String src;
|
||||||
public Integer weight;
|
public final Integer weight;
|
||||||
public String title;
|
public final String title;
|
||||||
public int height;
|
public final int height;
|
||||||
public int width;
|
public final int width;
|
||||||
public String alt;
|
public final String alt;
|
||||||
public boolean noFollow;
|
public final boolean noFollow;
|
||||||
public Element element;
|
public Element element;
|
||||||
|
|
||||||
public ImageResult(String src, Integer weight, String title, int height, int width, String alt,
|
public ImageResult(String src, Integer weight, String title, int height, int width, String alt,
|
||||||
|
@ -133,7 +133,7 @@ public class JResult implements Serializable {
|
|||||||
|
|
||||||
public List<String> getTextList() {
|
public List<String> getTextList() {
|
||||||
if (this.textList == null)
|
if (this.textList == null)
|
||||||
return new ArrayList<String>();
|
return new ArrayList<>();
|
||||||
return this.textList;
|
return this.textList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class OutputFormatter {
|
|||||||
* Takes an element and returns a list of texts extracted from the P tags
|
* Takes an element and returns a list of texts extracted from the P tags
|
||||||
*/
|
*/
|
||||||
public List<String> getTextList(Element topNode) {
|
public List<String> getTextList(Element topNode) {
|
||||||
List<String> texts = new ArrayList<String>();
|
List<String> texts = new ArrayList<>();
|
||||||
for (Element element : topNode.select(this.nodesToKeepCssSelector)) {
|
for (Element element : topNode.select(this.nodesToKeepCssSelector)) {
|
||||||
if (element.hasText()) {
|
if (element.hasText()) {
|
||||||
texts.add(element.text());
|
texts.add(element.text());
|
||||||
|
@ -279,11 +279,10 @@ public class SHelper {
|
|||||||
if (url.startsWith("http://www.google.com/url?")) {
|
if (url.startsWith("http://www.google.com/url?")) {
|
||||||
url = url.substring("http://www.google.com/url?".length());
|
url = url.substring("http://www.google.com/url?".length());
|
||||||
String arr[] = urlDecode(url).split("\\&");
|
String arr[] = urlDecode(url).split("\\&");
|
||||||
if (arr != null)
|
for (String str : arr) {
|
||||||
for (String str : arr) {
|
if (str.startsWith("q="))
|
||||||
if (str.startsWith("q="))
|
return str.substring("q=".length());
|
||||||
return str.substring("q=".length());
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -382,6 +381,7 @@ public class SHelper {
|
|||||||
try {
|
try {
|
||||||
day = Integer.parseInt(str);
|
day = Integer.parseInt(str);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
if (day < 1 || day > 31) {
|
if (day < 1 || day > 31) {
|
||||||
day = -1;
|
day = -1;
|
||||||
|
@ -20,7 +20,7 @@ public class AdBlock {
|
|||||||
|
|
||||||
private static final String TAG = "AdBlock";
|
private static final String TAG = "AdBlock";
|
||||||
private static final String BLOCKED_DOMAINS_LIST_FILE_NAME = "hosts.txt";
|
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 boolean mBlockAds;
|
||||||
private static final Locale mLocale = Locale.getDefault();
|
private static final Locale mLocale = Locale.getDefault();
|
||||||
private static AdBlock mInstance;
|
private static AdBlock mInstance;
|
||||||
|
@ -19,7 +19,7 @@ import acr.browser.lightning.controller.BrowserController;
|
|||||||
|
|
||||||
public class IntentUtils {
|
public class IntentUtils {
|
||||||
|
|
||||||
private Activity mActivity;
|
private final Activity mActivity;
|
||||||
|
|
||||||
static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile("(?i)"
|
static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile("(?i)"
|
||||||
+ // switch on case insensitive matching
|
+ // switch on case insensitive matching
|
||||||
|
@ -115,7 +115,7 @@ public final class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<HistoryItem> getOldBookmarks(Context context) {
|
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 bookUrl = new File(context.getFilesDir(), "bookurl");
|
||||||
File book = new File(context.getFilesDir(), "bookmarks");
|
File book = new File(context.getFilesDir(), "bookmarks");
|
||||||
try {
|
try {
|
||||||
@ -128,8 +128,8 @@ public final class Utils {
|
|||||||
}
|
}
|
||||||
readBook.close();
|
readBook.close();
|
||||||
readUrl.close();
|
readUrl.close();
|
||||||
} catch (FileNotFoundException ignored) {
|
} catch (IOException e) {
|
||||||
} catch (IOException ignored) {
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return bookmarks;
|
return bookmarks;
|
||||||
}
|
}
|
||||||
@ -192,11 +192,10 @@ public final class Utils {
|
|||||||
String imageFileName = "JPEG_" + timeStamp + "_";
|
String imageFileName = "JPEG_" + timeStamp + "_";
|
||||||
File storageDir = Environment
|
File storageDir = Environment
|
||||||
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
||||||
File imageFile = File.createTempFile(imageFileName, /* prefix */
|
return File.createTempFile(imageFileName, /* prefix */
|
||||||
".jpg", /* suffix */
|
".jpg", /* suffix */
|
||||||
storageDir /* directory */
|
storageDir /* directory */
|
||||||
);
|
);
|
||||||
return imageFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getWebpageBitmap(Resources resources, boolean dark) {
|
public static Bitmap getWebpageBitmap(Resources resources, boolean dark) {
|
||||||
|
@ -4,14 +4,6 @@
|
|||||||
|
|
||||||
package acr.browser.lightning.view;
|
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.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@ -28,6 +20,7 @@ import android.net.Uri;
|
|||||||
import android.net.http.SslError;
|
import android.net.http.SslError;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.method.PasswordTransformationMethod;
|
import android.text.method.PasswordTransformationMethod;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -52,29 +45,36 @@ import android.webkit.WebViewClient;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
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.Constants;
|
||||||
import acr.browser.lightning.constant.StartPage;
|
import acr.browser.lightning.constant.StartPage;
|
||||||
|
import acr.browser.lightning.controller.BrowserController;
|
||||||
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 acr.browser.lightning.R;
|
|
||||||
import acr.browser.lightning.utils.AdBlock;
|
import acr.browser.lightning.utils.AdBlock;
|
||||||
import acr.browser.lightning.utils.IntentUtils;
|
import acr.browser.lightning.utils.IntentUtils;
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
|
|
||||||
public class LightningView {
|
public class LightningView {
|
||||||
|
|
||||||
private Title mTitle;
|
private final Title mTitle;
|
||||||
private WebView mWebView;
|
private WebView mWebView;
|
||||||
private BrowserController mBrowserController;
|
private BrowserController mBrowserController;
|
||||||
private GestureDetector mGestureDetector;
|
private GestureDetector mGestureDetector;
|
||||||
private Activity mActivity;
|
private final Activity mActivity;
|
||||||
private WebSettings mSettings;
|
private WebSettings mSettings;
|
||||||
private static String mHomepage;
|
private static String mHomepage;
|
||||||
private static String mDefaultUserAgent;
|
private static String mDefaultUserAgent;
|
||||||
private static Bitmap mWebpageBitmap;
|
private static Bitmap mWebpageBitmap;
|
||||||
private static PreferenceManager mPreferences;
|
private static PreferenceManager mPreferences;
|
||||||
private AdBlock mAdBlock;
|
private final AdBlock mAdBlock;
|
||||||
private IntentUtils mIntentUtils;
|
private IntentUtils mIntentUtils;
|
||||||
private final Paint mPaint = new Paint();
|
private final Paint mPaint = new Paint();
|
||||||
private boolean isForegroundTab;
|
private boolean isForegroundTab;
|
||||||
@ -195,6 +195,7 @@ public class LightningView {
|
|||||||
icon = "file:///android_asset/startpage.png";
|
icon = "file:///android_asset/startpage.png";
|
||||||
// "https://startpage.com/graphics/startp_logo.gif";
|
// "https://startpage.com/graphics/startp_logo.gif";
|
||||||
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
|
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
|
||||||
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
// DUCK_SEARCH;
|
// DUCK_SEARCH;
|
||||||
icon = "file:///android_asset/duckduckgo.png";
|
icon = "file:///android_asset/duckduckgo.png";
|
||||||
@ -539,8 +540,6 @@ public class LightningView {
|
|||||||
icon.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
icon.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||||||
fos.flush();
|
fos.flush();
|
||||||
fos.close();
|
fos.close();
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -637,7 +636,7 @@ public class LightningView {
|
|||||||
|
|
||||||
public class LightningWebClient extends WebViewClient {
|
public class LightningWebClient extends WebViewClient {
|
||||||
|
|
||||||
Context mActivity;
|
final Context mActivity;
|
||||||
|
|
||||||
LightningWebClient(Context context) {
|
LightningWebClient(Context context) {
|
||||||
mActivity = context;
|
mActivity = context;
|
||||||
@ -690,7 +689,7 @@ public class LightningView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
final String host, final String realm) {
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||||
@ -760,7 +759,7 @@ public class LightningView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||||
builder.setTitle(mActivity.getString(R.string.title_warning));
|
builder.setTitle(mActivity.getString(R.string.title_warning));
|
||||||
builder.setMessage(mActivity.getString(R.string.message_untrusted_certificate))
|
builder.setMessage(mActivity.getString(R.string.message_untrusted_certificate))
|
||||||
@ -789,7 +788,7 @@ public class LightningView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||||
builder.setTitle(mActivity.getString(R.string.title_form_resubmission));
|
builder.setTitle(mActivity.getString(R.string.title_form_resubmission));
|
||||||
builder.setMessage(mActivity.getString(R.string.message_form_resubmission))
|
builder.setMessage(mActivity.getString(R.string.message_form_resubmission))
|
||||||
@ -830,7 +829,7 @@ public class LightningView {
|
|||||||
view.reload();
|
view.reload();
|
||||||
return true;
|
return true;
|
||||||
} else if (url.startsWith("intent://")) {
|
} else if (url.startsWith("intent://")) {
|
||||||
Intent intent = null;
|
Intent intent;
|
||||||
try {
|
try {
|
||||||
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
|
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
|
||||||
} catch (URISyntaxException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
@ -851,7 +850,7 @@ public class LightningView {
|
|||||||
|
|
||||||
public class LightningChromeClient extends WebChromeClient {
|
public class LightningChromeClient extends WebChromeClient {
|
||||||
|
|
||||||
Context mActivity;
|
final Context mActivity;
|
||||||
|
|
||||||
LightningChromeClient(Context context) {
|
LightningChromeClient(Context context) {
|
||||||
mActivity = context;
|
mActivity = context;
|
||||||
@ -888,7 +887,7 @@ public class LightningView {
|
|||||||
final boolean remember = true;
|
final boolean remember = true;
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||||
builder.setTitle(mActivity.getString(R.string.location));
|
builder.setTitle(mActivity.getString(R.string.location));
|
||||||
String org = null;
|
String org;
|
||||||
if (origin.length() > 50) {
|
if (origin.length() > 50) {
|
||||||
org = origin.subSequence(0, 50) + "...";
|
org = origin.subSequence(0, 50) + "...";
|
||||||
} else {
|
} else {
|
||||||
@ -1012,7 +1011,7 @@ public class LightningView {
|
|||||||
|
|
||||||
private Bitmap mFavicon;
|
private Bitmap mFavicon;
|
||||||
private String mTitle;
|
private String mTitle;
|
||||||
private Bitmap mDefaultIcon;
|
private final Bitmap mDefaultIcon;
|
||||||
|
|
||||||
public Title(Context context, boolean darkTheme) {
|
public Title(Context context, boolean darkTheme) {
|
||||||
mDefaultIcon = Utils.getWebpageBitmap(context.getResources(), darkTheme);
|
mDefaultIcon = Utils.getWebpageBitmap(context.getResources(), darkTheme);
|
||||||
|
Loading…
Reference in New Issue
Block a user