From cabb5e1c162d61ed8158bd9f6a3b1d3587cb683b Mon Sep 17 00:00:00 2001 From: Justin Ghan Date: Fri, 2 Jun 2023 13:40:14 -0700 Subject: [PATCH] Set insert mode color to be 20% of the text color Previously the insert mode color was based on the theme's primary color, which could be invisible against the background for some themes. Bug: 278205678 Test: atest TextViewHandwritingGestureTest Change-Id: Ia7d212b73c0ca498bef26f8202857a9c63712b85 --- core/java/android/widget/Editor.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 2dbff581fe84b..d37c37a392a51 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -8112,16 +8112,10 @@ public class Editor { mHighlightPaint = new Paint(); mHighlightPath = new Path(); - // The highlight color is supposed to be 12% of the color primary40. We can't - // directly access Material 3 theme. But because Material 3 sets the colorPrimary to - // be primary40, here we hardcoded it to be 12% of colorPrimary. - final TypedValue typedValue = new TypedValue(); - mTextView.getContext().getTheme() - .resolveAttribute(R.attr.colorPrimary, typedValue, true); - final int colorPrimary = typedValue.data; - final int highlightColor = ColorUtils.setAlphaComponent(colorPrimary, - (int) (0.12f * Color.alpha(colorPrimary))); - mHighlightPaint.setColor(highlightColor); + // Insert mode highlight color is 20% opacity of the default text color. + int color = mTextView.getTextColors().getDefaultColor(); + color = ColorUtils.setAlphaComponent(color, (int) (0.2f * Color.alpha(color))); + mHighlightPaint.setColor(color); } /**