Search in sources :

Example 21 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project Etar-Calendar by Etar-Group.

the class GeneralPreferences method onCreate.

@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);
    mTheme = (ListPreference) preferenceScreen.findPreference(KEY_THEME_PREF);
    mDefaultStart = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_START);
    mHideDeclined = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HIDE_DECLINED);
    mWeekStart = (ListPreference) preferenceScreen.findPreference(KEY_WEEK_START_DAY);
    mDayWeek = (ListPreference) preferenceScreen.findPreference(KEY_DAYS_PER_WEEK);
    mDefaultReminder = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_REMINDER);
    mHomeTZ = preferenceScreen.findPreference(KEY_HOME_TZ);
    mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY);
    buildSnoozeDelayEntries();
    mTheme.setSummary(mTheme.getEntry());
    mWeekStart.setSummary(mWeekStart.getEntry());
    mDayWeek.setSummary(mDayWeek.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);
    // 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();
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) Activity(android.app.Activity) PreferenceManager(android.preference.PreferenceManager) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference) RingtonePreference(android.preference.RingtonePreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) TimeZonePickerUtils(com.android.timezonepicker.TimeZonePickerUtils) TimeZonePickerDialog(com.android.timezonepicker.TimeZonePickerDialog) Vibrator(android.os.Vibrator) Editor(android.content.SharedPreferences.Editor)

Example 22 with OnPreferenceClickListener

use of android.preference.Preference.OnPreferenceClickListener in project newsrob by marianokamp.

the class SettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final EntryManager em = EntryManager.getInstance(this);
    addPreferencesFromResource(R.xml.settings);
    getPreferenceScreen().setOnPreferenceChangeListener(em);
    if (SDKVersionUtil.getVersion() < 8)
        disableSetting(em, EntryManager.SETTINGS_PLUGINS, "Froyo+");
    if (SDKVersionUtil.getVersion() < 11) {
        disableSetting(em, EntryManager.SETTINGS_HW_ACCEL_LISTS_ENABLED, "HC+ only");
        disableSetting(em, EntryManager.SETTINGS_HW_ACCEL_ADV_ENABLED, "HC+ only");
    }
    if (!em.isProVersion()) {
        disableSetting(em, EntryManager.SETTINGS_KEEP_STARRED);
        disableSetting(em, EntryManager.SETTINGS_KEEP_SHARED);
        disableSetting(em, EntryManager.SETTINGS_KEEP_NOTES);
        disableSetting(em, EntryManager.SETTINGS_UI_THEME);
        disableSetting(em, EntryManager.SETTINGS_SYNC_NEWSROB_ONLY_ENABLED);
    }
    if (em.shouldHWZoomControlsBeDisabled()) {
        Preference pref = getPreferenceScreen().findPreference(EntryManager.SETTINGS_HOVERING_ZOOM_CONTROLS_ENABLED);
        if (pref != null) {
            pref.setEnabled(false);
            if (pref.getSummary() != null)
                pref.setSummary("Disabled until HTC fixes a bug that hurts this function. Sorry.");
        }
    }
    if (em.shouldSyncInProgressNotificationBeDisabled()) {
        Preference pref = getPreferenceScreen().findPreference(EntryManager.SETTINGS_SYNC_IN_PROGRESS_NOTIFICATION);
        if (pref != null) {
            pref.setEnabled(false);
            if (pref.getSummary() != null)
                pref.setSummary("Disabled until HTC/Dell fixes a bug that hurts this function. Sorry.");
        }
    }
    if (em.shouldActionBarLocationOnlyAllowGone()) {
        ListPreference pref = (ListPreference) getPreferenceScreen().findPreference(EntryManager.SETTINGS_UI_ACTION_BAR_LOCATION);
        if (pref != null) {
            pref.setEnabled(false);
            CharSequence[] seq = pref.getEntries();
            CharSequence[] newSeq = new CharSequence[] { seq[2] };
            pref.setEntries(newSeq);
            getPreferenceScreen().removePreference(pref);
        }
    }
    final Preference p = getPreferenceScreen().findPreference(EntryManager.SETTINGS_USAGE_DATA_PERMISSION_GRANTED);
    p.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Dialog dialog = DashboardListActivity.createUsageDataCollectionPermissionDialog(em, SettingsActivity.this);
            dialog.show();
            return true;
        }
    });
}
Also used : OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) Preference(android.preference.Preference) ListPreference(com.newsrob.preference.ListPreference) Dialog(android.app.Dialog) ListPreference(com.newsrob.preference.ListPreference) EntryManager(com.newsrob.EntryManager)

Aggregations

OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)22 Preference (android.preference.Preference)21 CheckBoxPreference (android.preference.CheckBoxPreference)6 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)6 Intent (android.content.Intent)5 SharedPreferences (android.content.SharedPreferences)5 ListPreference (android.preference.ListPreference)5 DialogInterface (android.content.DialogInterface)4 PreferenceCategory (android.preference.PreferenceCategory)4 PreferenceScreen (android.preference.PreferenceScreen)4 AlertDialog (android.app.AlertDialog)3 Uri (android.net.Uri)3 Bundle (android.os.Bundle)3 View (android.view.View)3 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)3 SyncPreference (org.chromium.chrome.browser.preferences.SyncPreference)3 Activity (android.app.Activity)2 Dialog (android.app.Dialog)2 OnClickListener (android.content.DialogInterface.OnClickListener)2 EditTextPreference (android.preference.EditTextPreference)2