Merge "Get value text from ValueProxy"

main
Tadashi G. Takaoka 2013-06-18 09:29:23 +00:00 committed by Android (Google) Code Review
commit 500b1f410d
4 changed files with 31 additions and 26 deletions

View File

@ -439,7 +439,6 @@
</declare-styleable>
<declare-styleable name="SeekBarDialogPreference">
<attr name="valueFormatText" format="reference" />
<attr name="maxValue" format="integer" />
<attr name="minValue" format="integer" />
<attr name="stepValue" format="integer" />

View File

@ -170,14 +170,12 @@
<com.android.inputmethod.latin.SeekBarDialogPreference
android:key="pref_key_longpress_timeout"
android:title="@string/prefs_key_longpress_timeout_settings"
latin:valueFormatText="@string/abbreviation_unit_milliseconds"
latin:minValue="@integer/config_min_longpress_timeout"
latin:maxValue="@integer/config_max_longpress_timeout"
latin:stepValue="@integer/config_longpress_timeout_step" />
<com.android.inputmethod.latin.SeekBarDialogPreference
android:key="pref_vibration_duration_settings"
android:title="@string/prefs_keypress_vibration_duration_settings"
latin:valueFormatText="@string/abbreviation_unit_milliseconds"
latin:maxValue="@integer/config_max_vibration_duration" />
<com.android.inputmethod.latin.SeekBarDialogPreference
android:key="pref_keypress_sound_volume"

View File

@ -33,10 +33,10 @@ public final class SeekBarDialogPreference extends DialogPreference
public int readDefaultValue(final String key);
public void writeValue(final int value, final String key);
public void writeDefaultValue(final String key);
public String getValueText(final int value);
public void feedbackValue(final int value);
}
private final int mValueFormatResId;
private final int mMaxValue;
private final int mMinValue;
private final int mStepValue;
@ -50,7 +50,6 @@ public final class SeekBarDialogPreference extends DialogPreference
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.SeekBarDialogPreference, 0, 0);
mValueFormatResId = a.getResourceId(R.styleable.SeekBarDialogPreference_valueFormatText, 0);
mMaxValue = a.getInt(R.styleable.SeekBarDialogPreference_maxValue, 0);
mMinValue = a.getInt(R.styleable.SeekBarDialogPreference_minValue, 0);
mStepValue = a.getInt(R.styleable.SeekBarDialogPreference_stepValue, 0);
@ -60,15 +59,8 @@ public final class SeekBarDialogPreference extends DialogPreference
public void setInterface(final ValueProxy proxy) {
mValueProxy = proxy;
setSummary(getValueText(clipValue(proxy.readValue(getKey()))));
}
private String getValueText(final int value) {
if (mValueFormatResId == 0) {
return Integer.toString(value);
} else {
return getContext().getString(mValueFormatResId, value);
}
final int value = mValueProxy.readValue(getKey());
setSummary(mValueProxy.getValueText(value));
}
@Override
@ -101,16 +93,11 @@ public final class SeekBarDialogPreference extends DialogPreference
return clipValue(getValueFromProgress(progress));
}
private void setValue(final int value, final boolean fromUser) {
mValueView.setText(getValueText(value));
if (!fromUser) {
mSeekBar.setProgress(getProgressFromValue(value));
}
}
@Override
protected void onBindDialogView(final View view) {
setValue(clipValue(mValueProxy.readValue(getKey())), false /* fromUser */);
final int value = mValueProxy.readValue(getKey());
mValueView.setText(mValueProxy.getValueText(value));
mSeekBar.setProgress(getProgressFromValue(clipValue(value)));
}
@Override
@ -125,13 +112,15 @@ public final class SeekBarDialogPreference extends DialogPreference
super.onClick(dialog, which);
final String key = getKey();
if (which == DialogInterface.BUTTON_NEUTRAL) {
setValue(clipValue(mValueProxy.readDefaultValue(key)), false /* fromUser */);
final int value = mValueProxy.readDefaultValue(key);
setSummary(mValueProxy.getValueText(value));
mValueProxy.writeDefaultValue(key);
return;
}
if (which == DialogInterface.BUTTON_POSITIVE) {
setSummary(mValueView.getText());
mValueProxy.writeValue(getClippedValueFromProgress(mSeekBar.getProgress()), key);
final int value = getClippedValueFromProgress(mSeekBar.getProgress());
setSummary(mValueProxy.getValueText(value));
mValueProxy.writeValue(value, key);
return;
}
}
@ -139,7 +128,11 @@ public final class SeekBarDialogPreference extends DialogPreference
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress,
final boolean fromUser) {
setValue(getClippedValueFromProgress(progress), fromUser);
final int value = getClippedValueFromProgress(progress);
mValueView.setText(mValueProxy.getValueText(value));
if (!fromUser) {
mSeekBar.setProgress(getProgressFromValue(value));
}
}
@Override

View File

@ -364,6 +364,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
public void feedbackValue(final int value) {
AudioAndHapticFeedbackManager.getInstance().vibrate(value);
}
@Override
public String getValueText(final int value) {
return res.getString(R.string.abbreviation_unit_milliseconds, value);
}
});
}
@ -395,6 +400,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
return Settings.readDefaultKeyLongpressTimeout(res);
}
@Override
public String getValueText(final int value) {
return res.getString(R.string.abbreviation_unit_milliseconds, value);
}
@Override
public void feedbackValue(final int value) {}
});
@ -438,6 +448,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
return getPercentageFromValue(Settings.readDefaultKeypressSoundVolume(res));
}
@Override
public String getValueText(final int value) {
return Integer.toString(value);
}
@Override
public void feedbackValue(final int value) {
am.playSoundEffect(