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

Commit 0b2828ce authored by Omar Abdelmonem's avatar Omar Abdelmonem Committed by Android (Google) Code Review
Browse files

Merge "Made TouchpadDebugView edges rounded" into main

parents 350d40e9 6e7b28d5
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -29,7 +29,9 @@ import android.util.Slog;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.ViewConfiguration;
import android.view.ViewRootImpl;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -49,6 +51,7 @@ public class TouchpadDebugView extends LinearLayout {
    private static final float DEFAULT_RES_X = 47f;
    private static final float DEFAULT_RES_Y = 45f;
    private static final int TEXT_PADDING_DP = 12;
    private static final int ROUNDED_CORNER_RADIUS_DP = 24;

    /**
     * Input device ID for the touchpad that this debug view is displaying.
@@ -151,6 +154,30 @@ public class TouchpadDebugView extends LinearLayout {
        updateViewsDimensions();
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        postDelayed(() -> {
            final ViewRootImpl viewRootImpl = getRootView().getViewRootImpl();
            if (viewRootImpl == null) {
                Slog.d("TouchpadDebugView", "ViewRootImpl is null.");
                return;
            }

            SurfaceControl surfaceControl = viewRootImpl.getSurfaceControl();
            if (surfaceControl != null && surfaceControl.isValid()) {
                try (SurfaceControl.Transaction transaction = new SurfaceControl.Transaction()) {
                    transaction.setCornerRadius(surfaceControl,
                            TypedValue.applyDimension(COMPLEX_UNIT_DIP,
                                    ROUNDED_CORNER_RADIUS_DP,
                                    getResources().getDisplayMetrics())).apply();
                }
            } else {
                Slog.d("TouchpadDebugView", "SurfaceControl is invalid or has been released.");
            }
        }, 100);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        float deltaX;