From c97406e4198cdb8d1988382646509554276e7d26 Mon Sep 17 00:00:00 2001 From: wangzongmao Date: Thu, 24 Jun 2021 14:59:51 +0800 Subject: [PATCH 1/3] add new sample Signed-off-by: wangzongmao --- UI/MultimodalEvent/README_en.md | 26 +++ UI/MultimodalEvent/README_zh.md | 30 ++++ UI/MultimodalEvent/build.gradle | 36 ++++ UI/MultimodalEvent/entry/build.gradle | 21 +++ UI/MultimodalEvent/entry/src/main/config.json | 43 +++++ .../samples/multimodalevent/MainAbility.java | 34 ++++ .../multimodalevent/MyApplication.java | 30 ++++ .../slice/CommonEventAbilitySlice.java | 143 +++++++++++++++ .../slice/KeyEventAbilitySclice.java | 70 ++++++++ .../slice/MainAbilitySlice.java | 51 ++++++ .../slice/MediaEventAbilitySlice.java | 86 +++++++++ .../slice/SystemEventAbilitySlice.java | 79 ++++++++ .../slice/TelephoneEventAbilitySlice.java | 89 +++++++++ .../slice/TouchEventAbilitySlice.java | 76 ++++++++ .../samples/multimodalevent/utils/Utils.java | 81 +++++++++ .../main/resources/base/element/string.json | 16 ++ .../graphic/background_button_element.xml | 23 +++ .../main/resources/base/graphic/button_bg.xml | 23 +++ .../main/resources/base/graphic/common_bg.xml | 26 +++ .../resources/base/graphic/textfield_bg.xml | 26 +++ .../layout/common_event_ability_slice.xml | 39 ++++ .../base/layout/key_event_ability_slice.xml | 38 ++++ .../base/layout/main_ability_slice.xml | 106 +++++++++++ .../base/layout/media_event_ability_slice.xml | 40 +++++ .../layout/system_event_ability_slice.xml | 39 ++++ .../base/layout/tel_event_ability_slice.xml | 170 ++++++++++++++++++ .../base/layout/touch_event_ability_slice.xml | 37 ++++ .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../screenshots/device/key_event.png | Bin 0 -> 22804 bytes .../screenshots/device/media_event.png | Bin 0 -> 24251 bytes .../screenshots/device/multi_mode_event.png | Bin 0 -> 41214 bytes .../screenshots/device/sys_event.png | Bin 0 -> 41456 bytes .../screenshots/device/tel_event.png | Bin 0 -> 27239 bytes .../screenshots/device/touch_event .png | Bin 0 -> 18839 bytes UI/MultimodalEvent/settings.gradle | 15 ++ 35 files changed, 1493 insertions(+) create mode 100644 UI/MultimodalEvent/README_en.md create mode 100644 UI/MultimodalEvent/README_zh.md create mode 100644 UI/MultimodalEvent/build.gradle create mode 100644 UI/MultimodalEvent/entry/build.gradle create mode 100644 UI/MultimodalEvent/entry/src/main/config.json create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/MainAbility.java create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/MyApplication.java create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/CommonEventAbilitySlice.java create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/KeyEventAbilitySclice.java create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/MainAbilitySlice.java create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/MediaEventAbilitySlice.java create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/SystemEventAbilitySlice.java create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/TelephoneEventAbilitySlice.java create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/TouchEventAbilitySlice.java create mode 100644 UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/utils/Utils.java create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/element/string.json create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/graphic/background_button_element.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/graphic/button_bg.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/graphic/common_bg.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/graphic/textfield_bg.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/layout/common_event_ability_slice.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/layout/key_event_ability_slice.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/layout/main_ability_slice.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/layout/media_event_ability_slice.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/layout/system_event_ability_slice.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/layout/tel_event_ability_slice.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/layout/touch_event_ability_slice.xml create mode 100644 UI/MultimodalEvent/entry/src/main/resources/base/media/icon.png create mode 100644 UI/MultimodalEvent/screenshots/device/key_event.png create mode 100644 UI/MultimodalEvent/screenshots/device/media_event.png create mode 100644 UI/MultimodalEvent/screenshots/device/multi_mode_event.png create mode 100644 UI/MultimodalEvent/screenshots/device/sys_event.png create mode 100644 UI/MultimodalEvent/screenshots/device/tel_event.png create mode 100644 UI/MultimodalEvent/screenshots/device/touch_event .png create mode 100644 UI/MultimodalEvent/settings.gradle diff --git a/UI/MultimodalEvent/README_en.md b/UI/MultimodalEvent/README_en.md new file mode 100644 index 0000000000..625d4c1ef8 --- /dev/null +++ b/UI/MultimodalEvent/README_en.md @@ -0,0 +1,26 @@ +# Multimodal Input Standard Event + +##### Introduction + +In this sample, the **MultimodalEventHandle** class is used to register a standard event that is derived from the base class **StandardizedEventHandle**, handle the standard event, and map the input events from different devices to the standard event. + +##### Usage + +1. Call the **registerStandardizedEventHandle** method in the **MultimodalEventHandle** class to register a standard event. + +2. Implement the method for handling this standard event and execute the corresponding logic function. + +3. After the event is handled, call the **unregisterStandardizedEventHandle** method to unregister the event. + +In this sample, when an input event occurs, a dialog box is displayed for users. This indicates that the standard event handling is complete. + +##### Constraints + +For details about the applicable devices of multimodal input standard events, see [Multimodal Input Standard Event Overview](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ui-multimodal-standard-event-overview-0000001079953054). + +In addition to **CommonEventHandle**, **MediaEventHandle**, **SystemEventHandle**, and **TelephoneEventHandle**, Multimodal Input provides the **KeyEventHandle** and **TouchEventHandle** classes for handling standard key events and standard touch events, respectively. + +1. When receiving an original input event such as a key or touch event, Multimodal Input first determines whether to map the event to a standard common event \(handled by **CommonEventHandle**\), standard media event \(handled by **MediaEventHandle**\), standard system event \(handled by **SystemEventHandle**\), or standard call event \(handled by **TelephoneEventHandle**\). If any of these standard events has been registered and the original input event hits an action in this standard event, the callback of this standard event will be executed. +2. If this original event is not mapped to any of the preceding four standard events, Multimodal Input further determines whether to map it to a standard key event \(handled by **KeyEventHandle**\) or standard touch event \(handled by **TouchEventHandle**\). If the mapping is established and the two types of standard events have been registered, their callbacks will be executed. +3. If no standard event has been registered or the original input event does not have a mapped standard event, the **Ability** object continues dispatching this original input event. + diff --git a/UI/MultimodalEvent/README_zh.md b/UI/MultimodalEvent/README_zh.md new file mode 100644 index 0000000000..2b7e1a4f2f --- /dev/null +++ b/UI/MultimodalEvent/README_zh.md @@ -0,0 +1,30 @@ +# 多模输入事件标准化 + +### 简介 + +本示例通过提供处理标准化事件的类MultimodalEventHandle对标准化基类StandardizedEventHandle衍生出来的其它标准化事件进行注册,然后对相应的事件进行处理,将不同输入设备的输入事件映射到标准化事件上。 + +### 使用说明 + +1. 通过调用类MultimodalEventHandle的registerStandardizedEventHandle方法对相应的标准化事件进行注册; + +2. 实现相应的标准化事件的接口,执行相应的逻辑功能; + +3. 事件处理完成之后,需要利用unregisterStandardizedEventHandle取消注册。 + + +本示例当相应的触发事件发生时,系统会弹框提示,表示事件处理完成。 + +### 约束与限制 + +多模输入标准化事件适用设备情况请[点击链接](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ui-multimodal-standard-event-overview-0000001079953054)查看。 + +除了通用标准化事件(CommonEventHandle),媒体类标准化事件(MediaEventHandle),系统类标准化事件(SystemEventHandle),通话类标准化事件(TelephoneEventHandle)外,为了提供完整的事件处理能力,多模输入提供按键和触屏事件的回调接口类KeyEventHandle和TouchEventHandle; + +1. 在收到按键、触屏等原始输入事件时,会优先判断是否需要映射为通用标准化事件(CommonEventHandle),媒体类标准化事件(MediaEventHandle),系统类标准化事件(SystemEventHandle),通话类标准化事件(TelephoneEventHandle)。如果注册了以上四种标准化事件中的一种,且原始输入事件满足该标准事件中某一场景,就会执行该标准化事件提供的回调。 + +2. 如果不需要映射为上述四种标准化事件,则会继续判断是否需要映射为按键标准化事件(KeyEventHandle)和触摸标准化事件(TouchEventHandle)。只要注册了这两种标准化事件,分别执行这两种标准化事件中对应的回调。 + +3. 如果没有注册标准化事件,或者传统输入事件没有对应的标准化事件,则会由Ability继续分发给传统输入事件。 + + diff --git a/UI/MultimodalEvent/build.gradle b/UI/MultimodalEvent/build.gradle new file mode 100644 index 0000000000..1ce01d8202 --- /dev/null +++ b/UI/MultimodalEvent/build.gradle @@ -0,0 +1,36 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 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/MultimodalEvent/entry/build.gradle b/UI/MultimodalEvent/entry/build.gradle new file mode 100644 index 0000000000..b6bee94b66 --- /dev/null +++ b/UI/MultimodalEvent/entry/build.gradle @@ -0,0 +1,21 @@ +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/MultimodalEvent/entry/src/main/config.json b/UI/MultimodalEvent/entry/src/main/config.json new file mode 100644 index 0000000000..5023dc838a --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/config.json @@ -0,0 +1,43 @@ +{ + "app": { + "bundleName": "ohos.samples.multimodalevent", + "version": { + "code": 1000000, + "name": "1.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.multimodalevent", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "ohos.samples.multimodalevent.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/MainAbility.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/MainAbility.java new file mode 100644 index 0000000000..22efe120d8 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/MainAbility.java @@ -0,0 +1,34 @@ +/* + * 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.multimodalevent; + +import ohos.samples.multimodalevent.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +/** + * MainAbility + * + * @since 2021-05-24 + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } + +} diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/MyApplication.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/MyApplication.java new file mode 100644 index 0000000000..d31a6d0181 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/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.multimodalevent; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + * + * @since 2021-05-24 + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/CommonEventAbilitySlice.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/CommonEventAbilitySlice.java new file mode 100644 index 0000000000..8801d7b0bf --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/CommonEventAbilitySlice.java @@ -0,0 +1,143 @@ +/* + * 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.multimodalevent.slice; + +import java.lang.ref.WeakReference; + +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.MultimodalEvent; +import ohos.multimodalinput.standard.CommonEventHandle; +import ohos.multimodalinput.standard.MultimodalEventHandle; +import ohos.samples.multimodalevent.ResourceTable; +import ohos.samples.multimodalevent.utils.Utils; + +/** + * CommonEventAbilitySlice + * + * @since 2021-05-25 + */ +public class CommonEventAbilitySlice extends AbilitySlice { + private static final String TAG = MediaEventAbilitySlice.class.getName(); + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + private String message = "This is CommonEvent"; + + private Utils utils = Utils.getInstance(); + + private CommonEventHandle commonEventHandle = new CommonEventHandle() { + @Override + public boolean onShowMenu(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onSend(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onCopy(MultimodalEvent multimodalEvent) { + HiLog.info(LABEL_LOG, "onCopy"); + if (multimodalEvent != null) { + showCommonEvent(); + } + return false; + } + + @Override + public boolean onPaste(MultimodalEvent multimodalEvent) { + HiLog.info(LABEL_LOG, "onPaste"); + if (multimodalEvent != null) { + showCommonEvent(); + } + return false; + } + + @Override + public boolean onCut(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onUndo(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onRefresh(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onStartDrag(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onCancel(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onEnter(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onPrevious(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onNext(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onBack(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onPrint(MultimodalEvent multimodalEvent) { + return false; + } + }; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_common_event_ability_slice); + MultimodalEventHandle.registerStandardizedEventHandle(getAbility(), commonEventHandle); + } + + private void showCommonEvent() { + WeakReference referenceContext = new WeakReference<>(getContext()); + utils.showDialogBox(message, referenceContext); + } + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + MultimodalEventHandle.unregisterStandardizedEventHandle(getAbility(), commonEventHandle); + } +} diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/KeyEventAbilitySclice.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/KeyEventAbilitySclice.java new file mode 100644 index 0000000000..e5b3247182 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/KeyEventAbilitySclice.java @@ -0,0 +1,70 @@ +/* + * 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.multimodalevent.slice; + +import java.lang.ref.WeakReference; + +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.standard.KeyEventHandle; +import ohos.multimodalinput.standard.MultimodalEventHandle; +import ohos.samples.multimodalevent.ResourceTable; +import ohos.samples.multimodalevent.utils.Utils; + +/** + * KeyEventAbilitySclice + * + * @since 2021-05-24 + */ +public class KeyEventAbilitySclice extends AbilitySlice { + private static final String TAG = KeyEventAbilitySclice.class.getName(); + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + private String message = "This is keyEvent"; + + private Utils utils = Utils.getInstance(); + + private KeyEventHandle keyEventHandle = keyEvent -> { + HiLog.info(LABEL_LOG, "keyEvent"); + if (keyEvent != null && keyEvent.isKeyDown()) { + showKeyEvent(); + } + return false; + }; + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_key_event_ability_slice); + MultimodalEventHandle.registerStandardizedEventHandle(getAbility(), keyEventHandle); + } + + private void showKeyEvent() { + WeakReference referenceContext = new WeakReference<>(getContext()); + utils.showDialogBox(message, referenceContext); + } + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + MultimodalEventHandle.unregisterStandardizedEventHandle(getAbility(), keyEventHandle); + } +} diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/MainAbilitySlice.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/MainAbilitySlice.java new file mode 100644 index 0000000000..aabf4cf9f0 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/MainAbilitySlice.java @@ -0,0 +1,51 @@ +/* + * 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.multimodalevent.slice; + +import ohos.agp.components.Component; +import ohos.samples.multimodalevent.ResourceTable; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; + +/** + * MainAbilitySlice + * + * @since 2021-05-24 + */ +public class MainAbilitySlice extends AbilitySlice { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_main_ability_slice); + initComponents(); + } + + private void initComponents() { + Component componentTouch = findComponentById(ResourceTable.Id_touch_event); + componentTouch.setClickedListener(listener -> present(new TouchEventAbilitySlice(), new Intent())); + Component componentKey = findComponentById(ResourceTable.Id_key_event); + componentKey.setClickedListener(listener -> present(new KeyEventAbilitySclice(), new Intent())); + Component componentMedia = findComponentById(ResourceTable.Id_media_event); + componentMedia.setClickedListener(listener -> present(new MediaEventAbilitySlice(), new Intent())); + Component componentSystem = findComponentById(ResourceTable.Id_system_event); + componentSystem.setClickedListener(listener -> present(new SystemEventAbilitySlice(), new Intent())); + Component componentCommon = findComponentById(ResourceTable.Id_common_event); + componentCommon.setClickedListener(listener -> present(new CommonEventAbilitySlice(), new Intent())); + Component componentTel = findComponentById(ResourceTable.Id_telephone_event); + componentTel.setClickedListener(listener -> present(new TelephoneEventAbilitySlice(), new Intent())); + } + +} diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/MediaEventAbilitySlice.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/MediaEventAbilitySlice.java new file mode 100644 index 0000000000..8ac60e54fc --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/MediaEventAbilitySlice.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ohos.samples.multimodalevent.slice; + +import java.lang.ref.WeakReference; + +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.MultimodalEvent; +import ohos.multimodalinput.standard.MediaEventHandle; +import ohos.multimodalinput.standard.MultimodalEventHandle; +import ohos.samples.multimodalevent.ResourceTable; +import ohos.samples.multimodalevent.utils.Utils; + +/** + * MediaEventAbilitySlice + * + * @since 2021-05-24 + */ +public class MediaEventAbilitySlice extends AbilitySlice { + private static final String TAG = MediaEventAbilitySlice.class.getName(); + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + private String message = "This is mediaEvent"; + + private Utils utils = Utils.getInstance(); + + private MediaEventHandle mediaEventHandle = new MediaEventHandle() { + @Override + public boolean onPlay(MultimodalEvent multimodalEvent) { + HiLog.info(LABEL_LOG, "onPlay"); + return false; + } + + @Override + public boolean onPause(MultimodalEvent multimodalEvent) { + HiLog.info(LABEL_LOG, "onPause"); + return false; + } + + @Override + public boolean onMediaControl(MultimodalEvent multimodalEvent) { + HiLog.info(LABEL_LOG, "onMediaControl"); + if (multimodalEvent != null) { + showMediaEvent(); + } + return false; + } + }; + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_media_event_ability_slice); + MultimodalEventHandle.registerStandardizedEventHandle(getAbility(), mediaEventHandle); + } + + private void showMediaEvent() { + WeakReference referenceContext = new WeakReference<>(getContext()); + utils.showDialogBox(message, referenceContext); + } + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + MultimodalEventHandle.unregisterStandardizedEventHandle(getAbility(), mediaEventHandle); + } +} diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/SystemEventAbilitySlice.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/SystemEventAbilitySlice.java new file mode 100644 index 0000000000..b54bf6707c --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/SystemEventAbilitySlice.java @@ -0,0 +1,79 @@ +/* + * 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.multimodalevent.slice; + +import java.lang.ref.WeakReference; + +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.MultimodalEvent; +import ohos.multimodalinput.standard.MultimodalEventHandle; +import ohos.multimodalinput.standard.SystemEventHandle; +import ohos.samples.multimodalevent.ResourceTable; +import ohos.samples.multimodalevent.utils.Utils; + +/** + * SystemEventAbilitySlice + * + * @since 2021-05-25 + */ +public class SystemEventAbilitySlice extends AbilitySlice { + private static final String TAG = KeyEventAbilitySclice.class.getName(); + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + private String message = "Page closed"; + + private Utils utils = Utils.getInstance(); + + private SystemEventHandle systemEventHandle = new SystemEventHandle() { + @Override + public boolean onMute(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onClosePage(MultimodalEvent multimodalEvent) { + HiLog.info(LABEL_LOG, "onClosePage"); + if (multimodalEvent != null) { + showSystemEvent(); + } + return false; + } + }; + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_system_event_ability_slice); + MultimodalEventHandle.registerStandardizedEventHandle(getAbility(), systemEventHandle); + } + + private void showSystemEvent() { + WeakReference referenceContext = new WeakReference<>(getContext()); + utils.showDialogBox(message, referenceContext); + } + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + MultimodalEventHandle.unregisterStandardizedEventHandle(getAbility(), systemEventHandle); + } +} diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/TelephoneEventAbilitySlice.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/TelephoneEventAbilitySlice.java new file mode 100644 index 0000000000..18b0c791ca --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/TelephoneEventAbilitySlice.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.multimodalevent.slice; + +import java.lang.ref.WeakReference; + +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.MultimodalEvent; +import ohos.multimodalinput.standard.MultimodalEventHandle; +import ohos.multimodalinput.standard.TelephoneEventHandle; +import ohos.samples.multimodalevent.ResourceTable; +import ohos.samples.multimodalevent.utils.Utils; + +/** + * TelephoneEventAbilitySlice + * + * @since 2021-05-24 + */ +public class TelephoneEventAbilitySlice extends AbilitySlice { + private static final String TAG = TelephoneEventAbilitySlice.class.getName(); + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + private String message = "This is showTelephoneEvent"; + + private Utils utils = Utils.getInstance(); + + private TelephoneEventHandle telephoneEventHandle = new TelephoneEventHandle() { + @Override + public boolean onAnswer(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onRefuse(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onHangup(MultimodalEvent multimodalEvent) { + return false; + } + + @Override + public boolean onTelephoneControl(MultimodalEvent multimodalEvent) { + HiLog.info(LABEL_LOG, "onTelephoneControl"); + if (multimodalEvent != null) { + showTelphoneEvent(); + } + return false; + } + }; + + private void showTelphoneEvent() { + WeakReference referenceContext = new WeakReference<>(getContext()); + utils.showDialogBox(message, referenceContext); + } + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_tel_event_ability_slice); + MultimodalEventHandle.registerStandardizedEventHandle(getAbility(), telephoneEventHandle); + } + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + MultimodalEventHandle.unregisterStandardizedEventHandle(getAbility(), telephoneEventHandle); + } +} diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/TouchEventAbilitySlice.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/TouchEventAbilitySlice.java new file mode 100644 index 0000000000..475ab350c4 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/slice/TouchEventAbilitySlice.java @@ -0,0 +1,76 @@ +/* + * 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.multimodalevent.slice; + +import java.lang.ref.WeakReference; + +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.standard.MultimodalEventHandle; +import ohos.multimodalinput.standard.TouchEventHandle; +import ohos.samples.multimodalevent.ResourceTable; +import ohos.samples.multimodalevent.utils.Utils; + +/** + * TouchEventAbilitySlice + * + * @since 2021-05-24 + */ +public class TouchEventAbilitySlice extends AbilitySlice { + private static final String TAG = MediaEventAbilitySlice.class.getName(); + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, TAG); + + private static int count = 0; + + private String message = "This is touchEvent"; + + private Utils utils = Utils.getInstance(); + + private TouchEventHandle touchEventHandle = touchEvent -> { + HiLog.info(LABEL_LOG, "ontouch touchevent2"); + if (touchEvent != null) { + if (count > 0) { + return false; + } + count++; + showTouchEvent(); + } + return false; + }; + + private void showTouchEvent() { + WeakReference referenceContext = new WeakReference<>(getContext()); + utils.showDialogBox(message, referenceContext); + } + + @Override + protected void onStart(Intent intent) { + super.onStart(intent); + setUIContent(ResourceTable.Layout_touch_event_ability_slice); + MultimodalEventHandle.registerStandardizedEventHandle(getAbility(), touchEventHandle); + } + + @Override + protected void onStop() { + super.onStop(); + utils.distroyDialogBox(); + MultimodalEventHandle.unregisterStandardizedEventHandle(getAbility(), touchEventHandle); + } +} diff --git a/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/utils/Utils.java b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/utils/Utils.java new file mode 100644 index 0000000000..0d738574b3 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/java/ohos/samples/multimodalevent/utils/Utils.java @@ -0,0 +1,81 @@ +/* + * 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.multimodalevent.utils; + +import java.lang.ref.WeakReference; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +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; + + private static Utils instance; + + /** + * listDialog ListDialog + */ + public static ListDialog listDialog; + + private Utils (){ + } + + public static synchronized Utils getInstance() { + if (instance == null) { + instance = new Utils(); + } + return instance; + } + + /** + * showDialogBox + * + * @param message string + * @param weakReference WeakReference + */ + public void showDialogBox(String message, WeakReference weakReference) { + String[] items = new String[] { + message, "Current Time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", + Locale.getDefault()).format(new Date().getTime()) + }; + listDialog = new ListDialog(weakReference.get()); + listDialog.setAlignment(TextAlignment.CENTER); + listDialog.setSize(DIALOG_BOX_WIDTH, MATCH_CONTENT); + listDialog.setAutoClosable(true); + listDialog.setItems(items); + listDialog.show(); + } + + /** + * showDialogBox + */ + public void distroyDialogBox() { + if (listDialog != null) { + listDialog.destroy(); + } + } +} diff --git a/UI/MultimodalEvent/entry/src/main/resources/base/element/string.json b/UI/MultimodalEvent/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000..faf30b1e0d --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MultimodalEvent" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "HelloWorld", + "value": "Hello World" + } + ] +} \ No newline at end of file diff --git a/UI/MultimodalEvent/entry/src/main/resources/base/graphic/background_button_element.xml b/UI/MultimodalEvent/entry/src/main/resources/base/graphic/background_button_element.xml new file mode 100644 index 0000000000..1b15820a76 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/resources/base/graphic/background_button_element.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/UI/MultimodalEvent/entry/src/main/resources/base/graphic/button_bg.xml b/UI/MultimodalEvent/entry/src/main/resources/base/graphic/button_bg.xml new file mode 100644 index 0000000000..c84d3de4f0 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/resources/base/graphic/button_bg.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/UI/MultimodalEvent/entry/src/main/resources/base/graphic/common_bg.xml b/UI/MultimodalEvent/entry/src/main/resources/base/graphic/common_bg.xml new file mode 100644 index 0000000000..42d1786cf6 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/resources/base/graphic/common_bg.xml @@ -0,0 +1,26 @@ + + + + + + + + \ No newline at end of file diff --git a/UI/MultimodalEvent/entry/src/main/resources/base/graphic/textfield_bg.xml b/UI/MultimodalEvent/entry/src/main/resources/base/graphic/textfield_bg.xml new file mode 100644 index 0000000000..1ebac0334d --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/resources/base/graphic/textfield_bg.xml @@ -0,0 +1,26 @@ + + + + + + + + \ No newline at end of file diff --git a/UI/MultimodalEvent/entry/src/main/resources/base/layout/common_event_ability_slice.xml b/UI/MultimodalEvent/entry/src/main/resources/base/layout/common_event_ability_slice.xml new file mode 100644 index 0000000000..293e7ff480 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/resources/base/layout/common_event_ability_slice.xml @@ -0,0 +1,39 @@ + + + + + + + \ No newline at end of file diff --git a/UI/MultimodalEvent/entry/src/main/resources/base/layout/key_event_ability_slice.xml b/UI/MultimodalEvent/entry/src/main/resources/base/layout/key_event_ability_slice.xml new file mode 100644 index 0000000000..02cdd781dd --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/resources/base/layout/key_event_ability_slice.xml @@ -0,0 +1,38 @@ + + + + + + + \ No newline at end of file diff --git a/UI/MultimodalEvent/entry/src/main/resources/base/layout/main_ability_slice.xml b/UI/MultimodalEvent/entry/src/main/resources/base/layout/main_ability_slice.xml new file mode 100644 index 0000000000..58e8466b68 --- /dev/null +++ b/UI/MultimodalEvent/entry/src/main/resources/base/layout/main_ability_slice.xml @@ -0,0 +1,106 @@ + + + + + +