From 6e7b28d581c072c2fc93db90fe87d46e607abd3d Mon Sep 17 00:00:00 2001 From: Omar Abdelmonem Date: Sat, 14 Sep 2024 22:04:31 +0000 Subject: Made TouchpadDebugView edges rounded Bug: 366474774 Test: Presubmit Flag: com.android.hardware.input.touchpad_visualizer Change-Id: I1546713363e31599091791d7066afd7837483c84 --- .../server/input/debug/TouchpadDebugView.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/services/core/java/com/android/server/input/debug/TouchpadDebugView.java b/services/core/java/com/android/server/input/debug/TouchpadDebugView.java index 3f11e7836609..5ff8568f81b2 100644 --- a/services/core/java/com/android/server/input/debug/TouchpadDebugView.java +++ b/services/core/java/com/android/server/input/debug/TouchpadDebugView.java @@ -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; -- cgit v1.2.3-59-g8ed1b