Fix swiping for hue bar

This commit is contained in:
Moez Bhatti
2018-03-26 00:34:02 -04:00
parent 6908fd2003
commit d244ed4acf
2 changed files with 11 additions and 7 deletions
@@ -79,14 +79,15 @@ class HSVPickerView @JvmOverloads constructor(context: Context, attrs: Attribute
var hueThumbX = 0f
hueBackground.setOnTouchListener { _, event ->
hueGroup.setOnTouchListener { _, event ->
setupBounds()
when (event.action) {
MotionEvent.ACTION_DOWN -> {
hueThumbX = event.x - event.rawX
}
MotionEvent.ACTION_MOVE -> {
hueThumb.x = (event.rawX + hueThumbX + hueThumb.width / 2).within(0f, width - hueThumb.width.toFloat())
hueThumb.x = (event.rawX + hueThumbX + hueThumb.width / 2).within(min, max)
}
else -> return@setOnTouchListener false
@@ -94,8 +95,8 @@ class HSVPickerView @JvmOverloads constructor(context: Context, attrs: Attribute
true
}
hueBackground.clipToOutline = true
hueBackground.setImageDrawable(GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, hues))
hueTrack.clipToOutline = true
hueTrack.setImageDrawable(GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, hues))
}
private fun setupBounds() {
@@ -52,18 +52,21 @@
tools:tint="@color/tools_theme" />
<FrameLayout
android:id="@+id/hueGroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingEnd="24dp"
android:paddingStart="24dp"
android:paddingTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/saturation"
app:layout_constraintStart_toStartOf="@id/saturation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/saturation">
<ImageView
android:id="@+id/hueBackground"
android:id="@+id/hueTrack"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center_vertical"