/** @see android.app.Activity#onResume() */ @Override protected void onResume() { super.onResume(); final HistoryManager historyManager = HashItApplication.getApp(this).getHistoryManager(); final PreferenceScreen prefScreen = getPreferenceScreen(); final SharedPreferences defaults = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); if (SDK_INT >= HONEYCOMB) { // Look & Feel final PreferenceCategory lookAndFeel = new PreferenceCategory(this); lookAndFeel.setTitle(R.string.Header_LookAndFeel); prefScreen.addPreference(lookAndFeel); final Preference useDarkTheme = addCheckBoxPreference( lookAndFeel, USE_DARK_THEME, R.string.CheckBox_UseDarkTheme, defaults, false); useDarkTheme.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { recreate(); return true; } }); } // Convenience final PreferenceCategory convenience = new PreferenceCategory(this); convenience.setTitle(R.string.Header_Convenience); prefScreen.addPreference(convenience); final Preference enableHistory = addCheckBoxPreference( convenience, ENABLE_HISTORY, R.string.CheckBox_EnableHistory, defaults, true); enableHistory.setSummary(R.string.Summary_EnableHistory); final boolean enableClear = historyManager != null && !historyManager.isEmpty(); final Preference clear = addActionPreference( convenience, R.string.Action_ClearHistory, new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference pref) { historyManager.clear(); pref.setSummary(R.string.Summary_ClearHistory_Empty); pref.setEnabled(false); return true; } }, enableClear); clear.setSummary( enableClear ? R.string.Summary_ClearHistory : R.string.Summary_ClearHistory_Empty); final Preference autoExit = addCheckBoxPreference(convenience, AUTO_EXIT, R.string.CheckBox_AutoExit, defaults, false); autoExit.setSummary(R.string.Summary_AutoExit); final ListPreference cacheDuration = addListPreference( convenience, CACHE_DURATION, R.string.Label_CacheMasterKey, R.string.Header_CacheDuration, R.array.Array_CacheDuration, R.array.Array_CacheDuration_Values, defaults, -1); cacheDuration.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { updateSummary((ListPreference) preference, newValue); if (Integer.parseInt((String) newValue) <= 0) { MemoryCacheServiceImpl.stopService(SettingsActivity.this); } return true; } }); updateSummary(cacheDuration, cacheDuration.getValue()); final Preference showMasterKeyDigest; showMasterKeyDigest = addCheckBoxPreference( convenience, SHOW_MASTER_KEY_DIGEST, R.string.CheckBox_ShowMasterKeyDigest, defaults, true); showMasterKeyDigest.setSummary(R.string.Summary_ShowMasterKeyDigest); disableConflictingPreferences(DISABLE_CLIPBOARD, DEPS_DISABLE_CLIPBOARD); if (savedState != null) { final Parcelable listState = savedState.getParcelable(PREF_LIST_STATE); if (listState != null) { Handler handler = new Handler(); // run the position restore delayed (as it won't work synchronously) handler.post( new Runnable() { @Override public void run() { final ListView listView = getListView(); listView.onRestoreInstanceState(listState); } }); } savedState = null; } }
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable(PREF_LIST_STATE, getListView().onSaveInstanceState()); }
@Override protected void onRestoreInstanceState(Bundle state) { super.onRestoreInstanceState(state); savedState = state; }
/** @see android.preference.PreferenceActivity#onCreate(android.os.Bundle) */ @Override protected void onCreate(Bundle savedInstanceState) { applyTheme(this); super.onCreate(savedInstanceState); }