From b33c4caf67400485948754f06b28983a43a14351 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Tue, 8 Sep 2015 20:48:08 -0400 Subject: [PATCH] Fixed bug with WebView background being transparent, fixed some deprecated API usage, made HistoryDatabase a true singleton --- app/app.iml | 2 +- .../lightning/activity/BrowserActivity.java | 103 ++++++++---------- .../lightning/constant/HistoryPage.java | 3 +- .../lightning/database/HistoryDatabase.java | 71 +++++++++--- .../lightning/object/SearchAdapter.java | 6 +- .../browser/lightning/utils/ThemeUtils.java | 8 +- .../acr/browser/lightning/utils/WebUtils.java | 2 +- .../browser/lightning/view/LightningView.java | 26 ++--- app/src/main/res/values/colors.xml | 4 +- 9 files changed, 123 insertions(+), 102 deletions(-) diff --git a/app/app.iml b/app/app.iml index bb4e66a..6d8f35a 100644 --- a/app/app.iml +++ b/app/app.iml @@ -120,8 +120,8 @@ - + diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 59d1958..f05bb87 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/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.database.BookmarkManager; import acr.browser.lightning.database.HistoryDatabase; -import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.dialog.BookmarksDialogBuilder; import acr.browser.lightning.object.ClickHandler; import acr.browser.lightning.object.SearchAdapter; @@ -139,7 +138,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements // List private final List mWebViewList = new ArrayList<>(); - private final List mBookmarkList = new ArrayList<>(); private LightningView mCurrentView; private WebView mWebView; @@ -148,7 +146,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements private AutoCompleteTextView mSearch; private ImageView mArrowImage; private VideoView mVideoView; - private View mCustomView, mVideoProgressView; + private View mCustomView; // Adapter private LightningViewAdapter mTabAdapter; @@ -191,7 +189,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements BookmarksDialogBuilder bookmarksDialogBuilder; // Image - private Bitmap mDefaultVideoPoster, mWebpageBitmap; + private Bitmap mWebpageBitmap; private final ColorDrawable mBackground = new ColorDrawable(); private Drawable mDeleteIcon, mRefreshIcon, mClearIcon, mIcon; private DrawerArrowDrawable mArrowDrawable; @@ -292,7 +290,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements mDrawerListLeft.setAdapter(mTabAdapter); - mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext()); + mHistoryDatabase = HistoryDatabase.getInstance(); if (actionBar == null) return; @@ -621,11 +619,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements mColorMode = mPreferences.getColorModeEnabled(); mColorMode &= !mDarkTheme; if (!isIncognito() && !mColorMode && !mDarkTheme && mWebpageBitmap != null) { - //TODO fix toolbar coloring -// changeToolbarBackground(mWebpageBitmap, null); + changeToolbarBackground(mWebpageBitmap, null); } else if (!isIncognito() && mCurrentView != null && !mDarkTheme && mCurrentView.getFavicon() != null) { -// changeToolbarBackground(mCurrentView.getFavicon(), null); + changeToolbarBackground(mCurrentView.getFavicon(), null); } if (mFullScreen) { @@ -1034,7 +1031,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements return false; } mIsNewIntent = false; - LightningView startingTab = new LightningView(mActivity, url, mDarkTheme, isIncognito()); + LightningView startingTab = new LightningView(mActivity, url, mDarkTheme, isIncognito(), this); if (mIdGenerator == 0) { startingTab.resumeTimers(); } @@ -1267,7 +1264,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements mCurrentView.resumeTimers(); mCurrentView.onResume(); } - mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext()); + mHistoryDatabase = HistoryDatabase.getInstance(); initializePreferences(); for (int n = 0, size = mWebViewList.size(); n < size; n++) { if (mWebViewList.get(n) != null) { @@ -1337,7 +1334,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements int foregroundColor = ThemeUtils.getPrimaryColor(context); Bitmap foregroundTabBitmap = Bitmap.createBitmap(Utils.dpToPx(175), Utils.dpToPx(30), Bitmap.Config.ARGB_8888); 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 - public void onBindViewHolder(LightningViewHolder holder, int position) { + public void onBindViewHolder(final LightningViewHolder holder, int position) { holder.exitButton.setTag(position); holder.exitButton.setOnClickListener(mExitListener); holder.layout.setOnClickListener(mClickListener); @@ -1360,7 +1357,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements LightningView web = data.get(position); holder.txtTitle.setText(web.getTitle()); - Bitmap favicon = web.getFavicon(); + final Bitmap favicon = web.getFavicon(); if (web.isForegroundTab()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { holder.txtTitle.setTextAppearance(R.style.boldText); @@ -1373,8 +1370,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements holder.layout.setBackgroundDrawable(mForegroundTabDrawable); } if (!isIncognito() && mColorMode) { - // TODO fix toolbar coloring -// changeToolbarBackground(favicon, mForegroundTabDrawable); + changeToolbarBackground(favicon, null /* mForegroundTabDrawable */); } holder.favicon.setImageBitmap(favicon); } 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 * the color of the tab background, for use when the tabs are displayed on the top * of the screen. @@ -1453,26 +1448,33 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements * @param tabBackground the optional LinearLayout to color */ 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() { @Override public void onGenerated(Palette palette) { // OR with opaque black to remove transparency glitches - int color = 0xff000000 | palette.getVibrantColor(mActivity.getResources() - .getColor(R.color.primary_color)); + int color = 0xff000000 | palette.getVibrantColor(defaultColor); int finalColor; // Lighten up the dark color if it is // too dark if (Utils.isColorTooDark(color)) { - finalColor = Utils.mixTwoColors( - mActivity.getResources().getColor(R.color.primary_color), - color, 0.25f); + finalColor = Utils.mixTwoColors(defaultColor, color, 0.25f); } else { finalColor = color; } - ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), - mBackground.getColor(), finalColor); + ValueAnimator anim = ValueAnimator.ofInt(mBackground.getColor(), finalColor); + anim.setEvaluator(new ArgbEvaluator()); final Window window = getWindow(); if (!mShowTabsInDrawer) { window.setBackgroundDrawable(new ColorDrawable(Color.BLACK)); @@ -1485,11 +1487,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements if (mShowTabsInDrawer) { mBackground.setColor(color); window.setBackgroundDrawable(mBackground); - } - mToolbarLayout.setBackgroundColor(color); - if (tabBackground != null) { + } else if (tabBackground != null) { tabBackground.setColorFilter(color, PorterDuff.Mode.SRC_IN); } + mToolbarLayout.setBackgroundColor(color); } }); @@ -1523,7 +1524,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements } break; } - } else { if (url.startsWith(Constants.FILE)) { url = ""; @@ -1548,15 +1548,15 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements public void run() { try { if (mHistoryDatabase == null) { - mHistoryDatabase = HistoryDatabase.getInstance(mActivity.getApplicationContext()); + mHistoryDatabase = HistoryDatabase.getInstance(); } mHistoryDatabase.visitHistoryItem(url, title); } catch (IllegalStateException e) { - Log.e(Constants.TAG, "IllegalStateException in updateHistory"); + Log.e(Constants.TAG, "IllegalStateException in updateHistory", e); } catch (NullPointerException e) { - Log.e(Constants.TAG, "NullPointerException in updateHistory"); + Log.e(Constants.TAG, "NullPointerException in updateHistory", 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); } - if (API < 19) { + if (API < Build.VERSION_CODES.KITKAT) { try { mCustomViewCallback.onCustomViewHidden(); } catch (Throwable ignored) { @@ -1927,7 +1927,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements public FullscreenHolder(Context ctx) { super(ctx); 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 { 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 public Bitmap getDefaultVideoPoster() { - if (mDefaultVideoPoster == null) { - mDefaultVideoPoster = BitmapFactory.decodeResource(getResources(), - android.R.drawable.ic_media_play); - } - return mDefaultVideoPoster; + return BitmapFactory.decodeResource(getResources(), android.R.drawable.spinner_background); } - /** - * dumb method that returns the loading progress for a video - */ @Override public View getVideoLoadingProgressView() { - if (mVideoProgressView == null) { - LayoutInflater inflater = LayoutInflater.from(this); - mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null); - } - return mVideoProgressView; + LayoutInflater inflater = LayoutInflater.from(this); + return inflater.inflate(R.layout.video_loading_progress, null); } /** @@ -2343,7 +2329,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements } private void setupFrameLayoutButton(@IdRes int buttonId, @IdRes int imageId) { - FrameLayout frameButton = (FrameLayout) findViewById(buttonId); + View frameButton = findViewById(buttonId); frameButton.setOnClickListener(this); frameButton.setOnLongClickListener(this); ImageView buttonImage = (ImageView) findViewById(imageId); @@ -2410,8 +2396,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements */ @Subscribe public void bookmarkCurrentPage(final BookmarkEvents.WantToBookmarkCurrentPage event) { - eventBus.post(new BrowserEvents - .AddBookmark(mCurrentView.getTitle(), mCurrentView.getUrl())); + if (mCurrentView != null) { + 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)) { openBookmarkPage(mWebView); } - eventBus - .post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl())); + if (mCurrentView != null) { + eventBus.post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl())); + } } /** @@ -2451,8 +2439,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements && mCurrentView.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) { openBookmarkPage(mWebView); } - eventBus - .post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl())); + if (mCurrentView != null) { + eventBus.post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl())); + } } /** diff --git a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java index 5c2c058..41dc907 100644 --- a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java @@ -66,8 +66,7 @@ public class HistoryPage { } private static List getWebHistory(Context context) { - HistoryDatabase databaseHandler = HistoryDatabase.getInstance(context - .getApplicationContext()); + HistoryDatabase databaseHandler = HistoryDatabase.getInstance(); return databaseHandler.getLastHundredItems(); } } diff --git a/app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java b/app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java index 147384f..8d42983 100644 --- a/app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java +++ b/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.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; + import java.util.ArrayList; import java.util.List; import acr.browser.lightning.R; +import acr.browser.lightning.app.BrowserApp; public class HistoryDatabase extends SQLiteOpenHelper { @@ -35,9 +37,11 @@ public class HistoryDatabase extends SQLiteOpenHelper { private static HistoryDatabase mInstance; - public static HistoryDatabase getInstance(Context context) { + private boolean mLock; + + public static HistoryDatabase getInstance() { if (mInstance == null || mInstance.isClosed()) { - mInstance = new HistoryDatabase(context); + mInstance = new HistoryDatabase(BrowserApp.getAppContext()); } return mInstance; } @@ -77,41 +81,61 @@ public class HistoryDatabase extends SQLiteOpenHelper { @Override public synchronized void close() { - if (mDatabase != null) { - mDatabase.close(); + if (!mLock) { + if (mDatabase != null) { + mDatabase.close(); + mDatabase = null; + } } super.close(); } + private void openIfNecessary() { + if (mDatabase == null) { + mDatabase = this.getWritableDatabase(); + } + } + 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) { + mLock = true; + openIfNecessary(); ContentValues values = new ContentValues(); values.put(KEY_TITLE, title); values.put(KEY_TIME_VISITED, System.currentTimeMillis()); - Cursor q = mDatabase.query(false, TABLE_HISTORY, new String[] { KEY_URL }, - KEY_URL + " = ?", new String[] { url }, null, null, null, "1"); + Cursor q = mDatabase.query(false, TABLE_HISTORY, new String[]{KEY_URL}, + KEY_URL + " = ?", new String[]{url}, null, null, null, "1"); 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 { addHistoryItem(new HistoryItem(url, title)); } q.close(); + mLock = false; } private synchronized void addHistoryItem(HistoryItem item) { + mLock = true; + openIfNecessary(); ContentValues values = new ContentValues(); values.put(KEY_URL, item.getUrl()); values.put(KEY_TITLE, item.getTitle()); values.put(KEY_TIME_VISITED, System.currentTimeMillis()); mDatabase.insert(TABLE_HISTORY, null, values); + mLock = false; } String getHistoryItem(String url) { - Cursor cursor = mDatabase.query(TABLE_HISTORY, new String[] { KEY_ID, KEY_URL, KEY_TITLE }, - KEY_URL + " = ?", new String[] { url }, null, null, null, null); + mLock = true; + 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; if (cursor != null) { cursor.moveToFirst(); @@ -119,11 +143,14 @@ public class HistoryDatabase extends SQLiteOpenHelper { cursor.close(); } + mLock = false; return m; } public List findItemsContaining(String search) { - List itemList = new ArrayList<>(); + mLock = true; + openIfNecessary(); + List itemList = new ArrayList<>(5); String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " WHERE " + KEY_TITLE + " LIKE '%" + search + "%' OR " + KEY_URL + " LIKE '%" + search + "%' " + "ORDER BY " + KEY_TIME_VISITED + " DESC LIMIT 5"; @@ -142,11 +169,14 @@ public class HistoryDatabase extends SQLiteOpenHelper { } while (cursor.moveToNext() && n < 5); } cursor.close(); + mLock = false; return itemList; } public List getLastHundredItems() { - List itemList = new ArrayList<>(); + mLock = true; + openIfNecessary(); + List itemList = new ArrayList<>(100); String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED + " DESC"; @@ -164,10 +194,13 @@ public class HistoryDatabase extends SQLiteOpenHelper { } while (cursor.moveToNext() && counter < 100); } cursor.close(); + mLock = false; return itemList; } public List getAllHistoryItems() { + mLock = true; + openIfNecessary(); List itemList = new ArrayList<>(); String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " ORDER BY " + KEY_TIME_VISITED + " DESC"; @@ -185,25 +218,31 @@ public class HistoryDatabase extends SQLiteOpenHelper { } while (cursor.moveToNext()); } cursor.close(); + mLock = false; return itemList; } public synchronized int updateHistoryItem(HistoryItem item) { - + mLock = true; + openIfNecessary(); ContentValues values = new ContentValues(); values.put(KEY_URL, item.getUrl()); values.put(KEY_TITLE, item.getTitle()); values.put(KEY_TIME_VISITED, System.currentTimeMillis()); - return mDatabase.update(TABLE_HISTORY, values, KEY_ID + " = ?", - new String[] { String.valueOf(item.getId()) }); + int update = mDatabase.update(TABLE_HISTORY, values, KEY_ID + " = ?", + new String[]{String.valueOf(item.getId())}); + mLock = false; + return update; } public int getHistoryItemsCount() { + mLock = true; + openIfNecessary(); String countQuery = "SELECT * FROM " + TABLE_HISTORY; Cursor cursor = mDatabase.rawQuery(countQuery, null); int n = cursor.getCount(); cursor.close(); - + mLock = false; return n; } } diff --git a/app/src/main/java/acr/browser/lightning/object/SearchAdapter.java b/app/src/main/java/acr/browser/lightning/object/SearchAdapter.java index a8e6ac9..7430f41 100644 --- a/app/src/main/java/acr/browser/lightning/object/SearchAdapter.java +++ b/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) { BrowserApp.getAppComponent().inject(this); - mDatabaseHandler = HistoryDatabase.getInstance(context.getApplicationContext()); + mDatabaseHandler = HistoryDatabase.getInstance(); mAllBookmarks.addAll(mBookmarkManager.getAllBookmarks(true)); mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled(); mContext = context; @@ -125,7 +125,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { mSuggestions.clear(); } } - mDatabaseHandler = HistoryDatabase.getInstance(mContext.getApplicationContext()); + mDatabaseHandler = HistoryDatabase.getInstance(); } public void refreshBookmarks() { @@ -245,7 +245,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable { } } if (mDatabaseHandler == null || mDatabaseHandler.isClosed()) { - mDatabaseHandler = HistoryDatabase.getInstance(mContext.getApplicationContext()); + mDatabaseHandler = HistoryDatabase.getInstance(); } List historyList = mDatabaseHandler.findItemsContaining(constraint.toString()); synchronized (mHistory) { diff --git a/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java b/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java index 054b59e..29327fb 100644 --- a/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java @@ -112,11 +112,11 @@ public class ThemeUtils { Resources res = context.getResources(); int color; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - color = (dark) ? res.getColor(R.color.divider_dark, context.getTheme()) : - res.getColor(R.color.divider_light, context.getTheme()); + color = (dark) ? res.getColor(R.color.selected_dark, context.getTheme()) : + res.getColor(R.color.selected_light, context.getTheme()); } else { - color = (dark) ? res.getColor(R.color.divider_dark) : - res.getColor(R.color.divider_light); + color = (dark) ? res.getColor(R.color.selected_dark) : + res.getColor(R.color.selected_light); } return new ColorDrawable(color); } diff --git a/app/src/main/java/acr/browser/lightning/utils/WebUtils.java b/app/src/main/java/acr/browser/lightning/utils/WebUtils.java index f6b2280..96ce095 100644 --- a/app/src/main/java/acr/browser/lightning/utils/WebUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/WebUtils.java @@ -32,7 +32,7 @@ public class WebUtils { } public static void clearHistory(@NonNull Context context) { - HistoryDatabase.getInstance(context).deleteHistory(); + HistoryDatabase.getInstance().deleteHistory(); WebViewDatabase m = WebViewDatabase.getInstance(context); m.clearFormData(); m.clearHttpAuthUsernamePassword(); diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index 21ffabe..85907a1 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/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.Intent; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Paint; @@ -98,7 +99,7 @@ public class LightningView { private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION}; @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; mWebView = new WebView(activity); @@ -111,27 +112,20 @@ public class LightningView { mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity(); - try { - mBrowserController = (BrowserController) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity + " must implement BrowserController"); - } + mBrowserController = controller; + mIntentUtils = new IntentUtils(mBrowserController); - mWebView.setDrawingCacheBackgroundColor(0x00000000); + mWebView.setDrawingCacheBackgroundColor(Color.WHITE); mWebView.setFocusableInTouchMode(true); mWebView.setFocusable(true); - mWebView.setAnimationCacheEnabled(false); mWebView.setDrawingCacheEnabled(false); mWebView.setWillNotCacheDrawing(true); - mWebView.setAlwaysDrawnWithCacheEnabled(false); - mWebView.setBackgroundColor(0); - - if (API >= Build.VERSION_CODES.JELLY_BEAN) { - mWebView.setBackground(null); - mWebView.getRootView().setBackground(null); - } else if (mWebView.getRootView() != null) { - mWebView.getRootView().setBackgroundDrawable(null); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { + mWebView.setAnimationCacheEnabled(false); + mWebView.setAlwaysDrawnWithCacheEnabled(false); } + mWebView.setBackgroundColor(Color.WHITE); + mWebView.setScrollbarFadingEnabled(true); mWebView.setSaveEnabled(true); mWebView.setNetworkAvailable(true); diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 072e30f..2d7f07b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -21,8 +21,8 @@ #424242 - #1EFFFFFF - #1E000000 + #1FFFFFFF + #1F000000 #0FFFFFFF