Browse Source

Fix lint problems and other code style problems, also fixed sluggish navigation drawer issues

master
Anthony Restaino 10 years ago
parent
commit
d60fe82b4a
  1. 2
      res/layout/search.xml
  2. 12
      res/layout/tab_drawer.xml
  3. 2
      src/acr/browser/lightning/AnimatedProgressBar.java
  4. 3
      src/acr/browser/lightning/BookmarkManager.java
  5. 124
      src/acr/browser/lightning/BrowserActivity.java
  6. 10
      src/acr/browser/lightning/HistoryDatabaseHandler.java
  7. 6
      src/acr/browser/lightning/HistoryItem.java
  8. 6
      src/acr/browser/lightning/IntentUtils.java
  9. 36
      src/acr/browser/lightning/LightningView.java
  10. 1
      src/acr/browser/lightning/MainActivity.java
  11. 8
      src/acr/browser/lightning/SearchAdapter.java

2
res/layout/search.xml

@ -21,7 +21,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@null" android:background="@null"
android:gravity="left|center_vertical" android:gravity="left|center_vertical"
android:hint="@+string/search_hint" android:hint="@string/search_hint"
android:imeOptions="actionGo" android:imeOptions="actionGo"
android:inputType="textUri" android:inputType="textUri"
android:paddingBottom="1dp" android:paddingBottom="1dp"

12
res/layout/tab_drawer.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/left_drawer" android:id="@+id/left_drawer"
android:layout_width="@dimen/navigation_width" android:layout_width="@dimen/navigation_width"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -13,7 +13,6 @@
android:id="@+id/new_tab_button" android:id="@+id/new_tab_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="?attr/listBackground" android:background="?attr/listBackground"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal" > android:orientation="horizontal" >
@ -49,14 +48,13 @@
android:id="@+id/view" android:id="@+id/view"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_below="@+id/new_tab_button"
android:background="@color/gray_list_bg" /> android:background="@color/gray_list_bg" />
<ListView <ListView
android:id="@+id/left_drawer_list" android:id="@+id/left_drawer_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="0dp"
android:layout_above="@+id/lineView" android:layout_weight="1"
android:layout_below="@+id/view" android:layout_below="@+id/view"
android:choiceMode="singleChoice" android:choiceMode="singleChoice"
android:dividerHeight="1dp" android:dividerHeight="1dp"
@ -66,14 +64,12 @@
android:id="@+id/lineView" android:id="@+id/lineView"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_above="@+id/linearLayout1"
android:background="@color/gray_list_bg" /> android:background="@color/gray_list_bg" />
<LinearLayout <LinearLayout
android:id="@+id/linearLayout1" android:id="@+id/linearLayout1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:baselineAligned="false" android:baselineAligned="false"
android:orientation="horizontal" android:orientation="horizontal"
android:weightSum="2" > android:weightSum="2" >
@ -119,4 +115,4 @@
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
</RelativeLayout> </LinearLayout>

2
src/acr/browser/lightning/AnimatedProgressBar.java

