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

Commit 0fda3ba9 authored by Andy Wickham's avatar Andy Wickham
Browse files

Removes WindowManager and DisplayManager from sandbox.

Adds the back gesture panel directly to the fragment
View hierarchy rather than a separate Window.

Bug: 148542211
Change-Id: I196a72d29217308a5bdb78fdcff1face5d475379
parent 8492edb1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -107,11 +107,11 @@ public class BackGestureTutorialFragment extends Fragment implements BackGesture
    }

    void onAttachedToWindow() {
        mEdgeBackGestureHandler.setIsEnabled(true);
        mEdgeBackGestureHandler.setViewGroupParent((ViewGroup) getRootView());
    }

    void onDetachedFromWindow() {
        mEdgeBackGestureHandler.setIsEnabled(false);
        mEdgeBackGestureHandler.setViewGroupParent(null);
    }

    @Override
+16 −56
Original line number Diff line number Diff line
@@ -17,21 +17,18 @@ package com.android.quickstep.interaction;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.PointF;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemProperties;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;

import androidx.annotation.Nullable;

import com.android.launcher3.ResourceUtils;

@@ -40,7 +37,7 @@ import com.android.launcher3.ResourceUtils;
 *
 * Forked from platform/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/EdgeBackGestureHandler.java.
 */
public class EdgeBackGestureHandler implements DisplayListener, OnTouchListener {
public class EdgeBackGestureHandler implements OnTouchListener {

    private static final String TAG = "EdgeBackGestureHandler";
    private static final int MAX_LONG_PRESS_TIMEOUT = SystemProperties.getInt(
@@ -106,29 +103,22 @@ public class EdgeBackGestureHandler implements DisplayListener, OnTouchListener
        mEdgeWidth = ResourceUtils.getNavbarSize("config_backGestureInset", res);
    }

    void setIsEnabled(boolean isEnabled) {
        if (isEnabled == mIsEnabled) {
            return;
        }
        mIsEnabled = isEnabled;
    void setViewGroupParent(@Nullable ViewGroup parent) {
        mIsEnabled = parent != null;

        if (mEdgeBackPanel != null) {
            mEdgeBackPanel.onDestroy();
            mEdgeBackPanel = null;
        }

        if (!mIsEnabled) {
            mContext.getSystemService(DisplayManager.class).unregisterDisplayListener(this);
        } else {
            updateDisplaySize();
            mContext.getSystemService(DisplayManager.class).registerDisplayListener(this,
                    new Handler(Looper.getMainLooper()));

        if (mIsEnabled) {
            // Add a nav bar panel window.
            mEdgeBackPanel = new EdgeBackGesturePanel(mContext);
            mEdgeBackPanel = new EdgeBackGesturePanel(mContext, parent, createLayoutParams());
            mEdgeBackPanel.setBackCallback(mBackCallback);
            mEdgeBackPanel.setLayoutParams(createLayoutParams());
            updateDisplaySize();
            if (mContext.getDisplay() != null) {
                mContext.getDisplay().getRealSize(mDisplaySize);
                mEdgeBackPanel.setDisplaySize(mDisplaySize);
            }
        }
    }

@@ -136,21 +126,11 @@ public class EdgeBackGestureHandler implements DisplayListener, OnTouchListener
        mGestureCallback = callback;
    }

    private WindowManager.LayoutParams createLayoutParams() {
    private LayoutParams createLayoutParams() {
        Resources resources = mContext.getResources();
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
        return new LayoutParams(
                ResourceUtils.getNavbarSize("navigation_edge_panel_width", resources),
                ResourceUtils.getNavbarSize("navigation_edge_panel_height", resources),
                LayoutParams.TYPE_APPLICATION_PANEL,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
                        | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
                PixelFormat.TRANSLUCENT);
        layoutParams.setTitle(TAG + mDisplayId);
        layoutParams.windowAnimations = 0;
        layoutParams.setFitInsetsTypes(0 /* types */);
        return layoutParams;
                ResourceUtils.getNavbarSize("navigation_edge_panel_height", resources));
    }

    @Override
@@ -232,26 +212,6 @@ public class EdgeBackGestureHandler implements DisplayListener, OnTouchListener
        }
    }

    @Override
    public void onDisplayAdded(int displayId) { }

    @Override
    public void onDisplayRemoved(int displayId) { }

