diff --git a/Util/eTSUtilTypeCheck/README_zh.md b/Util/eTSUtilTypeCheck/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..c198958c8dd9055487299739e71152dac82bc633 --- /dev/null +++ b/Util/eTSUtilTypeCheck/README_zh.md @@ -0,0 +1,15 @@ +# util工具函数-类型校验 + +## 简介 + +本示例通过对给定值进行校验,判断是否符合Type类型,并输出校验结果。 + +### 使用说明 + +1.点击显示预置值按钮,将会显示预置值。 + +2.点击校验预置值按钮,将会对预置值进行校验,并输出校验结果。 + +### 约束与限制 + +本示例仅支持在标准系统上运行。 \ No newline at end of file diff --git a/Util/eTSUtilTypeCheck/build.gradle b/Util/eTSUtilTypeCheck/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..f350f30a90f962897ebab2c31e5bbf3e4868a578 --- /dev/null +++ b/Util/eTSUtilTypeCheck/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/Util/eTSUtilTypeCheck/entry/build.gradle b/Util/eTSUtilTypeCheck/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..cef7b37de8f320938458ca42edde1462669836d2 --- /dev/null +++ b/Util/eTSUtilTypeCheck/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 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/Util/eTSUtilTypeCheck/entry/src/main/config.json b/Util/eTSUtilTypeCheck/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..8d3b68879ed1cd534293a60f0a918410439dc8a8 --- /dev/null +++ b/Util/eTSUtilTypeCheck/entry/src/main/config.json @@ -0,0 +1,67 @@ +{ + "app": { + "bundleName": "com.samples.etsutiltypecheck", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.samples.etsutiltypecheck", + "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/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/app.ets b/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf28e58b36cf11db491d3f00768ef2c9e41d05cf --- /dev/null +++ b/Util/eTSUtilTypeCheck/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/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/common/checkType.ets b/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/common/checkType.ets new file mode 100644 index 0000000000000000000000000000000000000000..150e7267b64db2dffff4e84c0b25ba7a60b28c74 --- /dev/null +++ b/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/common/checkType.ets @@ -0,0 +1,88 @@ +/* + * 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' + +@Component +export struct CheckType { + @State result: string = ' ' + @Link checkResult: string + @Link presetValue: Array + +/* + * Determine the type of check value.The key in the map is the result of + * judging the type, and the value in the map is the method of judging the type. + * + * @param The value to check. + * @return Returns the check value type. + */ + check(value) { + let utilType = new util.Types() + let map = new Map() + map.set('ArrayBuffer', utilType.isAnyArrayBuffer(value)) + map.set('Arguments', utilType.isArgumentsObject(value)) + map.set('AsyncFunction', utilType.isAsyncFunction(value)) + map.set('Boolean', utilType.isBooleanObject(value)) + map.set('DataView', utilType.isDataView(value)) + map.set('External', utilType.isExternal(value)) + map.set('Float32Array', utilType.isFloat32Array(value)) + map.set('generator', utilType.isGeneratorFunction(value)) + map.set('Int8Array', utilType.isInt8Array(value)) + map.set('Map', utilType.isMap(value)) + map.set('Error', utilType.isNativeError(value)) + map.set('Number', utilType.isNumberObject(value)) + map.set('Promise', utilType.isPromise(value)) + map.set('RegExp', utilType.isRegExp(value)) + map.set('Set', utilType.isSet(value)) + map.set('String', utilType.isStringObject(value)) + map.set('Symbol', utilType.isSymbolObject(value)) + map.set('WeakMap', utilType.isWeakMap(value)) + map.set('Uint8Array', utilType.isUint8Array(value)) + map.set('WeakSet', utilType.isWeakSet(value)) + for (let [key, value] of map) { + if (value == true) { + this.result = key + break + } + } + return this.result + } + + show() { + let showResult: string = '' + for (let i = 0; i < this.presetValue.length; i++) { + let typeResult = this.check(this.presetValue[i]) + showResult = showResult + `${this.presetValue[i]} check success,this value type is ${typeResult}\n` + } + this.checkResult = showResult + } + + build() { + Button() { + Text($r("app.string.check")) + .fontColor(Color.Black) + .fontSize(20) + .textAlign(TextAlign.Center) + .width('85%') + } + .type(ButtonType.Capsule) + .backgroundColor('#0D9FFB') + .padding(5) + .margin({ top: 10 }) + .onClick(() => { + this.show() + }) + } +} \ No newline at end of file diff --git a/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/common/showKey.ets b/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/common/showKey.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ea74359028dbe1ba347838ba027ed0e1b19d061 --- /dev/null +++ b/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/common/showKey.ets @@ -0,0 +1,41 @@ +/* + * 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. + */ + +@Component +export struct ShowKey { + @State result: string = ' ' + @Link checkResult: string + @Link presetValue: Array + + build() { + Button() { + Text($r("app.string.show")) + .fontColor(Color.Black) + .fontSize(20) + .textAlign(TextAlign.Center) + .width('85%') + } + .type(ButtonType.Capsule) + .backgroundColor('#0D9FFB') + .padding(5) + .margin({ top: 10 }) + .onClick(() => { + this.checkResult = `numberVal = ${this.presetValue[0]}\n` + +`stringVal = ${this.presetValue[1]}\n` + +`booleanVal = ${this.presetValue[2]}\n` + +`int8Array = ${this.presetValue[3]}` + }) + } +} \ No newline at end of file diff --git a/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/pages/index.ets b/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..71481139c054b320869516fe737360119a72bff6 --- /dev/null +++ b/Util/eTSUtilTypeCheck/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,65 @@ +/* + * 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 { ShowKey } from '../common/showKey.ets' +import { CheckType } from '../common/checkType.ets' + +let int8Array = new Int8Array(new ArrayBuffer(8)) +let numVal = new Number(55) +let strVal = new String('sdsddadas') +let boolVal = new Boolean(true) +for (let i = 0; i < int8Array.length; i++) { + int8Array[i] = i +} + +@Entry +@Component +struct Index { + @State checkResult: string = ' ' + @State presetValue: Array = [numVal, strVal, boolVal, int8Array] + + build() { + Flex() { + Column() { + Text($r('app.string.entry_MainAbility')) + .textAlign(TextAlign.Center) + .width('100%') + .height('6%') + .backgroundColor('#0D9FFB') + .fontSize(20) + .fontColor(Color.Black) + + Scroll() { + Column() { + Text(this.checkResult) + .width('90%') + .height('65%') + .fontSize(20) + .margin(20) + .padding({ left: 5, right: 5 }) + .border({ width: 2, radius: 15, color: Color.Gray }) + } + } + + Column() { + ShowKey({ presetValue: $presetValue, checkResult: $checkResult }) + CheckType({ presetValue: $presetValue, checkResult: $checkResult }) + } + } + } + .width('100%') + .height('100%') + } +} diff --git a/Util/eTSUtilTypeCheck/entry/src/main/resources/base/element/string.json b/Util/eTSUtilTypeCheck/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8ea33e15421faffa3e854f4475580129ff43a39e --- /dev/null +++ b/Util/eTSUtilTypeCheck/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSUtilTypeCheck" + }, + { + "name": "description_mainability", + "value": "eTS_Empty Ability" + }, + { + "name": "text", + "value": "confirm" + }, + { + "name": "show", + "value": "Display preset value" + }, + { + "name": "check", + "value": "Check preset value" + } + ] +} \ No newline at end of file diff --git a/Util/eTSUtilTypeCheck/entry/src/main/resources/base/media/icon.png b/Util/eTSUtilTypeCheck/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/Util/eTSUtilTypeCheck/entry/src/main/resources/base/media/icon.png differ diff --git a/Util/eTSUtilTypeCheck/entry/src/main/resources/en/element/string.json b/Util/eTSUtilTypeCheck/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8ea33e15421faffa3e854f4475580129ff43a39e --- /dev/null +++ b/Util/eTSUtilTypeCheck/entry/src/main/resources/en/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSUtilTypeCheck" + }, + { + "name": "description_mainability", + "value": "eTS_Empty Ability" + }, + { + "name": "text", + "value": "confirm" + }, + { + "name": "show", + "value": "Display preset value" + }, + { + "name": "check", + "value": "Check preset value" + } + ] +} \ No newline at end of file diff --git a/Util/eTSUtilTypeCheck/entry/src/main/resources/zh/element/string.json b/Util/eTSUtilTypeCheck/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..354dbcfd64c2988c245f35f9efd2122f8b5908e9 --- /dev/null +++ b/Util/eTSUtilTypeCheck/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "util工具函数-内置对象类型检查" + }, + { + "name": "description_mainability", + "value": "eTS_Empty Ability" + }, + { + "name": "text", + "value": "确认" + }, + { + "name": "show", + "value": "显示预置值" + }, + { + "name": "check", + "value": "校验预置值" + } + ] +} \ No newline at end of file diff --git a/Util/eTSUtilTypeCheck/screenhots/devices/main.png b/Util/eTSUtilTypeCheck/screenhots/devices/main.png new file mode 100644 index 0000000000000000000000000000000000000000..9540a2a5d5e7a3592a0ab03178bee1fbae2cf01f Binary files /dev/null and b/Util/eTSUtilTypeCheck/screenhots/devices/main.png differ diff --git a/Util/eTSUtilTypeCheck/settings.gradle b/Util/eTSUtilTypeCheck/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/Util/eTSUtilTypeCheck/settings.gradle @@ -0,0 +1 @@ +include ':entry'