Search in sources :

Example 1 with PreferenceViewHolder

use of androidx.preference.PreferenceViewHolder in project Signal-Android by WhisperSystems.

the class CorrectedPreferenceFragment method onCreateAdapter.

@Override
@SuppressLint("RestrictedApi")
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
    return new PreferenceGroupAdapter(preferenceScreen) {

        @Override
        public void onBindViewHolder(PreferenceViewHolder holder, int position) {
            super.onBindViewHolder(holder, position);
            Preference preference = getItem(position);
            if (preference instanceof PreferenceCategory) {
                setZeroPaddingToLayoutChildren(holder.itemView);
            } else {
                View iconFrame = holder.itemView.findViewById(R.id.icon_frame);
                if (iconFrame != null) {
                    iconFrame.setVisibility(preference.getIcon() == null ? View.GONE : View.VISIBLE);
                }
            }
        }
    };
}
Also used : ColorPickerPreference(org.thoughtcrime.securesms.preferences.widgets.ColorPickerPreference) Preference(androidx.preference.Preference) CustomDefaultPreference(org.thoughtcrime.securesms.components.CustomDefaultPreference) PreferenceCategory(androidx.preference.PreferenceCategory) PreferenceGroupAdapter(androidx.preference.PreferenceGroupAdapter) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint)

Example 2 with PreferenceViewHolder

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

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 : LayoutInflater(android.view.LayoutInflater) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Example 3 with PreferenceViewHolder

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

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 : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Example 4 with PreferenceViewHolder

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

the class ImportancePreferenceTest method onBindViewHolder_nonConfigurable.

@Test
public void onBindViewHolder_nonConfigurable() {
    final ImportancePreference preference = new ImportancePreference(mContext);
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    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(false);
    preference.setImportance(IMPORTANCE_DEFAULT);
    preference.onBindViewHolder(holder);
    assertThat(holder.itemView.findViewById(R.id.silence).isEnabled()).isFalse();
    assertThat(holder.itemView.findViewById(R.id.alert).isEnabled()).isFalse();
    assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(selected);
    assertThat(holder.itemView.findViewById(R.id.silence).getBackground()).isEqualTo(unselected);
    // other button
    preference.setImportance(IMPORTANCE_LOW);
    holder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(R.layout.notif_importance_preference, null));
    preference.onBindViewHolder(holder);
    assertThat(holder.itemView.findViewById(R.id.alert).getBackground()).isEqualTo(unselected);
    assertThat(holder.itemView.findViewById(R.id.silence).getBackground()).isEqualTo(selected);
}
Also used : LayoutInflater(android.view.LayoutInflater) Drawable(android.graphics.drawable.Drawable) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Example 5 with PreferenceViewHolder

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

the class NotificationAppPreferenceTest method setSwitchEnabled_shouldUpdateButtonEnabledState_beforeViewBound.

@Test
public void setSwitchEnabled_shouldUpdateButtonEnabledState_beforeViewBound() {
    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.setSwitchEnabled(false);
    preference.onBindViewHolder(holder);
    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)

Aggregations

PreferenceViewHolder (androidx.preference.PreferenceViewHolder)47 Test (org.junit.Test)40 LayoutInflater (android.view.LayoutInflater)17 View (android.view.View)17 Switch (android.widget.Switch)16 LinearLayout (android.widget.LinearLayout)12 TextView (android.widget.TextView)8 CheckBox (android.widget.CheckBox)7 Preference (androidx.preference.Preference)5 Drawable (android.graphics.drawable.Drawable)3 ImageView (android.widget.ImageView)3 OnPreferenceChangeListener (androidx.preference.Preference.OnPreferenceChangeListener)3 Context (android.content.Context)2 Button (android.widget.Button)2 ProgressBar (android.widget.ProgressBar)2 PreferenceCategory (androidx.preference.PreferenceCategory)2 SwitchPreference (androidx.preference.SwitchPreference)2 AttrRes (android.annotation.AttrRes)1 SuppressLint (android.annotation.SuppressLint)1 SettingsEnums (android.app.settings.SettingsEnums)1