├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hewuzhao │ │ └── frameanimation │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── hewuzhao │ │ │ └── frameanimation │ │ │ ├── MainActivity.java │ │ │ └── TestActivity.java │ └── res │ │ ├── drawable-xxhdpi │ │ ├── big_00.png │ │ ├── big_01.png │ │ ├── big_02.png │ │ ├── big_03.png │ │ ├── big_04.png │ │ ├── big_05.png │ │ ├── big_06.png │ │ ├── big_07.png │ │ ├── big_08.png │ │ ├── big_09.png │ │ ├── big_10.png │ │ ├── big_11.png │ │ ├── big_12.png │ │ ├── big_13.png │ │ ├── big_14.png │ │ ├── big_15.png │ │ ├── big_16.png │ │ ├── big_17.png │ │ ├── big_18.png │ │ ├── big_19.png │ │ ├── small_00.jpg │ │ ├── small_01.jpg │ │ ├── small_02.jpg │ │ ├── small_03.jpg │ │ ├── small_04.jpg │ │ ├── small_05.jpg │ │ ├── small_06.jpg │ │ ├── small_07.jpg │ │ ├── small_08.jpg │ │ ├── small_09.jpg │ │ ├── small_10.jpg │ │ ├── small_11.jpg │ │ ├── small_12.jpg │ │ ├── small_13.jpg │ │ ├── small_14.jpg │ │ ├── small_15.jpg │ │ ├── small_16.jpg │ │ ├── small_17.jpg │ │ ├── small_18.jpg │ │ └── small_19.jpg │ │ ├── drawable │ │ ├── big_animation_drawable.xml │ │ └── small_animation_drawable.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_test.xml │ │ └── spinner_item_view.xml │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── hewuzhao │ └── frameanimation │ └── ExampleUnitTest.java ├── build.gradle ├── frameanimation ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hewuzhao │ │ └── frameanimation │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── hewuzhao │ │ │ └── frameanimation │ │ │ ├── FrameApplication.java │ │ │ ├── blobcache │ │ │ ├── BlobCache.java │ │ │ ├── BlobCacheManager.java │ │ │ └── BlobCacheUtil.java │ │ │ ├── bytespool │ │ │ └── BytesBuffer.java │ │ │ ├── frameview │ │ │ ├── CustomLinkedBlockingQueue.java │ │ │ ├── FrameItem.java │ │ │ ├── FrameList.java │ │ │ ├── FrameScaleType.java │ │ │ ├── FrameTextureView.java │ │ │ ├── FrameViewStatus.java │ │ │ └── LinkedBitmap.java │ │ │ └── utils │ │ │ ├── CommonUtil.java │ │ │ ├── FrameParseUtil.java │ │ │ ├── MatrixUtil.java │ │ │ └── ResourceUtil.java │ └── res │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── hewuzhao │ └── frameanimation │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── image └── gif-demo.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/assetWizardSettings.xml 45 | .idea/dictionaries 46 | .idea/libraries 47 | # Android Studio 3 in .gitignore file. 48 | .idea/caches 49 | .idea/modules.xml 50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 51 | .idea/navEditor.xml 52 | 53 | # Keystore files 54 | # Uncomment the following lines if you do not want to check your keystore files in. 55 | #*.jks 56 | #*.keystore 57 | 58 | # External native build folder generated in Android Studio 2.2 and later 59 | .externalNativeBuild 60 | .cxx/ 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Freeline 66 | freeline.py 67 | freeline/ 68 | freeline_project_description.json 69 | 70 | # fastlane 71 | fastlane/report.xml 72 | fastlane/Preview.html 73 | fastlane/screenshots 74 | fastlane/test_output 75 | fastlane/readme.md 76 | 77 | # Version control 78 | vcs.xml 79 | 80 | # lint 81 | lint/intermediates/ 82 | lint/generated/ 83 | lint/outputs/ 84 | lint/tmp/ 85 | # lint/reports/ 86 | 87 | *.iml 88 | .gradle 89 | /local.properties 90 | /.idea/* 91 | /.idea/caches 92 | /.idea/libraries 93 | /.idea/modules.xml 94 | /.idea/workspace.xml 95 | /.idea/navEditor.xml 96 | /.idea/assetWizardSettings.xml 97 | .idea/gradle.xml 98 | .idea/misc.xml 99 | .DS_Store 100 | /build 101 | /captures 102 | .externalNativeBuild 103 | .cxx 104 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FrameAnimation 2 | 3 | FrameAnimation是一个简洁流畅的高性能帧动画控件。 4 | 结合使用了TextureView和BlobCache,逐帧解析与绘制,避免了多帧的情况下使用Android原生AnimationDrawable带来的OOM和卡顿问题。 5 | 6 | 详细介绍文章:[OOM?高性能帧动画FrameAnimation-TextureView和BlobCache](https://blog.csdn.net/hewuzhao/article/details/109920572) 7 | 8 | BlobCache算法可以查看: 9 | 1. [BlobCache算法详解](https://blog.csdn.net/hewuzhao/article/details/108028320) 10 | 2. [BlobCache与DiskLruCache的读写对比](https://blog.csdn.net/hewuzhao/article/details/108696808) 11 | 12 | ## 示例 13 | 14 | 15 | 16 | ## 添加配置 17 | ``` 18 | dependencies { 19 | ... 20 | implementation 'com.hewuzhao.frameanimation:frameanimation:1.0.1' 21 | ... 22 | } 23 | ``` 24 | 25 | ## 使用方法 26 | **动画资源图片,在/res/drawable下建立xxx.xml文件:** 27 | ``` 28 | 34 | 35 | 38 | 41 | 44 | 47 | 50 | 53 | 56 | .... 57 | 58 | 59 | ``` 60 | 61 | |Attributes|format|describe| 62 | |-----|-----|-----| 63 | |maxBytes |integer |BlobCache缓存的最大容量,单位:字节 | 64 | |maxEntries |integer |BlobCache缓存的资源个数 | 65 | |version |integer |BlobCache版本号 | 66 | 67 | 68 | 69 | 70 | **在你的xml布局文件中使用:** 71 | ``` 72 | 78 | ``` 79 | |Attributes|format|describe| 80 | |-----|-----|-----| 81 | |src |reference |res/drawable下的资源列表 | 82 | |useCache |boolean |开关:是否使用BlobCache缓存 | 83 | 84 | 85 | **启动帧动画:** 86 | ``` 87 | FrameTextureView.startWithFrameSrc(R.drawable.xxx); 88 | ``` 89 | 90 | ## License 91 | ``` 92 | Copyright (C) hewuzhao, FrameAnimation Open Source Project 93 | 94 | Licensed under the Apache License, Version 2.0 (the "License"); 95 | you may not use this file except in compliance with the License. 96 | You may obtain a copy of the License at 97 | 98 | http://www.apache.org/licenses/LICENSE-2.0 99 | 100 | Unless required by applicable law or agreed to in writing, software 101 | distributed under the License is distributed on an "AS IS" BASIS, 102 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 103 | See the License for the specific language governing permissions and 104 | limitations under the License. 105 | ``` 106 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | defaultConfig { 7 | applicationId "com.hewuzhao.frameanimation" 8 | minSdkVersion 21 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'androidx.appcompat:appcompat:1.0.2' 25 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 26 | testImplementation 'junit:junit:4.12' 27 | androidTestImplementation 'androidx.test.ext:junit:1.1.0' 28 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 29 | implementation project(path: ':frameanimation') 30 | 31 | // test 32 | // implementation 'com.hewuzhao.frameanimation:frameanimation:1.0.1' 33 | 34 | implementation 'pub.devrel:easypermissions:3.0.0' 35 | } 36 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hewuzhao/frameanimation/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.hewuzhao.frameanimation; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("com.hewuzhao.frameanimation", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/hewuzhao/frameanimation/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.hewuzhao.frameanimation; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import androidx.appcompat.widget.AppCompatSpinner; 6 | 7 | import android.Manifest; 8 | import android.os.Bundle; 9 | import android.view.View; 10 | import android.widget.AdapterView; 11 | import android.widget.ArrayAdapter; 12 | import android.widget.Button; 13 | import android.widget.TextView; 14 | 15 | import com.hewuzhao.frameanimation.blobcache.BlobCacheManager; 16 | import com.hewuzhao.frameanimation.frameview.FrameScaleType; 17 | import com.hewuzhao.frameanimation.frameview.FrameTextureView; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import pub.devrel.easypermissions.EasyPermissions; 23 | 24 | /** 25 | * @author hewuzhao 26 | * @date 2020-02-10 27 | */ 28 | public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks { 29 | private static final String TAG = "MainActivity"; 30 | 31 | private final List SCALE_TYPE = Arrays.asList( 32 | "CENTER", 33 | "CENTER_INSIDE", 34 | "CENTER_CROP", 35 | "FIT_END", 36 | "FIT_CENTER", 37 | "FIT_START", 38 | "FIT_XY" 39 | ); 40 | 41 | private FrameTextureView mFrameView; 42 | private Button mSmallFrameBt; 43 | private Button mBtStop; 44 | private Button mBigFrameBt; 45 | private Button mCurrentSelectedBt; 46 | private AppCompatSpinner mScaleType; 47 | 48 | private boolean mIsInited = false; 49 | 50 | @Override 51 | protected void onCreate(Bundle savedInstanceState) { 52 | super.onCreate(savedInstanceState); 53 | setContentView(R.layout.activity_main); 54 | mFrameView = findViewById(R.id.frame_view); 55 | mSmallFrameBt = findViewById(R.id.small_frame_texture_view); 56 | mSmallFrameBt.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View v) { 59 | if (!mIsInited) { 60 | return; 61 | } 62 | mBtStop.setEnabled(true); 63 | updateCurrentSelectedBt(mSmallFrameBt); 64 | 65 | mFrameView.setVisibility(View.VISIBLE); 66 | showSmallFrameView(); 67 | } 68 | }); 69 | mBtStop = findViewById(R.id.bt_stop); 70 | mBtStop.setEnabled(false); 71 | mBtStop.setOnClickListener(new View.OnClickListener() { 72 | @Override 73 | public void onClick(View v) { 74 | if (mFrameView.isPause()) { 75 | mFrameView.resume(); 76 | mBtStop.setText("停止"); 77 | } else { 78 | pauseFrameViw(); 79 | mBtStop.setText("开始"); 80 | } 81 | } 82 | }); 83 | mBigFrameBt = findViewById(R.id.big_frame_texture_view); 84 | mBigFrameBt.setOnClickListener(new View.OnClickListener() { 85 | @Override 86 | public void onClick(View v) { 87 | if (!mIsInited) { 88 | return; 89 | } 90 | mBtStop.setEnabled(true); 91 | updateCurrentSelectedBt(mBigFrameBt); 92 | 93 | mFrameView.setVisibility(View.VISIBLE); 94 | showBigFrameView(); 95 | } 96 | }); 97 | 98 | mScaleType = findViewById(R.id.scale_type); 99 | mScaleType.setAdapter(new ArrayAdapter(this, R.layout.spinner_item_view, SCALE_TYPE)); 100 | mScaleType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 101 | @Override 102 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 103 | if (parent == null || view == null) { 104 | return; 105 | } 106 | if (view instanceof TextView) { 107 | String text = ((TextView) view).getText().toString(); 108 | int scaleType; 109 | switch (text) { 110 | case "CENTER": { 111 | scaleType = FrameScaleType.CENTER; 112 | break; 113 | } 114 | case "CENTER_INSIDE": { 115 | scaleType = FrameScaleType.CENTER_INSIDE; 116 | break; 117 | } 118 | case "CENTER_CROP": { 119 | scaleType = FrameScaleType.CENTER_CROP; 120 | break; 121 | } 122 | case "FIT_END": { 123 | scaleType = FrameScaleType.FIT_END; 124 | break; 125 | } 126 | case "FIT_CENTER": { 127 | scaleType = FrameScaleType.FIT_CENTER; 128 | break; 129 | } 130 | case "FIT_START": { 131 | scaleType = FrameScaleType.FIT_START; 132 | break; 133 | } 134 | default: { 135 | scaleType = FrameScaleType.FIT_XY; 136 | } 137 | } 138 | mFrameView.setScaleType(scaleType); 139 | } 140 | } 141 | 142 | @Override 143 | public void onNothingSelected(AdapterView parent) { 144 | 145 | } 146 | }); 147 | 148 | checkPermissions(); 149 | } 150 | 151 | private void updateCurrentSelectedBt(Button button) { 152 | if (mCurrentSelectedBt != null) { 153 | mCurrentSelectedBt.setEnabled(true); 154 | } 155 | mCurrentSelectedBt = button; 156 | mCurrentSelectedBt.setEnabled(false); 157 | } 158 | 159 | private void checkPermissions() { 160 | if (EasyPermissions.hasPermissions(this, Manifest.permission.READ_EXTERNAL_STORAGE, 161 | Manifest.permission.WRITE_EXTERNAL_STORAGE)) { 162 | init(); 163 | } else { 164 | EasyPermissions.requestPermissions(this, "test,test", 100, 165 | Manifest.permission.READ_EXTERNAL_STORAGE, 166 | Manifest.permission.WRITE_EXTERNAL_STORAGE); 167 | } 168 | } 169 | 170 | private void showSmallFrameView() { 171 | mFrameView.startWithFrameSrc(R.drawable.small_animation_drawable); 172 | } 173 | 174 | private void showBigFrameView() { 175 | mFrameView.startWithFrameSrc(R.drawable.big_animation_drawable); 176 | } 177 | 178 | private void pauseFrameViw() { 179 | mFrameView.pause(); 180 | } 181 | 182 | private void destroyFrameView() { 183 | mFrameView.destroy(); 184 | } 185 | 186 | 187 | private void init() { 188 | mIsInited = true; 189 | // TODO test 190 | mBigFrameBt.callOnClick(); 191 | } 192 | 193 | @Override 194 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 195 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 196 | // Forward results to EasyPermissions 197 | EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); 198 | } 199 | 200 | @Override 201 | public void onPermissionsGranted(int requestCode, @NonNull List perms) { 202 | if (requestCode == 100) { 203 | init(); 204 | } 205 | } 206 | 207 | @Override 208 | public void onPermissionsDenied(int requestCode, @NonNull List perms) { 209 | 210 | } 211 | 212 | @Override 213 | protected void onDestroy() { 214 | super.onDestroy(); 215 | destroyFrameView(); 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /app/src/main/java/com/hewuzhao/frameanimation/TestActivity.java: -------------------------------------------------------------------------------- 1 | package com.hewuzhao.frameanimation; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | 9 | public class TestActivity extends AppCompatActivity { 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_test); 15 | findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 16 | @Override 17 | public void onClick(View v) { 18 | startActivity(new Intent(TestActivity.this, MainActivity.class)); 19 | } 20 | }); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_00.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_01.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_02.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_03.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_04.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_05.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_06.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_07.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_08.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_09.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_10.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_11.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_12.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_13.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_14.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_15.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_16.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_17.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_18.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/big_19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/big_19.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_00.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_00.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_01.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_02.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_03.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_04.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_05.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_06.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_07.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_08.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_08.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_09.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_09.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_10.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_11.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_12.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_13.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_14.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_15.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_16.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_17.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_17.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_18.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/small_19.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hewuzhao/FrameAnimation/f739fd6ff261693a61c0057a19fd295ee0c7c024/app/src/main/res/drawable-xxhdpi/small_19.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/big_animation_drawable.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 11 | 14 | 17 | 20 | 23 | 26 | 29 | 32 | 35 | 38 | 41 | 44 | 47 | 50 | 53 | 56 | 59 | 62 | 65 | 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/small_animation_drawable.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 11 | 14 | 17 | 20 | 23 | 26 | 29 | 32 | 35 | 38 | 41 | 44 | 47 | 50 | 53 | 56 | 59 | 62 | 65 | 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 19 | 20 | 29 | 30 | 39 | 40 |