Search in sources :

Example 21 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class ProfileSelectDialogTest method updateUserHandlesIfNeeded_Remove.

@Test
public void updateUserHandlesIfNeeded_Remove() {
    final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    tile.userHandle.add(REMOVED_USER);
    tile.userHandle.add(NORMAL_USER);
    tile.userHandle.add(REMOVED_USER);
    ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
    assertThat(tile.userHandle).hasSize(1);
    assertThat(tile.userHandle.get(0).getIdentifier()).isEqualTo(NORMAL_USER.getIdentifier());
    verify(mUserManager, times(1)).getUserInfo(NORMAL_USER.getIdentifier());
    verify(mUserManager, times(2)).getUserInfo(REMOVED_USER.getIdentifier());
}
Also used : ActivityTile(com.android.settingslib.drawer.ActivityTile) Tile(com.android.settingslib.drawer.Tile) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test)

Example 22 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class DashboardFeatureProviderImplTest method bindIcon_withStaticIconAndIconUri_shouldLoadIconFromContentProvider.

@Test
@Config(shadows = { ShadowTileUtils.class })
public void bindIcon_withStaticIconAndIconUri_shouldLoadIconFromContentProvider() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
    final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
    mActivityInfo.metaData.putInt(META_DATA_PREFERENCE_ICON, R.drawable.ic_add_40dp);
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_ICON_URI, "content://com.android.settings/tile_icon");
    mImpl.bindIcon(preference, tile, false);
    final Bitmap preferenceBmp = Utils.createIconWithDrawable(preference.getIcon()).getBitmap();
    final Drawable staticIcon = Icon.createWithResource(mActivityInfo.packageName, R.drawable.ic_add_40dp).loadDrawable(preference.getContext());
    final Bitmap staticIconBmp = Utils.createIconWithDrawable(staticIcon).getBitmap();
    assertThat(preferenceBmp.sameAs(staticIconBmp)).isFalse();
    final Pair<String, Integer> iconInfo = TileUtils.getIconFromUri(mContext, "pkg", null, /* uri */
    null);
    final Drawable iconFromUri = Icon.createWithResource(iconInfo.first, iconInfo.second).loadDrawable(preference.getContext());
    final Bitmap iconBmpFromUri = Utils.createIconWithDrawable(iconFromUri).getBitmap();
    assertThat(preferenceBmp.sameAs(iconBmpFromUri)).isTrue();
}
Also used : Bitmap(android.graphics.Bitmap) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) Drawable(android.graphics.drawable.Drawable) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 23 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class DashboardFeatureProviderImplTest method bindPreference_withOrderMetadata_shouldUseOrderInMetadata.

@Test
public void bindPreference_withOrderMetadata_shouldUseOrderInMetadata() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final int testOrder = -30;
    mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
    final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, testOrder);
    mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN, preference, tile, "123", Preference.DEFAULT_ORDER);
    assertThat(preference.getOrder()).isEqualTo(testOrder);
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test)

Example 24 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class DashboardFeatureProviderImplTest method openTileIntent_profileSelectionDialog_validUserHandleShouldNotShow.

@Test
public void openTileIntent_profileSelectionDialog_validUserHandleShouldNotShow() {
    final int userId = 10;
    ShadowUserManager.getShadow().addUser(userId, "Someone", 0);
    final UserHandle userHandle = new UserHandle(userId);
    final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    tile.getIntent().putExtra(EXTRA_USER, userHandle);
    final ArrayList<UserHandle> handles = new ArrayList<>();
    handles.add(new UserHandle(0));
    handles.add(userHandle);
    tile.userHandle = handles;
    mImpl.openTileIntent(mActivity, tile);
    final ArgumentCaptor<UserHandle> argument = ArgumentCaptor.forClass(UserHandle.class);
    verify(mActivity).startActivityForResultAsUser(any(Intent.class), anyInt(), argument.capture());
    assertThat(argument.getValue().getIdentifier()).isEqualTo(userId);
    verify(mActivity, never()).getSupportFragmentManager();
}
Also used : UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test)

Example 25 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class DashboardFeatureProviderImplTest method bindPreference_hasSummaryUri_shouldLoadSummaryFromContentProviderAndHaveObserver.

@Test
@Config(shadows = { ShadowTileUtils.class })
public void bindPreference_hasSummaryUri_shouldLoadSummaryFromContentProviderAndHaveObserver() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    final String uriString = "content://com.android.settings/tile_summary";
    mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, uriString);
    final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN, preference, tile, null, /*key */
    Preference.DEFAULT_ORDER);
    assertThat(preference.getSummary()).isEqualTo(ShadowTileUtils.MOCK_SUMMARY);
    assertThat(observers.get(0).getUri().toString()).isEqualTo(uriString);
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

ActivityTile (com.android.settingslib.drawer.ActivityTile)41 Test (org.junit.Test)37 Tile (com.android.settingslib.drawer.Tile)35 ProviderTile (com.android.settingslib.drawer.ProviderTile)29 Preference (androidx.preference.Preference)20 SwitchPreference (androidx.preference.SwitchPreference)19 Intent (android.content.Intent)11 UserHandle (android.os.UserHandle)10 ArrayList (java.util.ArrayList)7 ActivityInfo (android.content.pm.ActivityInfo)5 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)5 Config (org.robolectric.annotation.Config)5 Bundle (android.os.Bundle)4 FragmentActivity (androidx.fragment.app.FragmentActivity)3 ProviderInfo (android.content.pm.ProviderInfo)2 ResolveInfo (android.content.pm.ResolveInfo)2 Bitmap (android.graphics.Bitmap)2 Drawable (android.graphics.drawable.Drawable)2 Before (org.junit.Before)2 ShadowActivity (org.robolectric.shadows.ShadowActivity)2