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:
@@ -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");
|
||||||
|
|
||||||
@@ -137,7 +140,7 @@ public class CustomSeekBarPreference extends Preference implements SeekBar.OnSee
|
|||||||
mStatusText.setText(mDefaultText);
|
mStatusText.setText(mDefaultText);
|
||||||
} else {
|
} else {
|
||||||
mStatusText.setText(String.valueOf(mCurrentValue) + mUnits);
|
mStatusText.setText(String.valueOf(mCurrentValue) + mUnits);
|
||||||
}
|
}
|
||||||
mSeekBar.setProgress(mCurrentValue - mMin);
|
mSeekBar.setProgress(mCurrentValue - mMin);
|
||||||
mTitle = (TextView) view.findViewById(android.R.id.title);
|
mTitle = (TextView) view.findViewById(android.R.id.title);
|
||||||
|
|
||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user