Search in sources :

Example 56 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class FingerprintPreferenceTest method bindAndClickDeleteButton_shouldInvokeOnDeleteListener.

@Test
public void bindAndClickDeleteButton_shouldInvokeOnDeleteListener() {
    final FrameLayout layout = new FrameLayout(mContext);
    LayoutInflater.from(mContext).inflate(mPreference.getSecondTargetResId(), layout, true);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(layout);
    mPreference.onBindViewHolder(holder);
    final View view = layout.findViewById(R.id.delete_button);
    assertThat(view).isNotNull();
    view.performClick();
    verify(mOnDeleteClickListener).onDeleteClick(mPreference);
}
Also used : FrameLayout(android.widget.FrameLayout) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) Test(org.junit.Test)

Example 57 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationAppPreferenceTest method setSwitchEnabled_shouldUpdateButtonEnabledState.

@Test
public void setSwitchEnabled_shouldUpdateButtonEnabledState() {
    final NotificationAppPreference preference = new NotificationAppPreference(mContext);
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.preference_app, null));
    final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
    inflater.inflate(R.layout.preference_widget_master_switch, widgetView, true);
    final Switch toggle = (Switch) holder.findViewById(R.id.switchWidget);
    preference.onBindViewHolder(holder);
    preference.setSwitchEnabled(true);
    assertThat(toggle.isEnabled()).isTrue();
    preference.setSwitchEnabled(false);
    assertThat(toggle.isEnabled()).isFalse();
}
Also used : Switch(android.widget.Switch) LayoutInflater(android.view.LayoutInflater) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) LinearLayout(android.widget.LinearLayout) Test(org.junit.Test)

Example 58 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationAppPreferenceTest method clickWidgetView_shouldNotifyPreferenceChanged.

@Test
public void clickWidgetView_shouldNotifyPreferenceChanged() {
    final NotificationAppPreference preference = new NotificationAppPreference(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(mContext).inflate(R.layout.preference_app, null));
    final View widgetView = holder.findViewById(android.R.id.widget_frame);
    final Preference.OnPreferenceChangeListener listener = mock(Preference.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 : Preference(androidx.preference.Preference) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) Test(org.junit.Test)

Example 59 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationAppPreferenceTest method clickWidgetView_shouldToggleButton.

@Test
public void clickWidgetView_shouldToggleButton() {
    final NotificationAppPreference preference = new NotificationAppPreference(mContext);
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.preference_app, 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);
    widgetView.performClick();
    assertThat(toggle.isChecked()).isTrue();
    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 60 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationAppPreferenceTest method clickWidgetView_shouldNotToggleButtonIfDisabled.

@Test
public void clickWidgetView_shouldNotToggleButtonIfDisabled() {
    final NotificationAppPreference preference = new NotificationAppPreference(mContext);
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.preference_app, 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)

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