This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Goooler
commented
Apr 14, 2022
Comment on lines
-279
to
-374
// ---------------------Private-------------------------------// | ||
|
||
/** | ||
* 设置 view 的背景,支持圆形和矩形,渐变色和描边圆角等 | ||
* | ||
* @param shapeType 背景形状,圆、矩形等 | ||
* @param gradualColors 渐变色数组,和填充色互斥 | ||
* @param angle 渐变色角度 | ||
* @param solidColor 填充色,和渐变色数组互斥 | ||
* @param strokeColor 描边色 | ||
* @param stroke 描边粗细 | ||
* @param radius 圆角大小 | ||
*/ | ||
private fun View.setBgShapeGradual( | ||
shapeType: Int = GradientDrawable.RECTANGLE, | ||
@ColorInt gradualColors: IntArray? = null, | ||
angle: Int = 0, | ||
@ColorInt solidColor: Int? = null, | ||
@ColorInt strokeColor: Int = Color.TRANSPARENT, | ||
@Px stroke: Float = 0f, | ||
@Px radius: Float = 0f | ||
) { | ||
background = GradientDrawable().apply { | ||
shape = shapeType | ||
useLevel = false | ||
gradientType = GradientDrawable.LINEAR_GRADIENT | ||
val remainder = angle % 45 | ||
val validAngle = if (remainder >= 22.5) { | ||
angle % 360 + 45 - remainder | ||
} else { | ||
angle % 360 - remainder | ||
} | ||
orientation = when (validAngle) { | ||
45 -> GradientDrawable.Orientation.BL_TR | ||
90 -> GradientDrawable.Orientation.BOTTOM_TOP | ||
135 -> GradientDrawable.Orientation.BR_TL | ||
180 -> GradientDrawable.Orientation.RIGHT_LEFT | ||
225 -> GradientDrawable.Orientation.TR_BL | ||
270 -> GradientDrawable.Orientation.TOP_BOTTOM | ||
315 -> GradientDrawable.Orientation.TL_BR | ||
else -> GradientDrawable.Orientation.LEFT_RIGHT | ||
} | ||
if (gradualColors != null && solidColor == null) { | ||
colors = gradualColors | ||
} else if (gradualColors == null && solidColor != null) { | ||
setColor(solidColor) | ||
} | ||
setStroke(stroke.toInt(), strokeColor) | ||
cornerRadius = radius | ||
} | ||
} | ||
|
||
/** | ||
* 设置 view 在矩形某几个角上需要圆角的背景 | ||
* | ||
* @param solidColor 填充色 | ||
* @param topLeft 左上圆角大小 | ||
* @param topRight 右上圆角大小 | ||
* @param bottomLeft 左下圆角大小 | ||
* @param bottomRight 左下圆角大小 | ||
*/ | ||
private fun View.setBgShapeCorners( | ||
@ColorInt solidColor: Int = Color.WHITE, | ||
@Px topLeft: Float = 0f, | ||
@Px topRight: Float = 0f, | ||
@Px bottomLeft: Float = 0f, | ||
@Px bottomRight: Float = 0f | ||
) { | ||
background = GradientDrawable().apply { | ||
shape = GradientDrawable.RECTANGLE | ||
setColor(solidColor) | ||
cornerRadii = floatArrayOf( | ||
topLeft, | ||
topLeft, | ||
topRight, | ||
topRight, | ||
bottomRight, | ||
bottomRight, | ||
bottomLeft, | ||
bottomLeft | ||
) | ||
} | ||
} | ||
|
||
private fun View.marginDirection(direction: Int, @Px margin: Float) { | ||
if (layoutParams is ViewGroup.MarginLayoutParams) { | ||
val p = layoutParams as ViewGroup.MarginLayoutParams | ||
when (direction) { | ||
0 -> p.marginStart = margin.toInt() | ||
1 -> p.topMargin = margin.toInt() | ||
2 -> p.marginEnd = margin.toInt() | ||
else -> p.bottomMargin = margin.toInt() | ||
} | ||
layoutParams = p | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move into BaseExtensions
Goooler
added a commit
that referenced
this pull request
Apr 30, 2022
* Disable dataBinding by default * Revert changes in #90
Goooler
added a commit
that referenced
this pull request
Apr 30, 2022
* Disable dataBinding by default * Revert changes in #90
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addressed from #89.