Browse Source

Fixed bug with WebView background being transparent, fixed some deprecated API usage, made HistoryDatabase a true singleton

master
Anthony Restaino 9 years ago
parent
commit
b33c4caf67
  1. 2
      app/app.iml
  2. 103
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  3. 3
      app/src/main/java/acr/browser/lightning/constant/HistoryPage.java
  4. 71
      app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java
  5. 6
      app/src/main/java/acr/browser/lightning/object/SearchAdapter.java
  6. 8
      app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java
  7. 2
      app/src/main/java/acr/browser/lightning/utils/WebUtils.java
  8. 26
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  9. 4
      app/src/main/res/values/colors.xml

2
app/app.iml

@ -120,8 +120,8 @@
<orderEntry type="library" exported="" name="design-23.0.1" level="project" /> <orderEntry type="library" exported="" name="design-23.0.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" /> <orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="jsr250-api-1.0" level="project" /> <orderEntry type="library" exported="" name="jsr250-api-1.0" level="project" />
<orderEntry type="library" exported="" name="javax.inject-1" level="project" />
<orderEntry type="library" exported="" name="dagger-2.0.1" level="project" /> <orderEntry type="library" exported="" name="dagger-2.0.1" level="project" />
<orderEntry type="library" exported="" name="javax.inject-1" level="project" />
<orderEntry type="library" exported="" name="jsoup-1.8.1" level="project" /> <orderEntry type="library" exported="" name="jsoup-1.8.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" /> <orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" /> <orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />

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

