use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class NotificationAppPreferenceTest method setChecked_shouldUpdateButtonCheckedState.
@Test
public void setChecked_shouldUpdateButtonCheckedState() {
final NotificationAppPreference preference = new NotificationAppPreference(mContext);
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.preference_app, null));
final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
inflater.inflate(R.layout.preference_widget_master_switch, widgetView, true);
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
preference.onBindViewHolder(holder);
preference.setChecked(true);
assertThat(toggle.isChecked()).isTrue();
preference.setChecked(false);
assertThat(toggle.isChecked()).isFalse();
}
use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class NotificationAppPreferenceTest method setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton.
@Test
public void setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton() {
final NotificationAppPreference preference = new NotificationAppPreference(mContext);
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.preference_app, null));
final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
inflater.inflate(R.layout.preference_widget_master_switch, widgetView, true);
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
toggle.setEnabled(true);
preference.onBindViewHolder(holder);
preference.setDisabledByAdmin(mock(RestrictedLockUtils.EnforcedAdmin.class));
assertThat(toggle.isEnabled()).isFalse();
}
use of androidx.preference.PreferenceViewHolder in project kdeconnect-android by KDE.
the class PluginPreference method onBindViewHolder.
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
View.OnClickListener toggleListener = v -> {
boolean newState = !device.isPluginEnabled(pluginKey);
// It actually works on API<14
setChecked(newState);
onStateChanged(holder, newState);
device.setPluginEnabled(pluginKey, newState);
};
View content = holder.findViewById(R.id.content);
View widget = holder.findViewById(android.R.id.widget_frame);
View parent = holder.itemView;
content.setOnClickListener(listener);
widget.setOnClickListener(toggleListener);
parent.setOnClickListener(toggleListener);
// Disable child backgrounds when known to be unneeded to prevent duplicate ripples
int selectableItemBackground;
if (listener == null) {
selectableItemBackground = 0;
} else {
TypedValue value = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, value, true);
selectableItemBackground = value.resourceId;
}
content.setBackgroundResource(selectableItemBackground);
widget.setBackgroundResource(selectableItemBackground);
onStateChanged(holder, isChecked());
}
use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.
the class FingerprintPreferenceTest method bindAndClickDeleteButton_shouldInvokeOnDeleteListener.
@Test
public void bindAndClickDeleteButton_shouldInvokeOnDeleteListener() {
final FrameLayout layout = new FrameLayout(mContext);
LayoutInflater.from(mContext).inflate(mPreference.getSecondTargetResId(), layout, true);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(layout);
mPreference.onBindViewHolder(holder);
final View view = layout.findViewById(R.id.delete_button);
assertThat(view).isNotNull();
view.performClick();
verify(mOnDeleteClickListener).onDeleteClick(mPreference);
}
use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.
the class WifiDisplaySettings method buildCertificationMenu.
private void buildCertificationMenu(final PreferenceScreen preferenceScreen) {
if (mCertCategory == null) {
mCertCategory = new PreferenceCategory(getPrefContext());
mCertCategory.setTitle(R.string.wifi_display_certification_heading);
mCertCategory.setOrder(ORDER_CERTIFICATION);
} else {
mCertCategory.removeAll();
}
preferenceScreen.addPreference(mCertCategory);
// display session info if there is an active p2p session
if (!mWifiDisplayStatus.getSessionInfo().getGroupId().isEmpty()) {
Preference p = new Preference(getPrefContext());
p.setTitle(R.string.wifi_display_session_info);
p.setSummary(mWifiDisplayStatus.getSessionInfo().toString());
mCertCategory.addPreference(p);
// show buttons for Pause/Resume when a WFD session is established
if (mWifiDisplayStatus.getSessionInfo().getSessionId() != 0) {
mCertCategory.addPreference(new Preference(getPrefContext()) {
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
Button b = (Button) view.findViewById(R.id.left_button);
b.setText(R.string.wifi_display_pause);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mDisplayManager.pauseWifiDisplay();
}
});
b = (Button) view.findViewById(R.id.right_button);
b.setText(R.string.wifi_display_resume);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mDisplayManager.resumeWifiDisplay();
}
});
}
});
mCertCategory.setLayoutResource(R.layout.two_buttons_panel);
}
}
// switch for Listen Mode
SwitchPreference pref = new SwitchPreference(getPrefContext()) {
@Override
protected void onClick() {
mListen = !mListen;
setListenMode(mListen);
setChecked(mListen);
}
};
pref.setTitle(R.string.wifi_display_listen_mode);
pref.setChecked(mListen);
mCertCategory.addPreference(pref);
// switch for Autonomous GO
pref = new SwitchPreference(getPrefContext()) {
@Override
protected void onClick() {
mAutoGO = !mAutoGO;
if (mAutoGO) {
startAutoGO();
} else {
stopAutoGO();
}
setChecked(mAutoGO);
}
};
pref.setTitle(R.string.wifi_display_autonomous_go);
pref.setChecked(mAutoGO);
mCertCategory.addPreference(pref);
// Drop down list for choosing WPS method (PBC/KEYPAD/DISPLAY)
ListPreference lp = new ListPreference(getPrefContext());
lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int wpsConfig = Integer.parseInt((String) value);
if (wpsConfig != mWpsConfig) {
mWpsConfig = wpsConfig;
getActivity().invalidateOptionsMenu();
Settings.Global.putInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, mWpsConfig);
}
return true;
}
});
mWpsConfig = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, WpsInfo.INVALID);
String[] wpsEntries = { "Default", "PBC", "KEYPAD", "DISPLAY" };
String[] wpsValues = { "" + WpsInfo.INVALID, "" + WpsInfo.PBC, "" + WpsInfo.KEYPAD, "" + WpsInfo.DISPLAY };
lp.setKey("wps");
lp.setTitle(R.string.wifi_display_wps_config);
lp.setEntries(wpsEntries);
lp.setEntryValues(wpsValues);
lp.setValue("" + mWpsConfig);
lp.setSummary("%1$s");
mCertCategory.addPreference(lp);
// Drop down list for choosing listen channel
lp = new ListPreference(getPrefContext());
lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int channel = Integer.parseInt((String) value);
if (channel != mListenChannel) {
mListenChannel = channel;
getActivity().invalidateOptionsMenu();
setWifiP2pChannels(mListenChannel, mOperatingChannel);
}
return true;
}
});
String[] lcEntries = { "Auto", "1", "6", "11" };
String[] lcValues = { "0", "1", "6", "11" };
lp.setKey("listening_channel");
lp.setTitle(R.string.wifi_display_listen_channel);
lp.setEntries(lcEntries);
lp.setEntryValues(lcValues);
lp.setValue("" + mListenChannel);
lp.setSummary("%1$s");
mCertCategory.addPreference(lp);
// Drop down list for choosing operating channel
lp = new ListPreference(getPrefContext());
lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
int channel = Integer.parseInt((String) value);
if (channel != mOperatingChannel) {
mOperatingChannel = channel;
getActivity().invalidateOptionsMenu();
setWifiP2pChannels(mListenChannel, mOperatingChannel);
}
return true;
}
});
String[] ocEntries = { "Auto", "1", "6", "11", "36" };
String[] ocValues = { "0", "1", "6", "11", "36" };
lp.setKey("operating_channel");
lp.setTitle(R.string.wifi_display_operating_channel);
lp.setEntries(ocEntries);
lp.setEntryValues(ocValues);
lp.setValue("" + mOperatingChannel);
lp.setSummary("%1$s");
mCertCategory.addPreference(lp);
}
Aggregations