Ejemplo n.º 1
0
  private void showTimezoneDialog() {
    final Activity activity = getActivity();
    if (activity == null) {
      return;
    }

    Bundle b = new Bundle();
    b.putLong(TimeZonePickerDialog.BUNDLE_START_TIME_MILLIS, System.currentTimeMillis());
    b.putString(TimeZonePickerDialog.BUNDLE_TIME_ZONE, Utils.getTimeZone(activity, null));

    FragmentManager fm = getActivity().getFragmentManager();
    TimeZonePickerDialog tzpd =
        (TimeZonePickerDialog) fm.findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
    if (tzpd != null) {
      tzpd.dismiss();
    }
    tzpd = new TimeZonePickerDialog();
    tzpd.setArguments(b);
    tzpd.setOnTimeZoneSetListener(this);
    tzpd.show(fm, FRAG_TAG_TIME_ZONE_PICKER);
  }
Ejemplo n.º 2
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();
  }