Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1474b788 authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Add AnimatedImageDrawable.getLoopCount

Bug: 73791004
Test: Id0335f15fdf0ebdc16d1edcabca547b9399c506f
Change-Id: I1c048196e45b91a1039c1f89e2176592765d2967
parent 7f66873e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14505,7 +14505,9 @@ package android.graphics.drawable {
    ctor public AnimatedImageDrawable();
    method public void clearAnimationCallbacks();
    method public void draw(android.graphics.Canvas);
    method public int getLoopCount();
    method public int getOpacity();
    method public final boolean isAutoMirrored();
    method public boolean isRunning();
    method public void registerAnimationCallback(android.graphics.drawable.Animatable2.AnimationCallback);
    method public void setAlpha(int);
+6 −0
Original line number Diff line number Diff line
@@ -132,6 +132,11 @@ static jboolean AnimatedImageDrawable_nStop(JNIEnv* env, jobject /*clazz*/, jlon
// Java's LOOP_INFINITE relies on this being the same.
static_assert(SkCodec::kRepetitionCountInfinite == -1);

static jint AnimatedImageDrawable_nGetLoopCount(JNIEnv* env, jobject /*clazz*/, jlong nativePtr) {
    auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr);
    return drawable->getRepetitionCount();
}

static void AnimatedImageDrawable_nSetLoopCount(JNIEnv* env, jobject /*clazz*/, jlong nativePtr,
                                                jint loopCount) {
    auto* drawable = reinterpret_cast<AnimatedImageDrawable*>(nativePtr);
@@ -218,6 +223,7 @@ static const JNINativeMethod gAnimatedImageDrawableMethods[] = {
    { "nIsRunning",          "(J)Z",                                                         (void*) AnimatedImageDrawable_nIsRunning },
    { "nStart",              "(J)Z",                                                         (void*) AnimatedImageDrawable_nStart },
    { "nStop",               "(J)Z",                                                         (void*) AnimatedImageDrawable_nStop },
    { "nGetLoopCount",       "(J)I",                                                         (void*) AnimatedImageDrawable_nGetLoopCount },
    { "nSetLoopCount",       "(JI)V",                                                        (void*) AnimatedImageDrawable_nSetLoopCount },
    { "nSetOnAnimationEndListener", "(JLandroid/graphics/drawable/AnimatedImageDrawable;)V", (void*) AnimatedImageDrawable_nSetOnAnimationEndListener },
    { "nNativeByteSize",     "(J)J",                                                         (void*) AnimatedImageDrawable_nNativeByteSize },
+17 −8
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.graphics.drawable;

import dalvik.annotation.optimization.FastNative;

import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -25,8 +23,6 @@ import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.InflateException;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
@@ -35,20 +31,21 @@ import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;

import com.android.internal.R;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import dalvik.annotation.optimization.FastNative;

import libcore.io.IoUtils;
import libcore.util.NativeAllocationRegistry;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.InputStream;
import java.lang.Runnable;
import java.util.ArrayList;

/**
@@ -106,6 +103,16 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 {
        nSetLoopCount(mState.mNativePtr, loopCount);
    }

    /**
     * Retrieve the number of times the animation will loop.
     */
    public int getLoopCount() {
        if (mState.mNativePtr == 0) {
            throw new IllegalStateException("called getLoopCount on empty AnimatedImageDrawable");
        }
        return nGetLoopCount(mState.mNativePtr);
    }

    /**
     * Create an empty AnimatedImageDrawable.
     */
@@ -490,6 +497,8 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 {
    @FastNative
    private static native boolean nStop(long nativePtr);
    @FastNative
    private static native int nGetLoopCount(long nativePtr);
    @FastNative
    private static native void nSetLoopCount(long nativePtr, int loopCount);
    // Pass the drawable down to native so it can call onAnimationEnd.
    private static native void nSetOnAnimationEndListener(long nativePtr,
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ public:
    // already stopped)
    bool stop();
    bool isRunning();
    int getRepetitionCount() const { return mSkAnimatedImage->getRepetitionCount(); }
    void setRepetitionCount(int count) { mSkAnimatedImage->setRepetitionCount(count); }

    void setOnAnimationEndListener(std::unique_ptr<OnAnimationEndListener> listener) {