am d99abf8c: Delete shared preference entry when user select default value

* commit 'd99abf8cb119ff2cb4e7d975001a939cc48d7112':
  Delete shared preference entry when user select default value
main
Tadashi G. Takaoka 2013-05-28 04:49:27 -07:00 committed by Android Git Automerger
commit 2bd3883be4
2 changed files with 23 additions and 3 deletions

View File

@ -32,6 +32,7 @@ public final class SeekBarDialogPreference extends DialogPreference
public int readValue(final String key); public int readValue(final String key);
public int readDefaultValue(final String key); public int readDefaultValue(final String key);
public void writeValue(final int value, final String key); public void writeValue(final int value, final String key);
public void writeDefaultValue(final String key);
public void feedbackValue(final int value); public void feedbackValue(final int value);
} }
@ -122,12 +123,16 @@ public final class SeekBarDialogPreference extends DialogPreference
@Override @Override
public void onClick(final DialogInterface dialog, final int which) { public void onClick(final DialogInterface dialog, final int which) {
super.onClick(dialog, which); super.onClick(dialog, which);
final String key = getKey();
if (which == DialogInterface.BUTTON_NEUTRAL) { if (which == DialogInterface.BUTTON_NEUTRAL) {
setValue(clipValue(mValueProxy.readDefaultValue(getKey())), false /* fromUser */); setValue(clipValue(mValueProxy.readDefaultValue(key)), false /* fromUser */);
mValueProxy.writeDefaultValue(key);
return;
} }
if (which != DialogInterface.BUTTON_NEGATIVE) { if (which == DialogInterface.BUTTON_POSITIVE) {
setSummary(mValueView.getText()); setSummary(mValueView.getText());
mValueProxy.writeValue(getClippedValueFromProgress(mSeekBar.getProgress()), getKey()); mValueProxy.writeValue(getClippedValueFromProgress(mSeekBar.getProgress()), key);
return;
} }
} }

View File

@ -328,6 +328,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
sp.edit().putInt(key, value).apply(); sp.edit().putInt(key, value).apply();
} }
@Override
public void writeDefaultValue(final String key) {
sp.edit().remove(key).apply();
}
@Override @Override
public int readValue(final String key) { public int readValue(final String key) {
return Settings.readKeypressVibrationDuration(sp, res); return Settings.readKeypressVibrationDuration(sp, res);
@ -358,6 +363,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
sp.edit().putInt(key, value).apply(); sp.edit().putInt(key, value).apply();
} }
@Override
public void writeDefaultValue(final String key) {
sp.edit().remove(key).apply();
}
@Override @Override
public int readValue(final String key) { public int readValue(final String key) {
return Settings.readKeyLongpressTimeout(sp, res); return Settings.readKeyLongpressTimeout(sp, res);
@ -396,6 +406,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
sp.edit().putFloat(key, getValueFromPercentage(value)).apply(); sp.edit().putFloat(key, getValueFromPercentage(value)).apply();
} }
@Override
public void writeDefaultValue(final String key) {
sp.edit().remove(key).apply();
}
@Override @Override
public int readValue(final String key) { public int readValue(final String key) {
return getPercentageFromValue(Settings.readKeypressSoundVolume(sp, res)); return getPercentageFromValue(Settings.readKeypressSoundVolume(sp, res));