Add DrawableUtils
This commit is contained in:
parent
29ebfebfd8
commit
a7163b8cf8
@ -44,14 +44,9 @@ public class AsyncDrawable extends Drawable {
|
|||||||
if (placeholder != null) {
|
if (placeholder != null) {
|
||||||
|
|
||||||
// process placeholder bounds
|
// process placeholder bounds
|
||||||
final Rect bounds = placeholder.getBounds();
|
if (placeholder.getBounds().isEmpty()) {
|
||||||
if (bounds.isEmpty()) {
|
// set intrinsic bounds for both drawables (this one and placeholder)
|
||||||
// set intrinsic bounds
|
final Rect rect = DrawableUtils.intrinsicBounds(placeholder);
|
||||||
final Rect rect = new Rect(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
placeholder.getIntrinsicWidth(),
|
|
||||||
placeholder.getIntrinsicHeight());
|
|
||||||
placeholder.setBounds(rect);
|
placeholder.setBounds(rect);
|
||||||
setBounds(rect);
|
setBounds(rect);
|
||||||
}
|
}
|
||||||
@ -123,6 +118,24 @@ public class AsyncDrawable extends Drawable {
|
|||||||
initBounds();
|
initBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove result from this drawable (for example, in case of cancellation)
|
||||||
|
*
|
||||||
|
* @since 3.0.1-SNAPSHOT
|
||||||
|
*/
|
||||||
|
public void clearResult() {
|
||||||
|
|
||||||
|
final Drawable result = this.result;
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
result.setCallback(null);
|
||||||
|
this.result = null;
|
||||||
|
|
||||||
|
// clear bounds
|
||||||
|
setBounds(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initBounds() {
|
private void initBounds() {
|
||||||
|
|
||||||
if (canvasWidth == 0) {
|
if (canvasWidth == 0) {
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package ru.noties.markwon.image;
|
||||||
|
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 3.0.1-SNAPSHOT
|
||||||
|
*/
|
||||||
|
public abstract class DrawableUtils {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static Rect intrinsicBounds(@NonNull Drawable drawable) {
|
||||||
|
return new Rect(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void applyIntrinsicBoundsIfEmpty(@NonNull Drawable drawable) {
|
||||||
|
if (drawable.getBounds().isEmpty()) {
|
||||||
|
drawable.setBounds(intrinsicBounds(drawable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DrawableUtils() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user