Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.koushikdutta.ion;
  
  import  android.graphics.Bitmap;
  import  android.graphics.drawable.BitmapDrawable;
  import  android.graphics.drawable.Drawable;
  import  android.os.Looper;
  import  android.view.ViewGroup;
  import  android.view.animation.Animation;
  import  android.widget.ImageView;
 
Created by koush on 7/4/14.
 
         {
             setComplete(new NullPointerException("uri"));
         }
     };
 
     Drawable placeholderDrawable;
     int placeholderResource;
     Drawable errorDrawable;
     int errorResource;
     Animation inAnimation;
     Animation loadAnimation;
     int loadAnimationResource;
     int inAnimationResource;
 
     public IonImageViewRequestBuilder(IonRequestBuilder builder) {
         super(builder);
     }
 
     public IonImageViewRequestBuilder(Ion ion) {
         super(ion);
     }
 
     @Override
     void reset() {
         super.reset();
          = null;
          = null;
          = 0;
          = null;
          = 0;
          = null;
          = 0;
          = null;
          = 0;
     }
 
     @Override
     protected IonRequestBuilder ensureBuilder() {
         if ( == null)
              = new IonRequestBuilder(ContextReference.fromContext(.getContext().getApplicationContext()), );
         return ;
     }
 
     @Override
     public ImageViewFuture load(String uri) {
         ensureBuilder();
         .load(uri);
         return intoImageView(.get());
     }
 
     @Override
     public Future<ImageView> load(String methodString url) {
         ensureBuilder();
         .load(methodurl);
         return intoImageView(.get());
     }
 
     IonImageViewRequestBuilder withImageView(ImageView imageView) {
          = new ContextReference.ImageViewContextReference(imageView);
         return this;
     }
 
     private IonDrawable setIonDrawable(ImageView imageViewBitmapInfo infoint loadedFrom) {
         IonDrawable ret = IonDrawable.getOrCreateIonDrawable(imageView)
         .ion()
         .setBitmap(infoloadedFrom)
         .setSize()
         .setError()
         .setPlaceholder()
         .setInAnimation()
         .setDisableFadeIn();
         imageView.setImageDrawable(ret);
         return ret;
     }
 
     @Override
     public ImageViewFuture intoImageView(ImageView imageView) {
        assert Thread.currentThread() == Looper.getMainLooper().getThread();
        if (imageView == null)
            throw new NullPointerException("imageView");
        // no uri? just set a placeholder and bail
        if (. == null) {
            setIonDrawable(imageViewnull, 0).cancel();
            return ;
        }
        withImageView(imageView);
        // executeCache the request, see if we get a bitmap from cache.
        BitmapFetcher bitmapFetcher = executeCache();
        if (bitmapFetcher.info != null) {
            doAnimation(imageViewnull, 0);
            IonDrawable drawable = setIonDrawable(imageViewbitmapFetcher.info..);
            drawable.cancel();
            IonDrawable.ImageViewFutureImpl imageViewFuture = drawable.getFuture();
            imageViewFuture.reset();
            imageViewFuture.setComplete(bitmapFetcher.info.exceptionimageView);
            return imageViewFuture;
        }
        IonDrawable drawable = setIonDrawable(imageViewnull, 0);
        doAnimation(imageView);
        IonDrawable.ImageViewFutureImpl imageViewFuture = drawable.getFuture();
        imageViewFuture.reset();
        drawable.register(bitmapFetcher.bitmapKey);
        // nothing from cache, check to see if there's too many imageview loads
        // already in progress
        if (BitmapFetcher.shouldDeferImageView()) {
            bitmapFetcher.defer();
        }
        else {
            bitmapFetcher.execute();
        }
        return imageViewFuture;
    }
    private Drawable getImageViewDrawable() {
        ImageView iv = .get();
        if (iv == null)
            return null;
        return iv.getDrawable();
    }
    @Override
    public Bitmap getBitmap() {
        Drawable d = getImageViewDrawable();
        if (d == null)
            return null;
        if (d instanceof BitmapDrawable)
            return ((BitmapDrawable)d).getBitmap();
        if (!(d instanceof IonDrawable))
            return null;
        IonDrawable id = (IonDrawable)d;
        d = id.getCurrentDrawable();
        if (d instanceof BitmapDrawable)
            return ((BitmapDrawable)d).getBitmap();
        return null;
    }
    @Override
    public BitmapInfo getBitmapInfo() {
        Drawable d = getImageViewDrawable();
        if (d == null)
            return null;
        if (!(d instanceof IonDrawable))
            return null;
        IonDrawable id = (IonDrawable)d;
        return id.getBitmapInfo();
    }
    @Override
        ImageView iv = .get();
        Drawable drawable = iv.getDrawable();
        if (drawable instanceof IonDrawable) {
            IonDrawable ionDrawable = (IonDrawable)drawable;
            drawable = ionDrawable.getCurrentDrawable();
        }
        return placeholder(drawable);
    }
    @Override
    protected void finalizeResize() {
        if ( > 0 &&  > 0)
            return;
        ImageView iv = .get();
        ViewGroup.LayoutParams lp = iv.getLayoutParams();
        if (lp == null)
            return;
        if ( <= 0 && lp.width > 0)
             = lp.width;
        if ( <= 0 && lp.height > 0)
             = lp.height;
    }
    @Override
    public IonImageViewRequestBuilder placeholder(Drawable drawable) {
         = drawable;
        return this;
    }
    @Override
    public IonImageViewRequestBuilder placeholder(int resourceId) {
         = resourceId;
        return this;
    }
    @Override
    public IonImageViewRequestBuilder error(Drawable drawable) {
         = drawable;
        return this;
    }
    @Override
    public IonImageViewRequestBuilder error(int resourceId) {
         = resourceId;
        return this;
    }
    @Override
    public IonImageViewRequestBuilder animateIn(Animation in) {
         = in;
        return this;
    }
    @Override
    public IonImageViewRequestBuilder animateLoad(Animation load) {
         = load;
        return this;
    }
    @Override
    public IonImageViewRequestBuilder animateLoad(int animationResource) {
         = animationResource;
        return this;
    }
    @Override
    public IonImageViewRequestBuilder animateIn(int animationResource) {
         = animationResource;
        return this;
    }
New to GrepCode? Check out our FAQ X