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

Commit 314761a8 authored by Samuel Fufa's avatar Samuel Fufa
Browse files

Setup SearchResultIcon for single cell results

SearchResultIcon will be able to render apps, shortcuts and remote actions. It can also handle its own focused state drawing.

Screenshot: https://screenshot.googleplex.com/C3KgjJtLQTBPgaf

Bug: 170752716
Test: Manual
Change-Id: I460a9c128ea3f5814784e342c5d5fa5b7e310882
parent d5bbe680
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
    with some minor changed based on the derivative app.
    -->

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.SET_WALLPAPER" />
    <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
+4 −11
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2015 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.
@@ -13,16 +12,10 @@
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<com.android.launcher3.BubbleTextView
    xmlns:android="http://schemas.android.com/apk/res/android"
<com.android.launcher3.BubbleTextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:launcher="http://schemas.android.com/apk/res-auto"
    style="@style/BaseIcon"
    style="@style/BaseIcon.AllApps"
    android:id="@+id/icon"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stateListAnimator="@animator/all_apps_fastscroll_icon_anim"
    launcher:iconDisplay="all_apps"
    launcher:centerVertically="true"
    android:paddingLeft="@dimen/dynamic_grid_cell_padding_x"
    android:paddingRight="@dimen/dynamic_grid_cell_padding_x" />
    launcher:centerVertically="true" />
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2008 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.views.SearchResultIcon xmlns:launcher="http://schemas.android.com/apk/res-auto"
    style="@style/BaseIcon.AllApps"
    launcher:iconDisplay="all_apps"
    launcher:centerVertically="true" />
+10 −0
Original line number Diff line number Diff line
@@ -223,6 +223,16 @@
        <item name="android:lines">1</item>
    </style>

    <!-- Base theme for AllApps BubbleTextViews -->
    <style name="BaseIcon.AllApps" parent="BaseIcon">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:stateListAnimator">@animator/all_apps_fastscroll_icon_anim</item>
        <item name="android:paddingLeft">@dimen/dynamic_grid_cell_padding_x</item>
        <item name="android:paddingRight">@dimen/dynamic_grid_cell_padding_x</item>
    </style>


    <!-- Icon displayed on the workspace -->
    <style name="BaseIcon.Workspace" >
        <item name="android:shadowRadius">2.0</item>
+67 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.launcher3;

import static com.android.launcher3.FastBitmapDrawable.newIcon;
import static com.android.launcher3.graphics.IconShape.getShape;
import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon;
import static com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound;

@@ -27,15 +28,18 @@ import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Process;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.util.Property;
@@ -50,6 +54,8 @@ import androidx.core.graphics.ColorUtils;

import com.android.launcher3.Launcher.OnResumeCallback;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
import com.android.launcher3.allapps.AllAppsSectionDecorator;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dot.DotInfo;
import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.folder.FolderIcon;
@@ -60,6 +66,7 @@ import com.android.launcher3.graphics.PreloadIconDrawable;
import com.android.launcher3.icons.DotRenderer;
import com.android.launcher3.icons.IconCache.IconLoadRequest;
import com.android.launcher3.icons.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfoWithIcon;
@@ -79,7 +86,7 @@ import java.text.NumberFormat;
 * too aggressive.
 */
public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, OnResumeCallback,
        IconLabelDotView, DraggableView, Reorderable {
        IconLabelDotView, DraggableView, Reorderable, AllAppsSectionDecorator.SelfDecoratingView {

    private static final int DISPLAY_WORKSPACE = 0;
    private static final int DISPLAY_ALL_APPS = 1;
@@ -87,6 +94,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
    private static final int DISPLAY_HERO_APP = 5;

    private static final int[] STATE_PRESSED = new int[]{android.R.attr.state_pressed};
    private static final float HIGHLIGHT_SCALE = 1.16f;


    private final PointF mTranslationForReorderBounce = new PointF(0, 0);
    private final PointF mTranslationForReorderPreview = new PointF(0, 0);
@@ -95,6 +104,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,

    private float mScaleForReorderBounce = 1f;

    protected final Paint mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    private final Path mHighlightPath = new Path();
    protected int mHighlightColor = Color.TRANSPARENT;
    private final BlurMaskFilter mHighlightShadowFilter;

    private static final Property<BubbleTextView, Float> DOT_SCALE_PROPERTY
            = new Property<BubbleTextView, Float>(Float.TYPE, "dotScale") {
        @Override
@@ -208,6 +222,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
        setEllipsize(TruncateAt.END);
        setAccessibilityDelegate(mActivity.getAccessibilityDelegate());
        setTextAlpha(1f);

        int shadowSize = context.getResources().getDimensionPixelSize(
                R.dimen.blur_size_click_shadow);
        mHighlightShadowFilter = new BlurMaskFilter(shadowSize, BlurMaskFilter.Blur.INNER);

    }

    @Override
@@ -421,8 +440,38 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,

    @Override
    public void onDraw(Canvas canvas) {
        if (FeatureFlags.ENABLE_DEVICE_SEARCH.get() && mHighlightColor != Color.TRANSPARENT) {
            int count = canvas.save();
            drawFocusHighlight(canvas);
            canvas.restoreToCount(count);
        }
        super.onDraw(canvas);
        drawDotIfNecessary(canvas);
    }

    protected void drawFocusHighlight(Canvas canvas) {
        boolean isBadged = getTag() instanceof ItemInfo && !Process.myUserHandle().equals(
                ((ItemInfo) getTag()).user);
        float insetScale = (HIGHLIGHT_SCALE - 1) / 2;
        canvas.translate(-getIconSize() * insetScale, -insetScale * getIconSize());
        float outlineSize = getIconSize() * HIGHLIGHT_SCALE;
        mHighlightPath.reset();
        mHighlightPaint.reset();
        getIconBounds(mDotParams.iconBounds);
        getShape().addToPath(mHighlightPath, mDotParams.iconBounds.left, mDotParams.iconBounds.top,
                outlineSize / 2);
        if (isBadged) {
            float borderSize = outlineSize - getIconSize();
            float badgeSize = LauncherIcons.getBadgeSizeForIconSize(getIconSize()) + borderSize;
            float badgeInset = outlineSize - badgeSize;
            getShape().addToPath(mHighlightPath, mDotParams.iconBounds.left + badgeInset,
                    mDotParams.iconBounds.top + badgeInset, badgeSize / 2);
        }
        mHighlightPaint.setMaskFilter(mHighlightShadowFilter);
        mHighlightPaint.setColor(mDotParams.color);
        canvas.drawPath(mHighlightPath, mHighlightPaint);
        mHighlightPaint.setMaskFilter(null);
        mHighlightPaint.setColor(mHighlightColor);
        canvas.drawPath(mHighlightPath, mHighlightPaint);
    }

    /**
@@ -787,10 +836,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,

    @Override
    public SafeCloseable prepareDrawDragView() {
        int highlightColor = mHighlightColor;
        mHighlightColor = Color.TRANSPARENT;
        resetIconScale();
        setForceHideDot(true);
        return () -> {
        };
        return () -> mHighlightColor = highlightColor;
    }

    private void resetIconScale() {
@@ -827,4 +877,17 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
        });
        iconUpdateAnimation.start();
    }


    @Override
    public void decorate(int color) {
        mHighlightColor = color;
        invalidate();
    }

    @Override
    public void removeDecoration() {
        mHighlightColor = Color.TRANSPARENT;
        invalidate();
    }
}
Loading