Search in sources :

Example 81 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project aware-client by denzilferreira.

the class Aware_Client method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    String value = "";
    Map<String, ?> keys = sharedPreferences.getAll();
    if (keys.containsKey(key)) {
        Object entry = keys.get(key);
        if (entry instanceof Boolean)
            value = String.valueOf(sharedPreferences.getBoolean(key, false));
        else if (entry instanceof String)
            value = String.valueOf(sharedPreferences.getString(key, "error"));
        else if (entry instanceof Integer)
            value = String.valueOf(sharedPreferences.getInt(key, 0));
    }
    Aware.setSetting(getApplicationContext(), key, value);
    Preference pref = findPreference(key);
    if (CheckBoxPreference.class.isInstance(pref)) {
        CheckBoxPreference check = (CheckBoxPreference) findPreference(key);
        check.setChecked(Aware.getSetting(getApplicationContext(), key).equals("true"));
        // update the parent to show active/inactive
        new SettingsSync().execute(pref);
        // Start/Stop sensor
        Aware.startAWARE(getApplicationContext());
    }
    if (EditTextPreference.class.isInstance(pref)) {
        EditTextPreference text = (EditTextPreference) findPreference(key);
        text.setText(Aware.getSetting(getApplicationContext(), key));
    }
    if (ListPreference.class.isInstance(pref)) {
        ListPreference list = (ListPreference) findPreference(key);
        list.setSummary(list.getEntry());
    }
}
Also used : EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) CheckBoxPreference(android.preference.CheckBoxPreference) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference)

Example 82 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project PhoneProfilesPlus by henrichg.

the class ProfilePreferencesNestedFragment method setSummary.

