use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.
the class PrimaryCheckBoxPreferenceTest method setChecked_shouldUpdateCheckBoxCheckedState.
@Test
public void setChecked_shouldUpdateCheckBoxCheckedState() {
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_widget_primary_checkbox, null));
final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
mPreference.onBindViewHolder(holder);
mPreference.setChecked(true);
assertThat(checkBox.isChecked()).isTrue();
mPreference.setChecked(false);
assertThat(checkBox.isChecked()).isFalse();
}
use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.
the class PrimaryCheckBoxPreferenceTest method clickWidgetView_shouldToggleCheckBox.
@Test
public void clickWidgetView_shouldToggleCheckBox() {
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.preference_two_target, null));
final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
assertThat(widgetView).isNotNull();
inflater.inflate(R.layout.preference_widget_primary_checkbox, widgetView, true);
final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
mPreference.onBindViewHolder(holder);
widgetView.performClick();
assertThat(checkBox.isChecked()).isTrue();
widgetView.performClick();
assertThat(checkBox.isChecked()).isFalse();
}
use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
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);
}
use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MasterCheckBoxPreferenceTest method clickWidgetView_shouldToggleCheckBox.
@Test
public void clickWidgetView_shouldToggleCheckBox() {
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.preference_two_target, null));
final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
assertThat(widgetView).isNotNull();
inflater.inflate(R.layout.preference_widget_master_checkbox, widgetView, true);
final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
mPreference.onBindViewHolder(holder);
widgetView.performClick();
assertThat(checkBox.isChecked()).isTrue();
widgetView.performClick();
assertThat(checkBox.isChecked()).isFalse();
}
use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MasterCheckBoxPreferenceTest method onBindViewHolder_shouldSetCheckboxEnabledState.
@Test
public void onBindViewHolder_shouldSetCheckboxEnabledState() {
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_widget_master_checkbox, null));
final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
mPreference.setCheckBoxEnabled(false);
mPreference.onBindViewHolder(holder);
assertThat(mPreference.isEnabled()).isTrue();
assertThat(checkBox.isEnabled()).isFalse();
mPreference.setCheckBoxEnabled(true);
assertThat(mPreference.isEnabled()).isTrue();
assertThat(checkBox.isEnabled()).isTrue();
}
Aggregations