Search in sources :

Example 86 with Preference

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

the class MoreSpecialAccessPreferenceControllerTest method handlePreferenceTreeClick_differentKey_shouldReturnFalse.

@Test
public void handlePreferenceTreeClick_differentKey_shouldReturnFalse() {
    when(mPackageManager.getPermissionControllerPackageName()).thenReturn(PERMISSION_CONTROLLER_PACKAGE_NAME);
    MoreSpecialAccessPreferenceController preferenceController = new MoreSpecialAccessPreferenceController(mContext, PREFERENCE_KEY);
    Preference preference = mock(Preference.class);
    when(preference.getKey()).thenReturn(DIFFERENT_PREFERENCE_KEY);
    assertThat(preferenceController.handlePreferenceTreeClick(preference)).isFalse();
}
Also used : Preference(androidx.preference.Preference) Test(org.junit.Test)

Example 87 with Preference

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

the class DashboardFeatureProviderImplTest method bindPreference_withIntentActionMetadata_shouldSetLaunchAction.

@Test
public void bindPreference_withIntentActionMetadata_shouldSetLaunchAction() {
    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();
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    final Intent launchIntent = shadowActivity.getNextStartedActivityForResult().intent;
    assertThat(launchIntent.getAction()).isEqualTo("TestAction");
    assertThat(launchIntent.getIntExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY, 0)).isEqualTo(MetricsEvent.SETTINGS_GESTURES);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Preference(androidx.preference.Preference) Tile(com.android.settingslib.drawer.Tile) ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) Test(org.junit.Test)

Example 88 with Preference

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

the class DashboardFeatureProviderImplTest method bindPreference_toInternalSettingActivity_shouldBindToDirectLaunchIntentAndNotLog.

@Test
public void bindPreference_toInternalSettingActivity_shouldBindToDirectLaunchIntentAndNotLog() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
    final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    tile.userHandle = new ArrayList<>();
    tile.userHandle.add(mock(UserHandle.class));
    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), anyInt());
    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 89 with Preference

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

the class DashboardFeatureProviderImplTest method bindPreference_withIconUri_shouldLoadIconFromContentProvider.

@Test
@Config(shadows = { ShadowTileUtils.class, ShadowThreadUtils.class })
public void bindPreference_withIconUri_shouldLoadIconFromContentProvider() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
    final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
    mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_ICON_URI, "content://com.android.settings/tile_icon");
    mImpl.bindIcon(preference, tile, false);
    assertThat(preference.getIcon()).isNotNull();
}
Also used : Preference(androidx.preference.Preference) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 90 with Preference

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

the class DashboardFeatureProviderImplTest method bindPreference_withNullKeyTileKey_shouldUseTileKey.

@Test
public void bindPreference_withNullKeyTileKey_shouldUseTileKey() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
    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()).isEqualTo(tile.getKey(mContext));
}
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