-
Notifications
You must be signed in to change notification settings - Fork 982
/
PositiveLongTextValidator.java
51 lines (40 loc) · 1.17 KB
/
PositiveLongTextValidator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.osmdroid.model;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
/**
* created on 12/4/2016.
*
* @author Alex O'Ree
* @since 5.6.1
*/
public class PositiveLongTextValidator implements TextWatcher {
EditText parent;
long minValue;
public PositiveLongTextValidator(EditText parent, long minValue) {
this.parent = parent;
this.minValue = minValue;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
String txt = parent.getText().toString();
if (txt == null || txt.length() == 0)
parent.setError("Not a valid number");
try {
long val = Long.parseLong(txt);
if (val < minValue) {
parent.setError("Must be at least " + minValue);
} else {
parent.setError(null);
}
} catch (Exception ex) {
parent.setError("Not a valid number");
}
}
}