From f778e8dd2c85b3f443e6a51a800b1dbdf10ff288 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 15 Aug 2020 21:29:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/widget/DetailSeekBar.kt | 16 +++- .../app/ui/widget/prefs/NameListPreference.kt | 2 +- .../legado/app/ui/widget/prefs/Preference.kt | 8 +- .../app/ui/widget/prefs/SwitchPreference.kt | 2 +- .../app/ui/widget/text/StrokeTextView.kt | 88 ++++++++++++------- .../res/layout/dialog_read_book_style.xml | 11 +++ app/src/main/res/values/attrs.xml | 5 +- app/src/main/res/xml/pref_config_read.xml | 30 +++---- 8 files changed, 106 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt index 504837afd..5198599e4 100644 --- a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt @@ -6,13 +6,16 @@ import android.view.View import android.widget.FrameLayout import android.widget.SeekBar import io.legado.app.R +import io.legado.app.lib.theme.bottomBackground +import io.legado.app.lib.theme.getPrimaryTextColor +import io.legado.app.utils.ColorUtils import io.legado.app.utils.progressAdd import kotlinx.android.synthetic.main.view_detail_seek_bar.view.* import org.jetbrains.anko.sdk27.listeners.onClick class DetailSeekBar(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs), SeekBar.OnSeekBarChangeListener { - + private val isBottomBackground: Boolean var valueFormat: ((progress: Int) -> String)? = null var onChanged: ((progress: Int) -> Unit)? = null var progress: Int @@ -30,10 +33,19 @@ class DetailSeekBar(context: Context, attrs: AttributeSet?) : FrameLayout(contex View.inflate(context, R.layout.view_detail_seek_bar, this) val typedArray = context.obtainStyledAttributes(attrs, R.styleable.DetailSeekBar) + isBottomBackground = + typedArray.getBoolean(R.styleable.DetailSeekBar_isBottomBackground, false) tv_seek_title.text = typedArray.getText(R.styleable.DetailSeekBar_title) seek_bar.max = typedArray.getInteger(R.styleable.DetailSeekBar_max, 0) typedArray.recycle() - + if (isBottomBackground) { + val isLight = ColorUtils.isColorLight(context.bottomBackground) + val textColor = context.getPrimaryTextColor(isLight) + tv_seek_title.setTextColor(textColor) + iv_seek_plus.setColorFilter(textColor) + iv_seek_reduce.setColorFilter(textColor) + tv_seek_value.setTextColor(textColor) + } iv_seek_plus.onClick { seek_bar.progressAdd(1) onChanged?.invoke(seek_bar.progress) diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt index 100f7f25e..c83ea7433 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt @@ -19,7 +19,7 @@ class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference layoutResource = R.layout.view_preference widgetLayoutResource = R.layout.item_fillet_text val typedArray = context.obtainStyledAttributes(attrs, R.styleable.Preference) - isBottomBackground = typedArray.getBoolean(R.styleable.Preference_bottomBackground, false) + isBottomBackground = typedArray.getBoolean(R.styleable.Preference_isBottomBackground, false) typedArray.recycle() } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt index 731e6118b..7ce8c9dfb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt @@ -30,7 +30,7 @@ class Preference(context: Context, attrs: AttributeSet) : init { layoutResource = R.layout.view_preference val typedArray = context.obtainStyledAttributes(attrs, R.styleable.Preference) - isBottomBackground = typedArray.getBoolean(R.styleable.Preference_bottomBackground, false) + isBottomBackground = typedArray.getBoolean(R.styleable.Preference_isBottomBackground, false) typedArray.recycle() } @@ -58,10 +58,10 @@ class Preference(context: Context, attrs: AttributeSet) : tvSummary.isGone = summary.isNullOrEmpty() } if (isBottomBackground && !tvTitle.isInEditMode) { - val bgColor = context.bottomBackground - val pTextColor = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor)) + val isLight = ColorUtils.isColorLight(context.bottomBackground) + val pTextColor = context.getPrimaryTextColor(isLight) tvTitle.setTextColor(pTextColor) - val sTextColor = context.getSecondaryTextColor(ColorUtils.isColorLight(bgColor)) + val sTextColor = context.getSecondaryTextColor(isLight) tvSummary?.setTextColor(sTextColor) } val iconView = it.findViewById(R.id.preference_icon) diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt index 9946f6c48..3ff87e05b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt @@ -17,7 +17,7 @@ class SwitchPreference(context: Context, attrs: AttributeSet) : init { layoutResource = R.layout.view_preference val typedArray = context.obtainStyledAttributes(attrs, R.styleable.Preference) - isBottomBackground = typedArray.getBoolean(R.styleable.Preference_bottomBackground, false) + isBottomBackground = typedArray.getBoolean(R.styleable.Preference_isBottomBackground, false) typedArray.recycle() } diff --git a/app/src/main/java/io/legado/app/ui/widget/text/StrokeTextView.kt b/app/src/main/java/io/legado/app/ui/widget/text/StrokeTextView.kt index af32acda2..62f8f18f2 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/StrokeTextView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/StrokeTextView.kt @@ -4,8 +4,8 @@ import android.content.Context import android.util.AttributeSet import androidx.appcompat.widget.AppCompatTextView import io.legado.app.R -import io.legado.app.lib.theme.Selector -import io.legado.app.lib.theme.ThemeStore +import io.legado.app.lib.theme.* +import io.legado.app.utils.ColorUtils import io.legado.app.utils.dp import io.legado.app.utils.getCompatColor @@ -13,10 +13,13 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) : AppCompatTextView(context, attrs) { private var radius = 1.dp + private val isBottomBackground: Boolean init { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.StrokeTextView) radius = typedArray.getDimensionPixelOffset(R.styleable.StrokeTextView_radius, radius) + isBottomBackground = + typedArray.getBoolean(R.styleable.StrokeTextView_isBottomBackground, false) typedArray.recycle() upBackground() } @@ -27,38 +30,59 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) : } private fun upBackground() { - if (isInEditMode) { - background = Selector.shapeBuild() - .setCornerRadius(radius) - .setStrokeWidth(1.dp) - .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) - .setDefaultStrokeColor(context.getCompatColor(R.color.secondaryText)) - .setSelectedStrokeColor(context.getCompatColor(R.color.accent)) - .setPressedBgColor(context.getCompatColor(R.color.transparent30)) - .create() - this.setTextColor( - Selector.colorBuild() - .setDefaultColor(context.getCompatColor(R.color.secondaryText)) - .setSelectedColor(context.getCompatColor(R.color.accent)) - .setDisabledColor(context.getCompatColor(R.color.md_grey_500)) + when { + isInEditMode -> { + background = Selector.shapeBuild() + .setCornerRadius(radius) + .setStrokeWidth(1.dp) + .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) + .setDefaultStrokeColor(context.getCompatColor(R.color.secondaryText)) + .setSelectedStrokeColor(context.getCompatColor(R.color.accent)) + .setPressedBgColor(context.getCompatColor(R.color.transparent30)) .create() - ) - } else { - background = Selector.shapeBuild() - .setCornerRadius(radius) - .setStrokeWidth(1.dp) - .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) - .setDefaultStrokeColor(ThemeStore.textColorSecondary(context)) - .setSelectedStrokeColor(ThemeStore.accentColor(context)) - .setPressedBgColor(context.getCompatColor(R.color.transparent30)) - .create() - this.setTextColor( - Selector.colorBuild() - .setDefaultColor(ThemeStore.textColorSecondary(context)) - .setSelectedColor(ThemeStore.accentColor(context)) - .setDisabledColor(context.getCompatColor(R.color.md_grey_500)) + this.setTextColor( + Selector.colorBuild() + .setDefaultColor(context.getCompatColor(R.color.secondaryText)) + .setSelectedColor(context.getCompatColor(R.color.accent)) + .setDisabledColor(context.getCompatColor(R.color.md_grey_500)) + .create() + ) + } + isBottomBackground -> { + val isLight = ColorUtils.isColorLight(context.bottomBackground) + background = Selector.shapeBuild() + .setCornerRadius(radius) + .setStrokeWidth(1.dp) + .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) + .setDefaultStrokeColor(context.getPrimaryTextColor(isLight)) + .setSelectedStrokeColor(context.accentColor) + .setPressedBgColor(context.getCompatColor(R.color.transparent30)) .create() - ) + this.setTextColor( + Selector.colorBuild() + .setDefaultColor(context.getPrimaryTextColor(isLight)) + .setSelectedColor(context.accentColor) + .setDisabledColor(context.getCompatColor(R.color.md_grey_500)) + .create() + ) + } + else -> { + background = Selector.shapeBuild() + .setCornerRadius(radius) + .setStrokeWidth(1.dp) + .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) + .setDefaultStrokeColor(ThemeStore.textColorSecondary(context)) + .setSelectedStrokeColor(ThemeStore.accentColor(context)) + .setPressedBgColor(context.getCompatColor(R.color.transparent30)) + .create() + this.setTextColor( + Selector.colorBuild() + .setDefaultColor(ThemeStore.textColorSecondary(context)) + .setSelectedColor(ThemeStore.accentColor(context)) + .setDisabledColor(context.getCompatColor(R.color.md_grey_500)) + .create() + ) + } } } } diff --git a/app/src/main/res/layout/dialog_read_book_style.xml b/app/src/main/res/layout/dialog_read_book_style.xml index 86ab37604..513dd9eef 100644 --- a/app/src/main/res/layout/dialog_read_book_style.xml +++ b/app/src/main/res/layout/dialog_read_book_style.xml @@ -30,6 +30,7 @@ android:text="@string/title" android:gravity="center" android:textSize="14sp" + app:isBottomBackground="true" app:radius="3dp" /> @@ -161,6 +169,7 @@ android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp" + app:isBottomBackground="true" app:max="100" app:title="@string/text_letter_spacing" /> @@ -170,6 +179,7 @@ android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp" + app:isBottomBackground="true" app:max="20" app:title="@string/line_size" /> @@ -179,6 +189,7 @@ android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="10dp" + app:isBottomBackground="true" app:max="20" app:title="@string/paragraph_size" /> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 243d21b37..6f38b1549 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -2,6 +2,7 @@ + @@ -70,6 +71,7 @@ + @@ -161,6 +163,7 @@ + @@ -193,6 +196,6 @@ - + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 1effb1567..7e2da9c1c 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -9,7 +9,7 @@ android:entries="@array/screen_direction_title" android:entryValues="@array/screen_direction_value" app:iconSpaceReserved="false" - app:bottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> + app:isBottomBackground="true" /> \ No newline at end of file