Search in sources :

Example 31 with PreferenceViewHolder

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);
}
Also used : SettingsMainSwitchPreference(com.android.settings.widget.SettingsMainSwitchPreference) LayoutInflater(android.view.LayoutInflater) ShadowApplication(org.robolectric.shadows.ShadowApplication) View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) LinearLayout(android.widget.LinearLayout) Before(org.junit.Before)

Example 32 with PreferenceViewHolder

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();
}
Also used : CheckBox(android.widget.CheckBox) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Example 33 with PreferenceViewHolder

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();
}
Also used : CheckBox(android.widget.CheckBox) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Example 34 with PreferenceViewHolder

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();
}
Also used : CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) LinearLayout(android.widget.LinearLayout) Test(org.junit.Test)

Example 35 with PreferenceViewHolder

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);
}
Also used : OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) Test(org.junit.Test)

Aggregations

PreferenceViewHolder (androidx.preference.PreferenceViewHolder)79 Test (org.junit.Test)61 View (android.view.View)33 LayoutInflater (android.view.LayoutInflater)29 LinearLayout (android.widget.LinearLayout)17 Switch (android.widget.Switch)16 TextView (android.widget.TextView)16 CheckBox (android.widget.CheckBox)14 Preference (androidx.preference.Preference)12 PreferenceCategory (androidx.preference.PreferenceCategory)7 Drawable (android.graphics.drawable.Drawable)6 ProgressBar (android.widget.ProgressBar)5 OnPreferenceChangeListener (androidx.preference.Preference.OnPreferenceChangeListener)5 ImportancePreference (com.android.settings.notification.app.ImportancePreference)5 Before (org.junit.Before)5 ImageView (android.widget.ImageView)4 Context (android.content.Context)3 Button (android.widget.Button)3 ListPreference (androidx.preference.ListPreference)3 PreferenceGroupAdapter (androidx.preference.PreferenceGroupAdapter)3