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

Commit 81d20f76 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Support ACTION/THUMBNAIL/SUGGEST corpus for rendering rendering" into sc-dev

parents 15b0f700 7575cca2
Loading
Loading
Loading
Loading
+0 −34
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2020 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<com.android.launcher3.search.SearchResultSuggestion xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:launcher="http://schemas.android.com/apk/res-auto"
    style="@style/BaseIcon"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="start|center_vertical"
    android:textAlignment="viewStart"
    android:textColor="?android:attr/textColorPrimary"
    android:textSize="18sp"
    android:padding="@dimen/dynamic_grid_edge_margin"
    launcher:iconDisplay="hero_app"
    android:drawableTint="?android:attr/textColorPrimary"
    launcher:customIcon="@drawable/ic_allapps_search"
    launcher:iconSizeOverride="24dp"
    launcher:matchTextInsetWithQuery="true"
    launcher:layoutHorizontal="true"
    android:drawablePadding="@dimen/dynamic_grid_icon_drawable_padding">

</com.android.launcher3.search.SearchResultSuggestion>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<com.android.launcher3.search.ThumbnailSearchResultView
<com.android.launcher3.search.SearchResultThumbnailView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="125dp"
    android:layout_height="125dp"/>
 No newline at end of file
+20 −15
Original line number Diff line number Diff line
@@ -18,7 +18,11 @@ package com.android.launcher3.search;

import static com.android.launcher3.allapps.AllAppsGridAdapter.VIEW_TYPE_ICON;

import android.app.search.Query;
import android.app.search.SearchSession;
import android.app.search.SearchTarget;
import android.app.search.SearchTargetEvent;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
import android.view.View;
@@ -30,7 +34,6 @@ import com.android.launcher3.R;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsGridAdapter;
import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.config.FeatureFlags;

