11 package com.freerdp.freerdpcore.utils;
13 import android.content.Context;
14 import android.content.res.TypedArray;
15 import android.preference.EditTextPreference;
16 import android.util.AttributeSet;
18 import com.freerdp.freerdpcore.R;
23 private int bounds_min, bounds_max, bounds_default;
33 super(context, attrs);
39 super(context, attrs, defStyle);
43 private void init(Context context, AttributeSet attrs)
48 context.obtainStyledAttributes(attrs, R.styleable.IntEditTextPreference, 0, 0);
50 array.getInt(R.styleable.IntEditTextPreference_bounds_min, Integer.MIN_VALUE);
52 array.getInt(R.styleable.IntEditTextPreference_bounds_max, Integer.MAX_VALUE);
53 bounds_default = array.getInt(R.styleable.IntEditTextPreference_bounds_default, 0);
58 bounds_min = Integer.MIN_VALUE;
59 bounds_max = Integer.MAX_VALUE;
64 public void setBounds(
int min,
int max,
int defaultValue)
68 bounds_default = defaultValue;
71 @Override
protected String getPersistedString(String defaultReturnValue)
73 int value = getPersistedInt(-1);
74 if (value > bounds_max || value < bounds_min)
75 value = bounds_default;
76 return String.valueOf(value);
79 @Override
protected boolean persistString(String value)
81 return persistInt(Integer.parseInt(value));
84 @Override
protected void onDialogClosed(
boolean positiveResult)
89 if (getEditText().getText().length() == 0)
90 getEditText().setText(
"0");
93 int value = Integer.parseInt(getEditText().getText().toString());
94 if (value > bounds_max || value < bounds_min)
95 value = bounds_default;
96 getEditText().setText(String.valueOf(value));
99 super.onDialogClosed(positiveResult);