Package pl.droidsonroids.gif
Class GifAnimationMetaData
java.lang.Object
pl.droidsonroids.gif.GifAnimationMetaData
- All Implemented Interfaces:
Parcelable,Serializable
public class GifAnimationMetaData extends Object implements Serializable, Parcelable
Lightweight version of
GifDrawable used to retrieve metadata of GIF only,
without having to allocate the memory for its pixels.- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface android.os.Parcelable
Parcelable.ClassLoaderCreator<T extends Object>, Parcelable.Creator<T extends Object> -
Field Summary
Fields Modifier and Type Field Description static Parcelable.Creator<GifAnimationMetaData>CREATORFields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE -
Constructor Summary
Constructors Constructor Description GifAnimationMetaData(byte[] bytes)Retrieves metadata from byte array.
It can be larger than size of the GIF data.GifAnimationMetaData(ContentResolver resolver, Uri uri)Retrieves metadata fromUriwhich is resolved usingresolver.GifAnimationMetaData(AssetFileDescriptor afd)Retrieves metadata from AssetFileDescriptor.GifAnimationMetaData(AssetManager assets, String assetName)Retrieves metadata from asset.GifAnimationMetaData(Resources res, int id)Retrieves from resource.GifAnimationMetaData(File file)Equivalent to GifMetadata(file.getPath())}GifAnimationMetaData(FileDescriptor fd)Retrieves metadata from FileDescriptorGifAnimationMetaData(InputStream stream)Retrieves metadata from InputStream.GifAnimationMetaData(String filePath)Constructs metadata from given file path.
Only metadata is read, no graphic data is decoded here.GifAnimationMetaData(ByteBuffer buffer)Retrieves metadata fromByteBuffer. -
Method Summary
Modifier and Type Method Description intdescribeContents()longgetAllocationByteCount()LikeGifDrawable.getAllocationByteCount()but does not include memory needed for backingBitmap.longgetDrawableAllocationByteCount(GifDrawable oldDrawable, int sampleSize)LikegetAllocationByteCount()but includes also backingBitmapand takes sample size into account.intgetDuration()intgetHeight()intgetLoopCount()longgetMetadataAllocationByteCount()intgetNumberOfFrames()intgetWidth()booleanisAnimated()StringtoString()voidwriteToParcel(Parcel dest, int flags)
-
Field Details
-
CREATOR
-
-
Constructor Details
-
GifAnimationMetaData
public GifAnimationMetaData(@NonNull Resources res, @RawRes @DrawableRes int id) throws Resources.NotFoundException, IOExceptionRetrieves from resource.- Parameters:
res- Resources to read fromid- resource id- Throws:
Resources.NotFoundException- if the given ID does not exist.IOException- when opening failedNullPointerException- if res is null
-
GifAnimationMetaData
public GifAnimationMetaData(@NonNull AssetManager assets, @NonNull String assetName) throws IOExceptionRetrieves metadata from asset.- Parameters:
assets- AssetManager to read fromassetName- name of the asset- Throws:
IOException- when opening failedNullPointerException- if assets or assetName is null
-
GifAnimationMetaData
Constructs metadata from given file path.
Only metadata is read, no graphic data is decoded here. In practice can be called from main thread. However it will violateStrictModepolicy if disk reads detection is enabled.- Parameters:
filePath- path to the GIF file- Throws:
IOException- when opening failedNullPointerException- if filePath is null
-
GifAnimationMetaData
Equivalent to GifMetadata(file.getPath())}- Parameters:
file- the GIF file- Throws:
IOException- when opening failedNullPointerException- if file is null
-
GifAnimationMetaData
Retrieves metadata from InputStream. InputStream must support marking, IllegalArgumentException will be thrown otherwise.- Parameters:
stream- stream to read from- Throws:
IOException- when opening failedIllegalArgumentException- if stream does not support markingNullPointerException- if stream is null
-
GifAnimationMetaData
Retrieves metadata from AssetFileDescriptor. Convenience wrapper forGifAnimationMetaData(FileDescriptor)- Parameters:
afd- source- Throws:
NullPointerException- if afd is nullIOException- when opening failed
-
GifAnimationMetaData
Retrieves metadata from FileDescriptor- Parameters:
fd- source- Throws:
IOException- when opening failedNullPointerException- if fd is null
-
GifAnimationMetaData
Retrieves metadata from byte array.
It can be larger than size of the GIF data. Bytes beyond GIF terminator are not accessed.- Parameters:
bytes- raw GIF bytes- Throws:
IOException- if bytes does not contain valid GIF dataNullPointerException- if bytes are null
-
GifAnimationMetaData
Retrieves metadata fromByteBuffer. Only direct buffers are supported. Buffer can be larger than size of the GIF data. Bytes beyond GIF terminator are not accessed.- Parameters:
buffer- buffer containing GIF data- Throws:
IOException- if buffer does not contain valid GIF data or is indirectNullPointerException- if buffer is null
-
GifAnimationMetaData
public GifAnimationMetaData(@Nullable ContentResolver resolver, @NonNull Uri uri) throws IOExceptionRetrieves metadata fromUriwhich is resolved usingresolver.ContentResolver.openAssetFileDescriptor(android.net.Uri, String)is used to open an Uri.- Parameters:
uri- GIF Uri, cannot be null.resolver- resolver, null is allowed for file:// scheme Uris only- Throws:
IOException- if resolution fails or destination is not a GIF.
-
-
Method Details
-
getWidth
public int getWidth()- Returns:
- width od the GIF canvas in pixels
-
getHeight
public int getHeight()- Returns:
- height od the GIF canvas in pixels
-
getNumberOfFrames
public int getNumberOfFrames()- Returns:
- number of frames in GIF, at least one
-
getLoopCount
public int getLoopCount()- Returns:
- loop count, 0 means that animation is infinite
-
getDuration
public int getDuration()- Returns:
- duration of of one loop the animation in milliseconds. Result is always multiple of 10.
-
isAnimated
public boolean isAnimated()- Returns:
- true if GIF is animated (has at least 2 frames and positive duration), false otherwise
-
getAllocationByteCount
public long getAllocationByteCount()LikeGifDrawable.getAllocationByteCount()but does not include memory needed for backingBitmap.BitmapinGifDrawablemay be allocated at the time of creation or existing one may be reused ifGifDrawableInit.with(GifDrawable)is used. This method assumes no subsampling (sample size = 1).
To calculate allocation byte count ofGifDrawablecreated from the same input sourcegetDrawableAllocationByteCount(GifDrawable, int)can be used.- Returns:
- possible size of the memory needed to store pixels excluding backing
Bitmapand assuming no subsampling
-
getDrawableAllocationByteCount
@Beta public long getDrawableAllocationByteCount(@Nullable GifDrawable oldDrawable, @IntRange(from=1L,to=65535L) int sampleSize)LikegetAllocationByteCount()but includes also backingBitmapand takes sample size into account.- Parameters:
oldDrawable- optional old drawable to be reused, passnullif there is no onesampleSize- sample size, pass1if not using subsampling- Returns:
- possible size of the memory needed to store pixels
- Throws:
IllegalArgumentException- if sample size out of range
-
getMetadataAllocationByteCount
public long getMetadataAllocationByteCount()- Returns:
- maximum possible size of the allocated memory needed to store metadata
-
toString
-
describeContents
public int describeContents()- Specified by:
describeContentsin interfaceParcelable
-
writeToParcel
- Specified by:
writeToParcelin interfaceParcelable
-