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

Commit 0076e67d authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Showing the caret/drag handle in transposed layout

> Adding a simple touch-down effect, without capturing the motion event

Bug: 79526736
Change-Id: I50dcc76836765d158dfdcef2886b190a85707ff2
parent 7c86a1ad
Loading
Loading
Loading
Loading
+76 −8
Original line number Original line Diff line number Diff line
@@ -18,14 +18,24 @@ package com.android.launcher3.views;
import static android.content.Context.ACCESSIBILITY_SERVICE;
import static android.content.Context.ACCESSIBILITY_SERVICE;
import static android.support.v4.graphics.ColorUtils.compositeColors;
import static android.support.v4.graphics.ColorUtils.compositeColors;
import static android.support.v4.graphics.ColorUtils.setAlphaComponent;
import static android.support.v4.graphics.ColorUtils.setAlphaComponent;
import static android.view.MotionEvent.ACTION_DOWN;


import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.NORMAL;

import static com.android.launcher3.anim.Interpolators.ACCEL;
import static com.android.launcher3.anim.Interpolators.DEACCEL;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.RectEvaluator;
import android.content.Context;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.Nullable;
@@ -85,6 +95,8 @@ public class ScrimView extends View implements Insettable, OnChangeListener,


    protected final int mDragHandleSize;
    protected final int mDragHandleSize;
    private final Rect mDragHandleBounds;
    private final Rect mDragHandleBounds;
    private final RectF mHitRect = new RectF();

    private final AccessibilityHelper mAccessibilityHelper;
    private final AccessibilityHelper mAccessibilityHelper;
    @Nullable
    @Nullable
    protected Drawable mDragHandle;
    protected Drawable mDragHandle;
@@ -110,6 +122,7 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
    @Override
    @Override
    public void setInsets(Rect insets) {
    public void setInsets(Rect insets) {
        updateDragHandleBounds();
        updateDragHandleBounds();
        updateDragHandleVisibility(null);
    }
    }


    @Override
    @Override
@@ -179,6 +192,46 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
        }
        }
    }
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        boolean value = super.onTouchEvent(event);
        if (!value && mDragHandle != null && event.getAction() == ACTION_DOWN
                && mDragHandle.getAlpha() == 255
                && mHitRect.contains(event.getX(), event.getY())) {

            final Drawable drawable = mDragHandle;
            mDragHandle = null;
            drawable.setBounds(mDragHandleBounds);

            Rect topBounds = new Rect(mDragHandleBounds);
            topBounds.offset(0, -mDragHandleBounds.height() / 2);

            Rect invalidateRegion = new Rect(mDragHandleBounds);
            invalidateRegion.top = topBounds.top;

            Keyframe frameTop = Keyframe.ofObject(0.6f, topBounds);
            frameTop.setInterpolator(DEACCEL);
            Keyframe frameBot = Keyframe.ofObject(1, mDragHandleBounds);
            frameBot.setInterpolator(ACCEL);
            PropertyValuesHolder holder = PropertyValuesHolder .ofKeyframe("bounds",
                    Keyframe.ofObject(0, mDragHandleBounds), frameTop, frameBot);
            holder.setEvaluator(new RectEvaluator());

            ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, holder);
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    getOverlay().remove(drawable);
                    updateDragHandleVisibility(drawable);
                }
            });
            anim.addUpdateListener((v) -> invalidate(invalidateRegion));
            getOverlay().add(drawable);
            anim.start();
        }
        return value;
    }

    protected void updateDragHandleBounds() {
    protected void updateDragHandleBounds() {
        DeviceProfile grid = mLauncher.getDeviceProfile();
        DeviceProfile grid = mLauncher.getDeviceProfile();
        final int left;
        final int left;
@@ -198,6 +251,9 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
            topMargin = grid.hotseatBarSizePx;
            topMargin = grid.hotseatBarSizePx;
        }
        }
        mDragHandleBounds.offsetTo(left, top - topMargin);
        mDragHandleBounds.offsetTo(left, top - topMargin);
        mHitRect.set(mDragHandleBounds);
        float inset = -mDragHandleSize / 2;
        mHitRect.inset(inset, inset);


        if (mDragHandle != null) {
        if (mDragHandle != null) {
            mDragHandle.setBounds(mDragHandleBounds);
            mDragHandle.setBounds(mDragHandleBounds);
@@ -210,11 +266,22 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
        stateManager.removeStateListener(this);
        stateManager.removeStateListener(this);


        if (enabled) {
        if (enabled) {
            mDragHandle = mLauncher.getDrawable(R.drawable.drag_handle_indicator);
            mDragHandle.setBounds(mDragHandleBounds);

            stateManager.addStateListener(this);
            stateManager.addStateListener(this);
            onStateSetImmediately(mLauncher.getStateManager().getState());
            onStateSetImmediately(mLauncher.getStateManager().getState());
        } else {
            setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
        }
        updateDragHandleVisibility(null);
    }

    private void updateDragHandleVisibility(Drawable recycle) {
        boolean visible = mLauncher.getDeviceProfile().isVerticalBarLayout() || mAM.isEnabled();
        boolean wasVisible = mDragHandle != null;
        if (visible != wasVisible) {
            if (visible) {
                mDragHandle = recycle != null ? recycle :
                        mLauncher.getDrawable(R.drawable.drag_handle_indicator);
                mDragHandle.setBounds(mDragHandleBounds);


                updateDragHandleAlpha();
                updateDragHandleAlpha();
            } else {
            } else {
@@ -222,6 +289,7 @@ public class ScrimView extends View implements Insettable, OnChangeListener,
            }
            }
            invalidate();
            invalidate();
        }
        }
    }


    @Override
    @Override
    public boolean dispatchHoverEvent(MotionEvent event) {
    public boolean dispatchHoverEvent(MotionEvent event) {