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);
}
}
}
}
}
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);
}
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();
}
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<>();
}
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();
}
Aggregations