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

Fails when attempting to animate vector path attributes #16

Open
twyatt opened this issue Jul 16, 2015 · 6 comments
Open

Fails when attempting to animate vector path attributes #16

twyatt opened this issue Jul 16, 2015 · 6 comments

Comments

@twyatt
Copy link

twyatt commented Jul 16, 2015

First and foremost, thanks for all your hard work on this library!

On Android API 14 devices, animating a vector group works beautifully but when attempting to animate vector path attributes (e.g. fillAlpha on path circlePath of circle.xml below) an exception is thrown:

07-15 23:51:44.013  17042-17042/com.example.vector_compat_test E/AndroidRuntimeFATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vector_compat_test/com.example.vector_compat_test.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/circle_fade.xml from drawable resource ID #0x7f02003c
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/circle_fade.xml from drawable resource ID #0x7f02003c
            at android.content.res.Resources.loadDrawable(Resources.java:1918)
            at android.content.res.Resources.getDrawable(Resources.java:659)
            at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:34)
            at com.example.vector_compat_test.MainActivity.onCreate(MainActivity.java:22)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag animated-vector
            at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:877)
            at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
            at android.content.res.Resources.loadDrawable(Resources.java:1915)
            at android.content.res.Resources.getDrawable(Resources.java:659)
            at com.wnafee.vector.compat.ResourcesCompat.getDrawable(ResourcesCompat.java:34)
            at com.example.vector_compat_test.MainActivity.onCreate(MainActivity.java:22)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

drawable/circle.xml

<?xml version="1.0" encoding="utf-8"?>
<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:width="150dp"
    android:height="150dp"
    android:viewportWidth="100"
    android:viewportHeight="100"

    app:vc_viewportWidth="100"
    app:vc_viewportHeight="100">

    <group
        android:name="circleGroup"
        android:rotation="0"
        android:pivotX="50"
        android:pivotY="50">

        <!--
        Circle path data generated with:
        CX: 50.5, CY: 50.5, R: 28
        http://complexdan.com/svg-circleellipse-to-path-converter/
        -->
        <path
            android:name="circlePath"
            android:fillColor="@android:color/white"
            android:fillAlpha="1.0"
            android:pathData="@string/path_circle"

            app:vc_fillColor="@android:color/white"
            app:vc_fillAlpha="1.0"
            app:vc_pathData="@string/path_circle"/>

    </group>

</vector>

drawable/circle_fade.xml

<?xml version="1.0" encoding="utf-8"?>
<animated-vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/circle">

    <target
        android:name="circlePath"
        android:animation="@animator/fade"/>

</animated-vector>

animator/fade.xml

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:propertyName="fillAlpha"
    android:duration="@android:integer/config_longAnimTime"
    android:valueFrom="1.0"
    android:valueTo="0.0"
    android:repeatCount="1"
    android:repeatMode="reverse"/>

MainActivity.java

...
import com.wnafee.vector.compat.ResourcesCompat;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Drawable drawable = ResourcesCompat.getDrawable(this, R.drawable.circle_fade);

        ImageView circleView = (ImageView) findViewById(R.id.circle);
        circleView.setImageDrawable(drawable);

        circleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (drawable instanceof Animatable) {
                    ((Animatable) drawable).start();
                } else {
                    Log.d(TAG, "!(drawable instanceof Animatable)");
                }
            }
        });
    }

}

The same project works when running on Android API 21+ devices.

@twyatt
Copy link
Author

twyatt commented Jul 16, 2015

Project used for testing: https://github.com/twyatt/vector-compat-test

@ghost
Copy link

ghost commented Jul 16, 2015

I have the same problem.

@timrijckaert
Copy link

Same problem here. Any solutions?

@olegosipenko
Copy link

Confirm, it's falling when trying to animate path attributes. Though the Support Vectors from Support Library successfully animate these attributes, but have no ways to animate paths, this library successfully animates paths, but no path attributes

@mshenawy22
Copy link

same problem , any solutions?

@twyatt
Copy link
Author

twyatt commented Jun 13, 2020

same problem , any solutions?

@mshenawy22 I don't believe this project is maintained anymore. Does the official AnimatedVectorDrawableCompat provide what you need?

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

4 participants