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

Commit 313ca2b3 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9787270 from 767f8111 to tm-qpr3-release

Change-Id: Ifa8f8589634c65c2e805309deb3ccc741ac340a0
parents 22f4b490 767f8111
Loading
Loading
Loading
Loading
+61 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.app.search.LayoutType.TALL_CARD_WITH_IMAGE_NO_ICON;
import android.app.blob.BlobHandle;
import android.app.search.SearchAction;
import android.app.search.SearchTarget;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.Nullable;
@@ -125,6 +126,8 @@ public class SearchTargetExtras {
    public static final String WEB_SUG_COUNT = "web_sug_count";

    /**
     *  Replaced with thumbnail crop type
     *
     *  Flag to control whether thumbnail(s) should fill the thumbnail container's width or not.
     *  When this flag is true, when there are less than the maximum number of thumbnails in the
     *  container, the thumbnails will stretch to fill the container's width.
@@ -133,8 +136,54 @@ public class SearchTargetExtras {
     *
     *  Only relevant in {@link LayoutType#THUMBNAIL_CONTAINER} and {@link LayoutType#THUMBNAIL}.
     */
    @Deprecated
    public static final String BUNDLE_EXTRA_SHOULD_FILL_CONTAINER_WIDTH =
            "should_fill_container_width";

    /**
     * Flag to control thumbnail container's crop mode, controlling the layout
     *
     * <ul>
     *     <li>SQUARE: Thumbnail(s) will be cropped to a square aspect ratio around the center.</li>
     *     <li>FILL_WIDTH: Thumbnail(s) should collectively fill the thumbnail container's width.
     *     When there are less than the maximum number of thumbnails in the container, the
     *     layouts' width will stretch to fit the container, the images will fill the width
     *     and then the top/bottom cropped to fit.</li>
     *     <li>FILL_HEIGHT: Thumbnail(s) should fill height and be cropped to fit in the width
     *     based on {@link BUNDLE_EXTRA_THUMBNAIL_MAX_COUNT} as the column count. When the image
     *     width is larger than the width / column, both sides will be cropped while maintaining
     *     the center.
     *     When there are less thumbnails than the max count, the layout will be constrained to
     *     equally divide the width of the container. If there are more thumbnails than the max
     *     count, the excessive thumbnails will be ignored.</li>
     * </ul>
     *
     * Only relevant in {@link LayoutType#THUMBNAIL_CONTAINER} and {@link LayoutType#THUMBNAIL}.
     */
    public static final String BUNDLE_EXTRA_THUMBNAIL_CROP_TYPE = "thumbnail_crop_type";
    public enum ThumbnailCropType {
        DEFAULT(0), // defaults to SQUARE behavior by {@link LayoutType#THUMBNAIL_CONTAINER}.
        SQUARE(1),
        FILL_WIDTH(2),
        FILL_HEIGHT(3);

        private final int mTypeId;

        ThumbnailCropType(int typeId) {
            mTypeId = typeId;
        }

        public int toTypeId() {
            return mTypeId;
        }
    };

    /**
     * How many grid spaces for the thumbnail container should be reserved.
     * Only relevant for {@link ThumbnailCropType#FILL_HEIGHT} crop type.
     */
    public static final String BUNDLE_EXTRA_THUMBNAIL_MAX_COUNT = "thumbnail_max_count";

    /**
     *  Flag to control whether the SearchTarget's label should be hidden.
     *  When this flag is true, label will be hidden.
@@ -164,4 +213,16 @@ public class SearchTargetExtras {
        return target != null && isAnswer(target)
                && target.getLayoutType().equals(TALL_CARD_WITH_IMAGE_NO_ICON);
    }

    /** Get the crop type thumbnails should use. Returns DEFAULT if not specified. */
    public static ThumbnailCropType getThumbnailCropType(@Nullable SearchTarget target)
            throws ArrayIndexOutOfBoundsException {
        Bundle extras = target == null ? Bundle.EMPTY : target.getExtras();
        if (extras.isEmpty()) {
            return ThumbnailCropType.DEFAULT;
        }
        ThumbnailCropType cropType = ThumbnailCropType.values()[extras.getInt(
                BUNDLE_EXTRA_THUMBNAIL_CROP_TYPE)];
        return cropType != null ? cropType : ThumbnailCropType.DEFAULT;
    }
}