Search in sources :

Example 31 with ActivityTile

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

the class DashboardFeatureProviderImplTest method bindPreference_shouldBindAllData.

@Test
public void bindPreference_shouldBindAllData() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final Tile tile = spy(new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
    mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
    doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565))).when(tile).getIcon(any(Context.class));
    mActivityInfo.metaData.putString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS, "HI");
    mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    assertThat(preference.getTitle()).isEqualTo(mContext.getText(R.string.settings_label));
    assertThat(preference.getSummary()).isEqualTo(mContext.getText(R.string.about_settings_summary));
    assertThat(preference.getIcon()).isNotNull();
    assertThat(preference.getFragment()).isEqualTo(mActivityInfo.metaData.getString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS));
    assertThat(preference.getOrder()).isEqualTo(tile.getOrder());
}
Also used : Context(android.content.Context) 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 32 with ActivityTile

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

the class DashboardFeatureProviderImplTest method bindIcon_withStaticIcon_shouldLoadStaticIcon.

@Test
public void bindIcon_withStaticIcon_shouldLoadStaticIcon() {
    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);
    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)).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)

Example 33 with ActivityTile

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

the class DashboardFeatureProviderImplTest method openTileIntent_profileSelectionDialog_invalidUserHandleShouldShow.

@Test
public void openTileIntent_profileSelectionDialog_invalidUserHandleShouldShow() {
    ShadowUserManager.getShadow().addUser(10, "Someone", 0);
    final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    tile.getIntent().putExtra(EXTRA_USER, new UserHandle(30));
    final ArrayList<UserHandle> handles = new ArrayList<>();
    handles.add(new UserHandle(0));
    handles.add(new UserHandle(10));
    tile.userHandle = handles;
    mImpl.openTileIntent(mActivity, tile);
    verify(mActivity, never()).startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
    verify(mActivity).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 34 with ActivityTile

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

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 ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
    tile.userHandle = new ArrayList<>();
    tile.userHandle.add(mock(UserHandle.class));
    mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    preference.getOnPreferenceClickListener().onPreferenceClick(null);
    verify(mFeatureFactory.metricsFeatureProvider).logStartedIntent(any(Intent.class), anyInt());
    verify(mActivity).startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) 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 35 with ActivityTile

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

the class DashboardFeatureProviderImplTest method openTileIntent_profileSelectionDialog_unresolvableWorkProfileIntentShouldNotShow.

@Test
public void openTileIntent_profileSelectionDialog_unresolvableWorkProfileIntentShouldNotShow() {
    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);
    final ArrayList<UserHandle> handles = new ArrayList<>();
    handles.add(new UserHandle(0));
    handles.add(userHandle);
    tile.userHandle = handles;
    when(mPackageManager.resolveActivityAsUser(any(Intent.class), anyInt(), eq(0))).thenReturn(new ResolveInfo());
    when(mPackageManager.resolveActivityAsUser(any(Intent.class), anyInt(), eq(userId))).thenReturn(null);
    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(0);
    verify(mActivity, never()).getSupportFragmentManager();
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) 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)

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