diff --git a/.travis.yml b/.travis.yml
index f6867bd..99632cf 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,36 +1,37 @@
language: android
+dist: trusty
+
+notifications:
+ email:
+ - alessandro.crugnola@gmail.com
jdk:
- oraclejdk8
+env:
+ global:
+ - ANDROID_API_LEVEL=28
+ - ANDROID_BUILD_TOOLS_VERSION=28.0.3
+
android:
components:
- - tools
- - tools
- - build-tools-28.0.3
- - platform-tools
-
-before_script:
- - mkdir "$ANDROID_HOME/licenses" || true
- - echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license"
+ - tools
+ - platform-tools
+ - build-tools-$ANDROID_BUILD_TOOLS_VERSION
+ - android-$ANDROID_API_LEVEL
+ - extra-android-support
+ licenses:
+ - 'android-sdk-license-.+'
before_install:
- - yes | sdkmanager "platforms;android-28"
-
-notifications:
- email:
- - alessandro.crugnola@gmail.com
-
-cache: false
-sudo: false
-
-install:
- - chmod +x ./gradlew; ls -l gradlew; ./gradlew wrapper -v
+ - chmod +x gradlew
+ # https://github.com/travis-ci/travis-ci/issues/8874#issuecomment-350350607
+ - yes | sdkmanager "platforms;android-$ANDROID_API_LEVEL"
script:
- - ./gradlew clean build assemble
+ - ./gradlew build
-cache:
- directories:
- - $HOME/.m2
- - $HOME/.gradle
+branches:
+ only:
+ - master
+ language: android
diff --git a/README.md b/README.md
index 653dfb1..77e7826 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,23 @@
-Material Number Sliding Picker
-======================
+# Material Number Sliding Picker (Fork)
A widget that enables the user to select a number from a predefined range.
Progress value can be changed using the up and down arrows, click and edit the editable text or swiping up/down or left/right.
-![Screen shot](./art/video.gif)
+```gradle
+dependencies {
+ implementation 'com.github.guilhe:NumberSlidingPicker:-SNAPSHOT'
+}
+```
+
+
+
+[![Build Status](https://travis-ci.org/sephiroth74/NumberSlidingPicker.svg?branch=master)](https://travis-ci.org/sephiroth74/NumberSlidingPicker) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/it.sephiroth.android.library/number-sliding-picker/badge.svg)](https://maven-badges.herokuapp.com/maven-central/it.sephiroth.android.library/number-sliding-picker) [![](https://jitpack.io/v/sephiroth74/NumberSlidingPicker.svg)](https://jitpack.io/#sephiroth74/NumberSlidingPicker)
-[![Build Status](https://travis-ci.org/sephiroth74/NumberSlidingPicker.svg?branch=master)](https://travis-ci.org/sephiroth74/NumberSlidingPicker)
+# About this Fork
-[![Maven Central](https://maven-badges.herokuapp.com/maven-central/it.sephiroth.android.library/number-sliding-picker/badge.svg)](https://maven-badges.herokuapp.com/maven-central/it.sephiroth.android.library/number-sliding-picker)
-[![](https://jitpack.io/v/sephiroth74/NumberSlidingPicker.svg)](https://jitpack.io/#sephiroth74/NumberSlidingPicker)
+I've forked this project to remove _RxJava_ dependency since we can achieve the same result using coroutines.
-Installation
-===
+# Installation
## Maven
@@ -22,7 +27,7 @@ compile 'it.sephiroth.android.library:number-sliding-picker:**version**'
## JitPack
-**Step 1.** Add the JitPack repository to your build file:
+### Step 1. Add the JitPack repository to your build file:
```gradle
allprojects {
@@ -33,7 +38,7 @@ allprojects {
}
```
-**Step 2.** Add the dependency
+### Step 2. Add the dependency
```gradle
dependencies {
@@ -43,9 +48,7 @@ dependencies {
Get the latest version on [JitPack](https://jitpack.io/#sephiroth74/NumberSlidingPicker)
-
-Usage
-===
+# Usage
```xml
+
diff --git a/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPicker.kt b/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPicker.kt
index aade88f..ad83a99 100644
--- a/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPicker.kt
+++ b/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPicker.kt
@@ -16,26 +16,22 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.view.ContextThemeWrapper
import androidx.appcompat.widget.AppCompatImageButton
-import io.reactivex.Observable
-import io.reactivex.android.schedulers.AndroidSchedulers
-import io.reactivex.disposables.Disposable
-import io.reactivex.schedulers.Schedulers
import it.sephiroth.android.library.uigestures.*
import it.sephiroth.android.library.xtooltip.ClosePolicy
import it.sephiroth.android.library.xtooltip.Tooltip
+import kotlinx.coroutines.Job
import timber.log.Timber
-import java.util.concurrent.TimeUnit
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.math.sin
-
class NumberPicker @JvmOverloads constructor(
- context: Context,
- attrs: AttributeSet? = null,
- defStyleAttr: Int = R.attr.pickerStyle,
- defStyleRes: Int = R.style.NumberPicker_Filled) : LinearLayout(context, attrs, defStyleAttr, defStyleRes) {
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = R.attr.pickerStyle,
+ defStyleRes: Int = R.style.NumberPicker_Filled
+) : LinearLayout(context, attrs, defStyleAttr, defStyleRes) {
interface OnNumberPickerChangeListener {
fun onProgressChanged(numberPicker: NumberPicker, progress: Int, fromUser: Boolean)
@@ -64,16 +60,14 @@ class NumberPicker @JvmOverloads constructor(
private lateinit var data: Data
- private var callback = { newValue: Int ->
- setProgress(newValue)
- }
+ private var callback = { newValue: Int -> setProgress(newValue) }
- private var buttonInterval: Disposable? = null
+ private var buttonIntervalJob: Job? = null
private val longGestureListener = { it: UIGestureRecognizer ->
Timber.i("longGestureListener = ${it.state}")
- when {
- it.state == UIGestureRecognizer.State.Began -> {
+ when (it.state) {
+ UIGestureRecognizer.State.Began -> {
requestFocus()
editText.isSelected = false
editText.clearFocus()
@@ -81,15 +75,13 @@ class NumberPicker @JvmOverloads constructor(
tracker.begin(it.downLocationX, it.downLocationY)
startInteraction()
}
-
- it.state == UIGestureRecognizer.State.Ended -> {
+ UIGestureRecognizer.State.Ended -> {
tracker.end()
endInteraction()
}
-
- it.state == UIGestureRecognizer.State.Changed -> {
+ UIGestureRecognizer.State.Changed -> {
var diff =
- if (data.orientation == VERTICAL) it.currentLocationY - it.downLocationY else it.currentLocationX - it.downLocationX
+ if (data.orientation == VERTICAL) it.currentLocationY - it.downLocationY else it.currentLocationX - it.downLocationX
if (diff > tracker.minDistance) {
diff = tracker.minDistance
} else if (diff < -tracker.minDistance) {
@@ -99,20 +91,29 @@ class NumberPicker @JvmOverloads constructor(
tooltip?.let { tooltip ->
when (data.orientation) {
- VERTICAL -> tooltip.offsetTo(tooltip.offsetX, final2 / 2 * tracker.minDistance)
- HORIZONTAL -> tooltip.offsetTo(final2 / 2 * tracker.minDistance, tooltip.offsetY)
+ VERTICAL -> tooltip.offsetTo(
+ tooltip.offsetX,
+ final2 / 2 * tracker.minDistance
+ )
+ HORIZONTAL -> tooltip.offsetTo(
+ final2 / 2 * tracker.minDistance,
+ tooltip.offsetY
+ )
}
}
tracker.addMovement(it.currentLocationX, it.currentLocationY)
}
+ else -> {
+ }
}
}
private val tapGestureListener = { _: UIGestureRecognizer ->
requestFocus()
- if (!editText.isFocused)
+ if (!editText.isFocused) {
editText.requestFocus()
+ }
}
@Suppress("MemberVisibilityCanBePrivate")
@@ -121,10 +122,9 @@ class NumberPicker @JvmOverloads constructor(
if (value != data.value) {
data.value = value
tooltip?.update(data.value.toString())
-
- if (editText.text.toString() != data.value.toString())
+ if (editText.text.toString() != data.value.toString()) {
editText.setText(data.value.toString())
-
+ }
numberPickerChangeListener?.onProgressChanged(this, progress, fromUser)
}
}
@@ -151,8 +151,6 @@ class NumberPicker @JvmOverloads constructor(
data.stepSize = value
}
- private var initialized = false
-
init {
setWillNotDraw(false)
isFocusable = true
@@ -161,24 +159,38 @@ class NumberPicker @JvmOverloads constructor(
orientation = HORIZONTAL
gravity = Gravity.CENTER
- val array = context.theme.obtainStyledAttributes(attrs, R.styleable.NumberPicker, defStyleAttr, defStyleRes)
+ val array = context.theme.obtainStyledAttributes(
+ attrs,
+ R.styleable.NumberPicker,
+ defStyleAttr,
+ defStyleRes
+ )
try {
val maxValue = array.getInteger(R.styleable.NumberPicker_picker_max, 100)
val minValue = array.getInteger(R.styleable.NumberPicker_picker_min, 0)
val stepSize = array.getInteger(R.styleable.NumberPicker_picker_stepSize, 1)
- val orientation = array.getInteger(R.styleable.NumberPicker_picker_orientation, LinearLayout.VERTICAL)
+ val orientation =
+ array.getInteger(R.styleable.NumberPicker_picker_orientation, VERTICAL)
val value = array.getInteger(R.styleable.NumberPicker_android_progress, 0)
arrowStyle = array.getResourceId(R.styleable.NumberPicker_picker_arrowStyle, 0)
background = array.getDrawable(R.styleable.NumberPicker_android_background)
- editTextStyleId = array.getResourceId(R.styleable.NumberPicker_picker_editTextStyle, R.style.NumberPicker_EditTextStyle)
- tooltipStyleId = array.getResourceId(R.styleable.NumberPicker_picker_tooltipStyle, R.style.NumberPicker_ToolTipStyle)
- disableGestures = array.getBoolean(R.styleable.NumberPicker_picker_disableGestures, false)
+ editTextStyleId = array.getResourceId(
+ R.styleable.NumberPicker_picker_editTextStyle,
+ R.style.NumberPicker_EditTextStyle
+ )
+ tooltipStyleId = array.getResourceId(
+ R.styleable.NumberPicker_picker_tooltipStyle,
+ R.style.NumberPicker_ToolTipStyle
+ )
+ disableGestures =
+ array.getBoolean(R.styleable.NumberPicker_picker_disableGestures, false)
maxDistance = context.resources.getDimensionPixelSize(R.dimen.picker_distance_max)
data = Data(value, minValue, maxValue, stepSize, orientation)
- val tracker_type = array.getInteger(R.styleable.NumberPicker_picker_tracker, TRACKER_LINEAR)
- tracker = when (tracker_type) {
+ val trackerType =
+ array.getInteger(R.styleable.NumberPicker_picker_tracker, TRACKER_LINEAR)
+ tracker = when (trackerType) {
TRACKER_LINEAR -> LinearTracker(this, maxDistance, orientation, callback)
TRACKER_EXPONENTIAL -> ExponentialTracker(this, maxDistance, orientation, callback)
else -> {
@@ -227,7 +239,6 @@ class NumberPicker @JvmOverloads constructor(
editText.isClickable = true
editText.isLongClickable = false
-
downButton = AppCompatImageButton(context)
downButton.setImageResource(R.drawable.arrow_up_selector_24)
downButton.setBackgroundResource(R.drawable.arrow_up_background)
@@ -253,8 +264,7 @@ class NumberPicker @JvmOverloads constructor(
if (!isEnabled) {
false
} else {
- val action = event.actionMasked
- when (action) {
+ when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
requestFocus()
setProgress(progress + stepSize)
@@ -263,26 +273,17 @@ class NumberPicker @JvmOverloads constructor(
upButton.requestFocus()
upButton.isPressed = true
- buttonInterval?.dispose()
-
- buttonInterval = Observable.interval(
- ARROW_BUTTON_INITIAL_DELAY,
- ARROW_BUTTON_FRAME_DELAY,
- TimeUnit.MILLISECONDS,
- Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe {
- setProgress(progress + stepSize)
- }
+ buttonIntervalJob?.cancel()
+ buttonIntervalJob = intervalJob(
+ ARROW_BUTTON_INITIAL_DELAY,
+ ARROW_BUTTON_FRAME_DELAY,
+ callback = { setProgress(progress + stepSize) })
}
-
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
upButton.isPressed = false
- buttonInterval?.dispose()
- buttonInterval = null
+ buttonIntervalJob?.cancel()
}
}
-
true
}
}
@@ -291,8 +292,7 @@ class NumberPicker @JvmOverloads constructor(
if (!isEnabled) {
false
} else {
- val action = event.actionMasked
- when (action) {
+ when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
requestFocus()
setProgress(progress - stepSize)
@@ -301,49 +301,28 @@ class NumberPicker @JvmOverloads constructor(
downButton.requestFocus()
downButton.isPressed = true
- buttonInterval?.dispose()
-
- buttonInterval = Observable.interval(
- ARROW_BUTTON_INITIAL_DELAY,
- ARROW_BUTTON_FRAME_DELAY,
- TimeUnit.MILLISECONDS,
- Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe {
- setProgress(progress - stepSize)
- }
+ buttonIntervalJob?.cancel()
+ buttonIntervalJob = intervalJob(
+ ARROW_BUTTON_INITIAL_DELAY,
+ ARROW_BUTTON_FRAME_DELAY,
+ callback = { setProgress(progress - stepSize) })
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
downButton.isPressed = false
-
- buttonInterval?.dispose()
- buttonInterval = null
-
-
+ buttonIntervalJob?.cancel()
}
}
-
true
}
}
-// editText.doOnTextChanged { text, _, _, _ ->
-// if (!text.isNullOrEmpty()) {
-// try {
-// this.setProgress(Integer.valueOf(text.toString()))
-// } catch (e: NumberFormatException) {
-// Timber.e(e)
-// }
-// }
-// }
-
editText.setOnFocusChangeListener { _, hasFocus ->
setBackgroundFocused(hasFocus)
if (!hasFocus) {
if (!editText.text.isNullOrEmpty()) {
- setProgress(Integer.valueOf(editText.text.toString()), true)
+ setProgress(editText.text.toString().toIntOrNull() ?: Integer.MAX_VALUE, true)
} else {
editText.setText(data.value.toString())
}
@@ -362,11 +341,7 @@ class NumberPicker @JvmOverloads constructor(
}
private fun setBackgroundFocused(hasFocus: Boolean) {
- if (hasFocus) {
- background?.state = FOCUSED_STATE_ARRAY
- } else {
- background?.state = UNFOCUSED_STATE_ARRAY
- }
+ background?.state = if (hasFocus) FOCUSED_STATE_ARRAY else UNFOCUSED_STATE_ARRAY
}
private fun initializeGestures() {
@@ -411,25 +386,23 @@ class NumberPicker @JvmOverloads constructor(
}
tooltip?.doOnShown { it.update(data.value.toString()) }
- tooltip?.show(this, if (data.orientation == VERTICAL) Tooltip.Gravity.LEFT else Tooltip.Gravity.TOP, false)
-
+ tooltip?.show(
+ this,
+ if (data.orientation == VERTICAL) Tooltip.Gravity.LEFT else Tooltip.Gravity.TOP,
+ false
+ )
numberPickerChangeListener?.onStartTrackingTouch(this)
-
}
private fun endInteraction() {
Timber.i("endInteraction")
-
animate().alpha(1.0f).start()
-
tooltip?.dismiss()
tooltip = null
-
numberPickerChangeListener?.onStopTrackingTouch(this)
}
companion object {
-
const val TRACKER_LINEAR = 0
const val TRACKER_EXPONENTIAL = 1
@@ -439,8 +412,6 @@ class NumberPicker @JvmOverloads constructor(
val FOCUSED_STATE_ARRAY = intArrayOf(android.R.attr.state_focused)
val UNFOCUSED_STATE_ARRAY = intArrayOf(0, -android.R.attr.state_focused)
-
-
}
}
@@ -468,10 +439,11 @@ class Data(value: Int, minValue: Int, maxValue: Int, var stepSize: Int, val orie
}
internal abstract class Tracker(
- val numberPicker: NumberPicker,
- private val maxDistance: Int,
- val orientation: Int,
- val callback: (Int) -> Unit) {
+ val numberPicker: NumberPicker,
+ private val maxDistance: Int,
+ val orientation: Int,
+ val callback: (Int) -> Unit
+) {
internal var started: Boolean = false
internal var initialValue: Int = 0
@@ -517,14 +489,14 @@ internal abstract class Tracker(
}
internal class ExponentialTracker(
- numberPicker: NumberPicker,
- maxDistance: Int,
- orientation: Int,
- callback: (Int) -> Unit) : Tracker(numberPicker, maxDistance, orientation, callback) {
+ numberPicker: NumberPicker,
+ maxDistance: Int,
+ orientation: Int,
+ callback: (Int) -> Unit
+) : Tracker(numberPicker, maxDistance, orientation, callback) {
private var time: Long = 1000L
private var direction: Int = 0
-
private val handler = Handler()
private var runnable: Runnable = object : Runnable {
@@ -552,18 +524,14 @@ internal class ExponentialTracker(
Timber.i("addMovement($x, $y)")
val currentPosition = if (orientation == LinearLayout.VERTICAL) -y else x
- val diff: Float
- val perc: Float
-
- diff = max(-minDistance, min(currentPosition - downPosition, minDistance))
- perc = (diff / minDistance)
+ val diff: Float = max(-minDistance, min(currentPosition - downPosition, minDistance))
+ val perc: Float = (diff / minDistance)
direction = when {
perc > 0 -> 1
perc < 0 -> -1
else -> 0
}
-
time = (MAX_TIME_DELAY - ((MAX_TIME_DELAY - MIN_TIME_DELAY).toFloat() * abs(perc))).toLong()
}
@@ -579,24 +547,19 @@ internal class ExponentialTracker(
}
internal class LinearTracker(
- numberPicker: NumberPicker,
- maxDistance: Int,
- orientation: Int,
- callback: (Int) -> Unit) : Tracker(numberPicker, maxDistance, orientation, callback) {
-
+ numberPicker: NumberPicker,
+ maxDistance: Int,
+ orientation: Int,
+ callback: (Int) -> Unit
+) : Tracker(numberPicker, maxDistance, orientation, callback) {
override fun addMovement(x: Float, y: Float) {
Timber.i("addMovement($x, $y)")
val currentPosition = if (orientation == LinearLayout.VERTICAL) -y else x
-
- val diff: Float
- val perc: Float
- var finalValue: Int
-
- diff = max(-minDistance, min(currentPosition - downPosition, minDistance))
- perc = (diff / minDistance)
- finalValue = initialValue + (abs(numberPicker.maxValue - numberPicker.minValue) * perc).toInt()
-
+ val diff: Float = max(-minDistance, min(currentPosition - downPosition, minDistance))
+ val perc: Float = (diff / minDistance)
+ var finalValue: Int =
+ initialValue + (abs(numberPicker.maxValue - numberPicker.minValue) * perc).toInt()
var diffValue = finalValue - numberPicker.progress
if (numberPicker.stepSize > 1) {
@@ -604,10 +567,7 @@ internal class LinearTracker(
diffValue -= (diffValue % numberPicker.stepSize)
}
}
-
finalValue = numberPicker.progress + diffValue
-
callback.invoke(finalValue)
}
-}
-
+}
\ No newline at end of file
diff --git a/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPickerBindingAdapter.kt b/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPickerBindingAdapter.kt
index f99cd4b..ed29812 100644
--- a/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPickerBindingAdapter.kt
+++ b/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPickerBindingAdapter.kt
@@ -5,7 +5,12 @@ import androidx.databinding.InverseBindingMethod
import androidx.databinding.InverseBindingMethods
@Suppress("unused")
-@InverseBindingMethods(InverseBindingMethod(type = NumberPicker::class, attribute = "android:progress"))
+@InverseBindingMethods(
+ InverseBindingMethod(
+ type = NumberPicker::class,
+ attribute = "android:progress"
+ )
+)
class NumberPickerBindingAdapter {
companion object {
@BindingAdapter("progress")
@@ -30,30 +35,40 @@ class NumberPickerBindingAdapter {
}
- @BindingAdapter(value = ["android:onStartTrackingTouch", "android:onStopTrackingTouch", "android:onProgressChanged", "android:progressAttrChanged"], requireAll = false)
+ @BindingAdapter(
+ value = ["android:onStartTrackingTouch", "android:onStopTrackingTouch", "android:onProgressChanged", "android:progressAttrChanged"],
+ requireAll = false
+ )
@JvmStatic
- fun bindListener(view: NumberPicker,
- startListener: OnStartTrackingTouch?,
- stopListener: OnStopTrackingTouch?,
- progressListener: OnProgressChanged?,
- attrChanged: Boolean?) {
+ fun bindListener(
+ view: NumberPicker,
+ startListener: OnStartTrackingTouch?,
+ stopListener: OnStopTrackingTouch?,
+ progressListener: OnProgressChanged?,
+ attrChanged: Boolean?
+ ) {
if (startListener == null && stopListener == null && progressListener == null) {
view.numberPickerChangeListener = null
} else {
- view.numberPickerChangeListener = object : NumberPicker.OnNumberPickerChangeListener {
- override fun onProgressChanged(numberPicker: NumberPicker, progress: Int, fromUser: Boolean) {
- progressListener?.onProgressChanged(numberPicker, progress, fromUser)
- }
+ view.numberPickerChangeListener =
+ object : NumberPicker.OnNumberPickerChangeListener {
+ override fun onProgressChanged(
+ numberPicker: NumberPicker,
+ progress: Int,
+ fromUser: Boolean
+ ) {
+ progressListener?.onProgressChanged(numberPicker, progress, fromUser)
+ }
- override fun onStartTrackingTouch(numberPicker: NumberPicker) {
- startListener?.onStartTrackingTouch(numberPicker)
- }
+ override fun onStartTrackingTouch(numberPicker: NumberPicker) {
+ startListener?.onStartTrackingTouch(numberPicker)
+ }
- override fun onStopTrackingTouch(numberPicker: NumberPicker) {
- stopListener?.onStopTrackingTouch(numberPicker)
- }
+ override fun onStopTrackingTouch(numberPicker: NumberPicker) {
+ stopListener?.onStopTrackingTouch(numberPicker)
+ }
- }
+ }
}
}
}
diff --git a/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPickerExt.kt b/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPickerExt.kt
index 41c60ac..cbd9c13 100644
--- a/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPickerExt.kt
+++ b/numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPickerExt.kt
@@ -1,35 +1,43 @@
+@file:Suppress("unused")
package it.sephiroth.android.library.numberpicker
+import kotlinx.coroutines.*
inline fun NumberPicker.doOnProgressChanged(
- crossinline action: (
- numberPicker: NumberPicker,
- progress: Int,
- formUser: Boolean) -> Unit) =
- addProgressChangedListener(progressChanged = action)
+ crossinline action: (
+ numberPicker: NumberPicker,
+ progress: Int,
+ formUser: Boolean
+ ) -> Unit
+) =
+ addProgressChangedListener(progressChanged = action)
inline fun NumberPicker.doOnStartTrackingTouch(crossinline action: (numberPicker: NumberPicker) -> Unit) =
- addProgressChangedListener(startTrackingTouch = action)
+ addProgressChangedListener(startTrackingTouch = action)
inline fun NumberPicker.doOnStopTrackingTouch(crossinline action: (numberPicker: NumberPicker) -> Unit) =
- addProgressChangedListener(stopTrackingTouch = action)
+ addProgressChangedListener(stopTrackingTouch = action)
inline fun NumberPicker.addProgressChangedListener(
- crossinline progressChanged: (
- numberPicker: NumberPicker,
- progress: Int,
- formUser: Boolean
- ) -> Unit = { _, _, _ -> },
+ crossinline progressChanged: (
+ numberPicker: NumberPicker,
+ progress: Int,
+ formUser: Boolean
+ ) -> Unit = { _, _, _ -> },
- crossinline startTrackingTouch: (numberPicker: NumberPicker) -> Unit = { _ -> },
+ crossinline startTrackingTouch: (numberPicker: NumberPicker) -> Unit = { _ -> },
- crossinline stopTrackingTouch: (numberPicker: NumberPicker) -> Unit = { _ -> }
+ crossinline stopTrackingTouch: (numberPicker: NumberPicker) -> Unit = { _ -> }
- ): NumberPicker.OnNumberPickerChangeListener {
+): NumberPicker.OnNumberPickerChangeListener {
val listener = object : NumberPicker.OnNumberPickerChangeListener {
- override fun onProgressChanged(numberPicker: NumberPicker, progress: Int, fromUser: Boolean) {
+ override fun onProgressChanged(
+ numberPicker: NumberPicker,
+ progress: Int,
+ fromUser: Boolean
+ ) {
progressChanged.invoke(numberPicker, progress, fromUser)
}
@@ -46,7 +54,7 @@ inline fun NumberPicker.addProgressChangedListener(
return listener
}
-class _OnNumberPickerChangeListener : NumberPicker.OnNumberPickerChangeListener {
+class OnNumberPickerChangeListener : NumberPicker.OnNumberPickerChangeListener {
override fun onProgressChanged(numberPicker: NumberPicker, progress: Int, fromUser: Boolean) {
_onProgressChanged?.invoke(numberPicker, progress, fromUser)
@@ -77,8 +85,24 @@ class _OnNumberPickerChangeListener : NumberPicker.OnNumberPickerChangeListener
private var _onStopTrackingTouch: ((NumberPicker) -> Unit)? = null
}
-inline fun NumberPicker.setListener(func: _OnNumberPickerChangeListener.() -> Unit) {
- val listener = _OnNumberPickerChangeListener()
+inline fun NumberPicker.setListener(func: OnNumberPickerChangeListener.() -> Unit) {
+ val listener = OnNumberPickerChangeListener()
listener.func()
numberPickerChangeListener = listener
}
+
+fun intervalJob(
+ initialDelay: Long = 0L,
+ period: Long = 700L,
+ scope: CoroutineScope = CoroutineScope(Dispatchers.Main),
+ callback: (Int) -> Unit
+): Job {
+ var value = 0
+ return scope.launch {
+ delay(initialDelay)
+ while (isActive) {
+ callback(value++)
+ delay(period)
+ }
+ }
+}
\ No newline at end of file
diff --git a/numberpicker/src/main/res/anim/anim_out.xml b/numberpicker/src/main/res/anim/anim_out.xml
index 340b798..96cadc3 100644
--- a/numberpicker/src/main/res/anim/anim_out.xml
+++ b/numberpicker/src/main/res/anim/anim_out.xml
@@ -1,8 +1,10 @@
+ android:duration="@android:integer/config_shortAnimTime"
+ android:interpolator="@android:interpolator/decelerate_quad"
+ android:shareInterpolator="true">
-
+
\ No newline at end of file
diff --git a/numberpicker/src/main/res/drawable/arrow_up_background.xml b/numberpicker/src/main/res/drawable/arrow_up_background.xml
index 3d7fbef..e407171 100644
--- a/numberpicker/src/main/res/drawable/arrow_up_background.xml
+++ b/numberpicker/src/main/res/drawable/arrow_up_background.xml
@@ -1,7 +1,7 @@
+ android:color="?attr/colorControlHighlight"
+ android:radius="18dp">
diff --git a/numberpicker/src/main/res/drawable/arrow_up_selector_18.xml b/numberpicker/src/main/res/drawable/arrow_up_selector_18.xml
index be7006f..f3f584f 100644
--- a/numberpicker/src/main/res/drawable/arrow_up_selector_18.xml
+++ b/numberpicker/src/main/res/drawable/arrow_up_selector_18.xml
@@ -1,8 +1,6 @@
-
+
-
diff --git a/numberpicker/src/main/res/drawable/arrow_up_selector_24.xml b/numberpicker/src/main/res/drawable/arrow_up_selector_24.xml
index 81d9e40..5be9395 100644
--- a/numberpicker/src/main/res/drawable/arrow_up_selector_24.xml
+++ b/numberpicker/src/main/res/drawable/arrow_up_selector_24.xml
@@ -1,8 +1,6 @@
-
+
-
diff --git a/numberpicker/src/main/res/drawable/mtrl_background_outlined.xml b/numberpicker/src/main/res/drawable/mtrl_background_outlined.xml
index 9d1e16d..fedc26f 100644
--- a/numberpicker/src/main/res/drawable/mtrl_background_outlined.xml
+++ b/numberpicker/src/main/res/drawable/mtrl_background_outlined.xml
@@ -4,8 +4,7 @@
-
-
+
@@ -14,8 +13,7 @@
-
-
+
diff --git a/numberpicker/src/main/res/drawable/round_keyboard_arrow_up_24.xml b/numberpicker/src/main/res/drawable/round_keyboard_arrow_up_24.xml
index 930a6ba..82475dc 100755
--- a/numberpicker/src/main/res/drawable/round_keyboard_arrow_up_24.xml
+++ b/numberpicker/src/main/res/drawable/round_keyboard_arrow_up_24.xml
@@ -1,10 +1,10 @@
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="?attr/colorControlNormal"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ android:pathData="M8.12,14.71L12,10.83l3.88,3.88c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L12.7,8.71c-0.39,-0.39 -1.02,-0.39 -1.41,0L6.7,13.3c-0.39,0.39 -0.39,1.02 0,1.41 0.39,0.38 1.03,0.39 1.42,0z" />