From e94bf556190335a9347fff6109074a738ecc5fcb Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 14 Feb 2023 09:31:29 +0900 Subject: [PATCH] Revisit API comment again with code example Bug: 266591082 Test: N/A Change-Id: I90635b488d807526e782e6d7d82436ccbde14e91 --- core/java/android/text/Highlights.java | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/core/java/android/text/Highlights.java b/core/java/android/text/Highlights.java index ac4a5f2881ccf..693dbcf84e84e 100644 --- a/core/java/android/text/Highlights.java +++ b/core/java/android/text/Highlights.java @@ -90,8 +90,19 @@ public class Highlights { /** * Add single range highlight. * - * If the given range has overlaps with the already added ranges, the previous highlights - * are overdrawn by this range. + * The {@link android.widget.TextView} and underlying {@link Layout} draws highlight in the + * order of the {@link #addRange} calls. + * + * For example, the following code draws (1, 2) with red and (2, 5) with blue. + * + * val redPaint = Paint().apply { color = Color.RED } + * val bluePaint = Paint().apply { color = Color.BLUE } + * val highlight = Highlights.Builder() + * .addRange(redPaint, 1, 4) + * .addRange(bluePaint, 2, 5) + * .build() + * + * * * @param paint a paint object used for drawing highlight path. * @param start an inclusive offset of the text. @@ -114,8 +125,15 @@ public class Highlights { /** * Add multiple ranges highlight. * - * If the given ranges have overlap with the already added ranges, the previous highlights - * are overdrawn by this range. + * For example, the following code draws (1, 2) with red and (2, 5) with blue. + * + * val redPaint = Paint().apply { color = Color.RED } + * val bluePaint = Paint().apply { color = Color.BLUE } + * val highlight = Highlights.Builder() + * .addRange(redPaint, 1, 4) + * .addRange(bluePaint, 2, 5) + * .build() + * * * @param paint a paint object used for drawing highlight path. * @param ranges a flatten ranges. The {@code 2 * i}-th element is an inclusive start offset