Example #1
0
  @Override
  protected void onResume() {
    super.onResume();
    getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

    lunchRingPref.setOnPreferenceChangeListener(this);
    dayRingPref.setOnPreferenceChangeListener(this);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    taskDatabaseMap = TaskDatabaseMap.getInstance(this);

    addPreferencesFromResource(R.xml.preferences);

    initDurationPreference(ConfigType.TASK_DURATION);
    initDurationPreference(ConfigType.BREAK_DURATION);
    initDurationPreference(ConfigType.EVERY_FOURTH_BREAK_DURATION);

    ringTonePreference =
        (RingtonePreference) findPreference(ConfigType.NOTIFICATION_RINGTONE.name());
    ringTonePreference.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          public boolean onPreferenceChange(Preference preference, Object newValue) {

            updateRingtonePreferenceSummary((String) newValue);
            taskDatabaseMap.getPreferences().updateRingtone((String) newValue);
            return false;
          }
        });

    String selectedRingtone = taskDatabaseMap.getPreferences().getRingtone();
    if (selectedRingtone != null) {
      updateRingtonePreferenceSummary(selectedRingtone);
    }
  }
 /** Sets up all the preference change listeners to use the specified listener. */
 private void setPreferenceListeners(OnPreferenceChangeListener listener) {
   mUseHomeTZ.setOnPreferenceChangeListener(listener);
   mHomeTZ.setOnPreferenceChangeListener(listener);
   mWeekStart.setOnPreferenceChangeListener(listener);
   mDefaultReminder.setOnPreferenceChangeListener(listener);
   mSnoozeDelay.setOnPreferenceChangeListener(listener);
   mRingtone.setOnPreferenceChangeListener(listener);
   mHideDeclined.setOnPreferenceChangeListener(listener);
   mVibrate.setOnPreferenceChangeListener(listener);
 }
