NumberPicker: apply signed, decimal constraints for keyboard usage.

This commit is contained in:
Johannes Mockenhaupt 2018-04-13 21:21:05 +02:00
parent efcc02775b
commit 719d3d459b
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 6 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -148,7 +149,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
}
public void setParams(Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formater, boolean allowZero, TextWatcher textWatcher) {
if(this.textWatcher != null) {
if (this.textWatcher != null) {
editText.removeTextChangedListener(this.textWatcher);
}
setParams(initValue, minValue, maxValue, step, formater, allowZero);
@ -164,6 +165,8 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
this.formater = formater;
this.allowZero = allowZero;
editText.setKeyListener(DigitsKeyListener.getInstance(minValue < 0, step != Math.rint(step)));
if (textWatcher != null)
editText.removeTextChangedListener(textWatcher);
updateEditText();
@ -202,7 +205,7 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
updateEditText();
}
private void dec( int multiplier) {
private void dec(int multiplier) {
value -= step * multiplier;
if (value < minValue) {
value = minValue;

View file

@ -23,8 +23,7 @@
android:layout_height="match_parent"
android:text="1"
android:textColor="@android:color/black"
android:inputType="numberDecimal"
android:digits="0123456789.,"
android:inputType="number"
android:gravity="center"
android:imeOptions="actionDone"
/>