From 4f62c048131d0282e57a678ec95f30a79af41d70 Mon Sep 17 00:00:00 2001 From: qhily999 Date: Thu, 29 Jul 2021 15:27:50 +0800 Subject: [PATCH 1/6] add distribute Calc --- common/DistributeCalc/build.gradle | 48 +++ common/DistributeCalc/entry/build.gradle | 26 ++ .../DistributeCalc/entry/src/main/config.json | 57 ++++ .../example/distributedcalc/MainAbility.java | 16 + .../distributedcalc/MyApplication.java | 10 + .../entry/src/main/js/default/app.js | 8 + .../js/default/common/RemoteDeviceModel.js | 158 ++++++++++ .../src/main/js/default/common/calculator.js | 145 +++++++++ .../src/main/js/default/common/ic_back.png | Bin 0 -> 1274 bytes .../main/js/default/common/ic_cal_delete.png | Bin 0 -> 1881 bytes .../main/js/default/common/ic_cal_devide.png | Bin 0 -> 1115 bytes .../main/js/default/common/ic_cal_equal.png | Bin 0 -> 1035 bytes .../main/js/default/common/ic_cal_minus.png | Bin 0 -> 1038 bytes .../js/default/common/ic_cal_multiply.png | Bin 0 -> 1618 bytes .../main/js/default/common/ic_cal_plus.png | Bin 0 -> 1124 bytes .../main/js/default/common/ic_hop_normal.png | Bin 0 -> 550 bytes .../entry/src/main/js/default/i18n/en-US.json | 6 + .../entry/src/main/js/default/i18n/zh-CN.json | 6 + .../src/main/js/default/pages/calc/calc.css | 170 ++++++++++ .../src/main/js/default/pages/calc/calc.hml | 54 ++++ .../src/main/js/default/pages/calc/calc.js | 196 ++++++++++++ .../src/main/js/default/pages/index/index.css | 215 +++++++++++++ .../src/main/js/default/pages/index/index.hml | 67 ++++ .../src/main/js/default/pages/index/index.js | 297 ++++++++++++++++++ .../main/resources/base/element/string.json | 12 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes common/DistributeCalc/settings.gradle | 1 + 27 files changed, 1492 insertions(+) create mode 100644 common/DistributeCalc/build.gradle create mode 100644 common/DistributeCalc/entry/build.gradle create mode 100644 common/DistributeCalc/entry/src/main/config.json create mode 100644 common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MainAbility.java create mode 100644 common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MyApplication.java create mode 100644 common/DistributeCalc/entry/src/main/js/default/app.js create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/calculator.js create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/ic_back.png create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/ic_cal_delete.png create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/ic_cal_devide.png create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/ic_cal_equal.png create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/ic_cal_minus.png create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/ic_cal_multiply.png create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/ic_cal_plus.png create mode 100644 common/DistributeCalc/entry/src/main/js/default/common/ic_hop_normal.png create mode 100644 common/DistributeCalc/entry/src/main/js/default/i18n/en-US.json create mode 100644 common/DistributeCalc/entry/src/main/js/default/i18n/zh-CN.json create mode 100644 common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.css create mode 100644 common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.hml create mode 100644 common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.js create mode 100644 common/DistributeCalc/entry/src/main/js/default/pages/index/index.css create mode 100644 common/DistributeCalc/entry/src/main/js/default/pages/index/index.hml create mode 100644 common/DistributeCalc/entry/src/main/js/default/pages/index/index.js create mode 100644 common/DistributeCalc/entry/src/main/resources/base/element/string.json create mode 100644 common/DistributeCalc/entry/src/main/resources/base/media/icon.png create mode 100644 common/DistributeCalc/settings.gradle diff --git a/common/DistributeCalc/build.gradle b/common/DistributeCalc/build.gradle new file mode 100644 index 0000000000..4017da2173 --- /dev/null +++ b/common/DistributeCalc/build.gradle @@ -0,0 +1,48 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +ohos { + signingConfigs { + release { + storeFile file('D:\\sign\\myApplication.p12') + storePassword '000000183B094E725BABC5F310F25709C494986705978CBAC9AB3457B52A0E3717E4F40E41178CCA' + keyAlias = 'my_app' + keyPassword '0000001822910DA0CE3444BB92ED34EA90022158E0D1BD27DFE784DFABEF950CE31644C31CEA20CA' + signAlg = 'SHA256withECDSA' + profile file('D:\\sign\\1111Release.p7b') + certpath file('D:\\sign\\l2.cer') + } + } + 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 0000000000..9b30d8f712 --- /dev/null +++ b/common/DistributeCalc/entry/build.gradle @@ -0,0 +1,26 @@ +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 { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +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 0000000000..a5509bf233 --- /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/java/com/example/distributedcalc/MainAbility.java b/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MainAbility.java new file mode 100644 index 0000000000..f07539ea95 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MainAbility.java @@ -0,0 +1,16 @@ +package com.example.distributedcalc; + +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/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MyApplication.java b/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MyApplication.java new file mode 100644 index 0000000000..14b4f1012a --- /dev/null +++ b/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MyApplication.java @@ -0,0 +1,10 @@ +package com.example.distributedcalc; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} 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 0000000000..394207eb54 --- /dev/null +++ b/common/DistributeCalc/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/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 0000000000..3ae88d6b54 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js @@ -0,0 +1,158 @@ +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); +// for (var i = 0; i < self.deviceList.length; i++) { +// if (self.deviceList[i].deviceId == data.device.deviceId) { +// console.info('Calc[RemoteDeviceModel] device founded, ignored'); +// return; +// } +// } + + 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 0000000000..7d5b85b6b8 --- /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 GIT binary patch literal 1274 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbBBuiW)N`mv#O3D+9QW+dm@{>{( zJaZG%Q-e|yQz{EjrrIztFl%InM3hAM`dB6B=jtVb)aX^@765fKFxc2v6eK2Rr0UTq__OB&@Hb09I0xZL0)vRD^GUf^&XRs)DJWnQpS7iGhN-rJkXg zfr+W1j)IYap}D?+slI`ku7RPIfrXWkp#l^r0c|TvNwW%aaf8|g1^l#~=$>Fbx5 zm+O@q>*W`v>l<2HTIw4Z=^Gj80#)c1SLT%@R_NvxE5l51Ni9w;$}A|!%+FH*nV6WA zUs__T1av9H3%LbwWAlok!2}F2{ffi_eM3D1ke6TzeSPsO&CP|YE-nd5MYtEM!Nnn! z1*!T$sm1xFMajU3OH&3}Rbb^@l$uzQUlfv`p92fUfQU|Iy$+UJ6X7x zTAG*{S~xm8Im7h2*VN}Bb=g6k%)h^yok!`}^Trx<|bGDVf+9ZWB;J1FWGE$&HTUuezdVeRVT z5+gZ5VA0ZKk1~O^vd)v5Up$mpB!fdqz6E=9WC8#_cnrIDwrpUXO@geCy#!nv;i literal 0 HcmV?d00001 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 GIT binary patch literal 1881 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbBBuiW)N`mv#O3D+9QW+dm@{>{( zJaZG%Q-e|yQz{EjrrIztFl%InM3hAM`dB6B=jtVb)aX^@765fK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fBMOw`c5I}eX54>i%NrC z0YOicT(g5;u3TaNDdpxJcMeO2#rr+Nq+&Xzf0bFedwW9Q*R&Te)fMaYentdkY`-sL zR?eNoV_wd5|I^;+yB0+Wo||H-#mugs{b2F#*0igugTZF3>|!i4j!L-JlE64eUW9>b1zutgiN;4a}T#{`tS}|NhH4($c)6 zthAz(Ac(R=6Q9KEM(1@c!{1ND&=6kMpm-X!8to`6T9DvmBLhJ~6FXoMigNG1hp>(y zme#1LG)fCQS;^46qT}PuX(mP!L|sG96s1mxKn8ZGdW8Ib>n;gYIYRCZ2()0vprSVQ zS+KRQIVJUVN@1C7s0Vd9787U?i6EzS={B2-ka=Df?;SHmg1igrjF2;;(n1S}85RTq zZ_pz#ej3zDk)9iZr-hh|th#QGR8`;a)ACAYIlzHv4dK1E0cA(N%3 zY&Pr7ZuJ^g2gQWLVT$%qKA#7Bc6H-ZN8{L+K8`oatgfiKf z1w~|7DZ}V0RIx=dkYOu^31Ts)Y9UY~h?1&1#?5(@Ag~GDMxrjk1Ro(Wk5^S?mWu^_ zfly;S9^`n2iF46-Z8XFO!u}u=;$qQQ0m~aww+3}oz{>O3#znEtKxih8%tK4F zZw`!eRU;RB&i%MK`C)qc{^jkuvgBiSN}_84 Ss`6LBx$cR0Gk-bS*8dl~>vQ1% literal 0 HcmV?d00001 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 GIT binary patch literal 1035 zcmaJ=O-K|`93RudB>Osu7Qu6jFlgsvb=Td|Nq1*wGlxY-jC| z1Rm_BWf^pd4$(n7SRG0V=@fLZgNGuBJ`M#^Ak;1B&APjGXd8I*-uv_a{r+FSH#5-R zTVHpmjv$EoM4y<%`%!Pz?!y0%#KHpJnoul_2F+2FlWj;uRC5G^gf5T4B$U7p9EblhY56uWZ>%KhQql$S>WaH*)!85D7c_3Pi`fZmIi=e+7JY& zpig1j8PE}?*dWs$U{3%)!*==4$s0&^eTLIgVi2LD*qVhj(*Pc$JYr5Dp2V4Mm7rT? zTEi)}2{(*(Ws7Dh#w)4hC`tc!)%CKsgOYGN-+vN2sk{a0By`LPTfu`HZSg``oM1y4 znRd!F$4gxt$e74-NB<7(sP30m&&>sjh z{#Y;~vTQ68jdesrVj$ceWJ3`lDwMFIsZ8k5KqaiYjcu!l^#q|?II;+B?GjYuwyA?c z;ha`E7p5X#5vx|tg{_FCaWb?w-oM6OGGPsQ$Fg|wr7VAFV9ncD+(RqsC;Tw-2{Dp# z-)+pl**(SV5fA6qRy(JczwMnlu=ya`Jl*hN_4n|wFn8_t{OqF}t2O(3h^m^k*FEct z#;GUqU-!OzcKG+%`|&&97at3kS6a_Dyw#5!oLySpJafxe{k6O2`Ofvln-4p$zg)P| l*mPlv*ij3nj#WLaX(WE`o4ecGdv3#fo{3n$xD-8q^$)tpPF?^2 literal 0 HcmV?d00001 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 GIT binary patch literal 1038 zcmaJ=O-K|`93N98HOW&@P&~#C3hsPt`#HGj?#!B7j>x*vUc_c+p1Xt2ylLjy&PoSS zB7!<}O6bx-Z;^FO30s1|zD^co5JT8(P-z-iF$3WUIbSOKmvV>*Hxqbs}uIeTW71{D`P9i#V>%F1IvL^cFLCgfB3 z00+WRh7WOpAm0c493N)6Aj^e(94~MY!Ow&0N0Vr_HYKE`p=vC0i_ry)ErDf=#UfKY z#UMM+^3iCN<@~JQ?;{>Qr(|Nq^_fn0jX{ErYU>u(kqJCTC5L8lj3$}xm0(zPTGOev zi8PFL6^rE=&MT?rD9itMHH^BqgVS(7-+vN2nUV$BG<49ct&+h_b$g*KLA0TQk)1(k zrq;!=0>a2CAPb11*R=@fkrh=pJ!5YLCCfs}bg*KoFeSxk!o%pgCd9>%KN#gg$xvM4 z`D8qi3@0K|Fd7K)k+_%;Ygh@Xvj#MA4Xf>A!ws>XAPkE{mY}U)hT4#g3{WXt&>QCx zXvkN^YK?OVHpH?d8P*%`U*oQsh=#mlUA*K{mp?R#=4~SG^}%L=Jd7(TDV}k+zq~EC z&2xvY?kuk@bUYdu&MHk6 fAQ+tAe%||p$`76pAE<4c-V047N2U9Tiwl1MuTxQQ literal 0 HcmV?d00001 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 GIT binary patch literal 1618 zcmaJ>eM}Q~7(QT51aUaQF%Z2R%F2-56{NHs1xt&x(*lF4Y#8bFdbB5AuUrpW8bJgU z#E)2Y`2~U_>N*Nz~vFnHq%{oS0n^aDT`yx%<7pH}CVjUr%m( zVtky3o39%H03HgtEQviAJ6_k1+3$V8ZfB3rnb;I2nM!BOD2)RWEv3Oh1&QkLBplV| zWM0Q30lj}A)#*?k_D$JUJ3AIpk6c}j{u>>T}prD1^XfTN^VrZOK#M%xw41wbzOokYG zS5%5J5tLFi4u*62AsBBN0!9eAJU+54oVOGVMR*Y~5)LE$5QHZ}1fozLIPpMiHd>o5 zN|LRZ$i?2oke*?TA{aKC&0KRBm!fqrPbd_^NGKc{8p1||m~spZY6&rz0wx(`xCx^P zBSTOI(7}jms4PYdv6a4SfizCh8cY*oVh09WP$SIaB94|O1C`4E4<*T|XcLo!zpwX$ z#3oga5r>m-6O~0{?Bdb`9I1>VDUG8HMXM-kEq?1?~ zg=LYrftkc=-(#iIVjY4YjcjHaP7~R=x> zZ?NLJ;f?b`v9-uRLi9!Z(S_$de~H;u)R31?cLW-?*WK6nUMZx1I^dQ1pgAC}DZgb~ zVCgLA>F#Hz+G>~lI_6GP!^F9;mv7%>KWaWmNL(+yR(Rdjg#y07n0dKVlLS!jS4PFR zJ_*XL>Q=8$i`(b-LxoFfiCgZ@rJD=lkIwU~4O?~O*7tUB%Gx$c>5H~KaO-N{zV zD~CJ>B^^Rp^3TB1_G5PY*_t&@g&(CB%_@uPYx-PAv`sj84JS)Bf&Sn!N!m4CCS z{X|-Cf&U^q(pS6wVa6)!f~cD6;U)Du54+fW5=NcVZ()HiU42w7GtfaYsXIz<4$;Nt zy_ugO2;)7L=c{-0|6{$ncWtjzed4!Kg-^<*eid=gb1WQYWUSY=L8*Jt`D)-yW3Sog zMcFVKkXsvh=F9^5@Y5~pID7k+@AzyWbD;9m?jp~1L9K&nyCS3E>?<>iE^z#Zjum(J ze}BRHXUh|hJ*jibN2^Kqo1e@tFHK7vnRCv%+s2jG`LEvkctqG}kp&I-dnz_{mI`;L zNLy{v*}r+uI1$xCcvp7a>8>g)nBlc#%gQxm5xRQtRiV(oI5?zp(X}AdInJ-6AogVC z)r8q4WnE_vYs8y5C%t{Ds0whd?-z~O%;O~W)ll=>IoLs`k()kuD-t|45AT%Mptl3Y zFc;cA0NZNyIDXm3hyV4fmb|L@?a+qgrb9uugXInPoa^I?)uZ3-J5hx#cAZ7-3p~aj zY5TqB-j|)W+~CaDPmQEVnz{GKM#Qzg6zLdK%k_tb<$cK>ZKs>!bsSq=kKe<*=0a~$ zwNisL9CklYhxea1L*C$;10DRX3&|0Cg7;h+Y$&06?ow32wf#qS=}uLi>hV4J=$0bw k1^Qg~2cQR-uKc%d2*5dNlUJA7QyhPJMQpt6bd0*-Ut}O_W&i*H literal 0 HcmV?d00001 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 GIT binary patch literal 1124 zcmaJ=TWHfz7>?Jcds#wjO_OdbEOYBB_Hk))*2bBfn4H;ec)y`C zg)u?#0?r2!5mE3#P}qYn&I{f_eDgsc^uZ@}h*D2xTYazwPR=<$|M&g3?;P*yY@64x ztbrhid8u|OjrY~=nll^!-w|ie;;jiKv#1C5p`u~~LeO9ikSRmSgEUaI!JQKzN)R*F z>6t9b${oB44Zq_0_)CU`(F75Vmn=o?2Z+ppyl%#*&v(ZuQrBYCwvf!omIw-Z`;ZNK zhB`CqP`}D)RD2T|E%BJZ07xNA#tzfrOEGGSm&a$1&18UKBQz7DnXr#xd8UOAuw>< z(O=x?hjyN3IgX>5038VUu!qkXG?7yBnU1&0AOT0UbqndxBwa=&2M17$!kPXq!LVwy zrc-GXZWvusESmK*Zb?-~S^mGPVbr`Glm>tD{U@=L8MFYM1`ZssRXn&puN%tZMH?sx z+8GFURJ+(!fCxGTXpy4mcCCe6Co8IMy2kZWC|TxHrh^ny1t}>;VIIG(YrG%|VuTf1 zlVL$(*`$z2MiMPjhzo|<7C}siRjdTn0Rxz*iq&e^1XCC53c|2(WC_^%E}*sA&>*J@ z=k@xzNOk!tSgmd@Lb5KF#>vp`c>fxA)r2+V9&6&omzw;6i8XIyad*ybTZ13QirEYfvt{4whF2q=$16wY_np`}dU;8#r+e+; zrR6g}@{>HX?ndL$ TnV*{9y6--f?38XKdJp~rtk`t_ literal 0 HcmV?d00001 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 GIT binary patch literal 550 zcmV+>0@?kEP)k8aA77<$9WO}Ig;iM6=$Kzn(G7gZew>KvyYMjf>vA~t=}k+< z_&F!A78M`B`HcNtRDTPLb9kQ`4W~uVnqc|{%`gy}GdCE)-V(%COqPfn4$YYaZ_r(W zIH=sGp&PHWhRf1q6k#Dor4c<;BEbYMWeo>|+}{vb!vkrGCZ)d4Ya-qsS|eFwCq6W0 z4III7<%R&p@E#qFj$={fj*>!o7?P?#n&+(Jo^+GGKM?N=?j6N1t>t(XfjcXR4+ZBX zdYT3I;I4GlF|!|h7X1-3B~?C4yl5ioI4t#Yk@V}ljkn=nCOz~OQTZrN$@$zg8@Ueb oinT^+A*qdzaSd0csrf(n3C?|Cjvr0^!vFvP07*qoM6N<$f{TUn0{{R3 literal 0 HcmV?d00001 diff --git a/common/DistributeCalc/entry/src/main/js/default/i18n/en-US.json b/common/DistributeCalc/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000..e63c70d978 --- /dev/null +++ b/common/DistributeCalc/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/common/DistributeCalc/entry/src/main/js/default/i18n/zh-CN.json b/common/DistributeCalc/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000..de6ee57483 --- /dev/null +++ b/common/DistributeCalc/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/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 0000000000..63df567ac1 --- /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 0000000000..f4aeed3022 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.hml @@ -0,0 +1,54 @@ + + +
+ + + + 计算器 + + + + {{expression}} + + + {{result}} + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.js b/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.js new file mode 100644 index 0000000000..35c9ea14d9 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.js @@ -0,0 +1,196 @@ +/* + * 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 {calc, isOperator} from '../../common/calculator.js'; +import app from '@system.app'; +import distributedDataKit from '@ohos.data.distributedData'; + +let pressedEqual = false; +let kvManager,kvStore; +const store_id = 'distributedCalc'; + +export default { + data: { + expression : '', + isPush:false, + result : '' + }, + onInit() { + this.$watch("expression", (value)=> { + if (value !== '') { + this.result = calc(value).toString(); + if(kvStore != null && !this.isPush) { + console.log('Calc[CalcPage] put key start'); + this.dataChange('expression',value); + } + } + }); + }, + dataChange(key, value){ + kvStore.put(key,value).then((data)=>{ + console.log('Calc[CalcPage] put key value successed! value:'+value); + }).catch((err)=>{ + console.log('Calc[CalcPage] put key value failed:'+err); + }); + }, + initKVManager(){ + let that = this; + console.log('Calc[CalcPage] get kv manager start'); + const config = + { + userInfo : { + userId : '0', + userType : 0 + }, + bundleName : 'com.example.distributedcalc' + }; + const promise = distributedDataKit.createKVManager(config); + promise.then((manager)=>{ + if(manager == null) { + console.log('Calc[CalcPage] get kv manager failed'); + return; + } + kvManager = manager; + console.log('Calc[CalcPage] get kv manager successed'); + const options = + { + createIfMissing : true, + encrypt : false, + backup : false, + autoSync : true, + kvStoreType : 1, + schema : '', + securityLevel : 3 + }; + kvManager.getKVStore(store_id,options).then((store)=>{ + if(store == null) { + console.log("Calc[CalcPage] get kv store failed"); + return; + } + kvStore = store; + console.log("Calc[CalcPage] get kv store successed"); + kvStore.on('dataChange', 1, function (data) { + console.info('Calc[CalcPage] dataChange, ' + JSON.stringify(data)); + console.info('Calc[CalcPage] dataChange, insert ' + data.insertEntries.length + " udpate " + data.updateEntries.length); + if(data) { + let arr = data.insertEntries.concat(data.updateEntries); + console.info('Calc[CalcPage] arr ' + JSON.stringify(arr)); + for(let i=0;i< arr.length;i++){ + let entry = arr[i]; + if(entry.key === 'expression') { + if(entry.value.value === 'exit') { + console.info('Calc[CalcPage] app exit! '); + app.terminate(); + return; + } + that.isPush = true; + if(entry.value.value == "clear") { + console.log("Calc[CalcPage] data expression:clear"); + that.expression = ''; + that.result = ''; + continue; + } + that.expression = entry.value.value; + console.log("Calc[CalcPage] data changed:"+entry.value.value); + } + } + } + }); + }).catch((err)=>{ + console.log("Calc[CalcPage] get kv store failed:"+err); + }); + }).catch((err)=>{ + console.log('Calc[CalcPage] get kv manager failed:'+err); + }); + console.log('Calc[CalcPage] get kv manager end'); + }, + stopDataListener(){ + console.log("Calc[CalcPage] stopDataListener start"); +// if(kvStore == null) { +// return; +// } +// kvStore.off('dataChange', function(){ +// console.log("Calc[CalcPage] stopDataListener success"); +// }); + console.log("Calc[CalcPage] stopDataListener end"); + }, + onShow(){ + console.log("Calc[CalcPage] on show"); + this.initKVManager(); + }, + onDestroy(){ + this.stopDataListener(); + }, + handleClear() { + this.expression = ''; + this.result = ''; + if(kvStore != null) { + this.dataChange('expression','clear'); + } + }, + handleInput(value) { + if (isOperator(value)) { + if (pressedEqual) { + pressedEqual = false; + } else { + const size = this.expression.length; + if (size) { + const last = this.expression.charAt(size - 1); + if (isOperator(last)) { + this.expression = this.expression.slice(0, -1); + } + } + } + if (!this.expression && (value == '*' || value == '/')) { + return; + } + this.expression += value; + } else { + if (pressedEqual) { + this.expression = value; + pressedEqual = false; + } else { + this.expression += value; + } + } + this.isPush = false; + }, + handleBackspace() { + if(pressedEqual) { + this.expression = ''; + this.result = ''; + pressedEqual = false; + } else { + this.expression = this.expression.slice(0, -1); + if (!this.expression.length) { + this.result = ''; + } + } + }, + handleEqual() { + if (this.result !== '') { + this.expression = this.result; + this.result = ''; + pressedEqual = true; + } + }, + handleTerminate(e) { + if (e.direction === 'right') { + app.terminate(); + } + }, + handleExist() { + app.terminate(); + }, +} \ No newline at end of file diff --git a/common/DistributeCalc/entry/src/main/js/default/pages/index/index.css b/common/DistributeCalc/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000..4397478a01 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,215 @@ +/* + * 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-select-device-btn { + left:90%; + top: 10px; +} + +.calc-select-device-dialog { + width: 90%; + height: 33%; +} + +.calc-select-device-wrapper { + width: 95%; + margin-left: 5%; + height: 100%; + flex-direction: column; +} + +.calc-select-device-item { + width: 100%; + height: 50%; +} + +.calc-select-device-item-cancel-btn { + text-align: center; + color: #0000ff; +} + +.calc-select-device-item-title { + text-align: left; + font-size: 40px; +} + +.calc-select-device-item-left { + width: 90%; + height: 100%; + text-align: left; + font-size: 32px; +} + +.calc-select-device-item-right { + width: 10%; + height: 100%; +} + +.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/index/index.hml b/common/DistributeCalc/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000..baffadc22a --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,67 @@ + + +
+ + + + {{title}} + + + + + {{expression}} + + + {{result}} + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 选择设备 + + + {{$item.deviceName}} + + + + 取消 +
+
+
diff --git a/common/DistributeCalc/entry/src/main/js/default/pages/index/index.js b/common/DistributeCalc/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000..00c1ee9f31 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,297 @@ +/* + * 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 {calc, isOperator} from '../../common/calculator.js'; +import app from '@system.app'; +import router from '@system.router'; +import distributedDataKit from '@ohos.data.distributeddata'; +import RemoteDeviceModel from '../../common/RemoteDeviceModel.js' +import featureAbility from '@ohos.ability.featureability'; + + +let pressedEqual = false; +let kvManager,kvStore; +const store_id = 'distributedCalc'; + +export default { + data: { + title:'计算器', + expression : '', + result : '', + selectedIndex: -1, + isPush:false, + isDistributed:false, + remoteDeviceModel: new RemoteDeviceModel(), + deviceList:[] + }, + onInit() { + this.$watch("expression", (value)=> { + if (value !== '') { + this.result = calc(value).toString(); + if(this.isDistributed && kvStore != null && !this.isPush) { + console.log('Calc[IndexPage] data changed'); + this.dataChange('expression',value); + } + } + }); + }, + onReady(){ + featureAbility.getWant((error, want) => { + console.info('Calc[IndexPage] featureAbility.getWant =' + JSON.stringify(want.parameters)); + if (want.parameters.isFA && want.parameters.isFA === 'FA') { + router.replace({ + uri:'pages/calc/calc' + }); + } + }); + }, + dataChange(key, value){ + kvStore.put(key,value).then((data)=>{ + console.log('Calc[IndexPage] put key value successed value:'+value); + }).catch((err)=>{ + console.log('Calc[IndexPage] put key value failed:'+err); + }); + }, + initKVManager(done){ + if(kvStore != null) { + this.isDistributed = true; + this.startDataListener(); + done(); + return; + } + console.log('Calc[IndexPage] get kv manager start'); + const config = + { + userInfo : { + userId : '0', + userType : 0 + }, + bundleName : 'com.example.distributedcalc' + }; + const promise = distributedDataKit.createKVManager(config); + promise.then((manager)=>{ + if(manager == null) { + console.log('Calc[IndexPage] get kv manager failed'); + return; + } + kvManager = manager; + console.log('Calc[IndexPage] get kv manager successed'); + const options = + { + createIfMissing : true, + encrypt : false, + backup : false, + autoSync : true, + kvStoreType : 1, + schema : '', + securityLevel : 3 + }; + kvManager.getKVStore(store_id,options).then((store)=>{ + if(store == null) { + console.log("Calc[IndexPage] get kv store failed"); + return; + } + kvStore = store; + console.log("Calc[IndexPage] get kv store successed"); + this.isDistributed = true; + this.startDataListener(); + done(); + }).catch((err)=>{ + console.log("Calc[IndexPage] get kv store failed:"+err); + }); + }).catch((err)=>{ + console.log('Calc[IndexPage] get kv manager failed:'+err); + }); + console.log('Calc[IndexPage] get kv manager end'); + }, + + startDataListener(){ + if(kvStore == null) { + console.info('Calc[IndexPage] startDataListener kvstore is null'); + return; + } + let that = this; + kvStore.on('dataChange', 1, function (data) { + console.info('Calc[IndexPage] dataChange, ' + JSON.stringify(data)); + console.info('Calc[IndexPage] dataChange, insert ' + data.insertEntries.length + " udpate " + data.updateEntries.length); + if(data) { + let arr = data.insertEntries.concat(data.updateEntries); + console.info('Calc[IndexPage] arr ' + JSON.stringify(arr)); + for(let i=0;i< arr.length;i++){ + let entry = arr[i]; + if(entry.key === 'expression') { + that.isPush = true; + if(entry.value.value == "clear") { + console.log("Calc[IndexPage] data expression:clear"); + that.expression = ''; + that.result = ''; + continue; + } + that.expression = entry.value.value; + console.log("Calc[IndexPage] data expression:" + that.expression); + console.log("Calc[IndexPage] data changed:" + entry.value.value); + } + } + } + }); + }, + + stopDataListener(){ + console.log("Calc[IndexPage] stopDataListener start"); +// if(kvStore == null) { +// console.log("Calc[IndexPage] stopDataListener kvStore is null"); +// return; +// } + //TODO:need function off +// kvStore.off('dataChange', function(){ +// console.log("Calc[IndexPage] stopDataListener success"); +// }); + console.log("Calc[IndexPage] stopDataListener end"); + }, + onDestroy(){ + this.remoteDeviceModel.unregisterDeviceListCallback(); + if(this.isDistributed && kvStore != null) { + this.stopDataListener(); + this.isDistributed = false; + } + }, + showDialog(){ + console.info('Calc[IndexPage] onContinueAbilityClick'); + let self = this; + this.remoteDeviceModel.registerDeviceListCallback(() => { + console.info('Calc[IndexPage] registerDeviceListCallback, callback entered'); + var list = new Array(); + list[0] = { + deviceId: '0', + deviceName: '本机', + checked: (self.selectedIndex == 0) + }; + console.info('Calc[IndexPage] on remote device updated, count=' + self.remoteDeviceModel.deviceList.length); + for (var i = 0; i < self.remoteDeviceModel.deviceList.length; i++) { + console.info('Calc[IndexPage] device ' + i + '/' + self.remoteDeviceModel.deviceList.length + + ' deviceId=' + self.remoteDeviceModel.deviceList[i].deviceId + ' deviceName=' + self.remoteDeviceModel.deviceList[i].deviceName + + ' deviceType=' + self.remoteDeviceModel.deviceList[i].deviceType); + list[i + 1] = { + deviceName: self.remoteDeviceModel.deviceList[i].deviceName, + deviceId: self.remoteDeviceModel.deviceList[i].deviceId, + checked: (self.selectedIndex == (i + 1)) + }; + } + self.deviceList = list; + }); + this.$element('showDialog').show(); + }, + cancelDialog(){ + this.$element('showDialog').close(); + this.remoteDeviceModel.unregisterDeviceListCallback(); + }, + selectDevice(index,e){ + if(!e.checked) { + return; + } + if(index === this.selectedIndex) { + return; + } + console.log("Calc[IndexPage] select index:"+index) + if (index == 0) { + console.log("Calc[IndexPage] stop ability") + this.dataChange('expression', 'exit'); + this.isDistributed = false; + this.stopDataListener(); + } else { + this.initKVManager(()=>{ + console.log("Calc[IndexPage] start ability deviceID:"+this.deviceList[index].deviceId); + featureAbility.startAbility({ + want:{ + bundleName: 'com.example.distributedcalc', + abilityName: 'com.example.distributedcalc.MainAbility', + deviceId:this.deviceList[index].deviceId, + parameters: { + isFA: 'FA' + } + } + }).then((data)=>{ + console.log("Calc[IndexPage] start ability finished:" + JSON.stringify(data)); + }); + console.log("Calc[IndexPage] start ability end") + }); + } + this.selectedIndex = index; + this.cancelDialog(); + }, + handleClear() { + this.expression = ''; + this.result = ''; + if(this.isDistributed && kvStore != null) { + console.log('Calc[IndexPage] data changed'); + this.dataChange('expression','clear'); + } + }, + handleInput(value) { + console.log("Calc[IndexPage] handle input value:"+value) + if (isOperator(value)) { + if (pressedEqual) { + pressedEqual = false; + } else { + const size = this.expression.length; + if (size) { + const last = this.expression.charAt(size - 1); + if (isOperator(last)) { + this.expression = this.expression.slice(0, -1); + } + } + } + if (!this.expression && (value == '*' || value == '/')) { + return; + } + this.expression += value; + } else { + if (pressedEqual) { + this.expression = value; + pressedEqual = false; + } else { + console.log("Calc[IndexPage] handle input:"+value) + this.expression += value; + } + } + this.isPush = false; + }, + handleBackspace() { + if(pressedEqual) { + this.expression = ''; + this.result = ''; + pressedEqual = false; + } else { + this.expression = this.expression.slice(0, -1); + if (!this.expression.length) { + this.result = ''; + } + } + }, + handleEqual() { + if (this.result !== '') { + this.expression = this.result; + this.result = ''; + pressedEqual = true; + } + }, + handleTerminate(e) { + if (e.direction === 'right') { + app.terminate(); + } + }, + handleExist() { + app.terminate(); + } +} \ No newline at end of file diff --git a/common/DistributeCalc/entry/src/main/resources/base/element/string.json b/common/DistributeCalc/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000..e259ca3b60 --- /dev/null +++ b/common/DistributeCalc/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DistributedCalc" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/common/DistributeCalc/entry/src/main/resources/base/media/icon.png b/common/DistributeCalc/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827b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mW+vVG4mxd(n$(eQf3-w>JPl2UJpafrPaL5@2j}%{VE-) zBI%6Qpj*dsdH<;g!S!avA~bv^0E+ zfyJbSjPb+j;J52U)<|cIcntQBI2T#>2;tOxu{%D?kML476AErF(qN9hPva5Nkc@BF zC-tLF@3ZFb%Kpj)M<{)x*l|*Ia@ECeXo2E4h2f!aV=cHAhi_E_mfUth(sM4^hJq7B zQsGWqdZUm9S%F`$nQ*_#NcuD`&)Ek%_s{&^78{9Hm ztri&rYLOxgFdG>O@+XHy z9#;|&vBCPXH5Mon^I`jSuR$&~ZWtyB67ujzFSj!51>#C}C17~TffQ{c-!QFQkTQ%! zIR^b1`zHx|*1GU?tbBx23weFLz5H?y_Q%N&t$}k?w+``2A=aotj0;2v$~AL z{scF-cL{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y Date: Thu, 29 Jul 2021 15:35:27 +0800 Subject: [PATCH 2/6] add distributeCalc --- common/DistributeCalc/build.gradle | 11 ----------- .../entry/src/main/js/default/i18n/en-US.json | 6 ------ .../entry/src/main/js/default/i18n/zh-CN.json | 6 ------ 3 files changed, 23 deletions(-) delete mode 100644 common/DistributeCalc/entry/src/main/js/default/i18n/en-US.json delete mode 100644 common/DistributeCalc/entry/src/main/js/default/i18n/zh-CN.json diff --git a/common/DistributeCalc/build.gradle b/common/DistributeCalc/build.gradle index 4017da2173..3c7d48fcaa 100644 --- a/common/DistributeCalc/build.gradle +++ b/common/DistributeCalc/build.gradle @@ -2,17 +2,6 @@ apply plugin: 'com.huawei.ohos.app' ohos { - signingConfigs { - release { - storeFile file('D:\\sign\\myApplication.p12') - storePassword '000000183B094E725BABC5F310F25709C494986705978CBAC9AB3457B52A0E3717E4F40E41178CCA' - keyAlias = 'my_app' - keyPassword '0000001822910DA0CE3444BB92ED34EA90022158E0D1BD27DFE784DFABEF950CE31644C31CEA20CA' - signAlg = 'SHA256withECDSA' - profile file('D:\\sign\\1111Release.p7b') - certpath file('D:\\sign\\l2.cer') - } - } compileSdkVersion 6 defaultConfig { compatibleSdkVersion 6 diff --git a/common/DistributeCalc/entry/src/main/js/default/i18n/en-US.json b/common/DistributeCalc/entry/src/main/js/default/i18n/en-US.json deleted file mode 100644 index e63c70d978..0000000000 --- a/common/DistributeCalc/entry/src/main/js/default/i18n/en-US.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "strings": { - "hello": "Hello", - "world": "World" - } -} \ No newline at end of file diff --git a/common/DistributeCalc/entry/src/main/js/default/i18n/zh-CN.json b/common/DistributeCalc/entry/src/main/js/default/i18n/zh-CN.json deleted file mode 100644 index de6ee57483..0000000000 --- a/common/DistributeCalc/entry/src/main/js/default/i18n/zh-CN.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "strings": { - "hello": "您好", - "world": "世界" - } -} \ No newline at end of file -- Gitee From 48ce7e8124d8bd04c84efaf4f1bc23869cd30d13 Mon Sep 17 00:00:00 2001 From: qhily999 Date: Thu, 29 Jul 2021 16:18:19 +0800 Subject: [PATCH 3/6] add distributecalc --- .../entry/src/main/js/default/app.js | 15 +++++++++++++ .../js/default/common/RemoteDeviceModel.js | 22 +++++++++++++------ .../src/main/js/default/pages/calc/calc.js | 10 ++------- .../src/main/js/default/pages/index/index.js | 11 +--------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/common/DistributeCalc/entry/src/main/js/default/app.js b/common/DistributeCalc/entry/src/main/js/default/app.js index 394207eb54..7ff1e139a7 100644 --- a/common/DistributeCalc/entry/src/main/js/default/app.js +++ b/common/DistributeCalc/entry/src/main/js/default/app.js @@ -1,3 +1,18 @@ +/* + * 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'); diff --git a/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js b/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js index 3ae88d6b54..598aa3a520 100644 --- a/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js +++ b/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js @@ -1,3 +1,18 @@ +/* + * 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'; @@ -94,13 +109,6 @@ export default class RemoteDeviceModel { }); console.info('Calc[RemoteDeviceModel] deviceFound self.deviceList=' + self.deviceList); console.info('Calc[RemoteDeviceModel] deviceFound self.deviceList.length=' + self.deviceList.length); -// for (var i = 0; i < self.deviceList.length; i++) { -// if (self.deviceList[i].deviceId == data.device.deviceId) { -// console.info('Calc[RemoteDeviceModel] device founded, ignored'); -// return; -// } -// } - console.info('Calc[RemoteDeviceModel] authenticateDevice ' + JSON.stringify(data.device)); self.#deviceManager.authenticateDevice(data.device); var list = self.#deviceManager.getTrustedDeviceListSync(); diff --git a/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.js b/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.js index 35c9ea14d9..afd161b3e8 100644 --- a/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.js +++ b/common/DistributeCalc/entry/src/main/js/default/pages/calc/calc.js @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import {calc, isOperator} from '../../common/calculator.js'; import app from '@system.app'; import distributedDataKit from '@ohos.data.distributedData'; @@ -116,14 +117,7 @@ export default { console.log('Calc[CalcPage] get kv manager end'); }, stopDataListener(){ - console.log("Calc[CalcPage] stopDataListener start"); -// if(kvStore == null) { -// return; -// } -// kvStore.off('dataChange', function(){ -// console.log("Calc[CalcPage] stopDataListener success"); -// }); - console.log("Calc[CalcPage] stopDataListener end"); + console.log("Calc[CalcPage] stopDataListener"); }, onShow(){ console.log("Calc[CalcPage] on show"); diff --git a/common/DistributeCalc/entry/src/main/js/default/pages/index/index.js b/common/DistributeCalc/entry/src/main/js/default/pages/index/index.js index 00c1ee9f31..d866c1355c 100644 --- a/common/DistributeCalc/entry/src/main/js/default/pages/index/index.js +++ b/common/DistributeCalc/entry/src/main/js/default/pages/index/index.js @@ -148,16 +148,7 @@ export default { }, stopDataListener(){ - console.log("Calc[IndexPage] stopDataListener start"); -// if(kvStore == null) { -// console.log("Calc[IndexPage] stopDataListener kvStore is null"); -// return; -// } - //TODO:need function off -// kvStore.off('dataChange', function(){ -// console.log("Calc[IndexPage] stopDataListener success"); -// }); - console.log("Calc[IndexPage] stopDataListener end"); + console.log("Calc[IndexPage] stopDataListener"); }, onDestroy(){ this.remoteDeviceModel.unregisterDeviceListCallback(); -- Gitee From 7a0b7ccccad395904c013960328948893d1e3d94 Mon Sep 17 00:00:00 2001 From: qhily999 Date: Thu, 29 Jul 2021 20:37:27 +0800 Subject: [PATCH 4/6] add distributedCalc --- common/DistributeCalc/entry/build.gradle | 2 - .../js/default/common/RemoteDeviceModel.js | 38 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/common/DistributeCalc/entry/build.gradle b/common/DistributeCalc/entry/build.gradle index 9b30d8f712..b81e304057 100644 --- a/common/DistributeCalc/entry/build.gradle +++ b/common/DistributeCalc/entry/build.gradle @@ -17,8 +17,6 @@ ohos { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) - testImplementation 'junit:junit:4.13' ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' } decc { diff --git a/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js b/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js index 598aa3a520..752fddc6b4 100644 --- a/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js +++ b/common/DistributeCalc/entry/src/main/js/default/common/RemoteDeviceModel.js @@ -21,13 +21,13 @@ var SUBSCRIBE_ID = 100; export default class RemoteDeviceModel { deviceList = new Array(); callback; - #deviceManager; + deviceManager_; constructor() { } registerDeviceListCallback(callback) { - if (typeof (this.#deviceManager) == 'undefined') { + if (typeof (this.deviceManager_) == 'undefined') { console.log("Calc[RemoteDeviceModel] deviceManager.createDeviceManager begin"); let self = this; deviceManager.createDeviceManager("com.example.distributedcalc", (error, value) => { @@ -35,7 +35,7 @@ export default class RemoteDeviceModel { console.error("Calc[RemoteDeviceModel] createDeviceManager failed."); return; } - self.#deviceManager = value; + self.deviceManager_ = value; self.registerDeviceListCallback_(callback); console.log("Calc[RemoteDeviceModel] createDeviceManager callback returned, error=" + error + " value=" + value); }); @@ -48,14 +48,14 @@ export default class RemoteDeviceModel { registerDeviceListCallback_(callback) { console.info('Calc[RemoteDeviceModel] registerDeviceListCallback'); this.callback = callback; - if (this.#deviceManager == undefined) { + 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(); + 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; @@ -64,7 +64,7 @@ export default class RemoteDeviceModel { console.info('Calc[RemoteDeviceModel] callback finished'); let self = this; - this.#deviceManager.on('deviceStateChange', (data) => { + this.deviceManager_.on('deviceStateChange', (data) => { console.info('Calc[RemoteDeviceModel] deviceStateChange data=' + JSON.stringify(data)); switch (data.action) { case 0: @@ -101,7 +101,7 @@ export default class RemoteDeviceModel { break; } }); - this.#deviceManager.on('deviceFound', (data) => { + this.deviceManager_.on('deviceFound', (data) => { console.info('Calc[RemoteDeviceModel] deviceFound data=' + JSON.stringify(data)); prompt.showToast({ message: 'deviceFound device=' + JSON.stringify(data.device), @@ -110,28 +110,28 @@ export default class RemoteDeviceModel { 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(); + 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) => { + 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) => { + 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', () => { + this.deviceManager_.on('serviceDie', () => { prompt.showToast({ message: 'serviceDie', duration: 3000, @@ -150,17 +150,17 @@ export default class RemoteDeviceModel { capability: 0 }; console.info('Calc[RemoteDeviceModel] startDeviceDiscover ' + SUBSCRIBE_ID); - this.#deviceManager.startDeviceDiscover(info); + 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.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 -- Gitee From 68c80406d0948f14195be2ef6835cab182aa3333 Mon Sep 17 00:00:00 2001 From: qhily999 Date: Thu, 29 Jul 2021 20:43:41 +0800 Subject: [PATCH 5/6] add distributed calc --- .../com/example/distributedcalc/MainAbility.java | 16 ---------------- .../example/distributedcalc/MyApplication.java | 10 ---------- 2 files changed, 26 deletions(-) delete mode 100644 common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MainAbility.java delete mode 100644 common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MyApplication.java diff --git a/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MainAbility.java b/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MainAbility.java deleted file mode 100644 index f07539ea95..0000000000 --- a/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MainAbility.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.example.distributedcalc; - -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/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MyApplication.java b/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MyApplication.java deleted file mode 100644 index 14b4f1012a..0000000000 --- a/common/DistributeCalc/entry/src/main/java/com/example/distributedcalc/MyApplication.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.example.distributedcalc; - -import ohos.aafwk.ability.AbilityPackage; - -public class MyApplication extends AbilityPackage { - @Override - public void onInitialize() { - super.onInitialize(); - } -} -- Gitee From f41bfbca010613b9b5211bce821aa45155f8e63d Mon Sep 17 00:00:00 2001 From: qhily999 Date: Thu, 29 Jul 2021 20:50:07 +0800 Subject: [PATCH 6/6] add distributed calc --- common/DistributeCalc/entry/build.gradle | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/common/DistributeCalc/entry/build.gradle b/common/DistributeCalc/entry/build.gradle index b81e304057..5e47037754 100644 --- a/common/DistributeCalc/entry/build.gradle +++ b/common/DistributeCalc/entry/build.gradle @@ -16,9 +16,7 @@ ohos { } -dependencies { - ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' -} +dependencies {} decc { supportType = ['html', 'xml'] } -- Gitee