Created
March 17, 2016 12:07
-
-
Save mswolters/9ffbdf01478e36194f8f to your computer and use it in GitHub Desktop.
TilingDrawable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TilingDrawable extends android.support.v7.graphics.drawable.DrawableWrapper { | |
private boolean callbackEnabled = true; | |
public TilingDrawable(Drawable drawable) { | |
super(drawable); | |
} | |
@Override | |
public void draw(Canvas canvas) { | |
callbackEnabled = false; | |
Rect bounds = getBounds(); | |
Drawable wrappedDrawable = getWrappedDrawable(); | |
int width = wrappedDrawable.getIntrinsicWidth(); | |
int height = wrappedDrawable.getIntrinsicHeight(); | |
for (int x = bounds.left; x < bounds.right + width - 1; x+= width) { | |
for (int y = bounds.top; y < bounds.bottom + height - 1; y += height) { | |
wrappedDrawable.setBounds(x, y, x + width, y + height); | |
wrappedDrawable.draw(canvas); | |
} | |
} | |
callbackEnabled = true; | |
} | |
@Override | |
protected void onBoundsChange(Rect bounds) { | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
public void invalidateDrawable(Drawable who) { | |
if (callbackEnabled) { | |
super.invalidateDrawable(who); | |
} | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
public void scheduleDrawable(Drawable who, Runnable what, long when) { | |
if (callbackEnabled) { | |
super.scheduleDrawable(who, what, when); | |
} | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
public void unscheduleDrawable(Drawable who, Runnable what) { | |
if (callbackEnabled) { | |
super.unscheduleDrawable(who, what); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@antaki93 You can use this way on Kotlin:
BTW, here's the original code of the TilingDrawable, in Kotlin: