From 264628371d02ac37218e7d840ef6792c7e2f6567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BC=9F=E6=9D=83?= Date: Sat, 12 Apr 2025 14:14:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cases/IME/case001/.gitignore | 6 ++ cases/IME/case001/BuildProfile.ets | 17 ++++ cases/IME/case001/Index.ets | 1 + cases/IME/case001/build-profile.json5 | 28 ++++++ cases/IME/case001/consumer-rules.txt | 0 cases/IME/case001/manifest.json | 6 ++ cases/IME/case001/obfuscation-rules.txt | 23 +++++ cases/IME/case001/oh-package.json5 | 11 +++ .../main/ets/entryability/EntryAbility.ets | 99 +++++++++++++++++++ cases/IME/case001/src/main/module.json5 | 46 +++++++++ .../base/profile/input_method_config.json | 18 ++++ .../resources/base/profile/main_pages.json | 10 ++ 12 files changed, 265 insertions(+) create mode 100644 cases/IME/case001/.gitignore create mode 100644 cases/IME/case001/BuildProfile.ets create mode 100644 cases/IME/case001/Index.ets create mode 100644 cases/IME/case001/build-profile.json5 create mode 100644 cases/IME/case001/consumer-rules.txt create mode 100644 cases/IME/case001/manifest.json create mode 100644 cases/IME/case001/obfuscation-rules.txt create mode 100644 cases/IME/case001/oh-package.json5 create mode 100644 cases/IME/case001/src/main/ets/entryability/EntryAbility.ets create mode 100644 cases/IME/case001/src/main/module.json5 create mode 100644 cases/IME/case001/src/main/resources/base/profile/input_method_config.json create mode 100644 cases/IME/case001/src/main/resources/base/profile/main_pages.json diff --git a/cases/IME/case001/.gitignore b/cases/IME/case001/.gitignore new file mode 100644 index 0000000..e2713a2 --- /dev/null +++ b/cases/IME/case001/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/cases/IME/case001/BuildProfile.ets b/cases/IME/case001/BuildProfile.ets new file mode 100644 index 0000000..3a501e5 --- /dev/null +++ b/cases/IME/case001/BuildProfile.ets @@ -0,0 +1,17 @@ +/** + * Use these variables when you tailor your ArkTS code. They must be of the const type. + */ +export const HAR_VERSION = '1.0.0'; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; +export const TARGET_NAME = 'default'; + +/** + * BuildProfile Class is used only for compatibility purposes. + */ +export default class BuildProfile { + static readonly HAR_VERSION = HAR_VERSION; + static readonly BUILD_MODE_NAME = BUILD_MODE_NAME; + static readonly DEBUG = DEBUG; + static readonly TARGET_NAME = TARGET_NAME; +} \ No newline at end of file diff --git a/cases/IME/case001/Index.ets b/cases/IME/case001/Index.ets new file mode 100644 index 0000000..42bf416 --- /dev/null +++ b/cases/IME/case001/Index.ets @@ -0,0 +1 @@ +export { MainPage } from './src/main/ets/components/MainPage'; diff --git a/cases/IME/case001/build-profile.json5 b/cases/IME/case001/build-profile.json5 new file mode 100644 index 0000000..cda3307 --- /dev/null +++ b/cases/IME/case001/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + } + ] +} diff --git a/cases/IME/case001/consumer-rules.txt b/cases/IME/case001/consumer-rules.txt new file mode 100644 index 0000000..e69de29 diff --git a/cases/IME/case001/manifest.json b/cases/IME/case001/manifest.json new file mode 100644 index 0000000..ca67fdc --- /dev/null +++ b/cases/IME/case001/manifest.json @@ -0,0 +1,6 @@ +{ + "caseNO": "case001", + "desc": "InputMethod", + "home": "case001/home", + "dependencies": [] +} \ No newline at end of file diff --git a/cases/IME/case001/obfuscation-rules.txt b/cases/IME/case001/obfuscation-rules.txt new file mode 100644 index 0000000..272efb6 --- /dev/null +++ b/cases/IME/case001/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/cases/IME/case001/oh-package.json5 b/cases/IME/case001/oh-package.json5 new file mode 100644 index 0000000..843f2a7 --- /dev/null +++ b/cases/IME/case001/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "case001", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": { + "@hadss/dialoghub": "file:./hadss_dialog.har" + } +} diff --git a/cases/IME/case001/src/main/ets/entryability/EntryAbility.ets b/cases/IME/case001/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000..37f1eee --- /dev/null +++ b/cases/IME/case001/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2025 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 '@ohos.hilog'; +import Window from '@ohos.window'; +import { AbilityConstant, Permissions, Want,AbilityLifecycleCallback, UIAbility } from '@kit.AbilityKit'; +import { PreferencesHandler } from '../model/PreferencesHandler'; +import window from '@ohos.window'; +import { SysPermissionUtil } from '../common/utils/SysPermissionUtil'; +import { KeyboardAvoidMode } from '@kit.ArkUI'; + + + +export default class EntryAbility extends UIAbility { + async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); + let AbilityLifecycleCallback: AbilityLifecycleCallback = { + onAbilityCreate(ability) { + console.log(`AbilityLifecycleCallback onAbilityCreate ability: ${ability}`); + }, + onWindowStageCreate(ability, windowStage) { + console.log(`AbilityLifecycleCallback onWindowStageCreate ability: ${ability}`); + console.log(`AbilityLifecycleCallback onWindowStageCreate windowStage: ${windowStage}`); + }, + onWindowStageActive(ability, windowStage) { + console.log(`AbilityLifecycleCallback onWindowStageActive ability: ${ability}`); + console.log(`AbilityLifecycleCallback onWindowStageActive windowStage: ${windowStage}`); + }, + onWindowStageInactive(ability, windowStage) { + console.log(`AbilityLifecycleCallback onWindowStageInactive ability: ${ability}`); + console.log(`AbilityLifecycleCallback onWindowStageInactive windowStage: ${windowStage}`); + }, + onWindowStageDestroy(ability, windowStage) { + console.log(`AbilityLifecycleCallback onWindowStageDestroy ability: ${ability}`); + console.log(`AbilityLifecycleCallback onWindowStageDestroy windowStage: ${windowStage}`); + }, + onAbilityDestroy(ability) { + console.log(`AbilityLifecycleCallback onAbilityDestroy ability: ${ability}`); + }, + onAbilityForeground(ability) { + console.log(`AbilityLifecycleCallback onAbilityForeground ability: ${ability}`); + }, + onAbilityBackground(ability) { + console.log(`AbilityLifecycleCallback onAbilityBackground ability: ${ability}`); + }, + onAbilityContinue(ability) { + console.log(`AbilityLifecycleCallback onAbilityContinue ability: ${ability}`); + } + } + let applicationContext = this.context.getApplicationContext(); + applicationContext.on('abilityLifecycle', AbilityLifecycleCallback); + } + + onDestroy() { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + PreferencesHandler.getInstance().release(); + } + + async onWindowStageCreate(windowStage: Window.WindowStage) { + windowStage.getMainWindowSync().setPreferredOrientation(window.Orientation.PORTRAIT); + + windowStage.on('windowStageEvent', (data) => { + console.info('cwq Succeeded in enabling the listener for window stage event changes. Data: ' + + JSON.stringify(data)); + }); + windowStage.loadContent('pages/MainSetting', (err, data) => { + if (err.code) { + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { + console.log('cwq onNewWant want ' + JSON.stringify(want)) + let permission = want.parameters?.permission as Permissions; + SysPermissionUtil.request(this.context, [permission], (isGranted, str, isDialogShow) => { + this.context.moveAbilityToBackground(); + }) + } +}; diff --git a/cases/IME/case001/src/main/module.json5 b/cases/IME/case001/src/main/module.json5 new file mode 100644 index 0000000..6e7e00b --- /dev/null +++ b/cases/IME/case001/src/main/module.json5 @@ -0,0 +1,46 @@ +{ + "module": { + "name": "case001", + "type": "har", + "deviceTypes": [ + "default", + "tablet", + "2in1" + ], + "requestPermissions": [ + { + "name": "ohos.permission.MICROPHONE", + "reason": "$string:entry_desc", + "usedScene": { + "when": "always" + } + }, + { + // 通过ACL申请提权 + "name": "ohos.permission.READ_PASTEBOARD", + "reason": "$string:entry_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + ], + "extensionAbilities": [ + { + "srcEntry": "./ets/ServiceExtAbility/InputMethodService.ets", + "name": "InputMethodAbility", + "description": "$string:extension_ability_descripter", + "type": "inputMethod", + "exported": true, + "metadata": [ + { + "name": "ohos.extension.input_method", + "resource": "$profile:input_method_config" + } + ] + } + ] + } +} diff --git a/cases/IME/case001/src/main/resources/base/profile/input_method_config.json b/cases/IME/case001/src/main/resources/base/profile/input_method_config.json new file mode 100644 index 0000000..dc5ef92 --- /dev/null +++ b/cases/IME/case001/src/main/resources/base/profile/input_method_config.json @@ -0,0 +1,18 @@ +{ + "subtypes": [ + { + "icon": "$media:en", + "id": "InputMethodExtAbility", + "label": "$string:input_method_en", + "locale": "en-US", + "mode": "lower" + }, + { + "icon": "$media:zh", + "id": "InputMethodExtAbility1", + "label": "$string:input_method_zn", + "locale": "zh-CN", + "mode": "lower" + } + ] +} \ No newline at end of file diff --git a/cases/IME/case001/src/main/resources/base/profile/main_pages.json b/cases/IME/case001/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000..960c6b5 --- /dev/null +++ b/cases/IME/case001/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,10 @@ +{ + "src": [ + "pages/SoftKeyboard", + "pages/MainSetting", + "pages/PhysicKeyboard", + "pages/AssistBar", + "pages/AdjustArea", + "pages/KeyboardSetting" + ] +} \ No newline at end of file -- Gitee