From 8314676918fa4c6ac50d43783587533f13159ad8 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Thu, 29 Jan 2015 15:39:53 -0500 Subject: [PATCH] Added option to enable/disable Color Mode --- res/layout/settings.xml | 35 ++++++++++++++++++ res/values/strings.xml | 1 + .../browser/lightning/BrowserActivity.java | 37 +++++++++---------- .../lightning/PreferenceConstants.java | 1 + .../browser/lightning/SettingsActivity.java | 31 +++++++++++++--- 5 files changed, 80 insertions(+), 25 deletions(-) diff --git a/res/layout/settings.xml b/res/layout/settings.xml index b8de31e..8469644 100644 --- a/res/layout/settings.xml +++ b/res/layout/settings.xml @@ -186,6 +186,41 @@ android:layout_alignParentRight="true" android:layout_centerVertical="true" /> + + + + + + + + + Close all tabs Block 3rd Party Cookies This feature is only available on Android 5.0+ + Enable Color Mode diff --git a/src/acr/browser/lightning/BrowserActivity.java b/src/acr/browser/lightning/BrowserActivity.java index 57610ca..42727cf 100644 --- a/src/acr/browser/lightning/BrowserActivity.java +++ b/src/acr/browser/lightning/BrowserActivity.java @@ -102,6 +102,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl private int mActionBarSize; private ActionBar mActionBar; private boolean mFullScreen; + private boolean mColorMode; private FrameLayout mBrowserFrame; private LinearLayout mPageLayout; private LinearLayout mUiLayout; @@ -494,7 +495,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl initializePreferences(); initializeTabs(); - if (API < 19) { + if (API <= Build.VERSION_CODES.JELLY_BEAN_MR2) { WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath()); } @@ -720,17 +721,20 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); } mFullScreen = mPreferences.getBoolean(PreferenceConstants.FULL_SCREEN, false); - if (mFullScreen) { - if (mBrowserFrame.findViewById(R.id.toolbar_layout) == null) { - mUiLayout.removeView(mToolbarLayout); - mBrowserFrame.addView(mToolbarLayout); - mToolbarLayout.bringToFront(); - } - } else { - if (mBrowserFrame.findViewById(R.id.toolbar_layout) != null) { - mBrowserFrame.removeView(mToolbarLayout); - mUiLayout.addView(mToolbarLayout, 0); - } + mColorMode = mPreferences.getBoolean(PreferenceConstants.ENABLE_COLOR_MODE, true); + + if (!isIncognito() && !mColorMode && mWebpageBitmap != null) + changeToolbarBackground(mWebpageBitmap); + else if (!isIncognito() && mCurrentView != null && mCurrentView.getFavicon() != null) + changeToolbarBackground(mCurrentView.getFavicon()); + + if (mFullScreen && mBrowserFrame.findViewById(R.id.toolbar_layout) == null) { + mUiLayout.removeView(mToolbarLayout); + mBrowserFrame.addView(mToolbarLayout); + mToolbarLayout.bringToFront(); + } else if (mBrowserFrame.findViewById(R.id.toolbar_layout) != null) { + mBrowserFrame.removeView(mToolbarLayout); + mUiLayout.addView(mToolbarLayout, 0); } if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, @@ -1180,9 +1184,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl } public void handleNewIntent(Intent intent) { - if (mCurrentView == null) { - initialize(); - } String url = null; if (intent != null) { @@ -1534,8 +1535,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl } mBookmarkList = mBookmarkManager.getBookmarks(true); notifyBookmarkDataSetChanged(); - } else { - initialize(); } initializePreferences(); if (mWebViews != null) { @@ -1546,8 +1545,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl mWebViews.remove(n); } } - } else { - initialize(); } } @@ -1696,7 +1693,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl if (web.isForegroundTab()) { holder.favicon.setImageBitmap(favicon); - if (!isIncognito()) + if (!isIncognito() && mColorMode) changeToolbarBackground(favicon); } else { Bitmap grayscaleBitmap = Bitmap.createBitmap(favicon.getWidth(), diff --git a/src/acr/browser/lightning/PreferenceConstants.java b/src/acr/browser/lightning/PreferenceConstants.java index 5eb713b..5e65d1d 100644 --- a/src/acr/browser/lightning/PreferenceConstants.java +++ b/src/acr/browser/lightning/PreferenceConstants.java @@ -41,6 +41,7 @@ public final class PreferenceConstants { public static final String RENDERING_MODE = "renderMode"; public static final String SYNC_HISTORY = "syncHistory"; public static final String BLOCK_THIRD_PARTY = "thirdParty"; + public static final String ENABLE_COLOR_MODE = "colorMode"; public static final String USE_PROXY = "useProxy"; public static final String USE_PROXY_HOST = "useProxyHost"; diff --git a/src/acr/browser/lightning/SettingsActivity.java b/src/acr/browser/lightning/SettingsActivity.java index 1ab853e..b47fd1b 100644 --- a/src/acr/browser/lightning/SettingsActivity.java +++ b/src/acr/browser/lightning/SettingsActivity.java @@ -74,6 +74,7 @@ public class SettingsActivity extends ActionBarActivity { RelativeLayout layoutImages = (RelativeLayout) findViewById(R.id.layoutImages); RelativeLayout layoutEnableJS = (RelativeLayout) findViewById(R.id.layoutEnableJS); RelativeLayout layoutOrbot = (RelativeLayout) findViewById(R.id.layoutUseOrbot); + RelativeLayout layoutColor = (RelativeLayout) findViewById(R.id.layoutColorMode); RelativeLayout layoutBookmarks = (RelativeLayout) findViewById(R.id.layoutBookmarks); layoutBookmarks.setOnClickListener(new OnClickListener(){ @@ -98,6 +99,7 @@ public class SettingsActivity extends ActionBarActivity { CheckBox images = (CheckBox) findViewById(R.id.cbImageBlock); CheckBox enablejs = (CheckBox) findViewById(R.id.cbJavascript); CheckBox orbot = (CheckBox) findViewById(R.id.cbOrbot); + CheckBox color = (CheckBox) findViewById(R.id.cbColorMode); images.setChecked(imagesBool); enablejs.setChecked(enableJSBool); @@ -108,10 +110,11 @@ public class SettingsActivity extends ActionBarActivity { } adblock.setChecked(mPreferences.getBoolean(PreferenceConstants.BLOCK_ADS, false)); orbot.setChecked(mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false)); + color.setChecked(mPreferences.getBoolean(PreferenceConstants.ENABLE_COLOR_MODE, true)); - initCheckBox(flash, adblock, images, enablejs, orbot); + initCheckBox(flash, adblock, images, enablejs, orbot, color); clickListenerForCheckBoxes(layoutFlash, layoutBlockAds, layoutImages, layoutEnableJS, - layoutOrbot, flash, adblock, images, enablejs, orbot); + layoutOrbot, layoutColor, flash, adblock, images, enablejs, orbot, color); RelativeLayout general = (RelativeLayout) findViewById(R.id.layoutGeneral); RelativeLayout display = (RelativeLayout) findViewById(R.id.layoutDisplay); @@ -127,9 +130,9 @@ public class SettingsActivity extends ActionBarActivity { } public void clickListenerForCheckBoxes(RelativeLayout layoutFlash, RelativeLayout layoutBlockAds, - RelativeLayout layoutImages, RelativeLayout layoutEnableJS, RelativeLayout layoutOrbot, + RelativeLayout layoutImages, RelativeLayout layoutEnableJS, RelativeLayout layoutOrbot, RelativeLayout layoutColor, final CheckBox flash, final CheckBox adblock, final CheckBox images, final CheckBox enablejs, - final CheckBox orbot) { + final CheckBox orbot, final CheckBox color) { layoutFlash.setOnClickListener(new OnClickListener() { @Override @@ -180,10 +183,18 @@ public class SettingsActivity extends ActionBarActivity { } }); + layoutColor.setOnClickListener(new OnClickListener(){ + + @Override + public void onClick(View v) { + color.setChecked(!color.isChecked()); + } + + }); } public void initCheckBox(CheckBox flash, CheckBox adblock, CheckBox images, CheckBox enablejs, - CheckBox orbot) { + CheckBox orbot, CheckBox color) { flash.setEnabled(API < 19); flash.setOnCheckedChangeListener(new OnCheckedChangeListener() { @@ -266,6 +277,16 @@ public class SettingsActivity extends ActionBarActivity { } }); + color.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mEditPrefs.putBoolean(PreferenceConstants.ENABLE_COLOR_MODE, isChecked); + mEditPrefs.commit(); + + } + + }); } private void getFlashChoice() {