Messaging: FrameSequence -> ImageDecoder

fixes playing / displaying gifs
replaces old deprecated FrameSequence & FrameSequenceDrawable libs

Change-Id: Id65fff90bdd09af86480636a8a0e404aeb39580f
This commit is contained in:
Ido Ben-Hur
2024-09-16 02:25:12 +03:00
committed by Michael Bestas
parent b11039ed8c
commit d8a0bf022d
4 changed files with 31 additions and 52 deletions
@@ -22,10 +22,10 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.drawable.AnimatedImageDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
import android.support.rastermill.FrameSequenceDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
@@ -194,8 +194,8 @@ public class AsyncImageView extends ImageView implements MediaResourceLoadListen
mImageResource = resource;
mImageResource.addRef();
setImageDrawable(drawable);
if (drawable instanceof FrameSequenceDrawable) {
((FrameSequenceDrawable) drawable).start();
if (drawable instanceof AnimatedImageDrawable) {
((AnimatedImageDrawable) drawable).start();
}
if (getVisibility() == VISIBLE) {
@@ -249,9 +249,8 @@ public class AsyncImageView extends ImageView implements MediaResourceLoadListen
private void releaseImageResource() {
final Drawable drawable = getDrawable();
if (drawable instanceof FrameSequenceDrawable) {
((FrameSequenceDrawable) drawable).stop();
((FrameSequenceDrawable) drawable).destroy();
if (drawable instanceof AnimatedImageDrawable) {
((AnimatedImageDrawable) drawable).stop();
}
if (mImageResource != null) {
mImageResource.release();
@@ -18,7 +18,6 @@ package com.android.messaging.ui.photoviewer;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.rastermill.FrameSequenceDrawable;
import androidx.loader.content.AsyncTaskLoader;
import com.android.ex.photo.PhotoViewController;
@@ -91,7 +90,6 @@ public class BuglePhotoBitmapLoader extends AsyncTaskLoader<BitmapResult>
final Drawable drawable = result != null ? result.drawable : null;
if (isReset()) {
// An async query came in while the loader is stopped. We don't need the result.
releaseDrawable(drawable);
return;
}
@@ -140,11 +138,6 @@ public class BuglePhotoBitmapLoader extends AsyncTaskLoader<BitmapResult>
@Override
public void onCanceled(BitmapResult result) {
super.onCanceled(result);
// At this point we can release the resources associated with 'drawable' if needed.
if (result != null) {
releaseDrawable(result.drawable);
}
}
/**
@@ -160,14 +153,6 @@ public class BuglePhotoBitmapLoader extends AsyncTaskLoader<BitmapResult>
releaseImageResource();
}
private void releaseDrawable(Drawable drawable) {
if (drawable != null && drawable instanceof FrameSequenceDrawable
&& !((FrameSequenceDrawable) drawable).isDestroyed()) {
((FrameSequenceDrawable) drawable).destroy();
}
}
private void setImageResource(final ImageResource resource) {
if (mImageResource != resource) {
// Clear out any information for what is currently used
@@ -181,7 +166,6 @@ public class BuglePhotoBitmapLoader extends AsyncTaskLoader<BitmapResult>
private void releaseImageResource() {
// If we are getting rid of the imageResource backing the drawable, we must also
// destroy the drawable before releasing it.
releaseDrawable(mDrawable);
mDrawable = null;
if (mImageResource != null) {
@@ -189,4 +173,4 @@ public class BuglePhotoBitmapLoader extends AsyncTaskLoader<BitmapResult>
}
mImageResource = null;
}
}
}
@@ -16,8 +16,8 @@
package com.android.messaging.ui.photoviewer;
import android.content.Intent;
import android.graphics.drawable.AnimatedImageDrawable;
import android.graphics.drawable.Drawable;
import android.support.rastermill.FrameSequenceDrawable;
import androidx.loader.content.Loader;
import com.android.ex.photo.PhotoViewCallbacks;
@@ -75,15 +75,15 @@ public class BuglePhotoViewFragment extends PhotoViewFragment {
private void stopGif() {
final Drawable drawable = getDrawable();
if (drawable != null && drawable instanceof FrameSequenceDrawable) {
((FrameSequenceDrawable) drawable).stop();
if (drawable != null && drawable instanceof AnimatedImageDrawable) {
((AnimatedImageDrawable) drawable).stop();
}
}
private void startGif() {
final Drawable drawable = getDrawable();
if (drawable != null && drawable instanceof FrameSequenceDrawable) {
((FrameSequenceDrawable) drawable).start();
if (drawable != null && drawable instanceof AnimatedImageDrawable) {
((AnimatedImageDrawable) drawable).start();
}
}
}