    @Override
    public void onDisplayChanged(int displayId) {
        if (displayId == mDisplayId) {
            updateDisplaySize();
        }
    }

    private void updateDisplaySize() {
        mContext.getDisplay().getRealSize(mDisplaySize);
        if (mEdgeBackPanel != null) {
            mEdgeBackPanel.setDisplaySize(mDisplaySize);
        }
    }

    void setInsets(int leftInset, int rightInset) {
        mLeftInset = leftInset;
        mRightInset = rightInset;
+13 −21
Original line number Diff line number Diff line
@@ -26,11 +26,11 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.os.SystemClock;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.WindowManager;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;

@@ -110,7 +110,6 @@ public class EdgeBackGesturePanel extends View {
    private static final Interpolator RUBBER_BAND_INTERPOLATOR_APPEAR =
            new PathInterpolator(1.0f / RUBBER_BAND_AMOUNT_APPEAR, 1.0f, 1.0f, 1.0f);

    private final WindowManager mWindowManager;
    private BackCallback mBackCallback;

    /**
@@ -147,7 +146,6 @@ public class EdgeBackGesturePanel extends View {

    private VelocityTracker mVelocityTracker;
    private int mArrowPaddingEnd;
    private WindowManager.LayoutParams mLayoutParams;

    /**
     * True if the panel is currently on the left of the screen
@@ -232,11 +230,9 @@ public class EdgeBackGesturePanel extends View {
                }
            };

    public EdgeBackGesturePanel(Context context) {
    public EdgeBackGesturePanel(Context context, ViewGroup parent, LayoutParams layoutParams) {
        super(context);

        mWindowManager = context.getSystemService(WindowManager.class);

        mDensity = context.getResources().getDisplayMetrics().density;

        mBaseTranslation = dp(BASE_TRANSLATION_DP);
@@ -290,11 +286,15 @@ public class EdgeBackGesturePanel extends View {

        mSwipeThreshold = ResourceUtils.getDimenByName(
            "navigation_edge_action_drag_threshold", context.getResources(), 16 /* defaultValue */);
        parent.addView(this, layoutParams);
        setVisibility(GONE);
    }

    void onDestroy() {
        mWindowManager.removeView(this);
        ViewGroup parent = (ViewGroup) getParent();
        if (parent != null) {
            parent.removeView(this);
        }
    }

    @Override
@@ -305,9 +305,6 @@ public class EdgeBackGesturePanel extends View {
    @SuppressLint("RtlHardcoded")
    void setIsLeftPanel(boolean isLeftPanel) {
        mIsLeftPanel = isLeftPanel;
        mLayoutParams.gravity = mIsLeftPanel
                ? (Gravity.LEFT | Gravity.TOP)
                : (Gravity.RIGHT | Gravity.TOP);
    }

    boolean getIsLeftPanel() {
@@ -323,11 +320,6 @@ public class EdgeBackGesturePanel extends View {
        mBackCallback = callback;
    }

    void setLayoutParams(WindowManager.LayoutParams layoutParams) {
        mLayoutParams = layoutParams;
        mWindowManager.addView(this, mLayoutParams);
    }

    private float getCurrentAngle() {
        return mCurrentAngle;
    }
@@ -349,7 +341,6 @@ public class EdgeBackGesturePanel extends View {
                mStartY = event.getY();
                setVisibility(VISIBLE);
                updatePosition(event.getY());
                mWindowManager.updateViewLayout(this, mLayoutParams);
                break;
            case MotionEvent.ACTION_MOVE:
                handleMoveEvent(event);
@@ -614,10 +605,11 @@ public class EdgeBackGesturePanel extends View {
    }

    private void updatePosition(float touchY) {
        float position = touchY - mFingerOffset;
        position = Math.max(position, mMinArrowPosition);
        position -= mLayoutParams.height / 2.0f;
        mLayoutParams.y = MathUtils.clamp((int) position, 0, mDisplaySize.y);
        float positionY = touchY - mFingerOffset;
        positionY = Math.max(positionY, mMinArrowPosition);
        positionY -= getLayoutParams().height / 2.0f;
        setX(mIsLeftPanel ? 0 : mDisplaySize.x - getLayoutParams().width);
        setY(MathUtils.clamp((int) positionY, 0, mDisplaySize.y));
    }

    private void setDesiredVerticalTransition(float verticalTranslation, boolean animated) {