diff --git a/common/DistributeCalc/build.gradle b/common/DistributeCalc/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..3c7d48fcaa641d9156caad6f91773a5cf92c4685 --- /dev/null +++ b/common/DistributeCalc/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' + +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.5.0' + classpath 'com.huawei.ohos:decctest:1.2.4.1' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() + } +} diff --git a/common/DistributeCalc/entry/build.gradle b/common/DistributeCalc/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..5e47037754d9c59dbd3e393dfb2f6c58e2fc729a --- /dev/null +++ b/common/DistributeCalc/entry/build.gradle @@ -0,0 +1,22 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies {} +decc { + supportType = ['html', 'xml'] +} diff --git a/common/DistributeCalc/entry/src/main/config.json b/common/DistributeCalc/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..a5509bf2330f31ba2830b827388216d499fc8c21 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/config.json @@ -0,0 +1,57 @@ +{ + "app": { + "bundleName": "com.example.distributedcalc", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.distributedcalc", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.distributedcalc.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index", + "pages/calc/calc" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/common/DistributeCalc/entry/src/main/js/default/app.js b/common/DistributeCalc/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..7ff1e139a7dcbfe5d3ffe7bff66ed6ccaca6a97a --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2020 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('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js b/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js new file mode 100644 index 0000000000000000000000000000000000000000..752fddc6b4ebb04f378d1f40f32bdeef50495873 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2020 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 prompt from '@system.prompt'; +import deviceManager from '@ohos.distributedHardware.deviceManager'; + +var SUBSCRIBE_ID = 100; + +export default class RemoteDeviceModel { + deviceList = new Array(); + callback; + deviceManager_; + + constructor() { + } + + registerDeviceListCallback(callback) { + if (typeof (this.deviceManager_) == 'undefined') { + console.log("Calc[RemoteDeviceModel] deviceManager.createDeviceManager begin"); + let self = this; + deviceManager.createDeviceManager("com.example.distributedcalc", (error, value) => { + if (error) { + console.error("Calc[RemoteDeviceModel] createDeviceManager failed."); + return; + } + self.deviceManager_ = value; + self.registerDeviceListCallback_(callback); + console.log("Calc[RemoteDeviceModel] createDeviceManager callback returned, error=" + error + " value=" + value); + }); + console.log("Calc[RemoteDeviceModel] deviceManager.createDeviceManager end"); + } else { + this.registerDeviceListCallback_(callback); + } + } + + registerDeviceListCallback_(callback) { + console.info('Calc[RemoteDeviceModel] registerDeviceListCallback'); + this.callback = callback; + if (this.deviceManager_ == undefined) { + console.error('Calc[RemoteDeviceModel] deviceManager has not initialized'); + this.callback(); + return; + } + + console.info('Calc[RemoteDeviceModel] getTrustedDeviceListSync begin'); + var list = this.deviceManager_.getTrustedDeviceListSync(); + console.info('Calc[RemoteDeviceModel] getTrustedDeviceListSync end, deviceList=' + JSON.stringify(list)); + if (typeof (list) != 'undefined' && typeof (list.length) != 'undefined') { + this.deviceList = list; + } + this.callback(); + console.info('Calc[RemoteDeviceModel] callback finished'); + + let self = this; + this.deviceManager_.on('deviceStateChange', (data) => { + console.info('Calc[RemoteDeviceModel] deviceStateChange data=' + JSON.stringify(data)); + switch (data.action) { + case 0: + self.deviceList[self.deviceList.length] = data.device; + console.info('Calc[RemoteDeviceModel] online, updated device list=' + JSON.stringify(self.deviceList)); + self.callback(); + break; + case 2: + if (self.deviceList.length > 0) { + for (var i = 0; i < self.deviceList.length; i++) { + if (self.deviceList[i].deviceId == data.device.deviceId) { + self.deviceList[i] = data.device; + break; + } + } + } + console.info('Calc[RemoteDeviceModel] change, updated device list=' + JSON.stringify(self.deviceList)); + self.callback(); + break; + case 1: + if (self.deviceList.length > 0) { + var list = new Array(); + for (var i = 0; i < self.deviceList.length; i++) { + if (self.deviceList[i].deviceId != data.device.deviceId) { + list[i] = data.device; + } + } + self.deviceList = list; + } + console.info('Calc[RemoteDeviceModel] offline, updated device list=' + JSON.stringify(data.device)); + self.callback(); + break; + default: + break; + } + }); + this.deviceManager_.on('deviceFound', (data) => { + console.info('Calc[RemoteDeviceModel] deviceFound data=' + JSON.stringify(data)); + prompt.showToast({ + message: 'deviceFound device=' + JSON.stringify(data.device), + duration: 3000, + }); + console.info('Calc[RemoteDeviceModel] deviceFound self.deviceList=' + self.deviceList); + console.info('Calc[RemoteDeviceModel] deviceFound self.deviceList.length=' + self.deviceList.length); + console.info('Calc[RemoteDeviceModel] authenticateDevice ' + JSON.stringify(data.device)); + self.deviceManager_.authenticateDevice(data.device); + var list = self.deviceManager_.getTrustedDeviceListSync(); + console.info('Calc[RemoteDeviceModel] getTrustedDeviceListSync end, deviceList=' + JSON.stringify(list)); + if (typeof (list) != 'undefined' && typeof (list.length) != 'undefined') { + self.deviceList = list; + } + }); + this.deviceManager_.on('discoverFail', (data) => { + prompt.showToast({ + message: 'discoverFail reason=' + data.reason, + duration: 3000, + }); + console.info('Calc[RemoteDeviceModel] discoverFail data=' + JSON.stringify(data)); + }); + this.deviceManager_.on('authResult', (data) => { + prompt.showToast({ + message: 'authResult data=' + JSON.stringify(data), + duration: 3000, + }); + console.info('Calc[RemoteDeviceModel] authResult data=' + JSON.stringify(data)); + }); + this.deviceManager_.on('serviceDie', () => { + prompt.showToast({ + message: 'serviceDie', + duration: 3000, + }); + console.error('Calc[RemoteDeviceModel] serviceDie'); + }); + + SUBSCRIBE_ID = Math.floor(65536 * Math.random()); + var info = { + subscribeId: SUBSCRIBE_ID, + mode: 0xAA, + medium: 2, + freq: 2, + isSameAccount: false, + isWakeRemote: true, + capability: 0 + }; + console.info('Calc[RemoteDeviceModel] startDeviceDiscover ' + SUBSCRIBE_ID); + this.deviceManager_.startDeviceDiscover(info); + } + + unregisterDeviceListCallback() { + console.info('Calc[RemoteDeviceModel] stopDeviceDiscover ' + SUBSCRIBE_ID); + this.deviceManager_.stopDeviceDiscover(SUBSCRIBE_ID); + this.deviceManager_.off('deviceStateChange'); + this.deviceManager_.off('deviceFound'); + this.deviceManager_.off('discoverFail'); + this.deviceManager_.off('authResult'); + this.deviceManager_.off('serviceDie'); + this.deviceList = new Array(); + } +} \ No newline at end of file diff --git a/common/DistributeCalc/entry/src/main/js/default/common/calculator.js b/common/DistributeCalc/entry/src/main/js/default/common/calculator.js new file mode 100644 index 0000000000000000000000000000000000000000..7d5b85b6b8e0a8dd3c959a1e29d248e17f69b6a9 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/common/calculator.js @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2020 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. + */ +const OperatorLevels = { + "+": 0, + "-": 0, + "*": 1, + "/": 1, +}; + +const OperatorHandlers = { + "+": (one, other) => one + other, + "-": (one, other) => one - other, + "*": (one, other) => one * other, + "/": (one, other) => one / other, +}; + +function calcSuffixExpression(expression) { + const numberStack = []; + + while (expression.length) { + const element = expression.shift(); + if (!isOperator(element)) { + numberStack.push(Number(element)); + } else { + const one = numberStack.pop(); + const other = numberStack.pop(); + const result = OperatorHandlers[element](other, one); + numberStack.push(result); + } + } + return numberStack[0]; +} + +function toSuffixExpression(expression) { + const operatorStack = []; + const suffixExpression = []; + let topOperator; + for (let idx = 0, size = expression.length; idx < size; idx++) { + const element = expression[idx]; + if (element === "(") { + operatorStack.push(element); + continue; + } + if (element === ")") { + if (operatorStack.length) { + let operator = operatorStack.pop(); + while (operator !== "(") { + suffixExpression.push(operator); + operator = operatorStack.pop(); + } + } + continue; + } + if (isOperator(element)) { + if (!operatorStack.length) { + operatorStack.push(element); + } else { + topOperator = operatorStack[operatorStack.length - 1]; + if (!isGrouping(topOperator) && !isPrioritized(element, topOperator)) { + suffixExpression.push(operatorStack.pop()); + } + operatorStack.push(element); + } + continue; + } + suffixExpression.push(element); + } + while (operatorStack.length) { + suffixExpression.push(operatorStack.pop()); + } + return suffixExpression; +} + +function parseInfixExpression(content) { + const size = content.length; + const lastIdx = size - 1; + let number = ""; + const expression = []; + for (let idx = 0; idx < size; idx++) { + const element = content[idx]; + if (isGrouping(element)) { + if (number !== "") { + expression.push(number); + number = ""; + } + expression.push(element); + } else if (isOperator(element)) { + if (isSymbol(element) && (idx === 0 || content[idx - 1] === "(")) { + number += element; + } else { + if (number !== "") { + expression.push(number); + number = ""; + } + + if (idx !== lastIdx) { + expression.push(element); + } + } + } else { + number += element; + } + + if (idx === lastIdx && number !== "") { + expression.push(number); + } + } + return expression; +} + +function isPrioritized(one, other) { + return OperatorLevels[one] > OperatorLevels[other]; +} + +export function isOperator(operator) { + return ( + operator === "+" || operator === "-" || operator === "*" || operator === "/" + ); +} + +function isSymbol(symbol) { + return symbol === "+" || symbol === "-"; +} + +function isGrouping(operator) { + return operator === "(" || operator === ")"; +} + +export function calc(content) { + const infixExpression = parseInfixExpression(content); + const suffixExpression = toSuffixExpression(infixExpression); + return calcSuffixExpression(suffixExpression); +} diff --git a/common/DistributeCalc/entry/src/main/js/default/common/ic_back.png b/common/DistributeCalc/entry/src/main/js/default/common/ic_back.png new file mode 100644 index 0000000000000000000000000000000000000000..4a269a11a6eca005d2eabb957992297446c858db Binary files /dev/null and b/common/DistributeCalc/entry/src/main/js/default/common/ic_back.png differ diff --git a/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_delete.png b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_delete.png new file mode 100644 index 0000000000000000000000000000000000000000..9932ba4fbf7f37556ca1df1a69a243ac1f2adcab Binary files /dev/null and b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_delete.png differ diff --git a/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_devide.png b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_devide.png new file mode 100644 index 0000000000000000000000000000000000000000..2bfc1ba7e3494166d13eb9c29ac4d2c009dbcf38 Binary files /dev/null and b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_devide.png differ diff --git a/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_equal.png b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_equal.png new file mode 100644 index 0000000000000000000000000000000000000000..b212e9da2d02da969cbcbaf70fe9f649691e9e57 Binary files /dev/null and b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_equal.png differ diff --git a/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_minus.png b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_minus.png new file mode 100644 index 0000000000000000000000000000000000000000..48c329a81b63b212e09dcee1d95605f72f5e9a6b Binary files /dev/null and b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_minus.png differ diff --git a/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_multiply.png b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_multiply.png new file mode 100644 index 0000000000000000000000000000000000000000..e6e075df08511bfa3a95f3d358bb71d0ccb87019 Binary files /dev/null and b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_multiply.png differ diff --git a/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_plus.png b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_plus.png new file mode 100644 index 0000000000000000000000000000000000000000..d43f0db5187673b2e5602fe7d914a30caf94ffcd Binary files /dev/null and b/common/DistributeCalc/entry/src/main/js/default/common/ic_cal_plus.png differ diff --git a/common/DistributeCalc/entry/src/main/js/default/common/ic_hop_normal.png b/common/DistributeCalc/entry/src/main/js/default/common/ic_hop_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..435ec58bbde7bc034fe558dc890af0b653ae2e2f Binary files /dev/null and b/common/DistributeCalc/entry/src/main/js/default/common/ic_hop_normal.png differ diff --git a/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.css b/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.css new file mode 100644 index 0000000000000000000000000000000000000000..63df567ac19c06350d2dce206cc21ff988310c3d --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.css @@ -0,0 +1,170 @@ +/* + * 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. + */ +.calc-container { + height: 100%; + width: 100%; + flex-direction: column; +} + +.calc-icon { + width: 36px; + height: 36px; +} + +.calc-titlebar { + width: 100%; + height: 10%; +} + +.calc-back-btn { + left: 39px; + top: 10px; +} + +.calc-title { + left: 96px; + font-size: 30px; + top: 10px; +} + +.calc-expr, .calc-rsl { + padding: 0 3%; +} + +.calc-expr { + font-size: 72px; + color: #000000; + width: 100%; + height: 10%; +} + +.calc-rsl { + color: #999; + font-size: 38px; + width: 100%; + height: 8%; +} + +.input-area { + width: 100%; + height: 65%; + margin-top: 25%; +} + +.calc-text-btn, .calc-op-btn, .calc-equals-btn { + border-radius: 16px; + height: 106px; + width: 18%; + font-size: 38px; +} + +.calc-text-btn { + background-color: #f2f2f2; + color: #000000; +} + +.calc-text-btn:active { + background-color: rgb(72, 72, 72); +} + +.calc-op-btn { + background-color: #4D3F97E9; + color: #FF3F97E9; +} + +.calc-op-btn:active { + background-color: rgb(54, 76, 97); +} + +.calc-equals-btn { + background-color: #FF006CDE; + color: #fff; +} + +.calc-equals-btn:active { + background-color: rgb(38, 129, 226); +} + +.calc-btn-row-1 { + top: 112px; +} + +.calc-btn-row-2 { + top: 226px; +} + +.calc-btn-row-3 { + top: 340px; +} + +.calc-btn-row-4 { + top: 454px; +} + +.calc-btn-col-1 { + left: 3%; +} + +.calc-btn-col-2 { + left: 22%; +} + +.calc-btn-col-3 { + left: 41%; +} + +.calc-btn-col-4 { + left: 60%; +} + +.calc-btn-col-5 { + left: 79%; +} + +.calc-btn-row-span-2 { + width: 37%; +} + +.calc-btn-col-span-2 { + height: 220px; +} + +.calc-icon-row-1 { + top: 152px; +} + +.calc-icon-row-2 { + top: 266px; +} + +.calc-icon-row-3 { + top: 380px; +} + +.calc-icon-row-4 { + top: 484px; +} + +.calc-icon-col-1 { + left: 69%; + transform: translateX(-50%); +} + +.calc-icon-col-2 { + left: 88%; + transform: translateX(-50%); +} + + diff --git a/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.hml b/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.hml new file mode 100644 index 0000000000000000000000000000000000000000..f4aeed30226a8770634078e866ecb5d0acb04a32 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.hml @@ -0,0 +1,54 @@ + + +