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

Commit 7dd0196e authored by Bryce Lee's avatar Bryce Lee Committed by Android (Google) Code Review
Browse files

Merge changes from topic "267565290" into tm-qpr-dev

* changes:
  Allow swiping down notification shade over dream.
  Allow in-progress touch sessions to continue outside resume.
  Correct display dimensions considered.
  Suppress transient bars over dreams.
parents c7095663 76d6afe9
Loading
Loading
Loading
Loading
+11 −15
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.graphics.Rect;
import android.graphics.Region;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.InputEvent;
@@ -89,8 +88,6 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
    private final FlingAnimationUtils mFlingAnimationUtils;
    private final FlingAnimationUtils mFlingAnimationUtilsClosing;

    private final DisplayMetrics mDisplayMetrics;

    private Boolean mCapture;
    private Boolean mExpanded;

@@ -161,7 +158,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
                    // (0).
                    final float dragDownAmount = e2.getY() - e1.getY();
                    final float screenTravelPercentage = Math.abs(e1.getY() - e2.getY())
                            / mCentralSurfaces.get().getDisplayHeight();
                            / mTouchSession.getBounds().height();
                    setPanelExpansion(mBouncerInitiallyShowing
                            ? screenTravelPercentage : 1 - screenTravelPercentage, dragDownAmount);
                    return true;
@@ -202,7 +199,6 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {

    @Inject
    public BouncerSwipeTouchHandler(
            DisplayMetrics displayMetrics,
            ScrimManager scrimManager,
            Optional<CentralSurfaces> centralSurfaces,
            NotificationShadeWindowController notificationShadeWindowController,
@@ -214,7 +210,6 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
                    FlingAnimationUtils flingAnimationUtilsClosing,
            @Named(SWIPE_TO_BOUNCER_START_REGION) float swipeRegionPercentage,
            UiEventLogger uiEventLogger) {
        mDisplayMetrics = displayMetrics;
        mCentralSurfaces = centralSurfaces;
        mScrimManager = scrimManager;
        mNotificationShadeWindowController = notificationShadeWindowController;
@@ -227,19 +222,20 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
    }

    @Override
    public void getTouchInitiationRegion(Region region) {
    public void getTouchInitiationRegion(Rect bounds, Region region) {
        final int width = bounds.width();
        final int height = bounds.height();

        if (mCentralSurfaces.map(CentralSurfaces::isBouncerShowing).orElse(false)) {
            region.op(new Rect(0, 0, mDisplayMetrics.widthPixels,
            region.op(new Rect(0, 0, width,
                            Math.round(
                                    mDisplayMetrics.heightPixels * mBouncerZoneScreenPercentage)),
                                    height * mBouncerZoneScreenPercentage)),
                    Region.Op.UNION);
        } else {
            region.op(new Rect(0,
                            Math.round(
                                    mDisplayMetrics.heightPixels
                                            * (1 - mBouncerZoneScreenPercentage)),
                            mDisplayMetrics.widthPixels,
                            mDisplayMetrics.heightPixels),
                            Math.round(height * (1 - mBouncerZoneScreenPercentage)),
                            width,
                            height),
                    Region.Op.UNION);
        }
    }
@@ -356,7 +352,7 @@ public class BouncerSwipeTouchHandler implements DreamTouchHandler {
        }

        // The animation utils deal in pixel units, rather than expansion height.
        final float viewHeight = mCentralSurfaces.get().getDisplayHeight();
        final float viewHeight = mTouchSession.getBounds().height();
        final float currentHeight = viewHeight * mCurrentExpansion;
        final float targetHeight = viewHeight * expansion;
        final float expansionHeight = targetHeight - currentHeight;
+44 −8
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.systemui.dreams.touch;

import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;

import android.graphics.Rect;
import android.graphics.Region;
import android.view.GestureDetector;
import android.view.InputEvent;
@@ -31,6 +34,7 @@ import androidx.lifecycle.LifecycleOwner;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dreams.touch.dagger.InputSessionComponent;
import com.android.systemui.shared.system.InputChannelCompat;
import com.android.systemui.util.display.DisplayHelper;

import com.google.common.util.concurrent.ListenableFuture;

@@ -69,7 +73,8 @@ public class DreamOverlayTouchMonitor {
                }

                final TouchSessionImpl touchSession =
                        new TouchSessionImpl(this, touchSessionImpl);
                        new TouchSessionImpl(this, touchSessionImpl.getBounds(),
                                touchSessionImpl);
                mActiveTouchSessions.add(touchSession);
                completer.set(touchSession);
            });
