Search in sources :

Example 41 with PreferenceCategory

use of android.preference.PreferenceCategory 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 42 with PreferenceCategory

use of android.preference.PreferenceCategory in project WordPress-Android by wordpress-mobile.

the class AppSettingsFragment method updateEditorSettings.

private void updateEditorSettings() {
    if (!AppPrefs.isVisualEditorAvailable()) {
        PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference(getActivity().getString(R.string.pref_key_account_settings_root));
        PreferenceCategory editor = (PreferenceCategory) findPreference(getActivity().getString(R.string.pref_key_editor));
        if (preferenceScreen != null && editor != null) {
            preferenceScreen.removePreference(editor);
        }
    } else {
        final ListPreference editorTypePreference = (ListPreference) findPreference(getActivity().getString(R.string.pref_key_editor_type));
        // If user has Aztec preference from previous installation and it's not available anymore, don't use it
        if (!AppPrefs.isAztecEditorAvailable() && "2".equals(editorTypePreference.getValue())) {
            if (AppPrefs.isVisualEditorEnabled()) {
                editorTypePreference.setValue("1");
            } else {
                editorTypePreference.setValue("0");
            }
        }
        // if Aztec unavailable, only show the old list old of editors
        if (!AppPrefs.isAztecEditorAvailable()) {
            editorTypePreference.setEntries(R.array.editor_entries_without_aztec);
            editorTypePreference.setEntryValues(R.array.editor_values_without_aztec);
        }
        editorTypePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(final Preference preference, final Object value) {
                if (value != null) {
                    int index = Integer.parseInt(value.toString());
                    CharSequence[] entries = editorTypePreference.getEntries();
                    editorTypePreference.setSummary(entries[index]);
                    switch(index) {
                        case 1:
                            AppPrefs.setAztecEditorEnabled(false);
                            AppPrefs.setVisualEditorEnabled(true);
                            break;
                        case 2:
                            AppPrefs.setAztecEditorEnabled(true);
                            AppPrefs.setVisualEditorEnabled(false);
                            break;
                        default:
                            AppPrefs.setAztecEditorEnabled(false);
                            AppPrefs.setVisualEditorEnabled(false);
                            break;
                    }
                    return true;
                } else {
                    return false;
                }
            }
        });
        String editorTypeKey = getString(R.string.pref_key_editor_type);
        String editorTypeSetting = mSettings.getString(editorTypeKey, "");
        if (!editorTypeSetting.equalsIgnoreCase("")) {
            CharSequence[] entries = editorTypePreference.getEntries();
            editorTypePreference.setSummary(entries[Integer.parseInt(editorTypeSetting)]);
        }
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) PreferenceCategory(android.preference.PreferenceCategory) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) ListPreference(android.preference.ListPreference)

Example 43 with PreferenceCategory

use of android.preference.PreferenceCategory in project WordPress-Android by wordpress-mobile.

the class NotificationsSettingsFragment method appendViewAllSitesOption.

private void appendViewAllSitesOption(Context context) {
    PreferenceCategory blogsCategory = (PreferenceCategory) findPreference(getString(R.string.pref_notification_blogs));
    PreferenceScreen prefScreen = getPreferenceManager().createPreferenceScreen(context);
    prefScreen.setTitle(R.string.all_your_sites);
    addSitesForViewAllSitesScreen(prefScreen);
    blogsCategory.addPreference(prefScreen);
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) PreferenceCategory(android.preference.PreferenceCategory)

Example 44 with PreferenceCategory

use of android.preference.PreferenceCategory in project WordPress-Android by wordpress-mobile.

the class NotificationsSettingsFragment method configureDotcomSettings.

private void configureDotcomSettings() {
    PreferenceCategory otherPreferenceCategory = (PreferenceCategory) findPreference(getString(R.string.pref_notification_other_category));
    NotificationsSettingsDialogPreference devicePreference = new NotificationsSettingsDialogPreference(getActivity(), null, Channel.DOTCOM, NotificationsSettings.Type.DEVICE, 0, mNotificationsSettings, mOnSettingsChangedListener);
    devicePreference.setTitle(R.string.notifications_account_emails);
    devicePreference.setDialogTitle(R.string.notifications_account_emails);
    devicePreference.setSummary(R.string.notifications_account_emails_summary);
    otherPreferenceCategory.addPreference(devicePreference);
}
Also used : PreferenceCategory(android.preference.PreferenceCategory)

Example 45 with PreferenceCategory

use of android.preference.PreferenceCategory in project WordPress-Android by wordpress-mobile.

the class NotificationsSettingsFragment method updateUIForNotificationsEnabledState.

// Updates the UI for preference screens based on if notifications are enabled or not
private void updateUIForNotificationsEnabledState() {
    if (mTypePreferenceCategories == null || mTypePreferenceCategories.size() == 0) {
        return;
    }
    for (final PreferenceCategory category : mTypePreferenceCategories) {
        if (mNotificationsEnabled && category.getPreferenceCount() > TYPE_COUNT) {
            category.removePreference(category.getPreference(TYPE_COUNT));
        } else if (!mNotificationsEnabled && category.getPreferenceCount() == TYPE_COUNT) {
            Preference disabledMessage = new Preference(getActivity());
            disabledMessage.setSummary(R.string.notifications_disabled);
            disabledMessage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent intent = new Intent();
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    Uri uri = Uri.fromParts("package", getActivity().getApplicationContext().getPackageName(), null);
                    intent.setData(uri);
                    startActivity(intent);
                    return true;
                }
            });
            category.addPreference(disabledMessage);
        }
        if (category.getPreferenceCount() >= TYPE_COUNT && category.getPreference(TYPE_COUNT - 1) != null) {
            category.getPreference(TYPE_COUNT - 1).setEnabled(mNotificationsEnabled);
        }
    }
}
Also used : PreferenceCategory(android.preference.PreferenceCategory) Preference(android.preference.Preference) Intent(android.content.Intent) Uri(android.net.Uri)

Aggregations

PreferenceCategory (android.preference.PreferenceCategory)81 Preference (android.preference.Preference)49 PreferenceScreen (android.preference.PreferenceScreen)31 ListPreference (android.preference.ListPreference)30 CheckBoxPreference (android.preference.CheckBoxPreference)26 Intent (android.content.Intent)19 EditTextPreference (android.preference.EditTextPreference)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 SwitchPreference (android.preference.SwitchPreference)8 ArrayList (java.util.ArrayList)7 Uri (android.net.Uri)6 SharedPreferences (android.content.SharedPreferences)5 Bundle (android.os.Bundle)5 View (android.view.View)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 Context (android.content.Context)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)3 RingtonePreference (android.preference.RingtonePreference)3 ListView (android.widget.ListView)3