diff --git a/AppScope/app.json5 b/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cbe69f1c7582001e0ab2a69a37237f5bb8f10901 --- /dev/null +++ b/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.customkeyboard", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/AppScope/resources/base/element/string.json b/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..11e9b6e77de9c3abb4abd656fe5983c38ec026e1 --- /dev/null +++ b/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CustomKeyboard" + } + ] +} diff --git a/AppScope/resources/base/media/app_icon.png b/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/AppScope/resources/base/media/app_icon.png differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..338e5b0bc22082e0ffcc7121c2ed3897a3ddccb0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved. + + 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. + +Apache License, Version 2.0 +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +1.You must give any other recipients of the Work or Derivative Works a copy of this License; and +2.You must cause any modified files to carry prominent notices stating that You changed the files; and +3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.en.md b/README.en.md deleted file mode 100644 index 9c81c9906b39d71a3028b83e17a0cfa5537a9cbc..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# CustomizeKeyboard - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index 08ae2e7034f14c9730470a70c7a2815b19ec8670..bc9f9d48dda2722f2fbedd2d8f6139bc878a8dd8 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,68 @@ -# CustomizeKeyboard +# 自定义键盘 -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +### 介绍 -#### 软件架构 -软件架构说明 +本示例介绍自定义键盘的实现,包括原生键盘和自定义键盘切换、自定义键盘光标处理、自定义键盘布局避让等场景。 +### 效果预览 +| 自定义键盘布局避让 | 自定义键盘和系统键盘切换 | 自定义键盘通用功能 | +|:-----------------:|:------------:|:-:| +| ![image](screenshots/device/avoid.gif) | ![image](screenshots/device/switch.gif) | ![image](screenshots/device/use.gif) | -#### 安装教程 -1. xxxx -2. xxxx -3. xxxx +使用说明 -#### 使用说明 +1. 首页点击“绑定自定义键盘”输入框,拉起自定义键盘,布局会向上避让。 -1. xxxx -2. xxxx -3. xxxx +2. 分别点击键盘上“123”、“ABC”、“中文”tab页签,切换数字键盘、英文键盘、系统键盘,实现一个输入框同时绑定自定义键盘和系统键盘。 -#### 参与贡献 +3. 支持键盘通用操作,包括内容输入、光标设置、大小写切换、复制、粘贴、删除等功能。 -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +### 工程目录 -#### 特技 +``` +├──entry/src/main/ets // 代码区 +│ ├──constants +│ │ └──Constants.ets // 公共常量类 +│ ├──entryability +│ │ └──EntryAbility.ets // 程序入口类 +│ ├──model +│ │ └──KeyboardController.ets // 自定义键盘控制类 +│ ├──pages +│ │ └──MainPage.ets // 主页面 +│ ├──view +│ │ ├──CustomKeyboard.ets // 自定义键盘入口 +│ │ ├──EnglishKeyboard.ets // 英文键盘组件 +│ │ ├──NumberKeyboard.ets // 数字键盘组件 +│ │ ├──TabButton.ets // 键盘上方Tab组件Button按钮 +│ │ ├──TabView.ets // 键盘上方Tab组件 +│ │ └──TextInputComponent.ets // 绑定自定义键盘的TextInput类 +│ └──viewmodel +│ └──MenuModel.ets // 键盘按钮数据 +└──entry/src/main/resources // 资应用资源目录 +``` -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +### 具体实现 + +1. TextInput组件customKeyboard属性绑定builder,实现自定义键盘。 +2. TextInput组件customKeyboard属性传值null,绑定系统键盘,实现自定义键盘和系统键盘的切换。 +3. 监听TextInput组件onTextSelectionChange、onChange事件,实现光标位置设置。 +4. 监听TextInput组件onPaste、onCut事件,实现复制粘贴功能。 +5. 通过window的keyboardHeightChange事件获取系统键盘高度,通过onAreaChange获取自定义键盘高度,设置布局避让。 + +### 相关权限 +不涉及。 + +### 依赖 +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS NEXT Release及以上。 + +3. DevEco Studio版本:DevEco Studio NEXT Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS NEXT Release SDK及以上。 \ No newline at end of file diff --git a/build-profile.json5 b/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed2b75e17797558b7d6146c8745dc6bb1b25d2ba --- /dev/null +++ b/build-profile.json5 @@ -0,0 +1,42 @@ +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..867c2f95cd15243dc4d5e66de45ce367193d374c --- /dev/null +++ b/entry/build-profile.json5 @@ -0,0 +1,31 @@ +{ + "apiType": "stageMode", + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + },"nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/entry/hvigorfile.ts b/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/entry/obfuscation-rules.txt b/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..803b25293388deda7b9a05a21b5aeadeb716b4d5 --- /dev/null +++ b/entry/oh-package.json5 @@ -0,0 +1,9 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} \ No newline at end of file diff --git a/entry/src/main/ets/constants/Constants.ets b/entry/src/main/ets/constants/Constants.ets new file mode 100644 index 0000000000000000000000000000000000000000..e33bcea6ddec538ecf3fdb23ba473702a8675ebf --- /dev/null +++ b/entry/src/main/ets/constants/Constants.ets @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 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. + */ + +export class Constants { + /** + * id of avoid message event. + */ + static readonly AVOID_EVENT_ID: number = 1; + /** + * border of image. + */ + static readonly IMAGE_BORDER: number = 12; + /** + * border of button. + */ + static readonly BUTTON_BORDER: number = 6; + /** + * number keyboard key. + */ + static readonly NUMBER_KEYBOARD: string = 'Number'; + /** + * english keyboard key. + */ + static readonly ENGLISH_KEYBOARD: string = 'English'; + /** + * system keyboard key. + */ + static readonly SYSTEM_KEYBOARD: string = 'System'; + /** + * the initial top padding of main page. + */ + static readonly MAIN_PAGE_INITIAL_PADDING: number = 210; + /** + * the radius of button in keyboard. + */ + static readonly KEYBOARD_BUTTON_RADIUS: number = 6; + /** + * the fontsize of button in keyboard. + */ + static readonly KEYBOARD_BUTTON_FONTSIZE_18: number = 18; + /** + * the fontsize of button in keyboard. + */ + static readonly KEYBOARD_BUTTON_FONTSIZE_20: number = 20; + /** + * the space between button in english keyboard. + */ + static readonly ENGLISH_KEYBOARD_BUTTON_SPACE: number = 6; + /** + * the default space in column. + */ + static readonly DEFAULT_COLUMN_SPACE: number = 12; +} \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..94d071b979a9479442e6ea1cc5ebe03295079ce3 --- /dev/null +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 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. + */ + +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/MainPage', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b9aeb2679294b37bbf46d72c11d065cc5caf0eb7 --- /dev/null +++ b/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/model/KeyboardController.ets b/entry/src/main/ets/model/KeyboardController.ets new file mode 100644 index 0000000000000000000000000000000000000000..62290591907b5795776970d7c3e0bdde2b17c43a --- /dev/null +++ b/entry/src/main/ets/model/KeyboardController.ets @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 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. + */ + +import { emitter } from '@kit.BasicServicesKit'; +import { Constants } from '../constants/Constants'; + +export class KeyboardController { + textInputController?: TextInputController; + text: string = ''; + leftCaretPos: number = 0; + rightCaretPos: number = 0; + targetCaretPos: number = 0; + keyBoardType: string = Constants.NUMBER_KEYBOARD; + isUpperCase: boolean = false; + + onInput(value: string | Resource): string { + if (typeof value === 'string') { + this.text = this.text.substring(0, this.leftCaretPos) + value + this.text.substring(this.rightCaretPos); + this.targetCaretPos = this.leftCaretPos + value.length; + return this.text; + } + + switch (value.id) { + case $r('app.string.keyboardButton_delete').id: + if (this.rightCaretPos === this.leftCaretPos && this.leftCaretPos > 0) { + this.leftCaretPos--; + } + this.text = this.text.substring(0, this.leftCaretPos) + this.text.substring(this.rightCaretPos); + this.targetCaretPos = this.leftCaretPos; + break; + case $r('app.string.keyboardButton_clear').id: + this.text = ''; + this.targetCaretPos = 0; + break; + case $r('app.string.keyboardButton_finish').id: + this.textInputController?.stopEditing(); + break; + case $r('app.string.tabButton_english_text').id: + this.keyBoardType = Constants.ENGLISH_KEYBOARD; + break; + case $r('app.string.tabButton_number_text').id: + this.keyBoardType = Constants.NUMBER_KEYBOARD; + break; + case $r('app.string.keyboardButton_space').id: + this.text = this.text.substring(0, this.leftCaretPos) + ' ' + this.text.substring(this.rightCaretPos); + this.targetCaretPos = this.leftCaretPos + 1; + break; + case $r('app.string.keyboardButton_uppercase').id: + case $r('app.string.keyboardButton_lowercase').id: + this.isUpperCase = !this.isUpperCase; + break; + } + return this.text; + } + + onPaste(value: string) { + this.text = this.text.substring(0, this.leftCaretPos) + value + this.text.substring(this.rightCaretPos); + this.targetCaretPos = this.leftCaretPos + value.length; + } + + onChange(value: string) { + this.text = value; + if (this.keyBoardType !== Constants.SYSTEM_KEYBOARD) { + this.textInputController?.caretPosition(this.targetCaretPos); + } + } + + setCaretPosition(start: number, end: number) { + this.leftCaretPos = start; + this.rightCaretPos = end; + } + + onCut() { + this.text = this.text.substring(0, this.leftCaretPos) + this.text.substring(this.rightCaretPos); + this.targetCaretPos = this.leftCaretPos; + } + + changeAvoidHeight(value: number) { + let event: emitter.InnerEvent = { + eventId: Constants.AVOID_EVENT_ID + }; + let eventData: emitter.EventData = { + data: { + 'avoidHeight': value + } + }; + emitter.emit(event, eventData); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/MainPage.ets b/entry/src/main/ets/pages/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..2d37216d3e495ba502aa6f4d3ce87ea66d88db44 --- /dev/null +++ b/entry/src/main/ets/pages/MainPage.ets @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024 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. + */ + +import { emitter } from '@kit.BasicServicesKit'; +import { Constants } from '../constants/Constants'; +import { TextInputComponent } from '../view/TextInputComponent'; + +@Entry +@Component +struct MainPage { + @State bottomPadding: number = Constants.MAIN_PAGE_INITIAL_PADDING; + + aboutToAppear(): void { + let event: emitter.InnerEvent = { + eventId: Constants.AVOID_EVENT_ID + } + emitter.on(event, (eventData: emitter.EventData) => { + if (eventData.data) { + let avoidHeight: number = eventData.data['avoidHeight']; + if (avoidHeight === 0) { + this.bottomPadding = Constants.MAIN_PAGE_INITIAL_PADDING; + } else { + this.bottomPadding = avoidHeight; + } + } + }) + } + + build() { + Navigation() { + Column() { + Image($r('app.media.arkui_background')) + .height($r('app.float.main_page_image_height')) + .width('100%') + .borderRadius(Constants.IMAGE_BORDER) + .padding({ left: $r('app.float.main_page_margin'), right: $r('app.float.main_page_margin') }) + + TextInputComponent() + } + .height('100%') + .justifyContent(FlexAlign.End) + .padding({ bottom: this.bottomPadding }) + .expandSafeArea([SafeAreaType.KEYBOARD, SafeAreaType.SYSTEM]) + } + .mode(NavigationMode.Stack) + .titleMode(NavigationTitleMode.Full) + .title($r('app.string.main_page_title')) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/view/CustomKeyboard.ets b/entry/src/main/ets/view/CustomKeyboard.ets new file mode 100644 index 0000000000000000000000000000000000000000..531c8b9cae93532eb334c0bbeef15bd58582bc6d --- /dev/null +++ b/entry/src/main/ets/view/CustomKeyboard.ets @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 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. + */ + +import { Constants } from '../constants/Constants'; +import { KeyboardController } from '../model/KeyboardController'; +import { EnglishKeyboard } from './EnglishKeyboard'; +import { NumberKeyboard } from './NumberKeyboard'; + +@Component +export struct CustomKeyboard { + @Consume isCustomKeyboardAttach: boolean; + @Consume inputText: string; + @Consume keyBoardController: KeyboardController; + @Consume systemKeyboardHeight: number; + @Consume customKeyboardHeight: number; + @Consume bottomRectHeight: number; + + build() { + Column() { + NumberKeyboard() + .visibility(this.keyBoardController.keyBoardType === Constants.NUMBER_KEYBOARD ? Visibility.Visible : + Visibility.None) + .margin({ top: $r('app.float.keyboard_margin_top') }) + + EnglishKeyboard() + .visibility(this.keyBoardController.keyBoardType === Constants.ENGLISH_KEYBOARD ? Visibility.Visible : + Visibility.None) + .margin({ top: $r('app.float.keyboard_margin_top') }) + } + .onAreaChange((oldValue: Area, newValue: Area) => { + this.customKeyboardHeight = Number(newValue.height); + let avoidHeight: number = (this.isCustomKeyboardAttach ? this.customKeyboardHeight : this.systemKeyboardHeight) + - this.bottomRectHeight; + this.keyBoardController.changeAvoidHeight(avoidHeight); + }) + .padding({ left: $r('app.float.keyboard_padding'), right: $r('app.float.keyboard_padding') }) + .height($r('app.float.keyboard_total_height')) + .width('100%') + .backgroundColor($r('app.color.keyboard_background_color')) + } +} + diff --git a/entry/src/main/ets/view/EnglishKeyboard.ets b/entry/src/main/ets/view/EnglishKeyboard.ets new file mode 100644 index 0000000000000000000000000000000000000000..be7ab1eb25b0d74a21a0123e9f8d4931179da975 --- /dev/null +++ b/entry/src/main/ets/view/EnglishKeyboard.ets @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2024 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. + */ + +import { EnglishKeyboardData, Menu } from '../viewmodel/MenuModel'; +import { KeyboardController } from '../model/KeyboardController'; +import { Constants } from '../constants/Constants'; + +@Component +export struct EnglishKeyboard { + build() { + Row() { + Scroll() { + Column() { + Row({ space: Constants.ENGLISH_KEYBOARD_BUTTON_SPACE }) { + ForEach(EnglishKeyboardData[0], (item: Menu) => { + EnglishButton({ item: item }) + }, (item: Menu) => JSON.stringify(item)) + } + + Row({ space: Constants.ENGLISH_KEYBOARD_BUTTON_SPACE }) { + ForEach(EnglishKeyboardData[1], (item: Menu) => { + EnglishButton({ item: item }) + }, (item: Menu) => JSON.stringify(item)) + } + .padding({ + left: $r('app.float.english_keyboard_padding_left'), + right: $r('app.float.english_keyboard_padding_right'), + top: $r('app.float.english_keyboard_padding_top') + }) + + Row({ space: Constants.ENGLISH_KEYBOARD_BUTTON_SPACE }) { + ForEach(EnglishKeyboardData[2], (item: Menu) => { + EnglishButton({ item: item }) + }, (item: Menu) => JSON.stringify(item)) + } + .padding({ top: $r('app.float.english_keyboard_padding_top') }) + + Row({ space: Constants.ENGLISH_KEYBOARD_BUTTON_SPACE }) { + ForEach(EnglishKeyboardData[3], (item: Menu) => { + EnglishButton({ item: item }) + }, (item: Menu) => JSON.stringify(item)) + } + .padding({ top: $r('app.float.english_keyboard_padding_top') }) + } + } + .scrollable(ScrollDirection.Horizontal) + .scrollBar(BarState.Off) + } + } +} + +@Component +struct EnglishButton { + @Prop item: Menu; + @Consume inputText: string; + @Consume keyBoardController: KeyboardController; + + getEnglishText(item: Menu): string | Resource { + if (this.keyBoardController.isUpperCase && item.upperText) { + return item.upperText; + } else { + return item.text; + } + } + + build() { + Button(this.getEnglishText(this.item), { type: ButtonType.Normal }) + .fontColor(Color.Black) + .backgroundColor(this.item.backgroundColor) + .borderRadius(Constants.KEYBOARD_BUTTON_RADIUS) + .fontSize(Constants.KEYBOARD_BUTTON_FONTSIZE_18) + .padding(0) + .width(this.item.width) + .height(this.item.height) + .onClick(() => { + this.inputText = this.keyBoardController.onInput(this.getEnglishText(this.item)); + }) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/view/NumberKeyboard.ets b/entry/src/main/ets/view/NumberKeyboard.ets new file mode 100644 index 0000000000000000000000000000000000000000..56e8ebf6923eaef86d65da6ea11b9d5cf5f2bca7 --- /dev/null +++ b/entry/src/main/ets/view/NumberKeyboard.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 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. + */ + +import { Menu, numberKeyboardData } from '../viewmodel/MenuModel'; +import { KeyboardController } from '../model/KeyboardController'; +import { Constants } from '../constants/Constants'; + +@Component +export struct NumberKeyboard { + @Consume inputText: string; + @Consume keyBoardController: KeyboardController; + layoutOptions: GridLayoutOptions = { + regularSize: [1, 1], + irregularIndexes: [14, 16], + onGetIrregularSizeByIndex: (index: number) => { + if (index === 14) { + return [2, 1]; + } + return [1, 2]; + } + }; + + build() { + Grid(undefined, this.layoutOptions) { + ForEach(numberKeyboardData, (item: Menu) => { + GridItem() { + Button(item.text, { type: ButtonType.Normal }) + .fontColor(Color.Black) + .backgroundColor(item.backgroundColor) + .borderRadius(Constants.KEYBOARD_BUTTON_RADIUS) + .fontSize(Constants.KEYBOARD_BUTTON_FONTSIZE_18) + .padding(0) + .width(item.width) + .height(item.height) + .onClick(() => { + this.inputText = this.keyBoardController.onInput(item.text); + }) + } + }, (item: Menu) => JSON.stringify(item)) + } + .columnsTemplate('1fr 1fr 1fr 1fr 1fr') + .rowsGap($r('app.float.number_keyboard_grid_gap')) + .columnsGap($r('app.float.number_keyboard_grid_gap')) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/view/TabButton.ets b/entry/src/main/ets/view/TabButton.ets new file mode 100644 index 0000000000000000000000000000000000000000..e05023e0d468e10edbdfdd31c19874257324d061 --- /dev/null +++ b/entry/src/main/ets/view/TabButton.ets @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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. + */ + +import { Constants } from '../constants/Constants'; +import { KeyboardController } from '../model/KeyboardController'; + +@Component +export struct TabButton { + @Consume isCustomKeyboardAttach: boolean; + @Prop text: Resource; + @Prop type: string; + @Consume keyBoardController: KeyboardController; + + build() { + Button(this.text, { type: ButtonType.Normal }) + .width($r('app.float.tabview_button_width')) + .height($r('app.float.tabview_button_height')) + .borderRadius(Constants.BUTTON_BORDER) + .fontSize(Constants.KEYBOARD_BUTTON_FONTSIZE_20) + .margin({ top: $r('app.float.keyboard_padding_top') }) + .backgroundColor(this.keyBoardController.keyBoardType === this.type ? Color.White : + $r('app.color.keyboard_background_color')) + .fontColor(this.keyBoardController.keyBoardType === this.type ? $r('app.color.menu_color_blue') : + Color.Black) + .onClick(() => { + this.keyBoardController.keyBoardType = this.type; + this.isCustomKeyboardAttach = this.type !== Constants.SYSTEM_KEYBOARD; + }) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/view/TabView.ets b/entry/src/main/ets/view/TabView.ets new file mode 100644 index 0000000000000000000000000000000000000000..48e18965ab0ff168f93db2bbbeb9d0b88efb5ccc --- /dev/null +++ b/entry/src/main/ets/view/TabView.ets @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 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. + */ + +import { Constants } from '../constants/Constants'; +import { TabButton } from './TabButton'; + +@Component +export struct TabView { + build() { + Row({ space: Constants.DEFAULT_COLUMN_SPACE }) { + TabButton({ text: $r('app.string.tabButton_number_text'), type: Constants.NUMBER_KEYBOARD }) + TabButton({ text: $r('app.string.tabButton_english_text'), type: Constants.ENGLISH_KEYBOARD }) + TabButton({ text: $r('app.string.tabButton_system_text'), type: Constants.SYSTEM_KEYBOARD }) + } + .justifyContent(FlexAlign.Center) + .width('100%') + .margin({ top: $r('app.float.main_page_margin_top') }) + .height($r('app.float.tabview_height')) + .backgroundColor($r('app.color.keyboard_background_color')) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/view/TextInputComponent.ets b/entry/src/main/ets/view/TextInputComponent.ets new file mode 100644 index 0000000000000000000000000000000000000000..80a1f857155b414535914991787c1305cd2fb37c --- /dev/null +++ b/entry/src/main/ets/view/TextInputComponent.ets @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2024 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. + */ + +import { window } from '@kit.ArkUI'; +import { KeyboardController } from '../model/KeyboardController'; +import { CustomKeyboard } from './CustomKeyboard'; +import { TabView } from './TabView'; + +@Component +export struct TextInputComponent { + @Provide keyBoardController: KeyboardController = new KeyboardController(); + @Provide isCustomKeyboardAttach: boolean = true; + @Provide isTabViewShow: boolean = false; + @Provide inputText: string = ''; + @Provide systemKeyboardHeight: number = 0; + @Provide customKeyboardHeight: number = 0; + @Provide bottomRectHeight: number = 0; + textInputController: TextInputController = new TextInputController(); + + aboutToAppear(): void { + this.keyBoardController.textInputController = this.textInputController; + window.getLastWindow(getContext(), (err, data) => { + let avoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); + this.bottomRectHeight = px2vp(avoidArea.bottomRect.height); + data.on('keyboardHeightChange', (value) => { + if (value) { + this.systemKeyboardHeight = px2vp(value); + let avoidHeight: number = + (this.isCustomKeyboardAttach ? this.customKeyboardHeight : this.systemKeyboardHeight) + - this.bottomRectHeight; + this.keyBoardController.changeAvoidHeight(avoidHeight); + } + }) + }) + } + + build() { + Column() { + TextInput({ + placeholder: $r('app.string.textInput_placeholder_custom'), + text: this.inputText, + controller: this.textInputController + }) + .margin({ + top: $r('app.float.main_page_margin_top'), + left: $r('app.float.main_page_margin'), + right: $r('app.float.main_page_margin') + }) + .customKeyboard(this.isCustomKeyboardAttach ? this.customKeyboard() : null) + .onTextSelectionChange((start: number, end: number) => { + this.keyBoardController.setCaretPosition(start, end); + }) + .onBlur(() => { + this.isTabViewShow = false; + this.keyBoardController.changeAvoidHeight(0); + }) + .onFocus(() => { + this.isTabViewShow = true; + }) + .onChange((value) => { + this.inputText = value; + this.keyBoardController.onChange(value); + }) + .onCut(() => { + this.keyBoardController.onCut(); + }) + .onPaste((value) => { + this.keyBoardController.onPaste(value); + }) + .height($r('app.float.main_page_textInput_height')) + TabView() + .visibility(this.isTabViewShow ? Visibility.Visible : Visibility.Hidden) + } + } + + @Builder + customKeyboard() { + CustomKeyboard() + } +} \ No newline at end of file diff --git a/entry/src/main/ets/viewmodel/MenuModel.ets b/entry/src/main/ets/viewmodel/MenuModel.ets new file mode 100644 index 0000000000000000000000000000000000000000..a7033ed1aed94ca74ca024d088075db76cf8b80c --- /dev/null +++ b/entry/src/main/ets/viewmodel/MenuModel.ets @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2024 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. + */ + +export let numberKeyboardData: Menu[] = [ + { + text: ',', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '1', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '2', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '3', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: $r('app.string.keyboardButton_delete'), + backgroundColor: $r('app.color.menu_color_gray'), + width: '100%', + height: '46vp' + }, + { + text: '?', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '4', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '5', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '6', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: $r('app.string.keyboardButton_clear'), + backgroundColor: $r('app.color.menu_color_gray'), + width: '100%', + height: '46vp' + }, + { + text: '!', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '7', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '8', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '9', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: $r('app.string.keyboardButton_finish'), + backgroundColor: $r('app.color.menu_color_gray'), + width: '100%', + height: '98vp' + }, + { + text: $r('app.string.tabButton_english_text'), + backgroundColor: $r('app.color.menu_color_gray'), + width: '100%', + height: '46vp' + }, + { + text: '0', + backgroundColor: $r('app.color.menu_color_white'), + width: '100%', + height: '46vp' + }, + { + text: '.', + backgroundColor: $r('app.color.menu_color_gray'), + width: '100%', + height: '46vp' + } +] + +export let EnglishKeyboardData: Menu[][] = [ + [ + { + text: 'q', + upperText: 'Q', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'w', + upperText: 'W', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'e', + upperText: 'E', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'r', + upperText: 'R', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 't', + upperText: 'T', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'y', + upperText: 'Y', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'u', + upperText: 'U', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'i', + upperText: 'I', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'o', + upperText: 'O', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'p', + upperText: 'P', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + } + ], + [ + { + text: 'a', + upperText: 'A', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 's', + upperText: 'S', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'd', + upperText: 'D', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'f', + upperText: 'F', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'g', + upperText: 'G', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'h', + upperText: 'H', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'j', + upperText: 'J', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'k', + upperText: 'K', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'l', + upperText: 'L', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + } + ], + [ + { + text: $r('app.string.keyboardButton_uppercase'), + upperText: $r('app.string.keyboardButton_lowercase'), + backgroundColor: $r('app.color.menu_color_gray'), + width: 49 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'z', + upperText: 'Z', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'x', + upperText: 'X', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'c', + upperText: 'C', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'v', + upperText: 'V', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'b', + upperText: 'B', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'n', + upperText: 'N', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: 'm', + upperText: 'M', + backgroundColor: $r('app.color.menu_color_white'), + width: 30 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: $r('app.string.keyboardButton_delete'), + backgroundColor: $r('app.color.menu_color_gray'), + width: 49 + px2vp(6) + 'vp', + height: '43vp' + } + ], + [ + { + text: $r('app.string.tabButton_number_text'), + backgroundColor: $r('app.color.menu_color_gray'), + width: 72 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: $r('app.string.keyboardButton_space'), + backgroundColor: $r('app.color.menu_color_white'), + width: 212 + px2vp(6) + 'vp', + height: '43vp' + }, + { + text: $r('app.string.keyboardButton_finish'), + backgroundColor: $r('app.color.menu_color_gray'), + width: 72 + px2vp(6) + 'vp', + height: '43vp' + } + ] +] + +export interface Menu { + text: string | Resource; + upperText?: string | Resource; + backgroundColor: Resource; + width: string; + height: string; +} diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ad219d733f6afa5ea07f85f580208b08cc3b9041 --- /dev/null +++ b/entry/src/main/module.json5 @@ -0,0 +1,50 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..da6ce5fb4d434af7cff9fce0423b6f7b2ca890d7 --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,24 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "menu_color_white", + "value": "#FFFFFF" + }, + { + "name": "menu_color_gray", + "value": "#BCC0C7" + }, + { + "name": "menu_color_blue", + "value": "#0A58F7" + }, + { + "name": "keyboard_background_color", + "value": "#DEE0E6" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..c29ed92f9b49e5b4afd61329ff821589d665ba70 --- /dev/null +++ b/entry/src/main/resources/base/element/float.json @@ -0,0 +1,64 @@ +{ + "float": [ + { + "name": "main_page_margin", + "value": "16vp" + }, + { + "name": "main_page_textInput_height", + "value": "37vp" + }, + { + "name": "main_page_image_height", + "value": "209vp" + }, + { + "name": "main_page_margin_top", + "value": "15vp" + }, + { + "name": "keyboard_padding", + "value": "7vp" + }, + { + "name": "keyboard_padding_top", + "value": "12vp" + }, + { + "name": "keyboard_margin_top", + "value": "10vp" + }, + { + "name": "keyboard_total_height", + "value": "283vp" + }, + { + "name": "number_keyboard_grid_gap", + "value": "6vp" + }, + { + "name": "english_keyboard_padding_top", + "value": "11vp" + }, + { + "name": "english_keyboard_padding_left", + "value": "18vp" + }, + { + "name": "english_keyboard_padding_right", + "value": "18vp" + }, + { + "name": "tabview_height", + "value": "54vp" + }, + { + "name": "tabview_button_height", + "value": "35vp" + }, + { + "name": "tabview_button_width", + "value": "114vp" + } + ] +} \ No newline at end of file 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 0000000000000000000000000000000000000000..8963a456a3839884c970df84596034d3265f5f31 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,60 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "CustomKeyboard" + }, + { + "name": "main_page_title", + "value": "CustomKeyboard" + }, + { + "name": "textInput_placeholder_custom", + "value": "Binding custom keyboard" + }, + { + "name": "tabButton_number_text", + "value": "123" + }, + { + "name": "tabButton_english_text", + "value": "ABC" + }, + { + "name": "tabButton_system_text", + "value": "中文" + }, + { + "name": "keyboardButton_delete", + "value": "删除" + }, + { + "name": "keyboardButton_clear", + "value": "清空" + }, + { + "name": "keyboardButton_finish", + "value": "确认" + }, + { + "name": "keyboardButton_space", + "value": "空格" + }, + { + "name": "keyboardButton_uppercase", + "value": "大写" + }, + { + "name": "keyboardButton_lowercase", + "value": "小写" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/arkui_background.png b/entry/src/main/resources/base/media/arkui_background.png new file mode 100644 index 0000000000000000000000000000000000000000..e388137712a3c172572786fdd94c29c9da93c266 Binary files /dev/null and b/entry/src/main/resources/base/media/arkui_background.png differ diff --git a/entry/src/main/resources/base/media/background.png b/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/entry/src/main/resources/base/media/background.png differ diff --git a/entry/src/main/resources/base/media/foreground.png b/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/entry/src/main/resources/base/media/foreground.png differ diff --git a/entry/src/main/resources/base/media/layered_image.json b/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/startIcon.png b/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/entry/src/main/resources/base/media/startIcon.png differ diff --git a/entry/src/main/resources/base/profile/backup_config.json b/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c89f1c1a4bcc3b2a9180f1d55d1527740b0f0c13 --- /dev/null +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/MainPage" + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8963a456a3839884c970df84596034d3265f5f31 --- /dev/null +++ b/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,60 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "CustomKeyboard" + }, + { + "name": "main_page_title", + "value": "CustomKeyboard" + }, + { + "name": "textInput_placeholder_custom", + "value": "Binding custom keyboard" + }, + { + "name": "tabButton_number_text", + "value": "123" + }, + { + "name": "tabButton_english_text", + "value": "ABC" + }, + { + "name": "tabButton_system_text", + "value": "中文" + }, + { + "name": "keyboardButton_delete", + "value": "删除" + }, + { + "name": "keyboardButton_clear", + "value": "清空" + }, + { + "name": "keyboardButton_finish", + "value": "确认" + }, + { + "name": "keyboardButton_space", + "value": "空格" + }, + { + "name": "keyboardButton_uppercase", + "value": "大写" + }, + { + "name": "keyboardButton_lowercase", + "value": "小写" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7125db916efb75b41cf8cab684de4cb1548e4baf --- /dev/null +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,60 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "CustomKeyboard" + }, + { + "name": "main_page_title", + "value": "自定义键盘" + }, + { + "name": "textInput_placeholder_custom", + "value": "绑定自定义键盘" + }, + { + "name": "tabButton_number_text", + "value": "123" + }, + { + "name": "tabButton_english_text", + "value": "ABC" + }, + { + "name": "tabButton_system_text", + "value": "中文" + }, + { + "name": "keyboardButton_delete", + "value": "删除" + }, + { + "name": "keyboardButton_clear", + "value": "清空" + }, + { + "name": "keyboardButton_finish", + "value": "确认" + }, + { + "name": "keyboardButton_space", + "value": "空格" + }, + { + "name": "keyboardButton_uppercase", + "value": "大写" + }, + { + "name": "keyboardButton_lowercase", + "value": "小写" + } + ] +} \ No newline at end of file diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..06b2783670a348f95533b352c1ceda909a842bbc --- /dev/null +++ b/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/hvigorfile.ts b/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/oh-package.json5 b/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bb12751b97530b9a3504e56e8ed09d8c9ba1fa52 --- /dev/null +++ b/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/screenshots/device/avoid.gif b/screenshots/device/avoid.gif new file mode 100644 index 0000000000000000000000000000000000000000..cc2e114884aa59bcd9a2b57b8ccfa9d8931348fb Binary files /dev/null and b/screenshots/device/avoid.gif differ diff --git a/screenshots/device/switch.gif b/screenshots/device/switch.gif new file mode 100644 index 0000000000000000000000000000000000000000..9bd3dddb955e5381ee03fa2351809524a9274459 Binary files /dev/null and b/screenshots/device/switch.gif differ diff --git a/screenshots/device/use.gif b/screenshots/device/use.gif new file mode 100644 index 0000000000000000000000000000000000000000..d02d8ce39cb1b9a1549fa1d1a9e623772077cbbb Binary files /dev/null and b/screenshots/device/use.gif differ