|
public class Main extends PreferenceActivity
{
private EditTextPreference delayReading;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
Preference editWhitelist = findPreference(getString(R.string.editWhitelist));
editWhitelist.setOnPreferenceClickListener(editWhitelistHandler);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
delayReading = (EditTextPreference) findPreference(getString(R.string.delayReadingTime));
delayReading.setOnPreferenceChangeListener(delayReadingHandler);
updateDelaySummary(settings.getString(getString(R.string.delayReadingTime), "0"));
// Check to see if the TTS is installed.
if (false == TTS.isInstalled(this))
{
new TTSVersionAlert(this, getString(R.string.notts), null, null).show();
}}
// On click handler for editing the whitelist.
OnPreferenceClickListener editWhitelistHandler = new OnPreferenceClickListener()
{
public boolean onPreferenceClick(Preference preference)
{
startActivity(new Intent(Main.this, Whitelist.class));
return true;
}
};
// On Preference change listener to update the delay summary.
OnPreferenceChangeListener delayReadingHandler = new OnPreferenceChangeListener()
{
public boolean onPreferenceChange(Preference preference, Object newValue)
{
updateDelaySummary((String) newValue);
return true;
}};
// Helper function to update the delay summary.
private void updateDelaySummary(String value)
{
String template = getString(R.string.delay_readout_summary);
Integer intValue = Integer.parseInt(value);
String plural = "s";
if (intValue == 1)
{
plural = "";
}
String result = String.format(template, intValue, plural);
delayReading.setSummary(result);
}
} |
|