private void setSummary(String key, Object value) {
    if (key.equals(Profile.PREF_PROFILE_NAME)) {
        Preference preference = prefMng.findPreference(key);
        if (preference != null) {
            preference.setSummary(value.toString());
            GlobalGUIRoutines.setPreferenceTitleStyle(preference, false, true, false, false);
            setCategorySummary(preference, false);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_VOLUME_RINGER_MODE)) {
        String sValue = value.toString();
        ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
        if (listPreference != null) {
            int index = listPreference.findIndexOfValue(sValue);
            CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
            listPreference.setSummary(summary);
            GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
            setCategorySummary(listPreference, index > 0);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_VOLUME_ZEN_MODE)) {
        if (android.os.Build.VERSION.SDK_INT >= 21) {
            /*final boolean canEnableZenMode =
                        (PPNotificationListenerService.isNotificationListenerServiceEnabled(context.getApplicationContext()) ||
                         (PPApplication.isRooted(false) && PPApplication.settingsBinaryExists())
                        );*/
            final boolean canEnableZenMode = ActivateProfileHelper.canChangeZenMode(context.getApplicationContext(), false);
            if (!canEnableZenMode) {
                ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
                if (listPreference != null) {
                    listPreference.setEnabled(false);
                    listPreference.setSummary(getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + getResources().getString(R.string.preference_not_allowed_reason_not_configured_in_system_settings));
                    boolean a60 = (android.os.Build.VERSION.SDK_INT == 23) && Build.VERSION.RELEASE.equals("6.0");
                    @SuppressLint("InlinedApi") boolean addS = !((android.os.Build.VERSION.SDK_INT >= 23) && (!a60) && GlobalGUIRoutines.activityActionExists(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS, context));
                    GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, false, false, false, addS);
                    setCategorySummary(listPreference, false);
                }
            } else {
                String sValue = value.toString();
                ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
                if (listPreference != null) {
                    int iValue = Integer.parseInt(sValue);
                    int index = listPreference.findIndexOfValue(sValue);
                    CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
                    if ((iValue != 0) && (iValue != 99)) {
                        if (!((iValue == 6) && (android.os.Build.VERSION.SDK_INT < 23))) {
                            String[] summaryArray = getResources().getStringArray(R.array.zenModeSummaryArray);
                            summary = summary + " - " + summaryArray[iValue - 1];
                        }
                    }
                    listPreference.setSummary(summary);
                    final String sRingerMode = preferences.getString(Profile.PREF_PROFILE_VOLUME_RINGER_MODE, "");
                    int iRingerMode;
                    if (sRingerMode.isEmpty())
                        iRingerMode = 0;
                    else
                        iRingerMode = Integer.parseInt(sRingerMode);
                    if (iRingerMode == 5) {
                        boolean a60 = (android.os.Build.VERSION.SDK_INT == 23) && Build.VERSION.RELEASE.equals("6.0");
                        @SuppressLint("InlinedApi") boolean addS = !((android.os.Build.VERSION.SDK_INT >= 23) && (!a60) && GlobalGUIRoutines.activityActionExists(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS, context));
                        GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, addS);
                        setCategorySummary(listPreference, index > 0);
                    }
                    listPreference.setEnabled(iRingerMode == 5);
                }
            }
        }
    }
    if (key.equals(Profile.PREF_PROFILE_SOUND_RINGTONE_CHANGE) || key.equals(Profile.PREF_PROFILE_SOUND_NOTIFICATION_CHANGE) || key.equals(Profile.PREF_PROFILE_SOUND_ALARM_CHANGE)) {
        String sValue = value.toString();
        ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
        if (listPreference != null) {
            int index = listPreference.findIndexOfValue(sValue);
            CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
            listPreference.setSummary(summary);
            GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
            setCategorySummary(listPreference, index > 0);
        }
        setSummaryForNotificationVolume0();
    }
    if (key.equals(Profile.PREF_PROFILE_SOUND_RINGTONE) || key.equals(Profile.PREF_PROFILE_SOUND_NOTIFICATION) || key.equals(Profile.PREF_PROFILE_SOUND_ALARM)) {
        setSummaryForNotificationVolume0();
    }
    if (key.equals(Profile.PREF_PROFILE_DEVICE_AIRPLANE_MODE) || key.equals(Profile.PREF_PROFILE_DEVICE_AUTOSYNC) || key.equals(Profile.PREF_PROFILE_DEVICE_WIFI) || key.equals(Profile.PREF_PROFILE_DEVICE_BLUETOOTH) || key.equals(Profile.PREF_PROFILE_DEVICE_MOBILE_DATA) || key.equals(Profile.PREF_PROFILE_DEVICE_MOBILE_DATA_PREFS) || key.equals(Profile.PREF_PROFILE_DEVICE_GPS) || key.equals(Profile.PREF_PROFILE_DEVICE_NFC) || key.equals(Profile.PREF_PROFILE_DEVICE_WIFI_AP) || key.equals(Profile.PREF_PROFILE_DEVICE_WIFI_AP_PREFS) || key.equals(Profile.PREF_PROFILE_DEVICE_POWER_SAVE_MODE) || key.equals(Profile.PREF_PROFILE_DEVICE_NETWORK_TYPE) || key.equals(Profile.PREF_PROFILE_DEVICE_CONNECT_TO_SSID)) {
        if (key.equals(Profile.PREF_PROFILE_DEVICE_MOBILE_DATA)) {
            // set mobile data preference title
            ListPreference mobileDataPreference = (ListPreference) prefMng.findPreference(Profile.PREF_PROFILE_DEVICE_MOBILE_DATA);
            if (mobileDataPreference != null) {
                if (android.os.Build.VERSION.SDK_INT >= 21) {
                    mobileDataPreference.setTitle(R.string.profile_preferences_deviceMobileData_21);
                    mobileDataPreference.setDialogTitle(R.string.profile_preferences_deviceMobileData_21);
                } else {
                    mobileDataPreference.setTitle(R.string.profile_preferences_deviceMobileData);
                    mobileDataPreference.setDialogTitle(R.string.profile_preferences_deviceMobileData);
                }
            }
        }
        int canChange = Profile.isProfilePreferenceAllowed(key, context);
        if (canChange != PPApplication.PREFERENCE_ALLOWED) {
            Preference preference = prefMng.findPreference(key);
            if (preference != null) {
                preference.setEnabled(false);
                if (canChange == PPApplication.PREFERENCE_NOT_ALLOWED)
                    preference.setSummary(getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + PPApplication.getNotAllowedPreferenceReasonString(context));
                GlobalGUIRoutines.setPreferenceTitleStyle(preference, false, false, false, false);
                setCategorySummary(preference, false);
            }
        } else if (key.equals(Profile.PREF_PROFILE_DEVICE_CONNECT_TO_SSID)) {
            Preference preference = prefMng.findPreference(key);
            if (preference != null) {
                String sValue = value.toString();
                boolean bold = !sValue.equals(Profile.CONNECTTOSSID_JUSTANY);
                GlobalGUIRoutines.setPreferenceTitleStyle(preference, bold, false, false, false);
                setCategorySummary(preference, bold);
            }
        } else {
            String sValue = value.toString();
            ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
            if (listPreference != null) {
                int index = listPreference.findIndexOfValue(sValue);
                CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
                listPreference.setSummary(summary);
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
                setCategorySummary(listPreference, index > 0);
            }
        }
    }
    if (key.equals(Profile.PREF_PROFILE_DEVICE_KEYGUARD)) {
        ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
        if (listPreference != null) {
            int canChange = Profile.isProfilePreferenceAllowed(key, context);
            if (canChange != PPApplication.PREFERENCE_ALLOWED) {
                listPreference.setEnabled(false);
                if (canChange == PPApplication.PREFERENCE_NOT_ALLOWED)
                    listPreference.setSummary(getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + PPApplication.getNotAllowedPreferenceReasonString(context));
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, false, false, false, false);
                setCategorySummary(listPreference, false);
            } else {
                String sValue = value.toString();
                int index = listPreference.findIndexOfValue(sValue);
                CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
                listPreference.setSummary(summary);
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
                setCategorySummary(listPreference, index > 0);
            }
        }
    }
    if (key.equals(Profile.PREF_PROFILE_DEVICE_SCREEN_TIMEOUT)) {
        String sValue = value.toString();
        ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
        if (listPreference != null) {
            int index = listPreference.findIndexOfValue(sValue);
            CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
            listPreference.setSummary(summary);
            GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
            setCategorySummary(listPreference, index > 0);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_DEVICE_AUTOROTATE)) {
        String sValue = value.toString();
        ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
        if (listPreference != null) {
            int index = listPreference.findIndexOfValue(sValue);
            CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
            listPreference.setSummary(summary);
            GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
            setCategorySummary(listPreference, index > 0);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_DEVICE_WALLPAPER_CHANGE) || key.equals(Profile.PREF_PROFILE_DEVICE_MOBILE_DATA_PREFS) || key.equals(Profile.PREF_PROFILE_DEVICE_RUN_APPLICATION_CHANGE) || key.equals(Profile.PREF_PROFILE_DEVICE_LOCATION_SERVICE_PREFS) || key.equals(Profile.PREF_PROFILE_VOLUME_SPEAKER_PHONE) || key.equals(Profile.PREF_PROFILE_VIBRATION_ON_TOUCH) || key.equals(Profile.PREF_PROFILE_VIBRATE_WHEN_RINGING) || key.equals(Profile.PREF_PROFILE_DEVICE_WALLPAPER_FOR) || key.equals(Profile.PREF_PROFILE_LOCK_DEVICE) || key.equals(Profile.PREF_PROFILE_DEVICE_WIFI_AP_PREFS)) {
        int canChange = PPApplication.PREFERENCE_ALLOWED;
        if (key.equals(Profile.PREF_PROFILE_VIBRATE_WHEN_RINGING))
            canChange = Profile.isProfilePreferenceAllowed(key, context);
        if (canChange != PPApplication.PREFERENCE_ALLOWED) {
            ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
            if (listPreference != null) {
                listPreference.setEnabled(false);
                if (canChange == PPApplication.PREFERENCE_NOT_ALLOWED)
                    listPreference.setSummary(getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + PPApplication.getNotAllowedPreferenceReasonString(context));
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, false, false, false, false);
                setCategorySummary(listPreference, false);
            }
        } else {
            String sValue = value.toString();
            ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
            if (listPreference != null) {
                int index = listPreference.findIndexOfValue(sValue);
                CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
                listPreference.setSummary(summary);
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
                setCategorySummary(listPreference, index > 0);
            }
        }
    }
    if (key.equals(Profile.PREF_PROFILE_NOTIFICATION_LED)) {
        ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
        if (listPreference != null) {
            if (android.os.Build.VERSION.SDK_INT >= 23) {
                listPreference.setTitle(R.string.profile_preferences_notificationLed_23);
                listPreference.setDialogTitle(R.string.profile_preferences_notificationLed_23);
            } else {
                listPreference.setTitle(R.string.profile_preferences_notificationLed);
                listPreference.setDialogTitle(R.string.profile_preferences_notificationLed);
            }
            int canChange = Profile.isProfilePreferenceAllowed(key, context);
            if (canChange != PPApplication.PREFERENCE_ALLOWED) {
                listPreference.setEnabled(false);
                if (canChange == PPApplication.PREFERENCE_NOT_ALLOWED)
                    listPreference.setSummary(getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + PPApplication.getNotAllowedPreferenceReasonString(context));
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, false, false, false, false);
                setCategorySummary(listPreference, false);
            } else {
                String sValue = value.toString();
                int index = listPreference.findIndexOfValue(sValue);
                CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
                listPreference.setSummary(summary);
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
                setCategorySummary(listPreference, index > 0);
            }
        }
    }
    if (key.equals(Profile.PREF_PROFILE_HEADS_UP_NOTIFICATIONS)) {
        ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
        if (listPreference != null) {
            int canChange = Profile.isProfilePreferenceAllowed(key, context);
            if (canChange != PPApplication.PREFERENCE_ALLOWED) {
                listPreference.setEnabled(false);
                if (canChange == PPApplication.PREFERENCE_NOT_ALLOWED)
                    listPreference.setSummary(getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + PPApplication.getNotAllowedPreferenceReasonString(context));
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, false, false, false, false);
                setCategorySummary(listPreference, false);
            } else {
                String sValue = value.toString();
                int index = listPreference.findIndexOfValue(sValue);
                CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
                listPreference.setSummary(summary);
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
                setCategorySummary(listPreference, index > 0);
            }
        }
    }
    if (key.equals(Profile.PREF_PROFILE_DURATION)) {
        Preference preference = prefMng.findPreference(key);
        if (preference != null) {
            String sValue = value.toString();
            int iValue = 0;
            if (!sValue.isEmpty())
                iValue = Integer.valueOf(sValue);
            // preference.setSummary(sValue);
            GlobalGUIRoutines.setPreferenceTitleStyle(preference, iValue > 0, false, false, false);
            setCategorySummary(preference, iValue > 0);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_AFTER_DURATION_DO)) {
        String sValue = value.toString();
        ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
        if (listPreference != null) {
            int index = listPreference.findIndexOfValue(sValue);
            CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
            listPreference.setSummary(summary);
            /*String defaultValue =
                        getResources().getString(
                                GlobalGUIRoutines.getResourceId(key, "string", context));*/
            String defaultValue = Profile.defaultValuesString.get(key);
            GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, value != defaultValue, false, false, false);
            setCategorySummary(listPreference, /*index > 0*/
            false);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_ASK_FOR_DURATION)) {
        String sValue = value.toString();
        CheckBoxPreference checkBoxPreference = (CheckBoxPreference) prefMng.findPreference(key);
        if (checkBoxPreference != null) {
            boolean show = sValue.equals("true");
            GlobalGUIRoutines.setPreferenceTitleStyle(checkBoxPreference, show, false, false, false);
            setCategorySummary(checkBoxPreference, show);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_DURATION_NOTIFICATION_SOUND)) {
        String sValue = value.toString();
        RingtonePreference ringtonePreference = (RingtonePreference) prefMng.findPreference(key);
        if (ringtonePreference != null) {
            boolean show = !sValue.isEmpty();
            GlobalGUIRoutines.setPreferenceTitleStyle(ringtonePreference, show, false, false, false);
            setCategorySummary(ringtonePreference, show);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_DURATION_NOTIFICATION_VIBRATE)) {
        String sValue = value.toString();
        CheckBoxPreference checkBoxPreference = (CheckBoxPreference) prefMng.findPreference(key);
        if (checkBoxPreference != null) {
            boolean show = sValue.equals("true");
            GlobalGUIRoutines.setPreferenceTitleStyle(checkBoxPreference, show, false, false, false);
            setCategorySummary(checkBoxPreference, show);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_HIDE_STATUS_BAR_ICON)) {
        String sValue = value.toString();
        CheckBoxPreference checkBoxPreference = (CheckBoxPreference) prefMng.findPreference(key);
        if (checkBoxPreference != null) {
            boolean show = sValue.equals("true");
            GlobalGUIRoutines.setPreferenceTitleStyle(checkBoxPreference, show, false, false, false);
            setCategorySummary(checkBoxPreference, show);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_VOLUME_RINGTONE) || key.equals(Profile.PREF_PROFILE_VOLUME_NOTIFICATION) || key.equals(Profile.PREF_PROFILE_VOLUME_MEDIA) || key.equals(Profile.PREF_PROFILE_VOLUME_ALARM) || key.equals(Profile.PREF_PROFILE_VOLUME_SYSTEM) || key.equals(Profile.PREF_PROFILE_VOLUME_VOICE)) {
        Preference preference = prefMng.findPreference(key);
        if (preference != null) {
            String sValue = value.toString();
            boolean change = VolumeDialogPreference.changeEnabled(sValue);
            GlobalGUIRoutines.setPreferenceTitleStyle(preference, change, false, false, false);
            setCategorySummary(preference, change);
        }
    }
    if (key.equals(PREF_VOLUME_NOTIFICATION_VOLUME0)) {
        setSummaryForNotificationVolume0();
    }
    if (key.equals(Profile.PREF_PROFILE_DEVICE_BRIGHTNESS)) {
        Preference preference = prefMng.findPreference(key);
        if (preference != null) {
            String sValue = value.toString();
            boolean change = BrightnessDialogPreference.changeEnabled(sValue);
            GlobalGUIRoutines.setPreferenceTitleStyle(preference, change, false, false, false);
            setCategorySummary(preference, change);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_APPLICATION_DISABLE_WIFI_SCANNING) || key.equals(Profile.PREF_PROFILE_APPLICATION_DISABLE_BLUETOOTH_SCANNING) || key.equals(Profile.PREF_PROFILE_APPLICATION_DISABLE_LOCATION_SCANNING) || key.equals(Profile.PREF_PROFILE_APPLICATION_DISABLE_MOBILE_CELL_SCANNING) || key.equals(Profile.PREF_PROFILE_APPLICATION_DISABLE_ORIENTATION_SCANNING)) {
        ListPreference listPreference = (ListPreference) prefMng.findPreference(key);
        if (listPreference != null) {
            int canChange = Profile.isProfilePreferenceAllowed(key, context);
            if (canChange != PPApplication.PREFERENCE_ALLOWED) {
                listPreference.setEnabled(false);
                if (canChange == PPApplication.PREFERENCE_NOT_ALLOWED)
                    listPreference.setSummary(getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + PPApplication.getNotAllowedPreferenceReasonString(context));
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, false, false, false, false);
                setCategorySummary(listPreference, false);
            } else {
                String sValue = value.toString();
                int index = listPreference.findIndexOfValue(sValue);
                CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
                listPreference.setSummary(summary);
                GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
                setCategorySummary(listPreference, index > 0);
            }
        }
    }
    if (key.equals(PREF_FORCE_STOP_APPLICATIONS_INSTALL_EXTENDER)) {
        Preference preference = prefMng.findPreference(key);
        if (preference != null) {
            int extenderVersion = AccessibilityServiceBroadcastReceiver.isExtenderInstalled(context);
            if (extenderVersion == 0)
                preference.setSummary(R.string.profile_preferences_deviceForceStopApplications_PPPExtender_install_summary);
            else if (extenderVersion < PPApplication.VERSION_CODE_EXTENDER)
                preference.setSummary(R.string.event_preferences_applications_PPPExtender_new_version_summary);
            else
                preference.setSummary(R.string.event_preferences_applications_PPPExtender_upgrade_summary);
        }
    }
    if (key.equals(Profile.PREF_PROFILE_DEVICE_FORCE_STOP_APPLICATION_CHANGE) || key.equals(Profile.PREF_PROFILE_DEVICE_FORCE_STOP_APPLICATION_PACKAGE_NAME)) {
        Preference preferenceScreen = prefMng.findPreference(PREF_FORCE_STOP_APPLICATIONS_CATEGORY);
        if (preferenceScreen != null) {
            int index = 0;
            String sValue = "0";
            CharSequence categorySummary = "";
            ListPreference listPreference = (ListPreference) prefMng.findPreference(Profile.PREF_PROFILE_DEVICE_FORCE_STOP_APPLICATION_CHANGE);
            if (listPreference != null) {
                boolean ok = true;
                CharSequence changeSummary = "";
                int extenderVersion = AccessibilityServiceBroadcastReceiver.isExtenderInstalled(context);
                if (extenderVersion == 0) {
                    ok = false;
                    changeSummary = getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + getString(R.string.preference_not_allowed_reason_not_extender_installed);
                    categorySummary = changeSummary;
                } else if (extenderVersion < PPApplication.VERSION_CODE_EXTENDER) {
                    ok = false;
                    changeSummary = getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + getString(R.string.preference_not_allowed_reason_extender_not_upgraded);
                    categorySummary = changeSummary;
                } else if (!AccessibilityServiceBroadcastReceiver.isAccessibilityServiceEnabled(context)) {
                    ok = false;
                    changeSummary = getResources().getString(R.string.profile_preferences_device_not_allowed) + ": " + getString(R.string.preference_not_allowed_reason_not_enabled_accessibility_settings_for_extender);
                    categorySummary = changeSummary;
                }
                if (!ok) {
                    listPreference.setSummary(changeSummary);
                    GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, false, false, false, false);
                    setCategorySummary(listPreference, false);
                } else {
                    sValue = listPreference.getValue();
                    index = listPreference.findIndexOfValue(sValue);
                    changeSummary = (index >= 0) ? listPreference.getEntries()[index] : null;
                    categorySummary = changeSummary;
                    listPreference.setSummary(changeSummary);
                    GlobalGUIRoutines.setPreferenceTitleStyle(listPreference, index > 0, false, false, false);
                    setCategorySummary(listPreference, index > 0);
                }
            }
            if (sValue.equals("1")) {
                ApplicationsMultiSelectDialogPreference appMultiSelectPreference = (ApplicationsMultiSelectDialogPreference) prefMng.findPreference(Profile.PREF_PROFILE_DEVICE_FORCE_STOP_APPLICATION_PACKAGE_NAME);
                if (appMultiSelectPreference != null)
                    categorySummary = categorySummary + " • " + appMultiSelectPreference.getSummaryAMSDP();
            }
            preferenceScreen.setSummary(categorySummary);
            GlobalGUIRoutines.setPreferenceTitleStyle(preferenceScreen, (index > 0), false, false, false);
        }
    }
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) CheckBoxPreference(android.preference.CheckBoxPreference) SuppressLint(android.annotation.SuppressLint) ListPreference(android.preference.ListPreference) SuppressLint(android.annotation.SuppressLint)

