From dfd96be03aba78f4bdb3b64d1b5d3f55429a0c03 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 12 Jun 2013 00:39:32 +0900 Subject: [PATCH] Retun an empty Path instead of null Bug: 9374496 Change-Id: If74306104e9d25288e1b216a328304da376c1bdb --- .../inputmethod/keyboard/internal/GestureTrail.java | 2 +- .../android/inputmethod/keyboard/internal/RoundedLine.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GestureTrail.java index 0f3cd7887..fb69e22e7 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureTrail.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureTrail.java @@ -245,7 +245,7 @@ final class GestureTrail { final float body1 = r1 * params.mTrailBodyRatio; final float body2 = r2 * params.mTrailBodyRatio; final Path path = roundedLine.makePath(p1x, p1y, body1, p2x, p2y, body2); - if (path != null) { + if (!path.isEmpty()) { roundedLine.getBounds(mRoundedLineBounds); if (params.mTrailShadowEnabled) { final float shadow2 = r2 * params.mTrailShadowRatio; diff --git a/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java b/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java index 2eefd6ae9..211ef5f8b 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java +++ b/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java @@ -37,16 +37,18 @@ public final class RoundedLine { * @param p2x the x-coordinate of the end point. * @param p2y the y-coordinate of the end point. * @param r2 the radius at the end point - * @return the path of rounded line + * @return an instance of {@link Path} that holds the result rounded line, or an instance of + * {@link Path} that holds an empty path if the start and end points are equal. */ public Path makePath(final float p1x, final float p1y, final float r1, final float p2x, final float p2y, final float r2) { + mPath.rewind(); final double dx = p2x - p1x; final double dy = p2y - p1y; // Distance of the points. final double l = Math.hypot(dx, dy); if (Double.compare(0.0d, l) == 0) { - return null; + return mPath; // Return an empty path } // Angle of the line p1-p2 final double a = Math.atan2(dy, dx); @@ -86,7 +88,6 @@ public final class RoundedLine { mArc2.set(p2x, p2y, p2x, p2y); mArc2.inset(-r2, -r2); - mPath.rewind(); // Trail cap at P1. mPath.moveTo(p1x, p1y); mPath.arcTo(mArc1, angle, a1);