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()) {
AccentBgTextView(context, null).apply {
setPadding(3.dp, 0, 3.dp, 0)
setRadios(2)
setRadius(2)
val lp = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
lp.setMargins(0, 0, 2.dp, 0)
layoutParams = lp

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

@ -12,10 +12,24 @@ import io.legado.app.utils.getCompatColor
open class StrokeTextView(context: Context, attrs: AttributeSet?) :
AppCompatTextView(context, attrs) {
private var radius = 1.dp
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) {
background = Selector.shapeBuild()
.setCornerRadius(1.dp)
.setCornerRadius(radius)
.setStrokeWidth(1.dp)
.setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500))
.setDefaultStrokeColor(context.getCompatColor(R.color.tv_text_secondary))
@ -31,7 +45,7 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) :
)
} else {
background = Selector.shapeBuild()
.setCornerRadius(1.dp)
.setCornerRadius(radius)
.setStrokeWidth(1.dp)
.setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500))
.setDefaultStrokeColor(ThemeStore.textColorSecondary(context))

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

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

Loading…
Cancel
Save