Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import android.text.InputFilter;
  2. import android.text.Spanned;
  3.  
  4. public class DoubleMinMaxFilter implements InputFilter {
  5.  
  6. private double mDoubleMin, mDoubleMax;
  7.  
  8. public DoubleMinMaxFilter(double minValue, double maxValue) {
  9. this.mDoubleMin = minValue;
  10. this.mDoubleMax = maxValue;
  11. }
  12.  
  13. @Override
  14. public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
  15. try {
  16. double input = Double.parseDouble(dest.toString() + source.toString());
  17. if (isInRange(mDoubleMin, mDoubleMax, input))
  18. return null;
  19. } catch (NumberFormatException nfe) { }
  20. return "";
  21. }
  22.  
  23. private boolean isInRange(double a, double b, double c) {
  24. return b > a ? c >= a && c <= b : c >= b && c <= a;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement