diff --git a/ETSUI/StringCodec/README.md b/ETSUI/StringCodec/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3d951cae2ebb92ce2381677eb29e239799ea0a9c --- /dev/null +++ b/ETSUI/StringCodec/README.md @@ -0,0 +1,19 @@ +# 字符串编解码 + +### 简介 + +本示例对字符串进行了特定格式的输出,对错误码的内容进行了文本输出,对字符串的编码和解码做了演示结果。 + +### 使用说明 + +1:点击特定格式输出,文本框会对该字符串进行不同格式的结果输出,例如整数、浮点数、字符串等格式。 + +2:点击获取系统对应的详细信息按钮,每行文本框输出左边的错误码所表示的具体文本意思。 + +3:点击文本编辑器,会对上面字符串编码后输出对应文本,并输出数据读取与写入的相关信息。 + +4:点击文本译码器,会对上面编码的文本内容进行译码,输出结果为上述编码前的字符串。 + +### 约束与限制 + +本示例仅支持在标准设备上运行。 \ No newline at end of file diff --git a/ETSUI/StringCodec/build.gradle b/ETSUI/StringCodec/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..c2c8bbaed13747b913f19cef893f515bc32d02a7 --- /dev/null +++ b/ETSUI/StringCodec/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 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' + classpath 'com.huawei.ohos:decctest:1.2.6.0' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } +} diff --git a/ETSUI/StringCodec/entry/build.gradle b/ETSUI/StringCodec/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..1587dd1948941f3eaaf092ae6cae7969cb6895ff --- /dev/null +++ b/ETSUI/StringCodec/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 7 + defaultConfig { + compatibleSdkVersion 7 + } + 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/ETSUI/StringCodec/entry/src/main/config.json b/ETSUI/StringCodec/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..27a3d3a6ed5d95ec767010b93945edbb9e17e65a --- /dev/null +++ b/ETSUI/StringCodec/entry/src/main/config.json @@ -0,0 +1,66 @@ +{ + "app": { + "bundleName": "ohos.samples.stringcodec", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.stringcodec", + "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:StringCodec", + "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/ETSUI/StringCodec/entry/src/main/ets/MainAbility/app.ets b/ETSUI/StringCodec/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..b7a0995c8e441cac86e21e06e7c9071664482b1c --- /dev/null +++ b/ETSUI/StringCodec/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,8 @@ +export default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/ETSUI/StringCodec/entry/src/main/ets/MainAbility/pages/index.ets b/ETSUI/StringCodec/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9b49b2e3fe96819c92e49e62af3e3a79b750724f --- /dev/null +++ b/ETSUI/StringCodec/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,260 @@ +import util from '@ohos.util' + +var resArray + +@Entry +@Component +struct StrCodec { + + @State SpecStrInput_s: string = '' + @State SpecStrInput_d: string = '' + @State SpecStrInput_i: string = '' + @State SpecStrInput_f: string = '' + + @State err_res01:string = '' + @State err_res02:string = '' + @State err_res03:string = '' + @State err_res04:string = '' + @State err_res05:string = '' + + @State resen:string ='' + @State resdec:string ='' + @State read:string ='' + @State write:string ='' + + build() { + + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { + Text($r('app.string.StringCodec_title')) + .width('100%') + .height(50) + .backgroundColor("#0D9FFB") + .textAlign(TextAlign.Start) + .fontSize(25) + .fontColor(Color.White) + .fontWeight(FontWeight.Bold) + .padding({left:20,top:10}) + Scroll(){ + Column(){ + Row(){ + Text($r('app.string.SpecString')) + .fontSize(15) + .width(60) + .height(50) + .margin({top:20 }) + .textAlign(TextAlign.Start) + Text($r('app.string.SpecString_info')) + .fontSize(15) + .width(200) + .height(50) + .margin({left:5,top:20 }) + .textAlign(TextAlign.Start) + } + Row() { + Text($r('app.string.result_f')).width('30%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.SpecStrInput_f) + .width('70%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + Row() { + Text($r('app.string.result_i')).width('30%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.SpecStrInput_i) + .width('70%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + Row() { + Text($r('app.string.result_d')).width('30%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.SpecStrInput_d) + .width('70%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + Row() { + Text($r('app.string.result_s')).width('30%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.SpecStrInput_s) + .width('70%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + Button(){ + Text($r('app.string.SpecFormOutput')).fontSize(15).fontWeight(FontWeight.Bold).fontColor(Color.White) + } + .width(300) + .margin({ top: 20 }) + .onClick(() => { + this.SpecStrInput_f = util.printf("%f", $r('app.string.SpecString_info')); + this.SpecStrInput_i = util.printf("%i", $r('app.string.SpecString_info')); + this.SpecStrInput_d = util.printf("%d", $r('app.string.SpecString_info')); + this.SpecStrInput_s = util.printf("%s", "HarmonyOS 3.0"); + }) + .backgroundColor("#0D9FFB") + + + Text('').width('100%').height(10).backgroundColor("#0D9FFB").margin({top:20}).border({width:2,color:"#0D9FFB"}) + + Row() { + Text($r('app.string.num1')).width('20%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.err_res01) + .width('80%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + + Row() { + Text($r('app.string.num2')).width('20%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.err_res02) + .width('80%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + + Row() { + Text($r('app.string.num3')).width('20%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.err_res03) + .width('80%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + + Row() { + Text($r('app.string.num4')).width('20%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.err_res04) + .width('80%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + + Row() { + Text($r('app.string.num5')).width('20%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.err_res05) + .width('80%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + + Button(){ + Text($r('app.string.getErrorInfo')).fontColor(Color.White).fontSize(15).fontWeight(FontWeight.Bold) + } + .margin({ top: 20 }) + .onClick(() => { + var errnum_01 = 10; + var errnum_02 = 20; + var errnum_03 = 100; + var errnum_04 = -10; + var errnum_05 = 1000; + this.err_res01 = util.getErrorString(errnum_01); + this.err_res02 = util.getErrorString(errnum_02); + this.err_res03 = util.getErrorString(errnum_03); + this.err_res04 = util.getErrorString(errnum_04); + this.err_res05 = util.getErrorString(errnum_05); + }) + .backgroundColor("#0D9FFB") + .width(300) + + Text('').width('100%').height(10).backgroundColor("#0D9FFB").margin({top:20}).border({width:2,color:"#0D9FFB"}) + + Row(){ + Text($r('app.string.SpecString')) + .fontSize(15) + .width(60) + .height(50) + .margin({top:20 }) + .textAlign(TextAlign.Start) + Text($r('app.string.StringCodec_info')) + .fontSize(15) + .width(240) + .height(50) + .margin({left:5,top:20 }) + .textAlign(TextAlign.Start) + } + Row() { + Text($r('app.string.result')).width('20%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.resen) + .width('80%') + .height(60) + .fontSize(15) + .maxLines(2) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + Row() { + Text($r('app.string.read')).width('20%').height(30).fontSize(15).textAlign(TextAlign.Start) + Text(this.read) + .width('30%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + Text($r('app.string.write')).width('20%').height(30).fontSize(15).textAlign(TextAlign.Center) + Text(this.write) + .width('30%') + .height(30) + .fontSize(15) + .textAlign(TextAlign.Start) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + + Button(){ + Text($r('app.string.Text_encoder')).fontColor(Color.White).fontSize(15).fontWeight(FontWeight.Bold) + } + .margin({ top: 20 }) + .onClick(() => { + var textEncoder = new util.TextEncoder() + var buffer = new ArrayBuffer(100) + resArray = new Uint8Array(buffer); + resArray = textEncoder.encode("HarmonyOS 3.0,未来有迹可循!"); + var resArratNum = textEncoder.encodeInto("HarmonyOS 3.0,未来有迹可循!", resArray) + this.resen = resArray.toString(); + this.read = JSON.stringify(resArratNum.read) + this.write = JSON.stringify(resArratNum. written) + }) + .backgroundColor("#0D9FFB") + .width(300) + + Row() { + Text($r('app.string.result')).width('20%').height(30).fontSize(15).textAlign(TextAlign.Start).fontColor(Color.Black) + Text(this.resdec) + .width('80%') + .height(60) + .fontSize(15) + .textAlign(TextAlign.Start) + .maxLines(2) + .border({width:2,radius:5,color:"#0D9FFB"}) + }.margin({ top: 20 }).width(300) + + Button(){ + Text($r('app.string.Text_decoder')).fontColor(Color.White).fontSize(15).fontWeight(FontWeight.Bold) + } + .margin({ top: 20,bottom:50 }) + .onClick(() => { + var textDecoder = new util.TextDecoder("utf-8",{ignoreBOM:true}); + var retStr = textDecoder.decode( resArray , {stream:false}); + this.resdec = retStr; + }) + .backgroundColor("#0D9FFB") + .width(300) + } + } + } + } +} \ No newline at end of file diff --git a/ETSUI/StringCodec/entry/src/main/resources/base/element/string.json b/ETSUI/StringCodec/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..37ab372ff012ddefab3cb9630e9d17f899f61193 --- /dev/null +++ b/ETSUI/StringCodec/entry/src/main/resources/base/element/string.json @@ -0,0 +1,97 @@ +{ + "string": [ + { + "name": "StringCodec", + "value": "StringCodec" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "StringCodec_title", + "value": "字符串编解码" + }, + { + "name": "StringName", + "value": "字符串" + }, + { + "name": "SpecString", + "value": "字符串 : " + }, + { + "name": "SpecString_info", + "value": "HarmonyOS 3.0" + }, + { + "name": "result", + "value": "result = " + }, + { + "name": "result_f", + "value": "result[%f] = " + }, + { + "name": "result_i", + "value": "result[%i] = " + }, + { + "name": "result_d", + "value": "result[%d] = " + }, + { + "name": "result_s", + "value": "result[%s] = " + }, + { + "name": "SpecFormOutput", + "value": "特定格式输出" + }, + { + "name": "num1", + "value": "10" + }, + { + "name": "num2", + "value": "20" + }, + { + "name": "num3", + "value": "100" + }, + { + "name": "num4", + "value": "-10" + }, + { + "name": "num5", + "value": "1000" + }, + { + "name": "getErrorInfo", + "value": "获取系统错误码对应的详细信息" + }, + { + "name": "StringCodec_info", + "value": "HarmonyOS 3.0,未来有迹可循!" + }, + { + "name": "read", + "value": "读取:" + }, + { + "name": "write", + "value": "写入:" + }, + { + "name": "Text_encoder", + "value": "文本编码器" + }, + { + "name": "Text_decoder", + "value": "文本译码器" + } + + ] +} \ No newline at end of file diff --git a/ETSUI/StringCodec/entry/src/main/resources/base/media/icon.png b/ETSUI/StringCodec/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ETSUI/StringCodec/entry/src/main/resources/base/media/icon.png differ diff --git a/ETSUI/StringCodec/screenshots/device/image1.png b/ETSUI/StringCodec/screenshots/device/image1.png new file mode 100644 index 0000000000000000000000000000000000000000..9633f69101f88afacd5de7f83e69add93987a312 Binary files /dev/null and b/ETSUI/StringCodec/screenshots/device/image1.png differ diff --git a/ETSUI/StringCodec/screenshots/device/image2.png b/ETSUI/StringCodec/screenshots/device/image2.png new file mode 100644 index 0000000000000000000000000000000000000000..db878e288445a7a653a690fe997687b2b1da8509 Binary files /dev/null and b/ETSUI/StringCodec/screenshots/device/image2.png differ diff --git a/ETSUI/StringCodec/settings.gradle b/ETSUI/StringCodec/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/ETSUI/StringCodec/settings.gradle @@ -0,0 +1 @@ +include ':entry'