Browse Source

Adding setting for black status bar

master
anthony restaino 8 years ago
parent
commit
ffec083eca
  1. 2
      app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java
  2. 4
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  3. 16
      app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java
  4. 21
      app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java
  5. 63
      app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java
  6. 9
      app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
  7. 6
      app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java
  8. 1
      app/src/main/res/values/strings.xml
  9. 4
      app/src/main/res/values/styles.xml
  10. 4
      app/src/main/res/xml/preference_display.xml

2
app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java

@ -23,7 +23,7 @@ import acr.browser.lightning.app.BrowserApp;
public class SettingsActivity extends ThemableSettingsActivity { public class SettingsActivity extends ThemableSettingsActivity {
private static final List<String> mFragments = new ArrayList<>(7); @NonNull private static final List<String> mFragments = new ArrayList<>(7);
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {

4
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -55,12 +55,12 @@ public class TabsManager {
private static final String URL_KEY = "URL_KEY"; private static final String URL_KEY = "URL_KEY";
private static final String BUNDLE_STORAGE = "SAVED_TABS.parcel"; private static final String BUNDLE_STORAGE = "SAVED_TABS.parcel";
private final List<LightningView> mTabList = new ArrayList<>(1); @NonNull private final List<LightningView> mTabList = new ArrayList<>(1);
@Nullable private LightningView mCurrentTab; @Nullable private LightningView mCurrentTab;
@Nullable private TabNumberChangedListener mTabNumberListener; @Nullable private TabNumberChangedListener mTabNumberListener;
private boolean mIsInitialized = false; private boolean mIsInitialized = false;
private final List<Runnable> mPostInitializationWorkList = new ArrayList<>(); @NonNull private final List<Runnable> mPostInitializationWorkList = new ArrayList<>();
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferenceManager;
@Inject Application mApp; @Inject Application mApp;

16
app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java

@ -2,6 +2,8 @@ package acr.browser.lightning.activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -10,6 +12,7 @@ import javax.inject.Inject;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ThemeUtils;
public abstract class ThemableBrowserActivity extends AppCompatActivity { public abstract class ThemableBrowserActivity extends AppCompatActivity {
@ -32,6 +35,18 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
setTheme(R.style.Theme_BlackTheme); setTheme(R.style.Theme_BlackTheme);
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
resetPreferences();
}
private void resetPreferences() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (mPreferences.getUseBlackStatusBar()) {
getWindow().setStatusBarColor(Color.BLACK);
} else {
getWindow().setStatusBarColor(ThemeUtils.getStatusBarColor(this));
}
}
} }
@Override @Override
@ -56,6 +71,7 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
resetPreferences();
mShouldRunOnResumeActions = true; mShouldRunOnResumeActions = true;
int theme = mPreferences.getUseTheme(); int theme = mPreferences.getUseTheme();
boolean drawerTabs = mPreferences.getShowTabsInDrawer(!isTablet()); boolean drawerTabs = mPreferences.getShowTabsInDrawer(!isTablet());

21
app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java

@ -1,6 +1,8 @@
package acr.browser.lightning.activity; package acr.browser.lightning.activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import javax.inject.Inject; import javax.inject.Inject;
@ -14,12 +16,12 @@ public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivi
private int mTheme; private int mTheme;
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferences;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
BrowserApp.getAppComponent().inject(this); BrowserApp.getAppComponent().inject(this);
mTheme = mPreferenceManager.getUseTheme(); mTheme = mPreferences.getUseTheme();
// set the theme // set the theme
if (mTheme == 0) { if (mTheme == 0) {
@ -33,12 +35,25 @@ public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivi
this.getWindow().setBackgroundDrawable(new ColorDrawable(ThemeUtils.getPrimaryColorDark(this))); this.getWindow().setBackgroundDrawable(new ColorDrawable(ThemeUtils.getPrimaryColorDark(this)));
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
resetPreferences();
}
private void resetPreferences() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (mPreferences.getUseBlackStatusBar()) {
getWindow().setStatusBarColor(Color.BLACK);
} else {
getWindow().setStatusBarColor(ThemeUtils.getStatusBarColor(this));
}
}
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (mPreferenceManager.getUseTheme() != mTheme) { resetPreferences();
if (mPreferences.getUseTheme() != mTheme) {
restart(); restart();
} }
} }

63
app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java

@ -33,6 +33,7 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
private static final String SETTINGS_TEXTSIZE = "text_size"; private static final String SETTINGS_TEXTSIZE = "text_size";
private static final String SETTINGS_DRAWERTABS = "cb_drawertabs"; private static final String SETTINGS_DRAWERTABS = "cb_drawertabs";
private static final String SETTINGS_SWAPTABS = "cb_swapdrawers"; private static final String SETTINGS_SWAPTABS = "cb_swapdrawers";
private static final String SETTINGS_BLACK_STATUS = "black_status_bar";
private static final float XXLARGE = 30.0f; private static final float XXLARGE = 30.0f;
private static final float XLARGE = 26.0f; private static final float XLARGE = 26.0f;
@ -42,8 +43,7 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
private static final float XSMALL = 10.0f; private static final float XSMALL = 10.0f;
private Activity mActivity; private Activity mActivity;
private CheckBoxPreference cbstatus, cbfullscreen, cbviewport, cboverview, cbreflow; private Preference mTheme;
private Preference theme;
private String[] mThemeOptions; private String[] mThemeOptions;
private int mCurrentTheme; private int mCurrentTheme;
@ -63,35 +63,38 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
mThemeOptions = this.getResources().getStringArray(R.array.themes); mThemeOptions = this.getResources().getStringArray(R.array.themes);
mCurrentTheme = mPreferenceManager.getUseTheme(); mCurrentTheme = mPreferenceManager.getUseTheme();
theme = findPreference(SETTINGS_THEME); mTheme = findPreference(SETTINGS_THEME);
Preference textsize = findPreference(SETTINGS_TEXTSIZE); Preference textSize = findPreference(SETTINGS_TEXTSIZE);
cbstatus = (CheckBoxPreference) findPreference(SETTINGS_HIDESTATUSBAR); CheckBoxPreference cbStatus = (CheckBoxPreference) findPreference(SETTINGS_HIDESTATUSBAR);
cbfullscreen = (CheckBoxPreference) findPreference(SETTINGS_FULLSCREEN); CheckBoxPreference cbFullScreen = (CheckBoxPreference) findPreference(SETTINGS_FULLSCREEN);
cbviewport = (CheckBoxPreference) findPreference(SETTINGS_VIEWPORT); CheckBoxPreference cbViewPort = (CheckBoxPreference) findPreference(SETTINGS_VIEWPORT);
cboverview = (CheckBoxPreference) findPreference(SETTINGS_OVERVIEWMODE); CheckBoxPreference cbOverview = (CheckBoxPreference) findPreference(SETTINGS_OVERVIEWMODE);
cbreflow = (CheckBoxPreference) findPreference(SETTINGS_REFLOW); CheckBoxPreference cbReflow = (CheckBoxPreference) findPreference(SETTINGS_REFLOW);
CheckBoxPreference cbBlackStatus = (CheckBoxPreference) findPreference(SETTINGS_BLACK_STATUS);
CheckBoxPreference cbDrawerTabs = (CheckBoxPreference) findPreference(SETTINGS_DRAWERTABS); CheckBoxPreference cbDrawerTabs = (CheckBoxPreference) findPreference(SETTINGS_DRAWERTABS);
CheckBoxPreference cbSwapTabs = (CheckBoxPreference) findPreference(SETTINGS_SWAPTABS); CheckBoxPreference cbSwapTabs = (CheckBoxPreference) findPreference(SETTINGS_SWAPTABS);
theme.setOnPreferenceClickListener(this); mTheme.setOnPreferenceClickListener(this);
textsize.setOnPreferenceClickListener(this); textSize.setOnPreferenceClickListener(this);
cbstatus.setOnPreferenceChangeListener(this); cbStatus.setOnPreferenceChangeListener(this);
cbfullscreen.setOnPreferenceChangeListener(this); cbFullScreen.setOnPreferenceChangeListener(this);
cbviewport.setOnPreferenceChangeListener(this); cbViewPort.setOnPreferenceChangeListener(this);
cboverview.setOnPreferenceChangeListener(this); cbOverview.setOnPreferenceChangeListener(this);
cbreflow.setOnPreferenceChangeListener(this); cbReflow.setOnPreferenceChangeListener(this);
cbBlackStatus.setOnPreferenceChangeListener(this);
cbDrawerTabs.setOnPreferenceChangeListener(this); cbDrawerTabs.setOnPreferenceChangeListener(this);
cbSwapTabs.setOnPreferenceChangeListener(this); cbSwapTabs.setOnPreferenceChangeListener(this);
cbstatus.setChecked(mPreferenceManager.getHideStatusBarEnabled()); cbStatus.setChecked(mPreferenceManager.getHideStatusBarEnabled());
cbfullscreen.setChecked(mPreferenceManager.getFullScreenEnabled()); cbFullScreen.setChecked(mPreferenceManager.getFullScreenEnabled());
cbviewport.setChecked(mPreferenceManager.getUseWideViewportEnabled()); cbViewPort.setChecked(mPreferenceManager.getUseWideViewportEnabled());
cboverview.setChecked(mPreferenceManager.getOverviewModeEnabled()); cbOverview.setChecked(mPreferenceManager.getOverviewModeEnabled());
cbreflow.setChecked(mPreferenceManager.getTextReflowEnabled()); cbReflow.setChecked(mPreferenceManager.getTextReflowEnabled());
cbBlackStatus.setChecked(mPreferenceManager.getUseBlackStatusBar());
cbDrawerTabs.setChecked(mPreferenceManager.getShowTabsInDrawer(true)); cbDrawerTabs.setChecked(mPreferenceManager.getShowTabsInDrawer(true));
cbSwapTabs.setChecked(mPreferenceManager.getBookmarksAndTabsSwapped()); cbSwapTabs.setChecked(mPreferenceManager.getBookmarksAndTabsSwapped());
theme.setSummary(mThemeOptions[mPreferenceManager.getUseTheme()]); mTheme.setSummary(mThemeOptions[mPreferenceManager.getUseTheme()]);
} }
@Override @Override
@ -118,23 +121,18 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
switch (preference.getKey()) { switch (preference.getKey()) {
case SETTINGS_HIDESTATUSBAR: case SETTINGS_HIDESTATUSBAR:
mPreferenceManager.setHideStatusBarEnabled(checked); mPreferenceManager.setHideStatusBarEnabled(checked);
cbstatus.setChecked(checked);
return true; return true;
case SETTINGS_FULLSCREEN: case SETTINGS_FULLSCREEN:
mPreferenceManager.setFullScreenEnabled(checked); mPreferenceManager.setFullScreenEnabled(checked);
cbfullscreen.setChecked(checked);
return true; return true;
case SETTINGS_VIEWPORT: case SETTINGS_VIEWPORT:
mPreferenceManager.setUseWideViewportEnabled(checked); mPreferenceManager.setUseWideViewportEnabled(checked);
cbviewport.setChecked(checked);
return true; return true;
case SETTINGS_OVERVIEWMODE: case SETTINGS_OVERVIEWMODE:
mPreferenceManager.setOverviewModeEnabled(checked); mPreferenceManager.setOverviewModeEnabled(checked);
cboverview.setChecked(checked);
return true; return true;
case SETTINGS_REFLOW: case SETTINGS_REFLOW:
mPreferenceManager.setTextReflowEnabled(checked); mPreferenceManager.setTextReflowEnabled(checked);
cbreflow.setChecked(checked);
return true; return true;
case SETTINGS_DRAWERTABS: case SETTINGS_DRAWERTABS:
mPreferenceManager.setShowTabsInDrawer(checked); mPreferenceManager.setShowTabsInDrawer(checked);
@ -142,6 +140,9 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
case SETTINGS_SWAPTABS: case SETTINGS_SWAPTABS:
mPreferenceManager.setBookmarkAndTabsSwapped(checked); mPreferenceManager.setBookmarkAndTabsSwapped(checked);
return true; return true;
case SETTINGS_BLACK_STATUS:
mPreferenceManager.setUseBlackStatusBar(checked);
return true;
default: default:
return false; return false;
} }
@ -205,7 +206,7 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferenceManager.setUseTheme(which); mPreferenceManager.setUseTheme(which);
if (which < mThemeOptions.length) { if (which < mThemeOptions.length) {
theme.setSummary(mThemeOptions[which]); mTheme.setSummary(mThemeOptions[which]);
} }
} }
}); });
@ -233,13 +234,13 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme
private static class TextSeekBarListener implements SeekBar.OnSeekBarChangeListener { private static class TextSeekBarListener implements SeekBar.OnSeekBarChangeListener {
private final TextView sample; private final TextView mSample;
public TextSeekBarListener(TextView sample) {this.sample = sample;} public TextSeekBarListener(TextView sample) {this.mSample = sample;}
@Override @Override
public void onProgressChanged(SeekBar view, int size, boolean user) { public void onProgressChanged(SeekBar view, int size, boolean user) {
this.sample.setTextSize(getTextSize(size)); this.mSample.setTextSize(getTextSize(size));
} }
@Override @Override

9
app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java

@ -55,6 +55,7 @@ public class PreferenceManager {
static final String IDENTIFYING_HEADERS = "removeIdentifyingHeaders"; static final String IDENTIFYING_HEADERS = "removeIdentifyingHeaders";
static final String SWAP_BOOKMARKS_AND_TABS = "swapBookmarksAndTabs"; static final String SWAP_BOOKMARKS_AND_TABS = "swapBookmarksAndTabs";
static final String SEARCH_SUGGESTIONS = "searchSuggestions"; static final String SEARCH_SUGGESTIONS = "searchSuggestions";
static final String BLACK_STATUS_BAR = "blackStatusBar";
static final String USE_PROXY = "useProxy"; static final String USE_PROXY = "useProxy";
static final String PROXY_CHOICE = "proxyChoice"; static final String PROXY_CHOICE = "proxyChoice";
@ -295,6 +296,10 @@ public class PreferenceManager {
return mPrefs.getBoolean(Name.IDENTIFYING_HEADERS, false); return mPrefs.getBoolean(Name.IDENTIFYING_HEADERS, false);
} }
public boolean getUseBlackStatusBar() {
return mPrefs.getBoolean(Name.BLACK_STATUS_BAR, false);
}
private void putBoolean(@NonNull String name, boolean value) { private void putBoolean(@NonNull String name, boolean value) {
mPrefs.edit().putBoolean(name, value).apply(); mPrefs.edit().putBoolean(name, value).apply();
} }
@ -307,6 +312,10 @@ public class PreferenceManager {
mPrefs.edit().putString(name, value).apply(); mPrefs.edit().putString(name, value).apply();
} }
public void setUseBlackStatusBar(boolean enabled) {
putBoolean(Name.BLACK_STATUS_BAR, enabled);
}
public void setRemoveIdentifyingHeadersEnabled(boolean enabled) { public void setRemoveIdentifyingHeadersEnabled(boolean enabled) {
putBoolean(Name.IDENTIFYING_HEADERS, enabled); putBoolean(Name.IDENTIFYING_HEADERS, enabled);
} }

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

@ -1,5 +1,6 @@
package acr.browser.lightning.utils; package acr.browser.lightning.utils;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -37,6 +38,11 @@ public class ThemeUtils {
return getColor(context, R.attr.colorAccent); return getColor(context, R.attr.colorAccent);
} }
@TargetApi(21)
public static int getStatusBarColor(@NonNull Context context) {
return getColor(context, android.R.attr.statusBarColor);
}
public static int getColor(@NonNull Context context, @AttrRes int resource) { public static int getColor(@NonNull Context context, @AttrRes int resource) {
TypedArray a = context.obtainStyledAttributes(sTypedValue.data, new int[]{resource}); TypedArray a = context.obtainStyledAttributes(sTypedValue.data, new int[]{resource});
int color = a.getColor(0, 0); int color = a.getColor(0, 0);

1
app/src/main/res/values/strings.xml

@ -216,6 +216,7 @@
</string-array> </string-array>
<string name="invert_color">Invert color</string> <string name="invert_color">Invert color</string>
<string name="dark_theme">Dark Theme</string> <string name="dark_theme">Dark Theme</string>
<string name="settings_black_status_bar">Black status bar</string>
<string name="tabs">Tabs</string> <string name="tabs">Tabs</string>
<string name="theme">App Theme</string> <string name="theme">App Theme</string>
<string name="light_theme">Light Theme</string> <string name="light_theme">Light Theme</string>

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

@ -44,7 +44,7 @@
<!-- Theme Colors --> <!-- Theme Colors -->
<item name="colorPrimary">@color/primary_color</item> <item name="colorPrimary">@color/primary_color</item>
<item name="colorPrimaryDark">@color/secondary_color</item> <item name="colorPrimaryDark">@color/primary_color</item>
<item name="colorAccent">@color/accent_color</item> <item name="colorAccent">@color/accent_color</item>
<item name="drawerBackground">@color/drawer_background</item> <item name="drawerBackground">@color/drawer_background</item>
<item name="dividerColor">@color/divider_light</item> <item name="dividerColor">@color/divider_light</item>
@ -67,7 +67,7 @@
<!-- Theme colors --> <!-- Theme colors -->
<item name="colorPrimary">@color/primary_color_dark</item> <item name="colorPrimary">@color/primary_color_dark</item>
<item name="colorPrimaryDark">@color/secondary_color</item> <item name="colorPrimaryDark">@color/primary_color_dark</item>
<item name="colorAccent">@color/accent_color</item> <item name="colorAccent">@color/accent_color</item>
<item name="drawerBackground">@color/drawer_background_dark</item> <item name="drawerBackground">@color/drawer_background_dark</item>
<item name="dividerColor">@color/divider_dark</item> <item name="dividerColor">@color/divider_dark</item>

4
app/src/main/res/xml/preference_display.xml

@ -18,6 +18,10 @@
android:defaultValue="true" android:defaultValue="true"
android:key="fullscreen" android:key="fullscreen"
android:title="@string/fullscreen"/> android:title="@string/fullscreen"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="black_status_bar"
android:title="@string/settings_black_status_bar"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="wideViewPort" android:key="wideViewPort"

Loading…
Cancel
Save