{"id":21130001,"url":"https://github.com/KeepSafe/MultiStateAnimation","last_synced_at":"2025-07-09T01:31:59.659Z","repository":{"id":30909021,"uuid":"34466842","full_name":"KeepSafe/MultiStateAnimation","owner":"KeepSafe","description":"Android library to create complex multi-state animations.","archived":false,"fork":false,"pushed_at":"2016-02-20T07:14:17.000Z","size":462,"stargazers_count":402,"open_issues_count":1,"forks_count":53,"subscribers_count":33,"default_branch":"master","last_synced_at":"2024-11-18T02:10:06.115Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KeepSafe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-23T16:06:59.000Z","updated_at":"2024-11-13T10:24:17.000Z","dependencies_parsed_at":"2022-09-03T20:32:28.874Z","dependency_job_id":null,"html_url":"https://github.com/KeepSafe/MultiStateAnimation","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeepSafe%2FMultiStateAnimation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeepSafe%2FMultiStateAnimation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeepSafe%2FMultiStateAnimation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeepSafe%2FMultiStateAnimation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KeepSafe","download_url":"https://codeload.github.com/KeepSafe/MultiStateAnimation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225115177,"owners_count":17423063,"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-11-20T05:32:09.871Z","updated_at":"2024-11-20T05:32:11.367Z","avatar_url":"https://github.com/KeepSafe.png","language":"Java","funding_links":[],"categories":["Libs"],"sub_categories":["\u003cA NAME=\"Animations\"\u003e\u003c/A\u003eAnimations"],"readme":"# MultiStateAnimation\n\nAndroid library to create complex multi-state animations.\n\n![Demo animation](docs/images/demo_1.gif)\n\n## Overview\n\nA class that allows for complex multi-state animations using Android's\n`AnimationDrawable`. It supports both oneshot and looped animation sections.\nTransitions between sections can be defined, and will play automatically when\nmoving between the defined states. State transitions can be queued\nasynchronously, and the library will take car of smoothly starting the next\nanimation once the current section is complete.\n\n## Installation\n\nAdd the following dependency to your gradle build file:\n```gradle\n    dependencies {  \n        compile 'com.getkeepsafe.android.multistateanimation:library:1.1.1'\n    }\n```\n## Usage\nEach animation consists of a series of states. A state has some metadata and a list\nof frames to draw. A state can also define transitions from other states. A\ntransition is a list of frames that will be played when moving directly from a\nspecified state to the state where the transition is defined.\n\nAn animation can be defined either with a JSON file included as a `raw` resource, \nor directly in Java code using builders.\n\n### Defining an animation with Java code\n\n```java\n\n    // The ID is used in code to specify a section to play\n    MultiStateAnimation.SectionBuilder firstSection = new MultiStateAnimation.SectionBuilder(\"first_section\")\n        // If true, this section will play once and stop. Otherwise it\n        // will loop indefinitely.\n        .setOneshot(false)\n        // The number of milliseconds that each frame of this section will\n        // play\n        .setFrameDuration(33)\n        // Each frame is the name of an image resource. They will be\n        // played in the order added.\n        .addFrame(R.drawable.first_section_01)\n        .addFrame(R.drawable.first_section_02);\n\n    // The frames of a transition will be played before playing\n    // the normal frames of this section when transitioning. In\n    // this case, the frames for this transition will play if\n    // \"first_section\" is playing when queueTransition(\"second_section\") \n    // is called\n    MultiStateAnimation.TransitionBuilder transitionFromFirst = new MultiStateAnimation.TransitionBuilder()\n        .setFrameDuration(33)\n        .addFrame(R.drawable.first_to_second_transition_001)\n        .addFrame(R.drawable.first_to_second_transition_002)\n        .addFrame(R.drawable.first_to_second_transition_003);\n\n    // As a special case, a transition ID of \"\" is a transition\n    // from nothing. It will play if the associated section is the\n    // first to ever play.\n    MultiStateAnimation.TransitionBuilder transitionFromNothing = new MultiStateAnimation.TransitionBuilder()\n        .addFrame(R.drawable.nothing_to_second_001)\n        .addFrame(R.drawable.nothing_to_second_002);\n\n    // A section with a single frame and \"oneshot\" set to true is\n    // equivalent to a static image\n    MultiStateAnimation.SectionBuilder secondSection = new MultiStateAnimation.SectionBuilder(\"second_section\")\n        .setOneshot(true)\n        .addTransition(\"first_section\", transitionFromFirst)\n        .addTransition(\"\", transitionFromNothing)\n        .addFrame(R.drawable.second_section_01);\n\n    // Animation should be given an View that will be used to display the animation.\n    ImageView view = (ImageView) findViewById(R.id.animationImageView);\n    MultiStateAnimation animation = new MultiStateAnimation.Builder(view)\n        .addSection(startSection)\n        .addSection(loadingSection)\n        .addSection(endSection)\n        .build(context);\n\n```\n\n### Defining an animation using JSON\n\nAs an alternative to using Java code, you can instead define animations using a JSON file stored as a raw resource. The following JSON file defines the same animation as the above Java code.\n\n```javascript\n\n    {\n        \"first_section\": { \n            \"oneshot\": false, \n            \"frame_duration\": 33, \n            \"frames\": [\n                \"first_section_1\",\n                \"first_section_2\"\n            ],\n    \n        }\n    \n        \"second_section\": {\n            \"oneshot\": true,\n            \"frames\": [\n                \"second_section_01\"\n            ],\n            \"transitions_from\": {\n                \"first_section\": {\n                    \"frame_duration\": 33,\n                    \"frames\": [\n                            \"first_to_second_transition_001\",\n                            \"first_to_second_transition_002\",\n                            \"first_to_second_transition_003\"\n                    ]\n                }\n                \"\": {\n                    \"frames\": [\n                        \"nothing_to_second_001\",\n                        \"nothing_to_second_002\"\n                    ]\n                }\n            }\n        }\n    }\n\n```\n\nThen a `MultiStateAnimationOjbect` can be created in Java:\n\n```java\n\n    ImageView view = (ImageView) findViewById(R.id.animationImageView);\n    MultiStateAnimation animationSeries = MultiStateAnimation.fromJsonResource(context, view, R.raw.sample_animation);\n\n```\n\n#### Generating JSON animation files automatically\n\nIncluded in the repo is a [Python 3 script](scripts/generate_animation_json.py) that can assist in generating the JSON for an animation. To use it, place the frames for each section of the animation in a separate folder, the pass those folders to the script.\n\nFor example, to generate the JSON file above, create a folder structure like this:\n```bash\n    .\n    ├── first_section\n    │   ├── first_section_1.png\n    │   └── first_section_2.png\n    ├── first_to_second_transition\n    │   ├── first_to_second_transition_001.png\n    │   ├── first_to_second_transition_002.png\n    │   └── first_to_second_transition_003.png\n    ├── nothing_to_second_transition\n    │   ├── nothing_to_second_001.png\n    │   └── nothing_to_second_002.png\n    └── second_section\n        └── second_section_01.png\n```\nThese folders can be located anywhere in your filesystem. To generate the JSON file, run the script with the folders as arguments:\n```bash\n    python generate_animation_json.py first_section/ second_section/ first_to_second_transition/ nothing_to_second_transition/ --output=sample_animation.json\n```\nThe script will ask a series of questions about each section, and save the resulting json file to `sample_animation.json`. You can run `python generate_animation_json.py --help` to see a full list of arguments\n\n### Playing animations\n\nOnce the animation object is created via one of the above methods, you can use `queueTransition` and `transitionNow` \nfrom the GUI thread to start playing the animations.\n\n```java\n\n    animationSeries.queueTransition(\"first_section\");\n    \n```\n\n## Sample application\n\nSee the [main Activity](samples/src/main/java/com/getkeepsafe/android/multistateanimation/samples/ThreeStateSampleActivity.java) and the [json animation definition](samples/res/raw/sample_animation.json)\n in the [sample application](samples/) for an example.\n\n## Java API\n\nCheck out [the Javadocs](http://keepsafe.github.io/MultiStateAnimation/) for more API details.\n\n## License\n\n    Copyright 2016 KeepSafe Inc.\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKeepSafe%2FMultiStateAnimation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKeepSafe%2FMultiStateAnimation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKeepSafe%2FMultiStateAnimation/lists"}