Interface Transformation<T>
-
- Type Parameters:
T- The type of the resource being transformed.
- All Superinterfaces:
Key
- All Known Implementing Classes:
BitmapDrawableTransformation,BitmapTransformation,CenterCrop,CenterInside,CircleCrop,DrawableTransformation,FitCenter,GifDrawableTransformation,GranularRoundedCorners,MultiTransformation,Rotate,RoundedCorners,UnitTransformation
public interface Transformation<T> extends Key
A class for performing an arbitrary transformation on a resource that implementsKey.equals(Object)andKey.hashCode()} to identify the transformation in the memory cache andKey.updateDiskCacheKey(java.security.MessageDigest)} to identify the transformation in disk caches.Using the fully qualified class name as a static final
String(notClass.getName()to avoid proguard obfuscation) is an easy way to implementKey.updateDiskCacheKey(java.security.MessageDigest)} correctly. If additional arguments are required they can be passed in to the constructor of theTransformationand then used to update theMessageDigestpassed in toKey.updateDiskCacheKey(MessageDigest). If arguments are primitive types, they can typically easily be serialized usingByteBuffer.Stringtypes can be serialized withString.getBytes(Charset)using the constantKey.CHARSET.Implementations must implement
Key.equals(Object)andKey.hashCode()for memory caching to work correctly.
-
-
Field Summary
-
Fields inherited from interface com.bumptech.glide.load.Key
CHARSET, STRING_CHARSET_NAME
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Resource<T>transform(android.content.Context context, Resource<T> resource, int outWidth, int outHeight)Transforms the given resource and returns the transformed resource.-
Methods inherited from interface com.bumptech.glide.load.Key
equals, hashCode, updateDiskCacheKey
-
-
-
-
Method Detail
-
transform
@NonNull Resource<T> transform(@NonNull android.content.Context context, @NonNull Resource<T> 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 and it's internal resources may be reused. This means it is not safe to rely on the original resource 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 object can be returned with modified internal state, or the data in the original resource can be copied into the transformed resource.
If a Transformation is updated,
Key.equals(Object),Key.hashCode(), andKey.updateDiskCacheKey(java.security.MessageDigest)should all change. If you're using a simple String key an easy way to do this is to append a version number to your key. Failing to do so will mean users may see images loaded from cache that had the old version of the Transformation applied. Changing the return values of those methods will ensure that the cache key has changed and therefore that any cached resources will be re-generated using the updated Transformation.During development you may need to either using
DiskCacheStrategy.NONEor make sureKey.updateDiskCacheKey(java.security.MessageDigest)changes each time you make a change to the Transformation. Otherwise the resource you request may be loaded from disk cache and your Transformation 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, orTarget.SIZE_ORIGINALto indicate the original resource width.outHeight- The height of the view or target the resource will be displayed in, orTarget.SIZE_ORIGINALto indicate the original resource height.- Returns:
- The transformed resource.
-
-