transformations, Bitmap result) {
- for (int i = 0, count = transformations.size(); i < count; i++) {
- final Transformation transformation = transformations.get(i);
- Bitmap newResult = transformation.transform(result);
-
- if (newResult == null) {
- final StringBuilder builder = new StringBuilder() //
- .append("Transformation ")
- .append(transformation.key())
- .append(" returned null after ")
- .append(i)
- .append(" previous transformation(s).\n\nTransformation list:\n");
- for (Transformation t : transformations) {
- builder.append(t.key()).append('\n');
- }
- Picasso.HANDLER.post(new Runnable() {
- @Override public void run() {
- throw new NullPointerException(builder.toString());
- }
- });
- return null;
- }
-
- if (newResult == result && result.isRecycled()) {
- Picasso.HANDLER.post(new Runnable() {
- @Override public void run() {
- throw new IllegalStateException("Transformation "
- + transformation.key()
- + " returned input Bitmap but recycled it.");
- }
- });
- return null;
- }
-
- // If the transformation returned a new bitmap ensure they recycled the original.
- if (newResult != result && !result.isRecycled()) {
- Picasso.HANDLER.post(new Runnable() {
- @Override public void run() {
- throw new IllegalStateException("Transformation "
- + transformation.key()
- + " mutated input Bitmap but failed to recycle the original.");
- }
- });
- return null;
- }
-
- result = newResult;
- }
- return result;
- }
-
- static Bitmap transformResult(Request data, Bitmap result, int exifRotation) {
- int inWidth = result.getWidth();
- int inHeight = result.getHeight();
-
- int drawX = 0;
- int drawY = 0;
- int drawWidth = inWidth;
- int drawHeight = inHeight;
-
- Matrix matrix = new Matrix();
-
- if (data.needsMatrixTransform()) {
- int targetWidth = data.targetWidth;
- int targetHeight = data.targetHeight;
-
- float targetRotation = data.rotationDegrees;
- if (targetRotation != 0) {
- if (data.hasRotationPivot) {
- matrix.setRotate(targetRotation, data.rotationPivotX, data.rotationPivotY);
- } else {
- matrix.setRotate(targetRotation);
- }
- }
-
- if (data.centerCrop) {
- float widthRatio = targetWidth / (float) inWidth;
- float heightRatio = targetHeight / (float) inHeight;
- float scale;
- if (widthRatio > heightRatio) {
- scale = widthRatio;
- int newSize = (int) Math.ceil(inHeight * (heightRatio / widthRatio));
- drawY = (inHeight - newSize) / 2;
- drawHeight = newSize;
- } else {
- scale = heightRatio;
- int newSize = (int) Math.ceil(inWidth * (widthRatio / heightRatio));
- drawX = (inWidth - newSize) / 2;
- drawWidth = newSize;
- }
- matrix.preScale(scale, scale);
- } else if (data.centerInside) {
- float widthRatio = targetWidth / (float) inWidth;
- float heightRatio = targetHeight / (float) inHeight;
- float scale = widthRatio < heightRatio ? widthRatio : heightRatio;
- matrix.preScale(scale, scale);
- } else if (targetWidth != 0 && targetHeight != 0 //
- && (targetWidth != inWidth || targetHeight != inHeight)) {
- // If an explicit target size has been specified and they do not match the results bounds,
- // pre-scale the existing matrix appropriately.
- float sx = targetWidth / (float) inWidth;
- float sy = targetHeight / (float) inHeight;
- matrix.preScale(sx, sy);
- }
- }
-
- if (exifRotation != 0) {
- matrix.preRotate(exifRotation);
- }
-
- Bitmap newResult =
- Bitmap.createBitmap(result, drawX, drawY, drawWidth, drawHeight, matrix, true);
- if (newResult != result) {
- result.recycle();
- result = newResult;
- }
-
- return result;
- }
-}
diff --git a/picasso/src/main/java/com/squareup/picasso/Cache.java b/picasso/src/main/java/com/squareup/picasso/Cache.java
deleted file mode 100644
index 73ff2f2894..0000000000
--- a/picasso/src/main/java/com/squareup/picasso/Cache.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2013 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.squareup.picasso;
-
-import android.graphics.Bitmap;
-
-/**
- * A memory cache for storing the most recently used images.
- *
- * Note: The {@link Cache} is accessed by multiple threads. You must ensure
- * your {@link Cache} implementation is thread safe when {@link Cache#get(String)} or {@link
- * Cache#set(String, android.graphics.Bitmap)} is called.
- */
-public interface Cache {
- /** Retrieve an image for the specified {@code key} or {@code null}. */
- Bitmap get(String key);
-
- /** Store an image in the cache for the specified {@code key}. */
- void set(String key, Bitmap bitmap);
-
- /** Returns the current size of the cache in bytes. */
- int size();
-
- /** Returns the maximum size in bytes that the cache can hold. */
- int maxSize();
-
- /** Clears the cache. */
- void clear();
-
- /** A cache which does not store any values. */
- Cache NONE = new Cache() {
- @Override public Bitmap get(String key) {
- return null;
- }
-
- @Override public void set(String key, Bitmap bitmap) {
- // Ignore.
- }
-
- @Override public int size() {
- return 0;
- }
-
- @Override public int maxSize() {
- return 0;
- }
-
- @Override public void clear() {
- }
- };
-}
diff --git a/picasso/src/main/java/com/squareup/picasso/ContactsPhotoRequestHandler.java b/picasso/src/main/java/com/squareup/picasso/ContactsPhotoRequestHandler.java
deleted file mode 100644
index e623c2c5fb..0000000000
--- a/picasso/src/main/java/com/squareup/picasso/ContactsPhotoRequestHandler.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2013 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.squareup.picasso;
-
-import android.annotation.TargetApi;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.UriMatcher;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.net.Uri;
-import android.provider.ContactsContract;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import static android.content.ContentResolver.SCHEME_CONTENT;
-import static android.os.Build.VERSION.SDK_INT;
-import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
-import static android.provider.ContactsContract.Contacts.openContactPhotoInputStream;
-import static com.squareup.picasso.Picasso.LoadedFrom.DISK;
-
-class ContactsPhotoRequestHandler extends RequestHandler {
- /** A lookup uri (e.g. content://com.android.contacts/contacts/lookup/3570i61d948d30808e537) */
- private static final int ID_LOOKUP = 1;
- /** A contact thumbnail uri (e.g. content://com.android.contacts/contacts/38/photo) */
- private static final int ID_THUMBNAIL = 2;
- /** A contact uri (e.g. content://com.android.contacts/contacts/38) */
- private static final int ID_CONTACT = 3;
- /**
- * A contact display photo (high resolution) uri
- * (e.g. content://com.android.contacts/display_photo/5)
- */
- private static final int ID_DISPLAY_PHOTO = 4;
-
- private static final UriMatcher matcher;
-
- static {
- matcher = new UriMatcher(UriMatcher.NO_MATCH);
- matcher.addURI(ContactsContract.AUTHORITY, "contacts/lookup/*/#", ID_LOOKUP);
- matcher.addURI(ContactsContract.AUTHORITY, "contacts/lookup/*", ID_LOOKUP);
- matcher.addURI(ContactsContract.AUTHORITY, "contacts/#/photo", ID_THUMBNAIL);
- matcher.addURI(ContactsContract.AUTHORITY, "contacts/#", ID_CONTACT);
- matcher.addURI(ContactsContract.AUTHORITY, "display_photo/#", ID_DISPLAY_PHOTO);
- }
-
- final Context context;
-
- ContactsPhotoRequestHandler(Context context) {
- this.context = context;
- }
-
- @Override public boolean canHandleRequest(Request data) {
- final Uri uri = data.uri;
- return (SCHEME_CONTENT.equals(uri.getScheme())
- && ContactsContract.Contacts.CONTENT_URI.getHost().equals(uri.getHost())
- && !uri.getPathSegments().contains(ContactsContract.Contacts.Photo.CONTENT_DIRECTORY));
- }
-
- @Override public Result load(Request data) throws IOException {
- InputStream is = null;
- try {
- is = getInputStream(data);
- return new Result(decodeStream(is, data), DISK);
- } finally {
- Utils.closeQuietly(is);
- }
- }
-
- private InputStream getInputStream(Request data) throws IOException {
- ContentResolver contentResolver = context.getContentResolver();
- Uri uri = data.uri;
- switch (matcher.match(uri)) {
- case ID_LOOKUP:
- uri = ContactsContract.Contacts.lookupContact(contentResolver, uri);
- if (uri == null) {
- return null;
- }
- // Resolved the uri to a contact uri, intentionally fall through to process the resolved uri
- case ID_CONTACT:
- if (SDK_INT < ICE_CREAM_SANDWICH) {
- return openContactPhotoInputStream(contentResolver, uri);
- } else {
- return ContactPhotoStreamIcs.get(contentResolver, uri);
- }
- case ID_THUMBNAIL:
- case ID_DISPLAY_PHOTO:
- return contentResolver.openInputStream(uri);
- default:
- throw new IllegalStateException("Invalid uri: " + uri);
- }
- }
-
- private Bitmap decodeStream(InputStream stream, Request data) throws IOException {
- if (stream == null) {
- return null;
- }
- final BitmapFactory.Options options = createBitmapOptions(data);
- if (requiresInSampleSize(options)) {
- InputStream is = getInputStream(data);
- try {
- BitmapFactory.decodeStream(is, null, options);
- } finally {
- Utils.closeQuietly(is);
- }
- calculateInSampleSize(data.targetWidth, data.targetHeight, options, data);
- }
- return BitmapFactory.decodeStream(stream, null, options);
- }
-
- @TargetApi(ICE_CREAM_SANDWICH)
- private static class ContactPhotoStreamIcs {
- static InputStream get(ContentResolver contentResolver, Uri uri) {
- return openContactPhotoInputStream(contentResolver, uri, true);
- }
- }
-}
diff --git a/picasso/src/main/java/com/squareup/picasso/ContentStreamRequestHandler.java b/picasso/src/main/java/com/squareup/picasso/ContentStreamRequestHandler.java
deleted file mode 100644
index 3dd0784bd7..0000000000
--- a/picasso/src/main/java/com/squareup/picasso/ContentStreamRequestHandler.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2013 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.squareup.picasso;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import java.io.IOException;
-import java.io.InputStream;
-
-import static android.content.ContentResolver.SCHEME_CONTENT;
-import static com.squareup.picasso.Picasso.LoadedFrom.DISK;
-
-class ContentStreamRequestHandler extends RequestHandler {
- final Context context;
-
- ContentStreamRequestHandler(Context context) {
- this.context = context;
- }
-
- @Override public boolean canHandleRequest(Request data) {
- return SCHEME_CONTENT.equals(data.uri.getScheme());
- }
-
- @Override public Result load(Request data) throws IOException {
- return new Result(decodeContentStream(data), DISK);
- }
-
- protected Bitmap decodeContentStream(Request data) throws IOException {
- ContentResolver contentResolver = context.getContentResolver();
- final BitmapFactory.Options options = createBitmapOptions(data);
- if (requiresInSampleSize(options)) {
- InputStream is = null;
- try {
- is = contentResolver.openInputStream(data.uri);
- BitmapFactory.decodeStream(is, null, options);
- } finally {
- Utils.closeQuietly(is);
- }
- calculateInSampleSize(data.targetWidth, data.targetHeight, options, data);
- }
- InputStream is = contentResolver.openInputStream(data.uri);
- try {
- return BitmapFactory.decodeStream(is, null, options);
- } finally {
- Utils.closeQuietly(is);
- }
- }
-}
diff --git a/picasso/src/main/java/com/squareup/picasso/DeferredRequestCreator.java b/picasso/src/main/java/com/squareup/picasso/DeferredRequestCreator.java
deleted file mode 100644
index ade526d851..0000000000
--- a/picasso/src/main/java/com/squareup/picasso/DeferredRequestCreator.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2013 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.squareup.picasso;
-
-import android.view.ViewTreeObserver;
-import android.widget.ImageView;
-import java.lang.ref.WeakReference;
-import org.jetbrains.annotations.TestOnly;
-
-class DeferredRequestCreator implements ViewTreeObserver.OnPreDrawListener {
-
- final RequestCreator creator;
- final WeakReference target;
- Callback callback;
-
- @TestOnly DeferredRequestCreator(RequestCreator creator, ImageView target) {
- this(creator, target, null);
- }
-
- DeferredRequestCreator(RequestCreator creator, ImageView target, Callback callback) {
- this.creator = creator;
- this.target = new WeakReference(target);
- this.callback = callback;
- target.getViewTreeObserver().addOnPreDrawListener(this);
- }
-
- @Override public boolean onPreDraw() {
- ImageView target = this.target.get();
- if (target == null) {
- return true;
- }
- ViewTreeObserver vto = target.getViewTreeObserver();
- if (!vto.isAlive()) {
- return true;
- }
-
- int width = target.getWidth();
- int height = target.getHeight();
-
- if (width <= 0 || height <= 0) {
- return true;
- }
-
- vto.removeOnPreDrawListener(this);
-
- this.creator.unfit().resize(width, height).into(target, callback);
- return true;
- }
-
- void cancel() {
- callback = null;
- ImageView target = this.target.get();
- if (target == null) {
- return;
- }
- ViewTreeObserver vto = target.getViewTreeObserver();
- if (!vto.isAlive()) {
- return;
- }
- vto.removeOnPreDrawListener(this);
- }
-}
diff --git a/picasso/src/main/java/com/squareup/picasso/Dispatcher.java b/picasso/src/main/java/com/squareup/picasso/Dispatcher.java
deleted file mode 100644
index 77e5a4a649..0000000000
--- a/picasso/src/main/java/com/squareup/picasso/Dispatcher.java
+++ /dev/null
@@ -1,569 +0,0 @@
-/*
- * Copyright (C) 2013 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.squareup.picasso;
-
-import android.Manifest;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
-import android.os.Message;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-import java.util.concurrent.ExecutorService;
-
-import static android.content.Context.CONNECTIVITY_SERVICE;
-import static android.content.Intent.ACTION_AIRPLANE_MODE_CHANGED;
-import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
-import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
-import static com.squareup.picasso.BitmapHunter.forRequest;
-import static com.squareup.picasso.Utils.OWNER_DISPATCHER;
-import static com.squareup.picasso.Utils.VERB_BATCHED;
-import static com.squareup.picasso.Utils.VERB_CANCELED;
-import static com.squareup.picasso.Utils.VERB_DELIVERED;
-import static com.squareup.picasso.Utils.VERB_ENQUEUED;
-import static com.squareup.picasso.Utils.VERB_IGNORED;
-import static com.squareup.picasso.Utils.VERB_PAUSED;
-import static com.squareup.picasso.Utils.VERB_REPLAYING;
-import static com.squareup.picasso.Utils.VERB_RETRYING;
-import static com.squareup.picasso.Utils.getLogIdsForHunter;
-import static com.squareup.picasso.Utils.getService;
-import static com.squareup.picasso.Utils.hasPermission;
-import static com.squareup.picasso.Utils.log;
-
-class Dispatcher {
- private static final int RETRY_DELAY = 500;
- private static final int AIRPLANE_MODE_ON = 1;
- private static final int AIRPLANE_MODE_OFF = 0;
-
- static final int REQUEST_SUBMIT = 1;
- static final int REQUEST_CANCEL = 2;
- static final int REQUEST_GCED = 3;
- static final int HUNTER_COMPLETE = 4;
- static final int HUNTER_RETRY = 5;
- static final int HUNTER_DECODE_FAILED = 6;
- static final int HUNTER_DELAY_NEXT_BATCH = 7;
- static final int HUNTER_BATCH_COMPLETE = 8;
- static final int NETWORK_STATE_CHANGE = 9;
- static final int AIRPLANE_MODE_CHANGE = 10;
- static final int TAG_PAUSE = 11;
- static final int TAG_RESUME = 12;
- static final int REQUEST_BATCH_RESUME = 13;
-
- private static final String DISPATCHER_THREAD_NAME = "Dispatcher";
- private static final int BATCH_DELAY = 200; // ms
-
- final DispatcherThread dispatcherThread;
- final Context context;
- final ExecutorService service;
- final Downloader downloader;
- final Map hunterMap;
- final Map