Theme improvements

This commit is contained in:
NekoInverter committed 2020-03-23 16:41:14 +08:00
1 parent a9b7df3284
commit d0d9b77f5e
65 files changed
+458 -561

No files matched your search

@@ -31,6 +31,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.collection.LruCache;
import com.getkeepsafe.relinker.ReLinker;
@@ -282,6 +283,8 @@ public class EhApplication extends RecordingApplication {
EhDB.mergeOldDB(this);
}
AppCompatDelegate.setDefaultNightMode(Settings.getTheme());
// Do io tasks in new thread
new AsyncTask<Void, Void, Void>() {
@Override
@@ -49,8 +49,9 @@ public class Settings {
********************/
public static final String KEY_THEME = "theme";
public static final int THEME_LIGHT = 0;
public static final int THEME_DARK = 1;
public static final String KEY_BLACK_DARK_THEME = "black_dark_theme";
public static final int THEME_LIGHT = 1;
public static final int THEME_SYSTEM = -1;
public static final int THEME_BLACK = 2;
public static final String KEY_APPLY_NAV_BAR_THEME_COLOR = "apply_nav_bar_theme_color";
public static final String KEY_GALLERY_SITE = "gallery_site";
@@ -109,7 +110,7 @@ public class Settings {
private static final boolean DEFAULT_SELECT_SITE = true;
private static final String KEY_QUICK_SEARCH_TIP = "quick_search_tip";
private static final boolean DEFAULT_QUICK_SEARCH_TIP = true;
private static final int DEFAULT_THEME = THEME_LIGHT;
private static final int DEFAULT_THEME = THEME_SYSTEM;
private static final boolean DEFAULT_APPLY_NAV_BAR_THEME_COLOR = true;
private static final int DEFAULT_GALLERY_SITE = 1;
private static final String KEY_LAUNCH_PAGE = "launch_page";
@@ -129,6 +130,8 @@ public class Settings {
private static final String DEFAULT_EXCLUDED_LANGUAGES = null;
private static final String KEY_CELLULAR_NETWORK_WARNING = "cellular_network_warning";
private static final boolean DEFAULT_CELLULAR_NETWORK_WARNING = false;
private static final String KEY_NIGHT_MODE = "night_mode";
private static final String DEFAULT_NIGHT_MODE = "-1";
/********************
****** Read
********************/
@@ -484,6 +484,7 @@ public class DownloadService extends Service implements DownloadManager.Download
// false for show, true for cancel
@Ops
private int mOps;
public NotificationDelay(Service service, NotificationManager notifyManager,
NotificationCompat.Builder builder, int id) {
mService = service;
@@ -19,9 +19,10 @@ package com.hippo.ehviewer.preference;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import androidx.preference.Preference;
import android.util.AttributeSet;
import androidx.preference.Preference;
import com.hippo.ehviewer.R;
public class VersionPreference extends Preference {
@@ -17,6 +17,8 @@
package com.hippo.ehviewer.ui;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.view.WindowManager;
@@ -32,9 +34,59 @@ import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import java.util.Locale;
import java.util.Objects;
public abstract class EhActivity extends AppCompatActivity {
private static final String THEME_DEFAULT = "DEFAULT";
private static final String THEME_BLACK = "BLACK";
private String mTheme;
public static boolean isBlackNightTheme() {
return Settings.getBoolean("black_dark_theme", false);
}
public static String getTheme(Context context) {
if (isBlackNightTheme()
&& isNightMode(context.getResources().getConfiguration()))
return THEME_BLACK;
return THEME_DEFAULT;
}
public static boolean isNightMode(Configuration configuration) {
return (configuration.uiMode & Configuration.UI_MODE_NIGHT_YES) > 0;
}
@Override
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
// apply real style and our custom style
if (getParent() == null) {
theme.applyStyle(resid, true);
} else {
try {
theme.setTo(getParent().getTheme());
} catch (Exception e) {
// Empty
}
theme.applyStyle(resid, false);
}
theme.applyStyle(getThemeStyleRes(this), true);
// only pass theme style to super, so styled theme will not be overwritten
super.onApplyThemeResource(theme, R.style.ThemeOverlay, first);
}
@StyleRes
public int getThemeStyleRes(Context context) {
switch (getTheme(context)) {
case THEME_BLACK:
return R.style.ThemeOverlay_Black;
case THEME_DEFAULT:
default:
return R.style.ThemeOverlay;
}
}
@StyleRes
protected abstract int getThemeResId(int theme);
@@ -49,6 +101,7 @@ public abstract class EhActivity extends AppCompatActivity {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Settings.getApplyNavBarThemeColor()) {
getWindow().setNavigationBarColor(AttrResources.getAttrColor(this, R.attr.colorPrimaryDark));
}
mTheme = getTheme(this);
}
@Override
@@ -67,6 +120,9 @@ public abstract class EhActivity extends AppCompatActivity {
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
if (!Objects.equals(mTheme, getTheme(this))) {
recreate();
}
}
@Override
@@ -48,6 +48,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.SwitchCompat;
import com.hippo.android.resource.AttrResources;
@@ -176,15 +177,7 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
@Override
protected int getThemeResId(int theme) {
switch (theme) {
case Settings.THEME_LIGHT:
default:
return R.style.AppTheme_Gallery;
case Settings.THEME_DARK:
return R.style.AppTheme_Gallery_Dark;
case Settings.THEME_BLACK:
return R.style.AppTheme_Gallery_Black;
}
return R.style.AppTheme_Gallery;
}
private void buildProvider() {
@@ -246,8 +239,9 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
}
@Override
@SuppressWarnings({"deprecation", "WrongConstant"})
@SuppressWarnings({"WrongConstant"})
protected void onCreate(@Nullable Bundle savedInstanceState) {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
if (Settings.getReadingFullscreen() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
@@ -25,14 +25,12 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -47,7 +45,6 @@ import androidx.drawerlayout.widget.DrawerLayout;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.snackbar.Snackbar;
import com.hippo.ehviewer.AppConfig;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhTagDatabase;
@@ -139,21 +136,11 @@ public final class MainActivity extends StageActivity
private LoadImageView mAvatar;
@Nullable
private TextView mDisplayName;
@Nullable
private Button mChangeTheme;
private int mNavCheckedItem = 0;
@Override
protected int getThemeResId(int theme) {
switch (theme) {
case Settings.THEME_LIGHT:
default:
return R.style.AppTheme_Main;
case Settings.THEME_DARK:
return R.style.AppTheme_Main_Dark;
case Settings.THEME_BLACK:
return R.style.AppTheme_Main_Black;
}
return R.style.AppTheme_Main;
}
@Override
@@ -168,9 +155,9 @@ public final class MainActivity extends StageActivity
return new Announcer(SecurityScene.class);
} else if (Settings.getShowWarning()) {
return new Announcer(WarningScene.class);
} else if (Settings.getAskAnalytics()) {
}/* else if (Settings.getAskAnalytics()) {
return new Announcer(AnalyticsScene.class);
} else if (EhUtils.needSignedIn(this)) {
}*/ else if (EhUtils.needSignedIn(this)) {
return new Announcer(SignInScene.class);
} else if (Settings.getSelectSite()) {
return new Announcer(SelectSiteScene.class);
@@ -194,12 +181,12 @@ public final class MainActivity extends StageActivity
newArgs.putString(WarningScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(WarningScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(WarningScene.class).setArgs(newArgs);
} else if (Settings.getAskAnalytics()) {
}/* else if (Settings.getAskAnalytics()) {
Bundle newArgs = new Bundle();
newArgs.putString(AnalyticsScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(AnalyticsScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(AnalyticsScene.class).setArgs(newArgs);
} else if (EhUtils.needSignedIn(this)) {
}*/ else if (EhUtils.needSignedIn(this)) {
Bundle newArgs = new Bundle();
newArgs.putString(SignInScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(SignInScene.KEY_TARGET_ARGS, announcer.getArgs());
@@ -333,14 +320,6 @@ public final class MainActivity extends StageActivity
View headerLayout = mNavView.getHeaderView(0);
mAvatar = (LoadImageView) ViewUtils.$$(headerLayout, R.id.avatar);
mDisplayName = (TextView) ViewUtils.$$(headerLayout, R.id.display_name);
mChangeTheme = (Button) ViewUtils.$$(this, R.id.change_theme);
//mDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
// Pre-L need shadow drawable
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_right, Gravity.RIGHT);
}
updateProfile();
@@ -348,12 +327,6 @@ public final class MainActivity extends StageActivity
mNavView.setNavigationItemSelectedListener(this);
}
mChangeTheme.setText(getThemeText());
mChangeTheme.setOnClickListener(v -> {
Settings.putTheme(getNextTheme());
((EhApplication) getApplication()).recreate();
});
if (savedInstanceState == null) {
onInit();
CommonOperations.checkUpdate(this, false);
@@ -368,35 +341,6 @@ public final class MainActivity extends StageActivity
EhTagDatabase.update(this);
}
private String getThemeText() {
int resId;
switch (Settings.getTheme()) {
default:
case Settings.THEME_LIGHT:
resId = R.string.theme_light;
break;
case Settings.THEME_DARK:
resId = R.string.theme_dark;
break;
case Settings.THEME_BLACK:
resId = R.string.theme_black;
break;
}
return getString(resId);
}
private int getNextTheme() {
switch (Settings.getTheme()) {
default:
case Settings.THEME_LIGHT:
return Settings.THEME_DARK;
case Settings.THEME_DARK:
return Settings.THEME_BLACK;
case Settings.THEME_BLACK:
return Settings.THEME_LIGHT;
}
}
private void checkDownloadLocation() {
UniFile uniFile = Settings.getDownloadLocation();
// null == uniFile for first start
@@ -25,7 +25,6 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBarDrawerToggle;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.ui.fragment.AboutFragment;
import com.hippo.ehviewer.ui.fragment.AdvancedFragment;
import com.hippo.ehviewer.ui.fragment.DownloadFragment;
@@ -50,15 +49,7 @@ public final class SettingsActivity extends EhActivity {
@Override
protected int getThemeResId(int theme) {
switch (theme) {
case Settings.THEME_LIGHT:
default:
return R.style.AppTheme_Settings;
case Settings.THEME_DARK:
return R.style.AppTheme_Settings_Dark;
case Settings.THEME_BLACK:
return R.style.AppTheme_Settings_Black;
}
return R.style.AppTheme_Settings;
}
private void setActionBarUpIndicator(Drawable drawable) {
@@ -26,21 +26,12 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
public abstract class ToolbarActivity extends EhActivity {
@Override
protected int getThemeResId(int theme) {
switch (theme) {
case Settings.THEME_LIGHT:
default:
return R.style.AppTheme_Toolbar;
case Settings.THEME_DARK:
return R.style.AppTheme_Toolbar_Dark;
case Settings.THEME_BLACK:
return R.style.AppTheme_Toolbar_Black;
}
return R.style.AppTheme_Toolbar;
}
@Override
@@ -21,6 +21,7 @@ import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.Preference;
import com.hippo.ehviewer.EhApplication;
@@ -37,6 +38,7 @@ public class EhFragment extends PreferenceFragmentCompat
addPreferencesFromResource(R.xml.eh_settings);
Preference theme = findPreference(Settings.KEY_THEME);
Preference blackDarkTheme = findPreference(Settings.KEY_BLACK_DARK_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);
@@ -52,6 +54,7 @@ public class EhFragment extends PreferenceFragmentCompat
detailSize.setOnPreferenceChangeListener(this);
thumbSize.setOnPreferenceChangeListener(this);
showTagTranslations.setOnPreferenceChangeListener(this);
blackDarkTheme.setOnPreferenceChangeListener(this);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
getPreferenceScreen().removePreference(applyNavBarThemeColor);
@@ -67,6 +70,7 @@ public class EhFragment extends PreferenceFragmentCompat
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (Settings.KEY_THEME.equals(key)) {
AppCompatDelegate.setDefaultNightMode(Integer.parseInt((String) newValue));
((EhApplication) getActivity().getApplication()).recreate();
return true;
} else if (Settings.KEY_APPLY_NAV_BAR_THEME_COLOR.equals(key)) {
@@ -86,6 +90,9 @@ public class EhFragment extends PreferenceFragmentCompat
if (Boolean.TRUE.equals(newValue)) {
EhTagDatabase.update(getActivity());
}
} else if (Settings.KEY_BLACK_DARK_THEME.equals(key)) {
((EhApplication) getActivity().getApplication()).recreate();
return true;
}
return true;
}
@@ -515,7 +515,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
mActionGroup = (ViewGroup) ViewUtils.$$(mHeader, R.id.action_card);
mDownload = (TextView) ViewUtils.$$(mActionGroup, R.id.download);
mRead = ViewUtils.$$(mActionGroup, R.id.read);
Ripple.addRipple(mOtherActions, isDarkTheme);
Ripple.addRipple(mDownload, isDarkTheme);
Ripple.addRipple(mRead, isDarkTheme);
mUploader.setOnClickListener(this);
@@ -45,10 +45,10 @@ public class SolidScene extends BaseScene {
break;
}
case CHECK_STEP_WARNING:
if (Settings.getAskAnalytics()) {
/*if (Settings.getAskAnalytics()) {
startScene(new Announcer(AnalyticsScene.class).setArgs(args));
break;
}
}*/
case CHECK_STEP_ANALYTICS:
if (EhUtils.needSignedIn(getContext2())) {
startScene(new Announcer(SignInScene.class).setArgs(args));
@@ -85,6 +85,7 @@ public final class ImageSearchLayout extends LinearLayout implements View.OnClic
setOrientation(VERTICAL);
setDividerDrawable(context.getResources().getDrawable(R.drawable.spacer_keyline));
setShowDividers(SHOW_DIVIDER_MIDDLE);
setClipToPadding(false);
LayoutInflater.from(context).inflate(R.layout.widget_image_search, this);
mPreview = (ImageView) ViewUtils.$$(this, R.id.preview);
@@ -42,8 +42,8 @@ import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import com.google.android.material.card.MaterialCardView;
import com.hippo.ehviewer.R;
import com.hippo.view.ViewTransition;
import com.hippo.yorozuya.AnimationUtils;
@@ -54,7 +54,7 @@ import com.hippo.yorozuya.ViewUtils;
import java.util.ArrayList;
import java.util.List;
public class SearchBar extends CardView implements View.OnClickListener,
public class SearchBar extends MaterialCardView implements View.OnClickListener,
TextView.OnEditorActionListener, TextWatcher,
SearchEditText.SearchEditTextListener {
@@ -28,8 +28,7 @@ public final class ViewAnimationUtils {
public static final boolean API_SUPPORT_CIRCULAR_REVEAL =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
// http://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported
public static final boolean API_SUPPORT_CANVAS_CLIP_PATH =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
private ViewAnimationUtils() {
}
@@ -90,18 +89,12 @@ public final class ViewAnimationUtils {
@Override
public void onAnimationStart(Animator animation) {
if (!API_SUPPORT_CANVAS_CLIP_PATH) {
mView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
mReveal.setRevealEnable(true);
}
@Override
public void onAnimationEnd(Animator animation) {
mReveal.setRevealEnable(false);
if (!API_SUPPORT_CANVAS_CLIP_PATH) {
mView.setLayerType(View.LAYER_TYPE_NONE, null);
}
}
}
}
@@ -140,8 +140,7 @@ public class LockPatternView extends View {
mPathPaint.setAntiAlias(true);
mPathPaint.setDither(true);
mRegularColor = getResources().getColor(AttrResources.getAttrBoolean(context, R.attr.isLightTheme) ?
R.color.lock_pattern_view_regular_color_light : R.color.lock_pattern_view_regular_color_dark);
mRegularColor = getResources().getColor(AttrResources.getAttrBoolean(context, R.attr.isLightTheme) ? R.color.lock_pattern_view_regular_color_light : R.color.lock_pattern_view_regular_color_dark);
mErrorColor = getResources().getColor(R.color.lock_pattern_view_error_color);
mSuccessColor = getResources().getColor(R.color.lock_pattern_view_success_color);