@ -112,7 +112,6 @@ import acr.browser.lightning.constant.HistoryPage;
import acr.browser.lightning.controller.BrowserController; import acr.browser.lightning.controller.BrowserController;
import acr.browser.lightning.database.BookmarkManager; import acr.browser.lightning.database.BookmarkManager;
import acr.browser.lightning.database.HistoryDatabase; import acr.browser.lightning.database.HistoryDatabase;
import acr.browser.lightning.database.HistoryItem;
import acr.browser.lightning.dialog.BookmarksDialogBuilder; import acr.browser.lightning.dialog.BookmarksDialogBuilder;
import acr.browser.lightning.object.ClickHandler; import acr.browser.lightning.object.ClickHandler;
import acr.browser.lightning.object.SearchAdapter; import acr.browser.lightning.object.SearchAdapter;
@ -139,7 +138,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
// List // List
private final List<LightningView> mWebViewList = new ArrayList<>(); private final List<LightningView> mWebViewList = new ArrayList<>();
private final List<HistoryItem> mBookmarkList = new ArrayList<>();
private LightningView mCurrentView; private LightningView mCurrentView;
private WebView mWebView; private WebView mWebView;
@ -148,7 +146,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private AutoCompleteTextView mSearch; private AutoCompleteTextView mSearch;
private ImageView mArrowImage; private ImageView mArrowImage;
private VideoView mVideoView; private VideoView mVideoView;
private View mCustomView, mVideoProgressView; private View mCustomView;
// Adapter // Adapter
private LightningViewAdapter mTabAdapter; private LightningViewAdapter mTabAdapter;
@ -191,7 +189,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
BookmarksDialogBuilder bookmarksDialogBuilder; BookmarksDialogBuilder bookmarksDialogBuilder;
// Image // Image
private Bitmap mDefaultVideoPoster, mWebpageBitmap; private Bitmap mWebpageBitmap;
private final ColorDrawable mBackground = new ColorDrawable(); private final ColorDrawable mBackground = new ColorDrawable();
private Drawable mDeleteIcon, mRefreshIcon, mClearIcon, mIcon; private Drawable mDeleteIcon, mRefreshIcon, mClearIcon, mIcon;
private DrawerArrowDrawable mArrowDrawable; private DrawerArrowDrawable mArrowDrawable;
@ -292,7 +290,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mDrawerListLeft.setAdapter(mTabAdapter); mDrawerListLeft.setAdapter(mTabAdapter);
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext()); mHistoryDatabase = HistoryDatabase.getInstance();
if (actionBar == null) if (actionBar == null)
return; return;
@ -621,11 +619,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mColorMode = mPreferences.getColorModeEnabled(); mColorMode = mPreferences.getColorModeEnabled();
mColorMode &= !mDarkTheme; mColorMode &= !mDarkTheme;
if (!isIncognito() && !mColorMode && !mDarkTheme && mWebpageBitmap != null) { if (!isIncognito() && !mColorMode && !mDarkTheme && mWebpageBitmap != null) {
//TODO fix toolbar coloring changeToolbarBackground(mWebpageBitmap, null);
// changeToolbarBackground(mWebpageBitmap, null);
} else if (!isIncognito() && mCurrentView != null && !mDarkTheme } else if (!isIncognito() && mCurrentView != null && !mDarkTheme
&& mCurrentView.getFavicon() != null) { && mCurrentView.getFavicon() != null) {
// changeToolbarBackground(mCurrentView.getFavicon(), null); changeToolbarBackground(mCurrentView.getFavicon(), null);
} }
if (mFullScreen) { if (mFullScreen) {
@ -1034,7 +1031,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
return false; return false;
} }
mIsNewIntent = false; mIsNewIntent = false;
LightningView startingTab = new LightningView(mActivity, url, mDarkTheme, isIncognito()); LightningView startingTab = new LightningView(mActivity, url, mDarkTheme, isIncognito(), this);
if (mIdGenerator == 0) { if (mIdGenerator == 0) {
startingTab.resumeTimers(); startingTab.resumeTimers();
} }
@ -1267,7 +1264,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mCurrentView.resumeTimers(); mCurrentView.resumeTimers();
mCurrentView.onResume(); mCurrentView.onResume();
} }
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext()); mHistoryDatabase = HistoryDatabase.getInstance();
initializePreferences(); initializePreferences();
for (int n = 0, size = mWebViewList.size(); n < size; n++) { for (int n = 0, size = mWebViewList.size(); n < size; n++) {
if (mWebViewList.get(n) != null) { if (mWebViewList.get(n) != null) {
@ -1337,7 +1334,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
int foregroundColor = ThemeUtils.getPrimaryColor(context); int foregroundColor = ThemeUtils.getPrimaryColor(context);
Bitmap foregroundTabBitmap = Bitmap.createBitmap(Utils.dpToPx(175), Utils.dpToPx(30), Bitmap.Config.ARGB_8888); Bitmap foregroundTabBitmap = Bitmap.createBitmap(Utils.dpToPx(175), Utils.dpToPx(30), Bitmap.Config.ARGB_8888);
Utils.drawTrapezoid(new Canvas(foregroundTabBitmap), foregroundColor, false); Utils.drawTrapezoid(new Canvas(foregroundTabBitmap), foregroundColor, false);
mForegroundTabDrawable = new BitmapDrawable(getResources(), foregroundTabBitmap); mForegroundTabDrawable = new BitmapDrawable(getResources(), foregroundTabBitmap).mutate();
} }
} }
@ -1349,7 +1346,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
@Override @Override
public void onBindViewHolder(LightningViewHolder holder, int position) { public void onBindViewHolder(final LightningViewHolder holder, int position) {
holder.exitButton.setTag(position); holder.exitButton.setTag(position);
holder.exitButton.setOnClickListener(mExitListener); holder.exitButton.setOnClickListener(mExitListener);
holder.layout.setOnClickListener(mClickListener); holder.layout.setOnClickListener(mClickListener);
@ -1360,7 +1357,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
LightningView web = data.get(position); LightningView web = data.get(position);
holder.txtTitle.setText(web.getTitle()); holder.txtTitle.setText(web.getTitle());
Bitmap favicon = web.getFavicon(); final Bitmap favicon = web.getFavicon();
if (web.isForegroundTab()) { if (web.isForegroundTab()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
holder.txtTitle.setTextAppearance(R.style.boldText); holder.txtTitle.setTextAppearance(R.style.boldText);
@ -1373,8 +1370,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
holder.layout.setBackgroundDrawable(mForegroundTabDrawable); holder.layout.setBackgroundDrawable(mForegroundTabDrawable);
} }
if (!isIncognito() && mColorMode) { if (!isIncognito() && mColorMode) {
// TODO fix toolbar coloring changeToolbarBackground(favicon, null /* mForegroundTabDrawable */);
// changeToolbarBackground(favicon, mForegroundTabDrawable);
} }
holder.favicon.setImageBitmap(favicon); holder.favicon.setImageBitmap(favicon);
} else { } else {
@ -1444,7 +1440,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
/** /**
* TODO Can this method been removed?
* Animates the color of the toolbar from one color to another. Optionally animates * Animates the color of the toolbar from one color to another. Optionally animates
* the color of the tab background, for use when the tabs are displayed on the top * the color of the tab background, for use when the tabs are displayed on the top
* of the screen. * of the screen.
@ -1453,26 +1448,33 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
* @param tabBackground the optional LinearLayout to color * @param tabBackground the optional LinearLayout to color
*/ */
private void changeToolbarBackground(@NonNull Bitmap favicon, @Nullable final Drawable tabBackground) { private void changeToolbarBackground(@NonNull Bitmap favicon, @Nullable final Drawable tabBackground) {
if (!mShowTabsInDrawer) {
// TODO something is messed up and keeping this from working when the tablet tabs are used
return;
}
final int defaultColor;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
defaultColor = getResources().getColor(R.color.primary_color);
} else {
defaultColor = getColor(R.color.primary_color);
}
Palette.from(favicon).generate(new Palette.PaletteAsyncListener() { Palette.from(favicon).generate(new Palette.PaletteAsyncListener() {
@Override @Override
public void onGenerated(Palette palette) { public void onGenerated(Palette palette) {
// OR with opaque black to remove transparency glitches // OR with opaque black to remove transparency glitches
int color = 0xff000000 | palette.getVibrantColor(mActivity.getResources() int color = 0xff000000 | palette.getVibrantColor(defaultColor);
.getColor(R.color.primary_color));
int finalColor; // Lighten up the dark color if it is int finalColor; // Lighten up the dark color if it is
// too dark // too dark
if (Utils.isColorTooDark(color)) { if (Utils.isColorTooDark(color)) {
finalColor = Utils.mixTwoColors( finalColor = Utils.mixTwoColors(defaultColor, color, 0.25f);
mActivity.getResources().getColor(R.color.primary_color),
color, 0.25f);
} else { } else {
finalColor = color; finalColor = color;
} }
ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), ValueAnimator anim = ValueAnimator.ofInt(mBackground.getColor(), finalColor);
mBackground.getColor(), finalColor); anim.setEvaluator(new ArgbEvaluator());
final Window window = getWindow(); final Window window = getWindow();
if (!mShowTabsInDrawer) { if (!mShowTabsInDrawer) {
window.setBackgroundDrawable(new ColorDrawable(Color.BLACK)); window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
@ -1485,11 +1487,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
if (mShowTabsInDrawer) { if (mShowTabsInDrawer) {
mBackground.setColor(color); mBackground.setColor(color);
window.setBackgroundDrawable(mBackground); window.setBackgroundDrawable(mBackground);
} } else if (tabBackground != null) {
mToolbarLayout.setBackgroundColor(color);
if (tabBackground != null) {
tabBackground.setColorFilter(color, PorterDuff.Mode.SRC_IN); tabBackground.setColorFilter(color, PorterDuff.Mode.SRC_IN);
} }
mToolbarLayout.setBackgroundColor(color);
} }
}); });
@ -1523,7 +1524,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
break; break;
} }
} else { } else {
if (url.startsWith(Constants.FILE)) { if (url.startsWith(Constants.FILE)) {
url = ""; url = "";
@ -1548,15 +1548,15 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
public void run() { public void run() {
try { try {
if (mHistoryDatabase == null) { if (mHistoryDatabase == null) {
mHistoryDatabase = HistoryDatabase.getInstance(mActivity.getApplicationContext()); mHistoryDatabase = HistoryDatabase.getInstance();
} }
mHistoryDatabase.visitHistoryItem(url, title); mHistoryDatabase.visitHistoryItem(url, title);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.e(Constants.TAG, "IllegalStateException in updateHistory"); Log.e(Constants.TAG, "IllegalStateException in updateHistory", e);
} catch (NullPointerException e) { } catch (NullPointerException e) {
Log.e(Constants.TAG, "NullPointerException in updateHistory"); Log.e(Constants.TAG, "NullPointerException in updateHistory", e);
} catch (SQLiteException e) { } catch (SQLiteException e) {
Log.e(Constants.TAG, "SQLiteException in updateHistory"); Log.e(Constants.TAG, "SQLiteException in updateHistory", e);
} }
} }
}; };
@ -1852,7 +1852,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
decor.removeView(mFullscreenContainer); decor.removeView(mFullscreenContainer);
} }
if (API < 19) { if (API < Build.VERSION_CODES.KITKAT) {
try { try {
mCustomViewCallback.onCustomViewHidden(); mCustomViewCallback.onCustomViewHidden();
} catch (Throwable ignored) { } catch (Throwable ignored) {
@ -1927,7 +1927,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
public FullscreenHolder(Context ctx) { public FullscreenHolder(Context ctx) {
super(ctx); super(ctx);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setBackgroundColor(ctx.getResources().getColor(android.R.color.black, getTheme())); setBackgroundColor(ctx.getColor(android.R.color.black));
} else { } else {
setBackgroundColor(ctx.getResources().getColor(android.R.color.black)); setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
} }
@ -1940,29 +1940,15 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
/**
* a stupid method that returns the bitmap image to display in place of
* a loading video
*/
@Override @Override
public Bitmap getDefaultVideoPoster() { public Bitmap getDefaultVideoPoster() {
if (mDefaultVideoPoster == null) { return BitmapFactory.decodeResource(getResources(), android.R.drawable.spinner_background);
mDefaultVideoPoster = BitmapFactory.decodeResource(getResources(),
android.R.drawable.ic_media_play);
}
return mDefaultVideoPoster;
} }
/**
* dumb method that returns the loading progress for a video
*/
@Override @Override
public View getVideoLoadingProgressView() { public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) { LayoutInflater inflater = LayoutInflater.from(this);
LayoutInflater inflater = LayoutInflater.from(this); return inflater.inflate(R.layout.video_loading_progress, null);
mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null);
}
return mVideoProgressView;
} }
/** /**
@ -2343,7 +2329,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
private void setupFrameLayoutButton(@IdRes int buttonId, @IdRes int imageId) { private void setupFrameLayoutButton(@IdRes int buttonId, @IdRes int imageId) {
FrameLayout frameButton = (FrameLayout) findViewById(buttonId); View frameButton = findViewById(buttonId);
frameButton.setOnClickListener(this); frameButton.setOnClickListener(this);
frameButton.setOnLongClickListener(this); frameButton.setOnLongClickListener(this);
ImageView buttonImage = (ImageView) findViewById(imageId); ImageView buttonImage = (ImageView) findViewById(imageId);
@ -2410,8 +2396,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
*/ */
@Subscribe @Subscribe
public void bookmarkCurrentPage(final BookmarkEvents.WantToBookmarkCurrentPage event) { public void bookmarkCurrentPage(final BookmarkEvents.WantToBookmarkCurrentPage event) {
eventBus.post(new BrowserEvents if (mCurrentView != null) {
.AddBookmark(mCurrentView.getTitle(), mCurrentView.getUrl())); eventBus.post(new BrowserEvents.AddBookmark(mCurrentView.getTitle(), mCurrentView.getUrl()));
}
} }
/** /**
@ -2436,8 +2423,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
&& mCurrentView.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) { && mCurrentView.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) {
openBookmarkPage(mWebView); openBookmarkPage(mWebView);
} }
eventBus if (mCurrentView != null) {
.post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl())); eventBus.post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl()));
}
} }
/** /**
@ -2451,8 +2439,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
&& mCurrentView.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) { && mCurrentView.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) {
openBookmarkPage(mWebView); openBookmarkPage(mWebView);
} }
eventBus if (mCurrentView != null) {
.post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl())); eventBus.post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl()));
}
} }
/** /**

3
app/src/main/java/acr/browser/lightning/constant/HistoryPage.java

@ -66,8 +66,7 @@ public class HistoryPage {
} }
private static List<HistoryItem> getWebHistory(Context context) { private static List<HistoryItem> getWebHistory(Context context) {
HistoryDatabase databaseHandler = HistoryDatabase.getInstance(context HistoryDatabase databaseHandler = HistoryDatabase.getInstance();
.getApplicationContext());
return databaseHandler.getLastHundredItems(); return databaseHandler.getLastHundredItems();
} }
} }

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

@ -8,10 +8,12 @@ import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
public class HistoryDatabase extends SQLiteOpenHelper { public class HistoryDatabase extends SQLiteOpenHelper {
@ -35,9 +37,11 @@ public class HistoryDatabase extends SQLiteOpenHelper {
private static HistoryDatabase mInstance; private static HistoryDatabase mInstance;
public static HistoryDatabase getInstance(Context context) { private boolean mLock;
public static HistoryDatabase getInstance() {
if (mInstance == null || mInstance.isClosed()) { if (mInstance == null || mInstance.isClosed()) {
mInstance = new HistoryDatabase(context); mInstance = new HistoryDatabase(BrowserApp.getAppContext());
} }
return mInstance; return mInstance;
} }
@ -77,41 +81,61 @@ public class HistoryDatabase extends SQLiteOpenHelper {
@Override @Override
public synchronized void close() { public synchronized void close() {
if (mDatabase != null) { if (!mLock) {
mDatabase.close(); if (mDatabase != null) {
mDatabase.close();
mDatabase = null;
}
} }
super.close(); super.close();
} }
private void openIfNecessary() {
if (mDatabase == null) {
mDatabase = this.getWritableDatabase();
}
}
public synchronized void deleteHistoryItem(String url) { public synchronized void deleteHistoryItem(String url) {
mDatabase.delete(TABLE_HISTORY, KEY_URL + " = ?", new String[] { url }); mLock = true;
openIfNecessary();
mDatabase.delete(TABLE_HISTORY, KEY_URL + " = ?", new String[]{url});
mLock = false;
} }
public synchronized void visitHistoryItem(String url, String title) { public synchronized void visitHistoryItem(String url, String title) {
mLock = true;
openIfNecessary();
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(KEY_TITLE, title); values.put(KEY_TITLE, title);
values.put(KEY_TIME_VISITED, System.currentTimeMillis()); values.put(KEY_TIME_VISITED, System.currentTimeMillis());
Cursor q = mDatabase.query(false, TABLE_HISTORY, new String[] { KEY_URL }, Cursor q = mDatabase.query(false, TABLE_HISTORY, new String[]{KEY_URL},
KEY_URL + " = ?", new String[] { url }, null, null, null, "1"); KEY_URL + " = ?", new String[]{url}, null, null, null, "1");
if (q.getCount() > 0) { if (q.getCount() > 0) {
mDatabase.update(TABLE_HISTORY, values, KEY_URL + " = ?", new String[] { url }); mDatabase.update(TABLE_HISTORY, values, KEY_URL + " = ?", new String[]{url});
} else { } else {
addHistoryItem(new HistoryItem(url, title)); addHistoryItem(new HistoryItem(url, title));
} }
q.close(); q.close();
mLock = false;
} }
private synchronized void addHistoryItem(HistoryItem item) { private synchronized void addHistoryItem(HistoryItem item) {
mLock = true;
openIfNecessary();
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());
values.put(KEY_TIME_VISITED, System.currentTimeMillis()); values.put(KEY_TIME_VISITED, System.currentTimeMillis());
mDatabase.insert(TABLE_HISTORY, null, values); mDatabase.insert(TABLE_HISTORY, null, values);
mLock = false;
} }
String getHistoryItem(String url) { String getHistoryItem(String url) {
Cursor cursor = mDatabase.query(TABLE_HISTORY, new String[] { KEY_ID, KEY_URL, KEY_TITLE }, mLock = true;
KEY_URL + " = ?", new String[] { url }, null, null, null, null); openIfNecessary();
Cursor cursor = mDatabase.query(TABLE_HISTORY, new String[]{KEY_ID, KEY_URL, KEY_TITLE},
KEY_URL + " = ?", new String[]{url}, null, null, null, null);
String m = null; String m = null;
if (cursor != null) { if (cursor != null) {
cursor.moveToFirst(); cursor.moveToFirst();
@ -119,11 +143,14 @@ public class HistoryDatabase extends SQLiteOpenHelper {
cursor.close(); cursor.close();
} }
mLock = false;
return m; return m;
} }
public List<HistoryItem> findItemsContaining(String search) { public List<HistoryItem> findItemsContaining(String search) {
List<HistoryItem> itemList = new ArrayList<>(); mLock = true;
openIfNecessary();
List<HistoryItem> itemList = new ArrayList<>(5);
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";
@ -142,11 +169,14 @@ public class HistoryDatabase extends SQLiteOpenHelper {
} while (cursor.moveToNext() && n < 5); } while (cursor.moveToNext() && n < 5);
} }
cursor.close(); cursor.close();
mLock = false;
return itemList; return itemList;
} }
public List<HistoryItem> getLastHundredItems() { public List<HistoryItem> getLastHundredItems() {
List<HistoryItem> itemList = new ArrayList<>(); mLock = true;
openIfNecessary();
List<HistoryItem> itemList = new ArrayList<>(100);
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED
+ " DESC"; + " DESC";
@ -164,10 +194,13 @@ public class HistoryDatabase extends SQLiteOpenHelper {
} while (cursor.moveToNext() && counter < 100); } while (cursor.moveToNext() && counter < 100);
} }
cursor.close(); cursor.close();
mLock = false;
return itemList; return itemList;
} }
public List<HistoryItem> getAllHistoryItems() { public List<HistoryItem> getAllHistoryItems() {
mLock = true;
openIfNecessary();
List<HistoryItem> itemList = new ArrayList<>(); 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";
@ -185,25 +218,31 @@ public class HistoryDatabase extends SQLiteOpenHelper {
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} }
cursor.close(); cursor.close();
mLock = false;
return itemList; return itemList;
} }
public synchronized int updateHistoryItem(HistoryItem item) { public synchronized int updateHistoryItem(HistoryItem item) {
mLock = true;
openIfNecessary();
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());
values.put(KEY_TIME_VISITED, System.currentTimeMillis()); values.put(KEY_TIME_VISITED, System.currentTimeMillis());
return mDatabase.update(TABLE_HISTORY, values, KEY_ID + " = ?", int update = mDatabase.update(TABLE_HISTORY, values, KEY_ID + " = ?",
new String[] { String.valueOf(item.getId()) }); new String[]{String.valueOf(item.getId())});
mLock = false;
return update;
} }
public int getHistoryItemsCount() { public int getHistoryItemsCount() {
mLock = true;
openIfNecessary();
String countQuery = "SELECT * FROM " + TABLE_HISTORY; String countQuery = "SELECT * FROM " + TABLE_HISTORY;
Cursor cursor = mDatabase.rawQuery(countQuery, null); Cursor cursor = mDatabase.rawQuery(countQuery, null);
int n = cursor.getCount(); int n = cursor.getCount();
cursor.close(); cursor.close();
mLock = false;
return n; return n;
} }
} }

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

@ -75,7 +75,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
public SearchAdapter(Context context, boolean dark, boolean incognito) { public SearchAdapter(Context context, boolean dark, boolean incognito) {
BrowserApp.getAppComponent().inject(this); BrowserApp.getAppComponent().inject(this);
mDatabaseHandler = HistoryDatabase.getInstance(context.getApplicationContext()); mDatabaseHandler = HistoryDatabase.getInstance();
mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true)); mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true));
mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled(); mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled();
mContext = context; mContext = context;
@ -125,7 +125,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
mSuggestions.clear(); mSuggestions.clear();
} }
} }
mDatabaseHandler = HistoryDatabase.getInstance(mContext.getApplicationContext()); mDatabaseHandler = HistoryDatabase.getInstance();
} }
public void refreshBookmarks() { public void refreshBookmarks() {
@ -245,7 +245,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
} }
} }
if (mDatabaseHandler == null || mDatabaseHandler.isClosed()) { if (mDatabaseHandler == null || mDatabaseHandler.isClosed()) {
mDatabaseHandler = HistoryDatabase.getInstance(mContext.getApplicationContext()); mDatabaseHandler = HistoryDatabase.getInstance();
} }
List<HistoryItem> historyList = mDatabaseHandler.findItemsContaining(constraint.toString()); List<HistoryItem> historyList = mDatabaseHandler.findItemsContaining(constraint.toString());
synchronized (mHistory) { synchronized (mHistory) {

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

@ -112,11 +112,11 @@ public class ThemeUtils {
Resources res = context.getResources(); Resources res = context.getResources();
int color; int color;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
color = (dark) ? res.getColor(R.color.divider_dark, context.getTheme()) : color = (dark) ? res.getColor(R.color.selected_dark, context.getTheme()) :
res.getColor(R.color.divider_light, context.getTheme()); res.getColor(R.color.selected_light, context.getTheme());
} else { } else {
color = (dark) ? res.getColor(R.color.divider_dark) : color = (dark) ? res.getColor(R.color.selected_dark) :
res.getColor(R.color.divider_light); res.getColor(R.color.selected_light);
} }
return new ColorDrawable(color); return new ColorDrawable(color);
} }

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

@ -32,7 +32,7 @@ public class WebUtils {
} }
public static void clearHistory(@NonNull Context context) { public static void clearHistory(@NonNull Context context) {
HistoryDatabase.getInstance(context).deleteHistory(); HistoryDatabase.getInstance().deleteHistory();
WebViewDatabase m = WebViewDatabase.getInstance(context); WebViewDatabase m = WebViewDatabase.getInstance(context);
m.clearFormData(); m.clearFormData();
m.clearHttpAuthUsernamePassword(); m.clearHttpAuthUsernamePassword();

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

@ -12,6 +12,7 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.ColorMatrix; import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter; import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint; import android.graphics.Paint;
@ -98,7 +99,7 @@ public class LightningView {
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION}; private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
@SuppressLint("NewApi") @SuppressLint("NewApi")
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito) { public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito, BrowserController controller) {
mActivity = activity; mActivity = activity;
mWebView = new WebView(activity); mWebView = new WebView(activity);
@ -111,27 +112,20 @@ public class LightningView {
mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity(); mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();
try { mBrowserController = controller;
mBrowserController = (BrowserController) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity + " must implement BrowserController");
}
mIntentUtils = new IntentUtils(mBrowserController); mIntentUtils = new IntentUtils(mBrowserController);
mWebView.setDrawingCacheBackgroundColor(0x00000000); mWebView.setDrawingCacheBackgroundColor(Color.WHITE);
mWebView.setFocusableInTouchMode(true); mWebView.setFocusableInTouchMode(true);
mWebView.setFocusable(true); mWebView.setFocusable(true);
mWebView.setAnimationCacheEnabled(false);
mWebView.setDrawingCacheEnabled(false); mWebView.setDrawingCacheEnabled(false);
mWebView.setWillNotCacheDrawing(true); mWebView.setWillNotCacheDrawing(true);
mWebView.setAlwaysDrawnWithCacheEnabled(false); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
mWebView.setBackgroundColor(0); mWebView.setAnimationCacheEnabled(false);
mWebView.setAlwaysDrawnWithCacheEnabled(false);
if (API >= Build.VERSION_CODES.JELLY_BEAN) {
mWebView.setBackground(null);
mWebView.getRootView().setBackground(null);
} else if (mWebView.getRootView() != null) {
mWebView.getRootView().setBackgroundDrawable(null);
} }
mWebView.setBackgroundColor(Color.WHITE);
mWebView.setScrollbarFadingEnabled(true); mWebView.setScrollbarFadingEnabled(true);
mWebView.setSaveEnabled(true); mWebView.setSaveEnabled(true);
mWebView.setNetworkAvailable(true); mWebView.setNetworkAvailable(true);

4
app/src/main/res/values/colors.xml

@ -21,8 +21,8 @@
<color name="primary_color_dark">#424242</color> <color name="primary_color_dark">#424242</color>
<color name="divider_dark">#1EFFFFFF</color> <color name="divider_dark">#1FFFFFFF</color>
<color name="divider_light">#1E000000</color> <color name="divider_light">#1F000000</color>
<color name="selected_dark">#0FFFFFFF</color> <color name="selected_dark">#0FFFFFFF</color>

Loading…
Cancel
Save