@ -61,7 +61,7 @@ public class AnimatedProgressBar extends LinearLayout {
* @param attrs is the attribute set passed by the constructor * @param attrs is the attribute set passed by the constructor
*/ */
private void init(final Context context, AttributeSet attrs) { private void init(final Context context, AttributeSet attrs) {
this.setLayerType(LAYER_TYPE_HARDWARE, null); this.setLayerType(LAYER_TYPE_NONE, null);
TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AnimatedProgressBar, 0, 0); TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AnimatedProgressBar, 0, 0);
int backgroundColor; int backgroundColor;
int progressColor; int progressColor;

3
src/acr/browser/lightning/BookmarkManager.java

@ -360,10 +360,9 @@ public class BookmarkManager {
if (file == null) { if (file == null) {
return; return;
} }
File bookmarksImport = file;
List<HistoryItem> list = new ArrayList<HistoryItem>(); List<HistoryItem> list = new ArrayList<HistoryItem>();
try { try {
BufferedReader bookmarksReader = new BufferedReader(new FileReader(bookmarksImport)); BufferedReader bookmarksReader = new BufferedReader(new FileReader(file));
String line; String line;
int number = 0; int number = 0;
while ((line = bookmarksReader.readLine()) != null) { while ((line = bookmarksReader.readLine()) != null) {

124
src/acr/browser/lightning/BrowserActivity.java

@ -77,7 +77,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
private DrawerLayout mDrawerLayout; private DrawerLayout mDrawerLayout;
private ListView mDrawerListLeft; private ListView mDrawerListLeft;
private RelativeLayout mDrawerLeft; private LinearLayout mDrawerLeft;
private LinearLayout mDrawerRight; private LinearLayout mDrawerRight;
private ListView mDrawerListRight; private ListView mDrawerListRight;
private RelativeLayout mNewTab; private RelativeLayout mNewTab;
@ -171,15 +171,20 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
// mProgressBar.setVisibility(View.GONE); // mProgressBar.setVisibility(View.GONE);
// TODO // TODO
mNewTab = (RelativeLayout) findViewById(R.id.new_tab_button); mNewTab = (RelativeLayout) findViewById(R.id.new_tab_button);
mDrawerLeft = (RelativeLayout) findViewById(R.id.left_drawer); mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer);
mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null); // Drawer
// stutters
// otherwise
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerListLeft = (ListView) findViewById(R.id.left_drawer_list); mDrawerListLeft = (ListView) findViewById(R.id.left_drawer_list);
mDrawerListLeft.setDivider(null); mDrawerListLeft.setDivider(null);
mDrawerListLeft.setDividerHeight(0); mDrawerListLeft.setDividerHeight(0);
mDrawerRight = (LinearLayout) findViewById(R.id.right_drawer); mDrawerRight = (LinearLayout) findViewById(R.id.right_drawer);
mDrawerRight.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mDrawerListRight = (ListView) findViewById(R.id.right_drawer_list); mDrawerListRight = (ListView) findViewById(R.id.right_drawer_list);
mDrawerListRight.setDivider(null); mDrawerListRight.setDivider(null);
mDrawerListRight.setDividerHeight(0); mDrawerListRight.setDividerHeight(0);
setNavigationDrawerWidth(); setNavigationDrawerWidth();
mDrawerLayout.setDrawerListener(new DrawerLocker()); mDrawerLayout.setDrawerListener(new DrawerLocker());
@ -232,6 +237,11 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
mArrowDrawable = new DrawerArrowDrawable(this); mArrowDrawable = new DrawerArrowDrawable(this);
mArrowImage = (ImageView) mActionBar.getCustomView().findViewById(R.id.arrow); mArrowImage = (ImageView) mActionBar.getCustomView().findViewById(R.id.arrow);
mArrowImage.setLayerType(View.LAYER_TYPE_HARDWARE, null); // Use a
// hardware
// layer for
// the
// animation
mArrowImage.setImageDrawable(mArrowDrawable); mArrowImage.setImageDrawable(mArrowDrawable);
LinearLayout arrowButton = (LinearLayout) mActionBar.getCustomView().findViewById( LinearLayout arrowButton = (LinearLayout) mActionBar.getCustomView().findViewById(
R.id.arrow_button); R.id.arrow_button);
@ -399,17 +409,22 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
@Override @Override
public void onFocusChange(View v, final boolean hasFocus) { public void onFocusChange(View v, final boolean hasFocus) {
if (!hasFocus && mCurrentView != null) { if (!hasFocus && mCurrentView != null) {
if (mCurrentView != null) {
if (mCurrentView.getProgress() < 100) { if (mCurrentView.getProgress() < 100) {
setIsLoading(); setIsLoading();
} else { } else {
setIsFinishedLoading(); setIsFinishedLoading();
} }
}
updateUrl(mCurrentView.getUrl(), true); updateUrl(mCurrentView.getUrl(), true);
} else if (hasFocus) { } else if (hasFocus) {
updateUrl(mCurrentView.getUrl(), false); String url = mCurrentView.getUrl();
mSearch.selectAll(); if (url == null || url.startsWith(Constants.FILE)) {
mSearch.setText("");
} else {
mSearch.setText(url);
}
((AutoCompleteTextView) v).selectAll(); // Hack to make sure
// the text gets
// selected
mIcon = mCopyIcon; mIcon = mCopyIcon;
mSearch.setCompoundDrawables(null, null, mCopyIcon, null); mSearch.setCompoundDrawables(null, null, mCopyIcon, null);
} }
@ -578,8 +593,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
if (mCurrentView != null) { if (mCurrentView != null) {
if (!mCurrentView.getUrl().startsWith(Constants.FILE)) { if (!mCurrentView.getUrl().startsWith(Constants.FILE)) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl() ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl());
.toString());
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
Utils.showToast(mContext, Utils.showToast(mContext,
mContext.getResources().getString(R.string.message_link_copied)); mContext.getResources().getString(R.string.message_link_copied));
@ -653,7 +667,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
.setNegativeButton(R.string.no, dialogClickListener).show(); .setNegativeButton(R.string.no, dialogClickListener).show();
return true; return true;
} else if (oh.isOrbotInstalled() & useProxy == true) { } else if (oh.isOrbotInstalled() & useProxy) {
initializeTor(); initializeTor();
return true; return true;
} else { } else {
@ -691,19 +705,23 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
.getLayoutParams(); .getLayoutParams();
params.width = maxWidth; params.width = maxWidth;
mDrawerLeft.setLayoutParams(params); mDrawerLeft.setLayoutParams(params);
mDrawerLeft.requestLayout();
DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight
.getLayoutParams(); .getLayoutParams();
paramsRight.width = maxWidth; paramsRight.width = maxWidth;
mDrawerRight.setLayoutParams(paramsRight); mDrawerRight.setLayoutParams(paramsRight);
mDrawerRight.requestLayout();
} else { } else {
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft
.getLayoutParams(); .getLayoutParams();
params.width = width; params.width = width;
mDrawerLeft.setLayoutParams(params); mDrawerLeft.setLayoutParams(params);
mDrawerLeft.requestLayout();
DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight
.getLayoutParams(); .getLayoutParams();
paramsRight.width = width; paramsRight.width = width;
mDrawerRight.setLayoutParams(paramsRight); mDrawerRight.setLayoutParams(paramsRight);
mDrawerRight.requestLayout();
} }
} }
@ -729,7 +747,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
if (mPreferences.getBoolean(PreferenceConstants.RESTORE_LOST_TABS, true)) { if (mPreferences.getBoolean(PreferenceConstants.RESTORE_LOST_TABS, true)) {
String mem = mPreferences.getString(PreferenceConstants.URL_MEMORY, ""); String mem = mPreferences.getString(PreferenceConstants.URL_MEMORY, "");
mEditPrefs.putString(PreferenceConstants.URL_MEMORY, ""); mEditPrefs.putString(PreferenceConstants.URL_MEMORY, "").apply();
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 (int n = 0; n < array.length; n++) {
@ -899,8 +917,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
if (mCurrentView != null) { if (mCurrentView != null) {
if (!mCurrentView.getUrl().startsWith(Constants.FILE)) { if (!mCurrentView.getUrl().startsWith(Constants.FILE)) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl() ClipData clip = ClipData.newPlainText("label", mCurrentView.getUrl());
.toString());
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
Utils.showToast(mContext, Utils.showToast(mContext,
mContext.getResources().getString(R.string.message_link_copied)); mContext.getResources().getString(R.string.message_link_copied));
@ -1006,25 +1023,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
}); });
} }
/** private void showCloseDialog(final int position) {
* The click listener for ListView in the navigation drawer
*/
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mIsNewIntent = false;
selectItem(position);
}
}
/**
* long click listener for Navigation Drawer
*/
private class DrawerItemLongClickListener implements ListView.OnItemLongClickListener {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext); AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext, ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext,
android.R.layout.simple_dropdown_item_1line); android.R.layout.simple_dropdown_item_1line);
@ -1047,6 +1046,28 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
}); });
builder.show(); builder.show();
}
/**
* The click listener for ListView in the navigation drawer
*/
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mIsNewIntent = false;
selectItem(position);
}
}
/**
* long click listener for Navigation Drawer
*/
private class DrawerItemLongClickListener implements ListView.OnItemLongClickListener {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
showCloseDialog(position);
return true; return true;
} }
} }
@ -1339,10 +1360,8 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
Log.d(Constants.TAG, "Cookies Cleared"); Log.d(Constants.TAG, "Cookies Cleared");
} }
if (reference != null) {
reference.pauseTimers(); reference.pauseTimers();
reference.onDestroy(); reference.onDestroy();
}
mCurrentView = null; mCurrentView = null;
mTitleAdapter.notifyDataSetChanged(); mTitleAdapter.notifyDataSetChanged();
finish(); finish();
@ -1362,33 +1381,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
@Override @Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) { public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, false) showCloseDialog(mDrawerListLeft.getCheckedItemPosition());
&& mCurrentView != null && !isIncognito()) {
mCurrentView.clearCache(true);
Log.d(Constants.TAG, "Cache Cleared");
}
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_HISTORY_EXIT, false)
&& !isIncognito()) {
clearHistory();
Log.d(Constants.TAG, "History Cleared");
}
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_COOKIES_EXIT, false)
&& !isIncognito()) {
clearCookies();
Log.d(Constants.TAG, "Cookies Cleared");
}
mCurrentView = null;
for (int n = 0; n < mWebViews.size(); n++) {
if (mWebViews.get(n) != null) {
mWebViews.get(n).onDestroy();
}
}
mWebViews.clear();
mTitleAdapter.notifyDataSetChanged();
finish();
} }
return true; return true;
} }
@ -1502,8 +1495,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
s = s + mWebViews.get(n).getUrl() + "|$|SEPARATOR|$|"; s = s + mWebViews.get(n).getUrl() + "|$|SEPARATOR|$|";
} }
} }
mEditPrefs.putString(PreferenceConstants.URL_MEMORY, s); mEditPrefs.putString(PreferenceConstants.URL_MEMORY, s).commit();
mEditPrefs.commit();
} }
} }
@ -1822,8 +1814,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
} catch (Exception e) { } catch (Exception e) {
} finally { e.printStackTrace();
} }
} else { } else {
// if it exists, retrieve it from the cache // if it exists, retrieve it from the cache
@ -1850,6 +1841,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
} }
} }
if (mIcon == null) { if (mIcon == null) {
@ -1878,7 +1870,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
@Override @Override
public void updateUrl(String url, boolean shortUrl) { public void updateUrl(String url, boolean shortUrl) {
if (url == null) { if (url == null || mSearch == null || mSearch.hasFocus()) {
return; return;
} }
if (shortUrl) { if (shortUrl) {
@ -1940,7 +1932,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
} }
try { try {
if (mHistoryHandler == null && !mHistoryHandler.isOpen()) { if (mHistoryHandler == null || !mHistoryHandler.isOpen()) {
mHistoryHandler = new HistoryDatabaseHandler(mContext); mHistoryHandler = new HistoryDatabaseHandler(mContext);
} }
mHistoryHandler.visitHistoryItem(url, title); mHistoryHandler.visitHistoryItem(url, title);

10
src/acr/browser/lightning/HistoryDatabaseHandler.java

@ -57,11 +57,7 @@ public class HistoryDatabaseHandler extends SQLiteOpenHelper {
} }
public boolean isOpen() { public boolean isOpen() {
if (mDatabase != null) { return mDatabase != null && mDatabase.isOpen();
return mDatabase.isOpen();
} else {
return false;
}
} }
@Override @Override
@ -184,10 +180,8 @@ public class HistoryDatabaseHandler extends SQLiteOpenHelper {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(KEY_URL, item.getUrl()); values.put(KEY_URL, item.getUrl());
values.put(KEY_TITLE, item.getTitle()); values.put(KEY_TITLE, item.getTitle());
int n = mDatabase.update(TABLE_HISTORY, values, KEY_ID + " = ?", return mDatabase.update(TABLE_HISTORY, values, KEY_ID + " = ?",
new String[] { String.valueOf(item.getId()) }); new String[] { String.valueOf(item.getId()) });
// updating row
return n;
} }
// Getting items Count // Getting items Count

6
src/acr/browser/lightning/HistoryItem.java

@ -140,11 +140,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
if (!mTitle.equals(that.mTitle)) { if (!mTitle.equals(that.mTitle)) {
return false; return false;
} }
if (!mUrl.equals(that.mUrl)) { return mUrl.equals(that.mUrl);
return false;
}
return true;
} }
@Override @Override

6
src/acr/browser/lightning/IntentUtils.java

@ -19,8 +19,6 @@ public class IntentUtils {
private Activity mActivity; private Activity mActivity;
private BrowserController mController;
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
"(" "("
@ -29,8 +27,7 @@ public class IntentUtils {
+ ")" + "(.*)"); + ")" + "(.*)");
public IntentUtils(BrowserController controller) { public IntentUtils(BrowserController controller) {
mController = controller; mActivity = controller.getActivity();
mActivity = mController.getActivity();
} }
public boolean startActivityForUrl(WebView tab, String url) { public boolean startActivityForUrl(WebView tab, String url) {
@ -69,6 +66,7 @@ public class IntentUtils {
return true; return true;
} }
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
ex.printStackTrace();
} }
return false; return false;
} }

