Search in sources :

Example 76 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

the class ImportancePreferenceTest method onBindViewHolder_selectButtonAndText.

@Test
public void onBindViewHolder_selectButtonAndText() {
    final ImportancePreference preference = new ImportancePreference(mContext);
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.notif_importance_preference, null));
    Drawable unselected = mock(Drawable.class);
    Drawable selected = mock(Drawable.class);
    preference.selectedBackground = selected;
    preference.unselectedBackground = unselected;
    preference.setConfigurable(true);
    preference.setImportance(IMPORTANCE_DEFAULT);
    preference.onBindViewHolder(holder);
    assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(selected);
    assertThat(holder.itemView.findViewById(R.id.silence).getBackground()).isEqualTo(unselected);
    assertThat(((TextView) holder.itemView.findViewById(R.id.alert_summary)).getText()).isEqualTo(mContext.getString(R.string.notification_channel_summary_default));
}
Also used : ImportancePreference(com.android.settings.notification.app.ImportancePreference) LayoutInflater(android.view.LayoutInflater) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Example 77 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

the class ImportancePreferenceTest method onClick_changesUICallsListener.

@Test
public void onClick_changesUICallsListener() {
    final ImportancePreference preference = spy(new ImportancePreference(mContext));
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.notif_importance_preference, null));
    Drawable unselected = mock(Drawable.class);
    Drawable selected = mock(Drawable.class);
    preference.selectedBackground = selected;
    preference.unselectedBackground = unselected;
    preference.setConfigurable(true);
    preference.setImportance(IMPORTANCE_DEFAULT);
    preference.onBindViewHolder(holder);
    View silenceButton = holder.itemView.findViewById(R.id.silence);
    silenceButton.callOnClick();
    assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
    assertThat(holder.itemView.findViewById(R.id.silence).getBackground()).isEqualTo(selected);
    verify(preference, times(1)).callChangeListener(IMPORTANCE_LOW);
}
Also used : ImportancePreference(com.android.settings.notification.app.ImportancePreference) LayoutInflater(android.view.LayoutInflater) Drawable(android.graphics.drawable.Drawable) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test)

Example 78 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project android_packages_apps_Settings by omnirom.

the class ImportancePreferenceTest method setImportanceSummary_default.

@Test
public void setImportanceSummary_default() {
    final ImportancePreference preference = spy(new ImportancePreference(mContext));
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.notif_importance_preference, null));
    preference.setConfigurable(true);
    preference.setImportance(IMPORTANCE_DEFAULT);
    preference.onBindViewHolder(holder);
    TextView tv = holder.itemView.findViewById(R.id.alert_summary);
    preference.setDisplayInStatusBar(true);
    preference.setDisplayOnLockscreen(true);
    preference.setImportanceSummary((ViewGroup) holder.itemView, IMPORTANCE_DEFAULT, true);
    assertThat(tv.getText()).isEqualTo(mContext.getString(R.string.notification_channel_summary_default));
}
Also used : ImportancePreference(com.android.settings.notification.app.ImportancePreference) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Example 79 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project apps-android-commons by commons-app.

the class SettingsFragment method onCreateAdapter.

@Override
protected Adapter onCreateAdapter(final PreferenceScreen preferenceScreen) {
    return new PreferenceGroupAdapter(preferenceScreen) {

        @Override
        public void onBindViewHolder(PreferenceViewHolder holder, int position) {
            super.onBindViewHolder(holder, position);
            Preference preference = getItem(position);
            View iconFrame = holder.itemView.findViewById(R.id.icon_frame);
            if (iconFrame != null) {
                iconFrame.setVisibility(View.GONE);
            }
        }
    };
}
Also used : MultiSelectListPreference(androidx.preference.MultiSelectListPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) PreferenceGroupAdapter(androidx.preference.PreferenceGroupAdapter) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) AdapterView(android.widget.AdapterView) CampaignView(fr.free.nrw.commons.campaigns.CampaignView) ListView(android.widget.ListView)

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