diff options
Diffstat (limited to 'core/java/android/transition/Explode.java')
| -rw-r--r-- | core/java/android/transition/Explode.java | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/core/java/android/transition/Explode.java b/core/java/android/transition/Explode.java index 0ccdf15..788676a 100644 --- a/core/java/android/transition/Explode.java +++ b/core/java/android/transition/Explode.java @@ -22,7 +22,6 @@ import android.animation.TimeInterpolator; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; -import android.util.FloatMath; import android.view.View; import android.view.ViewGroup; import android.view.animation.AccelerateInterpolator; @@ -143,32 +142,29 @@ public class Explode extends Visibility { int centerX = bounds.centerX(); int centerY = bounds.centerY(); - float xVector = centerX - focalX; - float yVector = centerY - focalY; + double xVector = centerX - focalX; + double yVector = centerY - focalY; if (xVector == 0 && yVector == 0) { // Random direction when View is centered on focal View. - xVector = (float) (Math.random() * 2) - 1; - yVector = (float) (Math.random() * 2) - 1; + xVector = (Math.random() * 2) - 1; + yVector = (Math.random() * 2) - 1; } - float vectorSize = calculateDistance(xVector, yVector); + double vectorSize = Math.hypot(xVector, yVector); xVector /= vectorSize; yVector /= vectorSize; - float maxDistance = + double maxDistance = calculateMaxDistance(sceneRoot, focalX - sceneRootX, focalY - sceneRootY); - outVector[0] = Math.round(maxDistance * xVector); - outVector[1] = Math.round(maxDistance * yVector); + outVector[0] = (int) Math.round(maxDistance * xVector); + outVector[1] = (int) Math.round(maxDistance * yVector); } - private static float calculateMaxDistance(View sceneRoot, int focalX, int focalY) { + private static double calculateMaxDistance(View sceneRoot, int focalX, int focalY) { int maxX = Math.max(focalX, sceneRoot.getWidth() - focalX); int maxY = Math.max(focalY, sceneRoot.getHeight() - focalY); - return calculateDistance(maxX, maxY); + return Math.hypot(maxX, maxY); } - private static float calculateDistance(float x, float y) { - return FloatMath.sqrt((x * x) + (y * y)); - } } |
