Giter VIP home page Giter VIP logo

picasso's Introduction

Picasso

A powerful image downloading and caching library for Android

For more information please see the website

Download

Download the latest AAR from Maven Central or grab via Gradle:

implementation 'com.squareup.picasso:picasso:2.8'

or Maven:

<dependency>
  <groupId>com.squareup.picasso</groupId>
  <artifactId>picasso</artifactId>
  <version>2.8</version>
</dependency>

Snapshots of the development version are available in Sonatype's snapshots repository.

Picasso requires at minimum Java 8 and API 21.

ProGuard

If you are using ProGuard you might need to add OkHttp's rules: https://github.com/square/okhttp/#r8--proguard

License

Copyright 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

   https://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.

picasso's People

Contributors

afollestad avatar aldenml avatar amilcar-andrade avatar chris-horner avatar dependabot[bot] avatar dlew avatar dnkoutso avatar drbild avatar eveliotc avatar f2prateek avatar gamepro65 avatar grohden avatar isira-seneviratne avatar jakewharton avatar jaredsburrows avatar jayh5 avatar johnwowus avatar jonan avatar jrodbx avatar lexs avatar lucasr avatar luis-cortes avatar nightlynexus avatar nsk-mironov avatar pforhan avatar pyricau avatar renovate[bot] avatar rjrjr avatar swankjesse avatar zacsweers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

picasso's Issues

NullPointerException in Stats.cacheMiss method

Nexus S, Android 4.1.2.

java.lang.NullPointerException
    at com.squareup.picasso.Stats.cacheMiss(Stats.java:54)
    at com.squareup.picasso.Picasso.resolveRequest(Picasso.java:186)
    at com.squareup.picasso.Picasso.run(Picasso.java:169)
    at com.squareup.picasso.Request.run(Request.java:108)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    at java.lang.Thread.run(Thread.java:856)

Remove `.fit()`, Introduce ImageView Subclass

Move to a custom ImageView subclass like we've traditionally done for things like Thumbor+Pollexor fetching. This would eliminate .fit() and defer all transformation until after the view has been measured.

This actually will be much faster than the aforementioned technique for Thumbor since the slow part of the image load, the HTTP request, can be performed immediately and retained for when the view has measured. Presumably this will always have happened when we hit the network and it'll be very close when we're pulling from the disk cache. The memory cache happens on the main thread so we'll be able to load the image instantly since the first draw pass won't have happened yet.

Loading contact photos from lookup URI not included

The Utils class has the method getContactPhotoStream(...), but apparently, this feature is not really built into Picasso yet, is it?

Picasso class should have a load(..) method that takes a lookup URI so that you can easily load a contact photo.

Or am I missing something?

PicassoDrawable cannot be cast to BitmapDrawable

onDraw() in my CustomImageView

Drawable drawable = getDrawable();
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();

java.lang.ClassCastException: com.squareup.picasso.PicassoDrawable cannot be cast to android.graphics.drawable.BitmapDrawable

Weird image size

I have integrated Picasso right now instead of my Android-Bimap implementation and i'm getting weird behaviour with the image size in a listView adapter.

I'm calling Picasso this way: Picasso.with(context).load(url).error(R.drawable.error_photo).into(imageDrawable);

weird_1

weird_2

Alpha on ImageView drawable support

I currently use

ImageView.setImageAlpha();

to make the Drawable of an ImageView transparent.

With Picasso the image will always be reset to be opaque. I looked at using a Transformation, but that works directly on Bitmaps.

Any advice or thoughts?

Caching images

is there an option to cache the images on "external storage" ?

Expose a way to grab images only from the local cache

In certain situations it is very useful to look only in the local cache, such as rendering widgets where the time constraints for returning a view make it impractical to wait for the HTTP call to complete.

Something like this diff below seems like it ought to work. If it looks okay, I can make a proper PR out of it with unit tests and such.

