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

Commit 6e7b28d5 authored by Omar Abdelmonem's avatar Omar Abdelmonem
Browse files

Made TouchpadDebugView edges rounded

Bug: 366474774
Test: Presubmit
Flag: com.android.hardware.input.touchpad_visualizer
Change-Id: I1546713363e31599091791d7066afd7837483c84
parent 3d1dc8b0
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;