@@ -96,6 +101,10 @@ public class DreamOverlayTouchMonitor {

                    completer.set(predecessor);
                }

                if (mActiveTouchSessions.isEmpty() && mStopMonitoringPending) {
                    stopMonitoring(false);
                }
            });

            return "DreamOverlayTouchMonitor::pop";
@@ -120,10 +129,13 @@ public class DreamOverlayTouchMonitor {

        private final TouchSessionImpl mPredecessor;
        private final DreamOverlayTouchMonitor mTouchMonitor;
        private final Rect mBounds;

        TouchSessionImpl(DreamOverlayTouchMonitor touchMonitor, TouchSessionImpl predecessor) {
        TouchSessionImpl(DreamOverlayTouchMonitor touchMonitor, Rect bounds,
                TouchSessionImpl predecessor) {
            mPredecessor = predecessor;
            mTouchMonitor = touchMonitor;
            mBounds = bounds;
        }

        @Override
@@ -185,6 +197,11 @@ public class DreamOverlayTouchMonitor {
        private void onRemoved() {
            mCallbacks.forEach(callback -> callback.onRemoved());
        }

        @Override
        public Rect getBounds() {
            return mBounds;
        }
    }

    /**
@@ -201,7 +218,12 @@ public class DreamOverlayTouchMonitor {

        @Override
        public void onPause(@NonNull LifecycleOwner owner) {
            stopMonitoring();
            stopMonitoring(false);
        }

        @Override
        public void onDestroy(LifecycleOwner owner) {
            stopMonitoring(true);
        }
    };

@@ -209,7 +231,7 @@ public class DreamOverlayTouchMonitor {
     * When invoked, instantiates a new {@link InputSession} to monitor touch events.
     */
    private void startMonitoring() {
        stopMonitoring();
        stopMonitoring(true);
        mCurrentInputSession = mInputSessionFactory.create(
                "dreamOverlay",
                mInputEventListener,
@@ -221,11 +243,16 @@ public class DreamOverlayTouchMonitor {
    /**
     * Destroys any active {@link InputSession}.
     */
    private void stopMonitoring() {
    private void stopMonitoring(boolean force) {
        if (mCurrentInputSession == null) {
            return;
        }

        if (!mActiveTouchSessions.isEmpty() && !force) {
            mStopMonitoringPending = true;
            return;
        }

        // When we stop monitoring touches, we must ensure that all active touch sessions and
        // descendants informed of the removal so any cleanup for active tracking can proceed.
        mExecutor.execute(() -> mActiveTouchSessions.forEach(touchSession -> {
@@ -237,11 +264,15 @@ public class DreamOverlayTouchMonitor {

        mCurrentInputSession.dispose();
        mCurrentInputSession = null;
        mStopMonitoringPending = false;
    }


    private final HashSet<TouchSessionImpl> mActiveTouchSessions = new HashSet<>();
    private final Collection<DreamTouchHandler> mHandlers;
    private final DisplayHelper mDisplayHelper;

    private boolean mStopMonitoringPending;

    private InputChannelCompat.InputEventListener mInputEventListener =
            new InputChannelCompat.InputEventListener() {
@@ -253,8 +284,11 @@ public class DreamOverlayTouchMonitor {
                        new HashMap<>();

                for (DreamTouchHandler handler : mHandlers) {
                    final Rect maxBounds = mDisplayHelper.getMaxBounds(ev.getDisplayId(),
                            TYPE_APPLICATION_OVERLAY);

                    final Region initiationRegion = Region.obtain();
                    handler.getTouchInitiationRegion(initiationRegion);
                    handler.getTouchInitiationRegion(maxBounds, initiationRegion);

                    if (!initiationRegion.isEmpty()) {
                        // Initiation regions require a motion event to determine pointer location
@@ -272,8 +306,8 @@ public class DreamOverlayTouchMonitor {
                        }
                    }

                    final TouchSessionImpl sessionStack =
                            new TouchSessionImpl(DreamOverlayTouchMonitor.this, null);
                    final TouchSessionImpl sessionStack = new TouchSessionImpl(
                            DreamOverlayTouchMonitor.this, maxBounds, null);
                    mActiveTouchSessions.add(sessionStack);
                    sessionMap.put(handler, sessionStack);
                }
@@ -389,11 +423,13 @@ public class DreamOverlayTouchMonitor {
            @Main Executor executor,
            Lifecycle lifecycle,
            InputSessionComponent.Factory inputSessionFactory,
            DisplayHelper displayHelper,
            Set<DreamTouchHandler> handlers) {
        mHandlers = handlers;
        mInputSessionFactory = inputSessionFactory;
        mExecutor = executor;
        mLifecycle = lifecycle;
        mDisplayHelper = displayHelper;
    }

    /**
+7 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.dreams.touch;

import android.graphics.Rect;
import android.graphics.Region;
import android.view.GestureDetector;

@@ -77,6 +78,11 @@ public interface DreamTouchHandler {
         * Returns the number of currently active sessions.
         */
        int getActiveSessionCount();

        /**
         * Returns the bounds of the display the touch region.
         */
        Rect getBounds();
    }

    /**
@@ -84,7 +90,7 @@ public interface DreamTouchHandler {
     * indicating the entire screen should be considered.
     * @param region A {@link Region} that is passed in to the target entry touch region.
     */
    default void getTouchInitiationRegion(Region region) {
    default void getTouchInitiationRegion(Rect bounds, Region region) {
    }

    /**
+92 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.dreams.touch;

import static com.android.systemui.dreams.touch.dagger.ShadeModule.NOTIFICATION_SHADE_GESTURE_INITIATION_HEIGHT;

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

import com.android.systemui.shade.NotificationPanelViewController;
import com.android.systemui.statusbar.phone.CentralSurfaces;

import java.util.Optional;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * {@link ShadeTouchHandler} is responsible for handling swipe down gestures over dream
 * to bring down the shade.
 */
public class ShadeTouchHandler implements DreamTouchHandler {
    private final Optional<CentralSurfaces> mSurfaces;
    private final int mInitiationHeight;

    @Inject
    ShadeTouchHandler(Optional<CentralSurfaces> centralSurfaces,
            @Named(NOTIFICATION_SHADE_GESTURE_INITIATION_HEIGHT) int initiationHeight) {
        mSurfaces = centralSurfaces;
        mInitiationHeight = initiationHeight;
    }

    @Override
    public void onSessionStart(TouchSession session) {
        if (mSurfaces.map(CentralSurfaces::isBouncerShowing).orElse(false)) {
            session.pop();
            return;
        }

        session.registerInputListener(ev -> {
            final NotificationPanelViewController viewController =
                    mSurfaces.map(CentralSurfaces::getNotificationPanelViewController).orElse(null);

            if (viewController != null) {
                viewController.handleExternalTouch((MotionEvent) ev);
            }

            if (ev instanceof MotionEvent) {
                if (((MotionEvent) ev).getAction() == MotionEvent.ACTION_UP) {
                    session.pop();
                }
            }
        });

        session.registerGestureListener(new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
                    float distanceY) {
                return true;
            }

            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                    float velocityY) {
                return true;
            }
        });
    }

    @Override
    public void getTouchInitiationRegion(Rect bounds, Region region) {
        final Rect outBounds = new Rect(bounds);
        outBounds.inset(0, 0, 0, outBounds.height() - mInitiationHeight);
        region.op(outBounds, Region.Op.UNION);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import dagger.Module;
@Module(includes = {
            BouncerSwipeModule.class,
            HideComplicationModule.class,
            ShadeModule.class,
        }, subcomponents = {
            InputSessionComponent.class,
})
Loading