From 539e9e825c0ea7d0e9f45fb534f5c71e13456c76 Mon Sep 17 00:00:00 2001 From: guojin26 Date: Thu, 29 Jul 2021 19:46:35 +0800 Subject: [PATCH] delete DistributedCommonEvent Signed-off-by: guojin26 --- ability/DistributedCommonEvent/README.md | 5 - ability/DistributedCommonEvent/build.gradle | 34 ---- .../DistributedCommonEvent/entry/build.gradle | 19 --- .../entry/src/main/config.json | 53 ------ .../DistributeNotificationPlugin.java | 157 ------------------ .../MainAbility.java | 32 ---- .../slice/MainAbilitySlice.java | 86 ---------- .../utils/LogUtil.java | 77 --------- .../main/resources/base/element/string.json | 12 -- .../main/resources/base/graphic/button_bg.xml | 26 --- .../base/layout/main_ability_slice.xml | 70 -------- .../src/main/resources/base/media/icon.png | Bin 6790 -> 0 bytes .../device/CommonEventPublishSuccess.png | Bin 62349 -> 0 bytes .../phone/CommonEventPublishSuccess.png | Bin 96769 -> 0 bytes .../phone/ReceiveCommonEventSuccess.png | Bin 104642 -> 0 bytes .../DistributedCommonEvent/settings.gradle | 1 - .../slice/MainAbilitySlice.java | 2 +- 17 files changed, 1 insertion(+), 573 deletions(-) delete mode 100644 ability/DistributedCommonEvent/README.md delete mode 100644 ability/DistributedCommonEvent/build.gradle delete mode 100644 ability/DistributedCommonEvent/entry/build.gradle delete mode 100644 ability/DistributedCommonEvent/entry/src/main/config.json delete mode 100644 ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/DistributeNotificationPlugin.java delete mode 100644 ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/MainAbility.java delete mode 100644 ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/slice/MainAbilitySlice.java delete mode 100644 ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/utils/LogUtil.java delete mode 100644 ability/DistributedCommonEvent/entry/src/main/resources/base/element/string.json delete mode 100644 ability/DistributedCommonEvent/entry/src/main/resources/base/graphic/button_bg.xml delete mode 100644 ability/DistributedCommonEvent/entry/src/main/resources/base/layout/main_ability_slice.xml delete mode 100644 ability/DistributedCommonEvent/entry/src/main/resources/base/media/icon.png delete mode 100644 ability/DistributedCommonEvent/screenshots/device/CommonEventPublishSuccess.png delete mode 100644 ability/DistributedCommonEvent/screenshots/phone/CommonEventPublishSuccess.png delete mode 100644 ability/DistributedCommonEvent/screenshots/phone/ReceiveCommonEventSuccess.png delete mode 100644 ability/DistributedCommonEvent/settings.gradle diff --git a/ability/DistributedCommonEvent/README.md b/ability/DistributedCommonEvent/README.md deleted file mode 100644 index 6076306769..0000000000 --- a/ability/DistributedCommonEvent/README.md +++ /dev/null @@ -1,5 +0,0 @@ -分布式通知及事件 -=============== -分布式通知及事件功能框架,提供封装发布公共事件信息的方法、设置发布者的过滤条件、提供在订户收到新的公共事件时将被回调的方法、提供订阅,取消订阅和发布公共事件的方法。 -本示例展示了如何跨设备订阅和退订公共事件操作。 - diff --git a/ability/DistributedCommonEvent/build.gradle b/ability/DistributedCommonEvent/build.gradle deleted file mode 100644 index e76a14f743..0000000000 --- a/ability/DistributedCommonEvent/build.gradle +++ /dev/null @@ -1,34 +0,0 @@ -// 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() - } -} \ No newline at end of file diff --git a/ability/DistributedCommonEvent/entry/build.gradle b/ability/DistributedCommonEvent/entry/build.gradle deleted file mode 100644 index 594f9016e5..0000000000 --- a/ability/DistributedCommonEvent/entry/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -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']) -} diff --git a/ability/DistributedCommonEvent/entry/src/main/config.json b/ability/DistributedCommonEvent/entry/src/main/config.json deleted file mode 100644 index dbdb3d192f..0000000000 --- a/ability/DistributedCommonEvent/entry/src/main/config.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "app": { - "bundleName": "ohos.samples.distributedcommoneventsample", - "version": { - "code": 1000000, - "name": "1.0" - } - }, - "deviceConfig": {}, - "module": { - "package": "ohos.samples.distributedcommoneventsample", - "name": ".MainAbility", - "reqCapabilities": [ - "video_support" - ], - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry", - "installationFree":false - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "orientation": "portrait", - "formsEnabled": false, - "name": ".MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:app_name", - "type": "page", - "launchType": "standard" - } - ], - "reqPermissions": [ - { - "name": "ohos.permission.GET_DISTRIBUTED_DEVICE_INFO" - } - ] - } -} \ No newline at end of file diff --git a/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/DistributeNotificationPlugin.java b/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/DistributeNotificationPlugin.java deleted file mode 100644 index 99db5aefc7..0000000000 --- a/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/DistributeNotificationPlugin.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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.distributedcommoneventsample; - -import ohos.samples.distributedcommoneventsample.utils.LogUtil; - -import ohos.aafwk.content.Intent; -import ohos.distributedschedule.interwork.DeviceInfo; -import ohos.distributedschedule.interwork.DeviceManager; -import ohos.event.commonevent.CommonEventData; -import ohos.event.commonevent.CommonEventManager; -import ohos.event.commonevent.CommonEventSubscribeInfo; -import ohos.event.commonevent.CommonEventSubscriber; -import ohos.event.commonevent.MatchingSkills; -import ohos.rpc.RemoteException; - -import java.util.List; - -/** - * Plugin class - */ -public class DistributeNotificationPlugin { - private static final String TAG = "DistributeNotificationPlugin"; - - private static final String TEST_ACTION = "usual.event.test2"; - - private static final String NOTIFICATION_KEY = "notification_key"; - - private static final String NOTIFICATION_CONTENT = "Receive CommonEvent Success"; - - private CommonEventSubscriber commonEventSubscriber; - - private DistributeNotificationEventListener eventListener; - - /** - * publish CommonEvent - */ - public void publishCommonEvent() { - LogUtil.info(TAG, "publish CommonEvent begin"); - Intent intent = new Intent(); - intent.setAction(TEST_ACTION); - intent.setParam(NOTIFICATION_KEY, NOTIFICATION_CONTENT); - CommonEventData eventData = new CommonEventData(intent); - try { - CommonEventManager.publishCommonEvent(eventData); - LogUtil.info("publishCommonEvent", "the action of Intent is:" + TEST_ACTION); - if (eventListener != null) { - eventListener.onEventPublish("CommonEvent Publish Success"); - } - } catch (RemoteException e) { - LogUtil.error(TAG, "CommonEvent publish Error!"); - } - } - - /** - * CommonEvent Subscribe - */ - public void subscribeCommonEvent() { - LogUtil.info(TAG, "CommonEvent onSubscribe begin."); - MatchingSkills skills = new MatchingSkills(); - skills.addEvent(TEST_ACTION); - CommonEventSubscribeInfo subscribeInfo = new CommonEventSubscribeInfo(skills); - List deviceInfos = DeviceManager.getDeviceList(DeviceInfo.FLAG_GET_ALL_DEVICE); - if (deviceInfos.size() == 0) { - LogUtil.error(TAG, "No online devices found"); - subscribeInfo.setDeviceId(""); - } else { - subscribeInfo.setDeviceId(deviceInfos.get(0).getDeviceId()); - LogUtil.info(TAG, "onSubscribe subscribeInfo setDeviceId:" + deviceInfos.get(0).getDeviceId()); - } - - commonEventSubscriber = new CommonEventSubscriber(subscribeInfo) { - @Override - public void onReceiveEvent(CommonEventData commonEventData) { - LogUtil.info(TAG, "CommonEventData onReceiveEvent begin"); - if (commonEventData == null) { - LogUtil.info(TAG, "commonEventData is null."); - return; - } - Intent intent = commonEventData.getIntent(); - if (intent == null) { - LogUtil.debug(TAG, "commonEventData getIntent is null."); - return; - } - String receivedAction = intent.getAction(); - LogUtil.info(TAG, "onReceiveEvent action:" + receivedAction); - if (receivedAction.equals(TEST_ACTION)) { - String notificationContent = intent.getStringParam(NOTIFICATION_KEY); - if (eventListener != null) { - eventListener.onEventReceive(notificationContent); - } - } - } - }; - - LogUtil.info(TAG, "CommonEventManager subscribeCommonEvent begin."); - try { - CommonEventManager.subscribeCommonEvent(commonEventSubscriber); - if (eventListener != null) { - eventListener.onEventSubscribe("CommonEvent Subscribe Success"); - } - } catch (RemoteException exception) { - LogUtil.error(TAG, "CommonEvent Subscribe Error!"); - } - } - - /** - * CommonEvent Unsubscribe - */ - public void unsubscribeCommonEvent() { - LogUtil.info(TAG, "CommonEvent onUnsubscribe begin."); - if (commonEventSubscriber == null) { - LogUtil.info(TAG, "CommonEvent onUnsubscribe commonEventSubscriber is null"); - return; - } - try { - CommonEventManager.unsubscribeCommonEvent(commonEventSubscriber); - if (eventListener != null) { - eventListener.onEventUnsubscribe("CommonEvent Unsubscribe Success"); - } - } catch (RemoteException exception) { - LogUtil.error(TAG, "unsubscribeCommonEvent remoteException!"); - } - commonEventSubscriber = null; - } - - /** - * interface - * - */ - public interface DistributeNotificationEventListener { - void onEventPublish(String result); - - void onEventSubscribe(String result); - - void onEventUnsubscribe(String result); - - void onEventReceive(String result); - } - - public void setEventListener(DistributeNotificationEventListener eventListener) { - this.eventListener = eventListener; - } -} diff --git a/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/MainAbility.java b/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/MainAbility.java deleted file mode 100644 index 5c1a370d58..0000000000 --- a/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/MainAbility.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.distributedcommoneventsample; - -import ohos.samples.distributedcommoneventsample.slice.MainAbilitySlice; - -import ohos.aafwk.ability.Ability; -import ohos.aafwk.content.Intent; - -/** - * MainAbility - */ -public class MainAbility extends Ability { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setMainRoute(MainAbilitySlice.class.getName()); - } -} diff --git a/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/slice/MainAbilitySlice.java b/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/slice/MainAbilitySlice.java deleted file mode 100644 index f4d4617d16..0000000000 --- a/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/slice/MainAbilitySlice.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.distributedcommoneventsample.slice; - -import ohos.samples.distributedcommoneventsample.DistributeNotificationPlugin; -import ohos.samples.distributedcommoneventsample.ResourceTable; - -import ohos.aafwk.ability.AbilitySlice; -import ohos.aafwk.content.Intent; -import ohos.agp.components.Component; -import ohos.agp.window.dialog.ToastDialog; - -/** - * MainAbilitySlice - */ -public class MainAbilitySlice extends AbilitySlice - implements DistributeNotificationPlugin.DistributeNotificationEventListener { - private static final int TOAST_DURATION = 3000; - - private DistributeNotificationPlugin notificationPlugin; - - @Override - public void onStart(Intent intent) { - super.onStart(intent); - super.setUIContent(ResourceTable.Layout_main_ability_slice); - notificationPlugin = new DistributeNotificationPlugin(); - notificationPlugin.setEventListener(this); - initComponents(); - } - - private void initComponents() { - Component publishButton = findComponentById(ResourceTable.Id_publish); - publishButton.setClickedListener(component -> notificationPlugin.publishCommonEvent()); - Component subscribeButton = findComponentById(ResourceTable.Id_subscribe); - subscribeButton.setClickedListener(component -> notificationPlugin.subscribeCommonEvent()); - Component unsubscribeButton = findComponentById(ResourceTable.Id_unsubscribe); - unsubscribeButton.setClickedListener(component -> notificationPlugin.unsubscribeCommonEvent()); - } - - @Override - public void onEventPublish(String result) { - showToast(result); - } - - @Override - public void onEventSubscribe(String result) { - showToast(result); - } - - @Override - public void onEventUnsubscribe(String result) { - showToast(result); - } - - @Override - public void onEventReceive(String result) { - showToast(result); - } - - @Override - public void onStop() { - super.onStop(); - notificationPlugin = null; - } - - private void showToast(String msg) { - ToastDialog dialog = new ToastDialog(this); - dialog.setDuration(TOAST_DURATION); - dialog.setAutoClosable(false); - dialog.setContentText(msg); - dialog.show(); - } -} diff --git a/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/utils/LogUtil.java b/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/utils/LogUtil.java deleted file mode 100644 index 4637e45070..0000000000 --- a/ability/DistributedCommonEvent/entry/src/main/java/ohos/samples/distributedcommoneventsample/utils/LogUtil.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.distributedcommoneventsample.utils; - -import ohos.hiviewdfx.HiLog; -import ohos.hiviewdfx.HiLogLabel; - -import java.util.Locale; - -/** - * Log utils - */ -public class LogUtil { - private static final String TAG_LOG = "DistributedCommonEventSample"; - - private static final int DOMAIN_ID = 0xD000F00; - - private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, DOMAIN_ID, LogUtil.TAG_LOG); - - private static final String LOG_FORMAT = "%s: %s"; - - private LogUtil() { - } - - /** - * Print debug log - * - * @param tag log tag - * @param msg log message - */ - public static void debug(String tag, String msg) { - HiLog.debug(LABEL_LOG, String.format(Locale.ROOT, LOG_FORMAT, tag, msg)); - } - - /** - * Print info log - * - * @param tag log tag - * @param msg log message - */ - public static void info(String tag, String msg) { - HiLog.info(LABEL_LOG, String.format(Locale.ROOT, LOG_FORMAT, tag, msg)); - } - - /** - * Print warn log - * - * @param tag log tag - * @param msg log message - */ - public static void warn(String tag, String msg) { - HiLog.warn(LABEL_LOG, String.format(Locale.ROOT, LOG_FORMAT, tag, msg)); - } - - /** - * Print error log - * - * @param tag log tag - * @param msg log message - */ - public static void error(String tag, String msg) { - HiLog.error(LABEL_LOG, String.format(Locale.ROOT, LOG_FORMAT, tag, msg)); - } -} diff --git a/ability/DistributedCommonEvent/entry/src/main/resources/base/element/string.json b/ability/DistributedCommonEvent/entry/src/main/resources/base/element/string.json deleted file mode 100644 index b86a8e461f..0000000000 --- a/ability/DistributedCommonEvent/entry/src/main/resources/base/element/string.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "DistributedCommonEvent" - }, - { - "name": "mainability_description", - "value": "hap sample empty page" - } - ] -} \ No newline at end of file diff --git a/ability/DistributedCommonEvent/entry/src/main/resources/base/graphic/button_bg.xml b/ability/DistributedCommonEvent/entry/src/main/resources/base/graphic/button_bg.xml deleted file mode 100644 index 72b03542a4..0000000000 --- a/ability/DistributedCommonEvent/entry/src/main/resources/base/graphic/button_bg.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/ability/DistributedCommonEvent/entry/src/main/resources/base/layout/main_ability_slice.xml b/ability/DistributedCommonEvent/entry/src/main/resources/base/layout/main_ability_slice.xml deleted file mode 100644 index 29ba7d4034..0000000000 --- a/ability/DistributedCommonEvent/entry/src/main/resources/base/layout/main_ability_slice.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - -