diff --git a/ETSUI/EtsResourceManager/README_zh.md b/ETSUI/EtsResourceManager/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..0a07227e506e070e31db18fe70af4bc1524e16c3 --- /dev/null +++ b/ETSUI/EtsResourceManager/README_zh.md @@ -0,0 +1,19 @@ +# Ets资源管理 + + + +### 简介 + +本示例展示了在eTS中如何调用资源管理的API接口读取字符串、字符串数组、根据指定数量获取指定ID字符串表示的单复数字符串、指定资源ID对应的媒体文件内容字节数、指定资源ID对应的图片资源Base64编码,以及获取设备状态和设备支持的能力。 + +### 使用说明 + +1、点击图标打开应用。 + +2、首页中展示了通过资源管理API接口读取的字符串、字符串数组、根据指定数量获取指定ID字符串表示的单复数字符串,指定资源ID对应的媒体文件内容字节数、指定资源ID对应的图片资源Base64编码字符串的长度,以及获取设备状态和设备支持的能力。 + + + +### 约束与限制 + +本示例仅支持标准系统上运行。 diff --git a/ETSUI/EtsResourceManager/build.gradle b/ETSUI/EtsResourceManager/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..cae0ab0036a5626c92f93fb72c5f763e9764d21b --- /dev/null +++ b/ETSUI/EtsResourceManager/build.gradle @@ -0,0 +1,33 @@ +// 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#section1112183053510 +ohos { + compileSdkVersion 7 + supportSystem "standard" +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } + dependencies { + classpath 'com.huawei.ohos:hap:3.0.3.4' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } +} diff --git a/ETSUI/EtsResourceManager/entry/build.gradle b/ETSUI/EtsResourceManager/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..eeb7e1258930dbfd3af9f86f229a811de106a92b --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/build.gradle @@ -0,0 +1,16 @@ +apply plugin: 'com.huawei.ohos.hap' +// For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 7 + defaultConfig { + compatibleSdkVersion 7 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } +} diff --git a/ETSUI/EtsResourceManager/entry/src/main/config.json b/ETSUI/EtsResourceManager/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..b7695221dd694c9aafc7e4f66a2d632ceb267fdf --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/config.json @@ -0,0 +1,62 @@ +{ + "app": { + "bundleName": "ohos.samples.etsresourcemanager", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.etsresourcemanager", + "name": ".MyApplication", + "mainAbility": ".MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".MainAbility" + } + ] + } +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/entry/src/main/ets/MainAbility/app.ets b/ETSUI/EtsResourceManager/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..cfb9635413551f8ad3434468b138550cbad174d6 --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ +export default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/entry/src/main/ets/MainAbility/pages/index.ets b/ETSUI/EtsResourceManager/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4aa93262997f319eb516a0b8b1c05a2e14c3aa8 --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,158 @@ +/* + * 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. + */ +import resourceManager from '@ohos.resourceManager'; + +@Entry +@Component +struct Index { + @State string_str: string = '' + @State strArray: string = 'stringArray:' + @State plural: string = 'plural:' + @State configuration: string = '' + @State capability: string = '' + @State media: string = 'icon' + @State mediaBase: string = 'icon' + + aboutToAppear() { + resourceManager.getResourceManager().then(mgr => { + mgr.getString(0x1000007, (error, value) => { + if (error != null) { + console.log('ResourceManager' + value); + } else { + console.log('ResourceManager' + value); + this.string_str += value + } + }); + mgr.getStringArray(0x1000009, (error, value) => { + if (error != null) { + console.log('ResourceManager' + value); + } else { + console.log('ResourceManager' + value); + this.strArray += JSON.stringify(value) + } + }); + mgr.getString(0x1000000, (error, value) => { + if (error != null) { + console.log('ResourceManager' + value); + } else { + console.log('ResourceManager' + value); + this.capability = value + } + }); + mgr.getString(0x1000001, (error, value) => { + if (error != null) { + console.log('ResourceManager' + value); + } else { + console.log('ResourceManager' + value); + this.configuration = value + } + }); + mgr.getPluralString(0x100000a, 2, (error, value) => { + if (error != null) { + console.log('getPluralString error' + value); + } else { + console.log('getPluralString:' + value); + this.plural += JSON.stringify(value) + } + }); + mgr.getDeviceCapability((error, value) => { + if (error != null) { + console.log('getDeviceCapability error:' + JSON.stringify(value)); + } else { + console.log('getDeviceCapability:' + JSON.stringify(value)); + this.capability += JSON.stringify(value) + } + }); + + mgr.getString(0x1000006, (error, value) => { + if (error != null) { + console.log('ResourceManager' + value); + } else { + console.log('ResourceManager' + value); + this.mediaBase += value + } + }); + mgr.getConfiguration((error, value) => { + if (error != null) { + console.log('getConfiguration error:' + JSON.stringify(value)); + } else { + console.log('getConfiguration:' + JSON.stringify(value)); + this.configuration += JSON.stringify(value) + } + }); + mgr.getString(0x1000005, (error, value) => { + if (error != null) { + console.log('ResourceManager' + value); + } else { + console.log('ResourceManager' + value); + this.media += value + } + }); + mgr.getMedia(0x100000b, (error, value) => { + if (error != null) { + console.log('ResourceManager' + value); + } else { + console.log('ResourceManager' + value); + this.media += value.byteLength / 1000 + 'kb' + } + }); + mgr.getMediaBase64(0x100000b, (error, value) => { + if (error != null) { + console.log('ResourceManager' + value); + } else { + console.log('ResourceManager' + value); + this.mediaBase += value.length + } + }); + }).catch(error => { + console.log(error); + }); + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) { + Text($r("app.string.title")) + .width('100%') + .height(50) + .backgroundColor('#0D9FFB') + .fontColor(Color.White) + .fontSize(20) + .padding({ left: 15 }) + + Scroll() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Center }) { + Text(this.string_str) + .fontSize(25) + Text(this.strArray) + .fontSize(25) + Text(this.plural) + .fontSize(25) + Text(this.capability) + .fontSize(25) + Text(this.configuration) + .fontSize(25) + Text(this.media) + .fontSize(25) + Text(this.mediaBase) + .fontSize(25) + } + .width('100%') + .padding(15) + } + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/entry/src/main/resources/base/element/plural.json b/ETSUI/EtsResourceManager/entry/src/main/resources/base/element/plural.json new file mode 100644 index 0000000000000000000000000000000000000000..bd3c5c38813aa3ddff57218724dc51b00bc51a41 --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/resources/base/element/plural.json @@ -0,0 +1,17 @@ +{ + "plural": [ + { + "name": "eat_apple", + "value": [ + { + "quantity": "one", + "value": "%d apple" + }, + { + "quantity": "other", + "value": "%d apples" + } + ] + } + ] +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/entry/src/main/resources/base/element/strarray.json b/ETSUI/EtsResourceManager/entry/src/main/resources/base/element/strarray.json new file mode 100644 index 0000000000000000000000000000000000000000..0844d7e6d2b95dae47c72cf2c75c4b90db657683 --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/resources/base/element/strarray.json @@ -0,0 +1,18 @@ +{ + "strarray": [ + { + "name": "str_array", + "value": [ + { + "value": "small" + }, + { + "value": "big" + }, + { + "value": "super" + } + ] + } + ] +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/entry/src/main/resources/base/element/string.json b/ETSUI/EtsResourceManager/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fc82391b8f4854882bd2c5066cf85462a9e0975d --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSResourceManager" + }, + { + "name": "description_mainability", + "value": "eTSResourceManager Ability" + }, + { + "name": "title", + "value": "ResourceManager" + }, + { + "name": "get_info", + "value": "get info from ResourceManager" + }, + { + "name": "string_str", + "value": "string:eTSResourceManager" + }, + { + "name": "capability", + "value": "DeviceCapability:" + }, + { + "name": "configuration", + "value": "Configuration:" + }, + { + "name": "media", + "value": "Media size:" + }, + { + "name": "media_base", + "value": "MediaBase64 string length:" + } + ] +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/entry/src/main/resources/base/media/icon.png b/ETSUI/EtsResourceManager/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ETSUI/EtsResourceManager/entry/src/main/resources/base/media/icon.png differ diff --git a/ETSUI/EtsResourceManager/entry/src/main/resources/en/element/strarray.json b/ETSUI/EtsResourceManager/entry/src/main/resources/en/element/strarray.json new file mode 100644 index 0000000000000000000000000000000000000000..0844d7e6d2b95dae47c72cf2c75c4b90db657683 --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/resources/en/element/strarray.json @@ -0,0 +1,18 @@ +{ + "strarray": [ + { + "name": "str_array", + "value": [ + { + "value": "small" + }, + { + "value": "big" + }, + { + "value": "super" + } + ] + } + ] +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/entry/src/main/resources/en/element/string.json b/ETSUI/EtsResourceManager/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ea66391492ffa474fe1708a8c82d025ddaa1ecdf --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/resources/en/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSResourceManager" + }, + { + "name": "description_mainability", + "value": "eTSResourceManager Ability" + }, + { + "name": "title", + "value": "ResourceManager" + }, + { + "name": "get_info", + "value": "get info from ResourceManager" + }, + { + "name": "string_str", + "value": "string:eTSResourceManager" + }, + { + "name": "capability", + "value": "DeviceCapability:" + }, + { + "name": "configuration", + "value": "Configuration:" + }, + { + "name": "media", + "value": "Media:" + }, + { + "name": "media_base", + "value": "MediaBase64:" + } + ] +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/entry/src/main/resources/zh/element/strarray.json b/ETSUI/EtsResourceManager/entry/src/main/resources/zh/element/strarray.json new file mode 100644 index 0000000000000000000000000000000000000000..0b3acb12fcd68b4bdbdfd5b552fc3804b5d1d031 --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/resources/zh/element/strarray.json @@ -0,0 +1,18 @@ +{ + "strarray": [ + { + "name": "str_array", + "value": [ + { + "value": "小" + }, + { + "value": "大" + }, + { + "value": "超大" + } + ] + } + ] +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/entry/src/main/resources/zh/element/string.json b/ETSUI/EtsResourceManager/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4d0f2c87089a2feb916091c8f174795897a15074 --- /dev/null +++ b/ETSUI/EtsResourceManager/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTS资源管理" + }, + { + "name": "description_mainability", + "value": "eTSResourceManager Ability" + }, + { + "name": "title", + "value": "资源管理" + }, + { + "name": "get_info", + "value": "通过资源管理获取信息" + }, + { + "name": "string_str", + "value": "string:eTS资源管理" + }, + { + "name": "capability", + "value": "设备支持能力:" + }, + { + "name": "configuration", + "value": "设备状态:" + }, + { + "name": "media", + "value": "图片字节数:" + }, + { + "name": "media_base", + "value": "Base64编码字符串长度:" + } + ] +} \ No newline at end of file diff --git a/ETSUI/EtsResourceManager/sceenshots/devices/main.png b/ETSUI/EtsResourceManager/sceenshots/devices/main.png new file mode 100644 index 0000000000000000000000000000000000000000..78f5da57a12d545065388c828f422a4b2ec7e01c Binary files /dev/null and b/ETSUI/EtsResourceManager/sceenshots/devices/main.png differ diff --git a/ETSUI/EtsResourceManager/settings.gradle b/ETSUI/EtsResourceManager/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/ETSUI/EtsResourceManager/settings.gradle @@ -0,0 +1 @@ +include ':entry'