예제 #1
0
 private void updateRingtoneSummary(RingtonePreference preference, String uri) {
   Uri ringtoneUri = Uri.parse((String) uri);
   Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);
   if (ringtone != null) {
     preference.setSummary(ringtone.getTitle(this));
   } else {
     preference.setSummary("Silent");
   }
   onContentChanged();
 }
  private void updateRingtonePreferenceSummary(String ringtoneUrl) {

    if (ringtoneUrl != null && ringtoneUrl.trim().equals("")) {
      ringTonePreference.setSummary("Silent");
      return;
    }

    Uri ringtoneUri = Uri.parse(ringtoneUrl);
    Ringtone ringtone = RingtoneManager.getRingtone(this, ringtoneUri);

    String title = null;
    if (ringtone != null) {
      title = ringtone.getTitle(this);
    }

    ringTonePreference.setSummary(title);
  }
예제 #3
0
 /** Handles time zone preference changes */
 @Override
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   String tz;
   final Activity activity = getActivity();
   if (preference == mUseHomeTZ) {
     if ((Boolean) newValue) {
       tz = mTimeZoneId;
     } else {
       tz = CalendarCache.TIMEZONE_TYPE_AUTO;
     }
     Utils.setTimeZone(activity, tz);
     return true;
   } else if (preference == mHideDeclined) {
     mHideDeclined.setChecked((Boolean) newValue);
     Intent intent = new Intent(Utils.getWidgetScheduledUpdateAction(activity));
     intent.setDataAndType(CalendarContract.CONTENT_URI, Utils.APPWIDGET_DATA_TYPE);
     activity.sendBroadcast(intent);
     return true;
   } else if (preference == mWeekStart) {
     mWeekStart.setValue((String) newValue);
     mWeekStart.setSummary(mWeekStart.getEntry());
   } else if (preference == mDefaultReminder) {
     mDefaultReminder.setValue((String) newValue);
     mDefaultReminder.setSummary(mDefaultReminder.getEntry());
   } else if (preference == mSnoozeDelay) {
     mSnoozeDelay.setValue((String) newValue);
     mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
   } else if (preference == mRingtone) {
     if (newValue instanceof String) {
       Utils.setRingTonePreference(activity, (String) newValue);
       String ringtone = getRingtoneTitleFromUri(activity, (String) newValue);
       mRingtone.setSummary(ringtone == null ? "" : ringtone);
     }
     return true;
   } else if (preference == mVibrate) {
     mVibrate.setChecked((Boolean) newValue);
     return true;
   } else if (preference == mDefaultStart) {
     int i = mDefaultStart.findIndexOfValue((String) newValue);
     mDefaultStart.setSummary(mDefaultStart.getEntries()[i]);
     return true;
   } else {
     return true;
   }
   return false;
 }
 public boolean onPreferenceChange(Preference preference, Object newValue) {
   ContentResolver resolver = mContext.getContentResolver();
   if (preference == mQuietHoursTimeRange) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_START, mQuietHoursTimeRange.getStartTime());
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_END, mQuietHoursTimeRange.getEndTime());
     SmsCallHelper.scheduleService(mContext);
     return true;
   } else if (preference == mQuietHoursEnabled) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_ENABLED, (Boolean) newValue ? 1 : 0);
     SmsCallHelper.scheduleService(mContext);
     return true;
   } else if (preference == mQuietHoursMute) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_MUTE, (Boolean) newValue ? 1 : 0);
     return true;
   } else if (preference == mQuietHoursStill) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_STILL, (Boolean) newValue ? 1 : 0);
     return true;
   } else if (preference == mQuietHoursDim) {
     Settings.System.putInt(resolver, Settings.System.QUIET_HOURS_DIM, (Boolean) newValue ? 1 : 0);
     return true;
   } else if (preference == mQuietHoursHaptic) {
     Settings.System.putInt(
         resolver, Settings.System.QUIET_HOURS_HAPTIC, (Boolean) newValue ? 1 : 0);
     return true;
   } else if (preference == mRingtoneLoop) {
     mRingtoneLoop.setSummary(
         (Boolean) newValue
             ? R.string.quiet_hours_bypass_ringtone_loop_summary_on
             : R.string.quiet_hours_bypass_ringtone_loop_summary_off);
     return true;
   } else if (preference == mAutoSms) {
     mSmsPref = Integer.parseInt((String) newValue);
     mAutoSms.setSummary(mAutoSms.getEntries()[mSmsPref]);
     shouldDisplayTextPref();
     return true;
   } else if (preference == mAutoSmsCall) {
     mCallPref = Integer.parseInt((String) newValue);
     mAutoSmsCall.setSummary(mAutoSmsCall.getEntries()[mCallPref]);
     shouldDisplayTextPref();
     return true;
   } else if (preference == mSmsBypass) {
     mSmsBypassPref = Integer.parseInt((String) newValue);
     mSmsBypass.setSummary(mSmsBypass.getEntries()[mSmsBypassPref]);
     mSmsBypassCode.setEnabled(mSmsBypassPref != 0);
     shouldDisplayRingerPrefs();
     return true;
   } else if (preference == mCallBypass) {
     mCallBypassPref = Integer.parseInt((String) newValue);
     mCallBypass.setSummary(mCallBypass.getEntries()[mCallBypassPref]);
     mCallBypassNumber.setEnabled(mCallBypassPref != 0);
     shouldDisplayRingerPrefs();
     return true;
   } else if (preference == mCallBypassNumber) {
     int val = Integer.parseInt((String) newValue);
     mCallBypassNumber.setSummary(
         mCallBypassNumber.getEntries()[val - 2]
             + getResources().getString(R.string.quiet_hours_calls_required_summary));
     return true;
   } else if (preference == mBypassRingtone) {
     Uri val = Uri.parse((String) newValue);
     SharedPreferences.Editor editor = mPrefs.edit();
     Ringtone ringtone = RingtoneManager.getRingtone(mContext, val);
     if (ringtone != null) {
       editor.putString(KEY_BYPASS_RINGTONE, val.toString()).apply();
       mBypassRingtone.setSummary(ringtone.getTitle(mContext));
     } else {
       // No silent option, won't reach here
       editor.putString(KEY_BYPASS_RINGTONE, null).apply();
     }
     return true;
   }
   return false;
 }
  @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();
              }
            }
          };
    }
  }
예제 #6
0
  private void updatePrefences(Preference preference) {
    if (preference instanceof EditTextPreference) {
      if (preference.getKey().equals(MyApplication.PROFILE_NAME_KEY)) {

        EditTextPreference etp = (EditTextPreference) preference;
        if (etp.getText() != null && !etp.getText().equals("")) {
          profile.setName(etp.getText());
          isNameSet = true;
        }
        isReady = isNameSet && isRepeatingSet && isActivatoinSet;
        etp.setSummary(etp.getText());
      }
    } else if (preference instanceof ListPreference) {
      ListPreference lp = (ListPreference) preference;
      if (preference.getKey().equals(MyApplication.AUTO_ACTIVATION_KEY)) {

        lp.setSummary(lp.getEntry());
        int idx = Integer.parseInt(lp.getValue());
        switch (idx) {
          case 0:
            break;
          case 1:
            showFromDialog();
            profile.setAcivationMode(MyApplication.BY_TIME);

            // lp.setSummary(profile.getSubTitle());
            break;
          case 2:
            profile.setAcivationMode(MyApplication.BY_LOCATOIN);
            profile.setSubTitle("By Location ");

            isActivatoinSet = true;
            isReady = isNameSet && isRepeatingSet && isActivatoinSet;
            break;
        }
        lp.setSummary(profile.getSubTitle());

      } else if (preference.getKey().equals(MyApplication.RING_MODE_KEY)) {

        lp.setSummary(lp.getEntry());
        profile.setRingerMode(Integer.parseInt(lp.getValue()));

      } else if (preference.getKey().equals(MyApplication.CHANGE_WIFI_KEY)) {

        lp.setSummary(lp.getEntry());
        profile.setWifiMode(Integer.parseInt(lp.getValue()));

      } else if (preference.getKey().equals(MyApplication.CHANGE_BLUETOOEH_KEY)) {

        lp.setSummary(lp.getEntry());
        profile.setBlueToothMode(Integer.parseInt(lp.getValue()));
      }

    } else if (preference instanceof MultiSelectListPreference) {
      if (preference.getKey().equals(MyApplication.REPEATIN_DAYS_KEY)) {

        MultiSelectListPreference msp = (MultiSelectListPreference) preference;
        Set<String> selectedDays = msp.getValues();
        ArrayList<Integer> selectedIndx = new ArrayList<>();

        for (String day : selectedDays) {
          selectedIndx.add(Integer.parseInt(day));
          // Toast.makeText(MyApplication.APP_CNTX,day,Toast.LENGTH_SHORT).show();
        }
        Collections.sort(selectedIndx);
        String summary = "";
        for (int idx : selectedIndx) {
          summary += MyApplication.DAYS_OF_WEEK[idx % 7].substring(0, 3) + ",";
        }

        if (summary.length() == 0) summary = "NONE";

        msp.setSummary(summary);
        profile.setRepeatingDays(selectedIndx);
        isRepeatingSet = true;
        isReady = isNameSet && isRepeatingSet && isActivatoinSet;
      }
    } else if (preference instanceof CheckBoxPreference) {
      CheckBoxPreference cbp = (CheckBoxPreference) preference;
      if (cbp.getKey().equals(MyApplication.CHANGE_RINGTONE_KEY)) {

        findPreference(MyApplication.CHOOSE_RINGTONE_KEY).setEnabled(cbp.isChecked());
        profile.setChangeRingtone(cbp.isChecked());

      } else if (cbp.getKey().equals(MyApplication.CHANGE_NOTIFICATION_KEY)) {
        findPreference(MyApplication.CHOOSE_NOTIFICATION_KEY).setEnabled(cbp.isChecked());
        profile.setChangeNotiTone(cbp.isChecked());
      }
    } else if (preference instanceof RingtonePreference) {
      RingtonePreference rtp = (RingtonePreference) preference;
      if (rtp.getKey().equals(MyApplication.CHOOSE_RINGTONE_KEY)) {
        String ring = getRingToneURI();
        Uri uri = Uri.parse(ring);
        Ringtone ringtone = RingtoneManager.getRingtone(MyApplication.APP_CNTX, uri);
        if (ringtone != null) rtp.setSummary(ringtone.getTitle(getActivity()));

        profile.setRingeToneURI(ring);

      } else if (rtp.getKey().equals(MyApplication.CHOOSE_NOTIFICATION_KEY)) {
        String ring = getNotiToneURI();
        Uri uri = Uri.parse(ring);
        Ringtone ringtone = RingtoneManager.getRingtone(MyApplication.APP_CNTX, uri);
        if (ringtone != null) rtp.setSummary(ringtone.getTitle(getActivity()));

        profile.setNotiToneURI(ring);
      }
    }
  }
