Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with AnimationDrawable in Android 4 #77

Open
msphn opened this issue Aug 13, 2015 · 1 comment
Open

Bug with AnimationDrawable in Android 4 #77

msphn opened this issue Aug 13, 2015 · 1 comment

Comments

@msphn
Copy link

msphn commented Aug 13, 2015

The bug exists in Android 4.* as far as I know, it's not reproducible in Android 5.*. It broke in API 15 and 17.

If you put a AnimationDrawable as a drawable to the ImageViewTouch, the animation does only start in Android 5.

I guess it's sort of a timing problem, I could work around by wasting with the object stack.

Example animation-list:

<?xml version="1.0" encoding="utf-8"?>
<animation-list
    android:id="@+id/led_animation_1"
    android:oneshot="false"
    xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/test1" android:duration="150" />
        <item android:drawable="@drawable/test2" android:duration="150" />
</animation-list>

Example code how it works in Android 5 but not in Android 4:

        this.imageView = (ImageViewTouch) view.findViewById(R.id.step_led_image);
        this.imageView.setDisplayType(ImageViewTouchBase.DisplayType.FIT_TO_SCREEN);
        this.imageView.setScaleEnabled(true);

        AnimationDrawable frameAnimation = (AnimationDrawable) getResources().getDrawable(R.drawable.led_animation_1);

        this.imageView.setImageDrawable(frameAnimation);
        frameAnimation.start();

How it actually works in Android 4:

        this.imageView = (ImageViewTouch) view.findViewById(R.id.step_led_image);
        this.imageView.setDisplayType(ImageViewTouchBase.DisplayType.FIT_TO_SCREEN);
        this.imageView.setScaleEnabled(true);

        AnimationDrawable frameAnimation = (AnimationDrawable) getResources().getDrawable(R.drawable.led_animation_1);

        this.imageView.setImageDrawable(frameAnimation);

        this.imageView.setBackground(frameAnimation);

        AnimationDrawable test = (AnimationDrawable) this.imageView.getBackground();
        test.start();

        this.imageView.setBackground(null);

The first one should be the good way, the second one is a dirty hack and not a solution, don't use that code or you end in hell.

But it's here to show the problem. The first code sticks at frame[0] in Android 4 but works well in 5. The second one sets the same drawable as background and as drawable, that results in some references. If I use getBackground to get my object back, I can run play on it and both starts! I guess we need a function like getImageDrawable, to fix it in a better way for Android 4.

I could implement that, if you like. I leave that here for discussion.

@msphn msphn changed the title Bug with Bug with AnimationDrawable in Android 4 Aug 13, 2015
@msphn
Copy link
Author

msphn commented Aug 26, 2015

Btw. the first code works fine with just using an ImageView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant