From 369663073e3d67568b3871c38db5cb3d60d04d37 Mon Sep 17 00:00:00 2001 From: GKF Date: Thu, 30 May 2019 16:16:11 +0800 Subject: [PATCH] Theme View --- .../lib/theme/prefs/ATEPreferenceCategory.kt | 36 +++++++ .../lib/theme/prefs/ATESwitchPreference.kt | 52 ++++++++++ .../app/lib/theme/prefs/IconListPreference.kt | 95 +++++++++++++++++++ .../app/lib/theme/view/ATEAccentBgTextView.kt | 33 +++++++ .../lib/theme/view/ATEAccentStrokeTextView.kt | 39 ++++++++ .../lib/theme/view/ATEAutoCompleteTextView.kt | 33 +++++++ .../legado/app/lib/theme/view/ATECheckBox.kt | 29 ++++++ .../legado/app/lib/theme/view/ATEEditText.kt | 29 ++++++ .../app/lib/theme/view/ATEPrimaryTextView.kt | 28 ++++++ .../app/lib/theme/view/ATEProgressBar.kt | 41 ++++++++ .../app/lib/theme/view/ATERadioButton.kt | 29 ++++++ .../app/lib/theme/view/ATERadioNoButton.kt | 37 ++++++++ .../lib/theme/view/ATESecondaryTextView.kt | 28 ++++++ .../legado/app/lib/theme/view/ATESeekBar.kt | 29 ++++++ .../app/lib/theme/view/ATEStockSwitch.kt | 34 +++++++ .../app/lib/theme/view/ATEStrokeTextView.kt | 41 ++++++++ .../io/legado/app/lib/theme/view/ATESwitch.kt | 34 +++++++ .../app/lib/theme/view/ATETextInputLayout.kt | 31 ++++++ .../io/legado/app/utils/FloatExtensions.kt | 16 ++++ .../java/io/legado/app/utils/IntExtensions.kt | 13 +++ .../main/res/layout/item_icon_preference.xml | 31 ++++++ app/src/main/res/layout/view_icon.xml | 5 + app/src/main/res/values/attrs.xml | 56 ++++++++++- 23 files changed, 798 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/legado/app/lib/theme/prefs/ATEPreferenceCategory.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/prefs/ATESwitchPreference.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/prefs/IconListPreference.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATEAccentBgTextView.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATEAccentStrokeTextView.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATECheckBox.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATEEditText.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATEPrimaryTextView.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATEProgressBar.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATERadioButton.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATERadioNoButton.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATESecondaryTextView.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATEStockSwitch.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATEStrokeTextView.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt create mode 100644 app/src/main/java/io/legado/app/lib/theme/view/ATETextInputLayout.kt create mode 100644 app/src/main/java/io/legado/app/utils/FloatExtensions.kt create mode 100644 app/src/main/java/io/legado/app/utils/IntExtensions.kt create mode 100644 app/src/main/res/layout/item_icon_preference.xml create mode 100644 app/src/main/res/layout/view_icon.xml diff --git a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEPreferenceCategory.kt b/app/src/main/java/io/legado/app/lib/theme/prefs/ATEPreferenceCategory.kt new file mode 100644 index 000000000..2029744ed --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/prefs/ATEPreferenceCategory.kt @@ -0,0 +1,36 @@ +package io.legado.app.lib.theme.prefs + +import android.content.Context +import android.os.Build +import android.preference.PreferenceCategory +import android.util.AttributeSet +import android.view.View +import android.widget.TextView +import androidx.annotation.RequiresApi +import io.legado.app.lib.theme.ThemeStore + + +class ATEPreferenceCategory : PreferenceCategory { + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super( + context, + attrs, + defStyleAttr, + defStyleRes + ) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + + constructor(context: Context) : super(context) + + override fun onBindView(view: View) { + super.onBindView(view) + if (view is TextView) { + view.setTextColor(ThemeStore.accentColor(view.getContext()))//设置title文本的颜色 + } + } + +} diff --git a/app/src/main/java/io/legado/app/lib/theme/prefs/ATESwitchPreference.kt b/app/src/main/java/io/legado/app/lib/theme/prefs/ATESwitchPreference.kt new file mode 100644 index 000000000..8d3ca5f56 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/prefs/ATESwitchPreference.kt @@ -0,0 +1,52 @@ +package io.legado.app.lib.theme.prefs + +import android.content.Context +import android.os.Build +import android.preference.SwitchPreference +import android.util.AttributeSet +import android.view.View +import android.view.ViewGroup +import android.widget.Switch +import androidx.annotation.RequiresApi +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.ThemeStore +import java.util.* + +class ATESwitchPreference : SwitchPreference { + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super( + context, + attrs, + defStyleAttr, + defStyleRes + ) + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + + constructor(context: Context) : super(context) + + override fun onBindView(view: View) { + super.onBindView(view) + + if (view is ViewGroup) { + val queue = LinkedList() + queue.add(view) + while (!queue.isEmpty()) { + val current = queue.removeFirst() + for (i in 0 until current.childCount) { + if (current.getChildAt(i) is Switch) { + ATH.setTint(current.getChildAt(i), ThemeStore.accentColor(view.getContext())) + return + } else if (current.getChildAt(i) is ViewGroup) { + queue.addLast(current.getChildAt(i) as ViewGroup) + } + } + } + } + + } + +} diff --git a/app/src/main/java/io/legado/app/lib/theme/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/lib/theme/prefs/IconListPreference.kt new file mode 100644 index 000000000..f1389a989 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/prefs/IconListPreference.kt @@ -0,0 +1,95 @@ +package io.legado.app.lib.theme.prefs + +import android.annotation.SuppressLint +import android.app.Activity +import android.app.AlertDialog.Builder +import android.content.Context +import android.graphics.drawable.Drawable +import android.preference.ListPreference +import android.util.AttributeSet +import android.view.View +import android.view.ViewGroup +import android.widget.ArrayAdapter +import android.widget.CheckedTextView +import android.widget.ImageView +import android.widget.ListAdapter +import io.legado.app.R +import java.util.* + + +class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { + + private val mEntryDrawables = ArrayList() + + init { + + val a = context.theme.obtainStyledAttributes(attrs, R.styleable.IconListPreference, 0, 0) + + val drawables: Array + + try { + drawables = a.getTextArray(R.styleable.IconListPreference_icons) + } finally { + a.recycle() + } + + for (drawable in drawables) { + val resId = context.resources.getIdentifier(drawable.toString(), "mipmap", context.packageName) + + val d = context.resources.getDrawable(resId) + + mEntryDrawables.add(d) + } + + widgetLayoutResource = R.layout.view_icon + } + + protected fun createListAdapter(): ListAdapter { + val selectedValue = value + val selectedIndex = findIndexOfValue(selectedValue) + return AppArrayAdapter(context, R.layout.item_icon_preference, entries, mEntryDrawables, selectedIndex) + } + + override fun onBindView(view: View) { + super.onBindView(view) + + val selectedValue = value + val selectedIndex = findIndexOfValue(selectedValue) + + val drawable = mEntryDrawables[selectedIndex] + + (view.findViewById(R.id.preview) as ImageView).setImageDrawable(drawable) + } + + override fun onPrepareDialogBuilder(builder: Builder) { + builder.setAdapter(createListAdapter(), this) + super.onPrepareDialogBuilder(builder) + } + + inner class AppArrayAdapter( + context: Context, textViewResourceId: Int, + objects: Array, imageDrawables: List, + selectedIndex: Int + ) : ArrayAdapter(context, textViewResourceId, objects) { + private var mImageDrawables: List? = null + private var mSelectedIndex = 0 + + init { + mSelectedIndex = selectedIndex + mImageDrawables = imageDrawables + } + + @SuppressLint("ViewHolder") + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + val inflater = (context as Activity).layoutInflater + val view = inflater.inflate(R.layout.item_icon_preference, parent, false) + val textView = view.findViewById(R.id.label) as CheckedTextView + textView.text = getItem(position) + textView.isChecked = position == mSelectedIndex + + val imageView = view.findViewById(R.id.icon) as ImageView + imageView.setImageDrawable(mImageDrawables!![position]) + return view + } + } +} 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 new file mode 100644 index 000000000..ae66905dd --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEAccentBgTextView.kt @@ -0,0 +1,33 @@ +package io.legado.app.lib.theme.view + +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.Selector +import io.legado.app.lib.theme.ThemeStore +import io.legado.app.utils.dp + +class ATEAccentBgTextView : AppCompatTextView { + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + background = Selector.shapeBuild() + .setCornerRadius(3.dp) + .setDefaultBgColor(ThemeStore.accentColor(context)) + .setPressedBgColor(ColorUtil.darkenColor(ThemeStore.accentColor(context))) + .create() + setTextColor(Color.WHITE) + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEAccentStrokeTextView.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEAccentStrokeTextView.kt new file mode 100644 index 000000000..def0146f3 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEAccentStrokeTextView.kt @@ -0,0 +1,39 @@ +package io.legado.app.lib.theme.view + +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.utils.dp + +class ATEAccentStrokeTextView : AppCompatTextView { + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + background = Selector.shapeBuild() + .setCornerRadius(3.dp) + .setStrokeWidth(1.dp) + .setDisabledStrokeColor(context.resources.getColor(R.color.md_grey_500)) + .setDefaultStrokeColor(ThemeStore.accentColor(context)) + .setPressedBgColor(context.resources.getColor(R.color.transparent30)) + .create() + setTextColor( + Selector.colorBuild() + .setDefaultColor(ThemeStore.accentColor(context)) + .setDisabledColor(context.resources.getColor(R.color.md_grey_500)) + .create() + ) + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt new file mode 100644 index 000000000..4a4688fbb --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt @@ -0,0 +1,33 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.os.Build +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatAutoCompleteTextView +import io.legado.app.lib.theme.Selector +import io.legado.app.lib.theme.ThemeStore + + +class ATEAutoCompleteTextView : AppCompatAutoCompleteTextView { + + constructor(context: Context) : super(context) { + init(context) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context) + } + + private fun init(context: Context) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + backgroundTintList = Selector.colorBuild() + .setFocusedColor(ThemeStore.accentColor(context)) + .setDefaultColor(ThemeStore.textColorPrimary(context)) + .create() + } + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATECheckBox.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATECheckBox.kt new file mode 100644 index 000000000..15e3b5f14 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATECheckBox.kt @@ -0,0 +1,29 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatCheckBox +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.ThemeStore + +/** + * @author Aidan Follestad (afollestad) + */ +class ATECheckBox : AppCompatCheckBox { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + ATH.setTint(this, ThemeStore.accentColor(context)) + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEEditText.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEEditText.kt new file mode 100644 index 000000000..c70ea4eda --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEEditText.kt @@ -0,0 +1,29 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatEditText +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.ThemeStore + +/** + * @author Aidan Follestad (afollestad) + */ +class ATEEditText : AppCompatEditText { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + ATH.setTint(this, ThemeStore.accentColor(context)) + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEPrimaryTextView.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEPrimaryTextView.kt new file mode 100644 index 000000000..b39385688 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEPrimaryTextView.kt @@ -0,0 +1,28 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatTextView +import io.legado.app.lib.theme.ThemeStore + +/** + * @author Aidan Follestad (afollestad) + */ +class ATEPrimaryTextView : AppCompatTextView { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + setTextColor(ThemeStore.textColorPrimary(context)) + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEProgressBar.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEProgressBar.kt new file mode 100644 index 000000000..3a1809f16 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEProgressBar.kt @@ -0,0 +1,41 @@ +package io.legado.app.lib.theme.view + +import android.annotation.TargetApi +import android.content.Context +import android.os.Build +import android.util.AttributeSet +import android.widget.ProgressBar +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.ThemeStore + +/** + * @author Aidan Follestad (afollestad) + */ +class ATEProgressBar : ProgressBar { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super( + context, + attrs, + defStyleAttr, + defStyleRes + ) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + ATH.setTint(this, ThemeStore.accentColor(context)) + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATERadioButton.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATERadioButton.kt new file mode 100644 index 000000000..583d5e054 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATERadioButton.kt @@ -0,0 +1,29 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatRadioButton +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.ThemeStore + +/** + * @author Aidan Follestad (afollestad) + */ +class ATERadioButton : AppCompatRadioButton { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + ATH.setTint(this, ThemeStore.accentColor(context)) + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATERadioNoButton.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATERadioNoButton.kt new file mode 100644 index 000000000..138f05992 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATERadioNoButton.kt @@ -0,0 +1,37 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.graphics.Color +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatRadioButton +import io.legado.app.lib.theme.Selector +import io.legado.app.lib.theme.ThemeStore +import io.legado.app.utils.dp + +/** + * @author Aidan Follestad (afollestad) + */ +class ATERadioNoButton : AppCompatRadioButton { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + background = Selector.shapeBuild() + .setCornerRadius(3.dp) + .setStrokeWidth(3.dp) + .setCheckedBgColor(ThemeStore.accentColor(context)) + .setCheckedStrokeColor(ThemeStore.accentColor(context)) + .setDefaultStrokeColor(Color.WHITE) + .create() + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATESecondaryTextView.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATESecondaryTextView.kt new file mode 100644 index 000000000..dec5d938e --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATESecondaryTextView.kt @@ -0,0 +1,28 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatTextView +import io.legado.app.lib.theme.ThemeStore + +/** + * @author Aidan Follestad (afollestad) + */ +class ATESecondaryTextView : AppCompatTextView { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + setTextColor(ThemeStore.textColorSecondary(context)) + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt new file mode 100644 index 000000000..4a49b34f3 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATESeekBar.kt @@ -0,0 +1,29 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatSeekBar +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.ThemeStore + +/** + * @author Aidan Follestad (afollestad) + */ +class ATESeekBar : AppCompatSeekBar { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + ATH.setTint(this, ThemeStore.accentColor(context)) + } +} 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 new file mode 100644 index 000000000..a22f3ee47 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEStockSwitch.kt @@ -0,0 +1,34 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import android.widget.Switch +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.ThemeStore + +/** + * @author Aidan Follestad (afollestad) + */ +class ATEStockSwitch : Switch { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + ATH.setTint(this, ThemeStore.accentColor(context)) + } + + override fun isShown(): Boolean { + return parent != null && visibility == View.VISIBLE + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEStrokeTextView.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEStrokeTextView.kt new file mode 100644 index 000000000..ee6697224 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEStrokeTextView.kt @@ -0,0 +1,41 @@ +package io.legado.app.lib.theme.view + +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.utils.dp + +class ATEStrokeTextView : AppCompatTextView { + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + background = Selector.shapeBuild() + .setCornerRadius(1.dp) + .setStrokeWidth(1.dp) + .setDisabledStrokeColor(context.resources.getColor(R.color.md_grey_500)) + .setDefaultStrokeColor(ThemeStore.textColorSecondary(context)) + .setSelectedStrokeColor(ThemeStore.accentColor(context)) + .setPressedBgColor(context.resources.getColor(R.color.transparent30)) + .create() + setTextColor( + Selector.colorBuild() + .setDefaultColor(ThemeStore.textColorSecondary(context)) + .setSelectedColor(ThemeStore.accentColor(context)) + .setDisabledColor(context.resources.getColor(R.color.md_grey_500)) + .create() + ) + } +} 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 new file mode 100644 index 000000000..6a718559e --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATESwitch.kt @@ -0,0 +1,34 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import android.widget.Switch +import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.ThemeStore + +/** + * @author Aidan Follestad (afollestad) + */ +class ATESwitch : Switch { + + constructor(context: Context) : super(context) { + init(context, null) + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init(context, attrs) + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context, attrs) + } + + private fun init(context: Context, attrs: AttributeSet?) { + ATH.setTint(this, ThemeStore.accentColor(context)) + } + + override fun isShown(): Boolean { + return parent != null && visibility == View.VISIBLE + } +} diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATETextInputLayout.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATETextInputLayout.kt new file mode 100644 index 000000000..e09b03e2c --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATETextInputLayout.kt @@ -0,0 +1,31 @@ +package io.legado.app.lib.theme.view + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import com.google.android.material.textfield.TextInputLayout +import io.legado.app.lib.theme.Selector +import io.legado.app.lib.theme.ThemeStore + +class ATETextInputLayout : TextInputLayout { + constructor(context: Context) : super(context) { + init(context) + } + + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { + init(context) + } + + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(context) + } + + private fun init(context: Context) { + defaultHintTextColor = Selector.colorBuild().setDefaultColor(ThemeStore.accentColor(context)).create() + } + + override fun draw(canvas: Canvas) { + + super.draw(canvas) + } +} diff --git a/app/src/main/java/io/legado/app/utils/FloatExtensions.kt b/app/src/main/java/io/legado/app/utils/FloatExtensions.kt new file mode 100644 index 000000000..af9576c00 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/FloatExtensions.kt @@ -0,0 +1,16 @@ +package io.legado.app.utils + +import android.content.res.Resources + + +val Float.dp: Float // [xxhdpi](360 -> 1080) + get() = android.util.TypedValue.applyDimension( + android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics + ) + + +val Float.sp: Float // [xxhdpi](360 -> 1080) + get() = android.util.TypedValue.applyDimension( + android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics + ) + diff --git a/app/src/main/java/io/legado/app/utils/IntExtensions.kt b/app/src/main/java/io/legado/app/utils/IntExtensions.kt new file mode 100644 index 000000000..11946c14a --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/IntExtensions.kt @@ -0,0 +1,13 @@ +package io.legado.app.utils + +import android.content.res.Resources + +val Int.dp: Int + get() = android.util.TypedValue.applyDimension( + android.util.TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), Resources.getSystem().displayMetrics + ).toInt() + +val Int.sp: Int + get() = android.util.TypedValue.applyDimension( + android.util.TypedValue.COMPLEX_UNIT_SP, this.toFloat(), Resources.getSystem().displayMetrics + ).toInt() \ No newline at end of file diff --git a/app/src/main/res/layout/item_icon_preference.xml b/app/src/main/res/layout/item_icon_preference.xml new file mode 100644 index 000000000..a2063a71f --- /dev/null +++ b/app/src/main/res/layout/item_icon_preference.xml @@ -0,0 +1,31 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_icon.xml b/app/src/main/res/layout/view_icon.xml new file mode 100644 index 000000000..d0247c6ef --- /dev/null +++ b/app/src/main/res/layout/view_icon.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index fc861ecca..7bbabf7f6 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -44,5 +44,59 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file