diff --git a/picasso/src/main/java/com/squareup/picasso/Picasso.java b/picasso/src/main/java/com/squareup/picasso/Picasso.java
index a4093c1..49a2d6d 100644
--- a/picasso/src/main/java/com/squareup/picasso/Picasso.java
+++ b/picasso/src/main/java/com/squareup/picasso/Picasso.java
@@ -349,7 +349,7 @@ public class Picasso {
       } else {
         Response response = null;
         try {
-          response = loader.load(uri, request.retryCount == 0);
+          response = loader.load(uri, request.retryCount == 0 || request.cacheOnly);
           if (response == null) {
             return null;
           }
diff --git a/picasso/src/main/java/com/squareup/picasso/Request.java b/picasso/src/main/java/com/squareup/picasso/Request.java
index ff89870..a11cc21 100644
--- a/picasso/src/main/java/com/squareup/picasso/Request.java
+++ b/picasso/src/main/java/com/squareup/picasso/Request.java
@@ -34,6 +34,7 @@ class Request implements Runnable {
   final PicassoBitmapOptions options;
   final List<Transformation> transformations;
   final boolean skipCache;
+  final boolean cacheOnly;
   final boolean noFade;
   final int errorResId;
   final Drawable errorDrawable;
@@ -46,7 +47,7 @@ class Request implements Runnable {
   boolean retryCancelled;

   Request(Picasso picasso, Uri uri, int resourceId, ImageView imageView,
-      PicassoBitmapOptions options, List<Transformation> transformations, boolean skipCache,
+      PicassoBitmapOptions options, List<Transformation> transformations, boolean skipCache, boolean cacheOnly,
       boolean noFade, int errorResId, Drawable errorDrawable) {
     this.picasso = picasso;
     this.uri = uri;
@@ -55,6 +56,7 @@ class Request implements Runnable {
     this.options = options;
     this.transformations = transformations;
     this.skipCache = skipCache;
+    this.cacheOnly = cacheOnly;
     this.noFade = noFade;
     this.errorResId = errorResId;
     this.errorDrawable = errorDrawable;
diff --git a/picasso/src/main/java/com/squareup/picasso/RequestBuilder.java b/picasso/src/main/java/com/squareup/picasso/RequestBuilder.java
index 74562c1..541f9c7 100644
--- a/picasso/src/main/java/com/squareup/picasso/RequestBuilder.java
+++ b/picasso/src/main/java/com/squareup/picasso/RequestBuilder.java
@@ -24,6 +24,7 @@ public class RequestBuilder {
   PicassoBitmapOptions options;
   private List<Transformation> transformations;
   private boolean skipCache;
+  private boolean cacheOnly;
   private boolean noFade;
   private boolean hasNullPlaceholder;
   private int placeholderResId;
@@ -123,6 +124,16 @@ public class RequestBuilder {
     return this;
   }

+  public RequestBuilder cacheOnly() {
+      if (this.skipCache) {
+          throw new IllegalStateException("Cannot specify cache only with skip cache.");
+      }
+
+      this.cacheOnly = true;
+
+      return this;
+  }
+
   /** Resize the image to the specified dimension size. */
   public RequestBuilder resizeDimen(int targetWidthResId, int targetHeightResId) {
     Resources resources = picasso.context.getResources();
@@ -277,7 +288,7 @@ public class RequestBuilder {
   public Bitmap get() throws IOException {
     checkNotMain();
     Request request =
-        new Request(picasso, uri, resourceId, null, options, transformations, skipCache, false, 0,
+        new Request(picasso, uri, resourceId, null, options, transformations, skipCache, cacheOnly, false, 0,
             null);
     return picasso.resolveRequest(request);
   }
@@ -328,7 +339,7 @@ public class RequestBuilder {
     }

     Request request =
-        new Request(picasso, uri, resourceId, target, options, transformations, skipCache, noFade,
+        new Request(picasso, uri, resourceId, target, options, transformations, skipCache, cacheOnly, noFade,
             errorResId, errorDrawable);
     picasso.submit(request);
   }

Debugging not working?

I just started using Picasso. It works like magic, saved me a lot of work.
But I'm trying to enable the debugging feature shown in the website, but it seems to do nothing. I don't know if I'm doing something wrong or it just doesn't work, I can't find any sample with debugging enabled.

My code looks something like this:

Picasso pic = Picasso.with(getActivity());
pic.setDebugging(true);
pic.load(foto).into(imageview);

Am I doing something wrong or it's a bug?

WeakReference on Target

Hi.

I had a strange-not-always-appearing bug.
Finally, I found it was because of using WeakReference on
public void into(Target target) {
makeTargetRequest(target, false);
}

I was using this method with an inner class. Something like
.load(xx).into(new Target() {
});

And as Picasso doesn't keep references on it, it was sometimes garbage collected before the image is downloaded.

Having a weakreference on an ImageView make sense but on a Target, I'm not sure.
It needs more work from the developper to keep a strong reference somewhere else to a target object he doesn't really care about.
I'm not afraid Piasso keeps a strong reference on this object until the request is done and the callback called.

Mike

Custom downloader

I've been using URLImageViewHelper to download and load images into ImageViews. I've been moving most of my usage of that library across to Picasso due to its ease of use, especially resizing images.

The only feature I feel Picasso is missing is an easy way to override the downloading of images. Some of the image I am downloading for my application are coming from a secure server that requires me to send a JSON object with log in credentials. It would be great to be able to either override the downloading or give Picasso some params to send with its request for the image.

Is there any plans for a future improvement that will allow for this kind of functionality?

Images do not center crop consistently

The images in the GridView below should center crop, though sometimes they squish to fit their container. This does not happen consistently.

Force closing and clearing the cache for the app then opening it yields the result below:

screenshot_2013-06-02-18-46-11

Whereas, resuming the app causes the images to center crop correctly:

screenshot_2013-06-02-18-46-41

//GridItem.xml
...
<ImageView
    android:id="@+id/mapImageStarredGrid"
    android:layout_width="match_parent"
    android:layout_height="175dp"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop" />
...

//Grid Adapter bindView()
...
Picasso.with(context)
  .load(request)
  .placeholder(R.color.super_light_grey)
  .error(R.color.light_grey)
  .into(holder.map);
...

JAR 1.0.2, on a N4.

Wrong Value for Thread.setPriority(...)

Thread.setPriority(int) doesn't work properly with the Process.THREAD_PRIORITY_BACKGROUND value.

You need to use Process.setThreadPriority(...) instead (or Thread.MIN_PRIORITY, but I'd recommend using Process).

Cannot set alpha or colorfilter

I'm setting a colorfilter for an ImageView using setColorFilter(filter), but it didn't seem to have any effect. Digging through the code, I noticed that the underlying PicassoDrawable has a no-op for setAlpha and setColorFilter. Does this cause any colorfilter/alpha set by the ImageView to not work?

 @Override public void setAlpha(int alpha) {
    // No-op
  }

  @Override public void setColorFilter(ColorFilter cf) {
    // No-op
  }

OutOfMemoryError with ViewPager

I noticed in an application I'm currently working on that your library together with a ViewPager gives an OutOfMemoryError when you rotate the screen several times and doing some swipes in between. When examing logcat, I noticed the heap allocation slowly increasing every time I rotated. Setting android:configchanges in the manifest to "orientation|screensize" seems to fix the problem, but I thought I would share my findings anyway. To isolate the issue, I made a small test project: https://github.com/AlexKolpa/PicassoTest. Hopefully that helps.

Use InSampleSize with Disk Cache

When a disk cache is installed, it's safe to use inSampleSize to decode a bitmap twice because the second hit will be from the disk cache. The first call will download it into the cache and read the size and the second call will read from the cache and decode the full bitmap.

Prioritization of fetches

I want to be able to warm the disk cache with a prefetch service, but fetches from this service should have a lower priority than on-demand fetches such as into an ImageView.

I believe this can be accomplished easily by adding RequestBuilder.lowpriority(boolean) and making Request comparable on this flag. The user would then be able to respect this flag by using a PriorityBlockingQueue<Runnable> in their ExecutorService.

If this sounds reasonable, I'm willing to add the improvement and file a pull request.

.centercrop should work with .fit

It would be nice if .centerCrop() worked with .fit(). For performance I want to resize the images to the size of the imageview, but I need to maintain aspect ratio.

Picasso Sample has stopped

Imported de sample project but when run in device or emulator it never starts. Black screen until death.

Random java.lang.RuntimeException

I am sometimes getting a RuntimeException, making my application crash. It seems the source of the problem is a NPE in Stats.cacheMiss.

I have seen this happening on my devices running respectively Android 4.1 and Android 4.2.2. It seems to happen randomly which I know isn't going to help debugging. After the application restarts everything works perfectly again.

Here's the full stack trace:

05-17 13:32:03.824  24618-24618/fr.utc.assos.uvweb             E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.RuntimeException: An unexpected exception occurred
        at com.squareup.picasso.Request$1.run(Request.java:114)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.NullPointerException
        at com.squareup.picasso.Stats.cacheMiss(Stats.java:54)
        at com.squareup.picasso.Picasso.resolveRequest(Picasso.java:186)
        at com.squareup.picasso.Picasso.run(Picasso.java:169)
        at com.squareup.picasso.Request.run(Request.java:108)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)

If there's anything I can do to help, please let me know!

Decode lock: picasso vs volley

I noticed that picasso is using "decode_lock" to prevent OOM (like the volley).
Volley is locking only a bitmap decoding. But picasso is locking both streaming and decoding of bitmap through BitmapFactory.decodeStream(). This can result in ineffective use of thread pool.

Volley:
synchronized (sDecodeLock) {
//...
return doParse(response);
//...
}

private Response doParse(NetworkResponse response) {
//...
byte[] data = response.data; // <- already downloaded data
//...
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
}

Picasso:
synchronized (DECODE_LOCK) {
return BitmapFactory.decodeStream(stream, null, bitmapOptions);
}

Image prefetch

Hi.

A suggestion : Maybe an option for pre-fetching images could be useful.
(so it would be for me :) )
It is actually possible with something like
public void prefetch(Context c, String url) {
Picasso.with(c).load(url).into(new Target() {
@OverRide public void onSuccess(Bitmap bitmap) {}
@OverRide public void onError() {}
});
}

but
Picasso.with(c).prefetch(url) would be more simple.

Also, if I'm not wrong, load(uti) doesnt not effectively start any loading.
May be it might be explained in the javadoc.

Getting out of memory error when using it on gridview

This is what i get after a couple of minutes playing with the gridview, the images are 612x612, getting this on nexus 7

05-22 12:06:48.297: E/AndroidRuntime(12339): Caused by: java.lang.OutOfMemoryError
05-22 12:06:48.297: E/AndroidRuntime(12339): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-22 12:06:48.297: E/AndroidRuntime(12339): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:529)
05-22 12:06:48.297: E/AndroidRuntime(12339): at com.squareup.picasso.Picasso.decodeStream(Picasso.java:224)
05-22 12:06:48.297: E/AndroidRuntime(12339): at com.squareup.picasso.Picasso.loadFromType(Picasso.java:310)
05-22 12:06:48.297: E/AndroidRuntime(12339): at com.squareup.picasso.Picasso.resolveRequest(Picasso.java:187)
05-22 12:06:48.297: E/AndroidRuntime(12339): at com.squareup.picasso.Picasso.run(Picasso.java:169)
05-22 12:06:48.297: E/AndroidRuntime(12339): at com.squareup.picasso.Request.run(Request.java:108)
05-22 12:06:48.297: E/AndroidRuntime(12339): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
05-22 12:06:48.297: E/AndroidRuntime(12339): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-22 12:06:48.297: E/AndroidRuntime(12339): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-22 12:06:48.297: E/AndroidRuntime(12339): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-22 12:06:48.297: E/AndroidRuntime(12339): at java.lang.Thread.run(Thread.java:856)
05-22 12:06:48.297: E/AndroidRuntime(12339): at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:198)

Support for FILO based downloading instead of FIFO based downloading

It would be nice if download order could be reversed. "Stack" based downloading instead of "Queue" based downloading. Usually the last requested image is the one on the screen. This seems like a smarter default behavior.

Imagine you are implementing a gallery of 1000 images and have a slow connection. When the user scrolls to the bottom and stops he will not see his image on screen for a very long time. He must wait for all images above to download before the images on his screen load.

I believe this could be added using PriorityBlockingQueue with a Comparator.

Use inSampleSize with streamed content

Currently streamed content is resized on the fly after initial decoding, this can cause memory spikes because of the extra memory allocation.

In a perfect world all images would be the correct size you need when downloaded but in a real world environment without server resizing this would cause picasso to choke on large images being resized to smaller image slots.

Support loading into background of any view

Add overload of into() that accepts any View and sets the background drawable. I'll submit a patch if I have time.

(This can be done with a custom Target right now, but you lose the convenience of just letting Picasso hold a weak reference to the view.)

Getting out of memory when loading a very large image

OOM occurs when the image being loaded is quite large (4000x3000). Or am I using wrong syntax for such case? Here's the code that caused OOM immediately.

String path = "http://upload.wikimedia.org/wikipedia/commons/3/30/E-2K_in_Songshan_Air_Force_Base_20110813.jpg";
ImageView imageView = (ImageView) findViewById(R.id.image);
Picasso.with(getApplicationContext()).load(path).resize(50, 50)
                .into(imageView);

Placeholders do not load in GridView/ListView

Placeholders are not loading when the following code is used to load an image within the getView(...) method of an AdapterView:

Picasso.with(mContext).load(url).placeholder(placeholder).error(placeholder).into(holder.thumbnail);

It seems that the images eventually load but it takes much longer to load compared to using the code above without the ".placeholder(placeholder)".

Add logging behind the setDebugging flag?

Logging behind the setDebugging flag would be very useful. Some things that would be nice to log:

  • when http requests start and finish
  • when http requests are canceled because view not on screen
  • when cache hit / miss

JakeWharton Suggested I add this issue:
#63

Should retry requests that failed when network goes online

Scenario:

  • Watching a listview with 5 rows each with an image
  • Phone is airplane mode or offline due to no reception
  • Picasso tries to load 5 images and fails (including retries)
  • Network goes up
  • Images should re-load, requests should be replayed.

Support Disk Cache Warming

fetch() with no callback coupled with skipCache(). Should not do any bitmap decoding and it should abandon the hold on the connection as soon as possible.

Image download callback

Hi,

Can I register a callback method on each into request so that I can do custom stuff after the image has downloaded ?

For eg: hide the progress bar, show custom notifications etc.

It would be really helpful.

ImageViews with different image sizes in adapter lead to wrong scaling

I have a GridView which has items containing simple image views. ImageViews are fixed size and content comes from web and can be any size so the idea is to use centerInside(). My adapter tries to reuse views, but seems like this leads to some weird resizing problems inside Picasso. Notice how the first image changes its size after its view has been reused after hosting some smaller image (see screenshot).

I checked in HierarchyViewer - ImageView itself stays the same measured size: 112dp x 60dp, but image inside gets scaled wrongly. This happens to a lot of items in process of the scrolling.

I tried both picasso-1.0.2 + picasso-master (here I also tried to .resize(112,60).centerInside()) - but nothing fixed this issue.

Any hints or workarounds? :)

screen

Layout snippet:

    <ImageView
        android:id="@+id/factory_item_image"
        android:layout_width="112dp"
        android:layout_height="60dp"
        android:layout_gravity="center_horizontal"
        />

Extract from getView():

        ImageView imageView = (ImageView) view.findViewById(R.id.factory_item_image);
        Picasso.with(context)
        .load(items[position].getImageData().url)
        .into(imageView);

OutOfMemory

I receive those out of memory that makes the application crash.
I think I prefer to did not have the image :) ...
I don't think I can do anything because it is an error on picasso thread.
Just adding a try/catch would be enough or is it a more general memory handling problem ?

E/dalvikvm-heap(18972): 1048576-byte external allocation too large for this process.
E/GraphicsJNI(18972): VM won't let us allocate 1048576 bytes
E/AndroidRuntime(18972): FATAL EXCEPTION: main
E/AndroidRuntime(18972): java.lang.RuntimeException: An unexpected exception occurred
E/AndroidRuntime(18972): at com.squareup.picasso.Request$1.run(Request.java:114)
E/AndroidRuntime(18972): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(18972): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(18972): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(18972): at android.app.ActivityThread.main(ActivityThread.java:3687)
E/AndroidRuntime(18972): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(18972): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(18972): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
E/AndroidRuntime(18972): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
E/AndroidRuntime(18972): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(18972): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime(18972): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
E/AndroidRuntime(18972): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:573)
E/AndroidRuntime(18972): at com.squareup.picasso.Picasso.decodeStream(Picasso.java:260)
E/AndroidRuntime(18972): at com.squareup.picasso.Picasso.loadFromType(Picasso.java:346)
E/AndroidRuntime(18972): at com.squareup.picasso.Picasso.resolveRequest(Picasso.java:215)
E/AndroidRuntime(18972): at com.squareup.picasso.Picasso.run(Picasso.java:197)
E/AndroidRuntime(18972): at com.squareup.picasso.Request.run(Request.java:108)
E/AndroidRuntime(18972): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:444)
E/AndroidRuntime(18972): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
E/AndroidRuntime(18972): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
E/AndroidRuntime(18972): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
E/AndroidRuntime(18972): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
E/AndroidRuntime(18972): at java.lang.Thread.run(Thread.java:1019)
E/AndroidRuntime(18972): at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:244)

downloading images with basic authentication

I can't figure out how to download images from a server with basic authentication.
i tried to extend the UrlConnectionLoader

@Override
    protected HttpURLConnection openConnection(String path) throws IOException {
        HttpURLConnection c = (HttpURLConnection)  new URL(path).openConnection();
        c.setRequestProperty("Authorization", "Basic " +
                Base64.encodeToString("user:pass".getBytes(), Base64.NO_WRAP));
        return c;
    }
....
new Picasso.Builder(context).loader(new MyPicassoLoader(context).build();

but that doesn't work.

Animators/Animation when image is loaded

Great library, very promising!
What would be picassos take on having animations to signal when a image is loaded?
For example, in a custom RemoteImageView implementation I used to have such code:

target.mNotAvailableView.setVisibility(GONE);
com.nineoldandroids.view.ViewPropertyAnimator.animate(target.mProgressView)
    .alpha(0.0f).setDuration(500).start();
if (bitmap == null) {
    target.mNotAvailableView.setVisibility(VISIBLE);
} else {
    com.nineoldandroids.view.ViewPropertyAnimator.animate(target.mImageView)
        .rotationY(-90).alpha(0.5f).setDuration(250)
        .setListener(new DefaultAnimatorListener() {
            @Override
            public void onAnimationEnd(Animator animator) {
                target.mImageView.setImageBitmap(bitmap);
                if (target.mImageLoadListener != null) {
                    target.mImageLoadListener.onRemoteImageLoadComplete();
                }

                com.nineoldandroids.view.ViewPropertyAnimator
                    .animate(target.mImageView).rotationY(0)
                    .alpha(1.0f).setDuration(250).setListener(null)
                    .start();
            }
        }).start();

I'm keen to see how picasso could handle something similar.

RuntimeException in Samsung Galaxy Tab

Exception in Samsung Galaxy Tab (wrong version number check?):

java.lang.RuntimeException
com.squareup.picasso.Request$1.run(Request.java:114)
android.os.Handler.handleCallback(Handler.java:587)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:132)
android.app.ActivityThread.main(ActivityThread.java:4126)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:491)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
dalvik.system.NativeStart.main(Native Method)
Caused by: com.squareup.picasso.UrlConnectionLoader$ResponseCacheHoneycombMR2.install(UrlConnectionLoader.java:68)
com.squareup.picasso.UrlConnectionLoader.installCacheIfNeeded(UrlConnectionLoader.java:57)
com.squareup.picasso.UrlConnectionLoader.load(UrlConnectionLoader.java:37)
com.squareup.picasso.Picasso.loadFromType(Picasso.java:306)
com.squareup.picasso.Picasso.resolveRequest(Picasso.java:187)
com.squareup.picasso.Picasso.run(Picasso.java:169)
com.squareup.picasso.Request.run(Request.java:108)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
java.util.concurrent.FutureTask.run(FutureTask.java:137)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
java.lang.Thread.run(Thread.java:1020)
com.squareup.picasso.Utils$PicassoThread.run(Utils.java:198)

onSuccess() not invoked when loading image into Target interface from net.

In case using load(url).into(target) method onSuccess(Bitmap bm) is not invoked. After rotating display is method invoked properly (loading from cache?). Also loading drawable works right.

Below is activity code showing problem:

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;

public class MainActivity extends Activity {

    private Picasso mPicasso;

    private TextView mTextView;
    private ImageView mImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mPicasso = Picasso.with(this);
        mPicasso.setDebugging(true);

        mTextView = (TextView) findViewById(R.id.textView1);
        mImageView = (ImageView) findViewById(R.id.imageView1);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        final String imageStr = "http://www.seznam.cz/st/img/2011//logo.png?3.33.2";

        //+works properly
        //mPicasso.load(fileStr).into(mImageView); 

        //+works properly
        //mPicasso.load(R.drawable.ic_launcher).into(new TargetImpl(mImageView, mTextView));

        //-onSuccess not invoked
        /*mPicasso.load(fileStr).into(new Target() {
            @Override
            public void onSuccess(Bitmap bm) {
                mImageView.setImageBitmap(bm);
                mTextView.setText("succ");
            }

            @Override
            public void onError() {
                mTextView.setText("err");
            }
        });*/

        //-onSuccess not invoked
        mPicasso.load(imageStr).into(new TargetImpl(mImageView, mTextView));
    }

    private static final class TargetImpl implements Target {
        private static final String TAG = TargetImpl.class.getSimpleName();

        private ImageView mImageView;
        private TextView mTextView;

        public TargetImpl(ImageView imageView, TextView targetView) {
            mImageView = imageView;
            mTextView = targetView;
        }

        @Override
        public void onSuccess(Bitmap bm) {
            mImageView.setImageBitmap(bm);
            mTextView.setText(TAG + ": onSuccess");
        }

        @Override
        public void onError() {
            mTextView.setText(TAG + ": onError");
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((mImageView == null) ? 0 : mImageView.hashCode());
            result = prime * result + ((mTextView == null) ? 0 : mTextView.hashCode());
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            TargetImpl other = (TargetImpl) obj;
            if (mImageView == null) {
                if (other.mImageView != null)
                    return false;
            } else if (!mImageView.equals(other.mImageView))
                return false;
            if (mTextView == null) {
                if (other.mTextView != null)
                    return false;
            } else if (!mTextView.equals(other.mTextView))
                return false;
            return true;
        }
    }
}

Am I missing something, is it a bug? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.