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

Image disappears after setAlpha/setColorFilter on ImageView containing GlideBitmapDrawable #118

Closed
TWiStErRob opened this issue Sep 5, 2014 · 0 comments
Assignees
Labels
Milestone

Comments

@TWiStErRob
Copy link
Collaborator

I narrowed it down to: GlideBitmapDrawable.destRect = 0,0 - 0,0 on every draw and that's because in the current instance applyGravity has never been true.

ImageView only sets the bounds of the Drawable once, when it receives the Drawable hence applyGravity is set only once. However when the above mentioned setters are called on ImageView it mutates the drawable which clones the the state, but that doesn't include bounds.

BitmapDrawable works around this (and works) by cloning only the state and returning this.

The above in code (I removed the uninteresting parts):

class ImageView {
    public void setAlpha(int alpha) {
            mAlpha = alpha;
            mColorMod = true;
            applyColorMod();
    }
   private void applyColorMod() {
        if (mDrawable != null && mColorMod) {
            mDrawable = mDrawable.mutate();
            mDrawable.setColorFilter(mColorFilter);
            mDrawable.setAlpha(mAlpha);
        }
    }
    public void setImageDrawable(Drawable drawable) {
        if (mDrawable != drawable) {
            updateDrawable(drawable);
        }
    }
    private void updateDrawable(Drawable d) {
        if (d != null) {
            applyColorMod();
            configureBounds();
        }
    }
    private void configureBounds() {
        if (dwidth <= 0 || dheight <= 0 || ScaleType.FIT_XY == mScaleType) {
            mDrawable.setBounds(0, 0, vwidth, vheight);
        } else {
            mDrawable.setBounds(0, 0, dwidth, dheight);
        }
    |
}
class GlideBitmapDrawable {
    protected void onBoundsChange(Rect bounds) {
        super.onBoundsChange(bounds);
        applyGravity = true;
    }
}
@TWiStErRob TWiStErRob changed the title Image disappears after setAlpha/setColorFilter on ImageView Image disappears after setAlpha/setColorFilter on ImageView containing GlideBitmapDrawable Sep 5, 2014
@sjudd sjudd self-assigned this Sep 5, 2014
@sjudd sjudd closed this as completed in 787279a Sep 6, 2014
@sjudd sjudd modified the milestones: 3.0, 3.3.1 Sep 7, 2014
@TWiStErRob TWiStErRob added the bug label Oct 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants