forked from upstream-mirrors/quik
Restrict swatch to bounds of SL picker
This commit is contained in:
@@ -34,4 +34,8 @@ fun Int.forEach(action: (Int) -> Unit) {
|
||||
for (index in 0 until this) {
|
||||
action(index)
|
||||
}
|
||||
}
|
||||
|
||||
fun Float.within(min: Float, max: Float): Float {
|
||||
return Math.min(max, Math.max(min, this))
|
||||
}
|
||||
@@ -25,7 +25,9 @@ import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import common.base.QkThemedActivity
|
||||
import common.util.extensions.dpToPx
|
||||
import common.util.extensions.setBackgroundTint
|
||||
import common.util.extensions.within
|
||||
import injection.appComponent
|
||||
import kotlinx.android.synthetic.main.theme_picker_activity.*
|
||||
import kotlinx.android.synthetic.main.theme_picker_hsl.*
|
||||
@@ -40,6 +42,8 @@ class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePicke
|
||||
@Inject lateinit var themeAdapter: ThemeAdapter
|
||||
@Inject lateinit var themePagerAdapter: ThemePagerAdapter
|
||||
|
||||
private val swatchPadding by lazy { 18.dpToPx(this) }
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
@@ -70,22 +74,17 @@ class ThemePickerActivity : QkThemedActivity<ThemePickerViewModel>(), ThemePicke
|
||||
hue.setOnTouchListener { _, event ->
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
dX = swatch.x - event.rawX
|
||||
dY = swatch.y - event.rawY
|
||||
|
||||
swatch.animate()
|
||||
.x(event.rawX + dX)
|
||||
.y(event.rawY + dY)
|
||||
.setDuration(0)
|
||||
.start()
|
||||
dX = event.x - event.rawX
|
||||
dY = event.y - event.rawY
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE ->
|
||||
swatch.animate()
|
||||
.x(event.rawX + dX)
|
||||
.y(event.rawY + dY)
|
||||
.setDuration(0)
|
||||
.start()
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
val min = hue.x - swatch.width / 2
|
||||
val max = min + hue.width
|
||||
|
||||
swatch.x = (event.rawX + dX + swatchPadding).within(min, max)
|
||||
swatch.y = (event.rawY + dY + swatchPadding).within(min, max)
|
||||
}
|
||||
|
||||
else -> return@setOnTouchListener false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user