use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MasterSwitchPreferenceTest method clickWidgetView_shouldNotToggleButtonIfDisabled.
@Test
public void clickWidgetView_shouldNotToggleButtonIfDisabled() {
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
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_switch, widgetView, true);
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
preference.onBindViewHolder(holder);
toggle.setEnabled(false);
widgetView.performClick();
assertThat(toggle.isChecked()).isFalse();
}
use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MasterSwitchPreferenceTest method onBindViewHolder_toggleButtonShouldHaveContentDescription.
@Test
public void onBindViewHolder_toggleButtonShouldHaveContentDescription() {
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_widget_master_switch, null));
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
final String label = "TestButton";
preference.setTitle(label);
preference.onBindViewHolder(holder);
assertThat(toggle.getContentDescription()).isEqualTo(label);
}
use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MasterSwitchPreferenceTest method setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton.
@Test
public void setDisabledByAdmin_hasEnforcedAdmin_shouldDisableButton() {
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_widget_master_switch, null));
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
toggle.setEnabled(true);
preference.onBindViewHolder(holder);
preference.setDisabledByAdmin(mock(EnforcedAdmin.class));
assertThat(toggle.isEnabled()).isFalse();
}
use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MasterSwitchPreferenceTest method setSwitchEnabled_shouldUpdateButtonEnabledState_beforeViewBound.
@Test
public void setSwitchEnabled_shouldUpdateButtonEnabledState_beforeViewBound() {
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_widget_master_switch, null));
final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
preference.setSwitchEnabled(false);
preference.onBindViewHolder(holder);
assertThat(toggle.isEnabled()).isFalse();
}
use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class MasterSwitchPreferenceTest method clickWidgetView_shouldNotifyPreferenceChanged.
@Test
public void clickWidgetView_shouldNotifyPreferenceChanged() {
final MasterSwitchPreference preference = new MasterSwitchPreference(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_two_target, null));
final View widgetView = holder.findViewById(android.R.id.widget_frame);
final OnPreferenceChangeListener listener = mock(OnPreferenceChangeListener.class);
preference.setOnPreferenceChangeListener(listener);
preference.onBindViewHolder(holder);
preference.setChecked(false);
widgetView.performClick();
verify(listener).onPreferenceChange(preference, true);
preference.setChecked(true);
widgetView.performClick();
verify(listener).onPreferenceChange(preference, false);
}
Aggregations