use of android.preference.PreferenceScreen in project Shuttle by timusus.
the class PreferenceManagerCompat method inflateFromResource.
/**
* Inflates a preference hierarchy from XML. If a preference hierarchy is
* given, the new preference hierarchies will be merged in.
*
* @param context The context of the resource.
* @param resId The resource ID of the XML to inflate.
* @param rootPreferences Optional existing hierarchy to merge the new
* hierarchies into.
* @return The root hierarchy (if one was not provided, the new hierarchy's
* root).
* @hide
*/
static PreferenceScreen inflateFromResource(PreferenceManager manager, Activity activity, int resId, PreferenceScreen screen) {
try {
Method m = PreferenceManager.class.getDeclaredMethod("inflateFromResource", Context.class, int.class, PreferenceScreen.class);
m.setAccessible(true);
return (PreferenceScreen) m.invoke(manager, activity, resId, screen);
} catch (Exception e) {
Log.w(TAG, "Couldn't call PreferenceManager.inflateFromResource by reflection", e);
}
return null;
}
use of android.preference.PreferenceScreen 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.PreferenceScreen in project Etar-Calendar by Etar-Group.
the class GeneralPreferences method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Activity activity = getActivity();
// Make sure to always use the same preferences file regardless of the package name
// we're running under
final PreferenceManager preferenceManager = getPreferenceManager();
final SharedPreferences sharedPreferences = getSharedPreferences(activity);
preferenceManager.setSharedPreferencesName(SHARED_PREFS_NAME);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.general_preferences);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
mAlert = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS);
mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE);
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator == null || !vibrator.hasVibrator()) {
PreferenceCategory mAlertGroup = (PreferenceCategory) preferenceScreen.findPreference(KEY_ALERTS_CATEGORY);
mAlertGroup.removePreference(mVibrate);
}
mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE);
String ringToneUri = Utils.getRingTonePreference(activity);
// Set the ringToneUri to the backup-able shared pref only so that
// the Ringtone dialog will open up with the correct value.
final Editor editor = preferenceScreen.getEditor();
editor.putString(GeneralPreferences.KEY_ALERTS_RINGTONE, ringToneUri).apply();
String ringtoneDisplayString = getRingtoneTitleFromUri(activity, ringToneUri);
mRingtone.setSummary(ringtoneDisplayString == null ? "" : ringtoneDisplayString);
mPopup = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_POPUP);
mUseHomeTZ = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HOME_TZ_ENABLED);
mTheme = (ListPreference) preferenceScreen.findPreference(KEY_THEME_PREF);
mDefaultStart = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_START);
mHideDeclined = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HIDE_DECLINED);
mWeekStart = (ListPreference) preferenceScreen.findPreference(KEY_WEEK_START_DAY);
mDayWeek = (ListPreference) preferenceScreen.findPreference(KEY_DAYS_PER_WEEK);
mDefaultReminder = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_REMINDER);
mHomeTZ = preferenceScreen.findPreference(KEY_HOME_TZ);
mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY);
buildSnoozeDelayEntries();
mTheme.setSummary(mTheme.getEntry());
mWeekStart.setSummary(mWeekStart.getEntry());
mDayWeek.setSummary(mDayWeek.getEntry());
mDefaultReminder.setSummary(mDefaultReminder.getEntry());
mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
mDefaultStart.setSummary(mDefaultStart.getEntry());
// This triggers an asynchronous call to the provider to refresh the data in shared pref
mTimeZoneId = Utils.getTimeZone(activity, null);
SharedPreferences prefs = CalendarUtils.getSharedPreferences(activity, Utils.SHARED_PREFS_NAME);
// off, we will explicitly read it.
if (!prefs.getBoolean(KEY_HOME_TZ_ENABLED, false)) {
mTimeZoneId = prefs.getString(KEY_HOME_TZ, Time.getCurrentTimezone());
}
mHomeTZ.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showTimezoneDialog();
return true;
}
});
if (mTzPickerUtils == null) {
mTzPickerUtils = new TimeZonePickerUtils(getActivity());
}
CharSequence timezoneName = mTzPickerUtils.getGmtDisplayName(getActivity(), mTimeZoneId, System.currentTimeMillis(), false);
mHomeTZ.setSummary(timezoneName != null ? timezoneName : mTimeZoneId);
TimeZonePickerDialog tzpd = (TimeZonePickerDialog) activity.getFragmentManager().findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
if (tzpd != null) {
tzpd.setOnTimeZoneSetListener(this);
}
migrateOldPreferences(sharedPreferences);
updateChildPreferences();
}
use of android.preference.PreferenceScreen 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.PreferenceScreen in project WordPress-Android by wordpress-mobile.
the class AppSettingsFragment method updateEditorSettings.
private void updateEditorSettings() {
if (!AppPrefs.isVisualEditorAvailable()) {
PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference(getActivity().getString(R.string.pref_key_account_settings_root));
PreferenceCategory editor = (PreferenceCategory) findPreference(getActivity().getString(R.string.pref_key_editor));
if (preferenceScreen != null && editor != null) {
preferenceScreen.removePreference(editor);
}
} else {
final ListPreference editorTypePreference = (ListPreference) findPreference(getActivity().getString(R.string.pref_key_editor_type));
// If user has Aztec preference from previous installation and it's not available anymore, don't use it
if (!AppPrefs.isAztecEditorAvailable() && "2".equals(editorTypePreference.getValue())) {
if (AppPrefs.isVisualEditorEnabled()) {
editorTypePreference.setValue("1");
} else {
editorTypePreference.setValue("0");
}
}
// if Aztec unavailable, only show the old list old of editors
if (!AppPrefs.isAztecEditorAvailable()) {
editorTypePreference.setEntries(R.array.editor_entries_without_aztec);
editorTypePreference.setEntryValues(R.array.editor_values_without_aztec);
}
editorTypePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(final Preference preference, final Object value) {
if (value != null) {
int index = Integer.parseInt(value.toString());
CharSequence[] entries = editorTypePreference.getEntries();
editorTypePreference.setSummary(entries[index]);
switch(index) {
case 1:
AppPrefs.setAztecEditorEnabled(false);
AppPrefs.setVisualEditorEnabled(true);
break;
case 2:
AppPrefs.setAztecEditorEnabled(true);
AppPrefs.setVisualEditorEnabled(false);
break;
default:
AppPrefs.setAztecEditorEnabled(false);
AppPrefs.setVisualEditorEnabled(false);
break;
}
return true;
} else {
return false;
}
}
});
String editorTypeKey = getString(R.string.pref_key_editor_type);
String editorTypeSetting = mSettings.getString(editorTypeKey, "");
if (!editorTypeSetting.equalsIgnoreCase("")) {
CharSequence[] entries = editorTypePreference.getEntries();
editorTypePreference.setSummary(entries[Integer.parseInt(editorTypeSetting)]);
}
}
}
Aggregations