From 1dc0b91608f3431b993f3738e04b1284f83b359e Mon Sep 17 00:00:00 2001 From: wangzongmao Date: Tue, 6 Jul 2021 21:01:01 +0800 Subject: [PATCH] add sample for MultiModeInput Signed-off-by: wangzongmao --- UI/MultiModeInput/README_en.md | 21 ++++ UI/MultiModeInput/README_zh.md | 21 ++++ UI/MultiModeInput/build.gradle | 35 +++++++ UI/MultiModeInput/entry/build.gradle | 19 ++++ UI/MultiModeInput/entry/src/main/config.json | 65 ++++++++++++ .../samples/multimodeinput/MainAbility.java | 33 ++++++ .../samples/multimodeinput/MyApplication.java | 30 ++++++ .../slice/KeyEventAbilitySlice.java | 96 ++++++++++++++++++ .../slice/MainAbilitySlice.java | 46 +++++++++ .../multimodeinput/slice/MouseEventSlice.java | 96 ++++++++++++++++++ .../slice/SpeechAbilitySlice.java | 89 ++++++++++++++++ .../slice/TouchAbilitySlice.java | 85 ++++++++++++++++ .../samples/multimodeinput/utils/Utils.java | 72 +++++++++++++ .../main/resources/base/element/color.json | 64 ++++++++++++ .../main/resources/base/element/float.json | 44 ++++++++ .../main/resources/base/element/string.json | 44 ++++++++ .../base/graphic/background_ability_main.xml | 20 ++++ .../base/graphic/background_dialog.xml | 21 ++++ .../main/resources/base/graphic/button_bg.xml | 23 +++++ .../resources/base/graphic/button_blue.xml | 22 ++++ .../base/graphic/button_blue_empty.xml | 21 ++++ .../base/graphic/button_blue_pressed.xml | 21 ++++ .../resources/base/graphic/button_gray.xml | 22 ++++ .../base/graphic/button_gray_empty.xml | 21 ++++ .../base/graphic/button_gray_pressed.xml | 21 ++++ .../resources/base/graphic/button_white.xml | 22 ++++ .../base/graphic/button_white_empty.xml | 21 ++++ .../base/graphic/button_white_pressed.xml | 21 ++++ .../resources/base/graphic/dialog_button.xml | 22 ++++ .../main/resources/base/graphic/list_item.xml | 22 ++++ .../base/graphic/list_item_clicked.xml | 20 ++++ .../base/graphic/list_item_nomral.xml | 20 ++++ .../resources/base/graphic/single_box.xml | 22 ++++ .../base/graphic/single_box_checked.xml | 24 +++++ .../base/graphic/single_box_normal.xml | 24 +++++ .../base/layout/first_main_ability_slice.xml | 38 +++++++ .../base/layout/key_main_ability_slice.xml | 38 +++++++ .../base/layout/main_ability_slice.xml | 78 ++++++++++++++ .../base/layout/mouse_ability_slice.xml | 38 +++++++ .../base/layout/second_main_ability_slice.xml | 37 +++++++ .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../src/main/resources/en/element/string.json | 44 ++++++++ .../src/main/resources/zh/element/string.json | 44 ++++++++ .../screenshots/device/button.png | Bin 0 -> 60577 bytes .../screenshots/device/keyevent.png | Bin 0 -> 76299 bytes .../screenshots/device/touchevent.png | Bin 0 -> 73786 bytes UI/MultiModeInput/settings.gradle | 15 +++ 47 files changed, 1602 insertions(+) create mode 100644 UI/MultiModeInput/README_en.md create mode 100644 UI/MultiModeInput/README_zh.md create mode 100644 UI/MultiModeInput/build.gradle create mode 100644 UI/MultiModeInput/entry/build.gradle create mode 100644 UI/MultiModeInput/entry/src/main/config.json create mode 100644 UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/MainAbility.java create mode 100644 UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/MyApplication.java create mode 100644 UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/KeyEventAbilitySlice.java create mode 100644 UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/MainAbilitySlice.java create mode 100644 UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/MouseEventSlice.java create mode 100644 UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/SpeechAbilitySlice.java create mode 100644 UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/TouchAbilitySlice.java create mode 100644 UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/utils/Utils.java create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/element/color.json create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/element/float.json create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/element/string.json create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/background_ability_main.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/background_dialog.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_bg.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue_empty.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue_pressed.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray_empty.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray_pressed.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white_empty.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white_pressed.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/dialog_button.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item_clicked.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item_nomral.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box_checked.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box_normal.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/layout/first_main_ability_slice.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/layout/key_main_ability_slice.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/layout/main_ability_slice.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/layout/mouse_ability_slice.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/layout/second_main_ability_slice.xml create mode 100644 UI/MultiModeInput/entry/src/main/resources/base/media/icon.png create mode 100644 UI/MultiModeInput/entry/src/main/resources/en/element/string.json create mode 100644 UI/MultiModeInput/entry/src/main/resources/zh/element/string.json create mode 100644 UI/MultiModeInput/screenshots/device/button.png create mode 100644 UI/MultiModeInput/screenshots/device/keyevent.png create mode 100644 UI/MultiModeInput/screenshots/device/touchevent.png create mode 100644 UI/MultiModeInput/settings.gradle diff --git a/UI/MultiModeInput/README_en.md b/UI/MultiModeInput/README_en.md new file mode 100644 index 0000000000..1217eb07fc --- /dev/null +++ b/UI/MultiModeInput/README_en.md @@ -0,0 +1,21 @@ +# Multimodal Input + +##### Introduction + +This sample app of multimodal input illustrates how to use APIs such as **KeyEventListener**, **TouchEventListener**, and **SpeechEventListener** to handle corresponding key, touch, and speech events. + +##### Usage + +The home page of the sample app contains the **touchEvent**, **keyEvent**, **mouseEvent**, and **speechEvent** buttons. The specific implementation is as follows: + +1. When you tap the **touchEvent** button, you will be redirected to another page. If you tap the **touch** button on that page, a popup dialog indicating a touch event will be displayed. +2. When you tap the **keyEvent** button, you will be redirected to another page. If you press the volume key on the phone, a popup dialog indicating a key pressing event will be displayed. +3. When you tap the **mouseEvent** button, you will be redirected to another page. If you tap the **mouse** button on that page by pressing the left key of the mouse, a popup dialog indicating a mouse click event will be displayed. +4. When you tap the **speechEvent** button, you will be redirected to another page. If you press the voice assistant button on the remote control of HUAWEI Vision, a popup dialog indicating a speech event will be displayed. + +##### Constraints + +This sample can only be run on standard-system devices. + +The support for multimodal input events varies depending on device types. For details, see [Multimodal Input Overview](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ui-multimodal-overview-0000000000031876). + diff --git a/UI/MultiModeInput/README_zh.md b/UI/MultiModeInput/README_zh.md new file mode 100644 index 0000000000..84c77269ad --- /dev/null +++ b/UI/MultiModeInput/README_zh.md @@ -0,0 +1,21 @@ +# 多模输入 + +##### 简介 + +本示例通过实现相关接口KeyEventListener、TouchEventListener、SpeechEventListener等,对相应的事件进行处理,例如按键事件、触摸事件、语音事件等。 + +##### 使用说明 + +本事例主页面包含触摸事件按钮、按键事件按钮、鼠标事件按钮、语音事件按钮; + +1. 当点击触摸事件按钮时,跳转到另一个页面,用手指触摸当前页面上的按钮,页面上会弹出提示框显示触摸事件; +2. 当点击按键事件按钮时,跳转到另一个页面,按手机的音量键,页面上会弹出提示框显示按键事件; +3. 当点击鼠标事件按钮时,跳转到另一个页面,用鼠标左键点击当前页面上的按钮,页面上会弹出提示框显示鼠标事件; +4. 当点击语音事件按钮时,跳转到另一个页面,按智慧屏遥控器上的语音按钮,页面上会弹出提示框显示语音事件。 + +##### 约束与限制 + +本示例仅支持在标准系统上运行; + +多模输入事件在不同形态产品支持的情况请[点击链接](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ui-multimodal-overview-0000000000031876)查看。 + diff --git a/UI/MultiModeInput/build.gradle b/UI/MultiModeInput/build.gradle new file mode 100644 index 0000000000..53acf4ea9a --- /dev/null +++ b/UI/MultiModeInput/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 4 + } +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } + dependencies { + classpath 'com.huawei.ohos:hap:2.4.4.2' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/UI/MultiModeInput/entry/build.gradle b/UI/MultiModeInput/entry/build.gradle new file mode 100644 index 0000000000..d63e339a83 --- /dev/null +++ b/UI/MultiModeInput/entry/build.gradle @@ -0,0 +1,19 @@ +apply plugin: 'com.huawei.ohos.hap' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 4 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) +} diff --git a/UI/MultiModeInput/entry/src/main/config.json b/UI/MultiModeInput/entry/src/main/config.json new file mode 100644 index 0000000000..4745d73941 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/config.json @@ -0,0 +1,65 @@ +{ + "app": { + "bundleName": "ohos.samples.multimodeinput", + "version": { + "code": 1000000, + "name": "1.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.multimodeinput", + "name": ".MyApplication", + "deviceType": [ + "default" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "ohos.samples.multimodeinput.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.MULTIMODAL_INTERACTIVE", + "reason": "", + "usedScene": { + "ability": [ + ".MainAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.WRITE_EXTERNAL_STORAGE", + "reason": "", + "usedScene": { + "ability": [ + ".MainAbility" + ], + "when": "inuse" + } + } + ] + } +} \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/MainAbility.java b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/MainAbility.java new file mode 100644 index 0000000000..59407a020c --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/MainAbility.java @@ -0,0 +1,33 @@ +/* + * 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 ohos.samples.multimodeinput; + +import ohos.samples.multimodeinput.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + * + * @since 2021-05-20 + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/MyApplication.java b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/MyApplication.java new file mode 100644 index 0000000000..d82ee4bc2e --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/MyApplication.java @@ -0,0 +1,30 @@ +/* + * 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 ohos.samples.multimodeinput; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + * + * @since 2021-05-20 + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/KeyEventAbilitySlice.java b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/KeyEventAbilitySlice.java new file mode 100644 index 0000000000..e2e028c217 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/KeyEventAbilitySlice.java @@ -0,0 +1,96 @@ +/* + * 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 ohos.samples.multimodeinput.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.app.Context; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.multimodalinput.event.KeyEvent; +import ohos.samples.multimodeinput.ResourceTable; +import ohos.samples.multimodeinput.utils.Utils; + +import java.lang.ref.WeakReference; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +/** + * KeyAbilitySlice + * + * @since 2021-05-12 + */ +public class KeyEventAbilitySlice extends AbilitySlice { + private static final String TAG = "KeyEventAbilitySlice"; + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + /** + * BACK_KEY_CODE BACK KEY KEYCODE + */ + private static final int BACK_KEY_CODE = 2; + + private Component componentKey; + + private Utils utils = Utils.getInstance(); + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_key_main_ability_slice); + componentKey = findComponentById(ResourceTable.Id_key_event_text); + HiLog.info(LABEL_LOG, "setKeyEventListener"); + componentKey.setKeyEventListener(onKeyEvent); + componentKey.setTouchFocusable(true); + componentKey.setFocusable(Component.FOCUS_ENABLE); + componentKey.requestFocus(); + } + + private void showKeyEvent(KeyEvent keyEvent) { + WeakReference referenceContext = new WeakReference<>(getContext()); + String[] items = new String[] { + "This is keyEvent", + "Current Time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", + Locale.getDefault()).format(new Date().getTime()), + "keyCode Value: " + keyEvent.getKeyCode(), + "Key press duration: " + keyEvent.getKeyDownDuration(), + "Is Key Pressed: " + keyEvent.isKeyDown() + }; + utils.showDialogBox(items, referenceContext.get()); + } + + private Component.KeyEventListener onKeyEvent = new Component.KeyEventListener() { + @Override + public boolean onKeyEvent(Component component, KeyEvent keyEvent) { + HiLog.info(LABEL_LOG, "onKeyEvent"); + if (keyEvent.isKeyDown()) { + int keyCode = keyEvent.getKeyCode(); + if (keyCode != BACK_KEY_CODE) { + showKeyEvent(keyEvent); + } + } + return false; + } + }; + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + } +} diff --git a/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/MainAbilitySlice.java b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/MainAbilitySlice.java new file mode 100644 index 0000000000..d1bd29c338 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/MainAbilitySlice.java @@ -0,0 +1,46 @@ +/* + * 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 ohos.samples.multimodeinput.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.samples.multimodeinput.ResourceTable; + +/** + * MainAbilitySlice + * + * @since 2021-05-12 + */ +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_main_ability_slice); + Component componentTouch = findComponentById(ResourceTable.Id_touchEvent); + componentTouch.setClickedListener(listener -> present(new TouchAbilitySlice(), new Intent())); + + Component componentKey = findComponentById(ResourceTable.Id_keyEvent); + componentKey.setClickedListener(listener -> present(new KeyEventAbilitySlice(), new Intent())); + + Component componentMouse = findComponentById(ResourceTable.Id_mouseEvent); + componentMouse.setClickedListener(listener -> present(new MouseEventSlice(), new Intent())); + + Component componentSpeech = findComponentById(ResourceTable.Id_speechEvent); + componentSpeech.setClickedListener(listener -> present(new SpeechAbilitySlice(), new Intent())); + } + +} diff --git a/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/MouseEventSlice.java b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/MouseEventSlice.java new file mode 100644 index 0000000000..4ed86c1009 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/MouseEventSlice.java @@ -0,0 +1,96 @@ +/* + * 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 ohos.samples.multimodeinput.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.app.Context; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.multimodalinput.event.MouseEvent; +import ohos.multimodalinput.event.TouchEvent; +import ohos.multimodalinput.standard.MultimodalEventHandle; +import ohos.multimodalinput.standard.TouchEventHandle; +import ohos.samples.multimodeinput.ResourceTable; +import ohos.samples.multimodeinput.utils.Utils; + +import java.lang.ref.WeakReference; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +/** + * MouseEventSlice + * + * @since 2021-06-30 + */ +public class MouseEventSlice extends AbilitySlice { + private static final String TAG = "MouseEventSlice"; + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + private Utils utils = Utils.getInstance(); + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_mouse_ability_slice); + MultimodalEventHandle.registerStandardizedEventHandle(getAbility(), touchEvent); + } + + private TouchEventHandle touchEvent = event -> { + HiLog.info(LABEL_LOG, "mouseEvent"); + if (event.getMultimodalEvent() instanceof MouseEvent) { + MouseEvent mouseEvent = (MouseEvent) event.getMultimodalEvent(); + showMouseEvent(mouseEvent); + } else { + showTouchEvent(event); + } + return false; + }; + + private void showMouseEvent(MouseEvent mouseEvent) { + WeakReference referenceContext = new WeakReference<>(getContext()); + String[] items = new String[] { + "This is MouseEvent", + "Current Time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", + Locale.getDefault()).format(new Date().getTime()), + "Mouse Button Pressed:" + mouseEvent.getPressedButtons() + }; + utils.showDialogBox(items, referenceContext.get()); + } + + private void showTouchEvent(TouchEvent touchEvent) { + Date date = new Date(); + WeakReference referenceContext = new WeakReference<>(getContext()); + String[] items = new String[] { + "This is TouchEvent", + "Current Time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", + Locale.getDefault()).format(date.getTime()), + "Operation Start Time: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", + Locale.getDefault()).format(date.getTime() - touchEvent.getStartTime()), + "Event Phase: " + touchEvent.getPhase() + }; + utils.showDialogBox(items, referenceContext.get()); + } + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + MultimodalEventHandle.unregisterStandardizedEventHandle(getAbility(), touchEvent); + } +} \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/SpeechAbilitySlice.java b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/SpeechAbilitySlice.java new file mode 100644 index 0000000000..697407f797 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/SpeechAbilitySlice.java @@ -0,0 +1,89 @@ +/* + * 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 ohos.samples.multimodeinput.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.app.Context; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.multimodalinput.event.SpeechEvent; +import ohos.samples.multimodeinput.ResourceTable; +import ohos.samples.multimodeinput.utils.Utils; + +import java.lang.ref.WeakReference; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +/** + * MmiPointAbilitySlice + * + * @since 2021-05-12 + */ +public class SpeechAbilitySlice extends AbilitySlice { + private static final String TAG = "SpeechAbilitySlice"; + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + private static final String VOICE_EVENT_KEY = "MOVE"; + + private Component componentSpeech; + + private Utils utils = Utils.getInstance(); + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_second_main_ability_slice); + componentSpeech = findComponentById(ResourceTable.Id_speech_event_button); + componentSpeech.subscribeVoiceEvents(new Component.VoiceEvent(VOICE_EVENT_KEY)); + componentSpeech.setSpeechEventListener(onSpeechEvent); + } + + private Component.SpeechEventListener onSpeechEvent = new Component.SpeechEventListener() { + @Override + public boolean onSpeechEvent(Component component, SpeechEvent speechEvent) { + HiLog.info(LABEL_LOG, "onSpeechEvent"); + if (speechEvent.getActionProperty() == VOICE_EVENT_KEY) { + showSpeechEvent(); + } + return false; + } + }; + + private void showSpeechEvent() { + WeakReference referenceContext = new WeakReference<>(getContext()); + String[] items = new String[] { + "This is speechEvent", + "Current Time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", + Locale.getDefault()).format(new Date().getTime()) + }; + utils.showDialogBox(items, referenceContext.get()); + } + + @Override + protected void onActive() { + super.onActive(); + } + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + } +} diff --git a/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/TouchAbilitySlice.java b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/TouchAbilitySlice.java new file mode 100644 index 0000000000..bbe6791fb7 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/slice/TouchAbilitySlice.java @@ -0,0 +1,85 @@ +/* + * 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 ohos.samples.multimodeinput.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.app.Context; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; +import ohos.multimodalinput.event.TouchEvent; +import ohos.samples.multimodeinput.ResourceTable; +import ohos.samples.multimodeinput.utils.Utils; + +import java.lang.ref.WeakReference; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +/** + * KeyAbilitySlice + * + * @since 2021-05-12 + */ +public class TouchAbilitySlice extends AbilitySlice { + private static final String TAG = "TouchAbilitySlice"; + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + private Component componentTouch; + + private Utils utils = Utils.getInstance(); + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_first_main_ability_slice); + + componentTouch = findComponentById(ResourceTable.Id_touch_event_button); + HiLog.info(LABEL_LOG, "setTouchEventListener"); + componentTouch.setTouchEventListener(onTouchEvent); + } + + private void showTouchEvent(TouchEvent touchEvent) { + Date date = new Date(); + WeakReference referenceContext = new WeakReference<>(getContext()); + String[] items = new String[] { + "This is TouchEvent", + "Current Time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", + Locale.getDefault()).format(date.getTime()), + "Operation Start Time: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", + Locale.getDefault()).format(date.getTime() - touchEvent.getStartTime()), + "Event Phase: " + touchEvent.getPhase() + }; + utils.showDialogBox(items, referenceContext.get()); + } + + private Component.TouchEventListener onTouchEvent = new Component.TouchEventListener() { + @Override + public boolean onTouchEvent(Component component, TouchEvent touchEvent) { + HiLog.info(LABEL_LOG, "onTouchEvent"); + showTouchEvent(touchEvent); + return true; + } + }; + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + } +} diff --git a/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/utils/Utils.java b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/utils/Utils.java new file mode 100644 index 0000000000..ba8b4d761c --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/java/ohos/samples/multimodeinput/utils/Utils.java @@ -0,0 +1,72 @@ +/* + * 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 ohos.samples.multimodeinput.utils; + +import ohos.agp.utils.TextAlignment; +import ohos.agp.window.dialog.ListDialog; +import ohos.app.Context; + +import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT; + +/** + * Utils + * + * @since 2021-06-08 + */ +public class Utils { + private static final int DIALOG_BOX_WIDTH = 985; + + /** + * listDialog ListDialog + */ + private ListDialog listDialog; + + private static Utils instance; + + private Utils (){ + } + + public static synchronized Utils getInstance() { + if (instance == null) { + instance = new Utils(); + } + return instance; + } + + /** + * showDialogBox + * + * @param items string array + * @param context Context + */ + public void showDialogBox(String[] items, Context context) { + listDialog = new ListDialog(context); + listDialog.setAlignment(TextAlignment.CENTER); + listDialog.setSize(DIALOG_BOX_WIDTH, MATCH_CONTENT); + listDialog.setAutoClosable(true); + listDialog.setItems(items); + listDialog.show(); + } + + /** + * distroyDialogBox + */ + public void distroyDialogBox() { + if (listDialog != null) { + listDialog.destroy(); + } + } +} diff --git a/UI/MultiModeInput/entry/src/main/resources/base/element/color.json b/UI/MultiModeInput/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000..9c4751cd0d --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/element/color.json @@ -0,0 +1,64 @@ +{ + "color": [ + { + "name": "color_button_blue_empty", + "value": "#0000FF" + }, + { + "name": "color_button_blue_pressed", + "value": "#0000CC" + }, + { + "name": "color_button_blue_text", + "value": "#FFFFFF" + }, + { + "name": "color_button_gray_empty", + "value": "#E5E5E5" + }, + { + "name": "color_button_gray_pressed", + "value": "#D0D0D0" + }, + { + "name": "color_button_gray_text", + "value": "#0F0F0F" + }, + { + "name": "color_button_white_empty", + "value": "#FAFAFA" + }, + { + "name": "color_button_white_pressed", + "value": "#E5E5E5" + }, + { + "name": "color_button_white_text", + "value": "#0F0F0F" + }, + { + "name": "color_transparent", + "value": "#00000000" + }, + { + "name": "color_white", + "value": "#FFFFFF" + }, + { + "name": "color_dialog_title_text", + "value": "#000000" + }, + { + "name": "color_dialog_content_text", + "value": "#5F5F5F" + }, + { + "name": "color_dialog_button_text_blue", + "value": "#0044FF" + }, + { + "name": "color_dialog_button_line", + "value": "#9F9F9F" + } + ] +} \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/element/float.json b/UI/MultiModeInput/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000..39d19dd54f --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/element/float.json @@ -0,0 +1,44 @@ +{ + "float": [ + { + "name": "button_height", + "value": "40vp" + }, + { + "name": "button_width", + "value": "280vp" + }, + { + "name": "button_margin", + "value": "10vp" + }, + { + "name": "button_text_size", + "value": "18fp" + }, + { + "name": "dialog_padding", + "value": "20vp" + }, + { + "name": "dialog_content_padding", + "value": "10vp" + }, + { + "name": "title_text_size", + "value": "18fp" + }, + { + "name": "content_text_size", + "value": "16fp" + }, + { + "name": "dialog_button_height", + "value": "40vp" + }, + { + "name": "dialog_check_box_size", + "value": "20vp" + } + ] +} \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/element/string.json b/UI/MultiModeInput/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000..c5c7210863 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/element/string.json @@ -0,0 +1,44 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MultiModeInput" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "key_text", + "value": "Please Press Key" + }, + { + "name": "touch_event", + "value": "touchEvent" + }, + { + "name": "key_event", + "value": "keyEvent" + }, + { + "name": "mouse_event", + "value": "mouseEvent" + }, + { + "name": "speech_event", + "value": "speechEvent" + }, + { + "name": "touch_button", + "value": "button" + }, + { + "name": "mouse_button", + "value": "Left mouse click" + }, + { + "name": "speech_button", + "value": "button" + } + ] +} \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/background_ability_main.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000000..44fb138779 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/background_dialog.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/background_dialog.xml new file mode 100644 index 0000000000..3602061530 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/background_dialog.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_bg.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_bg.xml new file mode 100644 index 0000000000..6fd0ed08ca --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_bg.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue.xml new file mode 100644 index 0000000000..c7ac8a58fa --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue_empty.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue_empty.xml new file mode 100644 index 0000000000..7d0ecf30a5 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue_empty.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue_pressed.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue_pressed.xml new file mode 100644 index 0000000000..1d11532e05 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_blue_pressed.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray.xml new file mode 100644 index 0000000000..8f28594239 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray_empty.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray_empty.xml new file mode 100644 index 0000000000..20ffd312b5 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray_empty.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray_pressed.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray_pressed.xml new file mode 100644 index 0000000000..29132e747d --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_gray_pressed.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white.xml new file mode 100644 index 0000000000..4e0079165a --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white_empty.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white_empty.xml new file mode 100644 index 0000000000..d4bb25a22b --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white_empty.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white_pressed.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white_pressed.xml new file mode 100644 index 0000000000..b90569bb1a --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/button_white_pressed.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/dialog_button.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/dialog_button.xml new file mode 100644 index 0000000000..174065f8b2 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/dialog_button.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item.xml new file mode 100644 index 0000000000..e7a8dff1bb --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item_clicked.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item_clicked.xml new file mode 100644 index 0000000000..5242e7b270 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item_clicked.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item_nomral.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item_nomral.xml new file mode 100644 index 0000000000..85330edb5f --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/list_item_nomral.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box.xml new file mode 100644 index 0000000000..9e5a6084e7 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box_checked.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box_checked.xml new file mode 100644 index 0000000000..dadda3763a --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box_checked.xml @@ -0,0 +1,24 @@ + + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box_normal.xml b/UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box_normal.xml new file mode 100644 index 0000000000..4aa73988b2 --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/graphic/single_box_normal.xml @@ -0,0 +1,24 @@ + + + + + + + \ No newline at end of file diff --git a/UI/MultiModeInput/entry/src/main/resources/base/layout/first_main_ability_slice.xml b/UI/MultiModeInput/entry/src/main/resources/base/layout/first_main_ability_slice.xml new file mode 100644 index 0000000000..a78c91629a --- /dev/null +++ b/UI/MultiModeInput/entry/src/main/resources/base/layout/first_main_ability_slice.xml @@ -0,0 +1,38 @@ + + + + + +