use of android.preference.ListPreference in project OpenCamera by ageback.
the class MyPreferenceFragment method setupVideoResolutions.
/**
* Call to set up or update the video resolutions listpreference.
* Note that we don't care if the currently selected preference for video resolution is no
* longer in the supported list for the new fps value, we let the user select a new one, else
* the Preview will choose an appropriate resolution when the user exits settings.
*/
private void setupVideoResolutions(String fps_value) {
if (MyDebug.LOG)
Log.d(TAG, "setupVideoResolutions: " + fps_value);
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
MainActivity main_activity = (MainActivity) MyPreferenceFragment.this.getActivity();
// video_quality = main_activity.getPreview().getVideoQualityHander().getSupportedVideoQuality();
video_quality = main_activity.getPreview().getSupportedVideoQuality(fps_value);
if (video_quality == null || video_quality.size() == 0) {
Log.e(TAG, "can't find any supported video sizes for current fps!");
// fall back to unfiltered list
video_quality = main_activity.getPreview().getVideoQualityHander().getSupportedVideoQuality();
}
if (video_quality != null) {
CharSequence[] entries = new CharSequence[video_quality.size()];
CharSequence[] values = new CharSequence[video_quality.size()];
for (int i = 0; i < video_quality.size(); i++) {
entries[i] = main_activity.getPreview().getCamcorderProfileDescription(video_quality.get(i));
values[i] = video_quality.get(i);
}
ListPreference lp = preference_video_quality_lp;
lp.setEntries(entries);
lp.setEntryValues(values);
String video_quality_preference_key = PreferenceKeys.getVideoQualityPreferenceKey(cameraId, main_activity.getPreview().fpsIsHighSpeed(fps_value));
if (MyDebug.LOG)
Log.d(TAG, "video_quality_preference_key: " + video_quality_preference_key);
String video_quality_value = sharedPreferences.getString(video_quality_preference_key, "");
if (MyDebug.LOG)
Log.d(TAG, "video_quality_value: " + video_quality_value);
// set the key, so we save for the correct cameraId and high-speed setting
// this must be done before setting the value (otherwise the video resolutions preference won't be
// updated correctly when this is called from the callback when the user switches between
// normal and high speed frame rates
lp.setKey(video_quality_preference_key);
lp.setValue(video_quality_value);
} else {
Preference pref = findPreference("preference_video_quality");
PreferenceGroup pg = (PreferenceGroup) this.findPreference("preference_screen_video_settings");
pg.removePreference(pref);
}
}
use of android.preference.ListPreference in project PhoneProfiles 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());
setTitleStyle(preference, false, true, 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);
setTitleStyle(listPreference, index > 0, 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));
setTitleStyle(listPreference, 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 != Profile.NO_CHANGE_VALUE) && (iValue != Profile.SHARED_PROFILE_VALUE)) {
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));
setTitleStyle(listPreference, index > 0, 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);
setTitleStyle(listPreference, index > 0, 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(getActivity()));
setTitleStyle(preference, 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);
setTitleStyle(preference, bold, 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);
setTitleStyle(listPreference, index > 0, 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(getActivity()));
setTitleStyle(listPreference, 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);
setTitleStyle(listPreference, index > 0, 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);
setTitleStyle(listPreference, index > 0, 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);
setTitleStyle(listPreference, index > 0, 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));
setTitleStyle(listPreference, 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);
setTitleStyle(listPreference, index > 0, 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(getActivity()));
setTitleStyle(listPreference, 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);
setTitleStyle(listPreference, index > 0, 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));
setTitleStyle(listPreference, 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);
setTitleStyle(listPreference, index > 0, 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);
setTitleStyle(preference, iValue > 0, 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);
setTitleStyle(listPreference, value != defaultValue, 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");
setTitleStyle(checkBoxPreference, show, 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();
setTitleStyle(ringtonePreference, show, 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");
setTitleStyle(checkBoxPreference, show, 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");
setTitleStyle(checkBoxPreference, show, 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);
setTitleStyle(preference, change, 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);
setTitleStyle(preference, change, false, false);
setCategorySummary(preference, change);
}
}
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);
setTitleStyle(listPreference, 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);
setTitleStyle(listPreference, index > 0, 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);
setTitleStyle(preferenceScreen, index > 0, false, false);
}
}
}
use of android.preference.ListPreference in project Ruisi by freedom10086.
the class FragSetting method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.setting);
setting_user_tail = (EditTextPreference) findPreference("setting_user_tail");
setting_forums_url = (ListPreference) findPreference("setting_forums_url");
clearCache = findPreference("clean_cache");
sharedPreferences = getPreferenceScreen().getSharedPreferences();
boolean b = sharedPreferences.getBoolean("setting_show_tail", false);
setting_user_tail.setEnabled(b);
setting_user_tail.setSummary(sharedPreferences.getString("setting_user_tail", "无小尾巴"));
setting_forums_url.setSummary(App.IS_SCHOOL_NET ? "当前网络校园网,点击切换" : "当前网络校外网,点击切换");
setting_forums_url.setValue(App.IS_SCHOOL_NET ? "1" : "2");
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
PackageManager manager;
PackageInfo info = null;
manager = getActivity().getPackageManager();
try {
info = manager.getPackageInfo(getActivity().getPackageName(), 0);
} catch (Exception e) {
e.printStackTrace();
}
int version_code = 1;
String version_name = "1.0";
if (info != null) {
version_code = info.versionCode;
version_name = info.versionName;
}
findPreference("about_this").setSummary("当前版本" + version_name + " version code:" + version_code);
// [2016年6月9日更新][code:25]睿思手机客户端
// 更新逻辑 检查睿思帖子标题 比对版本号
final int finalversion_code = version_code;
findPreference("about_this").setOnPreferenceClickListener(preference -> {
Toast.makeText(getActivity(), "正在检查更新", Toast.LENGTH_SHORT).show();
HttpUtil.get(App.CHECK_UPDATE_URL, new ResponseHandler() {
@Override
public void onSuccess(byte[] response) {
String res = new String(response);
int ih = res.indexOf("keywords");
int h_start = res.indexOf('\"', ih + 15);
int h_end = res.indexOf('\"', h_start + 1);
String title = res.substring(h_start + 1, h_end);
if (title.contains("code")) {
int st = title.indexOf("code");
int code = GetId.getNumber(title.substring(st));
if (code > finalversion_code) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putLong(App.CHECK_UPDATE_KEY, System.currentTimeMillis());
editor.apply();
new AlertDialog.Builder(getActivity()).setTitle("检测到新版本").setMessage(title).setPositiveButton("查看", (dialog, which) -> PostActivity.open(getActivity(), App.CHECK_UPDATE_URL, "谁用了FREEDOM")).setNegativeButton("取消", null).setCancelable(true).create().show();
} else {
Toast.makeText(getActivity(), "暂无更新", Toast.LENGTH_SHORT).show();
}
}
}
});
return true;
});
findPreference("open_sourse").setOnPreferenceClickListener(preference -> {
IntentUtils.openBroswer(getActivity(), "https://github.com/freedom10086/Ruisi");
return false;
});
clearCache.setSummary("缓存大小:" + DataManager.getTotalCacheSize(getActivity()));
clearCache.setOnPreferenceClickListener(preference -> {
DataManager.cleanApplicationData(getActivity());
Toast.makeText(getActivity(), "缓存清理成功!请重新登陆", Toast.LENGTH_SHORT).show();
clearCache.setSummary("缓存大小:" + DataManager.getTotalCacheSize(getActivity()));
return false;
});
}
use of android.preference.ListPreference in project Pix-Art-Messenger by kriztan.
the class SettingsActivity method onStart.
@Override
public void onStart() {
super.onStart();
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
multiAccountPreference = mSettingsFragment.findPreference("enable_multi_accounts");
if (multiAccountPreference != null) {
isMultiAccountChecked = ((CheckBoxPreference) multiAccountPreference).isChecked();
}
if (Config.FORCE_ORBOT) {
PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
if (connectionOptions != null) {
expert.removePreference(connectionOptions);
}
}
PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen");
// this feature is only available on Huawei Android 6.
PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei");
if (huaweiPreferenceScreen != null) {
Intent intent = huaweiPreferenceScreen.getIntent();
// remove when Api version is above M (Version 6.0) or if the intent is not callable
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) {
PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general");
generalCategory.removePreference(huaweiPreferenceScreen);
if (generalCategory.getPreferenceCount() == 0) {
if (mainPreferenceScreen != null) {
mainPreferenceScreen.removePreference(generalCategory);
}
}
}
}
ListPreference automaticMessageDeletionList = (ListPreference) mSettingsFragment.findPreference(AUTOMATIC_MESSAGE_DELETION);
if (automaticMessageDeletionList != null) {
final int[] choices = getResources().getIntArray(R.array.automatic_message_deletion_values);
CharSequence[] entries = new CharSequence[choices.length];
CharSequence[] entryValues = new CharSequence[choices.length];
for (int i = 0; i < choices.length; ++i) {
Log.d(Config.LOGTAG, "resolving choice " + choices[i]);
entryValues[i] = String.valueOf(choices[i]);
if (choices[i] == 0) {
entries[i] = getString(R.string.never);
} else {
entries[i] = TimeframeUtils.resolve(this, 1000L * choices[i]);
}
}
automaticMessageDeletionList.setEntries(entries);
automaticMessageDeletionList.setEntryValues(entryValues);
}
final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
if (removeCertsPreference != null) {
removeCertsPreference.setOnPreferenceClickListener(preference -> {
final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
if (aliases.size() == 0) {
displayToast(getString(R.string.toast_no_trusted_certs));
return true;
}
final ArrayList selectedItems = new ArrayList<>();
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null, (dialog, indexSelected, isChecked) -> {
if (isChecked) {
selectedItems.add(indexSelected);
} else if (selectedItems.contains(indexSelected)) {
selectedItems.remove(Integer.valueOf(indexSelected));
}
if (selectedItems.size() > 0)
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
else {
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
}
});
dialogBuilder.setPositiveButton(getResources().getString(R.string.dialog_manage_certs_positivebutton), (dialog, which) -> {
int count = selectedItems.size();
if (count > 0) {
for (int i = 0; i < count; i++) {
try {
Integer item = Integer.valueOf(selectedItems.get(i).toString());
String alias = aliases.get(item);
mtm.deleteCertificate(alias);
} catch (KeyStoreException e) {
e.printStackTrace();
displayToast("Error: " + e.getLocalizedMessage());
}
}
if (xmppConnectionServiceBound) {
reconnectAccounts();
}
displayToast(getResources().getQuantityString(R.plurals.toast_delete_certificates, count, count));
}
});
dialogBuilder.setNegativeButton(getResources().getString(R.string.dialog_manage_certs_negativebutton), null);
AlertDialog removeCertsDialog = dialogBuilder.create();
removeCertsDialog.show();
removeCertsDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
return true;
});
}
final Preference exportLogsPreference = mSettingsFragment.findPreference("export_logs");
if (exportLogsPreference != null) {
exportLogsPreference.setOnPreferenceClickListener(preference -> {
if (hasStoragePermission(REQUEST_WRITE_LOGS)) {
startExport();
}
return true;
});
}
if (Config.ONLY_INTERNAL_STORAGE) {
final Preference cleanCachePreference = mSettingsFragment.findPreference("clean_cache");
if (cleanCachePreference != null) {
cleanCachePreference.setOnPreferenceClickListener(preference -> cleanCache());
}
final Preference cleanPrivateStoragePreference = mSettingsFragment.findPreference("clean_private_storage");
if (cleanPrivateStoragePreference != null) {
cleanPrivateStoragePreference.setOnPreferenceClickListener(preference -> cleanPrivateStorage());
}
}
final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities");
if (deleteOmemoPreference != null) {
deleteOmemoPreference.setOnPreferenceClickListener(preference -> deleteOmemoIdentities());
}
final Preference enableMultiAccountsPreference = mSettingsFragment.findPreference("enable_multi_accounts");
if (enableMultiAccountsPreference != null) {
Log.d(Config.LOGTAG, "Multi account checkbox checked: " + isMultiAccountChecked);
if (isMultiAccountChecked) {
enableMultiAccountsPreference.setEnabled(false);
/*
if (xmppConnectionServiceBound) { // todo doesn't work --> it seems the service is never bound
final List<Account> accounts = xmppConnectionService.getAccounts();
Log.d(Config.LOGTAG, "Disabled multi account: Number of accounts " + accounts.size());
if (accounts.size() > 1) {
Log.d(Config.LOGTAG, "Disabled multi account not possible because you have more than one account");
enableMultiAccountsPreference.setEnabled(false);
} else {
Log.d(Config.LOGTAG, "Disabled multi account possible because you have one account");
enableMultiAccountsPreference.setEnabled(true);
}
} else {
enableMultiAccountsPreference.setEnabled(false);
}
*/
} else {
enableMultiAccountsPreference.setEnabled(true);
enableMultiAccountsPreference.setOnPreferenceClickListener(preference -> {
enableMultiAccounts();
return true;
});
}
}
}
use of android.preference.ListPreference in project Thrift-box by Sash0k.
the class SettingsFragment method setPrefenceTitle.
// ============================================================================
/**
* Установка заголовка списка
*/
private void setPrefenceTitle(String tag) {
final Preference preference = findPreference(tag);
if (preference instanceof ListPreference) {
if (((ListPreference) preference).getEntry() != null) {
final CharSequence title = ((ListPreference) preference).getEntry();
preference.setSummary(title);
}
} else if (preference instanceof EditTextPreference) {
preference.setTitle(((EditTextPreference) preference).getText());
}
}
Aggregations