From 491ed067dd1741e64341ec0f3bd94df7cd8c0693 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Mon, 4 May 2020 16:36:39 -0400 Subject: [PATCH] Make Canvas#drawPatch public Bug: 155422223 Bug: 155661807 Test: NinePatchTest#testDraw Test: NinePatchDrawableTest#testDraw As part of the move to a mainline module, code outside the module cannot access @hidden APIs on Canvas. Although no code outside the module calls these methods, there is a Canvas subclass that overrides it - NopCanvas, which overrides it to do nothing. This is useful, and cannot be achieved another way. (If NopCanvas did not override drawPatch, it would crash when attempting to draw a NinePatchDrawable.) In addition, this method is already public on RecordingCanvas. (This is likely an accident; it contains no documentation for the method.) Lastly, it is somewhat arbitrary that the way to draw a NinePatch directly was to call NinePatch#draw. This is the reverse of how Canvas drawing generally works. The newly public method matches the typical pattern (Canvas#draw(Something, Paint)) and is already called by NinePatch#draw. Change-Id: I16d7dc7391e3ad5777fdd7023472545c6104af69 --- api/current.txt | 4 ++-- graphics/java/android/graphics/Canvas.java | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/api/current.txt b/api/current.txt index 0b717cd1fab03..6e8c657000537 100644 --- a/api/current.txt +++ b/api/current.txt @@ -14300,6 +14300,8 @@ package android.graphics { method public void drawOval(@NonNull android.graphics.RectF, @NonNull android.graphics.Paint); method public void drawOval(float, float, float, float, @NonNull android.graphics.Paint); method public void drawPaint(@NonNull android.graphics.Paint); + method public void drawPatch(@NonNull android.graphics.NinePatch, @NonNull android.graphics.Rect, @Nullable android.graphics.Paint); + method public void drawPatch(@NonNull android.graphics.NinePatch, @NonNull android.graphics.RectF, @Nullable android.graphics.Paint); method public void drawPath(@NonNull android.graphics.Path, @NonNull android.graphics.Paint); method public void drawPicture(@NonNull android.graphics.Picture); method public void drawPicture(@NonNull android.graphics.Picture, @NonNull android.graphics.RectF); @@ -15354,8 +15356,6 @@ package android.graphics { } public final class RecordingCanvas extends android.graphics.Canvas { - method public final void drawPatch(@NonNull android.graphics.NinePatch, @NonNull android.graphics.Rect, @Nullable android.graphics.Paint); - method public final void drawPatch(@NonNull android.graphics.NinePatch, @NonNull android.graphics.RectF, @Nullable android.graphics.Paint); } public final class Rect implements android.os.Parcelable { diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 37ba869a94e3f..be8a262899d3a 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -1873,24 +1873,22 @@ public class Canvas extends BaseCanvas { } /** - * Draws the specified bitmap as an N-patch (most often, a 9-patches.) + * Draws the specified bitmap as an N-patch (most often, a 9-patch.) * * @param patch The ninepatch object to render * @param dst The destination rectangle. * @param paint The paint to draw the bitmap with. may be null - * @hide */ public void drawPatch(@NonNull NinePatch patch, @NonNull Rect dst, @Nullable Paint paint) { super.drawPatch(patch, dst, paint); } /** - * Draws the specified bitmap as an N-patch (most often, a 9-patches.) + * Draws the specified bitmap as an N-patch (most often, a 9-patch.) * * @param patch The ninepatch object to render * @param dst The destination rectangle. * @param paint The paint to draw the bitmap with. may be null - * @hide */ public void drawPatch(@NonNull NinePatch patch, @NonNull RectF dst, @Nullable Paint paint) { super.drawPatch(patch, dst, paint);