Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to layer a StateListDrawable over the bitmap. #377

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions ion/src/com/koushikdutta/ion/IonImageViewRequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Looper;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.ImageView;

import com.koushikdutta.async.future.Future;
import com.koushikdutta.ion.bitmap.BitmapInfo;
import com.koushikdutta.ion.builder.Builders;
Expand All @@ -28,6 +29,8 @@ public class IonImageViewRequestBuilder extends IonBitmapRequestBuilder implemen
int placeholderResource;
Drawable errorDrawable;
int errorResource;
StateListDrawable stateDrawable;
int stateResource;
Animation inAnimation;
Animation loadAnimation;
int loadAnimationResource;
Expand Down Expand Up @@ -84,14 +87,24 @@ IonImageViewRequestBuilder withImageView(ImageView imageView) {

private IonDrawable setIonDrawable(ImageView imageView, BitmapInfo info, int loadedFrom) {
IonDrawable ret = IonDrawable.getOrCreateIonDrawable(imageView)
.ion(ion)
.setBitmap(info, loadedFrom)
.setSize(resizeWidth, resizeHeight)
.setError(errorResource, errorDrawable)
.setPlaceholder(placeholderResource, placeholderDrawable)
.setInAnimation(inAnimation, inAnimationResource)
.setDisableFadeIn(disableFadeIn);
imageView.setImageDrawable(ret);
.ion(ion)
.setBitmap(info, loadedFrom)
.setSize(resizeWidth, resizeHeight)
.setError(errorResource, errorDrawable)
.setPlaceholder(placeholderResource, placeholderDrawable)
.setInAnimation(inAnimation, inAnimationResource)
.setDisableFadeIn(disableFadeIn);

if(stateDrawable == null && stateResource != 0) {
stateDrawable = (StateListDrawable) ion.getContext().getResources().getDrawable(stateResource);
}
if(stateDrawable != null) {
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] {ret, stateDrawable});
imageView.setImageDrawable(layerDrawable);
}
else {
imageView.setImageDrawable(ret);
}
return ret;
}

Expand Down Expand Up @@ -223,6 +236,18 @@ public IonImageViewRequestBuilder error(int resourceId) {
return this;
}

@Override
public IonImageViewRequestBuilder stateList(StateListDrawable drawable) {
stateDrawable = drawable;
return this;
}

@Override
public IonImageViewRequestBuilder stateList(int resourceId) {
stateResource = resourceId;
return this;
}

@Override
public IonImageViewRequestBuilder animateIn(Animation in) {
inAnimation = in;
Expand Down
15 changes: 15 additions & 0 deletions ion/src/com/koushikdutta/ion/builder/ImageViewBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.view.animation.Animation;

/**
Expand Down Expand Up @@ -36,6 +37,20 @@ public interface ImageViewBuilder<I extends ImageViewBuilder<?>> {
*/
public I error(int resourceId);

/**
* Layer a {@link android.graphics.drawable.StateListDrawable} over the bitmap
* @param drawable
* @return
*/
public I stateList(StateListDrawable drawable);

/**
* Layer a {@link android.graphics.drawable.StateListDrawable} over the bitmap
* @param resourceId should reference a {@code <state-list-drawable>}
* @return
*/
public I stateList(int resourceId);

/**
* If an ImageView is loaded successfully from a remote source or file storage,
* animate it in using the given Animation. The default animation is to fade
Expand Down