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; @@ -23,7 +23,7 @@ import acr.browser.lightning.app.BrowserApp;
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
protected void onCreate(Bundle savedInstanceState) {

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

@ -55,12 +55,12 @@ public class TabsManager { @@ -55,12 +55,12 @@ public class TabsManager {
private static final String URL_KEY = "URL_KEY";
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 TabNumberChangedListener mTabNumberListener;
private boolean mIsInitialized = false;
private final List<Runnable> mPostInitializationWorkList = new ArrayList<>();
@NonNull private final List<Runnable> mPostInitializationWorkList = new ArrayList<>();
@Inject PreferenceManager mPreferenceManager;
@Inject Application mApp;

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

@ -2,6 +2,8 @@ package acr.browser.lightning.activity; @@ -2,6 +2,8 @@ package acr.browser.lightning.activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
@ -10,6 +12,7 @@ import javax.inject.Inject; @@ -10,6 +12,7 @@ import javax.inject.Inject;
import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ThemeUtils;
public abstract class ThemableBrowserActivity extends AppCompatActivity {
@ -32,6 +35,18 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity { @@ -32,6 +35,18 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
setTheme(R.style.Theme_BlackTheme);
}
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
@ -56,6 +71,7 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity { @@ -56,6 +71,7 @@ public abstract class ThemableBrowserActivity extends AppCompatActivity {
@Override
protected void onResume() {
super.onResume();
resetPreferences();
mShouldRunOnResumeActions = true;
int theme = mPreferences.getUseTheme();
boolean drawerTabs = mPreferences.getShowTabsInDrawer(!isTablet());

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

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

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

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

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

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

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

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
package acr.browser.lightning.utils;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
@ -37,6 +38,11 @@ public class ThemeUtils { @@ -37,6 +38,11 @@ public class ThemeUtils {
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) {
TypedArray a = context.obtainStyledAttributes(sTypedValue.data, new int[]{resource});
int color = a.getColor(0, 0);

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

@ -216,6 +216,7 @@ @@ -216,6 +216,7 @@
</string-array>
<string name="invert_color">Invert color</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="theme">App Theme</string>
<string name="light_theme">Light Theme</string>

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

@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
<!-- Theme Colors -->
<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="drawerBackground">@color/drawer_background</item>
<item name="dividerColor">@color/divider_light</item>
@ -67,7 +67,7 @@ @@ -67,7 +67,7 @@
<!-- Theme colors -->
<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="drawerBackground">@color/drawer_background_dark</item>
<item name="dividerColor">@color/divider_dark</item>

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

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

Loading…
Cancel
Save