From bdb3cb325d26c4c490b38b1af36ec90836d40b0a Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Thu, 30 May 2019 18:41:59 -0400 Subject: [PATCH] Make CornerHandleView use device radius. Both the radius and margin will vary from device to device. Created a derivation of margin from the radius values based upon numbers on real devices. Bug: 133861138 Test: Verified padding and radius on multiple devices. Change-Id: I3a284d75da8beb7ab77e5cb8e1fa8af57c5e3978 --- .../android/systemui/CornerHandleView.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/CornerHandleView.java b/packages/SystemUI/src/com/android/systemui/CornerHandleView.java index 528db5acc86e8..691c3f98825d8 100644 --- a/packages/SystemUI/src/com/android/systemui/CornerHandleView.java +++ b/packages/SystemUI/src/com/android/systemui/CornerHandleView.java @@ -36,9 +36,9 @@ import com.android.settingslib.Utils; public class CornerHandleView extends View { private static final boolean ALLOW_TUNING = false; private static final int ANGLE_DEGREES = 50; - public static final int MARGIN_DP = 11; - public static final int RADIUS_DP = 37; - public static final float STROKE_DP = 2.5f; + private static final float STROKE_DP = 2.5f; + // Radius to use if none is available. + private static final int FALLBACK_RADIUS_DP = 15; private Paint mPaint; private int mLightColor; @@ -71,7 +71,7 @@ public class CornerHandleView extends View { /** * Receives an intensity from 0 (lightest) to 1 (darkest) and sets the handle color - * approriately. Intention is to match the home handle color. + * appropriately. Intention is to match the home handle color. */ public void updateDarkness(float darkIntensity) { mPaint.setColor((int) ArgbEvaluator.getInstance().evaluate(darkIntensity, @@ -115,20 +115,37 @@ public class CornerHandleView extends View { } private int getMarginPx() { + // Hand-derived function to map radiusPx to the margin amount. + // https://www.wolframalpha.com/input/?i=0.001402+*+x+%5E2%E2%88%920.08661+*+x%2B17.20+from+40+to+180 + int radius = getRadiusPx(); + int marginPx = (int) (0.001402f * radius * radius - 0.08661f * radius + 17.2f); if (ALLOW_TUNING) { - return SystemProperties.getInt("CORNER_HANDLE_MARGIN_PX", - (int) convertDpToPixel(MARGIN_DP, getContext())); + return SystemProperties.getInt("CORNER_HANDLE_MARGIN_PX", marginPx); } else { - return (int) convertDpToPixel(MARGIN_DP, getContext()); + return marginPx; } } private int getRadiusPx() { + // Attempt to get the bottom corner radius, otherwise fall back on the generic or top + // values. If none are available, use the FALLBACK_RADIUS_DP. + int radius = getResources().getDimensionPixelSize( + com.android.internal.R.dimen.rounded_corner_radius_bottom); + if (radius == 0) { + radius = getResources().getDimensionPixelSize( + com.android.internal.R.dimen.rounded_corner_radius); + } + if (radius == 0) { + radius = getResources().getDimensionPixelSize( + com.android.internal.R.dimen.rounded_corner_radius_top); + } + if (radius == 0) { + radius = (int) convertDpToPixel(FALLBACK_RADIUS_DP, mContext); + } if (ALLOW_TUNING) { - return SystemProperties.getInt("CORNER_HANDLE_RADIUS_PX", - (int) convertDpToPixel(RADIUS_DP, getContext())); + return SystemProperties.getInt("CORNER_HANDLE_RADIUS_PX", radius); } else { - return (int) convertDpToPixel(RADIUS_DP, getContext()); + return radius; } }