Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.koushikdutta.ion;
  
  import  android.annotation.TargetApi;
  import  android.graphics.Bitmap;
  import  android.graphics.drawable.BitmapDrawable;
  import  android.graphics.drawable.Drawable;
  import  android.os.Build;
  import  android.os.Looper;
  import  android.view.animation.Animation;
 import  android.widget.ImageView;
 
Created by koush on 7/4/14.
 
     Drawable placeholderDrawable;
     int placeholderResource;
     Drawable errorDrawable;
     int errorResource;
     Animation inAnimation;
     Animation loadAnimation;
     int loadAnimationResource;
     int inAnimationResource;
     boolean fadeIn = true;
     boolean crossfade;
 
     public IonImageViewRequestBuilder(IonRequestBuilder builder) {
         super(builder);
     }
 
     public IonImageViewRequestBuilder(Ion ion) {
         super(ion);
     }
 
     @Override
     void reset() {
         super.reset();
          = true;
          = false;
          = 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) {
         if ( == null || .get() != imageView)
              = new ContextReference.ImageViewContextReference(imageView);
         return this;
     }
 
     private IonDrawable setIonDrawable(ImageView imageViewBitmapFetcher bitmapFetcherint loadedFrom) {
         BitmapInfo info = null;
         if (bitmapFetcher != null)
             info = bitmapFetcher.info;
         if (info != null)
             bitmapFetcher = null;
 
         IonDrawable ret = IonDrawable.getOrCreateIonDrawable(imageView)
         .ion()
         .setBitmap(infoloadedFrom)
         .setBitmapFetcher(bitmapFetcher)
         .setRepeatAnimation( == .)
         .setSize()
         .setError()
        .setPlaceholder()
        .setFadeIn( || );
        imageView.setImageDrawable(ret);
        return ret;
    }
    @Override
    public IonBitmapRequestBuilder fadeIn(boolean fadeIn) {
        this. = fadeIn;
        return this;
    }
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    private static boolean getAdjustViewBounds_16(ImageView imageView) {
        return imageView.getAdjustViewBounds();
    }
    private static boolean getAdjustViewBounds(ImageView imageView) {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && getAdjustViewBounds_16(imageView);
    }
    @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);
        if () {
            Drawable drawable = imageView.getDrawable();
            if (drawable instanceof IonDrawable) {
                IonDrawable ionDrawable = (IonDrawable)drawable;
                drawable = ionDrawable.getCurrentDrawable();
            }
            placeholder(drawable);
        }
        int sampleWidth = ;
        int sampleHeight = ;
        // see if we need default transforms, or this if the imageview
        // will request the actual size on measure
        if ( == 0 &&  == 0 && !getAdjustViewBounds(imageView)) {
            // set the sample size hints from the current dimensions
            // but don't actually apply a transform.
            // this may be zero, in which case IonDrawable
            // will eventually try again with real dimensions
            // during draw.
            sampleWidth = imageView.getMeasuredWidth();
            sampleHeight = imageView.getMeasuredHeight();
        }
        else {
            addDefaultTransform();
        }
        // executeCache the request, see if we get a bitmap from cache.
        BitmapFetcher bitmapFetcher = executeCache(sampleWidthsampleHeight);
        if (bitmapFetcher.info != null) {
            doAnimation(imageViewnull, 0);
            IonDrawable drawable = setIonDrawable(imageViewbitmapFetcher..);
            drawable.cancel();
            ImageViewFutureImpl imageViewFuture = ImageViewFutureImpl.getOrCreateImageViewFuture(drawable)
            .setScaleMode();
            ImageViewFutureImpl.applyScaleMode(imageView);
            imageViewFuture.reset();
            imageViewFuture.setComplete(bitmapFetcher.info.exceptionimageView);
            return imageViewFuture;
        }
        IonDrawable drawable = setIonDrawable(imageViewbitmapFetcher, 0);
        doAnimation(imageView);
        ImageViewFutureImpl imageViewFuture = ImageViewFutureImpl.getOrCreateImageViewFuture(drawable)
        .setScaleMode();
        imageViewFuture.reset();
        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
    public IonImageViewRequestBuilder crossfade(boolean crossfade) {
        this. = crossfade;
        return this;
    }
    @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