use of android.support.v7.preference.ListPreference in project material-dialogs by afollestad.
the class MaterialListPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
if (getEntries() == null || getEntryValues() == null) {
throw new IllegalStateException("ListPreference requires an entries array and an entryValues array.");
}
int preselect = findIndexOfValue(getValue());
MaterialDialog.Builder builder = new MaterialDialog.Builder(context).title(getDialogTitle()).icon(getDialogIcon()).dismissListener(this).onAny(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
switch(which) {
default:
MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
break;
case NEUTRAL:
MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
break;
case NEGATIVE:
MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
break;
}
}
}).negativeText(getNegativeButtonText()).items(getEntries()).autoDismiss(// immediately close the dialog after selection
true).itemsCallbackSingleChoice(preselect, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
onClick(null, DialogInterface.BUTTON_POSITIVE);
if (which >= 0 && getEntryValues() != null) {
try {
Field clickedIndex = ListPreference.class.getDeclaredField("mClickedDialogEntryIndex");
clickedIndex.setAccessible(true);
clickedIndex.set(MaterialListPreference.this, which);
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
});
final View contentView = onCreateDialogView();
if (contentView != null) {
onBindDialogView(contentView);
builder.customView(contentView, false);
} else {
builder.content(getDialogMessage());
}
PrefUtil.registerOnActivityDestroyListener(this, this);
dialog = builder.build();
if (state != null) {
dialog.onRestoreInstanceState(state);
}
onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
dialog.show();
}
use of android.support.v7.preference.ListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class NetworkTrafficSettings method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.network_traffic_settings);
ContentResolver resolver = getActivity().getContentResolver();
PreferenceScreen prefSet = getPreferenceScreen();
loadResources();
mNetTrafficState = (ListPreference) prefSet.findPreference(NETWORK_TRAFFIC_STATE);
mNetTrafficUnit = (ListPreference) prefSet.findPreference(NETWORK_TRAFFIC_UNIT);
mNetTrafficPeriod = (ListPreference) prefSet.findPreference(NETWORK_TRAFFIC_PERIOD);
mNetTrafficAutohide = (SwitchPreference) prefSet.findPreference(NETWORK_TRAFFIC_AUTOHIDE);
mNetTrafficAutohide.setChecked((Settings.System.getInt(getContentResolver(), Settings.System.NETWORK_TRAFFIC_AUTOHIDE, 0) == 1));
mNetTrafficAutohide.setOnPreferenceChangeListener(this);
mNetTrafficAutohideThreshold = (SeekBarPreference) prefSet.findPreference(NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD);
int netTrafficAutohideThreshold = Settings.System.getInt(resolver, Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, 10);
mNetTrafficAutohideThreshold.setValue(netTrafficAutohideThreshold / 1);
mNetTrafficAutohideThreshold.setOnPreferenceChangeListener(this);
mNetTrafficColor = (ColorPickerPreference) prefSet.findPreference(NETWORK_TRAFFIC_COLOR);
mNetTrafficColor.setOnPreferenceChangeListener(this);
int intColor = Settings.System.getInt(getContentResolver(), Settings.System.NETWORK_TRAFFIC_COLOR, 0xffffffff);
String hexColor = String.format("#%08x", (0xffffffff & intColor));
mNetTrafficColor.setSummary(hexColor);
mNetTrafficColor.setNewPreviewColor(intColor);
// TrafficStats will return UNSUPPORTED if the device does not support it.
if (TrafficStats.getTotalTxBytes() != TrafficStats.UNSUPPORTED && TrafficStats.getTotalRxBytes() != TrafficStats.UNSUPPORTED) {
mNetTrafficVal = Settings.System.getInt(resolver, Settings.System.NETWORK_TRAFFIC_STATE, 0);
int intIndex = mNetTrafficVal & (MASK_UP + MASK_DOWN);
intIndex = mNetTrafficState.findIndexOfValue(String.valueOf(intIndex));
if (intIndex <= 0) {
mNetTrafficUnit.setEnabled(false);
mNetTrafficPeriod.setEnabled(false);
mNetTrafficAutohide.setEnabled(false);
mNetTrafficAutohideThreshold.setEnabled(false);
mNetTrafficColor.setEnabled(false);
}
mNetTrafficState.setValueIndex(intIndex >= 0 ? intIndex : 0);
mNetTrafficState.setSummary(mNetTrafficState.getEntry());
mNetTrafficState.setOnPreferenceChangeListener(this);
mNetTrafficUnit.setValueIndex(getBit(mNetTrafficVal, MASK_UNIT) ? 1 : 0);
mNetTrafficUnit.setSummary(mNetTrafficUnit.getEntry());
mNetTrafficUnit.setOnPreferenceChangeListener(this);
intIndex = (mNetTrafficVal & MASK_PERIOD) >>> 16;
intIndex = mNetTrafficPeriod.findIndexOfValue(String.valueOf(intIndex));
mNetTrafficPeriod.setValueIndex(intIndex >= 0 ? intIndex : 1);
mNetTrafficPeriod.setSummary(mNetTrafficPeriod.getEntry());
mNetTrafficPeriod.setOnPreferenceChangeListener(this);
} else {
prefSet.removePreference(findPreference(NETWORK_TRAFFIC_STATE));
prefSet.removePreference(findPreference(NETWORK_TRAFFIC_UNIT));
prefSet.removePreference(findPreference(NETWORK_TRAFFIC_PERIOD));
prefSet.removePreference(findPreference(NETWORK_TRAFFIC_AUTOHIDE));
prefSet.removePreference(findPreference(NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD));
prefSet.removePreference(findPreference(NETWORK_TRAFFIC_COLOR));
}
}
use of android.support.v7.preference.ListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class RecentsClearAll method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.rr_recents_clear_all_fragment);
final ContentResolver resolver = getContentResolver();
final PreferenceScreen prefSet = getPreferenceScreen();
final Resources res = getResources();
mRecentsClearAll = (SwitchPreference) prefSet.findPreference(SHOW_CLEAR_ALL_RECENTS);
mRecentsClearAll.setChecked(Settings.System.getIntForUser(resolver, Settings.System.SHOW_CLEAR_ALL_RECENTS, 1, UserHandle.USER_CURRENT) == 1);
mRecentsClearAll.setOnPreferenceChangeListener(this);
mRecentsClearAllLocation = (ListPreference) prefSet.findPreference(RECENTS_CLEAR_ALL_LOCATION);
int location = Settings.System.getIntForUser(resolver, Settings.System.RECENTS_CLEAR_ALL_LOCATION, 3, UserHandle.USER_CURRENT);
mRecentsClearAllLocation.setValue(String.valueOf(location));
mRecentsClearAllLocation.setSummary(mRecentsClearAllLocation.getEntry());
mRecentsClearAllLocation.setOnPreferenceChangeListener(this);
}
use of android.support.v7.preference.ListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class QsPullDown method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.rr_qs_pulldown);
mContext = getActivity().getApplicationContext();
mContentRes = getActivity().getContentResolver();
final Resources res = getResources();
PreferenceScreen prefs = getPreferenceScreen();
ContentResolver resolver = getActivity().getContentResolver();
mSmartPulldown = (ListPreference) findPreference(PREF_SMART_PULLDOWN);
mSmartPulldown.setOnPreferenceChangeListener(this);
int smartPulldown = Settings.System.getInt(resolver, Settings.System.QS_SMART_PULLDOWN, 0);
mSmartPulldown.setValue(String.valueOf(smartPulldown));
updateSmartPulldownSummary(smartPulldown);
mQuickPulldown = (ListPreference) findPreference(STATUS_BAR_QUICK_QS_PULLDOWN);
int quickPulldown = CMSettings.System.getInt(resolver, CMSettings.System.STATUS_BAR_QUICK_QS_PULLDOWN, 0);
mQuickPulldown.setValue(String.valueOf(quickPulldown));
if (quickPulldown == 0) {
// quick pulldown deactivated
mQuickPulldown.setSummary(res.getString(R.string.status_bar_quick_qs_pulldown_off));
} else {
String direction = res.getString(quickPulldown == 2 ? R.string.status_bar_quick_qs_pulldown_left : R.string.status_bar_quick_qs_pulldown_right);
mQuickPulldown.setSummary(res.getString(R.string.status_bar_quick_qs_pulldown_summary, direction));
}
mQuickPulldown.setOnPreferenceChangeListener(this);
mQuickPulldownFp = (SystemSettingSwitchPreference) findPreference(PREF_QUICK_PULLDOWN_FP);
if (!getResources().getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys)) {
getPreferenceScreen().removePreference(mQuickPulldownFp);
} else {
mQuickPulldownFp.setChecked((Settings.System.getInt(getContentResolver(), Settings.System.STATUS_BAR_QUICK_QS_PULLDOWN_FP, 0) == 1));
mQuickPulldownFp.setOnPreferenceChangeListener(this);
}
}
use of android.support.v7.preference.ListPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class AppRestrictionsFragment method onRestrictionsReceived.
private void onRestrictionsReceived(AppRestrictionsPreference preference, ArrayList<RestrictionEntry> restrictions) {
// Remove any earlier restrictions
removeRestrictionsForApp(preference);
// Non-custom-activity case - expand the restrictions in-place
int count = 1;
for (RestrictionEntry entry : restrictions) {
Preference p = null;
switch(entry.getType()) {
case RestrictionEntry.TYPE_BOOLEAN:
p = new SwitchPreference(getPrefContext());
p.setTitle(entry.getTitle());
p.setSummary(entry.getDescription());
((SwitchPreference) p).setChecked(entry.getSelectedState());
break;
case RestrictionEntry.TYPE_CHOICE:
case RestrictionEntry.TYPE_CHOICE_LEVEL:
p = new ListPreference(getPrefContext());
p.setTitle(entry.getTitle());
String value = entry.getSelectedString();
if (value == null) {
value = entry.getDescription();
}
p.setSummary(findInArray(entry.getChoiceEntries(), entry.getChoiceValues(), value));
((ListPreference) p).setEntryValues(entry.getChoiceValues());
((ListPreference) p).setEntries(entry.getChoiceEntries());
((ListPreference) p).setValue(value);
((ListPreference) p).setDialogTitle(entry.getTitle());
break;
case RestrictionEntry.TYPE_MULTI_SELECT:
p = new MultiSelectListPreference(getPrefContext());
p.setTitle(entry.getTitle());
((MultiSelectListPreference) p).setEntryValues(entry.getChoiceValues());
((MultiSelectListPreference) p).setEntries(entry.getChoiceEntries());
HashSet<String> set = new HashSet<>();
Collections.addAll(set, entry.getAllSelectedStrings());
((MultiSelectListPreference) p).setValues(set);
((MultiSelectListPreference) p).setDialogTitle(entry.getTitle());
break;
case RestrictionEntry.TYPE_NULL:
default:
}
if (p != null) {
p.setPersistent(false);
p.setOrder(preference.getOrder() + count);
// Store the restrictions key string as a key for the preference
p.setKey(preference.getKey().substring(PKG_PREFIX.length()) + DELIMITER + entry.getKey());
mAppList.addPreference(p);
p.setOnPreferenceChangeListener(AppRestrictionsFragment.this);
p.setIcon(R.drawable.empty_icon);
preference.mChildren.add(p);
count++;
}
}
preference.setRestrictions(restrictions);
if (// No visible restrictions
count == 1 && preference.isImmutable() && preference.isChecked()) {
// Special case of required app with no visible restrictions. Remove it
mAppList.removePreference(preference);
}
}
Aggregations