diff --git a/common/eTSUtilBase64Codec/README.md b/common/eTSUtilBase64Codec/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4b2021aeebf9096ca224a958340621a2468e4fff --- /dev/null +++ b/common/eTSUtilBase64Codec/README.md @@ -0,0 +1,15 @@ +# base64编解码 + +### 简介 + +Base64是一种基于64个可打印字符来表示二进制数据的方法,本示例展示了Base64编码及解码的结果输出 + +### 使用说明 + +1:点击**编码**按钮,将会把字符串转换为ASCII码,然后对ASCII码进行编码,并在文本框输出编码后的结果。 + +2:点击**解码**按钮,将会把编码后输出的结果作为解码器的入参,解码后得到ASCII码数组,然后将ASCII码数组转换为字符串在文本框输出。 + +### 约束与限制 + +本示例仅支持在标准系统上运行。 \ No newline at end of file diff --git a/common/eTSUtilBase64Codec/build.gradle b/common/eTSUtilBase64Codec/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..f350f30a90f962897ebab2c31e5bbf3e4868a578 --- /dev/null +++ b/common/eTSUtilBase64Codec/build.gradle @@ -0,0 +1,34 @@ +// 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 8 + 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.5.2' + classpath 'com.huawei.ohos:decctest:1.2.7.2' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } +} diff --git a/common/eTSUtilBase64Codec/entry/build.gradle b/common/eTSUtilBase64Codec/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..05a33cd3adb09a68a581b9f7c02c57d3911630e8 --- /dev/null +++ b/common/eTSUtilBase64Codec/entry/build.gradle @@ -0,0 +1,21 @@ +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 8 + defaultConfig { + compatibleSdkVersion 8 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13.1' +} diff --git a/common/eTSUtilBase64Codec/entry/src/main/config.json b/common/eTSUtilBase64Codec/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..1848fa79343a357b7ec57e1c2683d04586797e85 --- /dev/null +++ b/common/eTSUtilBase64Codec/entry/src/main/config.json @@ -0,0 +1,67 @@ +{ + "app": { + "bundleName": "ohos.samples.etsutilbase64codec", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.etsutilbase64codec", + "name": ".MyApplication", + "mainAbility": ".MainAbility", + "srcPath": "", + "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", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/common/eTSUtilBase64Codec/entry/src/main/ets/MainAbility/app.ets b/common/eTSUtilBase64Codec/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf28e58b36cf11db491d3f00768ef2c9e41d05cf --- /dev/null +++ b/common/eTSUtilBase64Codec/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,23 @@ +/* + * 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/common/eTSUtilBase64Codec/entry/src/main/ets/MainAbility/pages/index.ets b/common/eTSUtilBase64Codec/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cf03e3cd5544978fc819ceb570c73cbcffb2b8af --- /dev/null +++ b/common/eTSUtilBase64Codec/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,102 @@ +/* + * 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 util from '@ohos.util'; + +@Entry +@Component +struct Index { + @State windows_en: string = '' + @State windows_de: string = '' + @State input: string = 'harmony' + private StrToAscii: number[] = [] + private AsciiToStr: string = '' + + build() { + Scroll() { + Column() { + Text($r("app.string.change_str") + this.input) + .width('90%') + .height('10%') + .textAlign(TextAlign.Center) + .fontSize(20) + .fontWeight(FontWeight.Bold) + + Text(this.windows_en) + .width('90%') + .height('10%') + .margin({ top: 20 }) + .padding({left:10}) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .border({ width: 2, radius: 10, color: Color.Black }) + + Button() { + Text($r("app.string.encode")) + .fontSize(25) + .fontWeight(FontWeight.Bold) + } + .width(300) + .height('10%') + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + for (let i = 0;i < this.input.length; i++) { + this.StrToAscii.push(this.input.charCodeAt(i)) + } + var that = new util.Base64(); + var encodeNum = new Uint8Array(this.StrToAscii); + this.windows_en = that.encodeToStringSync(encodeNum) + }) + + Text(this.windows_de) + .width('90%') + .height('10%') + .fontSize(20) + .padding({left:10}) + .fontWeight(FontWeight.Bold) + .border({ width: 2, radius: 10, color: Color.Black }) + .margin({ top: 50 }) + + Button() { + Text($r("app.string.decode")) + .fontSize(25) + .fontWeight(FontWeight.Bold) + } + .width(300) + .height('10%') + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + var that = new util.Base64(); + var decodeNum = that.decodeSync(this.windows_en); + for (let i = 0; i < decodeNum.length; i++) { + this.AsciiToStr += String.fromCharCode(decodeNum[i]) + } + this.windows_de = this.AsciiToStr + }) + } + } + .scrollBar(BarState.Off) + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/common/eTSUtilBase64Codec/entry/src/main/resources/base/element/string.json b/common/eTSUtilBase64Codec/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..26d507690b7f98cee90a8be7b409ea6157cdbab2 --- /dev/null +++ b/common/eTSUtilBase64Codec/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "description_mainability", + "value": "eTS_Empty Ability" + }, + { + "name": "change_str", + "value": "要转换的字符串:" + }, + { + "name": "encode", + "value": "编码" + }, + { + "name": "decode", + "value": "解码" + } + ] +} \ No newline at end of file diff --git a/common/eTSUtilBase64Codec/entry/src/main/resources/base/media/icon.png b/common/eTSUtilBase64Codec/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/common/eTSUtilBase64Codec/entry/src/main/resources/base/media/icon.png differ diff --git a/common/eTSUtilBase64Codec/screenshots/device/base.png b/common/eTSUtilBase64Codec/screenshots/device/base.png new file mode 100644 index 0000000000000000000000000000000000000000..39b873ed391b78798484ad1926508454fe0a762e Binary files /dev/null and b/common/eTSUtilBase64Codec/screenshots/device/base.png differ diff --git a/common/eTSUtilBase64Codec/settings.gradle b/common/eTSUtilBase64Codec/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/common/eTSUtilBase64Codec/settings.gradle @@ -0,0 +1 @@ +include ':entry'