1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/com/squareup/picasso/Downloader.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* 1.5 + * Copyright (C) 2013 Square, Inc. 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 +package com.squareup.picasso; 1.20 + 1.21 +import android.graphics.Bitmap; 1.22 +import android.net.Uri; 1.23 +import java.io.IOException; 1.24 +import java.io.InputStream; 1.25 + 1.26 +/** A mechanism to load images from external resources such as a disk cache and/or the internet. */ 1.27 +public interface Downloader { 1.28 + /** 1.29 + * Download the specified image {@code url} from the internet. 1.30 + * 1.31 + * @param uri Remote image URL. 1.32 + * @param localCacheOnly If {@code true} the URL should only be loaded if available in a local 1.33 + * disk cache. 1.34 + * @return {@link Response} containing either a {@link Bitmap} representation of the request or an 1.35 + * {@link InputStream} for the image data. {@code null} can be returned to indicate a problem 1.36 + * loading the bitmap. 1.37 + * @throws IOException if the requested URL cannot successfully be loaded. 1.38 + */ 1.39 + Response load(Uri uri, boolean localCacheOnly) throws IOException; 1.40 + 1.41 + /** Thrown for non-2XX responses. */ 1.42 + class ResponseException extends IOException { 1.43 + public ResponseException(String message) { 1.44 + super(message); 1.45 + } 1.46 + } 1.47 + 1.48 + /** Response stream or bitmap and info. */ 1.49 + class Response { 1.50 + final InputStream stream; 1.51 + final Bitmap bitmap; 1.52 + final boolean cached; 1.53 + 1.54 + /** 1.55 + * Response image and info. 1.56 + * 1.57 + * @param bitmap Image. 1.58 + * @param loadedFromCache {@code true} if the source of the image is from a local disk cache. 1.59 + */ 1.60 + public Response(Bitmap bitmap, boolean loadedFromCache) { 1.61 + if (bitmap == null) { 1.62 + throw new IllegalArgumentException("Bitmap may not be null."); 1.63 + } 1.64 + this.stream = null; 1.65 + this.bitmap = bitmap; 1.66 + this.cached = loadedFromCache; 1.67 + } 1.68 + 1.69 + /** 1.70 + * Response stream and info. 1.71 + * 1.72 + * @param stream Image data stream. 1.73 + * @param loadedFromCache {@code true} if the source of the stream is from a local disk cache. 1.74 + */ 1.75 + public Response(InputStream stream, boolean loadedFromCache) { 1.76 + if (stream == null) { 1.77 + throw new IllegalArgumentException("Stream may not be null."); 1.78 + } 1.79 + this.stream = stream; 1.80 + this.bitmap = null; 1.81 + this.cached = loadedFromCache; 1.82 + } 1.83 + 1.84 + /** 1.85 + * Input stream containing image data. 1.86 + * <p> 1.87 + * If this returns {@code null}, image data will be available via {@link #getBitmap()}. 1.88 + */ 1.89 + public InputStream getInputStream() { 1.90 + return stream; 1.91 + } 1.92 + 1.93 + /** 1.94 + * Bitmap representing the image. 1.95 + * <p> 1.96 + * If this returns {@code null}, image data will be available via {@link #getInputStream()}. 1.97 + */ 1.98 + public Bitmap getBitmap() { 1.99 + return bitmap; 1.100 + } 1.101 + } 1.102 +}