{"id":13537654,"url":"https://github.com/wnafee/vector-compat","last_synced_at":"2025-05-16T12:11:52.687Z","repository":{"id":30062348,"uuid":"33611781","full_name":"wnafee/vector-compat","owner":"wnafee","description":"A support library for VectorDrawable and AnimatedVectorDrawable classes introduced in Lollipop","archived":false,"fork":false,"pushed_at":"2016-10-24T02:42:14.000Z","size":602,"stargazers_count":1225,"open_issues_count":25,"forks_count":161,"subscribers_count":44,"default_branch":"master","last_synced_at":"2025-04-15T03:18:13.450Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wnafee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-08T14:26:09.000Z","updated_at":"2025-03-31T23:55:08.000Z","dependencies_parsed_at":"2022-09-15T21:40:45.547Z","dependency_job_id":null,"html_url":"https://github.com/wnafee/vector-compat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnafee%2Fvector-compat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnafee%2Fvector-compat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnafee%2Fvector-compat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wnafee%2Fvector-compat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wnafee","download_url":"https://codeload.github.com/wnafee/vector-compat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527099,"owners_count":22085919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T09:01:01.683Z","updated_at":"2025-05-16T12:11:52.648Z","avatar_url":"https://github.com/wnafee.png","language":"Java","readme":"# vector-compat\nA support library for [`VectorDrawable`][1] and [`AnimatedVectorDrawable`][2] introduced in Lollipop with fully backwards compatible tint support (api 14+ so far)\n\n`vector-compat` provides the necessary tools to make animated icons similar to the new drawer hamburger icon that morphs to a back arrow when clicked. Any other morph animation between icons can be defined _purely in `xml` (**no java code required**)_ and the library takes care of the transformation animation. Because they are in vector format, these drawables can be of any height and width with no resulting pixelation.\n\n![Example](https://github.com/wnafee/vector-compat/blob/master/artwork/example.gif)\n![Example 1](https://github.com/wnafee/vector-compat/blob/master/artwork/example_1.gif)\n![Example 2](https://github.com/wnafee/vector-compat/blob/master/artwork/example_2.gif)\n\nThe library will transparently fall back to the lollipop implementation of `VectorDrawable` and `AnimatedVectorDrawable` on api 21+ devices\n\n##Commonly used animations\nThe library packs some ready-made morph animations developers can use in their code with `MorphButton`. More will be added soon as this is a work-in-progress. The library has the following morph animations :\n* Play-Pause morph animation (bi-directional morph)\n* Play-Stop morph animation (bi-directional morph)\n* Arrow-Hamburger menu morph animation (bi-directional morph)\n\n**The goal is to, with time, create a repo of commonly used morph animations that lots of developers find useful.**\n\nIf you have requests for particular morph animations, please open a [new issue](https://github.com/wnafee/vector-compat/issues/new) and I'll work on adding them to the library. You are also welcome to create a [pull request](https://github.com/wnafee/vector-compat/compare) if you've created some of your own. **_Please contribute_** :)\n\n## Download\nAdd the `vector-compat` dependency to your `build.gradle` file and make sure to use `buildToolsVersion` 22 or higher:\n\n[![Maven Central](https://img.shields.io/maven-central/v/com.wnafee/vector-compat.svg)](http://search.maven.org/#search%7Cga%7C1%7Cvector-compat)\n```groovy\nandroid {\n    // use version 22 or higher\n    buildToolsVersion \"22.0.1\"\n    ...\n}\ndependencies {\n    compile 'com.wnafee:vector-compat:1.0.5'\n    ...\n}\n```\n## Proguard\nIf you're using proguard for code shrinking and obfuscation, make sure to add the following:\n```proguard\n   -keep class com.wnafee.vector.** { *; }\n```\n## Usage\n`VectorDrawable` and `AnimatedVectorDrawable` xml drawable syntax is exactly the same as the lollipop documentation (can be seen [here][1] and [here][2] respectively). With 2 caveats: \n* Some attributes under the `\u003cvector\u003e` nodes must be listed once for the `android:` namespace and once for the local namespace with a `vc_` prefix (e.g. `app:vc_fillColor`). See example [here][4]. (For a complete list of `vc_` prefixed attributes see [attr.xml][6] for )\n* Any `pathType` anim xml must have the `android:valueType=\"pathType\"` in addition to `app:vc_valueType=\"pathType\"` to allow for lollipop implementation fallback. See example [here][5].\n\n\n#### Inflation\n`VectorDrawable` and `AnimatedVectorDrawable` in this support library can be inflated in one of 2 ways:\n\n* Calling static `getDrawable()` methods:\n```java\n//This will only inflate a drawable with \u003cvector\u003e as the root element\nVectorDrawable.getDrawable(context, R.drawable.ic_arrow_vector);\n\n//This will only inflate a drawable with \u003canimated-vector\u003e as the root element\nAnimatedVectorDrawable.getDrawable(context, R.drawable.ic_arrow_to_menu_animated_vector);\n\n// This will inflate any drawable and will auto-fallback to the lollipop implementation on api 21+ devices\nResourcesCompat.getDrawable(context, R.drawable.any_drawable);\n````\n_If inflating the Drawable in java code, it is recommended to always use `ResourcesCompat.getDrawable()` as this handles Lollipop fallback when applicable. This allows the system to cache Drawable ConstantState and hence is more efficient_\n\n* directly from the `MorphButton` view in xml:\n```xml\n\u003c!-- Insert xmlns:app=\"http://schemas.android.com/apk/res-auto\" in your root layout element --\u003e\n\u003ccom.wnafee.vector.MorphButton\n    android:id=\"@+id/playPauseBtn\"\n    android:layout_width=\"wrap_content\"\n    android:layout_height=\"wrap_content\"\n    app:vc_startDrawable=\"@drawable/ic_pause_to_play\"\n    app:vc_endDrawable=\"@drawable/ic_play_to_pause\" /\u003e \n```\n#### MorphButton\n`MorphButton` is a `CompoundButton` with 2 states: `MorphState.START` or `MorphState.END`. The attributes `vc_startDrawable` and `vc_endDrawable` define which foreground drawables to use for the button depending on the button's state. These can be any type of drawable (e.g. `BitmapDrawable`, `ColorDrawable`, `VectorDrawable`, `AnimatedVectorDrawable` etc.)\n\nTo use MorphButton in your app, make sure to include the `morphButtonStyle` item in your base app theme:\n```xml\n\u003cstyle name=\"MyAppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar\"\u003e\n    \u003citem name=\"morphButtonStyle\"\u003e@style/Widget.MorphButton\u003c/item\u003e\n\u003c/style\u003e\n```\n\n`MorphButtons` allow you to tint your foreground drawables (i.e. `vc_startDrawable` and `vc_endDrawable`) and background drawable separately in both xml and java. See the following examples for defining `MorphButtons`:\n\n**XML**:\n```xml\n\u003ccom.wnafee.vector.MorphButton\n    android:id=\"@+id/drawerBtn\"\n    android:layout_width=\"wrap_content\"\n    android:layout_height=\"wrap_content\"\n    android:scaleType=\"fitCenter\"\n    app:vc_backgroundTint=\"#f50057\"\n    app:vc_foregroundTint=\"#3F51B5\"\n    app:vc_startDrawable=\"@drawable/ic_arrow_to_drawer\"\n    app:vc_endDrawable=\"@drawable/ic_drawer_to_arrow\"/\u003e\n```\n\n**Java**:\n```java\n    MorphButton mb = new MorphButton(this);\n    mb.setBackgroundTintList(getResources().getColorStateList(R.color.background_tint_color));\n    mb.setForegroundTintList(ColorStateList.valueOf(Color.RED));\n    mb.setStartDrawable(R.drawable.ic_pause_to_play);\n    mb.setEndDrawable(R.drawable.ic_play_to_pause);\n    mb.setState(MorphState.END);\n```\nThe `scaleType` attribute defines how to scale the foreground drawable to fill the button's background. This is the same as [`ImageView.ScaleType`][7] which you can take a look at [here][7].\n\nButton clicks will toggle between the foreground drawables. If the drawables happen to implement the [`Animatable`][3] interface (e.g. `AnimatedVectorDrawable` or `AnimationDrawable`) then `start()` will be automatically called to animate between the start and end drawables defined in xml.\n \n MorphButton states can be set manually via `setState()` methods:\n```java\n// transition with no animation\nmyMorphButton.setState(MorphState.END) \n\n// ... or transition with animation if drawable is Animatable\nmyMorphButton.setState(MorphState.START, true) \n````\n\nIf you need to be informed of button state changes you need to add an `OnStateChangedListener`:\n```java\nMyMorphButton.setOnStateChangedListener(new OnStateChangedListener() {\n    @Override\n    public void onStateChanged(MorphState changedTo, boolean isAnimating) {\n        // changeTo is the new state\n        // isAnimating = true if the state changed with animation\n        // Do something here\n    }\n});\n```\n\n## License\n\n    Copyright 2015 Wael Nafee\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n[1]: http://developer.android.com/reference/android/graphics/drawable/VectorDrawable.html\n[2]: http://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable.html\n[3]: http://developer.android.com/reference/android/graphics/drawable/Animatable.html\n[4]: https://github.com/wnafee/vector-compat/blob/master/library/src/main/res/drawable/ic_arrow_vector.xml\n[5]: https://github.com/wnafee/vector-compat/blob/master/library/src/main/res/anim/arrow_to_drawer_path.xml\n[6]: https://github.com/wnafee/vector-compat/blob/master/library/src/main/res/values/attr.xml\n[7]: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html\n","funding_links":[],"categories":["Java","\u003ca name=\"Vector \u0026 SVG \u0026 path-view\"\u003eVector \u0026 SVG \u0026 path-view\u003c/a\u003e"],"sub_categories":["Personal Blog"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwnafee%2Fvector-compat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwnafee%2Fvector-compat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwnafee%2Fvector-compat/lists"}