예제 #7
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    final Activity activity = getActivity();

    // Make sure to always use the same preferences file regardless of the package name
    // we're running under
    final PreferenceManager preferenceManager = getPreferenceManager();
    final SharedPreferences sharedPreferences = getSharedPreferences(activity);
    preferenceManager.setSharedPreferencesName(SHARED_PREFS_NAME);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.general_preferences);

    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    mAlert = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS);
    mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE);
    Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null || !vibrator.hasVibrator()) {
      PreferenceCategory mAlertGroup =
          (PreferenceCategory) preferenceScreen.findPreference(KEY_ALERTS_CATEGORY);
      mAlertGroup.removePreference(mVibrate);
    }

    mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE);
    String ringToneUri = Utils.getRingTonePreference(activity);

    // Set the ringToneUri to the backup-able shared pref only so that
    // the Ringtone dialog will open up with the correct value.
    final Editor editor = preferenceScreen.getEditor();
    editor.putString(GeneralPreferences.KEY_ALERTS_RINGTONE, ringToneUri).apply();

    String ringtoneDisplayString = getRingtoneTitleFromUri(activity, ringToneUri);
    mRingtone.setSummary(ringtoneDisplayString == null ? "" : ringtoneDisplayString);

    mPopup = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_POPUP);
    mUseHomeTZ = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HOME_TZ_ENABLED);
    mHideDeclined = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HIDE_DECLINED);
    mWeekStart = (ListPreference) preferenceScreen.findPreference(KEY_WEEK_START_DAY);
    mDefaultReminder = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_REMINDER);
    mHomeTZ = preferenceScreen.findPreference(KEY_HOME_TZ);

    mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY);
    buildSnoozeDelayEntries();

    mDefaultStart = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_START);
    mDefaultStart.setOnPreferenceChangeListener(this);

    mWeekStart.setSummary(mWeekStart.getEntry());
    mDefaultReminder.setSummary(mDefaultReminder.getEntry());
    mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
    mDefaultStart.setSummary(mDefaultStart.getEntry());

    // This triggers an asynchronous call to the provider to refresh the data in shared pref
    mTimeZoneId = Utils.getTimeZone(activity, null);

    SharedPreferences prefs = CalendarUtils.getSharedPreferences(activity, Utils.SHARED_PREFS_NAME);

    // Utils.getTimeZone will return the currentTimeZone instead of the one
    // in the shared_pref if home time zone is disabled. So if home tz is
    // off, we will explicitly read it.
    if (!prefs.getBoolean(KEY_HOME_TZ_ENABLED, false)) {
      mTimeZoneId = prefs.getString(KEY_HOME_TZ, Time.getCurrentTimezone());
    }

    mHomeTZ.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            showTimezoneDialog();
            return true;
          }
        });

    if (mTzPickerUtils == null) {
      mTzPickerUtils = new TimeZonePickerUtils(getActivity());
    }
    CharSequence timezoneName =
        mTzPickerUtils.getGmtDisplayName(
            getActivity(), mTimeZoneId, System.currentTimeMillis(), false);
    mHomeTZ.setSummary(timezoneName != null ? timezoneName : mTimeZoneId);

    TimeZonePickerDialog tzpd =
        (TimeZonePickerDialog)
            activity.getFragmentManager().findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
    if (tzpd != null) {
      tzpd.setOnTimeZoneSetListener(this);
    }

    migrateOldPreferences(sharedPreferences);

    updateChildPreferences();
  }