Search in sources :

Example 91 with Preference

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

the class DashboardFeatureProviderImplTest method clickPreference_withUnresolvableIntent_shouldNotLaunchAnything.

@Test
public void clickPreference_withUnresolvableIntent_shouldNotLaunchAnything() {
    ReflectionHelpers.setField(mImpl, "mPackageManager", RuntimeEnvironment.application.getPackageManager());
    FragmentActivity activity = Robolectric.buildActivity(FragmentActivity.class).get();
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
    mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
    tile.userHandle = null;
    mImpl.bindPreferenceToTile(activity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    preference.performClick();
    final ShadowActivity.IntentForResult launchIntent = Shadows.shadowOf(activity).getNextStartedActivityForResult();
    assertThat(launchIntent).isNull();
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Preference(androidx.preference.Preference) Tile(com.android.settingslib.drawer.Tile) ShadowActivity(org.robolectric.shadows.ShadowActivity) Test(org.junit.Test)

Example 92 with Preference

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

the class DashboardFeatureProviderImplTest method bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority.

@Test
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN, preference, tile, null, /*key */
    Preference.DEFAULT_ORDER);
    assertThat(preference.getKey()).isNotNull();
    assertThat(preference.getOrder()).isEqualTo(Preference.DEFAULT_ORDER);
}
Also used : Preference(androidx.preference.Preference) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 93 with Preference

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

the class DashboardFeatureProviderImplTest method bindPreference_noFragmentMetadata_shouldBindToProfileSelector.

@Test
public void bindPreference_noFragmentMetadata_shouldBindToProfileSelector() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    tile.userHandle = new ArrayList<>();
    tile.userHandle.add(mock(UserHandle.class));
    tile.userHandle.add(mock(UserHandle.class));
    mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    preference.getOnPreferenceClickListener().onPreferenceClick(null);
    verify(mActivity).getSupportFragmentManager();
}
Also used : Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 94 with Preference

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

the class DashboardFeatureProviderImplTest method bindPreference_noFragmentMetadataSingleUser_shouldBindToDirectLaunchIntent.

@Test
public void bindPreference_noFragmentMetadataSingleUser_shouldBindToDirectLaunchIntent() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    tile.userHandle = new ArrayList<>();
    tile.userHandle.add(mock(UserHandle.class));
    when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
    mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    preference.getOnPreferenceClickListener().onPreferenceClick(null);
    verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent(any(Context.class), any(Intent.class), eq(MetricsEvent.SETTINGS_GESTURES));
    verify(mActivity).startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
}
Also used : Context(android.content.Context) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) Test(org.junit.Test)

Example 95 with Preference

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

the class DashboardFeatureProviderImplTest method bindPreference_noFragmentMetadata_shouldBindIntent.

@Test
public void bindPreference_noFragmentMetadata_shouldBindIntent() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
    final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    mImpl.bindPreferenceToTile(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    assertThat(preference.getFragment()).isNull();
    assertThat(preference.getOnPreferenceClickListener()).isNotNull();
    assertThat(preference.getOrder()).isEqualTo(tile.getOrder());
}
Also used : Preference(androidx.preference.Preference) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Aggregations

Preference (androidx.preference.Preference)863 Test (org.junit.Test)343 Before (org.junit.Before)164 Intent (android.content.Intent)81 PreferenceScreen (androidx.preference.PreferenceScreen)81 NotificationChannel (android.app.NotificationChannel)77 SwitchPreference (androidx.preference.SwitchPreference)75 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)69 Context (android.content.Context)60 ArrayList (java.util.ArrayList)50 NotificationBackend (com.android.settings.notification.NotificationBackend)45 ListPreference (androidx.preference.ListPreference)43 PreferenceCategory (androidx.preference.PreferenceCategory)40 Tile (com.android.settingslib.drawer.Tile)40 PreferenceManager (androidx.preference.PreferenceManager)39 Activity (android.app.Activity)27 UserHandle (android.os.UserHandle)27 FooterPreference (com.android.settingslib.widget.FooterPreference)27 PackageManager (android.content.pm.PackageManager)26 Bundle (android.os.Bundle)24