Merge pull request #70 from KKL369/master

BadgeView支持绘制成上平角
pull/71/head
kunfei 5 years ago committed by GitHub
commit 8214c0815c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/src/main/java/io/legado/app/ui/widget/BadgeView.kt
  2. 1
      app/src/main/res/layout/item_bookshelf_grid.xml
  3. 1
      app/src/main/res/values/attrs.xml

@ -36,6 +36,7 @@ class BadgeView @JvmOverloads constructor(
text = text text = text
} }
private var radius: Float = 0.toFloat() private var radius: Float = 0.toFloat()
private var flatangle: Boolean
val badgeCount: Int? val badgeCount: Int?
get() { get() {
@ -77,6 +78,8 @@ class BadgeView @JvmOverloads constructor(
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.BadgeView) val typedArray = context.obtainStyledAttributes(attrs, R.styleable.BadgeView)
val radios = val radios =
typedArray.getDimensionPixelOffset(R.styleable.BadgeView_bv_radius, 8) typedArray.getDimensionPixelOffset(R.styleable.BadgeView_bv_radius, 8)
flatangle =
typedArray.getBoolean(R.styleable.BadgeView_up_flat_angle, false)
typedArray.recycle() typedArray.recycle()
if (layoutParams !is LayoutParams) { if (layoutParams !is LayoutParams) {
@ -111,6 +114,7 @@ class BadgeView @JvmOverloads constructor(
val radius = dip2Px(dipRadius).toFloat() val radius = dip2Px(dipRadius).toFloat()
val radiusArray = val radiusArray =
floatArrayOf(radius, radius, radius, radius, radius, radius, radius, radius) floatArrayOf(radius, radius, radius, radius, radius, radius, radius, radius)
if (flatangle) { radiusArray.fill(0f, 0, 3) }
val roundRect = RoundRectShape(radiusArray, null, null) val roundRect = RoundRectShape(radiusArray, null, null)
val bgDrawable = ShapeDrawable(roundRect) val bgDrawable = ShapeDrawable(roundRect)

@ -56,6 +56,7 @@
android:includeFontPadding="false" android:includeFontPadding="false"
android:singleLine="true" android:singleLine="true"
app:bv_radius="1dp" app:bv_radius="1dp"
app:up_flat_angle="true"
app:layout_constraintLeft_toLeftOf="@id/iv_cover" app:layout_constraintLeft_toLeftOf="@id/iv_cover"
app:layout_constraintBottom_toBottomOf="@id/iv_cover" app:layout_constraintBottom_toBottomOf="@id/iv_cover"
tools:ignore="RtlHardcoded" /> tools:ignore="RtlHardcoded" />

@ -143,5 +143,6 @@
<declare-styleable name="BadgeView"> <declare-styleable name="BadgeView">
<attr name="bv_radius" format="dimension" /> <attr name="bv_radius" format="dimension" />
<attr name="up_flat_angle" format="boolean" />
</declare-styleable> </declare-styleable>
</resources> </resources>
Loading…
Cancel
Save