Search in sources :

Example 16 with Tile

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);
                    }
                }
            });
        }
    }
}
Also used : IContentProvider(android.content.IContentProvider) ArrayMap(android.util.ArrayMap) Tile(com.android.settingslib.drawer.Tile) Handler(android.os.Handler) Intent(android.content.Intent) PackageManager(android.content.pm.PackageManager) Preference(android.support.v7.preference.Preference) Resources(android.content.res.Resources) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 17 with Tile

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
}
Also used : Tile(com.android.settingslib.drawer.Tile) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Test(org.junit.Test)

Example 18 with Tile

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
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ArrayList(java.util.ArrayList) SuggestionAdapter(com.android.settings.dashboard.suggestions.SuggestionAdapter) Tile(com.android.settingslib.drawer.Tile) RecyclerView(android.support.v7.widget.RecyclerView) DisplayMetrics(android.util.DisplayMetrics) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Test(org.junit.Test)

Example 19 with Tile

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);
}
Also used : Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 20 with Tile

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();
}
Also used : 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)

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