From 191f023f75ea8698e7f8ded9872ea53825454d01 Mon Sep 17 00:00:00 2001 From: SparksOfFire <9453399+SparksOfFire@user.noreply.gitee.com> Date: Fri, 13 Aug 2021 18:50:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=9C=BA=E6=99=AF=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E6=96=87=E4=BB=B6=E5=A4=B9=EF=BC=8C=E5=B9=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=20=E5=88=86=E5=B8=83=E5=BC=8F=E8=B7=A8=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E6=90=9C=E7=B4=A2=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScenarioDemos/DistributedSearch/build.gradle | 52 ++++ .../DistributedSearch/entry/build.gradle | 27 ++ .../entry/src/main/config.json | 107 +++++++ .../distributedsearch/MainAbility.java | 51 ++++ .../distributedsearch/MyApplication.java | 24 ++ .../distributedsearch/data/DeviceData.java | 62 ++++ .../provider/ComponentViewHolder.java | 73 +++++ .../provider/DeviceDataProvider.java | 85 ++++++ .../provider/FileItemViewHolder.java | 64 ++++ .../provider/FileListProvider.java | 89 ++++++ .../provider/ListComponentProvider.java | 112 +++++++ .../slice/MainAbilitySlice.java | 250 ++++++++++++++++ .../ui/DeviceSelectDialog.java | 117 ++++++++ .../distributedsearch/ui/PopupDialog.java | 66 +++++ .../distributedsearch/utils/DeviceUtils.java | 122 ++++++++ .../utils/DistributedFile.java | 273 ++++++++++++++++++ .../distributedsearch/utils/LogUtil.java | 166 +++++++++++ .../distributedsearch/utils/WidgetHelper.java | 151 ++++++++++ .../distributedsearch/utils/WidgetStyle.java | 100 +++++++ .../base/animation/animator_value.xml | 4 + .../main/resources/base/element/colors.json | 20 ++ .../main/resources/base/element/string.json | 88 ++++++ .../base/graphic/background_ability_main.xml | 6 + .../base/graphic/background_button.xml | 8 + .../base/graphic/background_text_field.xml | 8 + .../graphic/background_white_radius_10.xml | 8 + .../base/graphic/ele_cursor_bubble.xml | 11 + .../base/layout/ability_everything.xml | 181 ++++++++++++ .../resources/base/layout/ability_main.xml | 19 ++ .../resources/base/layout/dialog_delete.xml | 67 +++++ .../base/layout/dialog_device_item.xml | 46 +++ .../base/layout/dialog_layout_device.xml | 66 +++++ .../main/resources/base/layout/file_item.xml | 55 ++++ .../src/main/resources/base/media/dv_pad.png | Bin 0 -> 590 bytes .../main/resources/base/media/dv_phone.png | Bin 0 -> 765 bytes .../main/resources/base/media/dv_watch.png | Bin 0 -> 18021 bytes .../main/resources/base/media/empty_state.png | Bin 0 -> 73036 bytes .../resources/base/media/home_icon_search.png | Bin 0 -> 12184 bytes .../src/main/resources/base/media/ic_back.png | Bin 0 -> 4319 bytes .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../base/media/icon_delete_notice.png | Bin 0 -> 105324 bytes .../main/resources/base/media/icon_file.png | Bin 0 -> 3318 bytes .../main/resources/base/media/icon_img.png | Bin 0 -> 4497 bytes .../main/resources/base/media/icon_music.png | Bin 0 -> 3916 bytes .../main/resources/base/media/icon_qianyi.png | Bin 0 -> 11141 bytes .../main/resources/base/media/icon_search.png | Bin 0 -> 6171 bytes .../main/resources/base/media/icon_video.png | Bin 0 -> 7625 bytes .../resources/base/media/item_left_img.jpg | Bin 0 -> 14564 bytes .../resources/base/media/nothing_state.png | Bin 0 -> 77589 bytes .../src/main/resources/base/media/qianyi.png | Bin 0 -> 4667 bytes .../resources/base/media/uncheck_point.png | Bin 0 -> 2650 bytes .../src/main/resources/base/media/zhankai.png | Bin 0 -> 2421 bytes .../src/main/resources/en/element/string.json | 88 ++++++ .../src/main/resources/zh/element/string.json | 88 ++++++ .../distributedsearch/ExampleOhosTest.java | 14 + .../distributedsearch/ExampleTest.java | 9 + .../screenshort/distributed_search.png | Bin 0 -> 441334 bytes .../DistributedSearch/settings.gradle | 15 + 58 files changed, 2792 insertions(+) create mode 100755 ScenarioDemos/DistributedSearch/build.gradle create mode 100755 ScenarioDemos/DistributedSearch/entry/build.gradle create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/config.json create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/MainAbility.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/MyApplication.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/data/DeviceData.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/ComponentViewHolder.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/DeviceDataProvider.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/FileItemViewHolder.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/FileListProvider.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/ListComponentProvider.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/slice/MainAbilitySlice.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/ui/DeviceSelectDialog.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/ui/PopupDialog.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/DeviceUtils.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/DistributedFile.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/LogUtil.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/WidgetHelper.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/WidgetStyle.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/animation/animator_value.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/element/colors.json create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/element/string.json create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_ability_main.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_button.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_text_field.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_white_radius_10.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/ele_cursor_bubble.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/layout/ability_everything.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/layout/ability_main.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/layout/dialog_delete.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/layout/dialog_device_item.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/layout/dialog_layout_device.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/layout/file_item.xml create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/dv_pad.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/dv_phone.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/dv_watch.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/empty_state.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/home_icon_search.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/ic_back.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/icon.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/icon_delete_notice.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/icon_file.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/icon_img.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/icon_music.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/icon_qianyi.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/icon_search.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/icon_video.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/item_left_img.jpg create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/nothing_state.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/qianyi.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/uncheck_point.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/base/media/zhankai.png create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/en/element/string.json create mode 100755 ScenarioDemos/DistributedSearch/entry/src/main/resources/zh/element/string.json create mode 100755 ScenarioDemos/DistributedSearch/entry/src/ohosTest/java/ohos/samples/distributedsearch/ExampleOhosTest.java create mode 100755 ScenarioDemos/DistributedSearch/entry/src/test/java/ohos/samples/distributedsearch/ExampleTest.java create mode 100755 ScenarioDemos/DistributedSearch/screenshort/distributed_search.png create mode 100755 ScenarioDemos/DistributedSearch/settings.gradle diff --git a/ScenarioDemos/DistributedSearch/build.gradle b/ScenarioDemos/DistributedSearch/build.gradle new file mode 100755 index 0000000000..abbc73b543 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/build.gradle @@ -0,0 +1,52 @@ +/* + * 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. + */ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +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' + classpath 'com.huawei.ohos:decctest:1.2.4.0' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/build.gradle b/ScenarioDemos/DistributedSearch/entry/build.gradle new file mode 100755 index 0000000000..61249ffabf --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 4 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html','xml'] +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/config.json b/ScenarioDemos/DistributedSearch/entry/src/main/config.json new file mode 100755 index 0000000000..6acb81fc07 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/config.json @@ -0,0 +1,107 @@ +{ + "app": { + "bundleName": "ohos.samples.distributedsearch", + "vendor": "sample", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.distributedsearch", + "name": ".MyApplication", + "mainAbility": "ohos.samples.distributedsearch.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "reqPermissions": [ + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC", + "reason": "用于分布式数据交换", + "usedScene": { + "ability": [ + "com.distributed.everything.slice.MainAbilitySlice" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.GET_DISTRIBUTED_DEVICE_INFO" + }, + { + "name": "ohos.permission.DISTRIBUTED_DEVICE_STATE_CHANGE" + }, + { + "name": "ohos.permission.READ_USER_STORAGE", + "reason": "用于读取用户存储信息", + "usedScene": { + "ability": [ + "com.distributed.everything.slice.MainAbilitySlice" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.WRITE_USER_STORAGE", + "reason": "用于写取用户存储信息", + "usedScene": { + "ability": [ + "com.distributed.everything.slice.MainAbilitySlice" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.READ_MEDIA", + "reason": "用于读取媒体文件信息", + "usedScene": { + "ability": [ + "com.distributed.everything.slice.MainAbilitySlice" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.WRITE_MEDIA", + "reason": "用于保存媒体文件信息", + "usedScene": { + "ability": [ + "com.distributed.everything.slice.MainAbilitySlice" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO" + } + ], + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "ohos.samples.distributedsearch.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/MainAbility.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/MainAbility.java new file mode 100755 index 0000000000..c7ff81299f --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/MainAbility.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.distributedsearch; + +import ohos.bundle.IBundleManager; +import ohos.samples.distributedsearch.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.security.SystemPermission; + +import java.util.ArrayList; +import java.util.List; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + + requestPermissions(); + } + + private void requestPermissions() { + String[] permissions = { + SystemPermission.DISTRIBUTED_DATASYNC, + SystemPermission.READ_USER_STORAGE, + SystemPermission.WRITE_USER_STORAGE + }; + List permissionsToProcess = new ArrayList<>(); + for (String permission : permissions) { + if (verifySelfPermission(permission) != IBundleManager.PERMISSION_GRANTED + && canRequestPermission(permission)) { + permissionsToProcess.add(permission); + } + } + requestPermissionsFromUser(permissionsToProcess.toArray(new String[0]), 0); + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/MyApplication.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/MyApplication.java new file mode 100755 index 0000000000..3dbcb403b0 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/MyApplication.java @@ -0,0 +1,24 @@ +/* + * 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.distributedsearch; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/data/DeviceData.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/data/DeviceData.java new file mode 100755 index 0000000000..0f67e6046b --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/data/DeviceData.java @@ -0,0 +1,62 @@ +/* + * 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.distributedsearch.data; + +import ohos.distributedschedule.interwork.DeviceInfo; + +/** + * The type Device data. + * + * @since 2021-04-27 + */ +public class DeviceData { + private boolean isChecked; + + private DeviceInfo deviceInfo; + + /** + * Instantiates a new Device data. + */ + public DeviceData() { + } + + /** + * Instantiates a new Device data. + * + * @param isChecked the is checked + * @param deviceInfo the device info + */ + public DeviceData(boolean isChecked, DeviceInfo deviceInfo) { + this.isChecked = isChecked; + this.deviceInfo = deviceInfo; + } + + public boolean isChecked() { + return isChecked; + } + + public void setChecked(boolean checked) { + isChecked = checked; + } + + public DeviceInfo getDeviceInfo() { + return deviceInfo; + } + + public void setDeviceInfo(DeviceInfo deviceInfo) { + this.deviceInfo = deviceInfo; + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/ComponentViewHolder.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/ComponentViewHolder.java new file mode 100755 index 0000000000..f83e0b7fb6 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/ComponentViewHolder.java @@ -0,0 +1,73 @@ +/* + * 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.distributedsearch.provider; + +import ohos.agp.components.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * The type Comment view holder. + * + * @since 2021-04-27 + */ +public class ComponentViewHolder { + /** + * Layout + */ + private Component componentView; + + /** + * Subcomponents in componentview + */ + private final Map childComponentMap = new HashMap<>(); + + /** + * Instantiates a new Component view holder. + */ + public ComponentViewHolder() { + } + + /** + * Instantiates a new Component view holder. + * + * @param componentView the component view + */ + public ComponentViewHolder(Component componentView) { + this.componentView = componentView; + componentView.setTag(this); + } + + public Component getComponentView() { + return componentView; + } + + /** + * Obtain the corresponding component according to the resource ID + * + * @param resId resId + * @return Component + */ + public Component getChildComponent(int resId) { + Component view = childComponentMap.get(resId); + if (view == null) { + view = componentView.findComponentById(resId); + childComponentMap.put(resId, view); + } + return view; + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/DeviceDataProvider.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/DeviceDataProvider.java new file mode 100755 index 0000000000..19ce062b64 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/DeviceDataProvider.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.distributedsearch.provider; + +import ohos.agp.components.Component; +import ohos.agp.components.Image; +import ohos.agp.components.Text; +import ohos.app.Context; +import ohos.samples.distributedsearch.ResourceTable; +import ohos.samples.distributedsearch.data.DeviceData; + +import java.util.List; + +/** + * The type Device data provider. + * + * @since 2021-04-27 + */ +public class DeviceDataProvider extends ListComponentProvider { + /** + * Instantiates a new Device data provider. + * + * @param context the context + * @param listBean the list bean + * @param resourceId the resource id + */ + public DeviceDataProvider(Context context, List listBean, int resourceId) { + super(context, listBean, resourceId); + } + + @Override + public void onItemDataBind(ComponentViewHolder componentViewHolder, DeviceData deviceData, int position) { + // 1 Set the name of the device + Text deviceText = (Text) componentViewHolder.getChildComponent(ResourceTable.Id_item_image_title); + deviceText.setText(deviceData.getDeviceInfo().getDeviceName()); + Text infoText = (Text) componentViewHolder.getChildComponent(ResourceTable.Id_item_image_info); + infoText.setText(deviceData.getDeviceInfo().getDeviceId()); + // 2 Set icon for device + setDeviceImg(componentViewHolder, deviceData); + } + + private void setDeviceImg(ComponentViewHolder componentViewHolder, DeviceData deviceData) { + Integer imageTypeId = null; + switch (deviceData.getDeviceInfo().getDeviceType()) { + case SMART_PHONE: + imageTypeId = ResourceTable.Media_dv_phone; + break; + case SMART_PAD: + imageTypeId = ResourceTable.Media_dv_pad; + break; + case SMART_WATCH: + imageTypeId = ResourceTable.Media_dv_watch; + break; + default: + break; + } + if (imageTypeId != null) { + Image image = (Image) componentViewHolder.getChildComponent(ResourceTable.Id_item_type); + image.setPixelMap(imageTypeId); + } + } + + @Override + public void onItemClick(Component component, DeviceData checkDeviceData, int position) { + for (DeviceData deviceData : listBean) { + deviceData.setChecked(false); + } + listBean.get(position).setChecked(true); + // Notify data changes + notifyDataChanged(); + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/FileItemViewHolder.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/FileItemViewHolder.java new file mode 100755 index 0000000000..a3c6c24c5b --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/FileItemViewHolder.java @@ -0,0 +1,64 @@ +/* + * 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.distributedsearch.provider; + +public class FileItemViewHolder { + private String filename; + private String devicename; + private int iconId; + private String filepath; + + public FileItemViewHolder(String fName, String dName, int icon) { + iconId = icon; + filename = fName; + devicename = dName; + } + + public FileItemViewHolder(String fName, String pName, String dName, int icon) { + iconId = icon; + filename = fName; + devicename = dName; + filepath = pName; + } + + public void setFilename(String f) { + filename = f; + } + public String getFilename() { + return filename; + } + + public void setDevicename(String i) { + devicename = i; + } + public String getDevicename() { + return devicename; + } + + public void setIconId(int icon) { + iconId = icon; + } + public int getIconId() { + return iconId; + } + + public void setFilepath(String p) { + filepath = p; + } + public String getFilepath() { + return filepath; + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/FileListProvider.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/FileListProvider.java new file mode 100755 index 0000000000..924550d40d --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/FileListProvider.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.distributedsearch.provider; + +import ohos.agp.components.BaseItemProvider; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.Image; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.app.Context; +import ohos.samples.distributedsearch.ResourceTable; +import ohos.samples.distributedsearch.utils.LogUtil; + +import java.util.List; + +public class FileListProvider extends BaseItemProvider { + private final static String TAG = "FileListProvider"; + private final Context mContext; + private final List mList; + + public FileListProvider(Context context, List listBean){ + mContext = context; + mList = listBean; + } + + @Override + public int getCount() { + return mList == null ? 0 : mList.size(); + } + + @Override + public T getItem(int i) { + + return (mList == null || mList.size() == 0) ? null : mList.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public Component getComponent(int i, Component component, ComponentContainer componentContainer) { + FileItemViewHolder holder; + + if (component == null) { + component = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_file_item, null, false); + } + + holder = (FileItemViewHolder)mList.get(i); + if (holder == null) { + LogUtil.error(TAG, "FileItemViewHolder[]"+ i + " is null"); + return component; + } + + Image icon = (Image)component.findComponentById(ResourceTable.Id_imageIcon); + icon.setPixelMap(holder.getIconId()); + + Text name = (Text)component.findComponentById(ResourceTable.Id_filename); + name.setText(holder.getFilename()); + Text devName = (Text)component.findComponentById(ResourceTable.Id_deviceinfo); + devName.setText(mContext.getString(ResourceTable.String_file_source_label) + ": " + holder.getDevicename()); + + return component; + } + + /** + * Set the binding event of item, and the subclass overrides as needed + * + * @param component component + * @param item item + * @param position position + */ + protected void onItemClick(Component component, T item, int position) { + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/ListComponentProvider.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/ListComponentProvider.java new file mode 100755 index 0000000000..5afd8f713a --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/provider/ListComponentProvider.java @@ -0,0 +1,112 @@ +/* + * 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.distributedsearch.provider; + +import ohos.agp.components.BaseItemProvider; +import ohos.agp.components.Component; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.LayoutScatter; +import ohos.app.Context; + +import java.util.List; + +/** + * The type List component provider. + * + * @param the type parameter + * @since 2021-04-27 + */ +public abstract class ListComponentProvider extends BaseItemProvider { + protected Context context; + + /** + * Item data + */ + protected List listBean; + + /** + * Layout resource id + */ + protected int resourceId; + + /** + * Instantiates a new List component provider. + * + * @param context the context + * @param listBean the list bean + * @param resourceId the resource id + */ + public ListComponentProvider(Context context, List listBean, int resourceId) { + this.context = context; + this.listBean = listBean; + this.resourceId = resourceId; + } + + /** + * Set the data of the view subcomponent + * + * @param componentViewHolder componentViewHolder + * @param item item + * @param position position + */ + protected abstract void onItemDataBind(ComponentViewHolder componentViewHolder, T item, int position); + + @Override + public int getCount() { + return listBean.size(); + } + + @Override + public T getItem(int i) { + return listBean.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public Component getComponent(int position, Component component, ComponentContainer componentContainer) { + ComponentViewHolder viewHolder; + if (component == null) { + component = LayoutScatter.getInstance(context).parse(resourceId, null, false); + viewHolder = new ComponentViewHolder(component); + component.setTag(viewHolder); + } else { + viewHolder = (ComponentViewHolder) component.getTag(); + } + if (viewHolder != null) { + T item = listBean.get(position); + // Set the data of the view subcomponent + onItemDataBind(viewHolder, item, position); + // Set binding event of item + viewHolder.getComponentView() + .setClickedListener(componentView -> onItemClick(componentView, item, position)); + } + return component; + } + + /** + * Set the binding event of item, and the subclass overrides as needed + * + * @param component component + * @param item item + * @param position position + */ + protected void onItemClick(Component component, T item, int position) { + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/slice/MainAbilitySlice.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/slice/MainAbilitySlice.java new file mode 100755 index 0000000000..036f01451e --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/slice/MainAbilitySlice.java @@ -0,0 +1,250 @@ +package ohos.samples.distributedsearch.slice; + +import ohos.agp.components.*; +import ohos.agp.utils.Color; +import ohos.samples.distributedsearch.ResourceTable; +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.samples.distributedsearch.provider.FileItemViewHolder; +import ohos.samples.distributedsearch.provider.FileListProvider; +import ohos.samples.distributedsearch.ui.DeviceSelectDialog; +import ohos.samples.distributedsearch.ui.PopupDialog; +import ohos.samples.distributedsearch.utils.DeviceUtils; +import ohos.samples.distributedsearch.utils.DistributedFile; +import ohos.samples.distributedsearch.utils.WidgetHelper; + +import java.util.ArrayList; +import java.util.List; + +public class MainAbilitySlice extends AbilitySlice { + private String gSearchKey = ""; + private TextField gTextField; + private int gFileType = DistributedFile.FILE_TYPE_IMAGE; + + private RadioButton mButtonImage; + private RadioButton mButtonAudio; + private RadioButton mButtonVideo; + private RadioButton mButtonText; + private RadioButton mButtonFileAll; + FileListProvider fileProvider; + private final ArrayList mFileList = new ArrayList<>(); + private ListContainer listview; + private Text result; + private Image mButton; + private Button mDevice; + private DistributedFile mDistributedFile; + private RadioContainer mRadioContainer; + private Image searchImage; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_everything); + + mDistributedFile = new DistributedFile(this); + mDistributedFile.start(); + + initUI(); + setEventListener(); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + } + + private void initUI() { + listview = (ListContainer)this.findComponentById(ResourceTable.Id_listview); + fileProvider = new FileListProvider(this, mFileList); + listview.setItemProvider(fileProvider); + + listview.setVisibility(Component.HIDE); + + result = (Text) findComponentById(ResourceTable.Id_result_info); + result.setVisibility(Component.VISIBLE); + + mRadioContainer = (RadioContainer)findComponentById(ResourceTable.Id_radio_container); + + mButtonImage = (RadioButton) this.findComponentById(ResourceTable.Id_sel_image); + mButtonAudio = (RadioButton) this.findComponentById(ResourceTable.Id_sel_audio); + mButtonVideo = (RadioButton) this.findComponentById(ResourceTable.Id_sel_video); + mButtonText = (RadioButton) this.findComponentById(ResourceTable.Id_sel_text); + mButtonFileAll = (RadioButton) this.findComponentById(ResourceTable.Id_sel_all); + mRadioContainer.mark(0); + mButtonImage.setClickable(false); + + gTextField = (TextField)this.findComponentById(ResourceTable.Id_textEntry); + gTextField.setTextColor(Color.BLACK); + searchImage = (Image)this.findComponentById(ResourceTable.Id_searchButton); + + mButton = (Image)findComponentById(ResourceTable.Id_AnimaBttn); + mDevice = (Button)findComponentById(ResourceTable.Id_deviceBttn); + + mButton.setPosition(350, 700); + mDevice.setPosition(320, 700); + mButton.setVisibility(Component.VISIBLE); + mDevice.setVisibility(Component.HIDE); + } + + private void setEventListener() { + setListViewEvent(); + setRadioContainerEvent(); + + searchImage.setClickedListener(component -> { + gSearchKey = gTextField.getText(); + if (!availableKey(gSearchKey)) { + WidgetHelper.showTips(this, getString(ResourceTable.String_input_notice_msg), 2000); + return; + } + + setListFile(); + }); + + mButton.setClickedListener(component -> { + mButton.setVisibility(Component.HIDE); + if (mDevice != null) { + mDevice.setVisibility(Component.VISIBLE); + mDevice.setFocusable(Component.FOCUS_ENABLE); + } + }); + + mDevice.setClickedListener(component -> { + + mDevice.setVisibility(Component.HIDE); + if (mButton != null) { + mButton.setVisibility(Component.VISIBLE); + mButton.setFocusable(Component.FOCUS_ENABLE); + } + DeviceSelectDialog mDialog = new DeviceSelectDialog(this); + mDialog.show(); + }); + } + + private void setListViewEvent() { + listview.setItemClickedListener((container, component, position, id) ->{ + FileItemViewHolder item = (FileItemViewHolder) listview.getItemProvider().getItem(position); + if (item != null && item.getFilepath() != null) { + WidgetHelper.showTips(this, + getString(ResourceTable.String_file_path_label) + ": " + + item.getFilepath() + "/" + item.getFilename(), 2000); + } + }); + listview.setItemLongClickedListener((container, component, position, id) ->{ + FileItemViewHolder item = (FileItemViewHolder) listview.getItemProvider().getItem(position); + if (item != null) { + PopupDialog mDialog = new PopupDialog(this); + mDialog.show(); + } + return true; + }); + } + + private void setRadioContainerEvent() { + mRadioContainer.setMarkChangedListener((radioContainer, i) -> { + RadioButton[] mRadioButton = { + mButtonImage, + mButtonAudio, + mButtonVideo, + mButtonText, + mButtonFileAll + }; + + if (gFileType == i) { + return; + } + + if (mRadioButton[gFileType] != null) { + mRadioButton[gFileType].setTextColor(Color.GRAY); + mRadioButton[gFileType].setClickable(true); + } + gFileType = i; + mRadioButton[gFileType].setClickable(false); + + gSearchKey = gTextField.getText(); + if (availableKey(gSearchKey)) { + setListFile(); + } + }); + } + + private boolean getFileViewList() { + List list; + if (!mDistributedFile.hasCheckResult()) { + return false; + } + list = mDistributedFile.getFile(gFileType); + if (list == null || list.size() == 0) { + return false; + } + + getFileList(list, gSearchKey); + + return mFileList.size() > 0; + } + + private void getFileList(List list, String key) { + mFileList.clear(); + for (String filename : list) { + String device; + String name; + String path = null; + + int idx = filename.lastIndexOf('/'); + if (idx < 0) { + name = filename; + } else { + name = filename.substring(idx+1); + path = filename.substring(0, idx+1); + } + idx = name.indexOf('+'); + if (idx < 0) { + device = getString(ResourceTable.String_local_device_name); + } else { + device = name.substring(0, idx); + if (DeviceUtils.isLocalDevice(this, device, DeviceUtils.DEVICE_TYPE_NAME)) { + device = getString(ResourceTable.String_local_device_name); + } + name = name.substring(idx+1); + } + + if (filename.contains(key)) { + int ico = ResourceTable.Media_icon_file; + int type = mDistributedFile.checkFileType(name); + + if (type == DistributedFile.FILE_TYPE_IMAGE) { + ico = ResourceTable.Media_icon_img; + } else if (type == DistributedFile.FILE_TYPE_AUDIO) { + ico = ResourceTable.Media_icon_music; + } else if (type == DistributedFile.FILE_TYPE_VIDEO) { + ico = ResourceTable.Media_icon_video; + } + + FileItemViewHolder viewHolder = new FileItemViewHolder(name, path, device, ico); + mFileList.add(viewHolder); + } + } + } + + private boolean availableKey(String key) { + if (key == null || key.length() == 0) { + return false; + } + return !key.contains(" "); + } + + private void setListFile() { + if (getFileViewList()) { + result.setVisibility(Component.HIDE); + listview.setVisibility(Component.VISIBLE); + fileProvider.notifyDataChanged(); + } else { + result.setVisibility(Component.VISIBLE); + listview.setVisibility(Component.HIDE); + } + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/ui/DeviceSelectDialog.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/ui/DeviceSelectDialog.java new file mode 100755 index 0000000000..7cf3521657 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/ui/DeviceSelectDialog.java @@ -0,0 +1,117 @@ +/* + * 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.distributedsearch.ui; + +import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT; +import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.agp.components.Component; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.ListContainer; +import ohos.agp.components.Text; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.CommonDialog; +import ohos.distributedschedule.interwork.DeviceInfo; +import ohos.distributedschedule.interwork.DeviceManager; +import ohos.samples.distributedsearch.ResourceTable; +import ohos.samples.distributedsearch.data.DeviceData; +import ohos.samples.distributedsearch.provider.DeviceDataProvider; +import ohos.samples.distributedsearch.utils.LogUtil; + +import java.util.ArrayList; +import java.util.List; + +/** + * The type Device select dialog. + * + * @since 2021-04-27 + */ +public class DeviceSelectDialog extends CommonDialog { + private static final String TAG = DeviceSelectDialog.class.getSimpleName(); + + private static final int CORNER_RADIUS = 10; + + private final AbilitySlice context; + + private DeviceInfo checkedDevice; + + /** + * Instantiates a new Device select dialog. + * + * @param context the context + */ + public DeviceSelectDialog(AbilitySlice context) { + super(context); + this.context = context; + } + + @Override + protected void onCreate() { + super.onCreate(); + // 1 Initialize device information + List deviceList = initDeviceData(); + // 2 Set data for listcontainer + Component rootView = + LayoutScatter.getInstance(context).parse(ResourceTable.Layout_dialog_layout_device, null, false); + ListContainer listContainer = + (ListContainer) rootView.findComponentById(ResourceTable.Id_list_container_device); + setItemProvider(listContainer, deviceList); + // 3 Set the yes or no event + configChoiceButton(rootView); + // 4 Set style + configStyle(rootView); + } + + private List initDeviceData() { + LogUtil.info(TAG, "begin to initDeviceData"); + List deviceInfoList = DeviceManager.getDeviceList(DeviceInfo.FLAG_GET_ONLINE_DEVICE); + List deviceList = new ArrayList<>(); + for (DeviceInfo deviceInfo : deviceInfoList) { + deviceList.add(new DeviceData(false, deviceInfo)); + } + if (deviceInfoList.size() > 0) { + checkedDevice = deviceInfoList.get(0); + } + LogUtil.info(TAG, "get " + deviceInfoList.size() + " devices"); + return deviceList; + } + + private void setItemProvider(ListContainer listContainer, List deviceList) { + LogUtil.info(TAG, "begin to setItemProvider"); + DeviceDataProvider deviceDataProvider = + new DeviceDataProvider(context, deviceList, ResourceTable.Layout_dialog_device_item); + listContainer.setItemProvider(deviceDataProvider); + } + + private void configChoiceButton(Component rootView) { + LogUtil.info(TAG, "begin to configChoiceButton"); + Text operateYes = (Text) rootView.findComponentById(ResourceTable.Id_operate_yes); + operateYes.setClickedListener(component -> destroy()); + Text operateNo = (Text) rootView.findComponentById(ResourceTable.Id_operate_no); + operateNo.setClickedListener(component -> destroy()); + } + + private void configStyle(Component rootView) { + LogUtil.info(TAG, "begin to configStyle"); + setSize(MATCH_PARENT, MATCH_CONTENT); + setAlignment(LayoutAlignment.BOTTOM); + setCornerRadius(CORNER_RADIUS); + setAutoClosable(true); + setContentCustomComponent(rootView); + setTransparent(true); + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/ui/PopupDialog.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/ui/PopupDialog.java new file mode 100755 index 0000000000..57e05c1a66 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/ui/PopupDialog.java @@ -0,0 +1,66 @@ +/* + * 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.distributedsearch.ui; + +import ohos.agp.components.Component; +import ohos.agp.components.LayoutScatter; +import ohos.agp.components.Text; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.window.dialog.CommonDialog; +import ohos.app.Context; +import ohos.samples.distributedsearch.ResourceTable; +import ohos.samples.distributedsearch.utils.LogUtil; + +import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT; +import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT; + +public class PopupDialog extends CommonDialog { + private static final String TAG = "PopupDialog"; + private static final int CORNER_RADIUS = 40; + private final Context mContext; + + public PopupDialog(Context context) { + super(context); + mContext = context; + } + @Override + protected void onCreate() { + super.onCreate(); + Component rootView = + LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_dialog_delete, null, false); + configChoiceButton(rootView); + configStyle(rootView); + } + private void configChoiceButton(Component rootView) { + LogUtil.info(TAG, "begin to configChoiceButton"); + Text operateYes = (Text) rootView.findComponentById(ResourceTable.Id_operate_yes); + operateYes.setClickedListener(component -> { + // delete file + destroy(); + }); + Text operateNo = (Text) rootView.findComponentById(ResourceTable.Id_operate_no); + operateNo.setClickedListener(component -> destroy()); + } + private void configStyle(Component rootView) { + LogUtil.info(TAG, "begin to configStyle"); + setSize(MATCH_PARENT, MATCH_CONTENT); + setAlignment(LayoutAlignment.CENTER); + setCornerRadius(CORNER_RADIUS); + setAutoClosable(true); + setContentCustomComponent(rootView); + setTransparent(true); + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/DeviceUtils.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/DeviceUtils.java new file mode 100755 index 0000000000..3e1310dc62 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/DeviceUtils.java @@ -0,0 +1,122 @@ +/* + * 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.distributedsearch.utils; + +import ohos.account.AccountAbility; +import ohos.account.DistributedInfo; +import ohos.app.Context; +import ohos.data.distributed.common.KvManagerConfig; +import ohos.data.distributed.common.KvManagerFactory; +import ohos.distributedschedule.interwork.DeviceInfo; +import ohos.distributedschedule.interwork.DeviceManager; +import java.util.ArrayList; +import java.util.List; + +public class DeviceUtils { + private static final String TAG = DeviceUtils.class.getSimpleName(); + + public static final int DEVICE_TYPE_NAME = 0; + public static final int DEVICE_TYPE_ID = 1; + + + private DeviceUtils() {} + + /** + * Get group id. + * @return group id. + */ + public static String getGroupId() { + AccountAbility account = AccountAbility.getAccountAbility(); + DistributedInfo distributeInfo = account.queryOsAccountDistributedInfo(); + return distributeInfo.getId(); + } + + public static List getAvailableDeviceId() { + List deviceIds = new ArrayList<>(); + + List deviceInfoList = DeviceManager.getDeviceList(DeviceInfo.FLAG_GET_ONLINE_DEVICE); + if (deviceInfoList == null) { + return deviceIds; + } + + if (deviceInfoList.size() == 0) { + System.out.println("did not find other device"); + return deviceIds; + } + + for (DeviceInfo deviceInfo : deviceInfoList) { + deviceIds.add(deviceInfo.getDeviceId()); + } + + return deviceIds; + } + + /** + * Get available id + * @return available device ids + */ + public static List getAllAvailableDeviceId() { + List deviceIds = new ArrayList<>(); + + List deviceInfoList = DeviceManager.getDeviceList(DeviceInfo.FLAG_GET_ALL_DEVICE); + if (deviceInfoList == null) { + return deviceIds; + } + System.out.println("deviceInfoList size " + deviceInfoList.size()); + if (deviceInfoList.size() == 0) { + System.out.println("did not find other device"); + return deviceIds; + } + + for (DeviceInfo deviceInfo : deviceInfoList) { + deviceIds.add(deviceInfo.getDeviceId()); + } + + return deviceIds; + } + + /** + * Check wether is the local device + * params: context: ability context + * info device name or id + * type: info type, 0 -- name, 1 -- id + * @return Remote device info list. + */ + public static boolean isLocalDevice(Context context, String info, int type) { + String result; + if (type == 0) { + result = KvManagerFactory.getInstance() + .createKvManager(new KvManagerConfig(context)) + .getLocalDeviceInfo().getName(); + } else if (type == 1) { + result = KvManagerFactory.getInstance() + .createKvManager(new KvManagerConfig(context)) + .getLocalDeviceInfo().getId(); + } else { + return false; + } + LogUtil.info(TAG, "info : "+info+",result : "+result); + return info.equals(result); + } + + /** + * Get remote device info + * @return Remote device info list. + */ + public static List getRemoteDevice() { + return DeviceManager.getDeviceList(DeviceInfo.FLAG_GET_ONLINE_DEVICE); + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/DistributedFile.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/DistributedFile.java new file mode 100755 index 0000000000..519f0b9a4c --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/DistributedFile.java @@ -0,0 +1,273 @@ +/* + * 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.distributedsearch.utils; + +import ohos.aafwk.ability.DataAbilityHelper; +import ohos.aafwk.ability.DataAbilityRemoteException; + +import ohos.app.Context; +import ohos.data.distributed.common.KvManagerConfig; +import ohos.data.distributed.common.KvManagerFactory; +import ohos.data.resultset.ResultSet; +import ohos.media.photokit.metadata.AVStorage; +import ohos.samples.distributedsearch.ResourceTable; +import ohos.utils.net.Uri; + +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +public class DistributedFile extends Thread{ + private static final String TAG = DistributedFile.class.getSimpleName(); + + public static final int FILE_TYPE_IMAGE = 0; + public static final int FILE_TYPE_AUDIO = 1; + public static final int FILE_TYPE_VIDEO = 2; + public static final int FILE_TYPE_TEXT = 3; + public static final int FILE_TYPE_FILE = 4; + public static final int FILE_TYPE_UNKNOWN = 0xFF; + + private static final int CACHE_SIZE = 8 * 1024; + private static final int END_OF_FILE = -1; + + private final String[] gImageType = {"jpg", "bmp", "jpeg", "png"}; + private final String[] gAudioType = {"mp3","wav", "flac"}; + private final String[] gVideoType = {"mp4","mjpeg"}; + private final String[] gTextType = {"xml","xlsx", "doc", "docx", "pdf", "txt"}; + + private final Context mContext; + private boolean isSearching = false; + private boolean checkResult = false; + + private final ArrayList localList = new ArrayList<>(); // Local file list object + private final ArrayList distributedList = new ArrayList<>(); // Distributed file list object + + public DistributedFile(Context context) { + mContext = context; + } + + @Override + public void run() { + isSearching = true; + initDistributedFiles(); // Initialize distributed file and local file list + getDistributedFiles(); // Get distributed file list + isSearching = false; + checkResult = true; + } + + public boolean isSearching() { + return isSearching; + } + + public boolean hasCheckResult() { + return checkResult; + } + + public List getFile(int type) { + if (distributedList.size() > 0) { + return getFileList(distributedList, type); + } else { + return getFileList(localList, type); + } + } + + private List getFileList(List gList, int type) { + if (type == FILE_TYPE_FILE || gList.size() == 0) { + return gList; + } + + ArrayList list = new ArrayList<>(); + + for (String filename : gList) { + if (isTypeFile(filename, type)) { + list.add(filename); + } + } + + return list; + } + + // Judge whether the file is the corresponding file type + private boolean isTypeFile(String file, int type) { + if (type == FILE_TYPE_FILE) { + return true; + } + if (type == FILE_TYPE_IMAGE) { + return isDestFile(file, gImageType); + } + if (type == FILE_TYPE_AUDIO) { + return isDestFile(file, gAudioType); + } + if (type == FILE_TYPE_VIDEO) { + return isDestFile(file, gVideoType); + } + if (type == FILE_TYPE_TEXT) { + return isDestFile(file, gTextType); + } + + return false; + } + + // Determines whether the string is in the given string array + private boolean isDestFile(String file, String[] des) { + int idx = file.lastIndexOf('.'); + if (idx < 0) { + return false; + } + String suffix = file.substring(idx+1); + + for (String de : des) { + if (de.equals(suffix)) { + return true; + } + } + + return false; + } + + // Search all local file entries + private void initDistributedFiles() { + // Search all pictures + searchFiles(AVStorage.Images.Media.EXTERNAL_DATA_ABILITY_URI); + // Search all audio files + searchFiles(AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI); + // Search all video files + searchFiles(AVStorage.Video.Media.EXTERNAL_DATA_ABILITY_URI); + } + + // func: Obtain the corresponding data in the database through the URI and write it to the + // distributed file system + // param: uri -- A connection in a database to find data + private void searchFiles(Uri uri) { + // Gets the current database object + DataAbilityHelper helper = DataAbilityHelper.creator(mContext); + // Database column key fields + String[] projections = new String[]{AVStorage.AVBaseColumns.ID, AVStorage.AVBaseColumns.DISPLAY_NAME, AVStorage.AVBaseColumns.DATA}; + try { + // Get the database result object according to the URI provided + ResultSet resultSet = helper.query(uri, projections, null); + if (resultSet == null) { + LogUtil.info(TAG, "resultSet == null"); + return; + } + // Get database data + while (resultSet.goToNextRow()) { + int mediaId = resultSet.getInt(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.ID)); + // Get file name from database DATA column + String fullFileName = resultSet.getString(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.DATA)); + String fileName = fullFileName.substring(fullFileName.lastIndexOf(File.separator) + 1); + Uri tmpUri = Uri.appendEncodedPathToUri(uri, "" + mediaId); + writeToDistributedDir(mContext, helper, fileName, tmpUri); + localList.add(fileName); + } + } catch (DataAbilityRemoteException e) { + LogUtil.error(TAG, "query Files failed."); + } + + } + + // Writes local database files to the distributed file system + private void writeToDistributedDir(Context context, DataAbilityHelper helper, String fileName, Uri uri) { + // Determine whether the distributed file system path can be obtained normally + if (context.getDistributedDir() == null) { + WidgetHelper.showOneSecondTips(context, context.getString(ResourceTable.String_distributed_exception_info)); + return; + } + // Gets the device name of the current device + String deviceName = KvManagerFactory.getInstance() + .createKvManager(new KvManagerConfig(context)) + .getLocalDeviceInfo().getName(); + // The files currently added to the distributed system are prefixed with the device name to + // distinguish the same file name of different devices + String uniqueFileName = deviceName + "+" + fileName; + String distributedFilePath = context.getDistributedDir().getPath() + '/' + uniqueFileName; + + writeFile(distributedFilePath, helper, uri); + } + + private void writeFile(String filename, DataAbilityHelper helper, Uri uri) { + InputStream inputStream = null; + OutputStream outputStream = null; + + try { + FileDescriptor fileDescriptor = helper.openFile(uri, "r"); + File file = new File(filename); + inputStream = new FileInputStream(fileDescriptor); + outputStream = new FileOutputStream(file); + + byte[] buffer = new byte[CACHE_SIZE]; + int count; + while ((count = inputStream.read(buffer)) != END_OF_FILE) { + outputStream.write(buffer, 0, count); + } + } catch (DataAbilityRemoteException | IOException e) { + LogUtil.error(TAG, "writeToDistributedDir exception : " + e); + } finally { + try { + if (inputStream != null) { + inputStream.close(); + } + if (outputStream != null) { + outputStream.close(); + } + } catch (IOException e) { + LogUtil.error(TAG, "close stream io exception"); + } + } + } + + // Get distributed file list + private void getDistributedFiles() { + if (mContext.getDistributedDir() == null) { + WidgetHelper.showOneSecondTips(mContext, mContext.getString(ResourceTable.String_distributed_exception_info)); + return; + } + File file = new File(mContext.getDistributedDir().getPath()); + File[] files = file.listFiles(); + if (files == null) { + LogUtil.error(TAG, "no distributed files!"); + return; + } + + for (File eachFile : files) { + distributedList.add(eachFile.getPath()); + } + } + + // Obtain the corresponding file type according to the given file name + public int checkFileType(String filename) { + if(isDestFile(filename, gImageType)) { + return FILE_TYPE_IMAGE; + } + if (isDestFile(filename, gAudioType)) { + return FILE_TYPE_AUDIO; + } + if (isDestFile(filename, gVideoType)) { + return FILE_TYPE_VIDEO; + } + if (isDestFile(filename, gTextType)) { + return FILE_TYPE_TEXT; + } + + return FILE_TYPE_UNKNOWN; + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/LogUtil.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/LogUtil.java new file mode 100755 index 0000000000..2dfe183749 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/LogUtil.java @@ -0,0 +1,166 @@ +/* + * 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.distributedsearch.utils; + +import ohos.distributedschedule.interwork.DeviceInfo; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +import java.util.Locale; + +/** + * Log util function + * + * @since 2019-10-15 + */ +public class LogUtil { + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000F00, ""); + + private static final String LOG_FORMAT = "%{public}s: %{public}s"; + + private LogUtil() { + /* Do nothing */ + } + + /** + * print device info to log + * + * @param className The prefix to log + * @param device The device into to print + * @param msg log message + */ + public static void printDevice(String className, DeviceInfo device, String msg) { + if (device == null) { + HiLog.error(LABEL_LOG, LOG_FORMAT, className, "DeviceInfo is null"); + } else { + HiLog.info(LABEL_LOG, + "%{public}s: %{public}s: { deviceId: %{public}s, deviceName: %{public}s, deviceType: %{public}s }", + className, msg, device.getDeviceId(), device.getDeviceName(), device.getDeviceType()); + } + } + + /** + * Print debug log + * + * @param className class name + * @param msg log message + */ + public static void debug(String className, String msg) { + HiLog.debug(LABEL_LOG, LOG_FORMAT, className, msg); + } + + /** + * Print info log + * + * @param className class name + * @param msg log message + */ + public static void info(String className, String msg) { + HiLog.info(LABEL_LOG, LOG_FORMAT, className, msg); + } + + /** + * Print info log + * + * @param className class name + * @param format format + * @param args args + */ + public static void info(String className, final String format, Object... args) { + String buffMsg = String.format(Locale.ROOT, format, args); + HiLog.info(LABEL_LOG, LOG_FORMAT, className, buffMsg); + } + + /** + * Print error log + * + * @param className class name + * @param msg log message + */ + public static void warn(String className, String msg) { + HiLog.warn(LABEL_LOG, LOG_FORMAT, className, msg); + } + + /** + * Print error log + * + * @param className class name + * @param msg log message + */ + public static void error(String className, String msg) { + HiLog.error(LABEL_LOG, LOG_FORMAT, className, msg); + } + + /** + * Print debug log + * + * @param classType class name + * @param format format + * @param args args + */ + public static void debug(Class classType, final String format, Object... args) { + String buffMsg = String.format(Locale.ROOT, format, args); + HiLog.debug(LABEL_LOG, LOG_FORMAT, classType == null ? "null" : classType.getSimpleName(), buffMsg); + } + + /** + * Print info log + * + * @param classType class name + * @param format format + * @param args args + */ + public static void info(Class classType, final String format, Object... args) { + String buffMsg = String.format(Locale.ROOT, format, args); + HiLog.info(LABEL_LOG, LOG_FORMAT, classType == null ? "null" : classType.getSimpleName(), buffMsg); + } + + /** + * Print warn log + * + * @param classType class name + * @param format format + * @param args args + */ + public static void warn(Class classType, final String format, Object... args) { + String buffMsg = String.format(Locale.ROOT, format, args); + HiLog.warn(LABEL_LOG, LOG_FORMAT, classType == null ? "null" : classType.getSimpleName(), buffMsg); + } + + /** + * Print error log + * + * @param classType class name + * @param format format + * @param args args + */ + public static void error(Class classType, final String format, Object... args) { + String buffMsg = String.format(Locale.ROOT, format, args); + HiLog.error(LABEL_LOG, LOG_FORMAT, classType == null ? "null" : classType.getSimpleName(), buffMsg); + } + + /** + * Print error log + * + * @param tag log tag + * @param format format + * @param args args + */ + public static void error(String tag, final String format, Object... args) { + String buffMsg = String.format(Locale.ROOT, format, args); + HiLog.error(LABEL_LOG, LOG_FORMAT, tag, buffMsg); + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/WidgetHelper.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/WidgetHelper.java new file mode 100755 index 0000000000..0df69fd5de --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/WidgetHelper.java @@ -0,0 +1,151 @@ +/* + * 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.distributedsearch.utils; + +import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT; +import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT; + +import ohos.agp.colors.RgbColor; +import ohos.agp.components.ComponentContainer; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.Text; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.agp.utils.LayoutAlignment; +import ohos.agp.utils.TextAlignment; +import ohos.agp.window.dialog.ToastDialog; +import ohos.app.Context; +import ohos.global.resource.NotExistException; +import ohos.global.resource.ResourceManager; +import ohos.global.resource.WrongTypeException; + +import java.io.IOException; + +/** + * The type Widget helper. + * + * @since 2021-04-27 + */ +public class WidgetHelper { + private static final String TAG = WidgetHelper.class.getSimpleName(); + + private static final int ONE_SECOND = 1000; + + private WidgetHelper() { + } + + /** + * Show tips. + * + * @param context the context + * @param msgId the msg id + */ + public static void showTips(Context context, int msgId) { + String msg = getStringByResourceId(context, msgId); + showOneSecondTips(context, msg); + } + + /** + * Show tips. + * + * @param context the context + * @param msg the msg + * @param durationTime the duration time + * @param widgetStyle the widget style + */ + public static void showTips(Context context, String msg, int durationTime, WidgetStyle widgetStyle) { + Text text = new Text(context); + text.setWidth(MATCH_CONTENT); + text.setHeight(MATCH_CONTENT); + text.setTextSize(widgetStyle.getTextSize()); + text.setText(msg); + text.setPadding(widgetStyle.getTextHorizontalPadding(), widgetStyle.getTextVerticalPadding(), + widgetStyle.getTextHorizontalPadding(), widgetStyle.getTextVerticalPadding()); + text.setMultipleLine(true); + text.setTextColor(Color.WHITE); + text.setTextAlignment(TextAlignment.CENTER); + + ShapeElement style = new ShapeElement(); + style.setShape(ShapeElement.RECTANGLE); + style.setRgbColor(new RgbColor(widgetStyle.getRgbColor())); + style.setCornerRadius(widgetStyle.getCornerRadius()); + text.setBackground(style); + + DirectionalLayout mainLayout = new DirectionalLayout(context); + mainLayout.setWidth(MATCH_PARENT); + mainLayout.setHeight(MATCH_CONTENT); + mainLayout.setAlignment(LayoutAlignment.CENTER); + mainLayout.addComponent(text); + + ToastDialog toastDialog = new ToastDialog(context); + toastDialog.setSize(MATCH_PARENT, MATCH_CONTENT); + toastDialog.setDuration(durationTime); + toastDialog.setAutoClosable(true); + toastDialog.setTransparent(true); + toastDialog.setAlignment(LayoutAlignment.CENTER); + toastDialog.setComponent((ComponentContainer) mainLayout); + toastDialog.show(); + } + + /** + * Show tips. + * + * @param context the context + * @param msg the msg + * @param durationTime the duration time + */ + public static void showTips(Context context, String msg, int durationTime) { + WidgetStyle widgetStyle = WidgetStyle.getDefault(); + showTips(context, msg, durationTime, widgetStyle); + } + + /** + * Show one second tips. + * + * @param context the context + * @param msg the msg + */ + public static void showOneSecondTips(Context context, String msg) { + showTips(context, msg, ONE_SECOND); + } + + /** + * Gets string by resource id. + * + * @param context the context + * @param id the id + * @return the string by resource id + */ + public static String getStringByResourceId(Context context, int id) { + if (context == null) { + LogUtil.info(TAG, "Context is null, getString failed"); + return ""; + } + ResourceManager resMgr = context.getResourceManager(); + if (resMgr == null) { + LogUtil.info(TAG, "ResourceManager is null, getString failed"); + return ""; + } + + String value = ""; + try { + value = resMgr.getElement(id).getString(); + } catch (NotExistException | WrongTypeException | IOException e) { + LogUtil.info(TAG, "get string value from resource manager failed"); + } + return value; + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/WidgetStyle.java b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/WidgetStyle.java new file mode 100755 index 0000000000..ff8a120c96 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/java/ohos/samples/distributedsearch/utils/WidgetStyle.java @@ -0,0 +1,100 @@ +/* + * 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.distributedsearch.utils; + +/** + * The type Widget style. + * + * @since 2021-04-27 + */ +public class WidgetStyle { + private static final int DEFAULT_CORNER_RADIUS = 15; + + private static final int DEFAULT_TEXT_SIZE = 48; + + private static final int DEFAULT_H_PADDING = 30; + + private static final int DEFAULT_V_PADDING = 20; + + private static final int DEFAULT_RGB_COLOR = 0x666666FF; + + private int cornerRadius; + + private int textSize; + + // left and right padding + private int textHorizontalPadding; + + // top and bottom padding + private int textVerticalPadding; + + private int rgbColor; + + public int getCornerRadius() { + return cornerRadius; + } + + public void setCornerRadius(int cornerRadius) { + this.cornerRadius = cornerRadius; + } + + public int getTextSize() { + return textSize; + } + + public void setTextSize(int textSize) { + this.textSize = textSize; + } + + public int getTextHorizontalPadding() { + return textHorizontalPadding; + } + + public void setTextHorizontalPadding(int textHorizontalPadding) { + this.textHorizontalPadding = textHorizontalPadding; + } + + public int getTextVerticalPadding() { + return textVerticalPadding; + } + + public void setTextVerticalPadding(int textVerticalPadding) { + this.textVerticalPadding = textVerticalPadding; + } + + public int getRgbColor() { + return rgbColor; + } + + public void setRgbColor(int rgbColor) { + this.rgbColor = rgbColor; + } + + /** + * Gets default. + * + * @return the default + */ + public static WidgetStyle getDefault() { + WidgetStyle widgetStyle = new WidgetStyle(); + widgetStyle.setCornerRadius(DEFAULT_CORNER_RADIUS); + widgetStyle.setTextSize(DEFAULT_TEXT_SIZE); + widgetStyle.setTextHorizontalPadding(DEFAULT_H_PADDING); + widgetStyle.setTextVerticalPadding(DEFAULT_V_PADDING); + widgetStyle.setRgbColor(DEFAULT_RGB_COLOR); + return widgetStyle; + } +} diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/animation/animator_value.xml b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/animation/animator_value.xml new file mode 100755 index 0000000000..10b8c66435 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/animation/animator_value.xml @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/element/colors.json b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/element/colors.json new file mode 100755 index 0000000000..c01a9178b7 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/element/colors.json @@ -0,0 +1,20 @@ +{ + "color": [ + { + "name": "news_type_text_off", + "value": "#55000000" + }, + { + "name": "news_type_text_on", + "value": "#afaafa" + }, + { + "name": "white", + "value": "#ffffff" + }, + { + "name": "half_transparent", + "value": "#55000000" + } + ] +} \ No newline at end of file diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/element/string.json b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000..723ac761ff --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/element/string.json @@ -0,0 +1,88 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "DistributedSearch" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + }, + { + "name": "button_distributed_device", + "value": "Dev" + }, + { + "name": "button_add_distributed", + "value": "Join distributed file system" + }, + { + "name": "image_label", + "value": "Image" + }, + { + "name": "audio_label", + "value": "Audio" + }, + { + "name": "video_label", + "value": "Video" + }, + { + "name": "text_label", + "value": "File" + }, + { + "name": "all_label", + "value": "All" + }, + { + "name": "result_info_label", + "value": "No results" + }, + { + "name": "cancel_label", + "value": "Cancel" + }, + { + "name": "confirm_label", + "value": "Confirm" + }, + { + "name": "input_notice_msg", + "value": "Please enter a valid search keyword" + }, + { + "name": "file_path_label", + "value": "File path" + }, + { + "name": "local_device_name", + "value": "Local" + }, + { + "name": "distributed_exception_info", + "value": "Note: distributed file exception!" + }, + { + "name": "file_source_label", + "value": "File source" + }, + { + "name": "delete_file_info", + "value": "Are you sure to delete this file?" + }, + { + "name": "delete_file_warn", + "value": "The file cannot be recovered after deletion" + }, + { + "name": "delete_label", + "value": "Delete" + } + ] +} \ No newline at end of file diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_ability_main.xml b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100755 index 0000000000..bf57e7d959 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_button.xml b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_button.xml new file mode 100755 index 0000000000..56ca853988 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_button.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_text_field.xml b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_text_field.xml new file mode 100755 index 0000000000..fc5145eada --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_text_field.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_white_radius_10.xml b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_white_radius_10.xml new file mode 100755 index 0000000000..f1ee87e0d4 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/background_white_radius_10.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/ele_cursor_bubble.xml b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/ele_cursor_bubble.xml new file mode 100755 index 0000000000..d67d985417 --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/graphic/ele_cursor_bubble.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/layout/ability_everything.xml b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/layout/ability_everything.xml new file mode 100755 index 0000000000..214ff957da --- /dev/null +++ b/ScenarioDemos/DistributedSearch/entry/src/main/resources/base/layout/ability_everything.xml @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +