From 57bc2d6e3f99a69d1e611692c8d5f50fdf7dc767 Mon Sep 17 00:00:00 2001 From: gaojianming108 Date: Wed, 26 May 2021 15:07:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=A7=BB=E6=A4=8D=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 70 +---- CHANGELOG.md | 71 +---- README.OPENSOURCE | 19 ++ README.md | 230 ++++++++++++-- build.gradle | 41 ++- {sample => entry}/.gitignore | 0 entry/build.gradle | 17 + entry/src/main/config.json | 100 ++++++ .../main/java/com/dd/sample/MainAbility.java | 92 ++++++ .../java/com/dd/sample/MyApplication.java | 29 ++ .../java/com/dd/sample/SignInAbility.java | 74 +++++ .../com/dd/sample/StateSampleAbility.java | 48 ++- .../java/com/dd/sample/StateTextFiled.java | 66 ++++ entry/src/main/java/com/dd/sample/Toast.java | 255 +++++++++++++++ .../dd/sample/slice/GenerateButtonSlice.java | 73 +++++ .../com/dd/sample/slice/StateSampleSlice.java | 86 +++++ .../dd/sample/slice/SubmitAbilitySlice.java | 68 ++++ .../dd/sample/utils/ProgressGenerator.java | 42 ++- .../main/resources/base/element/string.json | 64 ++++ .../graphic/background_ability_button.xml | 12 + .../base/graphic/background_ability_edit.xml | 8 + .../base/graphic/background_ability_main.xml | 12 + .../base/graphic/text_press_background.xml | 5 + .../resources/base/layout/ability_main.xml | 122 ++++++++ .../main/resources/base/layout/ac_states.xml | 76 +++++ .../base/layout/button_progress_slice.xml | 54 ++++ .../base/layout/generate_button_slice.xml | 32 ++ .../base/layout/singin_sample_silice.xml | 39 +++ .../base/layout/state_sample_silice.xml | 86 +++++ .../base/layout/submint_ablity_slice.xml | 36 +++ entry/src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../test/java/com/dd/sample/ExampleTest.java | 9 + gradle.properties | 39 +-- gradle/wrapper/gradle-wrapper.jar | Bin 49896 -> 58694 bytes gradle/wrapper/gradle-wrapper.properties | 3 +- gradlew | 115 ++++--- gradlew.bat | 33 +- img/demo.gif | Bin 0 -> 2381630 bytes library/build.gradle | 33 +- library/gradle.properties | 3 - library/proguard-rules.txt | 17 - library/src/main/AndroidManifest.xml | 3 - library/src/main/config.json | 27 ++ .../java/com/dd/processbutton/FlatButton.java | 172 +++++----- .../com/dd/processbutton/ProcessButton.java | 295 +++++++++--------- .../iml/ActionProcessButton.java | 195 +++++++----- .../iml/GenerateProcessButton.java | 22 +- .../iml/SubmitProcessButton.java | 26 +- .../processbutton/utils/AnimationUtils.java | 61 ++++ .../com/dd/processbutton/utils/AttrUtils.java | 138 ++++++++ .../utils/HmsResourcesManager.java | 105 +++++++ .../com/dd/processbutton/utils/Utils.java | 158 ++++++++++ .../src/main/res/drawable/rect_complete.xml | 7 - library/src/main/res/drawable/rect_error.xml | 7 - library/src/main/res/drawable/rect_normal.xml | 17 - .../src/main/res/drawable/rect_pressed.xml | 7 - .../src/main/res/drawable/rect_progress.xml | 7 - library/src/main/res/values/colors.xml | 13 - library/src/main/res/values/dimen.xml | 5 - .../values/library_processbutton_strings.xml | 13 - library/src/main/res/values/styles.xml | 16 - .../main/resources/base/element/color.json | 45 +++ .../main/resources/base/element/float.json | 12 + .../main/resources/base/element/string.json | 8 + maven_push.gradle | 82 ----- sample/build.gradle | 79 ----- sample/proguard-rules.txt | 17 - sample/src/main/AndroidManifest.xml | 42 --- .../main/java/com/dd/sample/MainActivity.java | 64 ---- .../java/com/dd/sample/MessageActivity.java | 39 --- .../java/com/dd/sample/SignInActivity.java | 49 --- .../java/com/dd/sample/UploadActivity.java | 35 --- .../main/res/drawable-hdpi/ic_launcher.png | Bin 1446 -> 0 bytes .../main/res/drawable-mdpi/ic_launcher.png | Bin 1011 -> 0 bytes .../main/res/drawable-xhdpi/ic_launcher.png | Bin 2317 -> 0 bytes .../main/res/drawable-xxhdpi/ic_launcher.png | Bin 4187 -> 0 bytes .../main/res/drawable-xxxhdpi/ic_launcher.png | Bin 5673 -> 0 bytes sample/src/main/res/layout/ac_message.xml | 28 -- sample/src/main/res/layout/ac_sign_in.xml | 47 --- sample/src/main/res/layout/ac_states.xml | 72 ----- sample/src/main/res/layout/ac_upload.xml | 28 -- sample/src/main/res/values/strings.xml | 27 -- screenshots/diagram-v-0-0-2.png | Bin 8351 -> 0 bytes screenshots/sample1.gif | Bin 242783 -> 0 bytes screenshots/sample1_small1.gif | Bin 160970 -> 0 bytes screenshots/sample1_small2.gif | Bin 164100 -> 0 bytes screenshots/sample2.gif | Bin 221710 -> 0 bytes screenshots/sample3.gif | Bin 238238 -> 0 bytes settings.gradle | 2 +- 89 files changed, 2767 insertions(+), 1382 deletions(-) create mode 100644 README.OPENSOURCE rename {sample => entry}/.gitignore (100%) create mode 100644 entry/build.gradle create mode 100644 entry/src/main/config.json create mode 100644 entry/src/main/java/com/dd/sample/MainAbility.java create mode 100644 entry/src/main/java/com/dd/sample/MyApplication.java create mode 100644 entry/src/main/java/com/dd/sample/SignInAbility.java rename sample/src/main/java/com/dd/sample/StateSampleActivity.java => entry/src/main/java/com/dd/sample/StateSampleAbility.java (35%) create mode 100644 entry/src/main/java/com/dd/sample/StateTextFiled.java create mode 100644 entry/src/main/java/com/dd/sample/Toast.java create mode 100644 entry/src/main/java/com/dd/sample/slice/GenerateButtonSlice.java create mode 100644 entry/src/main/java/com/dd/sample/slice/StateSampleSlice.java create mode 100644 entry/src/main/java/com/dd/sample/slice/SubmitAbilitySlice.java rename {sample => entry}/src/main/java/com/dd/sample/utils/ProgressGenerator.java (44%) create mode 100644 entry/src/main/resources/base/element/string.json create mode 100644 entry/src/main/resources/base/graphic/background_ability_button.xml create mode 100644 entry/src/main/resources/base/graphic/background_ability_edit.xml create mode 100644 entry/src/main/resources/base/graphic/background_ability_main.xml create mode 100644 entry/src/main/resources/base/graphic/text_press_background.xml create mode 100644 entry/src/main/resources/base/layout/ability_main.xml create mode 100644 entry/src/main/resources/base/layout/ac_states.xml create mode 100644 entry/src/main/resources/base/layout/button_progress_slice.xml create mode 100644 entry/src/main/resources/base/layout/generate_button_slice.xml create mode 100644 entry/src/main/resources/base/layout/singin_sample_silice.xml create mode 100644 entry/src/main/resources/base/layout/state_sample_silice.xml create mode 100644 entry/src/main/resources/base/layout/submint_ablity_slice.xml create mode 100644 entry/src/main/resources/base/media/icon.png create mode 100644 entry/src/test/java/com/dd/sample/ExampleTest.java create mode 100644 img/demo.gif delete mode 100644 library/gradle.properties delete mode 100644 library/proguard-rules.txt delete mode 100644 library/src/main/AndroidManifest.xml create mode 100644 library/src/main/config.json create mode 100644 library/src/main/java/com/dd/processbutton/utils/AnimationUtils.java create mode 100644 library/src/main/java/com/dd/processbutton/utils/AttrUtils.java create mode 100644 library/src/main/java/com/dd/processbutton/utils/HmsResourcesManager.java create mode 100644 library/src/main/java/com/dd/processbutton/utils/Utils.java delete mode 100644 library/src/main/res/drawable/rect_complete.xml delete mode 100644 library/src/main/res/drawable/rect_error.xml delete mode 100644 library/src/main/res/drawable/rect_normal.xml delete mode 100644 library/src/main/res/drawable/rect_pressed.xml delete mode 100644 library/src/main/res/drawable/rect_progress.xml delete mode 100644 library/src/main/res/values/colors.xml delete mode 100644 library/src/main/res/values/dimen.xml delete mode 100644 library/src/main/res/values/library_processbutton_strings.xml delete mode 100644 library/src/main/res/values/styles.xml create mode 100644 library/src/main/resources/base/element/color.json create mode 100644 library/src/main/resources/base/element/float.json create mode 100644 library/src/main/resources/base/element/string.json delete mode 100644 maven_push.gradle delete mode 100644 sample/build.gradle delete mode 100644 sample/proguard-rules.txt delete mode 100644 sample/src/main/AndroidManifest.xml delete mode 100644 sample/src/main/java/com/dd/sample/MainActivity.java delete mode 100644 sample/src/main/java/com/dd/sample/MessageActivity.java delete mode 100644 sample/src/main/java/com/dd/sample/SignInActivity.java delete mode 100644 sample/src/main/java/com/dd/sample/UploadActivity.java delete mode 100644 sample/src/main/res/drawable-hdpi/ic_launcher.png delete mode 100644 sample/src/main/res/drawable-mdpi/ic_launcher.png delete mode 100644 sample/src/main/res/drawable-xhdpi/ic_launcher.png delete mode 100644 sample/src/main/res/drawable-xxhdpi/ic_launcher.png delete mode 100644 sample/src/main/res/drawable-xxxhdpi/ic_launcher.png delete mode 100644 sample/src/main/res/layout/ac_message.xml delete mode 100644 sample/src/main/res/layout/ac_sign_in.xml delete mode 100644 sample/src/main/res/layout/ac_states.xml delete mode 100644 sample/src/main/res/layout/ac_upload.xml delete mode 100644 sample/src/main/res/values/strings.xml delete mode 100644 screenshots/diagram-v-0-0-2.png delete mode 100644 screenshots/sample1.gif delete mode 100644 screenshots/sample1_small1.gif delete mode 100644 screenshots/sample1_small2.gif delete mode 100644 screenshots/sample2.gif delete mode 100644 screenshots/sample3.gif diff --git a/.gitignore b/.gitignore index 0f41f1b..c598684 100644 --- a/.gitignore +++ b/.gitignore @@ -1,57 +1,15 @@ -### Android ### -# Built application files -*.apk -*.ap_ - -# Files for the Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - - -### Intellij ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm - -## Directory-based project format -.idea/ -# if you remove the above rule, at least ignore user-specific stuff: -# .idea/workspace.xml -# .idea/tasks.xml -# and these sensitive or high-churn files: -# .idea/dataSources.ids -# .idea/dataSources.xml -# .idea/sqlDataSources.xml -# .idea/dynamic.xml - -## File-based project format -*.ipr -*.iws *.iml - -## Additional for IntelliJ -out/ - -# generated by mpeltonen/sbt-idea plugin -.idea_modules/ - -# generated by JIRA plugin -atlassian-ide-plugin.xml - -# generated by Crashlytics plugin (for Android Studio and Intellij) -com_crashlytics_export_strings.xml - +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +upload.gradle diff --git a/CHANGELOG.md b/CHANGELOG.md index 94258ad..0114b71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,58 +1,13 @@ -## 1.0.4 -* Fixed issue #37 Broken normal text behaviour - -## 1.0.3 -* Added focused and selected states - -## 1.0.2 -* Added library description file for About AboutLibraries - -## 1.0.1 -* Fixed issue: buggy behavior when an endless button gets re-sized #14 - -## 1.0.0 -* Fixed issue: Button padding are ignored #11 -* Added prefix 'pb_' for all custom attributes to avoid conflict #12 - -## 0.0.7 -* Added api 10 compatibility -* Fixed bug in ProgressGenerator class - -## 0.0.6 -Bug fixes - -## 0.0.5 -* Fixed repository name type from `android-process-buton` to `android-process-button` - -## 0.0.4 -**Attributes** - -Renamed attributes: - - * `progressText` -> `textProgress` - * `completeText` -> `textComplete` - -Added attribute to control button corner roundness: - -* `cornerRadius` - - -**ProcessButton** - -Now button state depends on progress: - -* normal state [0] -* progress state [1-99] -* success state [100] -* error state [-1] *new - -Added abstract `drawProgress` method to simplify creation different progress buttons. - -General code clean-up. - -Thanks to **@avrahamshuk** for contribution. - -## 0.0.3 - -* Fixed bug when all buttons where sharing the same drawable state -* Uploaded proejct to Maven Central +## 0.0.3-SNAPSHOT +* modification: Update copyright + +## 0.0.2-SNAPSHOT +* optimization: Optimize code + +## 0.0.1-SNAPSHOT +ohos 第一个版本 + * 实现了原库的大部分 api + * 因为 "TextField组件特性" 原因,"首次进入账户名文本框边框线为选中状态、高亮蓝色,密码框边框线为灰色" 功能未能实现 + * 因为 "系统组件特性" 原因,"打开process-button组件,然后任选其中一个进度条进入,长按进度按钮不松开,然后在按钮范围之内移动,然后松开" 功能未能实现 + * 因为 "TextField组件特性" 原因,"文本框上移动光标,内容会跟着光标的移动放大文本" 功能未能实现 + * 因为 "TextField组件特性" 原因,"光标展示几秒后会消失、在输入内容时光标会消失" 功能未能实现 \ No newline at end of file diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000..ed8e562 --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,19 @@ +[ + + { + + "Name": "android-process-button", + + "License": "The MIT License (MIT)", + + "License File": "LICENSE", + + "Version Number": "v0.0.7", + + "Upstream URL": "https://github.com/dmytrodanylyk/android-process-button", + + "Description": "带加载进度和Loading状态的Button组件库" + + } + +] \ No newline at end of file diff --git a/README.md b/README.md index 91ec00b..b17993e 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,213 @@ -### Description [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.dmytrodanylyk.android-process-button/library/badge.png?style=flat)](http://goo.gl/GydnKe) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Android%20Process%20Button-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/367) +# ohos-process-button + + +#### 项目介绍 +- 项目名称:ohos-process-button +- 所属系列:openharmony的第三方组件适配移植 +- 功能:显示Button各种加载状态 +- 项目移植状态:100% +- 调用差异:无 +- 开发版本:sdk5,DevEco Studio2.1 beta4 +- 基线版本:Release v0.0.7 + +#### 效果演示 + + +#### 安装教程 + +1.在项目根目录下的build.gradle文件中, + ```gradle +allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } +} + ``` + +2.在entry模块的build.gradle文件中, + ```gradle + dependencies { + implementation('com.gitee.chinasoft_ohos:ohos-process-button:0.0.1-SNAPSHOT') + ...... + } +``` -Android Buttons With Built-in Progress Meters. +在sdk5,DevEco Studio2.1 beta4下项目可直接运行 +如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, +并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 -![](screenshots/sample1_small1.gif) -![](screenshots/sample1_small2.gif) +#### 使用说明 -### Wiki +1.使用相关的类: +- ProcessButton - 可拓展的基础类,实现drawProgress抽象方法可实现自己想要的Button效果 +- ActionProcessButton - 用来显示正在loading状态的Button +- GenerateProcessButton - 用来显示当前进度的Button(水平方向) +- SubmitProcessButton - 用来表示当前进度的Button(垂直方向) -- [Home] -- [Screenshots] -- [User Guide] -### Integration +2.使用实例 +初始sample的构建 +``` + public class StateSampleSlice extends Ability implements Component.ClickedListener { + private ActionProcessButton actionProcessButton; + private GenerateProcessButton generateProcessButton; + private SubmitProcessButton submitProcessButton; + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_state_sample_silice); + actionProcessButton = (ActionProcessButton) findComponentById(ResourceTable.Id_state_sample_action); + actionProcessButton.setMode(ActionProcessButton.Mode.ENDLESS); + generateProcessButton = (GenerateProcessButton) findComponentById(ResourceTable.Id_state_sample_generate); + submitProcessButton = (SubmitProcessButton) findComponentById(ResourceTable.Id_state_sample_submit); + + findComponentById(ResourceTable.Id_error_button).setClickedListener(this); + findComponentById(ResourceTable.Id_noramal_button).setClickedListener(this); + findComponentById(ResourceTable.Id_half_button).setClickedListener(this); + findComponentById(ResourceTable.Id_success_button).setClickedListener(this); + } + + @Override + public void onClick(Component component) { + switch (component.getId()) { + case ResourceTable.Id_error_button: + actionProcessButton.setProgress(-1); + generateProcessButton.setProgress(-1); + submitProcessButton.setProgress(-1); + break; + case ResourceTable.Id_noramal_button: + actionProcessButton.setProgress(0); + generateProcessButton.setProgress(0); + submitProcessButton.setProgress(0); + break; + case ResourceTable.Id_half_button: + actionProcessButton.setProgress(50); + generateProcessButton.setProgress(50); + submitProcessButton.setProgress(50); + break; + case ResourceTable.Id_success_button: + actionProcessButton.setProgress(100); + generateProcessButton.setProgress(100); + submitProcessButton.setProgress(100); + break; + } + } + + @Override + protected void onBackground() { + super.onBackground(); + actionProcessButton.setProgress(0); + generateProcessButton.setProgress(0); + submitProcessButton.setProgress(0); + } + + } +``` -The lib is available on Maven Central, you can find it with [Gradle, please] +3:相关属性的使用示例 +``` + + + + + + ``` -dependencies { - compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4' -} + +4:通用的ProcessButton相关方法的使用说明 ``` +void setProgress(int progress); 设置按钮进度 +int getProgress(); 获取按钮进度 + +void setMaxProgress(int mMaxProgress); 设置最大按钮进度 +int getMaxProgress(); 获取最大按钮进度 -### Sample +void setMinProgress(int mMinProgress); 设置最小按钮进度 +int getMinProgress(); 获取最小按钮进度 - - Android app on Google Play - - - DevAppsDirect - +void setNormalText(CharSequence normalText); 设置正常状态下的Button文本 +String getNormalText(); 获取正常状态下的Button文本 -### License +void setLoadingText(CharSequence loadingText); 设置loading状态下的Button文本 +String getLoadingText(); 获取loading状态下的Button文本 + +void setCompleteText(CharSequence completeText); 设置完成后的Button文本 +String getCompleteText(); 获取完成后的Button文本 + +void setErrorText(CharSequence errorText); 设置错误状态的Button文本 +String getErrorText(); 获取错误状态的Button文本 + +void setProgressDrawable(ShapeElement progressDrawable); 设置加载中的Button样式 +ShapeElement getCompleteDrawable(); 获取加载中的Button样式 + +void setCompleteDrawable(ShapeElement completeDrawable); 设置完成后的Button样式 +ShapeElement getCompleteDrawable(); 获取完成后的Button样式 + +void setErrorDrawable(ShapeElement errorDrawable); 设置错误状态的Button样式 +ShapeElement getErrorDrawable(); 获取错误状态的Button样式 + +``` +5:ActionProcessButton使用示例 +``` +ActionProcessButton actionProcessButton = (ActionProcessButton) findComponentById(ResourceTable.Id_btnSignIn); +actionProcessButton.setMode(ActionProcessButton.Mode.ENDLESS);设置ActionProcessButton的loading样式为左右闪动 +actionProcessButton.setMode(ActionProcessButton.Mode.PROGRESS);设置ActionProcessButton的loading样式为Progress进度样式 +actionProcessButton.setColorScheme(int color1, int color2, int color3, int color4);设置ActionProcessButton的闪动样式颜色 + +``` + +#### 测试信息 +CodeCheck代码测试无异常 + +CloudTest代码测试无异常 + +火绒安全病毒安全检测通过 + +当前版本demo功能与原组件基本无差异 + + +#### 版本迭代 + +- 0.0.1-SNAPSHOT + +#### 版权和许可信息 ``` The MIT License (MIT) @@ -56,12 +230,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -``` - -[SmoothProgressBar]:https://github.com/castorflex/SmoothProgressBar -[Home]:https://github.com/dmytrodanylyk/android-process-buton/wiki -[Screenshots]:https://github.com/dmytrodanylyk/android-process-buton/wiki/Screenshots -[User Guide]:https://github.com/dmytrodanylyk/android-process-buton/wiki/User-Guide -[Gradle, Please]:http://gradleplease.appspot.com/ - -[![Analytics](https://ga-beacon.appspot.com/UA-44382495-2/android-process-buton/readme)](https://github.com/igrigorik/ga-beacon) +``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 25c1465..3e28590 100644 --- a/build.gradle +++ b/build.gradle @@ -1,26 +1,43 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } +} buildscript { repositories { + maven { + url 'https://mirrors.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.2.2' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.huawei.ohos:hap:2.4.2.7' + classpath 'com.huawei.ohos:decctest:1.0.0.6' } } -def isReleaseBuild() { - return version.contains("SNAPSHOT") == false -} - allprojects { - version = VERSION_NAME - group = GROUP - repositories { + maven { + url 'https://mirrors.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } jcenter() } -} \ No newline at end of file +} diff --git a/sample/.gitignore b/entry/.gitignore similarity index 100% rename from sample/.gitignore rename to entry/.gitignore diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000..81fd62b --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,17 @@ +apply plugin: 'com.huawei.ohos.hap' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testCompile'junit:junit:4.12' + //compile project(path: ':library') + implementation('com.gitee.chinasoft_ohos:ohos-process-button:0.0.1-SNAPSHOT') + //implementation('com.gitee.chinasoft_ohos:material-about-library:0.0.1-SNAPSHOT') +} diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000..39bbcbe --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,100 @@ +{ + "app": { + "bundleName": "com.dd.sample", + "vendor": "dd", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.dd.sample", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.dd.sample.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "ohos_process_button", + "type": "page", + "launchType": "standard" + }, + { + "skills": [ + { + "actions": [ + "action.process_button.state_sample" + ] + } + ], + "orientation": "unspecified", + "name": "com.dd.sample.StateSampleAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "ohos_process_button", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "name": "com.dd.sample.SignInAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "ohos_process_button", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "name": "com.dd.sample.slice.GenerateButtonSlice", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "ohos_process_button", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "name": "com.dd.sample.slice.StateSampleSlice", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "ohos_process_button", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "name": "com.dd.sample.slice.SubmitAbilitySlice", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "ohos_process_button", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/dd/sample/MainAbility.java b/entry/src/main/java/com/dd/sample/MainAbility.java new file mode 100644 index 0000000..71f6424 --- /dev/null +++ b/entry/src/main/java/com/dd/sample/MainAbility.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dd.sample; + +import com.dd.sample.slice.GenerateButtonSlice; +import com.dd.sample.slice.StateSampleSlice; +import com.dd.sample.slice.SubmitAbilitySlice; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; + +/** + * 主测试页面 + * + * @since 2021-03-01 + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + findComponentById(ResourceTable.Id_button_progress).setClickedListener(component -> { + Intent intent2 = new Intent(); + Operation operation = getOperation(SignInAbility.class.getName()); + + intent2.setParam(SignInAbility.EXTRAS_ENDLESS_MODE, false); + intent2.setOperation(operation); + startAbility(intent2); + }); + findComponentById(ResourceTable.Id_endless_progress).setClickedListener(component -> { + Intent intent2 = new Intent(); + Operation operation = getOperation(SignInAbility.class.getName()); + + intent2.setParam(SignInAbility.EXTRAS_ENDLESS_MODE, true); + intent2.setOperation(operation); + startAbility(intent2); + }); + findComponentById(ResourceTable.Id_submit_btn).setClickedListener(component -> { + Intent intent2 = new Intent(); + Operation operation = getOperation(SubmitAbilitySlice.class.getName()); + + intent2.setParam(SignInAbility.EXTRAS_ENDLESS_MODE, true); + intent2.setOperation(operation); + startAbility(intent2); + }); + findComponentById(ResourceTable.Id_generate_btn).setClickedListener(component -> { + Intent intent2 = new Intent(); + Operation operation = getOperation(GenerateButtonSlice.class.getName()); + intent2.setOperation(operation); + startAbility(intent2); + }); + findComponentById(ResourceTable.Id_state_sample).setClickedListener(component -> { + Intent intent2 = new Intent(); + Operation operation = getOperation(StateSampleSlice.class.getName()); + intent2.setOperation(operation); + startAbility(intent2); + }); + } + + private Operation getOperation(String abilityName) { + return new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(getBundleName()) + .withAbilityName(abilityName) + .build(); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } +} diff --git a/entry/src/main/java/com/dd/sample/MyApplication.java b/entry/src/main/java/com/dd/sample/MyApplication.java new file mode 100644 index 0000000..882250c --- /dev/null +++ b/entry/src/main/java/com/dd/sample/MyApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dd.sample; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * Application + * @since 2021-03-01 + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/entry/src/main/java/com/dd/sample/SignInAbility.java b/entry/src/main/java/com/dd/sample/SignInAbility.java new file mode 100644 index 0000000..51c4a89 --- /dev/null +++ b/entry/src/main/java/com/dd/sample/SignInAbility.java @@ -0,0 +1,74 @@ +package com.dd.sample; + +import com.dd.processbutton.iml.ActionProcessButton; +import com.dd.sample.utils.ProgressGenerator; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.agp.components.TextField; + +public class SignInAbility extends Ability { + static final String EXTRAS_ENDLESS_MODE = "EXTRAS_ENDLESS_MODE"; + + private ActionProcessButton actionProcessButton; + private TextField num; + private TextField pass; + private ProgressGenerator progressGenerator; + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_button_progress_slice); + actionProcessButton = (ActionProcessButton) findComponentById(ResourceTable.Id_btnSignIn); + num = (TextField) findComponentById(ResourceTable.Id_user_num); + pass = (TextField) findComponentById(ResourceTable.Id_user_password); + + if (progressGenerator == null) { + progressGenerator = new ProgressGenerator(new ProgressGenerator.OnCompleteListener() { + @Override + public void onComplete() { + Toast.showLong(getContext(), "Loading Complete, button is disabled"); + actionProcessButton.setEnabled(false); + } + }); + } + + boolean booleanParam = intent.getBooleanParam(EXTRAS_ENDLESS_MODE, false); + if (booleanParam) { + actionProcessButton.setMode(ActionProcessButton.Mode.ENDLESS); + } else { + actionProcessButton.setMode(ActionProcessButton.Mode.PROGRESS); + } + actionProcessButton.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + num.setEnabled(false); + pass.setEnabled(false); + num.clearFocus(); + pass.clearFocus(); + progressGenerator.start(actionProcessButton); + actionProcessButton.setEnabled(false); + } + }); + + } + + @Override + protected void onBackground() { + super.onBackground(); + } + + + @Override + protected void onStop() { + super.onStop(); + progressGenerator.stop(); + actionProcessButton.setProgress(0); + actionProcessButton.setEnabled(true); + num.setText("jondoe"); + pass.setText("123456789"); + num.setEnabled(true); + pass.setEnabled(true); + } + +} diff --git a/sample/src/main/java/com/dd/sample/StateSampleActivity.java b/entry/src/main/java/com/dd/sample/StateSampleAbility.java similarity index 35% rename from sample/src/main/java/com/dd/sample/StateSampleActivity.java rename to entry/src/main/java/com/dd/sample/StateSampleAbility.java index 96909ee..7fb2ae9 100644 --- a/sample/src/main/java/com/dd/sample/StateSampleActivity.java +++ b/entry/src/main/java/com/dd/sample/StateSampleAbility.java @@ -1,55 +1,47 @@ package com.dd.sample; -import com.dd.processbutton.iml.ActionProcessButton; import com.dd.processbutton.iml.GenerateProcessButton; import com.dd.processbutton.iml.SubmitProcessButton; -import android.app.Activity; -import android.os.Bundle; -import android.view.View; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; -public class StateSampleActivity extends Activity implements View.OnClickListener { +public class StateSampleAbility extends Ability implements Component.ClickedListener { - private ActionProcessButton mBtnAction; private GenerateProcessButton mBtnGenerate; private SubmitProcessButton mBtnSubmit; @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.ac_states); - - mBtnAction = (ActionProcessButton) findViewById(R.id.btnAction); - mBtnSubmit = (SubmitProcessButton) findViewById(R.id.btnSubmit); - mBtnGenerate = (GenerateProcessButton) findViewById(R.id.btnGenerate); - - findViewById(R.id.btnProgressLoading).setOnClickListener(this); - findViewById(R.id.btnProgressError).setOnClickListener(this); - findViewById(R.id.btnProgressComplete).setOnClickListener(this); - findViewById(R.id.btnProgressNormal).setOnClickListener(this); + protected void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ac_states); + mBtnSubmit = (SubmitProcessButton) findComponentById(ResourceTable.Id_btnSubmit); + mBtnGenerate = (GenerateProcessButton) findComponentById(ResourceTable.Id_btnGenerate); + + findComponentById(ResourceTable.Id_btnProgressLoading).setClickedListener(this); + findComponentById(ResourceTable.Id_btnProgressError).setClickedListener(this); + findComponentById(ResourceTable.Id_btnProgressComplete).setClickedListener(this); + findComponentById(ResourceTable.Id_btnProgressNormal).setClickedListener(this); } @Override - public void onClick(View v) { - switch (v.getId()) { - case R.id.btnProgressLoading: - mBtnAction.setProgress(50); + public void onClick(Component component) { + switch (component.getId()) { + case ResourceTable.Id_btnProgressLoading: mBtnSubmit.setProgress(50); mBtnGenerate.setProgress(50); break; - case R.id.btnProgressError: - mBtnAction.setProgress(-1); + case ResourceTable.Id_btnProgressError: mBtnSubmit.setProgress(-1); mBtnGenerate.setProgress(-1); break; - case R.id.btnProgressComplete: - mBtnAction.setProgress(100); + case ResourceTable.Id_btnProgressComplete: mBtnSubmit.setProgress(100); mBtnGenerate.setProgress(100); break; - case R.id.btnProgressNormal: - mBtnAction.setProgress(0); + case ResourceTable.Id_btnProgressNormal: mBtnSubmit.setProgress(0); mBtnGenerate.setProgress(0); break; diff --git a/entry/src/main/java/com/dd/sample/StateTextFiled.java b/entry/src/main/java/com/dd/sample/StateTextFiled.java new file mode 100644 index 0000000..0d7ed11 --- /dev/null +++ b/entry/src/main/java/com/dd/sample/StateTextFiled.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dd.sample; + +import ohos.agp.colors.RgbColor; +import ohos.agp.components.AttrSet; +import ohos.agp.components.TextField; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.app.Context; + +/** + * 自定义状态的TextField + * + * @since 2021-03-01 + */ +public class StateTextFiled extends TextField { + private final ShapeElement normalElement = new ShapeElement(); + private final ShapeElement disableElement = new ShapeElement(); + + public StateTextFiled(Context context) { + super(context); + init(); + } + + public StateTextFiled(Context context, AttrSet attrSet) { + super(context, attrSet); + init(); + } + + public StateTextFiled(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + init(); + } + + private void init() { + normalElement.setRgbColor(RgbColor.fromArgbInt(Color.BLACK.getValue())); + disableElement.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor("#eeeeee"))); + this.setMultipleLine(false); + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + if (enabled) { + setBasement(normalElement); + setTextColor(new Color(Color.getIntColor("#000000"))); + } else { + setBasement(disableElement); + setTextColor(new Color(Color.getIntColor("#6C6C6C"))); + } + } +} diff --git a/entry/src/main/java/com/dd/sample/Toast.java b/entry/src/main/java/com/dd/sample/Toast.java new file mode 100644 index 0000000..245c951 --- /dev/null +++ b/entry/src/main/java/com/dd/sample/Toast.java @@ -0,0 +1,255 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dd.sample; + +import ohos.agp.colors.RgbColor; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.Text; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.utils.TextAlignment; +import ohos.agp.window.dialog.ToastDialog; +import ohos.agp.window.service.DisplayAttributes; +import ohos.agp.window.service.DisplayManager; +import ohos.app.Context; +import ohos.global.resource.NotExistException; +import ohos.global.resource.WrongTypeException; + +import java.io.IOException; + +/** + * Toast + * + * @since 2021-03-01 + */ +public class Toast { + private static final int LENGTH_LONG = 4000; + private static final int LENGTH_SHORT = 2000; + + /** + * Toast显示的位置枚举类型 + * + * @since 2021-03-01 + */ + public enum ToastLayout { + /** + * 系统默认 + */ + DEFAULT, + /** + * 中间 + */ + CENTER, + /** + * 顶部 + */ + TOP, + /** + * 底部 + */ + BOTTOM, + } + + private Toast() { + } + + /** + * 显示短时间的Toast + * + * @param context 上下文 + * @param content 内容 + */ + public static void showShort(Context context, String content) { + createTost(context, content, LENGTH_SHORT, ToastLayout.DEFAULT); + } + + /** + * 显示长时间的Toast + * + * @param context 上下文 + * @param content 内容 + */ + public static void showLong(Context context, String content) { + createTost(context, content, LENGTH_LONG, ToastLayout.DEFAULT); + } + + /** + * 显示Toast + * + * @param context 上下文 + * @param content 内容 + */ + public static void show(Context context, String content) { + createTost(context, content, LENGTH_SHORT, ToastLayout.DEFAULT); + } + + /** + * 显示Toast + * + * @param context 上下文 + * @param content 内容 + * @param duration 时间 ms + */ + public static void show(Context context, String content, int duration) { + createTost(context, content, duration, ToastLayout.DEFAULT); + } + + /** + * 显示Toast + * + * @param context 上下文 + * @param content 内容 + * @param layout 位置 + */ + public static void show(Context context, String content, ToastLayout layout) { + createTost(context, content, LENGTH_SHORT, layout); + } + + /** + * 显示Toast + * + * @param context 上下文 + * @param content 内容 + * @param duration 时间 + * @param layout 位置 + */ + public static void show(Context context, String content, int duration, ToastLayout layout) { + createTost(context, content, duration, layout); + } + + /** + * 显示短时Toast + * + * @param context 上下文 + * @param content 内容 + */ + public static void showShort(Context context, int content) { + createTost(context, getString(context, content), LENGTH_SHORT, ToastLayout.DEFAULT); + } + + /** + * 显示长时Toast + * + * @param context 上下文 + * @param content 内容 + */ + public static void showLong(Context context, int content) { + createTost(context, getString(context, content), LENGTH_LONG, ToastLayout.DEFAULT); + } + + /** + * 显示Toast + * + * @param context 上下文 + * @param content 内容 + */ + public static void show(Context context, int content) { + createTost(context, getString(context, content), LENGTH_SHORT, ToastLayout.DEFAULT); + } + + /** + * 显示Toast + * + * @param context 上下文 + * @param content 内容 + * @param duration 时间 ms + */ + public static void show(Context context, int content, int duration) { + createTost(context, getString(context, content), duration, ToastLayout.DEFAULT); + } + + /** + * 显示Toast + * + * @param context 上下文 + * @param content 内容 + * @param layout 位置 + */ + public static void show(Context context, int content, ToastLayout layout) { + createTost(context, getString(context, content), LENGTH_SHORT, layout); + } + + /** + * 显示Toast + * + * @param context 上下文 + * @param content 内容 + * @param duration 时间 ms + * @param layout 位置 + */ + public static void show(Context context, int content, int duration, ToastLayout layout) { + createTost(context, getString(context, content), duration, layout); + } + + private static void createTost(Context context, String content, int duration, ToastLayout layout) { + DirectionalLayout toastLayout = new DirectionalLayout(context); + DirectionalLayout.LayoutConfig textConfig = new DirectionalLayout.LayoutConfig( + DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT); + Text text = new Text(context); + text.setText(content); + text.setTextColor(new Color(Color.getIntColor("#000000"))); + text.setPadding(vp2px(context, 16), vp2px(context, 12), vp2px(context, 16), vp2px(context, 12)); + text.setTextSize(vp2px(context, 12)); + text.setBackground(buildDrawableByColorRadius(Color.getIntColor("#eeeeee"), vp2px(context, 20))); + text.setLayoutConfig(textConfig); + text.setTextAlignment(TextAlignment.CENTER); + toastLayout.addComponent(text); + int mLayout = LayoutAlignment.BOTTOM; + switch (layout) { + case TOP: + mLayout = LayoutAlignment.TOP; + break; + case BOTTOM: + mLayout = LayoutAlignment.BOTTOM; + break; + case CENTER: + mLayout = LayoutAlignment.CENTER; + break; + default: + break; + } + ToastDialog toastDialog = new ToastDialog(context); + toastDialog.setComponent(toastLayout); + toastDialog.setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT); + toastDialog.setAlignment(mLayout); + toastDialog.setTransparent(true); + toastDialog.setDuration(duration); + toastDialog.show(); + } + + private static ohos.agp.components.element.Element buildDrawableByColorRadius(int color, float radius) { + ShapeElement drawable = new ShapeElement(); + drawable.setShape(0); + drawable.setRgbColor(RgbColor.fromArgbInt(color)); + drawable.setCornerRadius(radius); + return drawable; + } + + private static String getString(Context context, int resId) { + try { + return context.getResourceManager().getElement(resId).getString(); + } catch (NotExistException | WrongTypeException | IOException e) { + e.getMessage(); + } + return ""; + } + + private static int vp2px(Context context, float vp) { + DisplayAttributes attributes = DisplayManager.getInstance().getDefaultDisplay(context).get().getAttributes(); + return (int) (attributes.densityPixels * vp); + } +} diff --git a/entry/src/main/java/com/dd/sample/slice/GenerateButtonSlice.java b/entry/src/main/java/com/dd/sample/slice/GenerateButtonSlice.java new file mode 100644 index 0000000..33708c8 --- /dev/null +++ b/entry/src/main/java/com/dd/sample/slice/GenerateButtonSlice.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dd.sample.slice; + +import com.dd.processbutton.iml.GenerateProcessButton; +import com.dd.sample.ResourceTable; +import com.dd.sample.Toast; +import com.dd.sample.utils.ProgressGenerator; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; + +/** + * 测试GenerateProcessButton + * + * @since 2021-03-01 + */ +public class GenerateButtonSlice extends Ability { + private GenerateProcessButton generateProcessButton; + private ProgressGenerator progressGenerator; + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_generate_button_slice); + generateProcessButton = (GenerateProcessButton) findComponentById(ResourceTable.Id_generate_process_btn); + progressGenerator = new ProgressGenerator(new ProgressGenerator.OnCompleteListener() { + @Override + public void onComplete() { + Toast.showLong(getContext(),"Loading Complete, button is disabled"); + } + }); + generateProcessButton.setClickedListener(new Component.ClickedListener() { + @Override + public void onClick(Component component) { + progressGenerator.start(generateProcessButton); + generateProcessButton.setEnabled(false); + } + }); + } + + @Override + protected void onActive() { + super.onActive(); + } + + @Override + protected void onForeground(Intent intent) { + super.onForeground(intent); + } + + @Override + protected void onStop() { + super.onStop(); + generateProcessButton.setProgress(0); + generateProcessButton.setEnabled(true); + progressGenerator.stop(); + } +} diff --git a/entry/src/main/java/com/dd/sample/slice/StateSampleSlice.java b/entry/src/main/java/com/dd/sample/slice/StateSampleSlice.java new file mode 100644 index 0000000..4d29f00 --- /dev/null +++ b/entry/src/main/java/com/dd/sample/slice/StateSampleSlice.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dd.sample.slice; + +import com.dd.processbutton.iml.ActionProcessButton; +import com.dd.processbutton.iml.GenerateProcessButton; +import com.dd.processbutton.iml.SubmitProcessButton; +import com.dd.sample.ResourceTable; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; + +/** + * 各种Button测试集合 + * @since 2021-03-01 + */ +public class StateSampleSlice extends Ability implements Component.ClickedListener { + private ActionProcessButton actionProcessButton; + private GenerateProcessButton generateProcessButton; + private SubmitProcessButton submitProcessButton; + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_state_sample_silice); + actionProcessButton = (ActionProcessButton) findComponentById(ResourceTable.Id_state_sample_action); + actionProcessButton.setMode(ActionProcessButton.Mode.ENDLESS); + generateProcessButton = (GenerateProcessButton) findComponentById(ResourceTable.Id_state_sample_generate); + submitProcessButton = (SubmitProcessButton) findComponentById(ResourceTable.Id_state_sample_submit); + + findComponentById(ResourceTable.Id_error_button).setClickedListener(this); + findComponentById(ResourceTable.Id_noramal_button).setClickedListener(this); + findComponentById(ResourceTable.Id_half_button).setClickedListener(this); + findComponentById(ResourceTable.Id_success_button).setClickedListener(this); + } + + @Override + public void onClick(Component component) { + switch (component.getId()) { + case ResourceTable.Id_error_button: + actionProcessButton.setProgress(-1); + generateProcessButton.setProgress(-1); + submitProcessButton.setProgress(-1); + break; + case ResourceTable.Id_noramal_button: + actionProcessButton.setProgress(0); + generateProcessButton.setProgress(0); + submitProcessButton.setProgress(0); + break; + case ResourceTable.Id_half_button: + actionProcessButton.setProgress(50); + generateProcessButton.setProgress(50); + submitProcessButton.setProgress(50); + break; + case ResourceTable.Id_success_button: + actionProcessButton.setProgress(100); + generateProcessButton.setProgress(100); + submitProcessButton.setProgress(100); + break; + default: + break; + } + } + + @Override + protected void onBackground() { + super.onBackground(); + actionProcessButton.setProgress(0); + generateProcessButton.setProgress(0); + submitProcessButton.setProgress(0); + } +} diff --git a/entry/src/main/java/com/dd/sample/slice/SubmitAbilitySlice.java b/entry/src/main/java/com/dd/sample/slice/SubmitAbilitySlice.java new file mode 100644 index 0000000..e04284e --- /dev/null +++ b/entry/src/main/java/com/dd/sample/slice/SubmitAbilitySlice.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dd.sample.slice; + +import com.dd.processbutton.iml.SubmitProcessButton; +import com.dd.sample.ResourceTable; +import com.dd.sample.Toast; +import com.dd.sample.utils.ProgressGenerator; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.components.TextField; + +/** + * 测试SubmitProcessButton + * @since 2021-03-01 + */ +public class SubmitAbilitySlice extends Ability { + private SubmitProcessButton submitProcessButton; + private TextField input; + private ProgressGenerator progressGenerator; + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_submint_ablity_slice); + progressGenerator = new ProgressGenerator(() -> + Toast.showLong(getContext(),"Loading Complete, button is disabled")); + + input = (TextField)findComponentById(ResourceTable.Id_input); + submitProcessButton = (SubmitProcessButton) findComponentById(ResourceTable.Id_sub_btn_sample); + submitProcessButton.setClickedListener(component -> { + progressGenerator.start(submitProcessButton); + submitProcessButton.setEnabled(false); + input.setEnabled(false); + input.clearFocus(); + }); + } + + @Override + protected void onBackground() { + super.onBackground(); + } + + @Override + protected void onStop() { + super.onStop(); + submitProcessButton.setText("SEND"); + submitProcessButton.setProgress(0); + submitProcessButton.setEnabled(true); + input.setText("How are you?"); + input.setEnabled(true); + progressGenerator.stop(); + } +} diff --git a/sample/src/main/java/com/dd/sample/utils/ProgressGenerator.java b/entry/src/main/java/com/dd/sample/utils/ProgressGenerator.java similarity index 44% rename from sample/src/main/java/com/dd/sample/utils/ProgressGenerator.java rename to entry/src/main/java/com/dd/sample/utils/ProgressGenerator.java index d48db54..52c813c 100644 --- a/sample/src/main/java/com/dd/sample/utils/ProgressGenerator.java +++ b/entry/src/main/java/com/dd/sample/utils/ProgressGenerator.java @@ -2,41 +2,65 @@ package com.dd.sample.utils; import com.dd.processbutton.ProcessButton; -import android.os.Handler; +import ohos.eventhandler.EventHandler; +import ohos.eventhandler.EventRunner; import java.util.Random; public class ProgressGenerator { + private final EventHandler eventHandler = new EventHandler(EventRunner.getMainEventRunner()); - public interface OnCompleteListener { + private Runnable runnable; - public void onComplete(); + public interface OnCompleteListener { + void onComplete(); } - private OnCompleteListener mListener; + private final OnCompleteListener mListener; private int mProgress; + public OnCompleteListener getmListener() { + return mListener; + } + + public int getmProgress() { + return mProgress; + } + + public Random getRandom() { + return random; + } + public ProgressGenerator(OnCompleteListener listener) { mListener = listener; } + public void setmProgress(int mProgress) { + this.mProgress = mProgress; + } + public void start(final ProcessButton button) { - final Handler handler = new Handler(); - handler.postDelayed(new Runnable() { + runnable = new Runnable() { @Override public void run() { mProgress += 10; button.setProgress(mProgress); if (mProgress < 100) { - handler.postDelayed(this, generateDelay()); + eventHandler.postTask(this, generateDelay()); } else { + mProgress = 0; mListener.onComplete(); } } - }, generateDelay()); + }; + eventHandler.postTask(runnable, generateDelay()); + } + + public void stop() { + eventHandler.removeTask(runnable); } - private Random random = new Random(); + private final Random random = new Random(); private int generateDelay() { return random.nextInt(1000); diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000..65bb2ac --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,64 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ohos_process_button" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "action_settings", + "value": "Settings" + }, + { + "name": "dummy_email", + "value": "jondoe@gmail.com" + }, + { + "name": "dummy_password", + "value": "123456789" + }, + { + "name": "Sign_in", + "value": "Sign in" + }, + { + "name": "Success", + "value": "Success" + }, + { + "name": "Loading", + "value": "Loading.." + }, + { + "name": "Question", + "value": "How are you?" + }, + { + "name": "Send", + "value": "Send" + }, + { + "name": "Done", + "value": "Done" + }, + { + "name": "Upload", + "value": "Upload" + }, + { + "name": "Beautiful_Picture", + "value": "Beautiful Picture" + }, + { + "name": "Uploading", + "value": "Uploading" + }, + { + "name": "Loading_Complete", + "value": "Loading Complete, button is disabled" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_button.xml b/entry/src/main/resources/base/graphic/background_ability_button.xml new file mode 100644 index 0000000..83e2706 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_button.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_edit.xml b/entry/src/main/resources/base/graphic/background_ability_edit.xml new file mode 100644 index 0000000..f6f017f --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_edit.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_main.xml b/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000..9eda45c --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/text_press_background.xml b/entry/src/main/resources/base/graphic/text_press_background.xml new file mode 100644 index 0000000..d48a29a --- /dev/null +++ b/entry/src/main/resources/base/graphic/text_press_background.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000..16c4427 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ac_states.xml b/entry/src/main/resources/base/layout/ac_states.xml new file mode 100644 index 0000000..5ce1096 --- /dev/null +++ b/entry/src/main/resources/base/layout/ac_states.xml @@ -0,0 +1,76 @@ + + + + + + + + +