Example #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences, false);
    addPreferencesFromResource(R.xml.preferences);

    Context context = getActivity();
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

    for (String prefName : new String[] {ALARM_SOUND, BACKUP_SOUND}) {
      try {
        String uriString = sharedPrefs.getString(prefName, null);
        Uri uri = Uri.parse(uriString);
        RingtonePreference preference = (RingtonePreference) findPreference(prefName);
        updateRingtonePreference(preference, uri);
        preference.setOnPreferenceChangeListener((OnPreferenceChangeListener) this);
      } catch (NullPointerException e) {

      }
    }

    mQuietHoursTimeRange = (TimeRangePreference) findPreference(KEY_QUIET_HOURS_TIMERANGE);
    mQuietHoursTimeRange.setStartTime(
        sharedPrefs.getInt(QUIET_HOURS_START, Settings.DEFAULT_QUIET_HOURS_START));
    mQuietHoursTimeRange.setEndTime(
        sharedPrefs.getInt(QUIET_HOURS_END, Settings.DEFAULT_QUIET_HOURS_END));

    mQuietHoursTimeRange.setOnPreferenceChangeListener((OnPreferenceChangeListener) this);

    mMaxAge = findPreference(MAX_AGE);
    int value = sharedPrefs.getInt(MAX_AGE, AlertsContract.DEFAULT_MAX_AGE);
    updateMaxAgePreference(mMaxAge, value);

    mMaxAge.setOnPreferenceChangeListener((OnPreferenceChangeListener) this);

    // Preference maxAge = findPreference("max_age");
    // maxAge.setOnPreferenceChangeListener((OnPreferenceChangeListener)context);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getPreferenceManager() != null) {
      addPreferencesFromResource(R.xml.quiet_hours_settings);

      mContext = getActivity().getApplicationContext();

      ContentResolver resolver = mContext.getContentResolver();

      PreferenceScreen prefSet = getPreferenceScreen();

      mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);

      // Load the preferences
      mQuietHoursNote = prefSet.findPreference(KEY_QUIET_HOURS_NOTE);
      mQuietHoursEnabled = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_ENABLED);
      mQuietHoursTimeRange =
          (TimeRangePreference) prefSet.findPreference(KEY_QUIET_HOURS_TIMERANGE);
      mQuietHoursMute = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_MUTE);
      mQuietHoursStill = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_STILL);
      mQuietHoursHaptic = (CheckBoxPreference) prefSet.findPreference(KEY_QUIET_HOURS_HAPTIC);
      mQuietHoursDim = (CheckBoxPreference) findPreference(KEY_QUIET_HOURS_DIM);
      mRingtoneLoop = (CheckBoxPreference) findPreference(KEY_LOOP_BYPASS_RINGTONE);
      mAutoSms = (ListPreference) findPreference(KEY_AUTO_SMS);
      mAutoSmsCall = (ListPreference) findPreference(KEY_AUTO_SMS_CALL);
      mAutoSmsMessage = (Preference) findPreference(KEY_AUTO_SMS_MESSAGE);
      mSmsBypass = (ListPreference) findPreference(KEY_SMS_BYPASS);
      mCallBypass = (ListPreference) findPreference(KEY_CALL_BYPASS);
      mCallBypassNumber = (ListPreference) findPreference(KEY_REQUIRED_CALLS);
      mSmsBypassCode = (Preference) findPreference(KEY_SMS_BYPASS_CODE);
      mBypassRingtone = (RingtonePreference) findPreference(KEY_BYPASS_RINGTONE);

      // Remove the "Incoming calls behaviour" note if the device does not support phone calls
      if (mQuietHoursNote != null
          && getResources().getBoolean(com.android.internal.R.bool.config_voice_capable) == false) {
        getPreferenceScreen().removePreference(mQuietHoursNote);
      }

      // Set the preference state and listeners where applicable
      mQuietHoursEnabled.setChecked(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_ENABLED, 0) == 1);
      mQuietHoursEnabled.setOnPreferenceChangeListener(this);
      mQuietHoursTimeRange.setTimeRange(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_START, 0),
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_END, 0));
      mQuietHoursTimeRange.setOnPreferenceChangeListener(this);
      mQuietHoursMute.setChecked(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_MUTE, 0) == 1);
      mQuietHoursMute.setOnPreferenceChangeListener(this);
      mQuietHoursStill.setChecked(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_STILL, 0) == 1);
      mQuietHoursStill.setOnPreferenceChangeListener(this);
      mQuietHoursHaptic.setChecked(
          Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_HAPTIC, 0) == 1);
      mQuietHoursHaptic.setOnPreferenceChangeListener(this);
      mRingtoneLoop.setOnPreferenceChangeListener(this);
      mAutoSms.setValue(mPrefs.getString(KEY_AUTO_SMS, "0"));
      mAutoSms.setOnPreferenceChangeListener(this);
      mAutoSmsCall.setValue(mPrefs.getString(KEY_AUTO_SMS_CALL, "0"));
      mAutoSmsCall.setOnPreferenceChangeListener(this);
      mSmsBypass.setValue(mPrefs.getString(KEY_SMS_BYPASS, "0"));
      mSmsBypass.setOnPreferenceChangeListener(this);
      mCallBypass.setValue(mPrefs.getString(KEY_CALL_BYPASS, "0"));
      mCallBypass.setOnPreferenceChangeListener(this);
      mCallBypassNumber.setValue(mPrefs.getString(KEY_REQUIRED_CALLS, "2"));
      mCallBypassNumber.setOnPreferenceChangeListener(this);
      mBypassRingtone.setOnPreferenceChangeListener(this);

      TelephonyManager telephonyManager =
          (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
      if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
        prefSet.removePreference((PreferenceGroup) findPreference("sms_respond"));
        prefSet.removePreference((PreferenceGroup) findPreference("quiethours_bypass"));
      } else {
        int callBypassNumber = Integer.parseInt(mPrefs.getString(KEY_REQUIRED_CALLS, "2"));
        boolean loopRingtone = mPrefs.getBoolean(KEY_LOOP_BYPASS_RINGTONE, true);
        mSmsBypassPref = Integer.parseInt(mPrefs.getString(KEY_SMS_BYPASS, "0"));
        mSmsPref = Integer.parseInt(mPrefs.getString(KEY_AUTO_SMS, "0"));
        mCallPref = Integer.parseInt(mPrefs.getString(KEY_AUTO_SMS_CALL, "0"));
        mCallBypassPref = Integer.parseInt(mPrefs.getString(KEY_CALL_BYPASS, "0"));
        Uri alertSoundUri = SmsCallHelper.returnUserRingtone(mContext);
        Ringtone ringtoneAlarm = RingtoneManager.getRingtone(mContext, alertSoundUri);
        mBypassRingtone.setSummary(ringtoneAlarm.getTitle(mContext));
        mRingtoneLoop.setChecked(loopRingtone);
        mRingtoneLoop.setSummary(
            loopRingtone
                ? R.string.quiet_hours_bypass_ringtone_loop_summary_on
                : R.string.quiet_hours_bypass_ringtone_loop_summary_off);
        mSmsBypass.setSummary(mSmsBypass.getEntries()[mSmsBypassPref]);
        mCallBypass.setSummary(mCallBypass.getEntries()[mCallBypassPref]);
        mCallBypassNumber.setSummary(
            mCallBypassNumber.getEntries()[callBypassNumber - 2]
                + getResources().getString(R.string.quiet_hours_calls_required_summary));
        mAutoSms.setSummary(mAutoSms.getEntries()[mSmsPref]);
        mAutoSmsCall.setSummary(mAutoSmsCall.getEntries()[mCallPref]);
        mCallBypassNumber.setEnabled(mCallBypassPref != 0);
        mSmsBypassCode.setEnabled(mSmsBypassPref != 0);
        shouldDisplayRingerPrefs();
        shouldDisplayTextPref();
        setSmsBypassCodeSummary();
      }

      // Remove the notification light setting if the device does not support it
      if (mQuietHoursDim != null
          && getResources().getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed)
              == false) {
        getPreferenceScreen().removePreference(mQuietHoursDim);
      } else {
        mQuietHoursDim.setChecked(
            Settings.System.getInt(resolver, Settings.System.QUIET_HOURS_DIM, 0) == 1);
        mQuietHoursDim.setOnPreferenceChangeListener(this);
      }

      mPreferencesChangeListener =
          new OnSharedPreferenceChangeListener() {
            public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
              if (key.equals(KEY_AUTO_SMS_CALL)
                  || key.equals(KEY_AUTO_SMS)
                  || key.equals(KEY_CALL_BYPASS)
                  || key.equals(KEY_SMS_BYPASS)) {
                SmsCallHelper.scheduleService(mContext);
              }
              if (key.equals(KEY_SMS_BYPASS_CODE)) {
                setSmsBypassCodeSummary();
              }
            }
          };
    }
  }