Search in sources :

Example 26 with PreferenceViewHolder

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

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 : ImportancePreference(com.android.settings.notification.app.ImportancePreference) LayoutInflater(android.view.LayoutInflater) Drawable(android.graphics.drawable.Drawable) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Example 27 with PreferenceViewHolder

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

the class ImportancePreferenceTest method setImportanceSummary.

@Test
public void setImportanceSummary() {
    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.silence_summary);
    preference.setDisplayInStatusBar(true);
    preference.setDisplayOnLockscreen(true);
    preference.setImportanceSummary((ViewGroup) holder.itemView, IMPORTANCE_LOW, true);
    assertThat(tv.getText()).isEqualTo(mContext.getString(R.string.notification_channel_summary_low));
}
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 28 with PreferenceViewHolder

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

the class ToggleBackupSettingFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(getActivity());
    setPreferenceScreen(preferenceScreen);
    mSummaryPreference = new Preference(getPrefContext()) {

        @Override
        public void onBindViewHolder(PreferenceViewHolder view) {
            super.onBindViewHolder(view);
            final TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
            summaryView.setText(getSummary());
        }
    };
    mSummaryPreference.setPersistent(false);
    mSummaryPreference.setLayoutResource(R.layout.text_description_preference);
    preferenceScreen.addPreference(mSummaryPreference);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) TextView(android.widget.TextView) PreferenceViewHolder(androidx.preference.PreferenceViewHolder)

Example 29 with PreferenceViewHolder

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

the class MobileNetworkSwitchControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean())).thenReturn(true);
    when(mSubscription.isEmbedded()).thenReturn(true);
    when(mSubscription.getSubscriptionId()).thenReturn(mSubId);
    // Most tests want to have 2 available subscriptions so that the switch bar will show.
    final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
    when(sub2.getSubscriptionId()).thenReturn(456);
    SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription, sub2));
    final String key = "prefKey";
    mController = new MobileNetworkSwitchController(mContext, key);
    mController.init(mLifecycle, mSubscription.getSubscriptionId());
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    mSwitchBar = new SettingsMainSwitchPreference(mContext);
    mSwitchBar.setKey(key);
    mScreen.addPreference(mSwitchBar);
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final View view = inflater.inflate(mSwitchBar.getLayoutResource(), new LinearLayout(mContext), false);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(view);
    mSwitchBar.onBindViewHolder(holder);
}
Also used : SettingsMainSwitchPreference(com.android.settings.widget.SettingsMainSwitchPreference) LayoutInflater(android.view.LayoutInflater) SubscriptionInfo(android.telephony.SubscriptionInfo) PreferenceManager(androidx.preference.PreferenceManager) View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) LinearLayout(android.widget.LinearLayout) Before(org.junit.Before)

Example 30 with PreferenceViewHolder

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

the class MutableGearPreferenceTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mMutableGearPreference = new MutableGearPreference(mContext, null);
    int layoutId = ResourcesUtils.getResourcesId(mContext, "layout", "preference_widget_gear");
    PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(LayoutInflater.from(ApplicationProvider.getApplicationContext()).inflate(layoutId, null));
    mViewHolder = spy(holder);
    mGearView = spy(new ImageView(mContext, null));
    int gearId = ResourcesUtils.getResourcesId(mContext, "id", "settings_button");
    when(mViewHolder.findViewById(gearId)).thenReturn(mGearView);
}
Also used : ImageView(android.widget.ImageView) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Before(org.junit.Before)

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