Search in sources :

Example 11 with PreferenceViewHolder

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

Example 12 with PreferenceViewHolder

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

Example 13 with PreferenceViewHolder

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

Example 14 with PreferenceViewHolder

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

Example 15 with PreferenceViewHolder

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);
}
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