summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2012-02-11 07:19:47 +0800
committerChih-Chung Chang <chihchung@google.com>2012-02-11 10:21:58 +0800
commit4e05190c04eab6f4700c557ae488f3d7e344d29c (patch)
tree824dcc1b3ea982629a6d9e2e3517f0c7790fdd7f
parent3d2225f6b0ff7f65620feaa283415a045718ffeb (diff)
downloadandroid_packages_apps_Snap-4e05190c04eab6f4700c557ae488f3d7e344d29c.tar.gz
android_packages_apps_Snap-4e05190c04eab6f4700c557ae488f3d7e344d29c.tar.bz2
android_packages_apps_Snap-4e05190c04eab6f4700c557ae488f3d7e344d29c.zip
Use FloatMath instead of Math.
Change-Id: I41661b231f6c034dbca6af26d5950eda6c5fc7da
-rw-r--r--gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java10
-rw-r--r--src/com/android/gallery3d/app/CropImage.java4
-rw-r--r--src/com/android/gallery3d/app/EyePosition.java15
-rw-r--r--src/com/android/gallery3d/data/LocationClustering.java3
-rw-r--r--src/com/android/gallery3d/photoeditor/RendererUtils.java13
-rw-r--r--src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java5
-rw-r--r--src/com/android/gallery3d/ui/AlbumSlidingWindow.java5
-rw-r--r--src/com/android/gallery3d/ui/CropView.java4
-rw-r--r--src/com/android/gallery3d/ui/PositionController.java11
-rw-r--r--src/com/android/gallery3d/ui/StringTexture.java3
-rw-r--r--src/com/android/gallery3d/ui/TileImageView.java9
11 files changed, 45 insertions, 37 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
index 2192cf8ec..67aa6d77b 100644
--- a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
+++ b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
@@ -23,6 +23,7 @@ import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Build;
+import android.util.FloatMath;
import android.util.Log;
import java.io.ByteArrayOutputStream;
@@ -71,7 +72,7 @@ public class BitmapUtils {
&& minSideLength == UNCONSTRAINED) return 1;
int lowerBound = (maxNumOfPixels == UNCONSTRAINED) ? 1 :
- (int) Math.ceil(Math.sqrt((double) (w * h) / maxNumOfPixels));
+ (int) FloatMath.ceil(FloatMath.sqrt((float) (w * h) / maxNumOfPixels));
if (minSideLength == UNCONSTRAINED) {
return lowerBound;
@@ -95,7 +96,7 @@ public class BitmapUtils {
// Fin the min x that 1 / x <= scale
public static int computeSampleSizeLarger(float scale) {
- int initialSize = (int) Math.floor(1f / scale);
+ int initialSize = (int) FloatMath.floor(1f / scale);
if (initialSize <= 1) return 1;
return initialSize <= 8
@@ -106,7 +107,7 @@ public class BitmapUtils {
// Find the max x that 1 / x >= scale.
public static int computeSampleSize(float scale) {
Utils.assertTrue(scale > 0);
- int initialSize = Math.max(1, (int) Math.ceil(1 / scale));
+ int initialSize = Math.max(1, (int) FloatMath.ceil(1 / scale));
return initialSize <= 8
? Utils.nextPowerOf2(initialSize)
: (initialSize + 7) / 8 * 8;
@@ -116,8 +117,7 @@ public class BitmapUtils {
Bitmap bitmap, int targetPixels, boolean recycle) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
- float scale = (float) Math.sqrt(
- (double) targetPixels / (width * height));
+ float scale = FloatMath.sqrt((float) targetPixels / (width * height));
if (scale >= 1.0f) return bitmap;
return resizeBitmapByScale(bitmap, scale, recycle);
}
diff --git a/src/com/android/gallery3d/app/CropImage.java b/src/com/android/gallery3d/app/CropImage.java
index 5ac9f0251..7e1572f0c 100644
--- a/src/com/android/gallery3d/app/CropImage.java
+++ b/src/com/android/gallery3d/app/CropImage.java
@@ -38,6 +38,7 @@ import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
+import android.util.FloatMath;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
@@ -554,8 +555,7 @@ public class CropImage extends AbstractGalleryActivity {
}
if (outputX * outputY > MAX_PIXEL_COUNT) {
- float scale = (float) Math.sqrt(
- (double) MAX_PIXEL_COUNT / outputX / outputY);
+ float scale = FloatMath.sqrt((float) MAX_PIXEL_COUNT / outputX / outputY);
Log.w(TAG, "scale down the cropped image: " + scale);
outputX = Math.round(scale * outputX);
outputY = Math.round(scale * outputY);
diff --git a/src/com/android/gallery3d/app/EyePosition.java b/src/com/android/gallery3d/app/EyePosition.java
index 7b4495a35..f9713e179 100644
--- a/src/com/android/gallery3d/app/EyePosition.java
+++ b/src/com/android/gallery3d/app/EyePosition.java
@@ -25,6 +25,7 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.SystemClock;
+import android.util.FloatMath;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;
@@ -41,9 +42,9 @@ public class EyePosition {
private static final int GYROSCOPE_SETTLE_DOWN = 15;
private static final float GYROSCOPE_RESTORE_FACTOR = 0.995f;
- private static final double USER_ANGEL = Math.toRadians(10);
- private static final float USER_ANGEL_COS = (float) Math.cos(USER_ANGEL);
- private static final float USER_ANGEL_SIN = (float) Math.sin(USER_ANGEL);
+ private static final float USER_ANGEL = (float) Math.toRadians(10);
+ private static final float USER_ANGEL_COS = FloatMath.cos(USER_ANGEL);
+ private static final float USER_ANGEL_SIN = FloatMath.sin(USER_ANGEL);
private static final float MAX_VIEW_RANGE = (float) 0.5;
private static final int NOT_STARTED = -1;
@@ -126,8 +127,8 @@ public class EyePosition {
float ty = -1 + t * y;
float tz = t * z;
- float length = (float) Math.sqrt(tx * tx + ty * ty + tz * tz);
- float glength = (float) Math.sqrt(temp);
+ float length = FloatMath.sqrt(tx * tx + ty * ty + tz * tz);
+ float glength = FloatMath.sqrt(temp);
mX = Utils.clamp((x * USER_ANGEL_COS / glength
+ tx * USER_ANGEL_SIN / length) * mUserDistance,
@@ -135,7 +136,7 @@ public class EyePosition {
mY = -Utils.clamp((y * USER_ANGEL_COS / glength
+ ty * USER_ANGEL_SIN / length) * mUserDistance,
-mLimit, mLimit);
- mZ = (float) -Math.sqrt(
+ mZ = -FloatMath.sqrt(
mUserDistance * mUserDistance - mX * mX - mY * mY);
mListener.onEyePositionChanged(mX, mY, mZ);
}
@@ -173,7 +174,7 @@ public class EyePosition {
mY = Utils.clamp((float) (mY + y * t / Math.hypot(mZ, mY)),
-mLimit, mLimit) * GYROSCOPE_RESTORE_FACTOR;
- mZ = (float) -Math.sqrt(
+ mZ = -FloatMath.sqrt(
mUserDistance * mUserDistance - mX * mX - mY * mY);
mListener.onEyePositionChanged(mX, mY, mZ);
}
diff --git a/src/com/android/gallery3d/data/LocationClustering.java b/src/com/android/gallery3d/data/LocationClustering.java
index 788060cf0..9f3a35890 100644
--- a/src/com/android/gallery3d/data/LocationClustering.java
+++ b/src/com/android/gallery3d/data/LocationClustering.java
@@ -23,6 +23,7 @@ import com.android.gallery3d.util.GalleryUtils;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
+import android.util.FloatMath;
import android.widget.Toast;
import java.util.ArrayList;
@@ -294,7 +295,7 @@ class LocationClustering extends Clustering {
}
// step 5: calculate the final score
- float score = totalDistance * (float) Math.sqrt(realK);
+ float score = totalDistance * FloatMath.sqrt(realK);
if (score < bestScore) {
bestScore = score;
diff --git a/src/com/android/gallery3d/photoeditor/RendererUtils.java b/src/com/android/gallery3d/photoeditor/RendererUtils.java
index b92907df0..3edcff5f5 100644
--- a/src/com/android/gallery3d/photoeditor/RendererUtils.java
+++ b/src/com/android/gallery3d/photoeditor/RendererUtils.java
@@ -19,6 +19,7 @@ package com.android.gallery3d.photoeditor;
import android.graphics.Bitmap;
import android.opengl.GLES20;
import android.opengl.GLUtils;
+import android.util.FloatMath;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -153,8 +154,8 @@ public class RendererUtils {
public static void setRenderToRotate(RenderContext context, int srcWidth, int srcHeight,
int dstWidth, int dstHeight, float degrees) {
float radian = -degrees * DEGREE_TO_RADIAN;
- float cosTheta = (float) Math.cos(radian);
- float sinTheta = (float) Math.sin(radian);
+ float cosTheta = FloatMath.cos(radian);
+ float sinTheta = FloatMath.sin(radian);
float cosWidth = cosTheta * srcWidth;
float sinWidth = sinTheta * srcWidth;
float cosHeight = cosTheta * srcHeight;
@@ -205,8 +206,8 @@ public class RendererUtils {
System.arraycopy(base, 0, vertices, 0, vertices.length);
if (horizontalDegrees % 180f != 0) {
float radian = (horizontalDegrees - horizontalRounds * 180) * DEGREE_TO_RADIAN;
- float cosTheta = (float) Math.cos(radian);
- float sinTheta = (float) Math.sin(radian);
+ float cosTheta = FloatMath.cos(radian);
+ float sinTheta = FloatMath.sin(radian);
float scale = length / (length + sinTheta * base[0]);
vertices[0] = cosTheta * base[0] * scale;
@@ -223,8 +224,8 @@ public class RendererUtils {
if (verticalDegrees % 180f != 0) {
float radian = (verticalDegrees - verticalRounds * 180) * DEGREE_TO_RADIAN;
- float cosTheta = (float) Math.cos(radian);
- float sinTheta = (float) Math.sin(radian);
+ float cosTheta = FloatMath.cos(radian);
+ float sinTheta = FloatMath.sin(radian);
float scale = length / (length + sinTheta * base[1]);
vertices[0] = base[0] * scale;
diff --git a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
index 87ff5579d..0f03da844 100644
--- a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
+++ b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
@@ -19,6 +19,7 @@ package com.android.gallery3d.ui;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Message;
+import android.util.FloatMath;
import com.android.gallery3d.R;
import com.android.gallery3d.app.GalleryActivity;
@@ -381,8 +382,8 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener {
float scaley = mBoxHeight / (float) height;
float scale = Math.min(scalex, scaley);
- width = (int) Math.floor(width * scale);
- height = (int) Math.floor(height * scale);
+ width = (int) FloatMath.floor(width * scale);
+ height = (int) FloatMath.floor(height * scale);
// Now draw it
int sourceType = SelectionDrawer.DATASOURCE_TYPE_NOT_CATEGORIZED;
diff --git a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
index b40d72c47..6947d7fb9 100644
--- a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
+++ b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
@@ -18,6 +18,7 @@ package com.android.gallery3d.ui;
import android.graphics.Bitmap;
import android.os.Message;
+import android.util.FloatMath;
import com.android.gallery3d.app.GalleryActivity;
import com.android.gallery3d.common.BitmapUtils;
@@ -329,8 +330,8 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener {
float scaley = mBoxHeight / (float) height;
float scale = Math.min(scalex, scaley);
- width = (int) Math.floor(width * scale);
- height = (int) Math.floor(height * scale);
+ width = (int) FloatMath.floor(width * scale);
+ height = (int) FloatMath.floor(height * scale);
// Now draw it
if (pass == 0) {
diff --git a/src/com/android/gallery3d/ui/CropView.java b/src/com/android/gallery3d/ui/CropView.java
index 71fdaab96..227e67e11 100644
--- a/src/com/android/gallery3d/ui/CropView.java
+++ b/src/com/android/gallery3d/ui/CropView.java
@@ -31,6 +31,7 @@ import android.graphics.RectF;
import android.media.FaceDetector;
import android.os.Handler;
import android.os.Message;
+import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.animation.DecelerateInterpolator;
import android.widget.Toast;
@@ -756,8 +757,7 @@ public class CropView extends GLView {
int rotation = mImageRotation;
int width = bitmap.getWidth();
int height = bitmap.getHeight();
- float scale = (float) Math.sqrt(
- (double) FACE_PIXEL_COUNT / (width * height));
+ float scale = FloatMath.sqrt((float) FACE_PIXEL_COUNT / (width * height));
// faceBitmap is a correctly rotated bitmap, as viewed by a user.
Bitmap faceBitmap;
diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java
index b4dac973f..734c571b4 100644
--- a/src/com/android/gallery3d/ui/PositionController.java
+++ b/src/com/android/gallery3d/ui/PositionController.java
@@ -29,6 +29,7 @@ import android.graphics.Color;
import android.graphics.RectF;
import android.os.Message;
import android.os.SystemClock;
+import android.util.FloatMath;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
@@ -406,7 +407,7 @@ class PositionController {
// force it to be in the center.
// (We do for height only, not width, because the user may
// want to scroll to the previous/next image.)
- if (Math.floor(mImageH * mToScale) <= mViewH) {
+ if (FloatMath.floor(mImageH * mToScale) <= mViewH) {
mToY = mImageH / 2;
}
@@ -582,19 +583,19 @@ class PositionController {
private void calculateStableBound(float scale, float horizontalSlack) {
// The number of pixels between the center of the view
// and the edge when the edge is aligned.
- mBoundLeft = (int) Math.ceil((mViewW - horizontalSlack) / (2 * scale));
+ mBoundLeft = (int) FloatMath.ceil((mViewW - horizontalSlack) / (2 * scale));
mBoundRight = mImageW - mBoundLeft;
- mBoundTop = (int) Math.ceil(mViewH / (2 * scale));
+ mBoundTop = (int) FloatMath.ceil(mViewH / (2 * scale));
mBoundBottom = mImageH - mBoundTop;
// If the scaled height is smaller than the view height,
// force it to be in the center.
- if (Math.floor(mImageH * scale) <= mViewH) {
+ if (FloatMath.floor(mImageH * scale) <= mViewH) {
mBoundTop = mBoundBottom = mImageH / 2;
}
// Same for width
- if (Math.floor(mImageW * scale) <= mViewW) {
+ if (FloatMath.floor(mImageW * scale) <= mViewW) {
mBoundLeft = mBoundRight = mImageW / 2;
}
}
diff --git a/src/com/android/gallery3d/ui/StringTexture.java b/src/com/android/gallery3d/ui/StringTexture.java
index f576c0172..935cd729e 100644
--- a/src/com/android/gallery3d/ui/StringTexture.java
+++ b/src/com/android/gallery3d/ui/StringTexture.java
@@ -21,6 +21,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.Typeface;
+import android.util.FloatMath;
import android.text.TextPaint;
import android.text.TextUtils;
@@ -69,7 +70,7 @@ class StringTexture extends CanvasTexture {
private static StringTexture newInstance(String text, TextPaint paint) {
FontMetricsInt metrics = paint.getFontMetricsInt();
- int width = (int) Math.ceil(paint.measureText(text));
+ int width = (int) FloatMath.ceil(paint.measureText(text));
int height = metrics.bottom - metrics.top;
// The texture size needs to be at least 1x1.
if (width <= 0) width = 1;
diff --git a/src/com/android/gallery3d/ui/TileImageView.java b/src/com/android/gallery3d/ui/TileImageView.java
index 980f7b208..05d09f5b8 100644
--- a/src/com/android/gallery3d/ui/TileImageView.java
+++ b/src/com/android/gallery3d/ui/TileImageView.java
@@ -19,6 +19,7 @@ package com.android.gallery3d.ui;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.RectF;
+import android.util.FloatMath;
import com.android.gallery3d.app.GalleryContext;
import com.android.gallery3d.common.Utils;
@@ -293,10 +294,10 @@ public class TileImageView extends GLView {
int height = (int) Math.ceil(Math.max(
Math.abs(sin * w + cos * h), Math.abs(sin * w - cos * h)));
- int left = (int) Math.floor(cX - width / (2f * scale));
- int top = (int) Math.floor(cY - height / (2f * scale));
- int right = (int) Math.ceil(left + width / scale);
- int bottom = (int) Math.ceil(top + height / scale);
+ int left = (int) FloatMath.floor(cX - width / (2f * scale));
+ int top = (int) FloatMath.floor(cY - height / (2f * scale));
+ int right = (int) FloatMath.ceil(left + width / scale);
+ int bottom = (int) FloatMath.ceil(top + height / scale);
// align the rectangle to tile boundary
int size = TILE_SIZE << level;