Example 83 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project Osmand by osmandapp.

the class SettingsMonitoringActivity method createLiveSection.

private void createLiveSection(PreferenceScreen grp) {
    PreferenceCategory cat;
    cat = new PreferenceCategory(this);
    cat.setTitle(R.string.live_monitoring_m);
    grp.addPreference(cat);
    cat.addPreference(createEditTextPreference(settings.LIVE_MONITORING_URL, R.string.live_monitoring_url, R.string.live_monitoring_url_descr));
    final CheckBoxPreference liveMonitoring = createCheckBoxPreference(settings.LIVE_MONITORING, R.string.live_monitoring_m, R.string.live_monitoring_m_descr);
    cat.addPreference(liveMonitoring);
    cat.addPreference(createTimeListPreference(settings.LIVE_MONITORING_INTERVAL, SECONDS, MINUTES, 1000, R.string.live_monitoring_interval, R.string.live_monitoring_interval_descr));
    cat.addPreference(createTimeListPreference(settings.LIVE_MONITORING_MAX_INTERVAL_TO_SEND, null, MAX_INTERVAL_TO_SEND_MINUTES, 1000, R.string.live_monitoring_max_interval_to_send, R.string.live_monitoring_max_interval_to_send_desrc));
}
Also used : PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference)

Example 84 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project Osmand by osmandapp.

