Search in sources :

Example 1 with ProviderTile

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

the class CategoryManager method filterDuplicateTiles.

/**
 * Filter out duplicate tiles from category. Duplicate tiles are the ones pointing to the
 * same intent for ActivityTile, and also the ones having the same description for ProviderTile.
 */
@VisibleForTesting
synchronized void filterDuplicateTiles(Map<String, DashboardCategory> categoryByKeyMap) {
    for (Entry<String, DashboardCategory> categoryEntry : categoryByKeyMap.entrySet()) {
        final DashboardCategory category = categoryEntry.getValue();
        final int count = category.getTilesCount();
        final Set<String> descriptions = new ArraySet<>();
        final Set<ComponentName> components = new ArraySet<>();
        for (int i = count - 1; i >= 0; i--) {
            final Tile tile = category.getTile(i);
            if (tile instanceof ProviderTile) {
                final String desc = tile.getDescription();
                if (descriptions.contains(desc)) {
                    category.removeTile(i);
                } else {
                    descriptions.add(desc);
                }
            } else {
                final ComponentName tileComponent = tile.getIntent().getComponent();
                if (components.contains(tileComponent)) {
                    category.removeTile(i);
                } else {
                    components.add(tileComponent);
                }
            }
        }
    }
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ArraySet(android.util.ArraySet) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) ComponentName(android.content.ComponentName) ProviderTile(com.android.settingslib.drawer.ProviderTile) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 2 with ProviderTile

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

the class DashboardFeatureProviderImplTest method bindPreference_shouldBindAllSwitchData.

@Test
public void bindPreference_shouldBindAllSwitchData() {
    final Preference preference = new SwitchPreference(RuntimeEnvironment.application);
    final Tile tile = spy(new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE, mSwitchMetaData));
    mSwitchMetaData.putInt(META_DATA_KEY_ORDER, 10);
    doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565))).when(tile).getIcon(any(Context.class));
    final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile, null, /* key*/
    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.getKey()).isEqualTo(KEY);
    assertThat(preference.getIcon()).isNotNull();
    assertThat(preference.getOrder()).isEqualTo(tile.getOrder());
    assertThat(observers.get(0).getUri().toString()).isEqualTo(SWITCH_URI);
}
Also used : Context(android.content.Context) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) SwitchPreference(androidx.preference.SwitchPreference) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Test(org.junit.Test)

Example 3 with ProviderTile

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

the class DashboardFeatureProviderImplTest method bindPreference_callbackOnChanged_shouldLoadFromContentProvider.

@Test
@Config(shadows = { ShadowTileUtils.class })
public void bindPreference_callbackOnChanged_shouldLoadFromContentProvider() {
    final SwitchPreference preference = new SwitchPreference(RuntimeEnvironment.application);
    final Tile tile = new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE, mSwitchMetaData);
    final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN, preference, tile, null, /*key */
    Preference.DEFAULT_ORDER);
    ShadowTileUtils.setProviderChecked(false);
    observers.get(0).onDataChanged();
    assertThat(preference.isChecked()).isFalse();
    ShadowTileUtils.setProviderChecked(true);
    observers.get(0).onDataChanged();
    assertThat(preference.isChecked()).isTrue();
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 4 with ProviderTile

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

the class DashboardFragmentTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    final ActivityInfo activityInfo = new ActivityInfo();
    activityInfo.packageName = "pkg";
    activityInfo.name = "class";
    activityInfo.metaData = new Bundle();
    activityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "injected_tile_key");
    mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
    mDashboardCategory = new DashboardCategory("key");
    mActivityTile = new ActivityTile(activityInfo, mDashboardCategory.key);
    mDashboardCategory.addTile(mActivityTile);
    final ProviderInfo providerInfo = new ProviderInfo();
    providerInfo.packageName = "pkg";
    providerInfo.name = "provider";
    providerInfo.authority = "authority";
    final Bundle metaData = new Bundle();
    metaData.putString(META_DATA_PREFERENCE_KEYHINT, "injected_tile_key2");
    metaData.putString(META_DATA_PREFERENCE_SWITCH_URI, "uri");
    mProviderTile = new ProviderTile(providerInfo, mDashboardCategory.key, metaData);
    mDashboardCategory.addTile(mProviderTile);
    mTestFragment = new TestFragment(RuntimeEnvironment.application);
    when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(nullable(String.class))).thenReturn(mDashboardCategory);
    mTestFragment.onAttach(RuntimeEnvironment.application);
    when(mContext.getPackageName()).thenReturn("TestPackage");
    mControllers = new ArrayList<>();
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ActivityInfo(android.content.pm.ActivityInfo) ProviderInfo(android.content.pm.ProviderInfo) Bundle(android.os.Bundle) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Before(org.junit.Before)

Example 5 with ProviderTile

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

the class DashboardFeatureProviderImplTest method bindPreference_onCheckedChanged_shouldPutStateToContentProvider.

@Test
@Config(shadows = { ShadowTileUtils.class })
public void bindPreference_onCheckedChanged_shouldPutStateToContentProvider() {
    final SwitchPreference preference = new SwitchPreference(RuntimeEnvironment.application);
    final Tile tile = new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE, mSwitchMetaData);
    final Bundle bundle = new Bundle();
    bundle.putBoolean(EXTRA_SWITCH_SET_CHECKED_ERROR, false);
    ShadowTileUtils.setResultBundle(bundle);
    mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN, preference, tile, null, /*key */
    Preference.DEFAULT_ORDER);
    preference.callChangeListener(false);
    assertThat(ShadowTileUtils.getProviderChecked()).isFalse();
    preference.callChangeListener(true);
    assertThat(ShadowTileUtils.getProviderChecked()).isTrue();
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Bundle(android.os.Bundle) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

ProviderTile (com.android.settingslib.drawer.ProviderTile)7 ActivityTile (com.android.settingslib.drawer.ActivityTile)5 Tile (com.android.settingslib.drawer.Tile)5 Bundle (android.os.Bundle)4 SwitchPreference (androidx.preference.SwitchPreference)4 Test (org.junit.Test)4 Config (org.robolectric.annotation.Config)3 ProviderInfo (android.content.pm.ProviderInfo)2 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)2 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 ActivityInfo (android.content.pm.ActivityInfo)1 ArraySet (android.util.ArraySet)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 Preference (androidx.preference.Preference)1 Before (org.junit.Before)1