feat: 优化代码

pull/141/head
kunfei 5 years ago
parent 56fdbd4d20
commit 98135941e6
  1. 2
      app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt
  2. 12
      app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt
  3. 18
      app/src/main/java/io/legado/app/ui/widget/text/StrokeTextView.kt
  4. 18
      app/src/main/res/layout/dialog_read_book_style.xml
  5. 4
      app/src/main/res/values/attrs.xml

@ -38,7 +38,7 @@ class LabelsBar(context: Context, attrs: AttributeSet?) : LinearLayout(context,
val tv = if (unUsedViews.isEmpty()) { val tv = if (unUsedViews.isEmpty()) {
AccentBgTextView(context, null).apply { AccentBgTextView(context, null).apply {
setPadding(3.dp, 0, 3.dp, 0) setPadding(3.dp, 0, 3.dp, 0)
setRadios(2) setRadius(2)
val lp = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) val lp = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
lp.setMargins(0, 0, 2.dp, 0) lp.setMargins(0, 0, 2.dp, 0)
layoutParams = lp layoutParams = lp

@ -14,31 +14,31 @@ import io.legado.app.utils.getCompatColor
class AccentBgTextView(context: Context, attrs: AttributeSet?) : class AccentBgTextView(context: Context, attrs: AttributeSet?) :
AppCompatTextView(context, attrs) { AppCompatTextView(context, attrs) {
private var radios = 0 private var radius = 0
init { init {
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.AccentBgTextView) val typedArray = context.obtainStyledAttributes(attrs, R.styleable.AccentBgTextView)
radios = typedArray.getDimensionPixelOffset(R.styleable.AccentBgTextView_radius, radios) radius = typedArray.getDimensionPixelOffset(R.styleable.AccentBgTextView_radius, radius)
typedArray.recycle() typedArray.recycle()
upBackground() upBackground()
setTextColor(Color.WHITE) setTextColor(Color.WHITE)
} }
fun setRadios(radio: Int) { fun setRadius(radius: Int) {
this.radios = radio.dp this.radius = radius.dp
upBackground() upBackground()
} }
private fun upBackground() { private fun upBackground() {
background = if (isInEditMode) { background = if (isInEditMode) {
Selector.shapeBuild() Selector.shapeBuild()
.setCornerRadius(radios) .setCornerRadius(radius)
.setDefaultBgColor(context.getCompatColor(R.color.colorAccent)) .setDefaultBgColor(context.getCompatColor(R.color.colorAccent))
.setPressedBgColor(ColorUtils.darkenColor(context.getCompatColor(R.color.colorAccent))) .setPressedBgColor(ColorUtils.darkenColor(context.getCompatColor(R.color.colorAccent)))
.create() .create()
} else { } else {
Selector.shapeBuild() Selector.shapeBuild()
.setCornerRadius(radios) .setCornerRadius(radius)
.setDefaultBgColor(ThemeStore.accentColor(context)) .setDefaultBgColor(ThemeStore.accentColor(context))
.setPressedBgColor(ColorUtils.darkenColor(ThemeStore.accentColor(context))) .setPressedBgColor(ColorUtils.darkenColor(ThemeStore.accentColor(context)))
.create() .create()

@ -12,10 +12,24 @@ import io.legado.app.utils.getCompatColor
open class StrokeTextView(context: Context, attrs: AttributeSet?) : open class StrokeTextView(context: Context, attrs: AttributeSet?) :
AppCompatTextView(context, attrs) { AppCompatTextView(context, attrs) {
private var radius = 1.dp
init { init {
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.StrokeTextView)
radius = typedArray.getDimensionPixelOffset(R.styleable.StrokeTextView_radius, radius)
typedArray.recycle()
upBackground()
}
fun setRadius(radius: Int) {
this.radius = radius.dp
upBackground()
}
private fun upBackground() {
if (isInEditMode) { if (isInEditMode) {
background = Selector.shapeBuild() background = Selector.shapeBuild()
.setCornerRadius(1.dp) .setCornerRadius(radius)
.setStrokeWidth(1.dp) .setStrokeWidth(1.dp)
.setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500))
.setDefaultStrokeColor(context.getCompatColor(R.color.tv_text_secondary)) .setDefaultStrokeColor(context.getCompatColor(R.color.tv_text_secondary))
@ -31,7 +45,7 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) :
) )
} else { } else {
background = Selector.shapeBuild() background = Selector.shapeBuild()
.setCornerRadius(1.dp) .setCornerRadius(radius)
.setStrokeWidth(1.dp) .setStrokeWidth(1.dp)
.setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500))
.setDefaultStrokeColor(ThemeStore.textColorSecondary(context)) .setDefaultStrokeColor(ThemeStore.textColorSecondary(context))

@ -29,7 +29,8 @@
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:text="@string/title" android:text="@string/title"
android:gravity="center" android:gravity="center"
android:textSize="14sp" /> android:textSize="14sp"
app:radius="3dp" />
<Space <Space
android:layout_width="0dp" android:layout_width="0dp"
@ -46,7 +47,8 @@
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:text="@string/text_bold" android:text="@string/text_bold"
android:gravity="center" android:gravity="center"
android:textSize="14sp" /> android:textSize="14sp"
app:radius="3dp" />
<Space <Space
android:layout_width="0dp" android:layout_width="0dp"
@ -63,7 +65,8 @@
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:text="@string/text_font" android:text="@string/text_font"
android:gravity="center" android:gravity="center"
android:textSize="14sp" /> android:textSize="14sp"
app:radius="3dp" />
<Space <Space
android:layout_width="0dp" android:layout_width="0dp"
@ -80,7 +83,8 @@
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:text="@string/text_indent" android:text="@string/text_indent"
android:gravity="center" android:gravity="center"
android:textSize="14sp" /> android:textSize="14sp"
app:radius="3dp" />
<Space <Space
android:layout_width="0dp" android:layout_width="0dp"
@ -96,7 +100,8 @@
android:paddingTop="4dp" android:paddingTop="4dp"
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:gravity="center" android:gravity="center"
android:textSize="14sp" /> android:textSize="14sp"
app:radius="3dp" />
<Space <Space
android:layout_width="0dp" android:layout_width="0dp"
@ -113,7 +118,8 @@
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:text="@string/padding" android:text="@string/padding"
android:gravity="center" android:gravity="center"
android:textSize="14sp" /> android:textSize="14sp"
app:radius="3dp" />
<Space <Space
android:layout_width="0dp" android:layout_width="0dp"

@ -159,6 +159,10 @@
<attr name="radius" /> <attr name="radius" />
</declare-styleable> </declare-styleable>
<declare-styleable name="StrokeTextView">
<attr name="radius" />
</declare-styleable>
<declare-styleable name="BadgeView"> <declare-styleable name="BadgeView">
<attr name="radius" /> <attr name="radius" />
<attr name="up_flat_angle" format="boolean" /> <attr name="up_flat_angle" format="boolean" />

Loading…
Cancel
Save