the class SettingsMonitoringActivity method createNotificationSection.

private void createNotificationSection(PreferenceScreen grp) {
    PreferenceCategory cat;
    cat = new PreferenceCategory(this);
    cat.setTitle(R.string.shared_string_notifications);
    grp.addPreference(cat);
    final CheckBoxPreference tripRecording = createCheckBoxPreference(settings.SHOW_TRIP_REC_NOTIFICATION, R.string.trip_rec_notification_settings, R.string.trip_rec_notification_settings_desc);
    cat.addPreference(tripRecording);
}
Also used : PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference)

Example 85 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project Osmand by osmandapp.

the class SettingsBaseActivity method updateAllSettings.

public void updateAllSettings() {
    for (OsmandPreference<Boolean> b : booleanPreferences.values()) {
        CheckBoxPreference pref = (CheckBoxPreference) screenPreferences.get(b.getId());
        pref.setChecked(b.get());
    }
    for (OsmandPreference<Integer> b : seekBarPreferences.values()) {
        SeekBarPreference pref = (SeekBarPreference) screenPreferences.get(b.getId());
        pref.setValue(b.get());
    }
    for (OsmandPreference<?> p : listPreferences.values()) {
        ListPreference listPref = (ListPreference) screenPreferences.get(p.getId());
        Map<String, ?> prefValues = listPrefValues.get(p.getId());
        String[] entryValues = new String[prefValues.size()];
        String[] entries = new String[prefValues.size()];
        int i = 0;
        for (Entry<String, ?> e : prefValues.entrySet()) {
            entries[i] = e.getKey();
            // case of null
            entryValues[i] = e.getValue() + "";
            i++;
        }
        listPref.setEntries(entries);
        listPref.setEntryValues(entryValues);
        listPref.setValue(p.get() + "");
    }
    for (OsmandPreference<String> s : editTextPreferences.values()) {
        EditTextPreference pref = (EditTextPreference) screenPreferences.get(s.getId());
        pref.setText(s.get());
    }
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) EditTextPreference(android.preference.EditTextPreference) SeekBarPreference(net.osmand.plus.views.SeekBarPreference)

Aggregations

CheckBoxPreference (android.preference.CheckBoxPreference)138 Preference (android.preference.Preference)70 ListPreference (android.preference.ListPreference)53 Intent (android.content.Intent)28 SharedPreferences (android.content.SharedPreferences)23 EditTextPreference (android.preference.EditTextPreference)23 PreferenceCategory (android.preference.PreferenceCategory)22 PreferenceScreen (android.preference.PreferenceScreen)22 ArrayList (java.util.ArrayList)17 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)13 DialogInterface (android.content.DialogInterface)11 Context (android.content.Context)10 PackageManager (android.content.pm.PackageManager)10 SuppressLint (android.annotation.SuppressLint)8 Bundle (android.os.Bundle)7 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)7 PreferenceManager (android.preference.PreferenceManager)7 File (java.io.File)7 AlertDialog (android.app.AlertDialog)6 Uri (android.net.Uri)6