Apply theme color to navigation bar

This commit is contained in:
seven332 committed 2018-12-14 20:20:22 +08:00
1 parent e8de8ac5c8
commit 419405f4e2
9 files changed
+40

No files matched your search

@@ -252,6 +252,13 @@ public class Settings {
putIntToStr(KEY_THEME, theme);
}
public static final String KEY_APPLY_NAV_BAR_THEME_COLOR = "apply_nav_bar_theme_color";
private static final boolean DEFAULT_APPLY_NAV_BAR_THEME_COLOR = false;
public static boolean getApplyNavBarThemeColor() {
return getBoolean(KEY_APPLY_NAV_BAR_THEME_COLOR, DEFAULT_APPLY_NAV_BAR_THEME_COLOR);
}
public static final String KEY_GALLERY_SITE = "gallery_site";
private static final int DEFAULT_GALLERY_SITE = 1;
@@ -17,14 +17,17 @@
package com.hippo.ehviewer.ui;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.hippo.android.resource.AttrResources;
import com.hippo.content.ContextLocalWrapper;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import java.util.Locale;
@@ -44,6 +47,10 @@ public abstract class EhActivity extends AppCompatActivity {
if (Settings.getEnableAnalytics()) {
FirebaseAnalytics.getInstance(this);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Settings.getApplyNavBarThemeColor()) {
getWindow().setNavigationBarColor(AttrResources.getAttrColor(this, R.attr.colorPrimaryDark));
}
}
@Override
@@ -18,14 +18,17 @@ package com.hippo.ehviewer.ui;
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.WindowManager;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.hippo.android.resource.AttrResources;
import com.hippo.app.PrettyPreferenceActivity;
import com.hippo.content.ContextLocalWrapper;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import java.util.Locale;
@@ -45,6 +48,10 @@ public abstract class EhPreferenceActivity extends PrettyPreferenceActivity {
if (Settings.getEnableAnalytics()) {
FirebaseAnalytics.getInstance(this);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Settings.getApplyNavBarThemeColor()) {
getWindow().setNavigationBarColor(AttrResources.getAttrColor(this, R.attr.colorPrimaryDark));
}
}
@Override
@@ -17,6 +17,7 @@
package com.hippo.ehviewer.ui.fragment;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
@@ -33,16 +34,22 @@ public class EhFragment extends PreferenceFragment
addPreferencesFromResource(R.xml.eh_settings);
Preference theme = findPreference(Settings.KEY_THEME);
Preference applyNavBarThemeColor = findPreference(Settings.KEY_APPLY_NAV_BAR_THEME_COLOR);
Preference gallerySite = findPreference(Settings.KEY_GALLERY_SITE);
Preference listMode = findPreference(Settings.KEY_LIST_MODE);
Preference detailSize = findPreference(Settings.KEY_DETAIL_SIZE);
Preference thumbSize = findPreference(Settings.KEY_THUMB_SIZE);
theme.setOnPreferenceChangeListener(this);
applyNavBarThemeColor.setOnPreferenceChangeListener(this);
gallerySite.setOnPreferenceChangeListener(this);
listMode.setOnPreferenceChangeListener(this);
detailSize.setOnPreferenceChangeListener(this);
thumbSize.setOnPreferenceChangeListener(this);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
getPreferenceScreen().removePreference(applyNavBarThemeColor);
}
}
@Override
@@ -51,6 +58,9 @@ public class EhFragment extends PreferenceFragment
if (Settings.KEY_THEME.equals(key)) {
((EhApplication) getActivity().getApplication()).recreate();
return true;
} else if (Settings.KEY_APPLY_NAV_BAR_THEME_COLOR.equals(key)) {
((EhApplication) getActivity().getApplication()).recreate();
return true;
} else if (Settings.KEY_GALLERY_SITE.equals(key)) {
getActivity().setResult(Activity.RESULT_OK);
return true;
@@ -408,6 +408,7 @@
<string name="settings_eh_theme_light">亮色</string>
<string name="settings_eh_theme_dark">暗色</string>
<string name="settings_eh_theme_black">黑色</string>
<string name="settings_eh_apply_nav_bar_theme_color">导航栏应用主题配色</string>
<string name="settings_eh_gallery_site">画廊站点</string>
<string name="settings_eh_list_mode">列表模式</string>
<string name="settings_eh_list_mode_detail">详情</string>
@@ -407,6 +407,7 @@
<string name="settings_eh_theme_light">亮色</string>
<string name="settings_eh_theme_dark">暗色</string>
<string name="settings_eh_theme_black">黑色</string>
<string name="settings_eh_apply_nav_bar_theme_color">導航欄應用主題配色</string>
<string name="settings_eh_gallery_site">畫廊站點</string>
<string name="settings_eh_list_mode">列表模式</string>
<string name="settings_eh_list_mode_detail">詳情</string>
@@ -407,6 +407,7 @@
<string name="settings_eh_theme_light">亮色</string>
<string name="settings_eh_theme_dark">暗色</string>
<string name="settings_eh_theme_black">黑色</string>
<string name="settings_eh_apply_nav_bar_theme_color">導航欄應用主題配色</string>
<string name="settings_eh_gallery_site">圖庫站台</string>
<string name="settings_eh_list_mode">列表模式</string>
<string name="settings_eh_list_mode_detail">詳細資料</string>
+1
View File
@@ -451,6 +451,7 @@
<string name="settings_eh_theme_light">Light</string>
<string name="settings_eh_theme_dark">Dark</string>
<string name="settings_eh_theme_black">Black</string>
<string name="settings_eh_apply_nav_bar_theme_color">Apply theme color to navigation bar</string>
<string name="settings_eh_gallery_site">Gallery site</string>
<string name="settings_eh_list_mode">List mode</string>
<string name="settings_eh_list_mode_detail">Detail</string>
+5
View File
@@ -51,6 +51,11 @@
app:entryValues="@array/theme_entry_values"
android:defaultValue="0"/>
<com.hippo.preference.SwitchPreference
android:key="apply_nav_bar_theme_color"
android:title="@string/settings_eh_apply_nav_bar_theme_color"
android:defaultValue="false"/>
<com.hippo.preference.ListPreference
android:key="list_mode"
android:title="@string/settings_eh_list_mode"