diff --git a/app/build.gradle b/app/build.gradle index a8775b1c3..baa389c14 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,13 +42,11 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'androidx.core:core-ktx:1.0.2' - implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.core:core-ktx:1.2.0-alpha01' + implementation 'androidx.appcompat:appcompat:1.1.0-alpha05' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'androidx.recyclerview:recyclerview:1.0.0' - implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9d4cfaca1..d540a2f60 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,7 +23,7 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/CAppTheme" + android:theme="@style/AppTheme.Light" tools:ignore="AllowBackup,GoogleAppIndexingWarning"> @@ -32,7 +32,7 @@ + android:theme="@style/AppTheme.Light.NoActionBar"> diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index 2ee755f42..c58318df1 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -1,17 +1,17 @@ package io.legado.app.base -import android.annotation.SuppressLint -import android.graphics.PorterDuff import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.view.menu.MenuItemImpl +import androidx.core.content.ContextCompat import androidx.lifecycle.ViewModel import io.legado.app.R -import io.legado.app.lib.theme.ColorUtil -import io.legado.app.lib.theme.MaterialValueHelper +import io.legado.app.lib.theme.ColorUtils +import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.ThemeStore -import java.util.* +import io.legado.app.lib.theme.getPrimaryTextColor abstract class BaseActivity : AppCompatActivity() { @@ -34,47 +34,45 @@ abstract class BaseActivity : AppCompatActivity() { * 设置MENU图标颜色 */ override fun onCreateOptionsMenu(menu: Menu): Boolean { - val primaryTextColor = MaterialValueHelper - .getPrimaryTextColor(this, ColorUtil.isColorLight(ThemeStore.primaryColor(this))) + val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(this))) + val defaultTextColor = ContextCompat.getColor(this, R.color.tv_text_default) for (i in 0 until menu.size()) { - val drawable = menu.getItem(i).icon - if (drawable != null) { - drawable.mutate() - drawable.setColorFilter(primaryTextColor, PorterDuff.Mode.SRC_ATOP) + (menu.getItem(i) as MenuItemImpl).let {//overflow:展开的item + DrawableUtils.setTint(it.icon, if (it.requiresOverflow()) defaultTextColor else primaryTextColor) } } return super.onCreateOptionsMenu(menu) } - @SuppressLint("PrivateApi") - override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean { - if (menu != null) { - //展开菜单显示图标 - if (menu.javaClass.simpleName.equals("MenuBuilder", ignoreCase = true)) { - try { - var method = menu.javaClass.getDeclaredMethod("setOptionalIconsVisible", java.lang.Boolean.TYPE) - method.isAccessible = true - method.invoke(menu, true) - method = menu.javaClass.getDeclaredMethod("getNonActionItems") - val menuItems = method.invoke(menu) as ArrayList - if (menuItems.isNotEmpty()) { - for (menuItem in menuItems) { - val drawable = menuItem.icon - if (drawable != null) { - drawable.mutate() - drawable.setColorFilter( - resources.getColor(R.color.tv_text_default), - PorterDuff.Mode.SRC_ATOP - ) - } - } - } - } catch (ignored: Exception) { - } - } - } - return super.onMenuOpened(featureId, menu) - } +// @SuppressLint("PrivateApi") +// override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean { +// if (menu != null) { +// //展开菜单显示图标 +// if (menu.javaClass.simpleName.equals("MenuBuilder", ignoreCase = true)) { +// try { +// var method = menu.javaClass.getDeclaredMethod("setOptionalIconsVisible", java.lang.Boolean.TYPE) +// method.isAccessible = true +// method.invoke(menu, true) +// method = menu.javaClass.getDeclaredMethod("getNonActionItems") +// val menuItems = method.invoke(menu) as ArrayList +// if (menuItems.isNotEmpty()) { +// for (menuItem in menuItems) { +// val drawable = menuItem.icon +// if (drawable != null) { +// drawable.mutate() +// drawable.setColorFilter( +// resources.getColor(R.color.tv_text_default), +// PorterDuff.Mode.SRC_ATOP +// ) +// } +// } +// } +// } catch (ignored: Exception) { +// } +// } +// } +// return super.onMenuOpened(featureId, menu) +// } override fun onOptionsItemSelected(item: MenuItem?): Boolean { item?.let { @@ -91,10 +89,10 @@ abstract class BaseActivity : AppCompatActivity() { } protected fun initTheme() { - if (ColorUtil.isColorLight(ThemeStore.primaryColor(this))) { - setTheme(R.style.CAppTheme) + if (ColorUtils.isColorLight(ThemeStore.primaryColor(this))) { + setTheme(R.style.AppTheme_Light) } else { - setTheme(R.style.CAppThemeBarDark) + setTheme(R.style.AppTheme_Dark) } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index e0a55c52b..f3283b30f 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -18,7 +18,7 @@ object ATH { @SuppressLint("CommitPrefEdits") fun didThemeValuesChange(context: Context, since: Long): Boolean { return ThemeStore.isConfigured(context) && ThemeStore.prefs(context).getLong( - ThemeStore.VALUES_CHANGED, + ThemeStorePrefKeys.VALUES_CHANGED, -1 ) > since } @@ -35,7 +35,7 @@ object ATH { } fun setLightStatusbarAuto(activity: Activity, bgColor: Int) { - setLightStatusbar(activity, ColorUtil.isColorLight(bgColor)) + setLightStatusbar(activity, ColorUtils.isColorLight(bgColor)) } fun setLightStatusbar(activity: Activity, enabled: Boolean) { @@ -64,7 +64,7 @@ object ATH { } fun setLightNavigationbarAuto(activity: Activity, bgColor: Int) { - setLightNavigationbar(activity, ColorUtil.isColorLight(bgColor)) + setLightNavigationbar(activity, ColorUtils.isColorLight(bgColor)) } fun setNavigationbarColorAuto(activity: Activity) { @@ -86,7 +86,7 @@ object ATH { val color1: Int if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Task description requires fully opaque color - color1 = ColorUtil.stripAlpha(color) + color1 = ColorUtils.stripAlpha(color) // Sets color of entry in the system recents page activity.setTaskDescription(ActivityManager.TaskDescription(activity.title as String, null, color1)) } @@ -103,7 +103,7 @@ object ATH { fun setAlertDialogTint(dialog: AlertDialog): AlertDialog { val colorStateList = Selector.colorBuild() .setDefaultColor(ThemeStore.accentColor(dialog.context)) - .setPressedColor(ColorUtil.darkenColor(ThemeStore.accentColor(dialog.context))) + .setPressedColor(ColorUtils.darkenColor(ThemeStore.accentColor(dialog.context))) .create() if (dialog.getButton(AlertDialog.BUTTON_NEGATIVE) != null) { dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(colorStateList) diff --git a/app/src/main/java/io/legado/app/lib/theme/ATHUtil.kt b/app/src/main/java/io/legado/app/lib/theme/ATHUtils.kt similarity index 80% rename from app/src/main/java/io/legado/app/lib/theme/ATHUtil.kt rename to app/src/main/java/io/legado/app/lib/theme/ATHUtils.kt index 6cc19d511..ed6dfb734 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATHUtil.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATHUtils.kt @@ -6,10 +6,10 @@ import androidx.annotation.AttrRes /** * @author Aidan Follestad (afollestad) */ -object ATHUtil { +object ATHUtils { fun isWindowBackgroundDark(context: Context): Boolean { - return !ColorUtil.isColorLight(ATHUtil.resolveColor(context, android.R.attr.windowBackground)) + return !ColorUtils.isColorLight(resolveColor(context, android.R.attr.windowBackground)) } @JvmOverloads diff --git a/app/src/main/java/io/legado/app/lib/theme/ColorUtil.kt b/app/src/main/java/io/legado/app/lib/theme/ColorUtils.kt similarity index 99% rename from app/src/main/java/io/legado/app/lib/theme/ColorUtil.kt rename to app/src/main/java/io/legado/app/lib/theme/ColorUtils.kt index fa9bce4bd..ba0289637 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ColorUtil.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ColorUtils.kt @@ -4,7 +4,7 @@ import android.graphics.Color import androidx.annotation.ColorInt import androidx.annotation.FloatRange -object ColorUtil { +object ColorUtils { fun intToString(intColor: Int): String { return String.format("#%06X", 0xFFFFFF and intColor) diff --git a/app/src/main/java/io/legado/app/lib/theme/DrawableUtil.kt b/app/src/main/java/io/legado/app/lib/theme/DrawableUtil.kt deleted file mode 100644 index 454d9ba71..000000000 --- a/app/src/main/java/io/legado/app/lib/theme/DrawableUtil.kt +++ /dev/null @@ -1,25 +0,0 @@ -package io.legado.app.lib.theme - -import android.graphics.drawable.ColorDrawable -import android.graphics.drawable.Drawable -import android.graphics.drawable.TransitionDrawable -import androidx.annotation.ColorInt - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -object DrawableUtil { - - fun createTransitionDrawable(@ColorInt startColor: Int, @ColorInt endColor: Int): TransitionDrawable { - return createTransitionDrawable(ColorDrawable(startColor), ColorDrawable(endColor)) - } - - fun createTransitionDrawable(start: Drawable, end: Drawable): TransitionDrawable { - val drawables = arrayOfNulls(2) - - drawables[0] = start - drawables[1] = end - - return TransitionDrawable(drawables) - } -} diff --git a/app/src/main/java/io/legado/app/lib/theme/DrawableUtils.kt b/app/src/main/java/io/legado/app/lib/theme/DrawableUtils.kt new file mode 100644 index 000000000..08b43fc82 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/DrawableUtils.kt @@ -0,0 +1,43 @@ +package io.legado.app.lib.theme + +import android.content.res.ColorStateList +import android.graphics.PorterDuff +import android.graphics.drawable.ColorDrawable +import android.graphics.drawable.Drawable +import android.graphics.drawable.TransitionDrawable +import androidx.annotation.ColorInt +import androidx.core.graphics.drawable.DrawableCompat + +/** + * @author Karim Abou Zeid (kabouzeid) + */ +object DrawableUtils { + + fun createTransitionDrawable(@ColorInt startColor: Int, @ColorInt endColor: Int): TransitionDrawable { + return createTransitionDrawable(ColorDrawable(startColor), ColorDrawable(endColor)) + } + + fun createTransitionDrawable(start: Drawable, end: Drawable): TransitionDrawable { + val drawables = arrayOfNulls(2) + + drawables[0] = start + drawables[1] = end + + return TransitionDrawable(drawables) + } + + fun setTintList(drawable: Drawable, tint: ColorStateList, tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP) { + val wrappedDrawable = DrawableCompat.wrap(drawable) + wrappedDrawable.mutate() + DrawableCompat.setTintMode(wrappedDrawable, tintMode) + DrawableCompat.setTintList(wrappedDrawable, tint) + } + + + fun setTint(drawable: Drawable, @ColorInt tint: Int, tintMode: PorterDuff.Mode = PorterDuff.Mode.SRC_ATOP) { + val wrappedDrawable = DrawableCompat.wrap(drawable) + wrappedDrawable.mutate() + DrawableCompat.setTintMode(wrappedDrawable, tintMode) + DrawableCompat.setTint(wrappedDrawable, tint) + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt index 410de43dc..42dd3c5a8 100644 --- a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt @@ -4,42 +4,73 @@ import android.annotation.SuppressLint import android.content.Context import androidx.annotation.ColorInt import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment import io.legado.app.R /** * @author Karim Abou Zeid (kabouzeid) */ -object MaterialValueHelper { - - @SuppressLint("PrivateResource") - @ColorInt - fun getPrimaryTextColor(context: Context, dark: Boolean): Int { - return if (dark) { - ContextCompat.getColor(context, R.color.primary_text_default_material_light) - } else ContextCompat.getColor(context, R.color.primary_text_default_material_dark) - } - - @SuppressLint("PrivateResource") - @ColorInt - fun getSecondaryTextColor(context: Context, dark: Boolean): Int { - return if (dark) { - ContextCompat.getColor(context, R.color.secondary_text_default_material_light) - } else ContextCompat.getColor(context, R.color.secondary_text_default_material_dark) - } - - @SuppressLint("PrivateResource") - @ColorInt - fun getPrimaryDisabledTextColor(context: Context, dark: Boolean): Int { - return if (dark) { - ContextCompat.getColor(context, R.color.primary_text_disabled_material_light) - } else ContextCompat.getColor(context, R.color.primary_text_disabled_material_dark) - } - - @SuppressLint("PrivateResource") - @ColorInt - fun getSecondaryDisabledTextColor(context: Context, dark: Boolean): Int { - return if (dark) { - ContextCompat.getColor(context, R.color.secondary_text_disabled_material_light) - } else ContextCompat.getColor(context, R.color.secondary_text_disabled_material_dark) - } +@SuppressLint("PrivateResource") +@ColorInt +fun Context.getPrimaryTextColor(dark: Boolean): Int { + return if (dark) { + ContextCompat.getColor(this, R.color.primary_text_default_material_light) + } else ContextCompat.getColor(this, R.color.primary_text_default_material_dark) } + +@SuppressLint("PrivateResource") +@ColorInt +fun Context.getSecondaryTextColor(dark: Boolean): Int { + return if (dark) { + ContextCompat.getColor(this, R.color.secondary_text_default_material_light) + } else ContextCompat.getColor(this, R.color.secondary_text_default_material_dark) +} + +@SuppressLint("PrivateResource") +@ColorInt +fun Context.getPrimaryDisabledTextColor(dark: Boolean): Int { + return if (dark) { + ContextCompat.getColor(this, R.color.primary_text_disabled_material_light) + } else ContextCompat.getColor(this, R.color.primary_text_disabled_material_dark) +} + +@SuppressLint("PrivateResource") +@ColorInt +fun Context.getSecondaryDisabledTextColor(dark: Boolean): Int { + return if (dark) { + ContextCompat.getColor(this, R.color.secondary_text_disabled_material_light) + } else ContextCompat.getColor(this, R.color.secondary_text_disabled_material_dark) +} + + +@SuppressLint("PrivateResource") +@ColorInt +fun Fragment.getPrimaryTextColor(dark: Boolean): Int { + return if (dark) { + ContextCompat.getColor(requireContext(), R.color.primary_text_default_material_light) + } else ContextCompat.getColor(requireContext(), R.color.primary_text_default_material_dark) +} + +@SuppressLint("PrivateResource") +@ColorInt +fun Fragment.getSecondaryTextColor(dark: Boolean): Int { + return if (dark) { + ContextCompat.getColor(requireContext(), R.color.secondary_text_default_material_light) + } else ContextCompat.getColor(requireContext(), R.color.secondary_text_default_material_dark) +} + +@SuppressLint("PrivateResource") +@ColorInt +fun Fragment.getPrimaryDisabledTextColor(dark: Boolean): Int { + return if (dark) { + ContextCompat.getColor(requireContext(), R.color.primary_text_disabled_material_light) + } else ContextCompat.getColor(requireContext(), R.color.primary_text_disabled_material_dark) +} + +@SuppressLint("PrivateResource") +@ColorInt +fun Fragment.getSecondaryDisabledTextColor(dark: Boolean): Int { + return if (dark) { + ContextCompat.getColor(requireContext(), R.color.secondary_text_disabled_material_light) + } else ContextCompat.getColor(requireContext(), R.color.secondary_text_disabled_material_dark) +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/theme/NavigationViewUtil.kt b/app/src/main/java/io/legado/app/lib/theme/NavigationViewUtils.kt similarity index 97% rename from app/src/main/java/io/legado/app/lib/theme/NavigationViewUtil.kt rename to app/src/main/java/io/legado/app/lib/theme/NavigationViewUtils.kt index 43d17ff4b..c199ba855 100644 --- a/app/src/main/java/io/legado/app/lib/theme/NavigationViewUtil.kt +++ b/app/src/main/java/io/legado/app/lib/theme/NavigationViewUtils.kt @@ -8,7 +8,7 @@ import com.google.android.material.navigation.NavigationView /** * @author Karim Abou Zeid (kabouzeid) */ -object NavigationViewUtil { +object NavigationViewUtils { fun setItemIconColors(navigationView: NavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) { val iconSl = ColorStateList( diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt index a55237ee5..5d5b24194 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt @@ -26,7 +26,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt override fun primaryColor(@ColorInt color: Int): ThemeStore { mEditor.putInt(ThemeStorePrefKeys.KEY_PRIMARY_COLOR, color) if (autoGeneratePrimaryDark(mContext)) - primaryColorDark(ColorUtil.darkenColor(color)) + primaryColorDark(ColorUtils.darkenColor(color)) return this } @@ -35,7 +35,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt } override fun primaryColorAttr(@AttrRes colorAttr: Int): ThemeStore { - return primaryColor(ATHUtil.resolveColor(mContext, colorAttr)) + return primaryColor(ATHUtils.resolveColor(mContext, colorAttr)) } override fun primaryColorDark(@ColorInt color: Int): ThemeStore { @@ -48,7 +48,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt } override fun primaryColorDarkAttr(@AttrRes colorAttr: Int): ThemeStore { - return primaryColorDark(ATHUtil.resolveColor(mContext, colorAttr)) + return primaryColorDark(ATHUtils.resolveColor(mContext, colorAttr)) } override fun accentColor(@ColorInt color: Int): ThemeStore { @@ -61,7 +61,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt } override fun accentColorAttr(@AttrRes colorAttr: Int): ThemeStore { - return accentColor(ATHUtil.resolveColor(mContext, colorAttr)) + return accentColor(ATHUtils.resolveColor(mContext, colorAttr)) } override fun statusBarColor(@ColorInt color: Int): ThemeStore { @@ -74,7 +74,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt } override fun statusBarColorAttr(@AttrRes colorAttr: Int): ThemeStore { - return statusBarColor(ATHUtil.resolveColor(mContext, colorAttr)) + return statusBarColor(ATHUtils.resolveColor(mContext, colorAttr)) } override fun navigationBarColor(@ColorInt color: Int): ThemeStore { @@ -87,7 +87,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt } override fun navigationBarColorAttr(@AttrRes colorAttr: Int): ThemeStore { - return navigationBarColor(ATHUtil.resolveColor(mContext, colorAttr)) + return navigationBarColor(ATHUtils.resolveColor(mContext, colorAttr)) } override fun textColorPrimary(@ColorInt color: Int): ThemeStore { @@ -100,7 +100,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt } override fun textColorPrimaryAttr(@AttrRes colorAttr: Int): ThemeStore { - return textColorPrimary(ATHUtil.resolveColor(mContext, colorAttr)) + return textColorPrimary(ATHUtils.resolveColor(mContext, colorAttr)) } override fun textColorPrimaryInverse(@ColorInt color: Int): ThemeStore { @@ -113,7 +113,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt } override fun textColorPrimaryInverseAttr(@AttrRes colorAttr: Int): ThemeStore { - return textColorPrimaryInverse(ATHUtil.resolveColor(mContext, colorAttr)) + return textColorPrimaryInverse(ATHUtils.resolveColor(mContext, colorAttr)) } override fun textColorSecondary(@ColorInt color: Int): ThemeStore { @@ -126,7 +126,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt } override fun textColorSecondaryAttr(@AttrRes colorAttr: Int): ThemeStore { - return textColorSecondary(ATHUtil.resolveColor(mContext, colorAttr)) + return textColorSecondary(ATHUtils.resolveColor(mContext, colorAttr)) } override fun textColorSecondaryInverse(@ColorInt color: Int): ThemeStore { @@ -139,7 +139,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt } override fun textColorSecondaryInverseAttr(@AttrRes colorAttr: Int): ThemeStore { - return textColorSecondaryInverse(ATHUtil.resolveColor(mContext, colorAttr)) + return textColorSecondaryInverse(ATHUtils.resolveColor(mContext, colorAttr)) } override fun backgroundColor(color: Int): ThemeStore { @@ -179,7 +179,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt // Static getters @CheckResult - protected fun prefs(context: Context): SharedPreferences { + internal fun prefs(context: Context): SharedPreferences { return context.getSharedPreferences(ThemeStorePrefKeys.CONFIG_PREFS_KEY_DEFAULT, Context.MODE_PRIVATE) } @@ -192,7 +192,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt fun primaryColor(context: Context): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_PRIMARY_COLOR, - ATHUtil.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64")) + ATHUtils.resolveColor(context, R.attr.colorPrimary, Color.parseColor("#455A64")) ) } @@ -201,7 +201,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt fun primaryColorDark(context: Context): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_PRIMARY_COLOR_DARK, - ATHUtil.resolveColor(context, R.attr.colorPrimaryDark, Color.parseColor("#37474F")) + ATHUtils.resolveColor(context, R.attr.colorPrimaryDark, Color.parseColor("#37474F")) ) } @@ -210,7 +210,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt fun accentColor(context: Context): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_ACCENT_COLOR, - ATHUtil.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238")) + ATHUtils.resolveColor(context, R.attr.colorAccent, Color.parseColor("#263238")) ) } @@ -235,7 +235,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt fun textColorPrimary(context: Context): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY, - ATHUtil.resolveColor(context, android.R.attr.textColorPrimary) + ATHUtils.resolveColor(context, android.R.attr.textColorPrimary) ) } @@ -244,7 +244,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt fun textColorPrimaryInverse(context: Context): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY_INVERSE, - ATHUtil.resolveColor(context, android.R.attr.textColorPrimaryInverse) + ATHUtils.resolveColor(context, android.R.attr.textColorPrimaryInverse) ) } @@ -253,7 +253,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt fun textColorSecondary(context: Context): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY, - ATHUtil.resolveColor(context, android.R.attr.textColorSecondary) + ATHUtils.resolveColor(context, android.R.attr.textColorSecondary) ) } @@ -262,7 +262,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt fun textColorSecondaryInverse(context: Context): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY_INVERSE, - ATHUtil.resolveColor(context, android.R.attr.textColorSecondaryInverse) + ATHUtils.resolveColor(context, android.R.attr.textColorSecondaryInverse) ) } @@ -271,7 +271,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt fun backgroundColor(context: Context): Int { return prefs(context).getInt( ThemeStorePrefKeys.KEY_BACKGROUND_COLOR, - ATHUtil.resolveColor(context, android.R.attr.colorBackground) + ATHUtils.resolveColor(context, android.R.attr.colorBackground) ) } diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt index abe73d828..4fd4540fc 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt @@ -6,26 +6,26 @@ package io.legado.app.lib.theme internal interface ThemeStorePrefKeys { companion object { - val CONFIG_PREFS_KEY_DEFAULT = "app_themes" - val IS_CONFIGURED_KEY = "is_configured" - val IS_CONFIGURED_VERSION_KEY = "is_configured_version" - val VALUES_CHANGED = "values_changed" + const val CONFIG_PREFS_KEY_DEFAULT = "app_themes" + const val IS_CONFIGURED_KEY = "is_configured" + const val IS_CONFIGURED_VERSION_KEY = "is_configured_version" + const val VALUES_CHANGED = "values_changed" - val KEY_PRIMARY_COLOR = "primary_color" - val KEY_PRIMARY_COLOR_DARK = "primary_color_dark" - val KEY_ACCENT_COLOR = "accent_color" - val KEY_STATUS_BAR_COLOR = "status_bar_color" - val KEY_NAVIGATION_BAR_COLOR = "navigation_bar_color" + const val KEY_PRIMARY_COLOR = "primary_color" + const val KEY_PRIMARY_COLOR_DARK = "primary_color_dark" + const val KEY_ACCENT_COLOR = "accent_color" + const val KEY_STATUS_BAR_COLOR = "status_bar_color" + const val KEY_NAVIGATION_BAR_COLOR = "navigation_bar_color" - val KEY_TEXT_COLOR_PRIMARY = "text_color_primary" - val KEY_TEXT_COLOR_PRIMARY_INVERSE = "text_color_primary_inverse" - val KEY_TEXT_COLOR_SECONDARY = "text_color_secondary" - val KEY_TEXT_COLOR_SECONDARY_INVERSE = "text_color_secondary_inverse" + const val KEY_TEXT_COLOR_PRIMARY = "text_color_primary" + const val KEY_TEXT_COLOR_PRIMARY_INVERSE = "text_color_primary_inverse" + const val KEY_TEXT_COLOR_SECONDARY = "text_color_secondary" + const val KEY_TEXT_COLOR_SECONDARY_INVERSE = "text_color_secondary_inverse" - val KEY_BACKGROUND_COLOR = "backgroundColor" + const val KEY_BACKGROUND_COLOR = "backgroundColor" - val KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar" - val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar" - val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark" + const val KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar" + const val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar" + const val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark" } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt index de2bf4164..215c16892 100644 --- a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt @@ -46,13 +46,13 @@ object TintHelper { } fun setTintSelector(view: View, @ColorInt color: Int, darker: Boolean, useDarkTheme: Boolean) { - val isColorLight = ColorUtil.isColorLight(color) + val isColorLight = ColorUtils.isColorLight(color) val disabled = ContextCompat.getColor( view.context, if (useDarkTheme) R.color.ate_button_disabled_dark else R.color.ate_button_disabled_light ) - val pressed = ColorUtil.shiftColor(color, if (darker) 0.9f else 1.1f) - val activated = ColorUtil.shiftColor(color, if (darker) 1.1f else 0.9f) + val pressed = ColorUtils.shiftColor(color, if (darker) 0.9f else 1.1f) + val activated = ColorUtils.shiftColor(color, if (darker) 1.1f else 0.9f) val rippleColor = getDefaultRippleColor(view.context, isColorLight) val textColor = ContextCompat.getColor( view.context, @@ -107,7 +107,7 @@ object TintHelper { var drawable: Drawable? = view.background if (drawable != null) { drawable = createTintedDrawable(drawable, sl) - ViewUtil.setBackgroundCompat(view, drawable) + ViewUtils.setBackgroundCompat(view, drawable) } if (view is TextView && view !is Button) { @@ -127,7 +127,7 @@ object TintHelper { view: View, @ColorInt color: Int, background: Boolean ) { - setTintAuto(view, color, background, ATHUtil.isWindowBackgroundDark(view.context)) + setTintAuto(view, color, background, ATHUtils.isWindowBackgroundDark(view.context)) } fun setTintAuto( @@ -175,7 +175,7 @@ object TintHelper { view.context, if (isDark) R.color.ripple_material_dark else R.color.ripple_material_light ) - val checked = ColorUtil.adjustAlpha(color, 0.4f) + val checked = ColorUtils.adjustAlpha(color, 0.4f) val sl = ColorStateList( arrayOf( intArrayOf(-android.R.attr.state_activated, -android.R.attr.state_checked), @@ -195,7 +195,7 @@ object TintHelper { var drawable: Drawable? = view.background if (drawable != null) { drawable = createTintedDrawable(drawable, color) - ViewUtil.setBackgroundCompat(view, drawable) + ViewUtils.setBackgroundCompat(view, drawable) } } } @@ -209,7 +209,7 @@ object TintHelper { intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked) ), intArrayOf( // Rdio button includes own alpha for disabled state - ColorUtil.stripAlpha( + ColorUtils.stripAlpha( ContextCompat.getColor( radioButton.context, if (useDarker) R.color.ate_control_disabled_dark else R.color.ate_control_disabled_light @@ -335,9 +335,9 @@ object TintHelper { ): Drawable? { var tint = tint if (useDarker) { - tint = ColorUtil.shiftColor(tint, 1.1f) + tint = ColorUtils.shiftColor(tint, 1.1f) } - tint = ColorUtil.adjustAlpha(tint, if (compatSwitch && !thumb) 0.5f else 1.0f) + tint = ColorUtils.adjustAlpha(tint, if (compatSwitch && !thumb) 0.5f else 1.0f) val disabled: Int var normal: Int if (thumb) { @@ -362,7 +362,7 @@ object TintHelper { // Stock switch includes its own alpha if (!compatSwitch) { - normal = ColorUtil.stripAlpha(normal) + normal = ColorUtils.stripAlpha(normal) } val sl = ColorStateList( diff --git a/app/src/main/java/io/legado/app/lib/theme/ViewUtil.kt b/app/src/main/java/io/legado/app/lib/theme/ViewUtils.kt similarity index 85% rename from app/src/main/java/io/legado/app/lib/theme/ViewUtil.kt rename to app/src/main/java/io/legado/app/lib/theme/ViewUtils.kt index 7b2e69451..f3afa243c 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ViewUtil.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ViewUtils.kt @@ -10,7 +10,7 @@ import androidx.annotation.ColorInt /** * @author Karim Abou Zeid (kabouzeid) */ -object ViewUtil { +object ViewUtils { fun removeOnGlobalLayoutListener(v: View, listener: ViewTreeObserver.OnGlobalLayoutListener) { v.viewTreeObserver.removeOnGlobalLayoutListener(listener) @@ -21,7 +21,7 @@ object ViewUtil { } fun setBackgroundTransition(view: View, newDrawable: Drawable): TransitionDrawable { - val transition = DrawableUtil.createTransitionDrawable(view.background, newDrawable) + val transition = DrawableUtils.createTransitionDrawable(view.background, newDrawable) setBackgroundCompat(view, transition) return transition } @@ -32,7 +32,7 @@ object ViewUtil { val start = oldColor ?: ColorDrawable(view.solidColor) val end = ColorDrawable(newColor) - val transition = DrawableUtil.createTransitionDrawable(start, end) + val transition = DrawableUtils.createTransitionDrawable(start, end) setBackgroundCompat(view, transition) diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEAccentBgTextView.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEAccentBgTextView.kt index ae66905dd..fbc849d6c 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATEAccentBgTextView.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEAccentBgTextView.kt @@ -4,7 +4,7 @@ import android.content.Context import android.graphics.Color import android.util.AttributeSet import androidx.appcompat.widget.AppCompatTextView -import io.legado.app.lib.theme.ColorUtil +import io.legado.app.lib.theme.ColorUtils import io.legado.app.lib.theme.Selector import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.dp @@ -26,7 +26,7 @@ class ATEAccentBgTextView : AppCompatTextView { background = Selector.shapeBuild() .setCornerRadius(3.dp) .setDefaultBgColor(ThemeStore.accentColor(context)) - .setPressedBgColor(ColorUtil.darkenColor(ThemeStore.accentColor(context))) + .setPressedBgColor(ColorUtils.darkenColor(ThemeStore.accentColor(context))) .create() setTextColor(Color.WHITE) } diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEStockSwitch.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEStockSwitch.kt index a22f3ee47..d80e3a766 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATEStockSwitch.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEStockSwitch.kt @@ -4,13 +4,14 @@ import android.content.Context import android.util.AttributeSet import android.view.View import android.widget.Switch +import androidx.appcompat.widget.SwitchCompat import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ThemeStore /** * @author Aidan Follestad (afollestad) */ -class ATEStockSwitch : Switch { +class ATEStockSwitch : SwitchCompat { constructor(context: Context) : super(context) { init(context, null) diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt index 6a718559e..a27798055 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt @@ -4,13 +4,14 @@ import android.content.Context import android.util.AttributeSet import android.view.View import android.widget.Switch +import androidx.appcompat.widget.SwitchCompat import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ThemeStore /** * @author Aidan Follestad (afollestad) */ -class ATESwitch : Switch { +class ATESwitch : SwitchCompat { constructor(context: Context) : super(context) { init(context, null) diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index 16b48ec19..192fa5a8b 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -1,5 +1,5 @@ - - - - @@ -27,41 +29,54 @@ @color/colorPrimary @color/colorPrimaryDark @color/colorAccent - @style/PopupMenu - @style/MenuItemTextStyle - @style/PopupMenu + @style/Style.PopupMenu + @style/Style.MenuItemText + @style/Style.PopupMenu - + + - + + + + //**************************************************************System Style******************************************************************************// + - + + - - - - + //**************************************************************Widget Style******************************************************************************// - - - - -