# MultiStateAnimation **Repository Path**: hihopeorg/MultiStateAnimation ## Basic Information - **Project Name**: MultiStateAnimation - **Description**: 多状态动画 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-09-02 - **Last Updated**: 2021-11-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MultiStateAnimation **本项目是基于开源项目MultiStateAnimation进行ohos化的移植和开发的,可以通过项目标签以及github地址( https://github.com/KeepSafe/MultiStateAnimation )追踪到原项目版本** #### 项目介绍 - 项目名称:MultiStateAnimation - 所属系列:ohos的第三方组件适配移植 - 功能:多状态动画 - 项目移植状态:完成 - 调用差异:无 - 项目作者和维护人:hihope - 联系方式:hihope@hoperun.com - 原项目Doc地址:https://github.com/KeepSafe/MultiStateAnimation - 原项目基线版本:v1.1.1 - 编程语言:Java - 外部库依赖:无 #### 效果展示: ![avatar](animation.gif) #### 安装教程 ##### 方案一: 1. 编译依赖库 library-release.har。 2. 启动 DevEco Studio,将编译的har包,导入工程目录“entry->libs”下。 3. 在moudle级别下的build.gradle文件中添加依赖,在dependences标签中增加对libs目录下har包的引用。 ``` dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) …… } ``` 4.在导入的har包上点击右键,选择“Add as Library”对包进行引用,选择需要引用的模块,并点击“OK”即引用成功。 ##### 方案二: 1. 在工程的build.gradle的allprojects中,添加HAR所在的Maven仓地址: ``` repositories { maven { url 'http://106.15.92.248:8081/repository/Releases/' } } ``` 2. 在应用模块的build.gradle的dependencies闭包中,添加如下代码: ``` dependencies { implementation 'com.getkeepsafe.ohos:multistateanimation:1.0.0' } ``` #### 使用说明 1、用java代码定义动画 ```java // ID 在代码中用于指定要播放的部分 MultiStateAnimation.SectionBuilder firstSection = new MultiStateAnimation.SectionBuilder("first_section") // 如果为 true,则此部分将播放一次并停止。 否则它将无限循环。 .setOneshot(false) // 每帧将播放的毫秒数 .setFrameDuration(33) // 每一帧都是一个图像资源的名称。 它们将按照添加的顺序播放。 .addFrame(ResourceTable.Media_first_section_01) .addFrame(ResourceTable.Media_first_section_02); // 过渡时将在播放此部分的正常帧之前播放过渡的帧。 在这种情况下,如果调用 // queueTransition("second_section") 时正在播放“first_section”,则将播放此转换的帧 MultiStateAnimation.TransitionBuilder transitionFromFirst = new MultiStateAnimation.TransitionBuilder() .setFrameDuration(33) .addFrame(ResourceTable.Media_first_to_second_transition_001) .addFrame(ResourceTable.Media_first_to_second_transition_002) .addFrame(ResourceTable.Media_first_to_second_transition_003); MultiStateAnimation.TransitionBuilder transitionFromNothing = new MultiStateAnimation.TransitionBuilder() .addFrame(ResourceTable.Media_nothing_to_second_001) .addFrame(ResourceTable.Media_nothing_to_second_002); // 具有单帧且“oneshot”设置为true的部分相当于静态图像 MultiStateAnimation.SectionBuilder secondSection = new MultiStateAnimation.SectionBuilder("second_section") .setOneshot(true) .addTransition("first_section", transitionFromFirst) .addTransition("", transitionFromNothing) .addFrame(ResourceTable.Media_second_section_01); //动画应该被赋予一个用于显示动画的视图。 Image view = (Image) findComponentById(ResourceTable.Id_animationImageView); MultiStateAnimation animation = new MultiStateAnimation.Builder(view) .addSection(startSection) .addSection(loadingSection) .addSection(endSection) .build(context); ``` 2、使用 JSON 定义动画 作为使用 Java 代码的替代方法,您可以使用存储为原始资源的 JSON 文件来定义动画。 以下 JSON 文件定义了与上述 Java 代码相同的动画。 ```json { "first_section": { "oneshot": false, "frame_duration": 33, "frames": [ "first_section_1", "first_section_2" ], } "second_section": { "oneshot": true, "frames": [ "second_section_01" ], "transitions_from": { "first_section": { "frame_duration": 33, "frames": [ "first_to_second_transition_001", "first_to_second_transition_002", "first_to_second_transition_003" ] } "": { "frames": [ "nothing_to_second_001", "nothing_to_second_002" ] } } } } ``` 然后可以在 Java 中创建 MultiStateAnimation: ```java Image view = (Image) findComponentById(ResourceTable.Id_animationImageView); MultiStateAnimation animationSeries = MultiStateAnimation.fromJsonResource(context, view, ResourceTable.Graphic_sample_animation); ``` #### 版本迭代 - v1.0.0 - 实现以下功能 1. 实现多状态动画 #### 版权和许可信息 ``` Copyright 2016 KeepSafe Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```