Search in sources :

Example 21 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.

the class DashboardFeatureProviderImplTest method bindPreference_noFragmentMetadata_shouldBindIntent.

@Test
public void bindPreference_noFragmentMetadata_shouldBindIntent() {
    final Preference preference = new Preference(ShadowApplication.getInstance().getApplicationContext());
    final Tile tile = new Tile();
    tile.metaData = new Bundle();
    tile.priority = 10;
    tile.intent = new Intent();
    tile.intent.setComponent(new ComponentName("pkg", "class"));
    mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    assertThat(preference.getFragment()).isNull();
    assertThat(preference.getOnPreferenceClickListener()).isNotNull();
    assertThat(preference.getOrder()).isEqualTo(-tile.priority);
}
Also used : Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 22 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.

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();
    tile.metaData = new Bundle();
    tile.userHandle = new ArrayList<>();
    tile.userHandle.add(mock(UserHandle.class));
    tile.intent = new Intent();
    tile.intent.setComponent(new ComponentName("pkg", "class"));
    when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
    mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    preference.getOnPreferenceClickListener().onPreferenceClick(null);
    verify(mFeatureFactory.metricsFeatureProvider).logDashboardStartIntent(any(Context.class), any(Intent.class), eq(MetricsProto.MetricsEvent.SETTINGS_GESTURES));
    verify(mActivity).startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
}
Also used : Context(android.content.Context) Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 23 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.

the class DashboardFeatureProviderImplTest method getPreferences_hasTileForCategory_shouldReturnPrefList.

@Test
public void getPreferences_hasTileForCategory_shouldReturnPrefList() {
    mImpl = new DashboardFeatureProviderImpl(mActivity);
    ReflectionHelpers.setField(mImpl, "mCategoryManager", mCategoryManager);
    final DashboardCategory category = new DashboardCategory();
    category.tiles.add(new Tile());
    when(mCategoryManager.getTilesByCategory(any(Context.class), eq(CategoryKey.CATEGORY_HOMEPAGE))).thenReturn(category);
    assertThat(mImpl.getPreferencesForCategory(mActivity, ShadowApplication.getInstance().getApplicationContext(), MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE).isEmpty()).isFalse();
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Context(android.content.Context) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 24 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.

the class DashboardFeatureProviderImplTest method bindPreference_withNullKeyTileKey_shouldUseTileKey.

@Test
public void bindPreference_withNullKeyTileKey_shouldUseTileKey() {
    final Preference preference = new Preference(RuntimeEnvironment.application);
    final Tile tile = new Tile();
    tile.key = "key";
    tile.intent = new Intent();
    tile.intent.setComponent(new ComponentName("pkg", "class"));
    mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN, preference, tile, null, /* key */
    Preference.DEFAULT_ORDER);
    assertThat(preference.getKey()).isEqualTo(tile.key);
}
Also used : Preference(android.support.v7.preference.Preference) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) ComponentName(android.content.ComponentName) Test(org.junit.Test)

Example 25 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.

the class DashboardFeatureProviderImplTest method clickPreference_withUnresolvableIntent_shouldNotLaunchAnything.

@Test
public void clickPreference_withUnresolvableIntent_shouldNotLaunchAnything() {
    ReflectionHelpers.setField(mImpl, "mPackageManager", RuntimeEnvironment.getPackageManager());
    Activity activity = Robolectric.buildActivity(Activity.class).get();
    final ShadowApplication application = ShadowApplication.getInstance();
    final Preference preference = new Preference(application.getApplicationContext());
    final Tile tile = new Tile();
    tile.key = "key";
    tile.intent = new Intent();
    tile.intent.setComponent(new ComponentName("pkg", "class"));
    tile.metaData = new Bundle();
    tile.metaData.putString("com.android.settings.intent.action", "TestAction");
    tile.userHandle = null;
    mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
    preference.performClick();
    final ShadowActivity.IntentForResult launchIntent = shadowOf(activity).getNextStartedActivityForResult();
    assertThat(launchIntent).isNull();
}
Also used : Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) ShadowActivity(org.robolectric.shadows.ShadowActivity) SettingsActivity(com.android.settings.SettingsActivity) Activity(android.app.Activity) Tile(com.android.settingslib.drawer.Tile) ShadowActivity(org.robolectric.shadows.ShadowActivity) Intent(android.content.Intent) ComponentName(android.content.ComponentName) ShadowApplication(org.robolectric.shadows.ShadowApplication) Test(org.junit.Test)

Aggregations

Tile (com.android.settingslib.drawer.Tile)466 Test (org.junit.Test)309 Intent (android.content.Intent)158 Bundle (android.os.Bundle)117 Preference (android.support.v7.preference.Preference)108 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)102 ComponentName (android.content.ComponentName)98 ArrayList (java.util.ArrayList)79 Context (android.content.Context)71 UserHandle (android.os.UserHandle)32 Activity (android.app.Activity)31 RecyclerView (android.support.v7.widget.RecyclerView)31 View (android.view.View)31 Icon (android.graphics.drawable.Icon)30 VisibleForTesting (android.support.annotation.VisibleForTesting)30 PackageManager (android.content.pm.PackageManager)25 TypedArray (android.content.res.TypedArray)24 ViewGroup (android.view.ViewGroup)24 RemoteViews (android.widget.RemoteViews)24 SettingsActivity (com.android.settings.SettingsActivity)24