diff --git a/JSCleanCalculator/README.md b/JSCleanCalculator/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8fd2d13d99a1edefd7640450d4d76dc82e09c167 --- /dev/null +++ b/JSCleanCalculator/README.md @@ -0,0 +1 @@ +# JSCleanCalculatorBeta diff --git a/JSCleanCalculator/build.gradle b/JSCleanCalculator/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..19fd4e71e7050e25a3169376f72cf3c810dadf92 --- /dev/null +++ b/JSCleanCalculator/build.gradle @@ -0,0 +1,37 @@ +// 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 6 + defaultConfig { + compatibleSdkVersion 6 + } +} + +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.3-RC' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/JSCleanCalculator/entry/.gitignore b/JSCleanCalculator/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..796b96d1c402326528b4ba3c12ee9d92d0e212e9 --- /dev/null +++ b/JSCleanCalculator/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/JSCleanCalculator/entry/build.gradle b/JSCleanCalculator/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..0c41d1ed0625f1808130ea36646467d8ddf49145 --- /dev/null +++ b/JSCleanCalculator/entry/build.gradle @@ -0,0 +1,17 @@ +apply plugin: 'com.huawei.ohos.hap' +ohos { + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 6 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + + supportSystem "standard" +} diff --git a/JSCleanCalculator/entry/package.json b/JSCleanCalculator/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..0967ef424bce6791893e9a57bb952f80fd536e93 --- /dev/null +++ b/JSCleanCalculator/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/JSCleanCalculator/entry/proguard-rules.pro b/JSCleanCalculator/entry/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/JSCleanCalculator/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/main/config.json b/JSCleanCalculator/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..979298495b60e35aea0950915f570ed22be7f6dd --- /dev/null +++ b/JSCleanCalculator/entry/src/main/config.json @@ -0,0 +1,57 @@ +{ + "app": { + "bundleName": "com.huawei.cookbook", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.cleancalculatorbeta", + "name": ".MyApplication", + "mainAbility": "com.example.cleancalculatorbeta.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.cleancalculatorbeta.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } +} \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/main/java/com/example/cleancalculatorbeta/MainAbility.java b/JSCleanCalculator/entry/src/main/java/com/example/cleancalculatorbeta/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..e62ea8da6c74db48f189f2b87eab761954a4629a --- /dev/null +++ b/JSCleanCalculator/entry/src/main/java/com/example/cleancalculatorbeta/MainAbility.java @@ -0,0 +1,16 @@ +package com.example.cleancalculatorbeta; + +import ohos.ace.ability.AceAbility; +import ohos.aafwk.content.Intent; + +public class MainAbility extends AceAbility { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + } + + @Override + public void onStop() { + super.onStop(); + } +} diff --git a/JSCleanCalculator/entry/src/main/java/com/example/cleancalculatorbeta/MyApplication.java b/JSCleanCalculator/entry/src/main/java/com/example/cleancalculatorbeta/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..47bac3babec4c80fa224371dee082e582d8dbea4 --- /dev/null +++ b/JSCleanCalculator/entry/src/main/java/com/example/cleancalculatorbeta/MyApplication.java @@ -0,0 +1,10 @@ +package com.example.cleancalculatorbeta; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/JSCleanCalculator/entry/src/main/js/default/app.js b/JSCleanCalculator/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..aedcefe0054c6e16c40491f4d1abc20a4dc1c6ef --- /dev/null +++ b/JSCleanCalculator/entry/src/main/js/default/app.js @@ -0,0 +1,8 @@ +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/JSCleanCalculator/entry/src/main/js/default/common/images/Wallpaper.png b/JSCleanCalculator/entry/src/main/js/default/common/images/Wallpaper.png new file mode 100644 index 0000000000000000000000000000000000000000..60d4841a80eb20c63de74306cb7f8350d6a85c48 Binary files /dev/null and b/JSCleanCalculator/entry/src/main/js/default/common/images/Wallpaper.png differ diff --git a/JSCleanCalculator/entry/src/main/js/default/common/images/bg-tv.jpg b/JSCleanCalculator/entry/src/main/js/default/common/images/bg-tv.jpg new file mode 100644 index 0000000000000000000000000000000000000000..86fc07358eea5c1474bc833fca07c6d4d8698a89 Binary files /dev/null and b/JSCleanCalculator/entry/src/main/js/default/common/images/bg-tv.jpg differ diff --git a/JSCleanCalculator/entry/src/main/js/default/common/utils/utils.js b/JSCleanCalculator/entry/src/main/js/default/common/utils/utils.js new file mode 100644 index 0000000000000000000000000000000000000000..3f4694b63b1eeb56731a7251b9fd4476fc2fd669 --- /dev/null +++ b/JSCleanCalculator/entry/src/main/js/default/common/utils/utils.js @@ -0,0 +1,67 @@ +/** +* 加法 +* 计算方式:1.先将所有的小数乘为整数; + 2.待加减运算执行完之后再除去对应的 m 的值,将其变为小数输出; +* */ +function accAdd(arg1, arg2) { + let r1, r2; + try { + r1 = arg1.toString().split('.')[1].length; + } catch (e) { + r1 = 0; + } + try { + r2 = arg2.toString().split('.')[1].length; + } catch (e) { + r2 = 0; + } + const m = Math.pow(10, Math.max(r1, r2)); + return (arg1 * m + arg2 * m) / m; +} + +/** +* 减法 +**/ +function accSub(arg1, arg2) { + return accAdd(arg1, -arg2); +} +/** +* 乘法 +* */ +function accMul(arg1, arg2) { + let m = 0; const s1 = arg1.toString(); const s2 = arg2.toString(); + try { + m += s1.split('.')[1].length; + } catch (e) { + m += 0; + } + try { + m += s2.split('.')[1].length; + } catch (e) { + m += 0; + } + return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m); +} + +/** +* 除法 +* */ +function accDiv(arg1, arg2) { + let t1 = 0; let t2 = 0; + try { + t1 = arg1.toString().split('.')[1].length; + } catch (e) { + t1 = 0; + } + try { + t2 = arg2.toString().split('.')[1].length; + } catch (e) { + t2 = 0; + } + const r1 = Number(arg1.toString().replace('.', '')); + const r2 = Number(arg2.toString().replace('.', '')); + return r1 / r2 * Math.pow(10, t2 - t1); +} + +export {accAdd, accSub, accMul, accDiv}; + diff --git a/JSCleanCalculator/entry/src/main/js/default/i18n/en-US.json b/JSCleanCalculator/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/JSCleanCalculator/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/main/js/default/i18n/zh-CN.json b/JSCleanCalculator/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/JSCleanCalculator/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/main/js/default/pages/index/index.css b/JSCleanCalculator/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..721d71220de65b5a48f3427dc67af7dcf0d08762 --- /dev/null +++ b/JSCleanCalculator/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,73 @@ +.container { + width: 100%; + display: flex; + flex-direction: column; + background-color: #000000; + position: relative; +} +.result_container { + flex-grow:1; + display: flex; + align-items: flex-end; + position: absolute; +} +.result_console{ + width: 100%; + padding: 0 8px; + height: 40%; + text-align: right; + color: #FFFFFF; + font-size: 40px; +} +.calculate_keyboard_container { + width: 100%; + display: flex; + flex-direction: row; + padding: 0 8px; + flex-wrap: wrap; + position: absolute; + bottom: 1%; +} +.calculate_keyboard_horizontal { + width: 100%; + display: flex; +} +.calculate_keyboard{ + align-items: center; + justify-content: center; +} +.calculate_keyboard_text{ + width: 25%; + aspect-ratio:1; + border: .2px solid #000; + font-size: 20px; + font-weight: bold; + color: #FFFFFF; + text-align: center; +} +.calculate_keyboard_text_special{ + width: 50%; + aspect-ratio: 2; +} + +.blackText{ + color: #000000; +} +.whiteText{ + color: #FFFFFF; +} +.orangeBg{ + background-color: #FFF67105; +} +.orangeBg:hover{ + opacity: .5; +} +.blackBg { + background-color: #dd322e2e; +} +.blackBg:hover { + background-color: #666666; +} +.greyBg { + background-color: #cccccc; +} diff --git a/JSCleanCalculator/entry/src/main/js/default/pages/index/index.hml b/JSCleanCalculator/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f55e096ebfa900696c3f120cbc061fa35286b619 --- /dev/null +++ b/JSCleanCalculator/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,46 @@ +
+
+ {{CalDisplay}} +
+
+
+
+ AC + ÷ + % + CE +
+
+
+
+ 7 + 8 + 9 + × +
+
+
+
+ 4 + 5 + 6 + - +
+
+
+
+ 1 + 2 + 3 + + +
+
+
+
+ 0 + . + = +
+
+
+
diff --git a/JSCleanCalculator/entry/src/main/js/default/pages/index/index.js b/JSCleanCalculator/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..557c38c8af5ca494e668eacd29411639f91d70be --- /dev/null +++ b/JSCleanCalculator/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,183 @@ +import * as cal from '../../common/utils/utils.js' +export default { + data: { + CalDisplay: '0', + pseudoStack: [], + isResult: false, + maxSize: 14 + }, + onInit() { + }, + touchstartfunc(touches) { + const currentVal = touches.currentTarget.attr.value; + switch (currentVal) { + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '0': + this.numberhandle(currentVal); + break; + case '+': + case '÷': + case '%': + case '×': + case '-': + this.calculatehandle(currentVal); + break; + case '.': + this.pointhandle(currentVal); + break; + case 'AC': + case 'CE': + this.deletehandle(currentVal); + break; + case '=': + this.resulthandle(); + break; + } + }, + numberhandle(param) { + if (this.CalDisplay === '错误') { + this.dataInit() + } + if (param === '0' && this.CalDisplay === '0') return + const temp = this.pseudoStack.pop(); + if (this.isResult) { + this.CalDisplay = param; + this.pseudoStack.push(this.CalDisplay); + this.isResult = false; + } else { + if (temp && this.isOperator(temp)) { + this.pseudoStack.push(temp); + this.CalDisplay = param; + this.pseudoStack.push(this.CalDisplay); + } else { + if (this.CalDisplay.length > this.maxSize){ + this.pseudoStack.push(temp); + return + } + this.CalDisplay = this.CalDisplay === '0' ? param : this.CalDisplay + param; + this.pseudoStack.push(this.CalDisplay); + } + } + }, + calculatehandle(param) { + if (this.CalDisplay === '错误') return + const temp = this.pseudoStack.pop(); + if (temp && this.isOperator(temp)) { + this.pseudoStack.push(param); + } else { + this.pseudoStack.push(temp); + this.pseudoStack.push(param); + } + this.isResult = false; + }, + pointhandle(param) { + if (this.CalDisplay === '错误') { + this.dataInit() + } + if (this.isResult) { + this.CalDisplay = '0' + param; + this.pseudoStack.push(this.CalDisplay); + this.isResult = false; + return; + } + if (this.pseudoStack.length === 0) { + this.CalDisplay = '0' + param; + this.pseudoStack.push(this.CalDisplay); + } else { + const temp = this.pseudoStack.pop(); + if (temp && this.isOperator(temp)) { + this.pseudoStack.push(temp); + this.CalDisplay = '0' + param; + this.pseudoStack.push(this.CalDisplay); + } else { + if (this.CalDisplay.indexOf(param) !== -1) { + return; + } + this.CalDisplay = this.CalDisplay === '0' ? '0' + param : this.CalDisplay + param; + this.pseudoStack.push(this.CalDisplay); + } + } + }, + deletehandle(param) { + if (this.isResult || this.CalDisplay === '错误') { + this.dataInit(); + } + if (param === 'AC') { + this.dataInit(); + } else { + if (this.pseudoStack.length === 0) { + return; + } + const temp = this.pseudoStack.pop(); + if (temp && this.isOperator(temp)) { + return; + } + const result = temp.substring(0, temp.length - 1); + if (result.length === 0) { + this.CalDisplay = '0'; + return; + } + this.CalDisplay = result; + this.pseudoStack.push(result); + } + }, + resulthandle() { + if (this.CalDisplay === '错误') return + const pseudoStackLength = this.pseudoStack.length; + if (pseudoStackLength < 3) { + return; + } + const secondParameter = Number(this.pseudoStack.pop()); + const operator = this.pseudoStack.pop(); + const firstParameter = Number(this.pseudoStack.pop()); + let result; + switch (operator) { + case '+': + result = cal.accAdd(firstParameter, secondParameter); + break; + case '÷': + result = cal.accDiv(firstParameter, secondParameter); + break; + case '%': + result = firstParameter % secondParameter; + break; + case '×': + result = cal.accMul(firstParameter, secondParameter); + break; + case '-': + result = cal.accSub(firstParameter, secondParameter); + break; + } + if (Math.abs(result) === Infinity || isNaN(result)) { + result = '错误' + } + if (result.toString().length > 14) { + result = Number(result).toExponential([6]) + } + result = result.toString(); + this.CalDisplay = result; + this.pseudoStack.push(result); + this.isResult = true; + }, + isNumber(param) { + const numEnums = '1234567890'; + return numEnums.indexOf(param) !== -1; + }, + isOperator(param) { + const operator = '+÷%×-'; + return operator.indexOf(param) !== -1; + }, + dataInit() { + this.CalDisplay = '0'; + this.pseudoStack = []; + this.isResult = false; + } +}; diff --git a/JSCleanCalculator/entry/src/main/resources/base/element/string.json b/JSCleanCalculator/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b085a598a0493bffaba3b2d797f4fab4646b0076 --- /dev/null +++ b/JSCleanCalculator/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "简易计算器" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + } + ] +} \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/main/resources/base/media/icon.png b/JSCleanCalculator/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/JSCleanCalculator/entry/src/main/resources/base/media/icon.png differ diff --git a/JSCleanCalculator/entry/src/ohosTest/java/com/example/cleancalculatorbeta/ExampleOhosTest.java b/JSCleanCalculator/entry/src/ohosTest/java/com/example/cleancalculatorbeta/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f637dfee3e715ba6f2b702aea4253362c7356db7 --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/java/com/example/cleancalculatorbeta/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.example.cleancalculatorbeta; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.example.cleancalculatorbeta", actualBundleName); + } +} \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/ohosTest/js/default/app.js b/JSCleanCalculator/entry/src/ohosTest/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..55b67e96deb821033f71d30b6fff05efdeb0d901 --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/js/default/app.js @@ -0,0 +1,8 @@ +export default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/JSCleanCalculator/entry/src/ohosTest/js/default/i18n/en-US.json b/JSCleanCalculator/entry/src/ohosTest/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/js/default/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/ohosTest/js/default/i18n/zh-CN.json b/JSCleanCalculator/entry/src/ohosTest/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/js/default/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/ohosTest/js/default/pages/index/index.css b/JSCleanCalculator/entry/src/ohosTest/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/JSCleanCalculator/entry/src/ohosTest/js/default/pages/index/index.hml b/JSCleanCalculator/entry/src/ohosTest/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/JSCleanCalculator/entry/src/ohosTest/js/default/pages/index/index.js b/JSCleanCalculator/entry/src/ohosTest/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..8be2df2479a8da755ed800ad70d2b6247e21b8a2 --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/js/default/pages/index/index.js @@ -0,0 +1,41 @@ +import file from '@system.file' +import app from '@system.app' +import device from '@system.device' +import router from '@system.router' +import {Core, Constant, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + const instrumentLog = new InstrumentLog({ + 'id': 'report', + 'version': '1.0.3' + }) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.addService('report', instrumentLog) + core.init() + core.subscribeEvent('spec', instrumentLog) + core.subscribeEvent('suite', instrumentLog) + core.subscribeEvent('task', instrumentLog) + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/ohosTest/js/test/ExampleJsunit.test.js b/JSCleanCalculator/entry/src/ohosTest/js/test/ExampleJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..b6d74caed96ddede98edd1bc9292f6568cd1cfd1 --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/js/test/ExampleJsunit.test.js @@ -0,0 +1,10 @@ +import app from '@system.app' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('appInfoTest', function () { + it('app_info_test_001', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('3') + }) +}) \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/ohosTest/js/test/List.test.js b/JSCleanCalculator/entry/src/ohosTest/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..305eb5bb254cd4802afaffebe68fca2f9436159f --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/js/test/List.test.js @@ -0,0 +1 @@ +require('./ExampleJsunit.test.js') \ No newline at end of file diff --git a/JSCleanCalculator/entry/src/ohosTest/resources/base/element/string.json b/JSCleanCalculator/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ebab015692df3d2f9381f296572edb059f873c6f --- /dev/null +++ b/JSCleanCalculator/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CleanCalculatorBeta" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/JSCleanCalculator/entry/src/ohosTest/resources/base/media/icon.png b/JSCleanCalculator/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/JSCleanCalculator/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/JSCleanCalculator/gradle.properties b/JSCleanCalculator/gradle.properties new file mode 100644 index 0000000000000000000000000000000000000000..be492496f9a20ac2d980ef4fc30061f4184c1c40 --- /dev/null +++ b/JSCleanCalculator/gradle.properties @@ -0,0 +1,13 @@ +# Project-wide Gradle settings. +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# If the Chinese output is garbled, please configure the following parameter. +# This function is enabled by default when the DevEco Studio builds the hap/app,if you need disable gradle parallel,you should set org.gradle.parallel false. +# more information see https://docs.gradle.org/current/userguide/performance.html +# org.gradle.parallel=false +# org.gradle.jvmargs=-Dfile.encoding=GBK \ No newline at end of file diff --git a/JSCleanCalculator/gradle/wrapper/gradle-wrapper.jar b/JSCleanCalculator/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..490fda8577df6c95960ba7077c43220e5bb2c0d9 Binary files /dev/null and b/JSCleanCalculator/gradle/wrapper/gradle-wrapper.jar differ diff --git a/JSCleanCalculator/gradle/wrapper/gradle-wrapper.properties b/JSCleanCalculator/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000000000000000000000000000000000..f59159e865d4b59feb1b8c44b001f62fc5d58df4 --- /dev/null +++ b/JSCleanCalculator/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/JSCleanCalculator/gradlew b/JSCleanCalculator/gradlew new file mode 100644 index 0000000000000000000000000000000000000000..2fe81a7d95e4f9ad2c9b2a046707d36ceb3980b3 --- /dev/null +++ b/JSCleanCalculator/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# 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 +# +# https://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. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/JSCleanCalculator/gradlew.bat b/JSCleanCalculator/gradlew.bat new file mode 100644 index 0000000000000000000000000000000000000000..62bd9b9ccefea2b65ae41e5d9a545e2021b90a1d --- /dev/null +++ b/JSCleanCalculator/gradlew.bat @@ -0,0 +1,103 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/JSCleanCalculator/settings.gradle b/JSCleanCalculator/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/JSCleanCalculator/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f56f485ee9de5eb9f73adf90b836449c4f96bba5 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# OpenHarmony Codelabs + +该Codelabs旨在向开发人员展示如何通过趣味场景来展示如何使用OpenHarmony能力的示例应用程序文档教程。 + +注意:IDE版本及配套SDK问题可前往https://developer.harmonyos.com/cn/develop/deveco-studio#download 查看配套的IDE、鸿蒙SDK、插件及Gradle版本。 \ No newline at end of file