Colorpicker and customseekbar: add method to set default values

also be sure default values is not greater than max value
This commit is contained in:
ezio84
2017-09-30 09:22:18 +02:00
committed by hungphan2001
parent d46369fee4
commit dbbb73f0ae
2 changed files with 18 additions and 1 deletions

View File

@@ -54,6 +54,9 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
mMax = attrs.getAttributeIntValue(ANDROIDNS, "max", 100); mMax = attrs.getAttributeIntValue(ANDROIDNS, "max", 100);
mMin = attrs.getAttributeIntValue(SETTINGS_NS, "min", 0); mMin = attrs.getAttributeIntValue(SETTINGS_NS, "min", 0);
mDefaultValue = attrs.getAttributeIntValue(ANDROIDNS, "defaultValue", -1); mDefaultValue = attrs.getAttributeIntValue(ANDROIDNS, "defaultValue", -1);
if (mDefaultValue > mMax) {
mDefaultValue = mMax;
}
mUnits = getAttributeStringValue(attrs, SETTINGS_NS, "units", ""); mUnits = getAttributeStringValue(attrs, SETTINGS_NS, "units", "");
mDefaultText = getAttributeStringValue(attrs, SETTINGS_NS, "defaultText", "Def"); mDefaultText = getAttributeStringValue(attrs, SETTINGS_NS, "defaultText", "Def");
@@ -222,6 +225,16 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
} }
} }
public void setDefaultValue(int value) {
mDefaultValue = value;
if (mDefaultValue > mMax) {
mDefaultValue = mMax;
}
if (mCurrentValue == mDefaultValue) {
mStatusText.setText(mDefaultText);
}
}
@Override @Override
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
if (mSeekBar != null && mStatusText != null && mTitle != null) { if (mSeekBar != null && mStatusText != null && mTitle != null) {

View File

@@ -284,6 +284,10 @@ public class ColorPickerPreference extends Preference implements
onColorChanged(color); onColorChanged(color);
} }
public void setDefaultColor(int color) {
mDefValue = color;
}
/** /**
* For custom purposes. Not used by ColorPickerPreferrence * For custom purposes. Not used by ColorPickerPreferrence
* *