Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Convert bindingAdapters to Java #90

Merged
merged 12 commits into from
Apr 14, 2022
Merged

Convert bindingAdapters to Java #90

merged 12 commits into from
Apr 14, 2022

Conversation

Goooler
Copy link
Owner

@Goooler Goooler commented Apr 14, 2022

Addressed from #89.

@Goooler Goooler merged commit 2170923 into trunk Apr 14, 2022
@Goooler Goooler deleted the binding_adapter branch April 14, 2022 08:49
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
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move into BaseExtensions

@Goooler Goooler added this to the 1.6.0 milestone Apr 14, 2022
Goooler added a commit that referenced this pull request Apr 30, 2022
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
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants