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

Commit c9a0a7c6 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Moving the shortcut application logic to the DeepShortcutView. This...

Merge "Moving the shortcut application logic to the DeepShortcutView. This makes the logic for accessing various properties consistant and and ties it to the UI of the DeepShortcutView." into ub-launcher3-calgary-polish
parents 8769b44a 5836bf72
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.shortcuts.DeepShortcutView;


import java.util.ArrayList;
import java.util.ArrayList;


@@ -46,7 +47,10 @@ public class ShortcutMenuAccessibilityDelegate extends LauncherAccessibilityDele
    @Override
    @Override
    public boolean performAction(View host, ItemInfo item, int action) {
    public boolean performAction(View host, ItemInfo item, int action) {
        if (action == ADD_TO_WORKSPACE) {
        if (action == ADD_TO_WORKSPACE) {
            final ShortcutInfo info = (ShortcutInfo) item;
            if (!(host.getParent() instanceof DeepShortcutView)) {
                return false;
            }
            final ShortcutInfo info = ((DeepShortcutView) host.getParent()).getFinalInfo();
            final int[] coordinates = new int[2];
            final int[] coordinates = new int[2];
            final long screenId = findSpaceOnWorkspace(item, coordinates);
            final long screenId = findSpaceOnWorkspace(item, coordinates);
            Runnable onComplete = new Runnable() {
            Runnable onComplete = new Runnable() {
+32 −1
Original line number Original line Diff line number Diff line
@@ -21,16 +21,19 @@ import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.View;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.FrameLayout;


import com.android.launcher3.IconCache;
import com.android.launcher3.IconCache;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LogAccelerateInterpolator;
import com.android.launcher3.LogAccelerateInterpolator;
import com.android.launcher3.R;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.Utilities;
import com.android.launcher3.shortcuts.DeepShortcutsContainer.UnbadgedShortcutInfo;
import com.android.launcher3.util.PillRevealOutlineProvider;
import com.android.launcher3.util.PillRevealOutlineProvider;
import com.android.launcher3.util.PillWidthRevealOutlineProvider;
import com.android.launcher3.util.PillWidthRevealOutlineProvider;


@@ -48,6 +51,8 @@ public class DeepShortcutView extends FrameLayout implements ValueAnimator.Anima
    private View mIconView;
    private View mIconView;
    private float mOpenAnimationProgress;
    private float mOpenAnimationProgress;


    private UnbadgedShortcutInfo mInfo;

    public DeepShortcutView(Context context) {
    public DeepShortcutView(Context context) {
        this(context, null, 0);
        this(context, null, 0);
    }
    }
@@ -87,10 +92,36 @@ public class DeepShortcutView extends FrameLayout implements ValueAnimator.Anima
        mPillRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
        mPillRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
    }
    }


    public void applyShortcutInfo(ShortcutInfo info) {
    /** package private **/
    void applyShortcutInfo(UnbadgedShortcutInfo info, DeepShortcutsContainer container) {
        mInfo = info;
        IconCache cache = LauncherAppState.getInstance().getIconCache();
        IconCache cache = LauncherAppState.getInstance().getIconCache();
        mBubbleText.applyFromShortcutInfo(info, cache);
        mBubbleText.applyFromShortcutInfo(info, cache);
        mIconView.setBackground(mBubbleText.getIcon());
        mIconView.setBackground(mBubbleText.getIcon());

        // Use the long label as long as it exists and fits.
        CharSequence longLabel = info.mDetail.getLongLabel();
        int availableWidth = mBubbleText.getWidth() - mBubbleText.getTotalPaddingLeft()
                - mBubbleText.getTotalPaddingRight();
        boolean usingLongLabel = !TextUtils.isEmpty(longLabel)
                && mBubbleText.getPaint().measureText(longLabel.toString()) <= availableWidth;
        mBubbleText.setText(usingLongLabel ? longLabel : info.mDetail.getShortLabel());

        // TODO: Add the click handler to this view directly and not the child view.
        mBubbleText.setOnClickListener(Launcher.getLauncher(getContext()));
        mBubbleText.setOnLongClickListener(container);
        mBubbleText.setOnTouchListener(container);
    }

    /**
     * Returns the shortcut info that is suitable to be added on the homescreen
     */
    public ShortcutInfo getFinalInfo() {
        ShortcutInfo badged = new ShortcutInfo(mInfo);
        // Queue an update task on the worker thread. This ensures that the badged
        // shortcut eventually gets its icon updated.
        Launcher.getLauncher(getContext()).getModel().updateShortcutInfo(mInfo.mDetail, badged);
        return badged;
    }
    }


    public View getIconView() {
    public View getIconView() {
+9 −35
Original line number Original line Diff line number Diff line
@@ -183,12 +183,8 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
                }
                }
                for (int i = 0; i < shortcuts.size(); i++) {
                for (int i = 0; i < shortcuts.size(); i++) {
                    final ShortcutInfoCompat shortcut = shortcuts.get(i);
                    final ShortcutInfoCompat shortcut = shortcuts.get(i);
                    final ShortcutInfo launcherShortcutInfo =
                    uiHandler.post(new UpdateShortcutChild(
                            new UnbadgedShortcutInfo(shortcut, mLauncher);
                            i, new UnbadgedShortcutInfo(shortcut, mLauncher)));
                    CharSequence shortLabel = shortcut.getShortLabel();
                    CharSequence longLabel = shortcut.getLongLabel();
                    uiHandler.post(new UpdateShortcutChild(i, launcherShortcutInfo,
                            shortLabel, longLabel));
                }
                }
            }
            }
        });
        });
@@ -197,32 +193,17 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
    /** Updates the child of this container at the given index based on the given shortcut info. */
    /** Updates the child of this container at the given index based on the given shortcut info. */
    private class UpdateShortcutChild implements Runnable {
    private class UpdateShortcutChild implements Runnable {
        private int mShortcutChildIndex;
        private int mShortcutChildIndex;
        private ShortcutInfo mShortcutChildInfo;
        private UnbadgedShortcutInfo mShortcutChildInfo;
        private CharSequence mShortLabel;
        private CharSequence mLongLabel;


        public UpdateShortcutChild(int shortcutChildIndex, ShortcutInfo shortcutChildInfo,
        public UpdateShortcutChild(int shortcutChildIndex, UnbadgedShortcutInfo shortcutChildInfo) {
                CharSequence shortLabel, CharSequence longLabel) {
            mShortcutChildIndex = shortcutChildIndex;
            mShortcutChildIndex = shortcutChildIndex;
            mShortcutChildInfo = shortcutChildInfo;
            mShortcutChildInfo = shortcutChildInfo;
            mShortLabel = shortLabel;
            mLongLabel = longLabel;
        }
        }


        @Override
        @Override
        public void run() {
        public void run() {
            DeepShortcutView shortcutViewContainer = getShortcutAt(mShortcutChildIndex);
            getShortcutAt(mShortcutChildIndex)
            shortcutViewContainer.applyShortcutInfo(mShortcutChildInfo);
                    .applyShortcutInfo(mShortcutChildInfo, DeepShortcutsContainer.this);
            BubbleTextView shortcutView = getShortcutAt(mShortcutChildIndex).getBubbleText();
            // Use the long label as long as it exists and fits.
            int availableWidth = shortcutView.getWidth() - shortcutView.getTotalPaddingLeft()
                    - shortcutView.getTotalPaddingRight();
            boolean usingLongLabel = !TextUtils.isEmpty(mLongLabel)
                    && shortcutView.getPaint().measureText(mLongLabel.toString()) <= availableWidth;
            shortcutView.setText(usingLongLabel ? mLongLabel : mShortLabel);
            shortcutView.setOnClickListener(mLauncher);
            shortcutView.setOnLongClickListener(DeepShortcutsContainer.this);
            shortcutView.setOnTouchListener(DeepShortcutsContainer.this);
        }
        }
    }
    }


@@ -525,14 +506,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
        // Return if global dragging is not enabled
        // Return if global dragging is not enabled
        if (!mLauncher.isDraggingEnabled()) return false;
        if (!mLauncher.isDraggingEnabled()) return false;


        UnbadgedShortcutInfo unbadgedInfo = (UnbadgedShortcutInfo) v.getTag();
        ShortcutInfo badged = new ShortcutInfo(unbadgedInfo);
        // Queue an update task on the worker thread. This ensures that the badged
        // shortcut eventually gets its icon updated.
        mLauncher.getModel().updateShortcutInfo(unbadgedInfo.mDetail, badged);

        // Long clicked on a shortcut.
        // Long clicked on a shortcut.

        mDeferContainerRemoval = true;
        mDeferContainerRemoval = true;
        DeepShortcutView sv = (DeepShortcutView) v.getParent();
        DeepShortcutView sv = (DeepShortcutView) v.getParent();
        sv.setWillDrawIcon(false);
        sv.setWillDrawIcon(false);
@@ -542,7 +516,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
        mIconShift.y = mIconLastTouchPos.y - mLauncher.getDeviceProfile().iconSizePx;
        mIconShift.y = mIconLastTouchPos.y - mLauncher.getDeviceProfile().iconSizePx;


        DragView dv = mLauncher.getWorkspace().beginDragShared(
        DragView dv = mLauncher.getWorkspace().beginDragShared(
                sv.getBubbleText(), this, false, badged,
                sv.getBubbleText(), this, false, sv.getFinalInfo(),
                new ShortcutDragPreviewProvider(sv.getIconView(), mIconShift));
                new ShortcutDragPreviewProvider(sv.getIconView(), mIconShift));
        dv.animateShift(-mIconShift.x, -mIconShift.y);
        dv.animateShift(-mIconShift.x, -mIconShift.y);


@@ -754,8 +728,8 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
    /**
    /**
     * Extension of {@link ShortcutInfo} which does not badge the icons.
     * Extension of {@link ShortcutInfo} which does not badge the icons.
     */
     */
    private static class UnbadgedShortcutInfo extends ShortcutInfo {
    static class UnbadgedShortcutInfo extends ShortcutInfo {
        private final ShortcutInfoCompat mDetail;
        public final ShortcutInfoCompat mDetail;


        public UnbadgedShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
        public UnbadgedShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
            super(shortcutInfo, context);
            super(shortcutInfo, context);