示例#1
0
  /** @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;
    }
  }
示例#2
0
  @Override
  protected void populateSecurityCategory(
      final PreferenceCategory security, final SharedPreferences defaults) {
    final Preference compatibilityMode =
        addCheckBoxPreference(
            security, COMPATIBILITY_MODE, R.string.CheckBox_CompatibilityMode, defaults, true);
    compatibilityMode.setSummary(R.string.Summary_CompatibilityMode);
    compatibilityMode.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          public boolean onPreferenceChange(final Preference pref, final Object newValue) {
            if (Boolean.FALSE == newValue) {
              new AlertDialog.Builder(SettingsActivity.this)
                  .setTitle(R.string.Title_SeedWarning)
                  .setMessage(R.string.Message_SeedWarning)
                  .setPositiveButton(android.R.string.ok, new DummyOnClickListener())
                  .setIcon(R.drawable.icon)
                  .show();
            }

            return true;
          }
        });
    final Preference setPrivateKey =
        addActionPreference(
            security,
            R.string.Action_ChangeSeed,
            new OnPreferenceClickListener() {
              public boolean onPreferenceClick(Preference pref) {
                final View view = View.inflate(SettingsActivity.this, R.layout.seed_entry, null);

                final EditText seed = (EditText) view.findViewById(R.id.Edit_SeedEntry);
                seed.setText(SeedHelper.getSeed(defaults));

                new AlertDialog.Builder(SettingsActivity.this)
                    .setTitle(R.string.Title_ChangeSeed)
                    .setView(view)
                    .setPositiveButton(
                        android.R.string.ok,
                        new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int which) {
                            SeedHelper.storeSeed(seed.getText().toString(), defaults);
                          }
                        })
                    .setNegativeButton(android.R.string.cancel, new DummyOnClickListener())
                    .setCancelable(true)
                    .setIcon(R.drawable.icon)
                    .show();
                return true;
              }
            },
            true);
    setPrivateKey.setSummary(R.string.Summary_ChangeSeed);
    final Preference disableClipboard =
        addCheckBoxPreference(
            security, DISABLE_CLIPBOARD, R.string.CheckBox_DisableClipboard, defaults, false);
    disableClipboard.setSummary(R.string.Summary_DisableClipboard);
    disableClipboard.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          public boolean onPreferenceChange(Preference preference, Object newVal) {
            Boolean newValue = (Boolean) newVal;

            disableConflictingPreferences(newValue, true, DEPS_DISABLE_CLIPBOARD);
            if (newValue) ((CheckBoxPreference) findPreference(AUTO_EXIT)).setChecked(false);

            return true;
          }
        });
  }