/**
 * Provides views for on-device search results
@@ -43,12 +46,12 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
    public static final int VIEW_TYPE_SEARCH_ICON_ROW = (1 << 9);
    public static final int VIEW_TYPE_SEARCH_PEOPLE = 1 << 11;
    public static final int VIEW_TYPE_SEARCH_THUMBNAIL = 1 << 12;
    public static final int VIEW_TYPE_SEARCH_SUGGEST = 1 << 13;
    public static final int VIEW_TYPE_SEARCH_WIDGET_LIVE = 1 << 15;
    public static final int VIEW_TYPE_SEARCH_WIDGET_PREVIEW = 1 << 16;

    private final AllAppsContainerView mAppsView;
    private static final String TAG = "SearchServiceAdapterProvider";

    private final AllAppsContainerView mAppsView;
    private final SparseIntArray mViewTypeToLayoutMap = new SparseIntArray();

    public DeviceSearchAdapterProvider(Launcher launcher, AllAppsContainerView appsView) {
@@ -61,7 +64,6 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
        mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_SLICE, R.layout.search_result_slice);
        mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_PEOPLE, R.layout.search_result_people_item);
        mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_THUMBNAIL, R.layout.search_result_thumbnail);
        mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_SUGGEST, R.layout.search_result_suggest);
        mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_WIDGET_LIVE, R.layout.search_result_widget_live);
        mViewTypeToLayoutMap.put(VIEW_TYPE_SEARCH_WIDGET_PREVIEW,
                R.layout.search_result_widget_preview);
@@ -74,11 +76,7 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
        SearchTargetHandler
                payloadResultView =
                (SearchTargetHandler) holder.itemView;
        if (!FeatureFlags.USE_SEARCH_API.get()) {
            payloadResultView.applySearchTarget(item.getSearchTargetLegacy());
        } else {
            payloadResultView.applySearchTarget(item.getSearchTarget(), item.getInlineItems());
        }
        payloadResultView.apply(item.getSearchTarget(), item.getInlineItems());
    }

    @Override
@@ -113,7 +111,8 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {

    /**
     * Determines what view type should be used to present search target.
     * Returns -1 if viewType is not found
     * Returns -1 if viewType is not found or if required field is not present
     * to render the viewType.
     */
    public int getViewTypeForSearchTarget(SearchTarget t) {
        switch (t.getLayoutType()) {
@@ -122,14 +121,20 @@ public class DeviceSearchAdapterProvider extends SearchAdapterProvider {
            case LayoutType.ICON_SINGLE_VERTICAL_TEXT:
                return VIEW_TYPE_SEARCH_ICON;
            case LayoutType.ICON_SLICE:
                if (t.getSliceUri() != null) {
                    return VIEW_TYPE_SEARCH_SLICE;
            case LayoutType.ICON_DOUBLE_HORIZONTAL_TEXT_BUTTON:
                }
                Log.w(TAG, "Dropping as LayoutType.ICON_SLICE target doesn't contain sliceUri.");
            case LayoutType.ICON_DOUBLE_HORIZONTAL_TEXT:
            case LayoutType.ICON_SINGLE_HORIZONTAL_TEXT:
                return VIEW_TYPE_SEARCH_ICON_ROW;
            default:
                return -1;

            case LayoutType.THUMBNAIL:
                if (t.getSearchAction() != null) {
                    return VIEW_TYPE_SEARCH_THUMBNAIL;
                }
                Log.w(TAG, "Dropping as LayoutType.THUMBNAIL target doesn't contain searchAction.");
        }

        return -1;
    }
}
+1 −4
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_ICON_ROW;
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_PEOPLE;
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_SLICE;
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_SUGGEST;
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_THUMBNAIL;
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_WIDGET_LIVE;
import static com.android.launcher3.search.DeviceSearchAdapterProvider.VIEW_TYPE_SEARCH_WIDGET_PREVIEW;
@@ -45,15 +44,13 @@ public class SearchAdapterItem extends AllAppsGridAdapter.AdapterItem {
    private static final int AVAILABLE_FOR_ACCESSIBILITY =
            VIEW_TYPE_SEARCH_SLICE | VIEW_TYPE_SEARCH_PEOPLE | VIEW_TYPE_SEARCH_THUMBNAIL
                    | VIEW_TYPE_SEARCH_ICON_ROW | VIEW_TYPE_SEARCH_ICON
                    | VIEW_TYPE_SEARCH_WIDGET_PREVIEW | VIEW_TYPE_SEARCH_WIDGET_LIVE
                    | VIEW_TYPE_SEARCH_SUGGEST;
                    | VIEW_TYPE_SEARCH_WIDGET_PREVIEW | VIEW_TYPE_SEARCH_WIDGET_LIVE;

    public SearchAdapterItem(SearchTargetLegacy searchTargetLegacy, int type) {
        mSearchTargetLegacy = searchTargetLegacy;
        viewType = type;
    }


    public SearchAdapterItem(SearchTarget searchTarget, int type) {
        mSearchTarget = searchTarget;
        viewType = type;
+59 −30
Original line number Diff line number Diff line
@@ -15,11 +15,18 @@
 */
package com.android.launcher3.search;

import static com.android.launcher3.model.data.SearchActionItemInfo.FLAG_BADGE_FROM_ICON;
import static com.android.launcher3.model.data.SearchActionItemInfo.FLAG_PRIMARY_ICON_FROM_TITLE;
import static com.android.launcher3.search.SearchTargetUtil.BUNDLE_EXTRA_BADGE_FROM_ICON;
import static com.android.launcher3.search.SearchTargetUtil.BUNDLE_EXTRA_PRIMARY_ICON_FROM_TITLE;
import static com.android.launcher3.search.SearchTargetUtil.BUNDLE_EXTRA_SHOULD_START;
import static com.android.launcher3.search.SearchTargetUtil.BUNDLE_EXTRA_SHOULD_START_FOR_RESULT;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;

import android.app.search.SearchAction;
import android.app.search.SearchTarget;
import android.app.search.SearchTargetEvent;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ShortcutInfo;
@@ -37,12 +44,14 @@ import com.android.launcher3.BubbleTextView;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.allapps.AllAppsStore;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.model.data.PackageItemInfo;
import com.android.launcher3.model.data.SearchActionItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.touch.ItemClickHandler;
import com.android.launcher3.touch.ItemLongClickListener;
import com.android.launcher3.util.ComponentKey;

@@ -52,17 +61,14 @@ import java.util.function.Consumer;
/**
 * A {@link BubbleTextView} representing a single cell result in AllApps
 */
public class SearchResultIcon extends BubbleTextView implements
        SearchTargetHandler, View.OnClickListener,
        View.OnLongClickListener {

    private static final String BUNDLE_EXTRA_SHOULD_START = "should_start";
    private static final String BUNDLE_EXTRA_SHOULD_START_FOR_RESULT = "should_start_for_result";
public class SearchResultIcon extends BubbleTextView implements SearchTargetHandler {

    private final Launcher mLauncher;

    private String mTargetId;
    private Consumer<ItemInfoWithIcon> mOnItemInfoChanged;


    public SearchResultIcon(Context context) {
        this(context, null, 0);
    }
@@ -96,34 +102,34 @@ public class SearchResultIcon extends BubbleTextView implements
    public void applySearchTarget(SearchTarget searchTarget, List<SearchTarget> inlineItems,
            Consumer<ItemInfoWithIcon> cb) {
        mOnItemInfoChanged = cb;
        applySearchTarget(searchTarget, inlineItems);
        apply(searchTarget, inlineItems);
    }

    @Override
    public void applySearchTarget(SearchTarget parentTarget, List<SearchTarget> children) {
        switch (parentTarget.getResultType()) {
            case ResultType.APPLICATION:
                prepareUsingApp(new ComponentName(parentTarget.getPackageName(),
                        parentTarget.getExtras().getString("class")), parentTarget.getUserHandle());
                mLongPressSupported = true;
                break;
            case ResultType.SHORTCUT:
    public void apply(SearchTarget parentTarget, List<SearchTarget> children) {
        mTargetId = parentTarget.getId();
        if (parentTarget.getShortcutInfo() != null) {
            prepareUsingShortcutInfo(parentTarget.getShortcutInfo());
            mLongPressSupported = true;
                break;
            default:
        } else if (parentTarget.getSearchAction() != null) {
            prepareUsingSearchAction(parentTarget);
            mLongPressSupported = false;
                break;
        } else {
            prepareUsingApp(new ComponentName(parentTarget.getPackageName(),
                    parentTarget.getExtras().getString(SearchTargetUtil.EXTRA_CLASS)),
                    parentTarget.getUserHandle());
            mLongPressSupported = true;
        }
    }

    private void prepareUsingSearchAction(SearchTarget searchTarget) {
        SearchAction searchAction = searchTarget.getSearchAction();
        Bundle extras = searchAction.getExtras();

        SearchActionItemInfo itemInfo = new SearchActionItemInfo(searchAction.getIcon(),
                searchTarget.getPackageName(), searchTarget.getUserHandle(),
                searchAction.getTitle());
                searchAction.getTitle()
        );
        itemInfo.setIntent(searchAction.getIntent());
        itemInfo.setPendingIntent(searchAction.getPendingIntent());

@@ -136,7 +142,12 @@ public class SearchResultIcon extends BubbleTextView implements
        } else if (extras != null && extras.getBoolean(BUNDLE_EXTRA_SHOULD_START)) {
            itemInfo.setFlags(SearchActionItemInfo.FLAG_SHOULD_START);
        }

        if (extras != null && extras.getBoolean(BUNDLE_EXTRA_BADGE_FROM_ICON)) {
            itemInfo.setFlags(FLAG_BADGE_FROM_ICON);
        }
        if (extras != null && extras.getBoolean(BUNDLE_EXTRA_PRIMARY_ICON_FROM_TITLE)) {
            itemInfo.setFlags(FLAG_PRIMARY_ICON_FROM_TITLE);
        }

        notifyItemInfoChanged(itemInfo);
        LauncherAppState appState = LauncherAppState.getInstance(mLauncher);
@@ -144,17 +155,33 @@ public class SearchResultIcon extends BubbleTextView implements
            try (LauncherIcons li = LauncherIcons.obtain(getContext())) {
                Icon icon = searchTarget.getSearchAction().getIcon();
                Drawable d;
                // This bitmapInfo can be used as main icon or as a badge
                BitmapInfo bitmapInfo;
                if (icon == null) {
                    PackageItemInfo pkgInfo = new PackageItemInfo(searchTarget.getPackageName());
                    pkgInfo.user = searchTarget.getUserHandle();
                    appState.getIconCache().getTitleAndIconForApp(pkgInfo, false);
                    itemInfo.bitmap = pkgInfo.bitmap;
                    bitmapInfo = pkgInfo.bitmap;
                } else {
                    d = itemInfo.getIcon().loadDrawable(getContext());
                    itemInfo.bitmap = li.createBadgedIconBitmap(d, itemInfo.user,
                    bitmapInfo = li.createBadgedIconBitmap(d, itemInfo.user,
                            Build.VERSION.SDK_INT);
                }

                BitmapInfo bitmapMainIcon;
                if (itemInfo.hasFlags(FLAG_PRIMARY_ICON_FROM_TITLE)) {
                    bitmapMainIcon = li.createIconBitmap(
                            String.valueOf(itemInfo.title.charAt(0)),
                            bitmapInfo.color);
                } else {
                    bitmapMainIcon = bitmapInfo;
                }
                if (itemInfo.hasFlags(FLAG_BADGE_FROM_ICON)) {
                    itemInfo.bitmap = li.badgeBitmap(bitmapMainIcon.icon, bitmapInfo);
                } else {
                    itemInfo.bitmap = bitmapInfo;
                }

            }
            MAIN_EXECUTOR.post(() -> applyFromSearchActionItemInfo(itemInfo));
        });
@@ -185,26 +212,28 @@ public class SearchResultIcon extends BubbleTextView implements

    @Override
    public boolean quickSelect() {
        //TODO: event reporting
        this.performClick();
        notifyEvent(mLauncher, mTargetId, SearchTargetEvent.ACTION_LAUNCH_KEYBOARD_FOCUS);
        return true;
    }

    @Override
    public void onClick(View view) {
        //TODO: event reporting
        mLauncher.getItemOnClickListener().onClick(this);
        ItemClickHandler.INSTANCE.onClick(view);
        notifyEvent(mLauncher, mTargetId, SearchTargetEvent.ACTION_LAUNCH_TOUCH);
    }

    @Override
    public boolean onLongClick(View view) {
        //TODO: event reporting
        if (!mLongPressSupported) {
            return false;
        }
        notifyEvent(mLauncher, mTargetId, SearchTargetEvent.ACTION_LONGPRESS);
        return ItemLongClickListener.INSTANCE_ALL_APPS.onLongClick(this);
    }



    private void notifyItemInfoChanged(ItemInfoWithIcon itemInfoWithIcon) {
        if (mOnItemInfoChanged != null) {
            mOnItemInfoChanged.accept(itemInfoWithIcon);
Loading