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

Commit 9bb0d726 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding feature to support two different swipe targets from all-apps and overview

Change-Id: I7e7b4abbcebcbd6de43805c57ee40b0edd5ba5aa
parent cc96aa1f
Loading
Loading
Loading
Loading
+95 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */
package com.android.launcher3.uioverrides;

import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.touch.SwipeDetector.DIRECTION_NEGATIVE;
import static com.android.launcher3.touch.SwipeDetector.DIRECTION_POSITIVE;
import static com.android.launcher3.touch.SwipeDetector.HORIZONTAL;
import static com.android.launcher3.touch.SwipeDetector.VERTICAL;
import static com.android.quickstep.TouchInteractionService.EDGE_NAV_BAR;

import android.graphics.Rect;
import android.view.MotionEvent;

import com.android.launcher3.Launcher;
import com.android.launcher3.anim.SpringAnimationHandler;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.util.VerticalSwipeController;
import com.android.quickstep.RecentsView;

/**
 * Extension of {@link VerticalSwipeController} to go from NORMAL to OVERVIEW.
 */
public class EdgeSwipeController extends VerticalSwipeController {

    private final Rect mTempRect = new Rect();

    public EdgeSwipeController(Launcher l) {
        super(l, NORMAL, OVERVIEW, l.getDeviceProfile().isVerticalBarLayout()
                ? HORIZONTAL : VERTICAL);
    }

    @Override
    protected boolean shouldInterceptTouch(MotionEvent ev) {
        return mLauncher.isInState(NORMAL) && (ev.getEdgeFlags() & EDGE_NAV_BAR) != 0;
    }

    @Override
    protected int getSwipeDirection(MotionEvent ev) {
        return isTransitionFlipped() ? DIRECTION_NEGATIVE : DIRECTION_POSITIVE;
    }

    @Override
    protected boolean isTransitionFlipped() {
        if (mLauncher.getDeviceProfile().isVerticalBarLayout()) {
            Rect insets = mLauncher.getDragLayer().getInsets();
            return insets.left > insets.right;
        }
        return false;
    }

    @Override
    protected void onTransitionComplete(boolean wasFling, boolean stateChanged) {
        // TODO: Log something
    }

    @Override
    protected void initSprings() {
        mSpringHandlers = new SpringAnimationHandler[0];
    }

    @Override
    protected float getShiftRange() {
        RecentsView.getPageRect(mLauncher, mTempRect);
        DragLayer dl = mLauncher.getDragLayer();
        Rect insets = dl.getInsets();

        if (mLauncher.getDeviceProfile().isVerticalBarLayout()) {
            if (insets.left > insets.right) {
                return insets.left + mTempRect.left;
            } else {
                return dl.getWidth() - mTempRect.right + insets.right;
            }
        } else {
            return dl.getHeight() - mTempRect.bottom + insets.bottom;
        }
    }
}
+22 −8
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
import static com.android.launcher3.anim.SpringAnimationHandler.Y_DIRECTION;
import static com.android.quickstep.TouchInteractionService.EDGE_NAV_BAR;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -42,6 +43,7 @@ import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.anim.SpringAnimationHandler;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.touch.SwipeDetector;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
@@ -90,6 +92,7 @@ public class TwoStepSwipeController extends AnimatorListenerAdapter
    private static final int FLAG_OVERVIEW_DISABLED_CANCEL_STATE = 1 << 2;
    private static final int FLAG_RECENTS_PLAN_LOADING = 1 << 3;
    private static final int FLAG_OVERVIEW_DISABLED = 1 << 4;
    private static final int FLAG_DISABLED_TWO_TARGETS = 1 << 5;

    private final Launcher mLauncher;
    private final SwipeDetector mDetector;
@@ -120,18 +123,25 @@ public class TwoStepSwipeController extends AnimatorListenerAdapter
    }

    private boolean canInterceptTouch(MotionEvent ev) {
        if (!mLauncher.isInState(NORMAL) && !mLauncher.isInState(ALL_APPS)) {
            // Don't listen for the swipe gesture if we are already in some other state.
        if (mCurrentAnimation != null) {
            // If we are already animating from a previous state, we can intercept.
            return true;
        }
        if (mLauncher.isInState(NORMAL)) {
            if ((ev.getEdgeFlags() & EDGE_NAV_BAR) != 0 &&
                    !mLauncher.getDeviceProfile().isVerticalBarLayout()) {
                // On normal swipes ignore edge swipes
                return false;
            }
        if (mAnimatingToOverview) {
        } else if (mLauncher.isInState(ALL_APPS)) {
            if (!mLauncher.getAppsView().shouldContainerScroll(ev)) {
                return false;
            }
        if (mCurrentAnimation != null) {
            // If we are already animating from a previous state, we can intercept.
            return true;
        } else {
            // Don't listen for the swipe gesture if we are already in some other state.
            return false;
        }
        if (mLauncher.isInState(ALL_APPS) && !mLauncher.getAppsView().shouldContainerScroll(ev)) {
        if (mAnimatingToOverview) {
            return false;
        }
        if (AbstractFloatingView.getTopOpenView(mLauncher) != null) {
@@ -237,6 +247,10 @@ public class TwoStepSwipeController extends AnimatorListenerAdapter

            mDragPauseDetector = new DragPauseDetector(this::onDragPauseDetected);
            mDragPauseDetector.addDisabledFlags(FLAG_OVERVIEW_DISABLED_OUT_OF_RANGE);
            if (FeatureFlags.ENABLE_TWO_SWIPE_TARGETS) {
                mDragPauseDetector.addDisabledFlags(FLAG_DISABLED_TWO_TARGETS);
            }

            mOverviewProgressRange = new FloatRange();
            mOverviewProgressRange.start = mLauncher.isInState(NORMAL)
                    ? MIN_PROGRESS_TO_OVERVIEW
+10 −3
Original line number Diff line number Diff line
@@ -37,9 +37,16 @@ public class UiFactory {
    public static final boolean USE_HARDWARE_BITMAP = false; // FeatureFlags.IS_DOGFOOD_BUILD;

    public static TouchController[] createTouchControllers(Launcher launcher) {
        if (FeatureFlags.ENABLE_TWO_SWIPE_TARGETS) {
            return new TouchController[]{
                    new EdgeSwipeController(launcher),
                    new TwoStepSwipeController(launcher),
                    new OverviewSwipeUpController(launcher)};
        } else {
            return new TouchController[]{
                    new TwoStepSwipeController(launcher),
                    new OverviewSwipeUpController(launcher)};
        }
    }

    public static AccessibilityDelegate newPageIndicatorAccessibilityDelegate() {
+5 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ import java.util.function.Consumer;
@TargetApi(Build.VERSION_CODES.O)
public class TouchInteractionService extends Service {

    public static final int EDGE_NAV_BAR = 1 << 8;

    private static final String TAG = "TouchInteractionService";

    private final IBinder mMyBinder = new IOverviewProxy.Stub() {
@@ -381,9 +383,12 @@ public class TouchInteractionService extends Service {
        }

        private void sendEvent(MotionEvent ev) {
            int flags = ev.getEdgeFlags();
            ev.setEdgeFlags(flags | EDGE_NAV_BAR);
            ev.offsetLocation(-mLocationOnScreen[0], -mLocationOnScreen[1]);
            mTarget.dispatchTouchEvent(ev);
            ev.offsetLocation(mLocationOnScreen[0], mLocationOnScreen[1]);
            ev.setEdgeFlags(flags);
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -57,4 +57,6 @@ abstract class BaseFlags {
    public static final boolean ALL_APPS_TABS_ENABLED = true;
    // When enabled prediction row is rendered as it's own custom view
    public static final boolean ALL_APPS_PREDICTION_ROW_VIEW = true;

    public static final boolean ENABLE_TWO_SWIPE_TARGETS = true;
}
Loading