36
src/acr/browser/lightning/LightningView.java

@ -90,14 +90,13 @@ public class LightningView {
if (API > 15) { if (API > 15) {
mWebView.setBackground(null); mWebView.setBackground(null);
mWebView.getRootView().setBackground(null); mWebView.getRootView().setBackground(null);
} else { } else if (mWebView.getRootView() != null) {
mWebView.getRootView().setBackgroundDrawable(null); mWebView.getRootView().setBackgroundDrawable(null);
} }
mWebView.setWillNotCacheDrawing(false); mWebView.setWillNotCacheDrawing(false);
mWebView.setAlwaysDrawnWithCacheEnabled(true); mWebView.setAlwaysDrawnWithCacheEnabled(true);
mWebView.setScrollbarFadingEnabled(true); mWebView.setScrollbarFadingEnabled(true);
mWebView.setSaveEnabled(true); mWebView.setSaveEnabled(true);
mWebView.setWebChromeClient(new LightningChromeClient(activity)); mWebView.setWebChromeClient(new LightningChromeClient(activity));
mWebView.setWebViewClient(new LightningWebClient(activity)); mWebView.setWebViewClient(new LightningWebClient(activity));
mWebView.setDownloadListener(new LightningDownloadListener(activity)); mWebView.setDownloadListener(new LightningDownloadListener(activity));
@ -395,9 +394,6 @@ public class LightningView {
if (API > 16) { if (API > 16) {
settings.setMediaPlaybackRequiresUserGesture(true); settings.setMediaPlaybackRequiresUserGesture(true);
} }
if (API < 19) {
settings.setDatabasePath(context.getCacheDir() + "/databases");
}
if (API >= Build.VERSION_CODES.LOLLIPOP && !mBrowserController.isIncognito()) { if (API >= Build.VERSION_CODES.LOLLIPOP && !mBrowserController.isIncognito()) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
} else if (API >= Build.VERSION_CODES.LOLLIPOP) { } else if (API >= Build.VERSION_CODES.LOLLIPOP) {
@ -411,20 +407,24 @@ public class LightningView {
settings.setDomStorageEnabled(false); settings.setDomStorageEnabled(false);
} }
settings.setAppCacheEnabled(true); settings.setAppCacheEnabled(true);
settings.setAppCachePath(context.getCacheDir().toString());
settings.setCacheMode(WebSettings.LOAD_DEFAULT); settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setGeolocationDatabasePath(context.getFilesDir().toString());
settings.setAllowFileAccess(true);
settings.setDatabaseEnabled(true); settings.setDatabaseEnabled(true);
settings.setSupportZoom(true); settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true); settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false); settings.setDisplayZoomControls(false);
settings.setAllowContentAccess(true); settings.setAllowContentAccess(true);
settings.setAllowFileAccess(true);
settings.setDefaultTextEncodingName("utf-8"); settings.setDefaultTextEncodingName("utf-8");
if (API > 16) { if (API > 16) {
settings.setAllowFileAccessFromFileURLs(false); settings.setAllowFileAccessFromFileURLs(false);
settings.setAllowUniversalAccessFromFileURLs(false); settings.setAllowUniversalAccessFromFileURLs(false);
} }
settings.setAppCachePath(context.getDir("appcache", 0).getPath());
settings.setGeolocationDatabasePath(context.getDir("geolocation", 0).getPath());
if (API < Build.VERSION_CODES.KITKAT) {
settings.setDatabasePath(context.getDir("databases", 0).getPath());
}
} }
public boolean isShown() { public boolean isShown() {
@ -471,11 +471,11 @@ public class LightningView {
} }
public void setNormalRendering() { public void setNormalRendering() {
mWebView.setLayerType(View.LAYER_TYPE_NONE, mPaint); mWebView.setLayerType(View.LAYER_TYPE_NONE, null);
} }
public void setSoftwareRendering() { public void setSoftwareRendering() {
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint); mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
} }
public void setColorMode(int mode) { public void setColorMode(int mode) {
@ -483,6 +483,9 @@ public class LightningView {
switch (mode) { switch (mode) {
case 0: case 0:
mPaint.setColorFilter(null); mPaint.setColorFilter(null);
// setSoftwareRendering(); // Some devices get segfaults
// in the WebView with Hardware Acceleration enabled,
// the only fix is to disable hardware rendering
setNormalRendering(); setNormalRendering();
mInvertPage = false; mInvertPage = false;
break; break;
@ -652,6 +655,16 @@ public class LightningView {
mActivity = context; mActivity = context;
} }
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
if (mAdBlock.isAd(request.getUrl().getHost())) {
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
return new WebResourceResponse("text/plain", "utf-8", EMPTY);
}
return super.shouldInterceptRequest(view, request);
}
@Override @Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) { public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (mAdBlock.isAd(url)) { if (mAdBlock.isAd(url)) {
@ -766,7 +779,7 @@ public class LightningView {
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
if (view.isShown()) { if (view.isShown()) {
mBrowserController.updateUrl(url, true); mBrowserController.updateUrl(url, true);
view.invalidate(); view.postInvalidate();
} }
if (view.getTitle() == null || view.getTitle().isEmpty()) { if (view.getTitle() == null || view.getTitle().isEmpty()) {
mTitle.setTitle(mActivity.getString(R.string.untitled)); mTitle.setTitle(mActivity.getString(R.string.untitled));
@ -785,7 +798,6 @@ public class LightningView {
mBrowserController.updateUrl(url, false); mBrowserController.updateUrl(url, false);
mBrowserController.showActionBar(); mBrowserController.showActionBar();
} }
mTitle.setFavicon(mWebpageBitmap); mTitle.setFavicon(mWebpageBitmap);
mBrowserController.update(); mBrowserController.update();
} }

1
src/acr/browser/lightning/MainActivity.java

@ -36,7 +36,6 @@ public class MainActivity extends BrowserActivity {
@Override @Override
public synchronized void initializeTabs() { public synchronized void initializeTabs() {
super.initializeTabs();
restoreOrNewTab(); restoreOrNewTab();
// if incognito mode use newTab(null, true); instead // if incognito mode use newTab(null, true); instead
} }

8
src/acr/browser/lightning/SearchAdapter.java

@ -162,13 +162,10 @@ 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) { if (constraint == null || constraint.toString() == null) {
return results; return results;
} }
String query = constraint.toString().toLowerCase(Locale.getDefault()); String query = constraint.toString().toLowerCase(Locale.getDefault());
if (query == null) {
return results;
}
if (mUseGoogle && !mIncognito && !mIsExecuting) { if (mUseGoogle && !mIncognito && !mIsExecuting) {
new RetrieveSearchSuggestions().execute(query); new RetrieveSearchSuggestions().execute(query);
} }
@ -269,11 +266,10 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
try { try {
download.close(); download.close();
} catch (IOException e) { } catch (IOException e) {
return filter; e.printStackTrace();
} }
} }
} }
return filter; return filter;
} }

Loading…
Cancel
Save