コード例 #1
0
 @Override
 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
   // Initialize the default interval if there is none:
   if (preference.getKey().equals(PREF_KEY_NOTIFICATION_TOGGLE)) {
     final CheckBoxPreference pref = (CheckBoxPreference) preference;
     if (pref.isChecked()) {
       AlarmsUtility.setupAlarm(getActivity());
       findPreference(PREF_KEY_NOTIFICATION_FREQUENCY_TOGGLE).setEnabled(true);
     } else {
       AlarmsUtility.cancelAlarm(getActivity());
       findPreference(PREF_KEY_NOTIFICATION_FREQUENCY_TOGGLE).setEnabled(false);
     }
   }
   return super.onPreferenceTreeClick(preferenceScreen, preference);
 }
コード例 #2
0
        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
          // Meaning a change in our radio buttons was made
          if (key.equals(PREF_KEY_NOTIFICATION_FREQUENCY_TOGGLE)) {
            listPreference.setSummary(
                getString(R.string.text_configured) + listPreference.getEntry().toString());
            if (listPreference.getEntry().equals(getString(R.string.text_daily))) {
              prefs.edit().putBoolean(AlarmsUtility.PREF_ALARM_DAILY, true).commit();
            } else {
              prefs.edit().putBoolean(AlarmsUtility.PREF_ALARM_DAILY, false).commit();
            }

            // Remove the current alarm
            AlarmsUtility.cancelAlarm(getActivity().getApplicationContext());
            // Reset one with the new frequency preference that has been set
            AlarmsUtility.setupAlarm(getActivity().getApplicationContext());
          }
        }