2 Ekim 2017 Pazartesi

Picasso Sınıfı

Giriş
Picasso sunucudan resim indirmek için kullanılır. Bu kütüphanenin başka bir alternatifi Glide kütüphanesi. Farklarının açıklaması şöyle
Picasso downloads the image and stores the full-size image (in my case the image resolution was 1160*750) in the cache and whenever we ask for the same image, it will return the full-size image and resize them to fit into the ImageView in real time.
On the other hand, Glide works differently. Glide downloads the image from the given URL, resize it to the size of the image view and stores it to the disk cache.
Picasso.Builder Sınıfı
downloader metodu
Kendi downloader sınıfımız tanımlamak için şöyle yaparız.
public class DropBoxThumbDowloader implements Downloader {


  @Override
  public Response load(Uri uri, boolean localCacheOnly) throws IOException {
    InputStream in = ...;
    return new Response(in, false, -1);
  }
}
Şöyle yaparız.
Picasso pi = new  Picasso.Builder(context.getApplicationContext())
  .downloader(new DropBoxThumbDowloader(dropBoxInteractor)).build();

Picasso Sınıfı
Daha detaylı açıklama burada
cancelRequest metodu
Şöyle yaparız.
ImageView imageView = ...;
p.cancelRequest (imageView);
into metodu
Şöyle yaparız.
Picasso.with(this).load("YOUR IMAGE URL HERE").into(imageView);
into metodu - Target
Şöyle yaparız.
Bitmap bitmapImage = null;
Picasso.with(context)
  .load(url)
  .into(new Target() {
    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
      ...
    }

    @Override
    public void onBitmapFailed(Drawable errorDrawable) {
      ...
    }

    @Override
    public void onPrepareLoad(Drawable placeHolderDrawable) {
      ...
    }
});
load metodu
Şöyle yaparız.
String photoUrl1 = ...;
Picasso r = p.load (photoUrl);
memoryPolicy metodu
Şöyle yaparız.
ImageView imageView = ...;
Picasso.with(MyActivity.this).load(photoUrl).memoryPolicy(MemoryPolicy.NO_CACHE)
  .networkPolicy(NetworkPolicy.NO_CACHE).resize(width, 0).into(imageView);
placeholder metoud
Şöyle yaparız.
Picasso.with(context)
  .load(url)
  .placeholder(R.drawable.user_placeholder)
  .error(R.drawable.user_placeholder_error)
  .into(imageView);
with metodu
Şöyle yaparız.
Picasso p = Picasso.with (context);

Hiç yorum yok:

Yorum Gönder