aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/main/java')
-rw-r--r--library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/AttributeStrategy.java31
-rw-r--r--library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/SizeStrategy.java19
-rw-r--r--library/src/main/java/com/bumptech/glide/load/engine/executor/FifoPriorityThreadPoolExecutor.java30
-rw-r--r--library/src/main/java/com/bumptech/glide/load/engine/prefill/PreFillType.java35
-rw-r--r--library/src/main/java/com/bumptech/glide/load/model/ModelCache.java28
-rw-r--r--library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java64
6 files changed, 84 insertions, 123 deletions
diff --git a/library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/AttributeStrategy.java b/library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/AttributeStrategy.java
index ef57437e..f3035e50 100644
--- a/library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/AttributeStrategy.java
+++ b/library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/AttributeStrategy.java
@@ -56,7 +56,8 @@ class AttributeStrategy implements LruPoolStrategy {
return "[" + width + "x" + height + "], " + config;
}
- private static class KeyPool extends BaseKeyPool<Key> {
+ // Visible for testing.
+ static class KeyPool extends BaseKeyPool<Key> {
public Key get(int width, int height, Bitmap.Config config) {
Key result = get();
result.init(width, height, config);
@@ -69,7 +70,8 @@ class AttributeStrategy implements LruPoolStrategy {
}
}
- private static class Key implements Poolable {
+ // Visible for testing.
+ static class Key implements Poolable {
private final KeyPool pool;
private int width;
private int height;
@@ -88,26 +90,13 @@ class AttributeStrategy implements LruPoolStrategy {
@Override
public boolean equals(Object o) {
- if (this == o) {
- return true;
+ if (o instanceof Key) {
+ Key other = (Key) o;
+ return width == other.width
+ && height == other.height
+ && config == other.config;
}
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- Key key = (Key) o;
-
- if (height != key.height) {
- return false;
- }
- if (width != key.width) {
- return false;
- }
- if (config != key.config) {
- return false;
- }
-
- return true;
+ return false;
}
@Override
diff --git a/library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/SizeStrategy.java b/library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/SizeStrategy.java
index b33d13ac..1ce61aaf 100644
--- a/library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/SizeStrategy.java
+++ b/library/src/main/java/com/bumptech/glide/load/engine/bitmap_recycle/SizeStrategy.java
@@ -119,7 +119,8 @@ class SizeStrategy implements LruPoolStrategy {
return "[" + size + "]";
}
- private static class KeyPool extends BaseKeyPool<Key> {
+ // Visible for testing.
+ static class KeyPool extends BaseKeyPool<Key> {
public Key get(int size) {
Key result = get();
@@ -133,7 +134,8 @@ class SizeStrategy implements LruPoolStrategy {
}
}
- private static final class Key implements Poolable {
+ // Visible for testing.
+ static final class Key implements Poolable {
private final KeyPool pool;
private int size;
@@ -147,16 +149,11 @@ class SizeStrategy implements LruPoolStrategy {
@Override
public boolean equals(Object o) {
- if (this == o) {
- return true;
+ if (o instanceof Key) {
+ Key other = (Key) o;
+ return size == other.size;
}
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- Key key = (Key) o;
-
- return size == key.size;
+ return false;
}
@Override
diff --git a/library/src/main/java/com/bumptech/glide/load/engine/executor/FifoPriorityThreadPoolExecutor.java b/library/src/main/java/com/bumptech/glide/load/engine/executor/FifoPriorityThreadPoolExecutor.java
index 9972fc6d..db0a128a 100644
--- a/library/src/main/java/com/bumptech/glide/load/engine/executor/FifoPriorityThreadPoolExecutor.java
+++ b/library/src/main/java/com/bumptech/glide/load/engine/executor/FifoPriorityThreadPoolExecutor.java
@@ -34,7 +34,7 @@ public class FifoPriorityThreadPoolExecutor extends ThreadPoolExecutor {
@Override
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
- return new FifoPriorityLoadTask<T>(runnable, value, ordering.getAndIncrement());
+ return new LoadTask<T>(runnable, value, ordering.getAndIncrement());
}
/**
@@ -57,11 +57,12 @@ public class FifoPriorityThreadPoolExecutor extends ThreadPoolExecutor {
}
}
- private static class FifoPriorityLoadTask<T> extends FutureTask<T> implements Comparable<FifoPriorityLoadTask<?>> {
+ // Visible for testing.
+ static class LoadTask<T> extends FutureTask<T> implements Comparable<LoadTask<?>> {
private final int priority;
private final int order;
- public FifoPriorityLoadTask(Runnable runnable, T result, int order) {
+ public LoadTask(Runnable runnable, T result, int order) {
super(runnable, result);
if (!(runnable instanceof Prioritized)) {
throw new IllegalArgumentException("FifoPriorityThreadPoolExecutor must be given Runnables that "
@@ -71,25 +72,14 @@ public class FifoPriorityThreadPoolExecutor extends ThreadPoolExecutor {
this.order = order;
}
+ @SuppressWarnings("unchecked")
@Override
public boolean equals(Object o) {
- if (this == o) {
- return true;
+ if (o instanceof LoadTask) {
+ LoadTask<Object> other = (LoadTask<Object>) o;
+ return order == other.order && priority == other.priority;
}
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- FifoPriorityLoadTask that = (FifoPriorityLoadTask) o;
-
- if (order != that.order) {
- return false;
- }
- if (priority != that.priority) {
- return false;
- }
-
- return true;
+ return false;
}
@Override
@@ -100,7 +90,7 @@ public class FifoPriorityThreadPoolExecutor extends ThreadPoolExecutor {
}
@Override
- public int compareTo(FifoPriorityLoadTask<?> loadTask) {
+ public int compareTo(LoadTask<?> loadTask) {
int result = priority - loadTask.priority;
if (result == 0) {
result = order - loadTask.order;
diff --git a/library/src/main/java/com/bumptech/glide/load/engine/prefill/PreFillType.java b/library/src/main/java/com/bumptech/glide/load/engine/prefill/PreFillType.java
index 33d0387e..5037b352 100644
--- a/library/src/main/java/com/bumptech/glide/load/engine/prefill/PreFillType.java
+++ b/library/src/main/java/com/bumptech/glide/load/engine/prefill/PreFillType.java
@@ -30,15 +30,6 @@ public final class PreFillType {
if (config == null) {
throw new NullPointerException("Config must not be null");
}
- if (width <= 0) {
- throw new IllegalArgumentException("Width must be > 0");
- }
- if (height <= 0) {
- throw new IllegalArgumentException("Height must be > 0");
- }
- if (weight <= 0) {
- throw new IllegalArgumentException("Weight must be > 0");
- }
this.width = width;
this.height = height;
@@ -76,18 +67,14 @@ public final class PreFillType {
@Override
public boolean equals(Object o) {
- if (this == o) {
- return true;
- } else if (o == null || getClass() != o.getClass()) {
- return false;
+ if (o instanceof PreFillType) {
+ PreFillType other = (PreFillType) o;
+ return height == other.height
+ && width == other.width
+ && weight == other.weight
+ && config == other.config;
}
-
- PreFillType size = (PreFillType) o;
-
- return height == size.height
- && weight == size.weight
- && width == size.width
- && config == size.config;
+ return false;
}
@Override
@@ -112,7 +99,7 @@ public final class PreFillType {
/**
* Builder for {@link PreFillType}.
*/
- public static final class Builder {
+ public static class Builder {
private final int width;
private final int height;
@@ -133,6 +120,12 @@ public final class PreFillType {
* @param height The height in pixels of the Bitmaps to prefill.
*/
public Builder(int width, int height) {
+ if (width <= 0) {
+ throw new IllegalArgumentException("Width must be > 0");
+ }
+ if (height <= 0) {
+ throw new IllegalArgumentException("Height must be > 0");
+ }
this.width = width;
this.height = height;
}
diff --git a/library/src/main/java/com/bumptech/glide/load/model/ModelCache.java b/library/src/main/java/com/bumptech/glide/load/model/ModelCache.java
index a0dede14..55c0de0c 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/ModelCache.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/ModelCache.java
@@ -60,14 +60,15 @@ public class ModelCache<A, B> {
cache.put(key, value);
}
- private static final class ModelKey<A> {
+ // Visible for testing.
+ static final class ModelKey<A> {
private static final Queue<ModelKey<?>> KEY_QUEUE = Util.createQueue(0);
private int height;
private int width;
private A model;
- public static <A> ModelKey<A> get(A model, int width, int height) {
+ static <A> ModelKey<A> get(A model, int width, int height) {
@SuppressWarnings("unchecked")
ModelKey<A> modelKey = (ModelKey<A>) KEY_QUEUE.poll();
if (modelKey == null) {
@@ -92,26 +93,11 @@ public class ModelCache<A, B> {
@Override
public boolean equals(Object o) {
- if (this == o) {
- return true;
+ if (o instanceof ModelKey) {
+ ModelKey other = (ModelKey) o;
+ return width == other.width && height == other.height && model.equals(other.model);
}
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- ModelKey<?> modelKey = (ModelKey<?>) o;
-
- if (height != modelKey.height) {
- return false;
- }
- if (width != modelKey.width) {
- return false;
- }
- if (!model.equals(modelKey.model)) {
- return false;
- }
-
- return true;
+ return false;
}
@Override
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java
index 80ab07cc..0f9c6693 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/TransformationUtils.java
@@ -149,22 +149,18 @@ public final class TransformationUtils {
* Returns a matrix with rotation set based on Exif orientation tag.
* If the orientation is undefined or 0 null is returned.
*
+ * @deprecated No longer used by Glide, scheduled to be removed in Glide 4.0
* @param pathToOriginal Path to original image file that may have exif data.
* @return A rotation in degrees based on exif orientation
*/
@TargetApi(Build.VERSION_CODES.ECLAIR)
+ @Deprecated
public static int getOrientation(String pathToOriginal) {
int degreesToRotate = 0;
try {
ExifInterface exif = new ExifInterface(pathToOriginal);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
- if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
- degreesToRotate = 90;
- } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
- degreesToRotate = 180;
- } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
- degreesToRotate = 270;
- }
+ return getExifOrientationDegrees(orientation);
} catch (Exception e) {
if (Log.isLoggable(TAG, Log.ERROR)) {
Log.e(TAG, "Unable to get orientation for image with path=" + pathToOriginal, e);
@@ -177,10 +173,12 @@ public final class TransformationUtils {
* This is an expensive operation that copies the image in place with the pixels rotated.
* If possible rather use getOrientationMatrix, and set that as the imageMatrix on an ImageView.
*
+ * @deprecated No longer used by Glide, scheduled to be removed in Glide 4.0
* @param pathToOriginal Path to original image file that may have exif data.
* @param imageToOrient Image Bitmap to orient.
* @return The oriented bitmap. May be the imageToOrient without modification, or a new Bitmap.
*/
+ @Deprecated
public static Bitmap orientImage(String pathToOriginal, Bitmap imageToOrient) {
int degreesToRotate = getOrientation(pathToOriginal);
return rotateImage(imageToOrient, degreesToRotate);
@@ -255,7 +253,36 @@ public final class TransformationUtils {
* @return The rotated and/or flipped image or toOrient if no rotation or flip was necessary.
*/
public static Bitmap rotateImageExif(Bitmap toOrient, BitmapPool pool, int exifOrientation) {
+ if (exifOrientation == ExifInterface.ORIENTATION_NORMAL
+ || exifOrientation == ExifInterface.ORIENTATION_UNDEFINED) {
+ return toOrient;
+ }
final Matrix matrix = new Matrix();
+ initializeMatrixForRotation(exifOrientation, matrix);
+
+ // From Bitmap.createBitmap.
+ final RectF newRect = new RectF(0, 0, toOrient.getWidth(), toOrient.getHeight());
+ matrix.mapRect(newRect);
+
+ final int newWidth = Math.round(newRect.width());
+ final int newHeight = Math.round(newRect.height());
+
+ Bitmap result = pool.get(newWidth, newHeight, toOrient.getConfig());
+ if (result == null) {
+ result = Bitmap.createBitmap(newWidth, newHeight, toOrient.getConfig());
+ }
+
+ matrix.postTranslate(-newRect.left, -newRect.top);
+
+ final Canvas canvas = new Canvas(result);
+ final Paint paint = new Paint(PAINT_FLAGS);
+ canvas.drawBitmap(toOrient, matrix, paint);
+
+ return result;
+ }
+
+ // Visible for testing.
+ static void initializeMatrixForRotation(int exifOrientation, Matrix matrix) {
switch (exifOrientation) {
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
matrix.setScale(-1, 1);
@@ -281,29 +308,8 @@ public final class TransformationUtils {
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.setRotate(-90);
break;
- // case ExifInterface.ORIENTATION_NORMAL
default:
- return toOrient;
+ // Do nothing.
}
-
- // From Bitmap.createBitmap.
- final RectF newRect = new RectF(0, 0, toOrient.getWidth(), toOrient.getHeight());
- matrix.mapRect(newRect);
-
- final int newWidth = Math.round(newRect.width());
- final int newHeight = Math.round(newRect.height());
-
- Bitmap result = pool.get(newWidth, newHeight, toOrient.getConfig());
- if (result == null) {
- result = Bitmap.createBitmap(newWidth, newHeight, toOrient.getConfig());
- }
-
- matrix.postTranslate(-newRect.left, -newRect.top);
-
- final Canvas canvas = new Canvas(result);
- final Paint paint = new Paint(PAINT_FLAGS);
- canvas.drawBitmap(toOrient, matrix, paint);
-
- return result;
}
}