use of android.preference.ListPreference in project qksms by moezbhatti.
the class SettingsFragment method onPreferenceChange.
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
String valueString = newValue == null ? "null" : newValue.toString();
if (key.equals(NOTIFICATION_LED_COLOR)) {
// Format the color as a nice string if it's the LED color.
valueString = ThemeManager.getColorString(Integer.parseInt(valueString));
}
Log.d(TAG, "onPreferenceChange key:" + key + " newValue: " + valueString);
AnalyticsManager.getInstance().sendEvent(AnalyticsManager.CATEGORY_PREFERENCE_CHANGE, key, valueString);
switch(key) {
case BACKGROUND:
ThemeManager.setTheme(ThemeManager.Theme.fromString((String) newValue));
break;
case STATUS_TINT:
ThemeManager.setStatusBarTintEnabled(mContext, (Boolean) newValue);
break;
case NAVIGATION_TINT:
ThemeManager.setNavigationBarTintEnabled(mContext, (Boolean) newValue);
break;
case FONT_FAMILY:
preference.setSummary(mFontFamilies[Integer.parseInt("" + newValue)]);
break;
case FONT_SIZE:
preference.setSummary(mFontSizes[Integer.parseInt("" + newValue)]);
break;
case FONT_WEIGHT:
int i = Integer.parseInt("" + newValue);
preference.setSummary(mFontWeights[i == 2 ? 0 : 1]);
break;
case COLOR_SENT:
ThemeManager.setSentBubbleColored((Boolean) newValue);
break;
case COLOR_RECEIVED:
ThemeManager.setReceivedBubbleColored((Boolean) newValue);
break;
case NIGHT_AUTO:
updateAlarmManager(mContext, (Boolean) newValue);
break;
case DAY_START:
case NIGHT_START:
updateAlarmManager(mContext, true);
break;
case DELETE_OLD_MESSAGES:
if ((Boolean) newValue) {
new QKDialog().setContext(mContext).setTitle(R.string.pref_delete_old_messages).setMessage(R.string.dialog_delete_old_messages).setPositiveButton(R.string.yes, v -> {
QKPreferences.setBoolean(QKPreference.AUTO_DELETE, true);
((CheckBoxPreference) preference).setChecked(true);
DeleteOldMessagesService.setupAutoDeleteAlarm(mContext);
mContext.makeToast(R.string.toast_deleting_old_messages);
}).setNegativeButton(R.string.cancel, null).show();
return false;
}
break;
case DELETE_UNREAD_MESSAGES:
preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_unread_summary, newValue));
break;
case DELETE_READ_MESSAGES:
preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_read_summary, newValue));
break;
case YAPPY:
if ((Boolean) newValue) {
try {
EndlessJabberInterface.EnableIntegration(mContext, EndlessJabber.class, true, false);
} catch (Exception e) {
e.printStackTrace();
}
if (!EndlessJabberInterface.IsInstalled(mContext)) {
EndlessJabberInterface.OpenGooglePlayLink(mContext);
}
} else {
try {
EndlessJabberInterface.DisableIntegration(mContext, EndlessJabber.class);
} catch (Exception e) {
e.printStackTrace();
}
}
break;
case QUICKCOMPOSE:
NotificationManager.initQuickCompose(getActivity(), (Boolean) newValue, !(Boolean) newValue);
break;
case MMSC_URL:
case MMS_PROXY:
case MMS_PORT:
preference.setSummary(newValue.toString());
break;
case MAX_MMS_ATTACHMENT_SIZE:
// Update the summary in the list preference
ListPreference listpref = (ListPreference) preference;
int index = listpref.findIndexOfValue((String) newValue);
preference.setSummary(mMaxMmsAttachmentSizes[index]);
// Update the SMS helper static class with the new option
SmsHelper.setMaxAttachmentSizeSetting(mContext, (String) newValue);
break;
case DELAY_DURATION:
try {
int duration = Integer.parseInt((String) newValue);
if (duration < 1 || duration > 30)
throw new Exception("Duration out of bounds");
} catch (Exception e) {
Toast.makeText(mContext, R.string.delayed_duration_bounds_error, Toast.LENGTH_SHORT).show();
}
break;
}
return true;
}
use of android.preference.ListPreference in project k-9 by k9mail.
the class FolderSettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String folderName = (String) getIntent().getSerializableExtra(EXTRA_FOLDER_NAME);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
try {
LocalStore localStore = mAccount.getLocalStore();
mFolder = localStore.getFolder(folderName);
mFolder.open(Folder.OPEN_MODE_RW);
} catch (MessagingException me) {
Timber.e(me, "Unable to edit folder %s preferences", folderName);
return;
}
boolean isPushCapable = false;
try {
Store store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
} catch (Exception e) {
Timber.e(e, "Could not get remote store");
}
addPreferencesFromResource(R.xml.folder_settings_preferences);
String displayName = FolderInfoHolder.getDisplayName(this, mAccount, mFolder.getName());
Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
category.setTitle(displayName);
mInTopGroup = (CheckBoxPreference) findPreference(PREFERENCE_IN_TOP_GROUP);
mInTopGroup.setChecked(mFolder.isInTopGroup());
mIntegrate = (CheckBoxPreference) findPreference(PREFERENCE_INTEGRATE);
mIntegrate.setChecked(mFolder.isIntegrate());
mDisplayClass = (ListPreference) findPreference(PREFERENCE_DISPLAY_CLASS);
mDisplayClass.setValue(mFolder.getDisplayClass().name());
mDisplayClass.setSummary(mDisplayClass.getEntry());
mDisplayClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mDisplayClass.findIndexOfValue(summary);
mDisplayClass.setSummary(mDisplayClass.getEntries()[index]);
mDisplayClass.setValue(summary);
return false;
}
});
mSyncClass = (ListPreference) findPreference(PREFERENCE_SYNC_CLASS);
mSyncClass.setValue(mFolder.getRawSyncClass().name());
mSyncClass.setSummary(mSyncClass.getEntry());
mSyncClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mSyncClass.findIndexOfValue(summary);
mSyncClass.setSummary(mSyncClass.getEntries()[index]);
mSyncClass.setValue(summary);
return false;
}
});
mPushClass = (ListPreference) findPreference(PREFERENCE_PUSH_CLASS);
mPushClass.setEnabled(isPushCapable);
mPushClass.setValue(mFolder.getRawPushClass().name());
mPushClass.setSummary(mPushClass.getEntry());
mPushClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mPushClass.findIndexOfValue(summary);
mPushClass.setSummary(mPushClass.getEntries()[index]);
mPushClass.setValue(summary);
return false;
}
});
mNotifyClass = (ListPreference) findPreference(PREFERENCE_NOTIFY_CLASS);
mNotifyClass.setValue(mFolder.getRawNotifyClass().name());
mNotifyClass.setSummary(mNotifyClass.getEntry());
mNotifyClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mNotifyClass.findIndexOfValue(summary);
mNotifyClass.setSummary(mNotifyClass.getEntries()[index]);
mNotifyClass.setValue(summary);
return false;
}
});
}
use of android.preference.ListPreference in project android_frameworks_base by ParanoidAndroid.
the class ListPreferenceTest method testListPreferenceSummaryFromEntries.
public void testListPreferenceSummaryFromEntries() {
String[] entries = { "one", "two", "three" };
String[] entryValues = { "1", "2", "3" };
ListPreference lp = new ListPreference(getContext());
lp.setEntries(entries);
lp.setEntryValues(entryValues);
lp.setValue(entryValues[1]);
assertTrue(lp.getSummary() == null);
lp.setSummary("%1$s");
assertEquals(entries[1], lp.getSummary());
lp.setValue(entryValues[2]);
assertEquals(entries[2], lp.getSummary());
lp.setSummary(null);
assertTrue(lp.getSummary() == null);
lp.setSummary("The color is %1$s");
assertEquals("The color is " + entries[2], lp.getSummary());
}
use of android.preference.ListPreference in project android_frameworks_base by ResurrectionRemix.
the class ListPreferenceTest method testListPreferenceSummaryFromEntries.
public void testListPreferenceSummaryFromEntries() {
String[] entries = { "one", "two", "three" };
String[] entryValues = { "1", "2", "3" };
ListPreference lp = new ListPreference(getContext());
lp.setEntries(entries);
lp.setEntryValues(entryValues);
lp.setValue(entryValues[1]);
assertTrue(lp.getSummary() == null);
lp.setSummary("%1$s");
assertEquals(entries[1], lp.getSummary());
lp.setValue(entryValues[2]);
assertEquals(entries[2], lp.getSummary());
lp.setSummary(null);
assertTrue(lp.getSummary() == null);
lp.setSummary("The color is %1$s");
assertEquals("The color is " + entries[2], lp.getSummary());
}
use of android.preference.ListPreference in project KISS by Neamar.
the class SettingsActivity method onCreate.
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
prefs = PreferenceManager.getDefaultSharedPreferences(this);
String theme = prefs.getString("theme", "light");
if (theme.contains("dark")) {
setTheme(R.style.SettingThemeDark);
}
// Do it here to make the transition as smooth as possible
if (prefs.getBoolean("force-portrait", true)) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
}
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
ListPreference iconsPack = (ListPreference) findPreference("icons-pack");
setListPreferenceIconsPacksData(iconsPack);
fixSummaries();
addExcludedAppSettings(prefs);
addSearchProvidersSelector(prefs);
UiTweaks.updateThemePrimaryColor(this);
// Notification color can't be updated before Lollipop
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
PreferenceScreen screen = (PreferenceScreen) findPreference("ui-holder");
Preference pref = findPreference("notification-bar-color");
screen.removePreference(pref);
}
}
Aggregations