use of android.preference.EditTextPreference in project k-9 by k9mail.
the class AccountSettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
try {
final Store store = mAccount.getRemoteStore();
mIsMoveCapable = store.isMoveCapable();
mIsPushCapable = store.isPushCapable();
mIsExpungeCapable = store.isExpungeCapable();
mIsSeenFlagSupported = store.isSeenFlagSupported();
} catch (Exception e) {
Timber.e(e, "Could not get remote store");
}
addPreferencesFromResource(R.xml.account_settings_preferences);
mMainScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_MAIN);
mAccountDescription = (EditTextPreference) findPreference(PREFERENCE_DESCRIPTION);
mAccountDescription.setSummary(mAccount.getDescription());
mAccountDescription.setText(mAccount.getDescription());
mAccountDescription.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
mAccountDescription.setSummary(summary);
mAccountDescription.setText(summary);
return false;
}
});
mMarkMessageAsReadOnView = (CheckBoxPreference) findPreference(PREFERENCE_MARK_MESSAGE_AS_READ_ON_VIEW);
mMarkMessageAsReadOnView.setChecked(mAccount.isMarkMessageAsReadOnView());
mMessageFormat = (ListPreference) findPreference(PREFERENCE_MESSAGE_FORMAT);
mMessageFormat.setValue(mAccount.getMessageFormat().name());
mMessageFormat.setSummary(mMessageFormat.getEntry());
mMessageFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mMessageFormat.findIndexOfValue(summary);
mMessageFormat.setSummary(mMessageFormat.getEntries()[index]);
mMessageFormat.setValue(summary);
return false;
}
});
mAlwaysShowCcBcc = (CheckBoxPreference) findPreference(PREFERENCE_ALWAYS_SHOW_CC_BCC);
mAlwaysShowCcBcc.setChecked(mAccount.isAlwaysShowCcBcc());
mMessageReadReceipt = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGE_READ_RECEIPT);
mMessageReadReceipt.setChecked(mAccount.isMessageReadReceiptAlways());
mAccountQuotePrefix = (EditTextPreference) findPreference(PREFERENCE_QUOTE_PREFIX);
mAccountQuotePrefix.setSummary(mAccount.getQuotePrefix());
mAccountQuotePrefix.setText(mAccount.getQuotePrefix());
mAccountQuotePrefix.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String value = newValue.toString();
mAccountQuotePrefix.setSummary(value);
mAccountQuotePrefix.setText(value);
return false;
}
});
mAccountDefaultQuotedTextShown = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT_QUOTED_TEXT_SHOWN);
mAccountDefaultQuotedTextShown.setChecked(mAccount.isDefaultQuotedTextShown());
mReplyAfterQuote = (CheckBoxPreference) findPreference(PREFERENCE_REPLY_AFTER_QUOTE);
mReplyAfterQuote.setChecked(mAccount.isReplyAfterQuote());
mStripSignature = (CheckBoxPreference) findPreference(PREFERENCE_STRIP_SIGNATURE);
mStripSignature.setChecked(mAccount.isStripSignature());
mComposingScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_COMPOSING);
Preference.OnPreferenceChangeListener quoteStyleListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final QuoteStyle style = QuoteStyle.valueOf(newValue.toString());
int index = mQuoteStyle.findIndexOfValue(newValue.toString());
mQuoteStyle.setSummary(mQuoteStyle.getEntries()[index]);
if (style == QuoteStyle.PREFIX) {
mComposingScreen.addPreference(mAccountQuotePrefix);
mComposingScreen.addPreference(mReplyAfterQuote);
} else if (style == QuoteStyle.HEADER) {
mComposingScreen.removePreference(mAccountQuotePrefix);
mComposingScreen.removePreference(mReplyAfterQuote);
}
return true;
}
};
mQuoteStyle = (ListPreference) findPreference(PREFERENCE_QUOTE_STYLE);
mQuoteStyle.setValue(mAccount.getQuoteStyle().name());
mQuoteStyle.setSummary(mQuoteStyle.getEntry());
mQuoteStyle.setOnPreferenceChangeListener(quoteStyleListener);
// Call the onPreferenceChange() handler on startup to update the Preference dialogue based
// upon the existing quote style setting.
quoteStyleListener.onPreferenceChange(mQuoteStyle, mAccount.getQuoteStyle().name());
mCheckFrequency = (ListPreference) findPreference(PREFERENCE_FREQUENCY);
mCheckFrequency.setValue(String.valueOf(mAccount.getAutomaticCheckIntervalMinutes()));
mCheckFrequency.setSummary(mCheckFrequency.getEntry());
mCheckFrequency.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mCheckFrequency.findIndexOfValue(summary);
mCheckFrequency.setSummary(mCheckFrequency.getEntries()[index]);
mCheckFrequency.setValue(summary);
return false;
}
});
mDisplayMode = (ListPreference) findPreference(PREFERENCE_DISPLAY_MODE);
mDisplayMode.setValue(mAccount.getFolderDisplayMode().name());
mDisplayMode.setSummary(mDisplayMode.getEntry());
mDisplayMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mDisplayMode.findIndexOfValue(summary);
mDisplayMode.setSummary(mDisplayMode.getEntries()[index]);
mDisplayMode.setValue(summary);
return false;
}
});
mSyncMode = (ListPreference) findPreference(PREFERENCE_SYNC_MODE);
mSyncMode.setValue(mAccount.getFolderSyncMode().name());
mSyncMode.setSummary(mSyncMode.getEntry());
mSyncMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mSyncMode.findIndexOfValue(summary);
mSyncMode.setSummary(mSyncMode.getEntries()[index]);
mSyncMode.setValue(summary);
return false;
}
});
mTargetMode = (ListPreference) findPreference(PREFERENCE_TARGET_MODE);
mTargetMode.setValue(mAccount.getFolderTargetMode().name());
mTargetMode.setSummary(mTargetMode.getEntry());
mTargetMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mTargetMode.findIndexOfValue(summary);
mTargetMode.setSummary(mTargetMode.getEntries()[index]);
mTargetMode.setValue(summary);
return false;
}
});
mDeletePolicy = (ListPreference) findPreference(PREFERENCE_DELETE_POLICY);
if (!mIsSeenFlagSupported) {
removeListEntry(mDeletePolicy, DeletePolicy.MARK_AS_READ.preferenceString());
}
mDeletePolicy.setValue(mAccount.getDeletePolicy().preferenceString());
mDeletePolicy.setSummary(mDeletePolicy.getEntry());
mDeletePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mDeletePolicy.findIndexOfValue(summary);
mDeletePolicy.setSummary(mDeletePolicy.getEntries()[index]);
mDeletePolicy.setValue(summary);
return false;
}
});
mExpungePolicy = (ListPreference) findPreference(PREFERENCE_EXPUNGE_POLICY);
if (mIsExpungeCapable) {
mExpungePolicy.setValue(mAccount.getExpungePolicy().name());
mExpungePolicy.setSummary(mExpungePolicy.getEntry());
mExpungePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mExpungePolicy.findIndexOfValue(summary);
mExpungePolicy.setSummary(mExpungePolicy.getEntries()[index]);
mExpungePolicy.setValue(summary);
return false;
}
});
} else {
((PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING)).removePreference(mExpungePolicy);
}
mSyncRemoteDeletions = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_REMOTE_DELETIONS);
mSyncRemoteDeletions.setChecked(mAccount.syncRemoteDeletions());
mSearchableFolders = (ListPreference) findPreference(PREFERENCE_SEARCHABLE_FOLDERS);
mSearchableFolders.setValue(mAccount.getSearchableFolders().name());
mSearchableFolders.setSummary(mSearchableFolders.getEntry());
mSearchableFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mSearchableFolders.findIndexOfValue(summary);
mSearchableFolders.setSummary(mSearchableFolders.getEntries()[index]);
mSearchableFolders.setValue(summary);
return false;
}
});
mDisplayCount = (ListPreference) findPreference(PREFERENCE_DISPLAY_COUNT);
mDisplayCount.setValue(String.valueOf(mAccount.getDisplayCount()));
mDisplayCount.setSummary(mDisplayCount.getEntry());
mDisplayCount.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mDisplayCount.findIndexOfValue(summary);
mDisplayCount.setSummary(mDisplayCount.getEntries()[index]);
mDisplayCount.setValue(summary);
return false;
}
});
mMessageAge = (ListPreference) findPreference(PREFERENCE_MESSAGE_AGE);
if (!mAccount.isSearchByDateCapable()) {
((PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING)).removePreference(mMessageAge);
} else {
mMessageAge.setValue(String.valueOf(mAccount.getMaximumPolledMessageAge()));
mMessageAge.setSummary(mMessageAge.getEntry());
mMessageAge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mMessageAge.findIndexOfValue(summary);
mMessageAge.setSummary(mMessageAge.getEntries()[index]);
mMessageAge.setValue(summary);
return false;
}
});
}
mMessageSize = (ListPreference) findPreference(PREFERENCE_MESSAGE_SIZE);
mMessageSize.setValue(String.valueOf(mAccount.getMaximumAutoDownloadMessageSize()));
mMessageSize.setSummary(mMessageSize.getEntry());
mMessageSize.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mMessageSize.findIndexOfValue(summary);
mMessageSize.setSummary(mMessageSize.getEntries()[index]);
mMessageSize.setValue(summary);
return false;
}
});
mAccountDefault = (CheckBoxPreference) findPreference(PREFERENCE_DEFAULT);
mAccountDefault.setChecked(mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()));
mAccountShowPictures = (ListPreference) findPreference(PREFERENCE_SHOW_PICTURES);
mAccountShowPictures.setValue("" + mAccount.getShowPictures());
mAccountShowPictures.setSummary(mAccountShowPictures.getEntry());
mAccountShowPictures.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mAccountShowPictures.findIndexOfValue(summary);
mAccountShowPictures.setSummary(mAccountShowPictures.getEntries()[index]);
mAccountShowPictures.setValue(summary);
return false;
}
});
mLocalStorageProvider = (ListPreference) findPreference(PREFERENCE_LOCAL_STORAGE_PROVIDER);
{
final Map<String, String> providers;
providers = StorageManager.getInstance(this).getAvailableProviders();
int i = 0;
final String[] providerLabels = new String[providers.size()];
final String[] providerIds = new String[providers.size()];
for (final Map.Entry<String, String> entry : providers.entrySet()) {
providerIds[i] = entry.getKey();
providerLabels[i] = entry.getValue();
i++;
}
mLocalStorageProvider.setEntryValues(providerIds);
mLocalStorageProvider.setEntries(providerLabels);
mLocalStorageProvider.setValue(mAccount.getLocalStorageProviderId());
mLocalStorageProvider.setSummary(providers.get(mAccount.getLocalStorageProviderId()));
mLocalStorageProvider.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
mLocalStorageProvider.setSummary(providers.get(newValue));
return true;
}
});
}
// IMAP-specific preferences
mSearchScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_SEARCH);
mCloudSearchEnabled = (CheckBoxPreference) findPreference(PREFERENCE_CLOUD_SEARCH_ENABLED);
mRemoteSearchNumResults = (ListPreference) findPreference(PREFERENCE_REMOTE_SEARCH_NUM_RESULTS);
mRemoteSearchNumResults.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference pref, Object newVal) {
updateRemoteSearchLimit((String) newVal);
return true;
}
});
//mRemoteSearchFullText = (CheckBoxPreference) findPreference(PREFERENCE_REMOTE_SEARCH_FULL_TEXT);
mPushPollOnConnect = (CheckBoxPreference) findPreference(PREFERENCE_PUSH_POLL_ON_CONNECT);
mIdleRefreshPeriod = (ListPreference) findPreference(PREFERENCE_IDLE_REFRESH_PERIOD);
mMaxPushFolders = (ListPreference) findPreference(PREFERENCE_MAX_PUSH_FOLDERS);
if (mIsPushCapable) {
mPushPollOnConnect.setChecked(mAccount.isPushPollOnConnect());
mCloudSearchEnabled.setChecked(mAccount.allowRemoteSearch());
String searchNumResults = Integer.toString(mAccount.getRemoteSearchNumResults());
mRemoteSearchNumResults.setValue(searchNumResults);
updateRemoteSearchLimit(searchNumResults);
//mRemoteSearchFullText.setChecked(mAccount.isRemoteSearchFullText());
mIdleRefreshPeriod.setValue(String.valueOf(mAccount.getIdleRefreshMinutes()));
mIdleRefreshPeriod.setSummary(mIdleRefreshPeriod.getEntry());
mIdleRefreshPeriod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mIdleRefreshPeriod.findIndexOfValue(summary);
mIdleRefreshPeriod.setSummary(mIdleRefreshPeriod.getEntries()[index]);
mIdleRefreshPeriod.setValue(summary);
return false;
}
});
mMaxPushFolders.setValue(String.valueOf(mAccount.getMaxPushFolders()));
mMaxPushFolders.setSummary(mMaxPushFolders.getEntry());
mMaxPushFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mMaxPushFolders.findIndexOfValue(summary);
mMaxPushFolders.setSummary(mMaxPushFolders.getEntries()[index]);
mMaxPushFolders.setValue(summary);
return false;
}
});
mPushMode = (ListPreference) findPreference(PREFERENCE_PUSH_MODE);
mPushMode.setValue(mAccount.getFolderPushMode().name());
mPushMode.setSummary(mPushMode.getEntry());
mPushMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mPushMode.findIndexOfValue(summary);
mPushMode.setSummary(mPushMode.getEntries()[index]);
mPushMode.setValue(summary);
return false;
}
});
} else {
PreferenceScreen incomingPrefs = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING);
incomingPrefs.removePreference((PreferenceScreen) findPreference(PREFERENCE_SCREEN_PUSH_ADVANCED));
incomingPrefs.removePreference((ListPreference) findPreference(PREFERENCE_PUSH_MODE));
mMainScreen.removePreference(mSearchScreen);
}
mAccountNotify = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY);
mAccountNotify.setChecked(mAccount.isNotifyNewMail());
mAccountNotifyNewMailMode = (ListPreference) findPreference(PREFERENCE_NOTIFY_NEW_MAIL_MODE);
mAccountNotifyNewMailMode.setValue(mAccount.getFolderNotifyNewMailMode().name());
mAccountNotifyNewMailMode.setSummary(mAccountNotifyNewMailMode.getEntry());
mAccountNotifyNewMailMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mAccountNotifyNewMailMode.findIndexOfValue(summary);
mAccountNotifyNewMailMode.setSummary(mAccountNotifyNewMailMode.getEntries()[index]);
mAccountNotifyNewMailMode.setValue(summary);
return false;
}
});
mAccountNotifySelf = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SELF);
mAccountNotifySelf.setChecked(mAccount.isNotifySelfNewMail());
mAccountNotifyContactsMailOnly = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_CONTACTS_MAIL_ONLY);
mAccountNotifyContactsMailOnly.setChecked(mAccount.isNotifyContactsMailOnly());
mAccountNotifySync = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SYNC);
mAccountNotifySync.setChecked(mAccount.isShowOngoing());
mAccountRingtone = (RingtonePreference) findPreference(PREFERENCE_RINGTONE);
// XXX: The following two lines act as a workaround for the RingtonePreference
// which does not let us set/get the value programmatically
SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
String currentRingtone = (!mAccount.getNotificationSetting().shouldRing() ? null : mAccount.getNotificationSetting().getRingtone());
prefs.edit().putString(PREFERENCE_RINGTONE, currentRingtone).commit();
mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE);
mAccountVibrate.setChecked(mAccount.getNotificationSetting().shouldVibrate());
mAccountVibratePattern = (ListPreference) findPreference(PREFERENCE_VIBRATE_PATTERN);
mAccountVibratePattern.setValue(String.valueOf(mAccount.getNotificationSetting().getVibratePattern()));
mAccountVibratePattern.setSummary(mAccountVibratePattern.getEntry());
mAccountVibratePattern.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mAccountVibratePattern.findIndexOfValue(summary);
mAccountVibratePattern.setSummary(mAccountVibratePattern.getEntries()[index]);
mAccountVibratePattern.setValue(summary);
doVibrateTest(preference);
return false;
}
});
mAccountVibrateTimes = (ListPreference) findPreference(PREFERENCE_VIBRATE_TIMES);
mAccountVibrateTimes.setValue(String.valueOf(mAccount.getNotificationSetting().getVibrateTimes()));
mAccountVibrateTimes.setSummary(String.valueOf(mAccount.getNotificationSetting().getVibrateTimes()));
mAccountVibrateTimes.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final String value = newValue.toString();
mAccountVibrateTimes.setSummary(value);
mAccountVibrateTimes.setValue(value);
doVibrateTest(preference);
return false;
}
});
mAccountLed = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFICATION_LED);
mAccountLed.setChecked(mAccount.getNotificationSetting().isLed());
mNotificationOpensUnread = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFICATION_OPENS_UNREAD);
mNotificationOpensUnread.setChecked(mAccount.goToUnreadMessageSearch());
new PopulateFolderPrefsTask().execute();
mChipColor = findPreference(PREFERENCE_CHIP_COLOR);
mChipColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
onChooseChipColor();
return false;
}
});
mLedColor = findPreference(PREFERENCE_LED_COLOR);
mLedColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
onChooseLedColor();
return false;
}
});
findPreference(PREFERENCE_COMPOSITION).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
onCompositionSettings();
return true;
}
});
findPreference(PREFERENCE_MANAGE_IDENTITIES).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
onManageIdentities();
return true;
}
});
findPreference(PREFERENCE_INCOMING).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
mIncomingChanged = true;
onIncomingSettings();
return true;
}
});
findPreference(PREFERENCE_OUTGOING).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
onOutgoingSettings();
return true;
}
});
mHasCrypto = K9.isOpenPgpProviderConfigured();
PreferenceScreen cryptoMenu = (PreferenceScreen) findPreference(PREFERENCE_CRYPTO);
if (mHasCrypto) {
mCryptoKey = (OpenPgpKeyPreference) findPreference(PREFERENCE_CRYPTO_KEY);
mCryptoKey.setValue(mAccount.getCryptoKey());
mCryptoKey.setOpenPgpProvider(K9.getOpenPgpProvider());
// TODO: other identities?
mCryptoKey.setDefaultUserId(OpenPgpApiHelper.buildUserId(mAccount.getIdentity(0)));
mCryptoKey.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
long value = (Long) newValue;
mCryptoKey.setValue(value);
return false;
}
});
cryptoMenu.setOnPreferenceClickListener(null);
} else {
cryptoMenu.setSummary(R.string.account_settings_no_openpgp_provider_configured);
cryptoMenu.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Dialog dialog = ((PreferenceScreen) preference).getDialog();
if (dialog != null) {
dialog.dismiss();
}
Toast.makeText(AccountSettings.this, R.string.no_crypto_provider_see_global, Toast.LENGTH_SHORT).show();
return true;
}
});
}
}
use of android.preference.EditTextPreference in project qksms by moezbhatti.
the class SettingsFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
setHasOptionsMenu(true);
mContext = (QKActivity) getActivity();
mPrefs = mContext.getPrefs();
mRes = mContext.getResources();
mContext.setTitle(R.string.title_settings);
mResource = args.getInt("category", R.xml.settings);
addPreferencesFromResource(mResource);
// Set `this` to be the preferences click/change listener for all the preferences.
PreferenceScreen screen = getPreferenceScreen();
for (int i = 0; i < screen.getPreferenceCount(); i++) {
Preference pref = screen.getPreference(i);
pref.setOnPreferenceClickListener(this);
pref.setOnPreferenceChangeListener(this);
// well.
if (pref instanceof PreferenceCategory) {
Stack<PreferenceCategory> stack = new Stack<>();
stack.push((PreferenceCategory) pref);
do {
PreferenceCategory category = stack.pop();
for (int j = 0; j < category.getPreferenceCount(); j++) {
Preference subPref = category.getPreference(j);
subPref.setOnPreferenceClickListener(this);
subPref.setOnPreferenceChangeListener(this);
if (subPref instanceof PreferenceCategory) {
stack.push((PreferenceCategory) subPref);
}
}
} while (!stack.isEmpty());
}
}
Preference icon = findPreference(ICON);
if (icon != null) {
icon.setOnPreferenceClickListener(this);
}
mThemeLed = findPreference(NOTIFICATION_LED_COLOR);
if (mThemeLed != null) {
mLedColors = new int[] { mRes.getColor(R.color.blue_light), mRes.getColor(R.color.purple_light), mRes.getColor(R.color.green_light), mRes.getColor(R.color.yellow_light), mRes.getColor(R.color.red_light), mRes.getColor(R.color.white_pure) };
mLedColorPickerDialog = new ColorPickerDialog();
mLedColorPickerDialog.initialize(R.string.pref_theme_led, mLedColors, Integer.parseInt(mPrefs.getString(NOTIFICATION_LED_COLOR, "-48060")), 3, 2);
mLedColorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
mPrefs.edit().putString(mThemeLed.getKey(), "" + color).apply();
onPreferenceChange(findPreference(mThemeLed.getKey()), color);
}
});
}
ListPreference font_family = (ListPreference) findPreference(FONT_FAMILY);
if (font_family != null) {
mFontFamilies = mRes.getStringArray(R.array.font_families);
font_family.setSummary(mFontFamilies[Integer.parseInt(font_family.getValue())]);
}
ListPreference font_size = (ListPreference) findPreference(FONT_SIZE);
if (font_size != null) {
mFontSizes = mRes.getStringArray(R.array.font_sizes);
font_size.setSummary(mFontSizes[Integer.parseInt(font_size.getValue())]);
}
ListPreference font_weight = (ListPreference) findPreference(FONT_WEIGHT);
if (font_weight != null) {
mFontWeights = mRes.getStringArray(R.array.font_weights);
int i = Integer.parseInt(font_weight.getValue());
font_weight.setSummary(mFontWeights[i == 2 ? 0 : 1]);
}
EditTextPreference deleteUnread = (EditTextPreference) findPreference(DELETE_UNREAD_MESSAGES);
if (deleteUnread != null) {
deleteUnread.setSummary(mContext.getString(R.string.pref_delete_old_messages_unread_summary, QKPreferences.getString(QKPreference.AUTO_DELETE_UNREAD)));
}
EditTextPreference deleteRead = (EditTextPreference) findPreference(DELETE_READ_MESSAGES);
if (deleteRead != null) {
deleteRead.setSummary(mContext.getString(R.string.pref_delete_old_messages_read_summary, QKPreferences.getString(QKPreference.AUTO_DELETE_READ)));
}
Preference day_start = findPreference(DAY_START);
if (day_start != null) {
day_start.setSummary(DateFormatter.getSummaryTimestamp(mContext, mPrefs.getString(DAY_START, "6:00")));
}
Preference night_start = findPreference(NIGHT_START);
if (night_start != null) {
night_start.setSummary(DateFormatter.getSummaryTimestamp(mContext, mPrefs.getString(NIGHT_START, "21:00")));
}
mMmscUrl = (EditTextPreference) findPreference(MMSC_URL);
if (mMmscUrl != null) {
mMmscUrl.setSummary(mMmscUrl.getText());
}
mMmsProxy = (EditTextPreference) findPreference(MMS_PROXY);
if (mMmsProxy != null) {
mMmsProxy.setSummary(mMmsProxy.getText());
}
mMmsPort = (EditTextPreference) findPreference(MMS_PORT);
if (mMmsPort != null) {
mMmsPort.setSummary(mMmsPort.getText());
}
mMaxMmsAttachmentSize = (ListPreference) findPreference(MAX_MMS_ATTACHMENT_SIZE);
if (mMaxMmsAttachmentSize != null) {
mMaxMmsAttachmentSizes = mRes.getStringArray(R.array.max_mms_attachment_sizes);
String value = mMaxMmsAttachmentSize.getValue();
String summary = mMaxMmsAttachmentSizes[mMaxMmsAttachmentSize.findIndexOfValue(value)];
mMaxMmsAttachmentSize.setSummary(summary);
}
Preference version = findPreference(VERSION);
if (version != null) {
String v = "unknown";
try {
PackageInfo info = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
v = info.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
version.setSummary(v);
}
// Status and nav bar tinting are only supported on kit kat or above.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
removePreference(CATEGORY_APPEARANCE_SYSTEM_BARS);
}
}
use of android.preference.EditTextPreference in project Etar-Calendar by Etar-Group.
the class QuickResponseSettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceScreen ps = getPreferenceManager().createPreferenceScreen(getActivity());
ps.setTitle(R.string.quick_response_settings_title);
mResponses = Utils.getQuickResponses(getActivity());
if (mResponses != null) {
mEditTextPrefs = new EditTextPreference[mResponses.length];
Arrays.sort(mResponses);
int i = 0;
for (String response : mResponses) {
EditTextPreference et = new EditTextPreference(getActivity());
et.setDialogTitle(R.string.quick_response_settings_edit_title);
// Display Text
et.setTitle(response);
// Value to edit
et.setText(response);
et.setOnPreferenceChangeListener(this);
mEditTextPrefs[i++] = et;
ps.addPreference(et);
}
} else {
Log.wtf(TAG, "No responses found");
}
setPreferenceScreen(ps);
}
use of android.preference.EditTextPreference in project apps-android-commons by commons-app.
the class SettingsFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
// Update spinner to show selected value as summary
ListPreference licensePreference = (ListPreference) findPreference(Prefs.DEFAULT_LICENSE);
licensePreference.setSummary(getString(Utils.licenseNameFor(licensePreference.getValue())));
// Keep summary updated when changing value
licensePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(getString(Utils.licenseNameFor((String) newValue)));
return true;
}
});
CheckBoxPreference themePreference = (CheckBoxPreference) findPreference("theme");
themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
getActivity().recreate();
return true;
}
});
final EditTextPreference uploadLimit = (EditTextPreference) findPreference("uploads");
final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(CommonsApplication.getInstance());
int uploads = sharedPref.getInt(Prefs.UPLOADS_SHOWING, 100);
uploadLimit.setText(uploads + "");
uploadLimit.setSummary(uploads + "");
uploadLimit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int value = Integer.parseInt(newValue.toString());
final SharedPreferences.Editor editor = sharedPref.edit();
if (value > 500) {
new AlertDialog.Builder(getActivity()).setTitle(R.string.maximum_limit).setMessage(R.string.maximum_limit_alert).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).setIcon(android.R.drawable.ic_dialog_alert).show();
editor.putInt(Prefs.UPLOADS_SHOWING, 500);
editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
uploadLimit.setSummary(500 + "");
uploadLimit.setText(500 + "");
} else {
editor.putInt(Prefs.UPLOADS_SHOWING, Integer.parseInt(newValue.toString()));
editor.putBoolean(Prefs.IS_CONTRIBUTION_COUNT_CHANGED, true);
uploadLimit.setSummary(newValue.toString());
}
editor.apply();
return true;
}
});
}
use of android.preference.EditTextPreference in project collect by opendatakit.
the class FormMetadataFragment method initPrefFromProp.
/**
* Initializes an EditTextPreference from a property.
*
* @param propertyManager a PropertyManager
* @param sharedPreferences shared preferences
* @param propMgrName the PropertyManager property name
* @param differentPrefKey the EditTextPreference key, null if the same as the propMgrName
*/
private void initPrefFromProp(PropertyManager propertyManager, SharedPreferences sharedPreferences, String propMgrName, String differentPrefKey) {
String propVal = propertyManager.getSingularProperty(propMgrName);
String prefKey = differentPrefKey == null ? propMgrName : differentPrefKey;
EditTextPreference textPref = (EditTextPreference) findPreference(prefKey);
if (propVal != null) {
textPref.setSummary(propVal);
textPref.setText(propVal);
}
if (textPref.isSelectable()) {
textPref.setOnPreferenceChangeListener(createChangeListener(sharedPreferences, prefKey));
}
}
Aggregations