Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c54e87e authored by Maurice Lam's avatar Maurice Lam Committed by Android (Google) Code Review
Browse files

Merge "Add custom view support to Tiles"

parents 990f90cb d8ae77b7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;
import android.text.TextUtils;
import android.widget.RemoteViews;

import java.util.ArrayList;

@@ -84,6 +85,11 @@ public class Tile implements Parcelable {
     */
    public String key;

    /**
     * Optional remote view which will be displayed instead of the regular title-summary item.
     */
    public RemoteViews remoteViews;

    public Tile() {
        // Empty
    }
@@ -119,6 +125,7 @@ public class Tile implements Parcelable {
        dest.writeInt(priority);
        dest.writeBundle(metaData);
        dest.writeString(key);
        dest.writeParcelable(remoteViews, flags);
    }

    public void readFromParcel(Parcel in) {
@@ -139,6 +146,7 @@ public class Tile implements Parcelable {
        priority = in.readInt();
        metaData = in.readBundle();
        key = in.readString();
        remoteViews = in.readParcelable(RemoteViews.class.getClassLoader());
    }

    Tile(Parcel in) {
+15 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.IContentProvider;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
@@ -35,6 +34,7 @@ import android.provider.Settings.Global;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.widget.RemoteViews;

import java.util.ArrayList;
import java.util.Collections;
@@ -153,6 +153,14 @@ public class TileUtils {
    public static final String META_DATA_PREFERENCE_SUMMARY_URI =
            "com.android.settings.summary_uri";

    /**
     * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the
     * custom view which should be displayed for the preference. The custom view will be inflated
     * as a remote view.
     */
    public static final String META_DATA_PREFERENCE_CUSTOM_VIEW =
            "com.android.settings.custom_view";

    public static final String SETTING_PKG = "com.android.settings";

    /**
@@ -353,6 +361,7 @@ public class TileUtils {
            String summary = null;
            String keyHint = null;
            Uri uri = null;
            RemoteViews remoteViews = null;

            // Get the activity's meta-data
            try {
@@ -385,6 +394,10 @@ public class TileUtils {
                            keyHint = metaData.getString(META_DATA_PREFERENCE_KEYHINT);
                        }
                    }
                    if (metaData.containsKey(META_DATA_PREFERENCE_CUSTOM_VIEW)) {
                        int layoutId = metaData.getInt(META_DATA_PREFERENCE_CUSTOM_VIEW);
                        remoteViews = new RemoteViews(applicationInfo.packageName, layoutId);
                    }
                }
            } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
                if (DEBUG) Log.d(LOG_TAG, "Couldn't find info", e);
@@ -414,6 +427,7 @@ public class TileUtils {
                    activityInfo.name);
            // Suggest a key for this tile
            tile.key = keyHint;
            tile.remoteViews = remoteViews;

            return true;
        }
+25 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Pair;

import com.android.settingslib.R;
import com.android.settingslib.SuggestionParser;
import com.android.settingslib.TestConfig;

@@ -293,6 +294,30 @@ public class TileUtilsTest {
        assertThat(outTiles.size()).isEqualTo(1);
    }

    @Test
    public void getTilesForIntent_shouldShowRemoteViewIfSpecified() {
        Intent intent = new Intent();
        Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>();
        List<Tile> outTiles = new ArrayList<>();
        List<ResolveInfo> info = new ArrayList<>();
        ResolveInfo resolveInfo = newInfo(true, null /* category */);
        resolveInfo.activityInfo.metaData.putInt("com.android.settings.custom_view",
                R.layout.user_preference);
        info.add(resolveInfo);

        when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt()))
                .thenReturn(info);

        TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache,
                null /* defaultCategory */, outTiles, false /* usePriority */,
                false /* checkCategory */);

        assertThat(outTiles.size()).isEqualTo(1);
        Tile tile = outTiles.get(0);
        assertThat(tile.remoteViews).isNotNull();
        assertThat(tile.remoteViews.getLayoutId()).isEqualTo(R.layout.user_preference);
    }

    public static ResolveInfo newInfo(boolean systemApp, String category) {
        return newInfo(systemApp, category, null);
    }