Skip to content

Commit 4801546

Browse files
committed
up/down observe on main thread, hide keyboard, fixed dependencies
1 parent 6f2d3d0 commit 4801546

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies {
3636
implementation project(':numberpicker')
3737

3838
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
39-
implementation 'androidx.core:core-ktx:1.1.0-alpha03'
39+
implementation 'androidx.core:core-ktx:1.1.0-alpha04'
4040

4141
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
4242
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88

99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.4.0-beta02'
11+
classpath 'com.android.tools.build:gradle:3.4.0-beta03'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313
// NOTE: Do not place your application dependencies here; they belong
1414
// in the individual module build.gradle files

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ kotlin.code.style=official
2323
ANDROID_BUILD_SDK_VERSION=28
2424
ANDROID_BUILD_TARGET_SDK_VERSION=28
2525

26-
VERSION_NAME=1.0.0
27-
VERSION_CODE=1
26+
VERSION_NAME=1.0.1
27+
VERSION_CODE=2
2828
GROUP=it.sephiroth.android.library
2929

3030
POM_DESCRIPTION=Sliding Number Picker for Android

numberpicker/build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ dependencies {
4242

4343
// implementation project(':xtooltip')
4444

45-
implementation 'com.github.sephiroth74:android-target-tooltip:feature~update_text_and_position-SNAPSHOT'
46-
47-
45+
implementation 'com.github.sephiroth74:android-target-tooltip:v2.0.4'
4846
implementation 'com.github.sephiroth74:AndroidUIGestureRecognizer:v1.2.7'
4947

5048
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
@@ -53,7 +51,7 @@ dependencies {
5351
implementation 'io.reactivex.rxjava2:rxjava:2.2.6'
5452

5553
implementation 'androidx.appcompat:appcompat:1.0.2'
56-
implementation 'androidx.core:core-ktx:1.1.0-alpha03'
54+
implementation 'androidx.core:core-ktx:1.1.0-alpha04'
5755

5856
implementation 'com.google.android.material:material:1.0.0'
5957

numberpicker/src/main/java/it/sephiroth/android/library/numberpicker/NumberPicker.kt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package it.sephiroth.android.library.numberpicker
22

33
import android.annotation.SuppressLint
4+
import android.app.Activity
45
import android.content.Context
56
import android.graphics.PointF
67
import android.os.Handler
78
import android.util.AttributeSet
89
import android.view.Gravity
910
import android.view.MotionEvent
1011
import android.view.ViewGroup
12+
import android.view.inputmethod.EditorInfo
13+
import android.view.inputmethod.InputMethodManager
1114
import android.widget.EditText
1215
import android.widget.LinearLayout
1316
import android.widget.TextView
@@ -28,6 +31,7 @@ import kotlin.math.max
2831
import kotlin.math.min
2932
import kotlin.math.sin
3033

34+
3135
class NumberPicker @JvmOverloads constructor(
3236
context: Context,
3337
attrs: AttributeSet? = null,
@@ -146,6 +150,9 @@ class NumberPicker @JvmOverloads constructor(
146150

147151
init {
148152
setWillNotDraw(false)
153+
isFocusable = true
154+
isFocusableInTouchMode = true
155+
149156
orientation = HORIZONTAL
150157
gravity = Gravity.CENTER
151158

@@ -190,6 +197,11 @@ class NumberPicker @JvmOverloads constructor(
190197
delegate.isEnabled = enabled
191198
}
192199

200+
private fun hideKeyboard() {
201+
val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
202+
imm.hideSoftInputFromWindow(windowToken, 0)
203+
}
204+
193205
private fun inflateChildren() {
194206
upButton = AppCompatImageButton(context)
195207
upButton.setImageResource(R.drawable.arrow_up_selector_24)
@@ -240,6 +252,8 @@ class NumberPicker @JvmOverloads constructor(
240252
requestFocus()
241253
setProgress(progress + stepSize)
242254
editText.clearFocus()
255+
hideKeyboard()
256+
243257
upButton.requestFocus()
244258
upButton.isPressed = true
245259
buttonInterval?.dispose()
@@ -249,7 +263,7 @@ class NumberPicker @JvmOverloads constructor(
249263
ARROW_BUTTON_FRAME_DELAY,
250264
TimeUnit.MILLISECONDS,
251265
Schedulers.io())
252-
.subscribeOn(AndroidSchedulers.mainThread())
266+
.observeOn(AndroidSchedulers.mainThread())
253267
.subscribe {
254268
setProgress(progress + stepSize)
255269
}
@@ -276,6 +290,8 @@ class NumberPicker @JvmOverloads constructor(
276290
requestFocus()
277291
setProgress(progress - stepSize)
278292
editText.clearFocus()
293+
hideKeyboard()
294+
279295
downButton.requestFocus()
280296
downButton.isPressed = true
281297
buttonInterval?.dispose()
@@ -285,7 +301,7 @@ class NumberPicker @JvmOverloads constructor(
285301
ARROW_BUTTON_FRAME_DELAY,
286302
TimeUnit.MILLISECONDS,
287303
Schedulers.io())
288-
.subscribeOn(AndroidSchedulers.mainThread())
304+
.observeOn(AndroidSchedulers.mainThread())
289305
.subscribe {
290306
setProgress(progress - stepSize)
291307
}
@@ -324,6 +340,16 @@ class NumberPicker @JvmOverloads constructor(
324340
}
325341
}
326342
}
343+
344+
editText.setOnEditorActionListener { _, actionId, _ ->
345+
when (actionId) {
346+
EditorInfo.IME_ACTION_DONE -> {
347+
editText.clearFocus()
348+
true
349+
}
350+
else -> false
351+
}
352+
}
327353
}
328354

329355
private fun setBackgroundFocused(hasFocus: Boolean) {

numberpicker/src/main/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<item name="android:gravity">center</item>
8282
<item name="android:editable">true</item>
8383
<item name="android:background">@null</item>
84+
<item name="android:imeOptions">actionDone</item>
8485
</style>
8586

8687
</resources>

0 commit comments

Comments
 (0)