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

Commit b4f55ed7 authored by Matt Casey's avatar Matt Casey
Browse files

Ignore all input outside of clipboard UI

Touches outside the UI should pass through but also dismiss the UI. This
can be done with insets in the draggable constraint layout (similar to
how ScreenshotView works).

Bug: 221509682
Test: manual test of bug repro.
Change-Id: I9fab0bff52e647cbeb8cb53a18a6603bb5c4195f
parent edc7b17c
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@ package com.android.systemui.clipboardoverlay;
import android.animation.Animator;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.Region;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;

import androidx.constraintlayout.widget.ConstraintLayout;

@@ -34,7 +36,8 @@ import java.util.function.Consumer;
/**
 * ConstraintLayout that is draggable when touched in a specific region
 */
public class DraggableConstraintLayout extends ConstraintLayout {
public class DraggableConstraintLayout extends ConstraintLayout
        implements ViewTreeObserver.OnComputeInternalInsetsListener {
    private final SwipeDismissHandler mSwipeDismissHandler;
    private final GestureDetector mSwipeDetector;
    private Consumer<Animator> mOnDismissInitiated;
@@ -95,11 +98,6 @@ public class DraggableConstraintLayout extends ConstraintLayout {
        mSwipeDetector.setIsLongpressEnabled(false);
    }

    @Override // View
    protected void onFinishInflate() {

    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
@@ -137,4 +135,29 @@ public class DraggableConstraintLayout extends ConstraintLayout {
    public void setOnInteractionCallback(Runnable callback) {
        mOnInteraction = callback;
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        getViewTreeObserver().addOnComputeInternalInsetsListener(this);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        getViewTreeObserver().removeOnComputeInternalInsetsListener(this);
    }

    @Override
    public void onComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo inoutInfo) {
        // Only child views are touchable.
        Region r = new Region();
        Rect rect = new Rect();
        for (int i = 0; i < getChildCount(); i++) {
            getChildAt(i).getGlobalVisibleRect(rect);
            r.op(rect, Region.Op.UNION);
        }
        inoutInfo.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION);
        inoutInfo.touchableRegion.set(r);
    }
}