use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.
the class SecurityFeatureProviderImpl method updatePreferencesToRunOnWorkerThread.
@VisibleForTesting
void updatePreferencesToRunOnWorkerThread(Context context, PreferenceScreen preferenceScreen, DashboardCategory dashboardCategory) {
int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
Map<String, IContentProvider> providerMap = new ArrayMap<>();
for (int i = 0; i < tilesCount; i++) {
Tile tile = dashboardCategory.getTile(i);
// If the tile does not have a key or appropriate meta data, skip it.
if (TextUtils.isEmpty(tile.key) || (tile.metaData == null)) {
continue;
}
Preference matchingPref = preferenceScreen.findPreference(tile.key);
// If the tile does not have a matching preference, skip it.
if (matchingPref == null) {
continue;
}
// Check if the tile has content providers for dynamically updatable content.
final String iconUri = tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_ICON_URI, null);
final String summaryUri = tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, null);
if (!TextUtils.isEmpty(iconUri)) {
String packageName = null;
if (tile.intent != null) {
Intent intent = tile.intent;
if (!TextUtils.isEmpty(intent.getPackage())) {
packageName = intent.getPackage();
} else if (intent.getComponent() != null) {
packageName = intent.getComponent().getPackageName();
}
}
Pair<String, Integer> icon = TileUtils.getIconFromUri(context, packageName, iconUri, providerMap);
if (icon != null) {
sIconCache.put(iconUri, icon);
// Icon is only returned if the icon belongs to Settings or the target app.
// setIcon must be called on the UI thread.
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
try {
matchingPref.setIcon(context.getPackageManager().getResourcesForApplication(icon.first).getDrawable(icon.second, /* res id */
context.getTheme()));
} catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
// Intentionally ignored. If icon resources cannot be found, do not
// update.
}
}
});
}
}
if (!TextUtils.isEmpty(summaryUri)) {
String summary = TileUtils.getTextFromUri(context, summaryUri, providerMap, TileUtils.META_DATA_PREFERENCE_SUMMARY);
sSummaryCache.put(summaryUri, summary);
// setSummary must be called on UI thread.
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
// Only update the summary if it has actually changed.
if (summary == null) {
if (matchingPref.getSummary() != null) {
matchingPref.setSummary(summary);
}
} else if (!summary.equals(matchingPref.getSummary())) {
matchingPref.setSummary(summary);
}
}
});
}
}
}
use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.
the class DashboardAdapterTest method testSuggestionDismissed_moreThanTwoSuggestions_defaultMode_shouldNotCrash.
@Test
public void testSuggestionDismissed_moreThanTwoSuggestions_defaultMode_shouldNotCrash() {
final RecyclerView data = new RecyclerView(RuntimeEnvironment.application);
final View itemView = mock(View.class);
when(itemView.findViewById(R.id.data)).thenReturn(data);
final DashboardAdapter.SuggestionAndConditionContainerHolder holder = new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
final List<Tile> suggestions = makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4");
final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null, /*savedInstance */
null, /* conditions */
null, /* suggestionParser */
null));
adapter.setCategoriesAndSuggestions(null, /* category */
suggestions);
adapter.onBindConditionAndSuggestion(holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
// default mode, only displaying 2 suggestions
adapter.onSuggestionDismissed(suggestions.get(1));
// verify operations that access the lists will not cause ConcurrentModificationException
assertThat(holder.data.getAdapter().getItemCount()).isEqualTo(1);
adapter.setCategoriesAndSuggestions(null, /* category */
suggestions);
// should not crash
}
use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.
the class DashboardAdapterTest method testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash.
@Test
public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null);
final List<Tile> suggestions = makeSuggestions("pkg1");
final DashboardCategory category = mock(DashboardCategory.class);
final List<Tile> tiles = new ArrayList<>();
tiles.add(mock(Tile.class));
category.tiles = tiles;
mDashboardAdapter.setCategoriesAndSuggestions(category, suggestions);
final RecyclerView data = mock(RecyclerView.class);
when(data.getResources()).thenReturn(mResources);
when(data.getContext()).thenReturn(mContext);
when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
final View itemView = mock(View.class);
when(itemView.findViewById(R.id.data)).thenReturn(data);
final DashboardAdapter.SuggestionAndConditionContainerHolder holder = new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
mDashboardAdapter.onBindConditionAndSuggestion(holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
verify(data).setAdapter(any(SuggestionAdapter.class));
// should not crash
}
use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.
the class DashboardDataTest method testGetPositionByTile_notExisted_returnNotFound.
@Test
public void testGetPositionByTile_notExisted_returnNotFound() {
final Tile tile = mock(Tile.class);
tile.title = "";
final int position = mDashboardDataWithOneConditions.getPositionByTile(tile);
assertThat(position).isEqualTo(DashboardData.POSITION_NOT_FOUND);
}
use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by LineageOS.
the class DashboardFeatureProviderImplTest method bindPreference_noFragmentMetadata_shouldBindToProfileSelector.
@Test
public void bindPreference_noFragmentMetadata_shouldBindToProfileSelector() {
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.userHandle.add(mock(UserHandle.class));
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
preference.getOnPreferenceClickListener().onPreferenceClick(null);
verify(mActivity).getFragmentManager();
}
Aggregations