use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.
the class BlockPreferenceControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = RuntimeEnvironment.application;
mController = spy(new BlockPreferenceController(mContext, mDependentFieldListener, mBackend));
mPreference = new SettingsMainSwitchPreference(mContext);
final LayoutInflater inflater = LayoutInflater.from(mContext);
final View view = inflater.inflate(mPreference.getLayoutResource(), new LinearLayout(mContext), false);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(view);
mPreference.onBindViewHolder(holder);
}
use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.
the class PrimaryCheckBoxPreferenceTest method onBindViewHolder_shouldSetCheckboxEnabledState.
@Test
public void onBindViewHolder_shouldSetCheckboxEnabledState() {
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.setCheckBoxEnabled(false);
mPreference.onBindViewHolder(holder);
assertThat(mPreference.isEnabled()).isTrue();
assertThat(checkBox.isEnabled()).isFalse();
mPreference.setCheckBoxEnabled(true);
assertThat(mPreference.isEnabled()).isTrue();
assertThat(checkBox.isEnabled()).isTrue();
}
use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.
the class PrimaryCheckBoxPreferenceTest method setCheckboxEnabled_shouldOnlyUpdateCheckBoxEnabledState.
@Test
public void setCheckboxEnabled_shouldOnlyUpdateCheckBoxEnabledState() {
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.setCheckBoxEnabled(false);
assertThat(mPreference.isEnabled()).isTrue();
assertThat(checkBox.isEnabled()).isFalse();
mPreference.setCheckBoxEnabled(true);
assertThat(mPreference.isEnabled()).isTrue();
assertThat(checkBox.isEnabled()).isTrue();
}
use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.
the class PrimaryCheckBoxPreferenceTest method clickWidgetView_shouldNotToggleCheckBoxIfDisabled.
@Test
public void clickWidgetView_shouldNotToggleCheckBoxIfDisabled() {
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);
mPreference.setEnabled(false);
widgetView.performClick();
assertThat(checkBox.isChecked()).isFalse();
}
use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.
the class PrimaryCheckBoxPreferenceTest method clickWidgetView_shouldNotifyPreferenceChanged.
@Test
public void clickWidgetView_shouldNotifyPreferenceChanged() {
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);
mPreference.setOnPreferenceChangeListener(listener);
mPreference.onBindViewHolder(holder);
mPreference.setChecked(false);
widgetView.performClick();
verify(listener).onPreferenceChange(mPreference, true);
mPreference.setChecked(true);
widgetView.performClick();
verify(listener).onPreferenceChange(mPreference, false);
}
Aggregations