Fix DrawableUtils (intrinsic bounds)
This commit is contained in:
		
							parent
							
								
									f0a03b7df6
								
							
						
					
					
						commit
						1f3c50da03
					
				| @ -43,11 +43,8 @@ public class AsyncDrawable extends Drawable { | ||||
|         final Drawable placeholder = loader.placeholder(); | ||||
|         if (placeholder != null) { | ||||
| 
 | ||||
|             // process placeholder bounds | ||||
|             if (placeholder.getBounds().isEmpty()) { | ||||
|                 final Rect rect = DrawableUtils.intrinsicBounds(placeholder); | ||||
|                 placeholder.setBounds(rect); | ||||
|             } | ||||
|             // process placeholder bounds (if it's not empty -> ignore, use whatever bounds that were set) | ||||
|             DrawableUtils.applyIntrinsicBoundsIfEmpty(placeholder); | ||||
| 
 | ||||
|             // apply placeholder immediately if we have one | ||||
|             setResult(placeholder); | ||||
|  | ||||
| @ -2,6 +2,7 @@ package ru.noties.markwon.image; | ||||
| 
 | ||||
| import android.graphics.Rect; | ||||
| import android.graphics.drawable.Drawable; | ||||
| import android.support.annotation.CheckResult; | ||||
| import android.support.annotation.NonNull; | ||||
| 
 | ||||
| /** | ||||
| @ -10,10 +11,15 @@ import android.support.annotation.NonNull; | ||||
| public abstract class DrawableUtils { | ||||
| 
 | ||||
|     @NonNull | ||||
|     @CheckResult | ||||
|     public static Rect intrinsicBounds(@NonNull Drawable drawable) { | ||||
|         return new Rect(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); | ||||
|     } | ||||
| 
 | ||||
|     public static void applyIntrinsicBounds(@NonNull Drawable drawable) { | ||||
|         drawable.setBounds(intrinsicBounds(drawable)); | ||||
|     } | ||||
| 
 | ||||
|     public static void applyIntrinsicBoundsIfEmpty(@NonNull Drawable drawable) { | ||||
|         if (drawable.getBounds().isEmpty()) { | ||||
|             drawable.setBounds(intrinsicBounds(drawable)); | ||||
|  | ||||
| @ -10,8 +10,6 @@ import android.support.annotation.Nullable; | ||||
| 
 | ||||
| import java.io.InputStream; | ||||
| 
 | ||||
| import ru.noties.markwon.utils.DrawableUtils; | ||||
| 
 | ||||
| /** | ||||
|  * This class can be used as the last {@link MediaDecoder} to _try_ to handle all rest cases. | ||||
|  * Here we just assume that supplied InputStream is of image type and try to decode it. | ||||
| @ -42,7 +40,7 @@ public class ImageMediaDecoder extends MediaDecoder { | ||||
|         final Bitmap bitmap = BitmapFactory.decodeStream(inputStream); | ||||
|         if (bitmap != null) { | ||||
|             out = new BitmapDrawable(resources, bitmap); | ||||
|             DrawableUtils.intrinsicBounds(out); | ||||
|             DrawableUtils.applyIntrinsicBounds(out); | ||||
|         } else { | ||||
|             out = null; | ||||
|         } | ||||
|  | ||||
| @ -3,11 +3,16 @@ package ru.noties.markwon.utils; | ||||
| import android.graphics.drawable.Drawable; | ||||
| import android.support.annotation.NonNull; | ||||
| 
 | ||||
| /** | ||||
|  * @deprecated Please use {@link ru.noties.markwon.image.DrawableUtils} | ||||
|  */ | ||||
| @Deprecated | ||||
| public abstract class DrawableUtils { | ||||
| 
 | ||||
|     public static void intrinsicBounds(@NonNull Drawable drawable) { | ||||
|         drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); | ||||
|     } | ||||
| 
 | ||||
|     private DrawableUtils() {} | ||||
|     private DrawableUtils() { | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -9,8 +9,8 @@ import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| 
 | ||||
| import pl.droidsonroids.gif.GifDrawable; | ||||
| import ru.noties.markwon.image.DrawableUtils; | ||||
| import ru.noties.markwon.image.MediaDecoder; | ||||
| import ru.noties.markwon.utils.DrawableUtils; | ||||
| 
 | ||||
| /** | ||||
|  * @since 1.1.0 | ||||
| @ -41,7 +41,7 @@ public class GifMediaDecoder extends MediaDecoder { | ||||
|         if (bytes != null) { | ||||
|             try { | ||||
|                 out = newGifDrawable(bytes); | ||||
|                 DrawableUtils.intrinsicBounds(out); | ||||
|                 DrawableUtils.applyIntrinsicBounds(out); | ||||
| 
 | ||||
|                 if (!autoPlayGif) { | ||||
|                     ((GifDrawable) out).pause(); | ||||
|  | ||||
| @ -13,8 +13,8 @@ import com.caverock.androidsvg.SVGParseException; | ||||
| 
 | ||||
| import java.io.InputStream; | ||||
| 
 | ||||
| import ru.noties.markwon.image.DrawableUtils; | ||||
| import ru.noties.markwon.image.MediaDecoder; | ||||
| import ru.noties.markwon.utils.DrawableUtils; | ||||
| 
 | ||||
| /** | ||||
|  * @since 1.1.0 | ||||
| @ -65,7 +65,7 @@ public class SvgMediaDecoder extends MediaDecoder { | ||||
|             svg.renderToCanvas(canvas); | ||||
| 
 | ||||
|             out = new BitmapDrawable(resources, bitmap); | ||||
|             DrawableUtils.intrinsicBounds(out); | ||||
|             DrawableUtils.applyIntrinsicBounds(out); | ||||
|         } | ||||
| 
 | ||||
|         return out; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dimitry Ivanov
						Dimitry Ivanov