├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── README_ZH.md ├── ScreenShot.PNG ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── huawei │ │ └── image │ │ └── render │ │ └── sample │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── AlphaAnimation │ │ │ ├── aixin7.png │ │ │ ├── bj.jpg │ │ │ └── manifest.xml │ │ ├── DropPhysicalView │ │ │ ├── background.jpg │ │ │ ├── jinbi.png │ │ │ ├── manifest.xml │ │ │ ├── shiwu.png │ │ │ └── xx.png │ │ ├── FlipBook │ │ │ ├── bg1.jpg │ │ │ ├── bg2.jpg │ │ │ ├── bg3.jpg │ │ │ ├── front.jpg │ │ │ └── manifest.xml │ │ ├── Marquee │ │ │ ├── bj.jpg │ │ │ └── manifest.xml │ │ ├── MeshImage │ │ │ ├── background.jpg │ │ │ ├── manifest.xml │ │ │ └── part.png │ │ ├── Paint │ │ │ ├── bg.jpg │ │ │ ├── manifest.xml │ │ │ ├── part.png │ │ │ └── part_2.png │ │ ├── ParticleScatter │ │ │ ├── bj.jpg │ │ │ ├── manifest.xml │ │ │ └── maojiao.png │ │ ├── ParticleView │ │ │ ├── background.jpg │ │ │ ├── manifest.xml │ │ │ └── particle.png │ │ ├── PositionAnimation │ │ │ ├── bj.jpg │ │ │ ├── manifest.xml │ │ │ └── ty.png │ │ ├── RotateView │ │ │ ├── 1.jpg │ │ │ ├── bj.jpg │ │ │ └── manifest.xml │ │ ├── RotationAnimation │ │ │ ├── bj.jpg │ │ │ ├── manifest.xml │ │ │ └── ty.png │ │ ├── SizeAnimation │ │ │ ├── default_background.jpg │ │ │ ├── manifest.xml │ │ │ └── ty.png │ │ ├── SourcesAnimation │ │ │ ├── bj.jpg │ │ │ ├── manifest.xml │ │ │ ├── zuida1_1.png │ │ │ ├── zuida1_2.png │ │ │ ├── zuida1_3.png │ │ │ ├── zuida1_4.png │ │ │ └── zuida1_5.png │ │ └── WaterWallpaper │ │ │ ├── background.jpg │ │ │ └── manifest.xml │ ├── ic_launcher-playstore.png │ ├── java │ │ └── com │ │ │ └── huawei │ │ │ └── image │ │ │ └── render │ │ │ └── sample │ │ │ ├── activity │ │ │ ├── ImageKitRenderDemoActivity.kt │ │ │ └── ImageKitRenderDemoActivity1.kt │ │ │ └── util │ │ │ └── Utils.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_entries.xml │ │ ├── activity_image_kit_demo.xml │ │ ├── activity_image_kit_demo_1.xml │ │ ├── activity_main.xml │ │ └── recycler_view.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── values-zh-rCN │ │ └── strings.xml │ │ └── values │ │ ├── arrays.xml │ │ ├── colors.xml │ │ ├── ic_launcher_background.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── huawei │ └── image │ └── render │ └── sample │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── render.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 | 116 | 118 |
119 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | 39 | 40 | 44 | 45 | 49 | 50 | 54 | 55 | 59 | 60 | 64 | 65 | 69 | 70 | 74 | 75 | 79 | 80 | 84 | 85 | 89 | 90 | 94 | 95 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## HUAWEI Image Kit Render Sample for Kotlin 2 | 3 | English | [中文](README_ZH.md) 4 | 5 | ## Table of Contents 6 | 7 | * [Introduction](#introduction) 8 | * [Getting Started](#getting-started) 9 | * [Supported Environments](#supported-environments) 10 | * [Result](#result) 11 | * [License](#license) 12 | 13 | ## Introduction 14 | The Image Render service provides basic and advanced animation effects to help you reproduce image contents in an efficient way. This sample code encapsulates APIs of the HUAWEI Image Kit Render Service, it provides a sample programs for your reference or usage. 15 | 16 | 1. Supports five basic animations and any of their combination. 17 | 18 | 2. Provides nine advanced animation effects, bringing more fun to user interactions. 19 | 20 | For details, please refer to [XML Syntax Specifications for Image Render](https://developer.huawei.com/consumer/en/doc/development/Media-Guides/xml-introduction-0000001050439245?ha_source=hms1). 21 | 22 | ## Getting Started 23 | 1. Check whether the Android studio development environment is ready. Open the sample code project directory with file "build.gradle" in Android Studio. Run TestApp on your divice or simulator which have installed latest Huawei Mobile Service(HMS). 24 | 2. Register a [HUAWEI account](https://developer.huawei.com/consumer/en/). 25 | 3. Create an app and configure the app information in AppGallery Connect. 26 | See details: [HUAWEI Image Service Development Preparation](https://developer.huawei.com/consumer/en/doc/development/Media-Guides/config-agc-0000001050199019?ha_source=hms1) 27 | 4. To build this demo, please first import the demo in the Android Studio (3.x+). 28 | 5. Run the sample on your Android device or emulator. 29 | 30 | ## Supported Environments 31 | - Android Studio 3.0 or later. 32 | 33 | - Java SDK 1.8 or later. 34 | 35 | - Android SDK version is 26 or later. 36 | 37 | - Gradle 3.3.2. 38 | 39 | - HMS Core (APK) 4.0.2.300 or later(applicable to the SDK, but not the fallback-SDK). 40 | 41 | 42 | ## Result 43 | 44 | 45 | 46 | ## License 47 | 48 | ImageRenderSample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0). 49 | -------------------------------------------------------------------------------- /README_ZH.md: -------------------------------------------------------------------------------- 1 | # 华为图像服务场景动效Kotlin示例代码 2 | 3 | [English](README.md) | 中文 4 | 5 | ## 目录 6 | 7 | * [简介](#简介) 8 | * [开发准备](#开发准备) 9 | * [环境要求](#环境要求) 10 | * [运行结果](#运行结果) 11 | * [授权许可](#授权许可) 12 | 13 | ## 简介 14 | 场景动效服务提供基础动效和高级动效,帮助您实现图片内容高效再生产。本示例代码对华为图像服务场景动效接口进行封装,包含丰富的示例程序,方便您参考或直接使用。 15 | 16 | 1. 提供5种基础动效,并支持多动效叠加使用。 17 | 18 | 2. 提供9种效果炫酷的高级动效,并支持用户交互。 19 | 20 | 更多信息请参见[场景动效xml规范说明文档](https://developer.huawei.com/consumer/cn/doc/development/Media-Guides/xml-introduction-0000001050439245?ha_source=hms1). 21 | 22 | ## 开发准备 23 | 1. 检查Android Studio开发环境是否就绪。将示例工程导入Android Studio(3.0及以上版本)中。 24 | 2. 在Android Studio中打开示例工程项目级build.gradle文件,并在您已安装最新版华为移动服务的设备或模拟器上运行测试应用。 25 | 3. 注册[华为帐号](https://developer.huawei.com/consumer/cn/)。 26 | 4. 创建应用并在AppGallery Connect中配置相关信息。具体请参考[开发准备](https://developer.huawei.com/consumer/cn/doc/development/Media-Guides/config-agc-0000001050199019?ha_source=hms1)。 27 | 5. 在Android设备或模拟器上运行您的应用。 28 | 29 | ## 环境要求 30 | - Android Studio 3.0及以上 31 | 32 | - JDK 1.8及以上 33 | 34 | - Android SDK 26及以上 35 | 36 | - Gradle 3.3.2 37 | 38 | - HMS Core (APK) 4.0.2.300及以上(仅依赖SDK情况下需要满足此要求,fallback-SDK无此要求) 39 | 40 | 41 | ## 运行结果 42 | 43 | 44 | 45 | ## 技术支持 46 | 如果您对HMS Core还处于评估阶段,可在[Reddit社区](https://www.reddit.com/r/HuaweiDevelopers/)获取关于HMS Core的最新讯息,并与其他开发者交流见解。 47 | 48 | 如果您对使用HMS示例代码有疑问,请尝试: 49 | - 开发过程遇到问题上[Stack Overflow](https://stackoverflow.com/questions/tagged/huawei-mobile-services),在`huawei-mobile-services`标签下提问,有华为研发专家在线一对一解决您的问题。 50 | - 到[华为开发者论坛](https://developer.huawei.com/consumer/cn/forum/blockdisplay?fid=18) HMS Core板块与其他开发者进行交流。 51 | 52 | 如果您在尝试示例代码中遇到问题,请向仓库提交[issue](https://github.com/HMS-Core/hms-image-render-java/issues),也欢迎您提交[Pull Request](https://github.com/HMS-Core/hms-image-render-java/pulls)。 53 | 54 | ## 授权许可 55 | 场景动效Java示例代码经过[Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0)授权许可。 56 | -------------------------------------------------------------------------------- /ScreenShot.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/ScreenShot.PNG -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'com.huawei.agconnect' 5 | 6 | android { 7 | compileSdkVersion 28 8 | buildToolsVersion "28.0.3" 9 | defaultConfig { 10 | applicationId "com.huawei.image.render.sample" 11 | minSdkVersion 26 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | } 16 | 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 21 | } 22 | lintOptions { 23 | abortOnError false 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 31 | implementation 'com.android.support:appcompat-v7:28.0.0' 32 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 33 | testImplementation 'junit:junit:4.12' 34 | implementation('com.huawei.hms:image-render:1.0.3.301') 35 | implementation('com.huawei.hms:image-render-fallback:1.0.3.301') 36 | } 37 | -------------------------------------------------------------------------------- /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/huawei/image/render/sample/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.huawei.image.render.sample 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.huawei.image.render.sample", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/assets/AlphaAnimation/aixin7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/AlphaAnimation/aixin7.png -------------------------------------------------------------------------------- /app/src/main/assets/AlphaAnimation/bj.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/AlphaAnimation/bj.jpg -------------------------------------------------------------------------------- /app/src/main/assets/AlphaAnimation/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/assets/DropPhysicalView/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/DropPhysicalView/background.jpg -------------------------------------------------------------------------------- /app/src/main/assets/DropPhysicalView/jinbi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/DropPhysicalView/jinbi.png -------------------------------------------------------------------------------- /app/src/main/assets/DropPhysicalView/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/assets/DropPhysicalView/shiwu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/DropPhysicalView/shiwu.png -------------------------------------------------------------------------------- /app/src/main/assets/DropPhysicalView/xx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/DropPhysicalView/xx.png -------------------------------------------------------------------------------- /app/src/main/assets/FlipBook/bg1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/FlipBook/bg1.jpg -------------------------------------------------------------------------------- /app/src/main/assets/FlipBook/bg2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/FlipBook/bg2.jpg -------------------------------------------------------------------------------- /app/src/main/assets/FlipBook/bg3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/FlipBook/bg3.jpg -------------------------------------------------------------------------------- /app/src/main/assets/FlipBook/front.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/FlipBook/front.jpg -------------------------------------------------------------------------------- /app/src/main/assets/FlipBook/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/assets/Marquee/bj.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/Marquee/bj.jpg -------------------------------------------------------------------------------- /app/src/main/assets/Marquee/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/assets/MeshImage/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/MeshImage/background.jpg -------------------------------------------------------------------------------- /app/src/main/assets/MeshImage/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/assets/MeshImage/part.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/MeshImage/part.png -------------------------------------------------------------------------------- /app/src/main/assets/Paint/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/Paint/bg.jpg -------------------------------------------------------------------------------- /app/src/main/assets/Paint/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/assets/Paint/part.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/Paint/part.png -------------------------------------------------------------------------------- /app/src/main/assets/Paint/part_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/Paint/part_2.png -------------------------------------------------------------------------------- /app/src/main/assets/ParticleScatter/bj.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/ParticleScatter/bj.jpg -------------------------------------------------------------------------------- /app/src/main/assets/ParticleScatter/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/assets/ParticleScatter/maojiao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/ParticleScatter/maojiao.png -------------------------------------------------------------------------------- /app/src/main/assets/ParticleView/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/ParticleView/background.jpg -------------------------------------------------------------------------------- /app/src/main/assets/ParticleView/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/assets/ParticleView/particle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/ParticleView/particle.png -------------------------------------------------------------------------------- /app/src/main/assets/PositionAnimation/bj.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/PositionAnimation/bj.jpg -------------------------------------------------------------------------------- /app/src/main/assets/PositionAnimation/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/assets/PositionAnimation/ty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/PositionAnimation/ty.png -------------------------------------------------------------------------------- /app/src/main/assets/RotateView/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/RotateView/1.jpg -------------------------------------------------------------------------------- /app/src/main/assets/RotateView/bj.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/RotateView/bj.jpg -------------------------------------------------------------------------------- /app/src/main/assets/RotateView/manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/assets/RotationAnimation/bj.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/RotationAnimation/bj.jpg -------------------------------------------------------------------------------- /app/src/main/assets/RotationAnimation/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/assets/RotationAnimation/ty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/RotationAnimation/ty.png -------------------------------------------------------------------------------- /app/src/main/assets/SizeAnimation/default_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/SizeAnimation/default_background.jpg -------------------------------------------------------------------------------- /app/src/main/assets/SizeAnimation/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/assets/SizeAnimation/ty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/SizeAnimation/ty.png -------------------------------------------------------------------------------- /app/src/main/assets/SourcesAnimation/bj.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/SourcesAnimation/bj.jpg -------------------------------------------------------------------------------- /app/src/main/assets/SourcesAnimation/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/assets/SourcesAnimation/zuida1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/SourcesAnimation/zuida1_1.png -------------------------------------------------------------------------------- /app/src/main/assets/SourcesAnimation/zuida1_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/SourcesAnimation/zuida1_2.png -------------------------------------------------------------------------------- /app/src/main/assets/SourcesAnimation/zuida1_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/SourcesAnimation/zuida1_3.png -------------------------------------------------------------------------------- /app/src/main/assets/SourcesAnimation/zuida1_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/SourcesAnimation/zuida1_4.png -------------------------------------------------------------------------------- /app/src/main/assets/SourcesAnimation/zuida1_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/SourcesAnimation/zuida1_5.png -------------------------------------------------------------------------------- /app/src/main/assets/WaterWallpaper/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/assets/WaterWallpaper/background.jpg -------------------------------------------------------------------------------- /app/src/main/assets/WaterWallpaper/manifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HMS-Core/hms-image-render-kotlin/6e213394fa98f315f89cb1a7360d293191585715/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /app/src/main/java/com/huawei/image/render/sample/activity/ImageKitRenderDemoActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.huawei.image.render.sample.activity 17 | 18 | import android.Manifest 19 | import android.app.Activity 20 | import android.content.Intent 21 | import android.content.pm.PackageManager 22 | import android.os.Bundle 23 | import android.os.Environment 24 | import android.support.v4.app.ActivityCompat 25 | import android.support.v4.content.ContextCompat 26 | import android.util.Log 27 | import android.view.View 28 | import android.view.WindowManager 29 | import android.widget.* 30 | import android.widget.AdapterView.OnItemSelectedListener 31 | import com.huawei.hms.image.render.* 32 | import com.huawei.hms.image.render.ImageRender.RenderCallBack 33 | import com.huawei.image.render.sample.R 34 | import com.huawei.image.render.sample.activity.ImageKitRenderDemoActivity 35 | import com.huawei.image.render.sample.util.Utils 36 | import org.json.JSONException 37 | import org.json.JSONObject 38 | import java.io.File 39 | import java.io.FileOutputStream 40 | import java.io.IOException 41 | import java.util.* 42 | 43 | /** 44 | * The ImageRenderSample code provides examples of initializing the service, obtaining views, playing animation, pausing animation, and destroying resources. 45 | * 46 | * @author huawei 47 | * @since 5.0.0 48 | */ 49 | class ImageKitRenderDemoActivity : Activity() { 50 | /** 51 | * Layout container 52 | */ 53 | private var contentView: FrameLayout? = null 54 | 55 | // imageRender object 56 | private var imageRenderAPI: ImageRenderImpl? = null 57 | private var sourcePath: String? = null 58 | private var textProgress: TextView? = null 59 | private var mCurrentDemo: String? = null 60 | private var marqueeVis = 1 61 | private var hashCode: String? = null 62 | override fun onCreate(savedInstanceState: Bundle?) { 63 | super.onCreate(savedInstanceState) 64 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) 65 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) 66 | window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN 67 | setContentView(R.layout.activity_image_kit_demo) 68 | sourcePath = 69 | filesDir.path + File.separator + SOURCE_PATH 70 | initView() 71 | val permissionCheck = ContextCompat.checkSelfPermission( 72 | this@ImageKitRenderDemoActivity, 73 | Manifest.permission.WRITE_EXTERNAL_STORAGE 74 | ) 75 | if (permissionCheck == PackageManager.PERMISSION_GRANTED) { 76 | initData() 77 | initImageRender() 78 | } else { 79 | ActivityCompat.requestPermissions( 80 | this@ImageKitRenderDemoActivity, 81 | arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 82 | PERMISSION_REQUEST_CODE 83 | ) 84 | } 85 | } 86 | 87 | /** 88 | * Initialize the view. 89 | */ 90 | private fun initView() { 91 | contentView = findViewById(R.id.content) 92 | textProgress = findViewById(R.id.text_progress) 93 | val spinner = 94 | findViewById(R.id.spinner_animations) 95 | spinner.onItemSelectedListener = object : OnItemSelectedListener { 96 | override fun onItemSelected( 97 | parent: AdapterView<*>?, 98 | view: View, 99 | position: Int, 100 | id: Long 101 | ) { 102 | mCurrentDemo = spinner.adapter.getItem(position).toString() 103 | changeAnimation(mCurrentDemo!!) 104 | } 105 | 106 | override fun onNothingSelected(parent: AdapterView<*>?) {} 107 | } 108 | } 109 | 110 | /** 111 | * change the animation which is choose in spinner 112 | * @param animationName animationName 113 | */ 114 | private fun changeAnimation(animationName: String) { 115 | if (!Utils.copyAssetsFilesToDirs( 116 | this, 117 | animationName, 118 | sourcePath.toString() 119 | ) 120 | ) { 121 | Log.e( 122 | TAG, 123 | "copy files failure, please check permissions" 124 | ) 125 | return 126 | } 127 | if (imageRenderAPI == null) { 128 | Log.e( 129 | TAG, 130 | "initRemote fail, please check kit version" 131 | ) 132 | return 133 | } 134 | if (contentView!!.childCount > 0) { 135 | imageRenderAPI!!.removeRenderView() 136 | contentView!!.removeAllViews() 137 | addView() 138 | } 139 | } 140 | 141 | /** 142 | * Create default resources. 143 | * You can compile the manifest.xml file and image resource file. The code is for reference only. 144 | */ 145 | private fun initData() { 146 | // Absolute path of the resource files. 147 | if (!Utils.createResourceDirs(sourcePath)) { 148 | Log.e( 149 | TAG, 150 | "Create dirs fail, please check permission" 151 | ) 152 | } 153 | if (!Utils.copyAssetsFileToDirs( 154 | this, 155 | "AlphaAnimation" + File.separator + "aixin7.png", 156 | sourcePath + File.separator + "aixin7.png" 157 | ) 158 | ) { 159 | Log.e( 160 | TAG, 161 | "Copy resource file fail, please check permission" 162 | ) 163 | } 164 | if (!Utils.copyAssetsFileToDirs( 165 | this, 166 | "AlphaAnimation" + File.separator + "bj.jpg", 167 | sourcePath + File.separator + "bj.jpg" 168 | ) 169 | ) { 170 | Log.e( 171 | TAG, 172 | "Copy resource file fail, please check permission" 173 | ) 174 | } 175 | if (!Utils.copyAssetsFileToDirs( 176 | this, 177 | "AlphaAnimation" + File.separator + "manifest.xml", 178 | sourcePath + File.separator + "manifest.xml" 179 | ) 180 | ) { 181 | Log.e( 182 | TAG, 183 | "Copy resource file fail, please check permission" 184 | ) 185 | } 186 | } 187 | 188 | /** 189 | * Use the ImageRender API. 190 | */ 191 | private fun initImageRender() { 192 | // Obtain an ImageRender object. 193 | ImageRender.getInstance(this, object : RenderCallBack { 194 | override fun onSuccess(imageRender: ImageRenderImpl) { 195 | Log.i( 196 | TAG, 197 | "getImageRenderAPI success" 198 | ) 199 | imageRenderAPI = imageRender 200 | useImageRender() 201 | } 202 | 203 | override fun onFailure(i: Int) { 204 | Log.e( 205 | TAG, 206 | "getImageRenderAPI failure, errorCode = $i" 207 | ) 208 | } 209 | }) 210 | } 211 | 212 | /** 213 | * The Image Render service is required. 214 | */ 215 | private fun useImageRender() { 216 | if (imageRenderAPI == null) { 217 | Log.e( 218 | TAG, 219 | "initRemote fail, please check kit version" 220 | ) 221 | return 222 | } 223 | addView() 224 | } 225 | 226 | private fun addView() { 227 | // Initialize the ImageRender object. 228 | val initResult = imageRenderAPI!!.doInit( 229 | sourcePath, 230 | Utils.authJson 231 | ) 232 | Log.i( 233 | TAG, 234 | "DoInit result == $initResult" 235 | ) 236 | if (initResult == 0) { 237 | // Obtain the rendered view. 238 | val renderView = imageRenderAPI!!.renderView 239 | if (renderView.getResultCode() == ResultCode.SUCCEED) { 240 | val view = renderView.getView() 241 | if (null != view) { 242 | // Add the rendered view to the layout. 243 | contentView!!.addView(view) 244 | hashCode = view.hashCode().toString() 245 | } else { 246 | Log.w( 247 | TAG, 248 | "GetRenderView fail, view is null" 249 | ) 250 | } 251 | } else if (renderView.getResultCode() == ResultCode.ERROR_GET_RENDER_VIEW_FAILURE) { 252 | Log.w(TAG, "GetRenderView fail") 253 | } else if (renderView.getResultCode() == ResultCode.ERROR_XSD_CHECK_FAILURE) { 254 | Log.w( 255 | TAG, 256 | "GetRenderView fail, resource file parameter error, please check resource file." 257 | ) 258 | } else if (renderView.getResultCode() == ResultCode.ERROR_VIEW_PARSE_FAILURE) { 259 | Log.w( 260 | TAG, 261 | "GetRenderView fail, resource file parsing failed, please check resource file." 262 | ) 263 | } else if (renderView.getResultCode() == ResultCode.ERROR_REMOTE) { 264 | Log.w( 265 | TAG, 266 | "GetRenderView fail, remote call failed, please check HMS service" 267 | ) 268 | } else if (renderView.getResultCode() == ResultCode.ERROR_DOINIT) { 269 | Log.w( 270 | TAG, 271 | "GetRenderView fail, init failed, please init again" 272 | ) 273 | } 274 | } else { 275 | Log.w( 276 | TAG, 277 | "Do init fail, errorCode == $initResult" 278 | ) 279 | } 280 | } 281 | 282 | override fun onDestroy() { 283 | // Destroy the view. 284 | if (null != imageRenderAPI) { 285 | imageRenderAPI!!.removeRenderView() 286 | } 287 | super.onDestroy() 288 | } 289 | 290 | override fun onResume() { 291 | super.onResume() 292 | Log.i(TAG, "onResume") 293 | if (null != imageRenderAPI) { 294 | imageRenderAPI!!.bindRenderView( 295 | sourcePath, 296 | Utils.authJson, 297 | object : IBindCallBack { 298 | override fun onBind(renderView: RenderView, i: Int) { 299 | if (renderView != null) { 300 | if (renderView.getResultCode() == ResultCode.SUCCEED) { 301 | val view = renderView.getView() 302 | if (null != view) { 303 | contentView!!.addView(view) 304 | hashCode = view.hashCode().toString() 305 | } 306 | } 307 | } 308 | } 309 | 310 | override fun onParseEnd() {} 311 | }) 312 | } 313 | } 314 | 315 | /** 316 | * Play the animation. 317 | * 318 | * @param view button 319 | */ 320 | fun startAnimation(view: View?) { 321 | // Play the rendered view. 322 | Log.i(TAG, "Start animation") 323 | if (null != imageRenderAPI) { 324 | val playResult = imageRenderAPI!!.playAnimation() 325 | if (playResult == ResultCode.SUCCEED) { 326 | Log.i( 327 | TAG, 328 | "Start animation success" 329 | ) 330 | } else { 331 | Log.i( 332 | TAG, 333 | "Start animation failure" 334 | ) 335 | } 336 | } else { 337 | Log.w( 338 | TAG, 339 | "Start animation fail, please init first." 340 | ) 341 | } 342 | } 343 | 344 | /** 345 | * Stop the animation. 346 | * 347 | * @param view button 348 | */ 349 | fun stopAnimation(view: View?) { 350 | // Stop the renderView animation. 351 | Log.i(TAG, "Stop animation") 352 | if (null != imageRenderAPI) { 353 | val playResult = imageRenderAPI!!.stopAnimation() 354 | if (playResult == ResultCode.SUCCEED) { 355 | Log.i( 356 | TAG, 357 | "Stop animation success" 358 | ) 359 | } else { 360 | Log.i( 361 | TAG, 362 | "Stop animation failure" 363 | ) 364 | } 365 | } else { 366 | Log.w( 367 | TAG, 368 | "Stop animation fail, please init first." 369 | ) 370 | } 371 | } 372 | 373 | /** 374 | * Pause animation 375 | * 376 | * @param view button 377 | */ 378 | fun pauseAnimation(view: View?) { 379 | if (imageRenderAPI != null) { 380 | val result = imageRenderAPI!!.pauseAnimation(true) 381 | Log.d( 382 | TAG, 383 | "pauseAnimation result == $result" 384 | ) 385 | } 386 | } 387 | 388 | /** 389 | * Resume animation 390 | * 391 | * @param view button 392 | */ 393 | fun resumeAnimation(view: View?) { 394 | if (imageRenderAPI != null) { 395 | val result = imageRenderAPI!!.resumeAnimation() 396 | Log.d( 397 | TAG, 398 | "resumeAnimation result == $result" 399 | ) 400 | } 401 | } 402 | 403 | /** 404 | * Set variable value 405 | * 406 | * @param view button 407 | */ 408 | fun setVariable(view: View?) { 409 | if ("Marquee" == mCurrentDemo) { 410 | marqueeVis = 1 - marqueeVis 411 | imageRenderAPI!!.setKeyValueInfo("SetVariable", "var", "" + marqueeVis) 412 | } 413 | } 414 | 415 | override fun onPause() { 416 | super.onPause() 417 | Log.i(TAG, "onPause") 418 | if (null != imageRenderAPI) { 419 | imageRenderAPI!!.unBindRenderView(hashCode) 420 | } 421 | } 422 | 423 | /** 424 | * Next page 425 | * 426 | * @param view button 427 | */ 428 | fun nextPage(view: View?) { 429 | val intent = 430 | Intent(this@ImageKitRenderDemoActivity, ImageKitRenderDemoActivity1::class.java) 431 | startActivity(intent) 432 | } 433 | 434 | /** 435 | * Start record. 436 | * 437 | * @param view button 438 | */ 439 | fun startRecord(view: View?) { 440 | Log.d( 441 | "#######start record:", 442 | System.currentTimeMillis().toString() + "" 443 | ) 444 | Toast.makeText(this, "start record", Toast.LENGTH_SHORT).show() 445 | if (null != imageRenderAPI) { 446 | val result = recordInfo 447 | val start = imageRenderAPI!!.startRecord(result, object : IStreamCallBack { 448 | override fun onRecordSuccess(hashMap: HashMap) { 449 | runOnUiThread { 450 | Toast.makeText( 451 | this@ImageKitRenderDemoActivity, 452 | "record success", 453 | Toast.LENGTH_SHORT 454 | ).show() 455 | } 456 | saveRecordResult(hashMap) 457 | } 458 | 459 | override fun onRecordFailure(hashMap: HashMap) { 460 | val errorCode = hashMap["errorCode"] as Int 461 | val errorMessage = hashMap["errorMessage"] as String? 462 | Log.i( 463 | TAG, 464 | "back result$errorCode;back msg$errorMessage" 465 | ) 466 | } 467 | 468 | // progress:{1-100} 469 | override fun onProgress(progress: Int) { 470 | showRecordProgress(progress) 471 | } 472 | }) 473 | if (start == ResultCode.SUCCEED) { 474 | Log.i(TAG, "start record success") 475 | } else { 476 | Log.i( 477 | TAG, 478 | "start record failure:$start" 479 | ) 480 | } 481 | } else { 482 | Log.w( 483 | TAG, 484 | "start record fail, please init first." 485 | ) 486 | } 487 | } 488 | 489 | private val recordInfo: JSONObject 490 | private get() { 491 | val result = JSONObject() 492 | val recordType = 493 | (findViewById(R.id.recordtype) as EditText).text.toString() 494 | val videoScale = 495 | (findViewById(R.id.videoscale) as EditText).text.toString() 496 | val videoFps = 497 | (findViewById(R.id.videofps) as EditText).text.toString() 498 | val gifScale = 499 | (findViewById(R.id.gifscale) as EditText).text.toString() 500 | val gifFps = 501 | (findViewById(R.id.giffps) as EditText).text.toString() 502 | try { 503 | val videoJson = JSONObject() 504 | val gifJson = JSONObject() 505 | result.put("recordType", recordType) 506 | videoJson.put("videoScale", videoScale) 507 | videoJson.put("videoFps", videoFps) 508 | gifJson.put("gifScale", gifScale) 509 | gifJson.put("gifFps", gifFps) 510 | result.put("video", videoJson) 511 | result.put("gif", gifJson) 512 | } catch (e: JSONException) { 513 | Log.w(TAG, e.message) 514 | } 515 | return result 516 | } 517 | 518 | private fun saveRecordResult(hashMap: HashMap) { 519 | val fileName = (Environment.getExternalStorageDirectory() 520 | .toString() + File.separator 521 | + "VideoAndPic") 522 | val fileDir = File(fileName) 523 | if (!fileDir.exists()) { 524 | if (!fileDir.mkdir()) { 525 | return 526 | } 527 | } 528 | val mp4Path = 529 | fileName + File.separator + System.currentTimeMillis() + ".mp4" 530 | val gifPath = 531 | fileName + File.separator + System.currentTimeMillis() + ".gif" 532 | val recordType = hashMap["recordType"] as String? 533 | val videoBytes = hashMap["videoBytes"] as ByteArray? 534 | val gifBytes = hashMap["gifBytes"] as ByteArray? 535 | try { 536 | if (recordType == "1") { 537 | videoBytes?.let { saveFile(it, mp4Path) } 538 | } else if (recordType == "2") { 539 | gifBytes?.let { saveFile(it, gifPath) } 540 | } else if (recordType == "3") { 541 | videoBytes?.let { saveFile(it, mp4Path) } 542 | gifBytes?.let { saveFile(it, gifPath) } 543 | } 544 | } catch (e: IOException) { 545 | Log.w(TAG, e.message) 546 | } 547 | } 548 | 549 | @Throws(IOException::class) 550 | private fun saveFile(bytes: ByteArray, path: String) { 551 | val fos = FileOutputStream(File(path)) 552 | try { 553 | fos.write(bytes, 0, bytes.size) 554 | fos.close() 555 | } catch (e: IOException) { 556 | Log.e(TAG, e.message) 557 | } finally { 558 | try { 559 | fos.close() 560 | } catch (e: IOException) { 561 | Log.e(TAG, e.message) 562 | } 563 | } 564 | } 565 | 566 | private fun showRecordProgress(progress: Int) { 567 | runOnUiThread { textProgress!!.text = "progress:$progress%" } 568 | } 569 | 570 | /** 571 | * Stop record. 572 | * 573 | * @param view button 574 | */ 575 | fun stopRecord(view: View?) { 576 | Toast.makeText(this, "stop record", Toast.LENGTH_SHORT).show() 577 | if (null != imageRenderAPI) { 578 | val result = imageRenderAPI!!.stopRecord() 579 | if (result == ResultCode.SUCCEED) { 580 | Log.i(TAG, "stop record success") 581 | } else { 582 | Log.i(TAG, "stop record failure:$result") 583 | } 584 | } else { 585 | Log.w( 586 | TAG, 587 | "stop record fail, please init first." 588 | ) 589 | } 590 | } 591 | 592 | override fun onRequestPermissionsResult( 593 | requestCode: Int, 594 | permissions: Array, 595 | grantResults: IntArray 596 | ) { 597 | if (requestCode == PERMISSION_REQUEST_CODE) { 598 | if (grantResults.size > 0 599 | && grantResults[0] == PackageManager.PERMISSION_GRANTED 600 | ) { 601 | // The permission is granted. 602 | initData() 603 | initImageRender() 604 | } else { 605 | // The permission is rejected. 606 | Log.w(TAG, "permission denied") 607 | Toast.makeText( 608 | this@ImageKitRenderDemoActivity, 609 | "Please grant the app the permission to read the SD card", 610 | Toast.LENGTH_SHORT 611 | ).show() 612 | } 613 | } 614 | } 615 | 616 | companion object { 617 | /** 618 | * TAG 619 | */ 620 | const val TAG = "ImageKitRenderDemo" 621 | 622 | /** 623 | * Resource folder, which can be set as you want. 624 | */ 625 | const val SOURCE_PATH = "sources" 626 | 627 | /** 628 | * requestCode for applying for permissions. 629 | */ 630 | const val PERMISSION_REQUEST_CODE = 0x01 631 | } 632 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huawei/image/render/sample/activity/ImageKitRenderDemoActivity1.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.huawei.image.render.sample.activity 17 | 18 | import android.annotation.SuppressLint 19 | import android.app.Activity 20 | import android.os.Build 21 | import android.os.Bundle 22 | import android.os.SystemClock 23 | import android.support.annotation.RequiresApi 24 | import android.util.Log 25 | import android.view.View 26 | import android.view.WindowManager 27 | import android.widget.FrameLayout 28 | import com.huawei.hms.image.render.* 29 | import com.huawei.hms.image.render.ImageRender.RenderCallBack 30 | import com.huawei.image.render.sample.R 31 | import com.huawei.image.render.sample.util.Utils 32 | import java.io.File 33 | 34 | /** 35 | * 功能描述 36 | * 37 | * @author c00511068 38 | * @since 2020-09-07 39 | */ 40 | class ImageKitRenderDemoActivity1 : Activity() { 41 | /** 42 | * 布Layout container 43 | */ 44 | private var contentView: FrameLayout? = null 45 | 46 | // imageRender object 47 | private var imageRenderAPI: ImageRenderImpl? = null 48 | 49 | // Resource folder, which can be set as you want. 50 | private var sourcePath: String? = null 51 | private var hashCode: String? = null 52 | private var view: View? = null 53 | 54 | @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) 55 | override fun onCreate(savedInstanceState: Bundle?) { 56 | super.onCreate(savedInstanceState) 57 | Log.i(TAG, "onCreate") 58 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) 59 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) 60 | window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN 61 | setContentView(R.layout.activity_image_kit_demo_1) 62 | sourcePath = 63 | filesDir.path + File.separator + ImageKitRenderDemoActivity.SOURCE_PATH 64 | initView() 65 | initImageRender() 66 | } 67 | 68 | /** 69 | * Initialize the view. 70 | */ 71 | @SuppressLint("ClickableViewAccessibility") 72 | private fun initView() { 73 | contentView = findViewById(R.id.content) 74 | } 75 | 76 | /** 77 | * Get ImageRenderAPI 78 | */ 79 | private fun initImageRender() { 80 | Log.i( 81 | TAG, 82 | "timerecorde" + SystemClock.elapsedRealtime() 83 | ) 84 | Log.d( 85 | TAG, 86 | "initImageRender time = " + SystemClock.uptimeMillis() 87 | ) 88 | ImageRender.getInstance(this, object : RenderCallBack { 89 | override fun onSuccess(imageRender: ImageRenderImpl) { 90 | imageRenderAPI = imageRender 91 | } 92 | 93 | override fun onFailure(i: Int) { 94 | Log.e( 95 | TAG, 96 | "Get ImageRender instance failed, errorCode:$i" 97 | ) 98 | } 99 | }) 100 | } 101 | 102 | override fun onResume() { 103 | super.onResume() 104 | Log.i(TAG, "onResume") 105 | if (null != imageRenderAPI) { 106 | imageRenderAPI!!.bindRenderView( 107 | sourcePath, 108 | Utils.authJson, 109 | object : IBindCallBack { 110 | override fun onParseEnd() {} 111 | override fun onBind(renderView: RenderView, i: Int) { 112 | if (renderView != null) { 113 | if (renderView.getResultCode() == ResultCode.SUCCEED) { 114 | view = renderView.getView() 115 | if (null != view) { 116 | hashCode = view.hashCode().toString() 117 | contentView!!.addView(view) 118 | } 119 | } 120 | } 121 | } 122 | }) 123 | } 124 | } 125 | 126 | override fun onDestroy() { 127 | Log.d(TAG, "onDestroy") 128 | super.onDestroy() 129 | } 130 | 131 | override fun onPause() { 132 | super.onPause() 133 | Log.i(TAG, "onPause") 134 | if (null != imageRenderAPI) { 135 | imageRenderAPI!!.unBindRenderView(hashCode) 136 | } 137 | } 138 | 139 | /** 140 | * Start the animation 141 | * 142 | * @param view button 143 | */ 144 | fun startAnimation(view: View?) { 145 | Log.i(TAG, "Start animation") 146 | if (null != imageRenderAPI) { 147 | val playResult = imageRenderAPI!!.playAnimation() 148 | Log.i( 149 | TAG, 150 | "Start animation:$playResult" 151 | ) 152 | } else { 153 | Log.w( 154 | TAG, 155 | "Start animation fail, please init first." 156 | ) 157 | } 158 | } 159 | 160 | /** 161 | * Pause the animation 162 | * 163 | * @param view button 164 | */ 165 | fun pauseAnimation(view: View?) { 166 | // imageRender停止renderView动画 167 | Log.i(TAG, "Pause animation") 168 | if (null != imageRenderAPI) { 169 | val pauseResult = imageRenderAPI!!.pauseAnimation(true) 170 | if (pauseResult == ResultCode.SUCCEED) { 171 | Log.i( 172 | TAG, 173 | "Pause animation success" 174 | ) 175 | } else { 176 | Log.i( 177 | TAG, 178 | "Pause animation failure" 179 | ) 180 | } 181 | } else { 182 | Log.w( 183 | TAG, 184 | "Pause animation fail, please init first." 185 | ) 186 | } 187 | } 188 | 189 | /** 190 | * Resume the animation 191 | * 192 | * @param view button 193 | */ 194 | fun restartAnimation(view: View?) { 195 | Log.i(TAG, "restart animation") 196 | if (null != imageRenderAPI) { 197 | val playResult = imageRenderAPI!!.resumeAnimation() 198 | if (playResult == ResultCode.SUCCEED) { 199 | Log.i( 200 | TAG, 201 | "Restart animation success" 202 | ) 203 | } else { 204 | Log.i( 205 | TAG, 206 | "Restart animation failure" 207 | ) 208 | } 209 | } else { 210 | Log.w( 211 | TAG, 212 | "Restart animation fail, please init first." 213 | ) 214 | } 215 | } 216 | 217 | /** 218 | * Stop the animation. 219 | * 220 | * @param view button 221 | */ 222 | fun stopAnimation(view: View?) { 223 | // Stop the renderView animation. 224 | Log.i(TAG, "Stop animation") 225 | if (null != imageRenderAPI) { 226 | val playResult = imageRenderAPI!!.stopAnimation() 227 | if (playResult == ResultCode.SUCCEED) { 228 | Log.i( 229 | TAG, 230 | "Stop animation success" 231 | ) 232 | } else { 233 | Log.i( 234 | TAG, 235 | "Stop animation failure" 236 | ) 237 | } 238 | } else { 239 | Log.w( 240 | TAG, 241 | "Stop animation fail, please init first." 242 | ) 243 | } 244 | } 245 | 246 | companion object { 247 | /** 248 | * TAG 249 | */ 250 | const val TAG = "ImageKitRenderDemo1" 251 | 252 | /** 253 | * requestCode for applying for permissions. 254 | */ 255 | const val PERMISSION_REQUEST_CODE = 0x01 256 | } 257 | } -------------------------------------------------------------------------------- /app/src/main/java/com/huawei/image/render/sample/util/Utils.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.huawei.image.render.sample.util 17 | 18 | import android.content.Context 19 | import android.util.Log 20 | import org.json.JSONException 21 | import org.json.JSONObject 22 | import java.io.File 23 | import java.io.FileOutputStream 24 | import java.io.IOException 25 | import java.io.InputStream 26 | 27 | /** 28 | * Function Description 29 | * 30 | * @since 2020-04-28 31 | */ 32 | object Utils { 33 | /** 34 | * TAG 35 | */ 36 | private const val TAG = "Utils" 37 | 38 | /** 39 | * create demo dir 40 | * 41 | * @param dirPath dir path 42 | * @return result 43 | */ 44 | fun createResourceDirs(dirPath: String?): Boolean { 45 | val dir = File(dirPath) 46 | return if (!dir.exists()) { 47 | if (dir.parentFile.mkdir()) { 48 | dir.mkdir() 49 | } else { 50 | dir.mkdir() 51 | } 52 | } else false 53 | } 54 | 55 | /** 56 | * copy assets folders to sdCard 57 | * @param context context 58 | * @param foldersName folderName 59 | * @param path path 60 | * @return result 61 | */ 62 | fun copyAssetsFilesToDirs( 63 | context: Context, 64 | foldersName: String, 65 | path: String 66 | ): Boolean { 67 | try { 68 | val files = context.assets.list(foldersName) 69 | for (file in files) { 70 | if (!copyAssetsFileToDirs( 71 | context, 72 | foldersName + File.separator + file, 73 | path + File.separator + file 74 | ) 75 | ) { 76 | Log.e( 77 | TAG, 78 | "Copy resource file fail, please check permission" 79 | ) 80 | return false 81 | } 82 | } 83 | } catch (e: IOException) { 84 | Log.e(TAG, e.message) 85 | return false 86 | } 87 | return true 88 | } 89 | 90 | /** 91 | * copy resource file to sdCard 92 | * 93 | * @param context context 94 | * @param fileName fileName 95 | * @param path sdCard path 96 | * @return result 97 | */ 98 | fun copyAssetsFileToDirs( 99 | context: Context, 100 | fileName: String?, 101 | path: String? 102 | ): Boolean { 103 | var inputStream: InputStream? = null 104 | var outputStream: FileOutputStream? = null 105 | try { 106 | inputStream = context.assets.open(fileName) 107 | val file = File(path) 108 | outputStream = FileOutputStream(file) 109 | val temp = ByteArray(4096) 110 | var n: Int 111 | while (-1 != inputStream.read(temp).also { n = it }) { 112 | outputStream.write(temp, 0, n) 113 | } 114 | } catch (e: IOException) { 115 | Log.e(TAG, e.message) 116 | return false 117 | } finally { 118 | try { 119 | inputStream?.close() 120 | } catch (e: IOException) { 121 | Log.e(TAG, e.message) 122 | } finally { 123 | if (outputStream != null) { 124 | try { 125 | outputStream.close() 126 | } catch (e: IOException) { 127 | Log.e(TAG, e.message) 128 | } 129 | } 130 | } 131 | } 132 | return true 133 | } 134 | 135 | /** 136 | * Add authentication parameters. 137 | * 138 | * @return JsonObject of Authentication parameters. 139 | */ 140 | val authJson: JSONObject 141 | get() { 142 | val authJson = JSONObject() 143 | try { 144 | authJson.put("projectId", "projectId-test") 145 | authJson.put("appId", "appId-test") 146 | authJson.put("authApiKey", "authApiKey-test") 147 | authJson.put("clientSecret", "clientSecret-test") 148 | authJson.put("clientId", "clientId-test") 149 | authJson.put("token", "token-test") 150 | } catch (e: JSONException) { 151 | Log.w( 152 | TAG, 153 | "Get authJson fail, please check auth info" 154 | ) 155 | } 156 | return authJson 157 | } 158 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_entries.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_image_kit_demo.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 15 | 16 | 20 | 27 | 28 | 35 | 36 | 37 | 43 |