-
- All Implemented Interfaces:
-
com.mobwith.imgmodule.load.Key,com.mobwith.imgmodule.load.Transformation
public class DrawableTransformation implements Transformation<Drawable>
Applies a BitmapTransformation to Drawables by first attempting to convert the Drawable to a Bitmap and then running the Transformation on the converted Bitmap.
This class is relatively efficient for BitmapDrawable where the Bitmap is readily accessible. For non-Bitmap based Drawables, this class must first try to draw the Drawable to a Bitmap using android.graphics.Canvas, which is less efficient. Drawables that implement android.graphics.drawable.Animatable will fail with an exception. Drawables that return <= 0 for and/or getIntrinsicWidth will fail with an exception if the requested size is . Drawables without intrinsic dimensions are drawn using the dimensions provided in transform. As a result, they may be transformed incorrectly or in unexpected ways.
-
-
Constructor Summary
Constructors Constructor Description DrawableTransformation(Transformation<Bitmap> wrapped, boolean isRequired)
-
Method Summary
Modifier and Type Method Description Transformation<BitmapDrawable>asBitmapDrawable()Resource<Drawable>transform(@NonNull() Context context, @NonNull() Resource<Drawable> resource, int outWidth, int outHeight)Transforms the given resource and returns the transformed resource. booleanequals(Object o)inthashCode()voidupdateDiskCacheKey(@NonNull() MessageDigest messageDigest)Adds all uniquely identifying information to the given digest. -
-
Constructor Detail
-
DrawableTransformation
DrawableTransformation(Transformation<Bitmap> wrapped, boolean isRequired)
-
-
Method Detail
-
asBitmapDrawable
Transformation<BitmapDrawable> asBitmapDrawable()
-
transform
@NonNull() Resource<Drawable> transform(@NonNull() Context context, @NonNull() Resource<Drawable> resource, int outWidth, int outHeight)
Transforms the given resource and returns the transformed resource.
If the original resource object is not returned, the original resource will be recycled andit's internal resources may be reused. This means it is not safe to rely on the originalresource or any internal state of the original resource in any new resource that is created.Usually this shouldn't occur, but if absolutely necessary either the original resource objectcan be returned with modified internal state, or the data in the original resource can becopied into the transformed resource.
If a Transformation is updated, equals, hashCode, and should all change. If you're using a simpleString key an easy way to do this is to append a version number to your key. Failing to do sowill mean users may see images loaded from cache that had the old version of the Transformationapplied. Changing the return values of those methods will ensure that the cache key has changedand therefore that any cached resources will be re-generated using the updated Transformation.
During development you may need to either using or make sure changes each time you make a change to theTransformation. Otherwise the resource you request may be loaded from disk cache and yourTransformation may not be called.
- Parameters:
context- The Application contextresource- The resource to transform.outWidth- The width of the view or target the resource will be displayed in, or to indicate the original resourcewidth.outHeight- The height of the view or target the resource will be displayed in, or to indicate the original resourceheight.
-
hashCode
int hashCode()
-
updateDiskCacheKey
void updateDiskCacheKey(@NonNull() MessageDigest messageDigest)
Adds all uniquely identifying information to the given digest.
Note - Using reset inside of this method will resultin undefined behavior.
-
-
-
-