提交 44c09795 编写于 作者: X xinking129

modify format

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 f8efc91c
......@@ -13,67 +13,67 @@
* limitations under the License.
*/
import hilog from '@ohos.hilog';
import Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
import Ability from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window';
import commonEvent from '@ohos.commonEvent';
let commonStateArr: number[] = [-1, -1, -1, -1]
let commonStateArr: number[] = [-1, -1, -1, -1];
let commonEventData = {
parameters: {
commonStateArr: commonStateArr
}
}
let onForeGroundTAG = -1
let TAG = 'StateChangeTestTAG'
let ApplicationStateChangeCallbackFir = {
};
let onForeGroundTAG = -1;
let TAG = 'StateChangeTestTAG';
let applicationStateChangeCallbackFir = {
onApplicationForeground() {
console.log(TAG, 'ApplicationStateChangeCallbackFir onApplicationForeground')
commonEventData.parameters.commonStateArr[0] = 1
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationForeground');
commonEventData.parameters.commonStateArr[0] = 1;
setTimeout(() => {
console.info('Enter onApplicationForeground publish!')
commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err))
console.info("====>processState publish err: " + JSON.stringify(err));
})
}, 1000)
}, 1000);
},
onApplicationBackground() {
console.log(TAG, 'ApplicationStateChangeCallbackFir onApplicationBackground')
commonEventData.parameters.commonStateArr[1] = 1
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationBackground');
commonEventData.parameters.commonStateArr[1] = 1;
if (globalThis.want.action == 'NeedBackGroundOff' || globalThis.want.action == 'MultiAppRegister') {
console.info('entered needbackgroundoff!')
globalThis.applicationContext.off('applicationStateChange', ApplicationStateChangeCallbackFir)
if (globalThis.want.action === 'NeedBackGroundOff' || globalThis.want.action === 'MultiAppRegister') {
console.info('entered needbackgroundoff!');
globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackFir);
}
}
}
};
let ApplicationStateChangeCallbackSec = {
let applicationStateChangeCallbackSec = {
onApplicationForeground() {
console.log(TAG, 'ApplicationStateChangeCallbackSec onApplicationForeground')
commonEventData.parameters.commonStateArr[2] = 1
console.log(TAG, 'applicationStateChangeCallbackSec onApplicationForeground');
commonEventData.parameters.commonStateArr[2] = 1;
},
onApplicationBackground() {
console.log(TAG, 'ApplicationStateChangeCallbackSec onApplicationBackground')
commonEventData.parameters.commonStateArr[3] = 1
if (globalThis.want.action == 'doubleNeedBackGroundOff') {
console.log(TAG, 'applicationStateChangeCallbackSec onApplicationBackground');
commonEventData.parameters.commonStateArr[3] = 1;
if (globalThis.want.action === 'doubleNeedBackGroundOff') {
setTimeout(() => {
globalThis.applicationContext.off('applicationStateChange', ApplicationStateChangeCallbackSec)
}, 500)
globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackSec);
}, 500);
}
else if (globalThis.want.action == 'DoubleRegisterOff') {
else if (globalThis.want.action === 'DoubleRegisterOff') {
setTimeout(() => {
console.info('entered DoubleRegisterOff')
globalThis.applicationContext.off('applicationStateChange')
}, 500)
console.info('entered DoubleRegisterOff');
globalThis.applicationContext.off('applicationStateChange');
}, 500);
}
}
}
export default class EntryAbility extends Ability {
onCreate(want, launchParam) {
onForeGroundTAG = -1
onForeGroundTAG = -1;
for (let i = 0; i < 4; i++) {
commonStateArr[i] = -1
}
......@@ -81,18 +81,18 @@ export default class EntryAbility extends Ability {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.abilityContext = this.context
globalThis.want = want
globalThis.abilityContext = this.context;
globalThis.want = want;
globalThis.applicationContext = this.context.getApplicationContext();
if (globalThis.want.action == 'RegisterOnOffOn') {
globalThis.applicationContext.on('applicationStateChange', ApplicationStateChangeCallbackFir)
globalThis.applicationContext.off('applicationStateChange', ApplicationStateChangeCallbackFir)
if (globalThis.want.action === 'RegisterOnOffOn') {
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackFir);
globalThis.applicationContext.off('applicationStateChange', applicationStateChangeCallbackFir);
}
globalThis.applicationContext.on('applicationStateChange', ApplicationStateChangeCallbackFir)
if (globalThis.want.action == 'doubleRegister' || globalThis.want.action == 'doubleNeedBackGroundOff'
|| globalThis.want.action == 'DoubleRegisterOff') {
console.info("double in action is logic entered!")
globalThis.applicationContext.on('applicationStateChange', ApplicationStateChangeCallbackSec)
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackFir);
if (globalThis.want.action === 'doubleRegister' || globalThis.want.action === 'doubleNeedBackGroundOff'||
globalThis.want.action === 'DoubleRegisterOff') {
console.info("double in action is logic entered!");
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackSec);
}
}
......@@ -128,14 +128,14 @@ export default class EntryAbility extends Ability {
// Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Abilityone onForeground');
onForeGroundTAG += 1
if (onForeGroundTAG == 1 && (globalThis.want.action == 'NeedBackGroundOff' || globalThis.want.action == 'MultiAppRegister'
|| globalThis.want.action == 'DoubleRegisterOff')) {
onForeGroundTAG += 1;
if (onForeGroundTAG === 1 && (globalThis.want.action === 'NeedBackGroundOff' || globalThis.want.action === 'MultiAppRegister'||
globalThis.want.action === 'DoubleRegisterOff')) {
setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err))
console.info("====>processState publish err: " + JSON.stringify(err));
})
}, 2000)
}, 2000);
}
}
......
......@@ -13,47 +13,47 @@
* limitations under the License.
*/
import hilog from '@ohos.hilog';
import Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
import commonEvent from '@ohos.commonEvent'
import Ability from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window';
import commonEvent from '@ohos.commonEvent';
let TAG = 'getRunningProcess'
let commonStateArr
let TAG = 'getRunningProcess';
let commonStateArr;
let commonEventData = {
parameters: {
commonStateArr: commonStateArr
}
}
let ApplicationStateChangeCallbackFir = {
};
let applicationStateChangeCallbackFir = {
onApplicationForeground() {
console.log(TAG, 'ApplicationStateChangeCallbackFir onApplicationForeground')
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationForeground');
},
onApplicationBackground() {
console.log(TAG, 'ApplicationStateChangeCallbackFir onApplicationBackground')
console.log(TAG, 'applicationStateChangeCallbackFir onApplicationBackground');
setTimeout(() => {
console.info('Enter onApplicationForeground publish!')
commonEventData.parameters.commonStateArr = 1
console.info('Enter onApplicationForeground publish!');
commonEventData.parameters.commonStateArr = 1;
commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err))
console.info('====>processState publish err: ' + JSON.stringify(err));
})
}, 1000)
}, 1000);
}
}
let ForegroundTAG = -1
let ForegroundTAG = -1;
export default class EntryAbility extends Ability {
onCreate(want, launchParam) {
ForegroundTAG = -1
commonEventData.parameters.commonStateArr = -1
ForegroundTAG = -1;
commonEventData.parameters.commonStateArr = -1;
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.abilityContext1 = this.context
globalThis.want1 = want
globalThis.abilityContext1 = this.context;
globalThis.want1 = want;
globalThis.applicationContext1 = this.context.getApplicationContext();
globalThis.applicationContext1.on('applicationStateChange', ApplicationStateChangeCallbackFir)
globalThis.applicationContext1.on('applicationStateChange', applicationStateChangeCallbackFir);
}
......@@ -87,12 +87,12 @@ export default class EntryAbility extends Ability {
onForeground() {
// Ability has brought to foreground
ForegroundTAG++
if (ForegroundTAG == 1) {
if (ForegroundTAG === 1) {
setTimeout(() => {
commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err))
console.info("====>processState publish err: " + JSON.stringify(err));
})
}, 3000)
}, 3000);
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
......
......@@ -13,8 +13,8 @@
* limitations under the License.
*/
import hilog from '@ohos.hilog';
import Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
import Ability from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window';
export default class EntryAbility1 extends Ability {
onCreate(want, launchParam) {
......@@ -22,8 +22,8 @@ export default class EntryAbility1 extends Ability {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.abilityContext2 = this.context
globalThis.want2 = want
globalThis.abilityContext2 = this.context;
globalThis.want2 = want;
globalThis.applicationContext2 = this.context.getApplicationContext();
}
......@@ -62,7 +62,7 @@ export default class EntryAbility1 extends Ability {
globalThis.abilityContext2.terminateSelf((err) => {
console.log('terminateSelf result:' + JSON.stringify(err));
})
}, 3000)
}, 3000);
}
onBackground() {
......
......@@ -13,20 +13,20 @@
* limitations under the License.
*/
import hilog from '@ohos.hilog';
import Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
import Ability from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window';
let TAG = 'StateChangeTestTAG'
let ApplicationStateChangeCallbackSec = {
let TAG = 'StateChangeTestTAG';
let applicationStateChangeCallbackSec = {
onApplicationForeground() {
console.info('==== ApplicationStateChange Foreground ====');
console.log(TAG, 'App2 ApplicationStateChangeCallbackSec onApplicationForeground')
console.log(TAG, 'App2 applicationStateChangeCallbackSec onApplicationForeground');
},
onApplicationBackground() {
console.info('==== ApplicationStateChange Background ====');
console.log(TAG, 'App2 ApplicationStateChangeCallbackSec onApplicationBackground')
console.log(TAG, 'App2 applicationStateChangeCallbackSec onApplicationBackground');
}
}
};
export default class EntryAbility extends Ability {
onCreate(want, launchParam) {
......@@ -35,11 +35,11 @@ export default class EntryAbility extends Ability {
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.abilityContext = this.context
globalThis.want = want
globalThis.abilityContext = this.context;
globalThis.want = want;
if (want.action == 'MultiAppRegister' || want.action == 'DoubleRegisterOff') {
globalThis.applicationContext = this.context.getApplicationContext();
globalThis.applicationContext.on('applicationStateChange', ApplicationStateChangeCallbackSec)
globalThis.applicationContext.on('applicationStateChange', applicationStateChangeCallbackSec);
}
}
......
......@@ -13,52 +13,52 @@
* limitations under the License.
*/
import hilog from '@ohos.hilog';
import Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
import commonEvent from '@ohos.commonEvent'
import AbilityConstant from '@ohos.app.ability.AbilityConstant'
import Ability from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window';
import commonEvent from '@ohos.commonEvent';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
let sequence = 0;
let TAG = 'GetRunningProcessInformation'
let commonStateArr: number[] = [-1, -1, -1, -1]
let TAG = 'GetRunningProcessInformation';
let commonStateArr: number[] = [-1, -1, -1, -1];
let commonEventData = {
parameters: {
commonStateArr: commonStateArr
}
}
};
globalThis.StartFloatingAbility = () => {
let want = {
"deviceId": "",
"bundleName": "com.example.getrunningprocessinformationtworeply", //
"abilityName": "EntryAbility"
'deviceId': '',
'bundleName': 'com.example.getrunningprocessinformationtworeply',
'abilityName': 'EntryAbility'
};
let options = {
windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FLOATING,
};
globalThis.abilityContext.startAbility(want, options, (error) => {
console.log(TAG, "start floating ability error.code = " + error.code)
console.log(TAG, 'start floating ability error.code = ' + error.code);
})
}
globalThis.StartNormalAbility = () => {
let want = {
"deviceId": "",
"bundleName": "com.example.getrunningprocessinformationtworeply", //
"abilityName": "EntryAbility"
'deviceId': '',
'bundleName': 'com.example.getrunningprocessinformationtworeply',
'abilityName': 'EntryAbility'
};
globalThis.abilityContext.startAbility(want, (error) => {
console.log(TAG, "start normal ability error.code = " + error.code)
console.log(TAG, 'start normal ability error.code = ' + error.code);
})
}
globalThis.GetRunningProcessInfoCallback = () => {
globalThis.applicationContext.getRunningProcessInformation((err, data) => {
if (err) {
console.log(TAG, `getRunningProcessInformation err: ` + JSON.stringify(err));
console.log(TAG, 'getRunningProcessInformation err: ' + JSON.stringify(err));
}
else {
console.log(TAG, 'Oncreate Callback State: ' + JSON.stringify(data[0].state));
commonStateArr[sequence++] = data[0].state
commonStateArr[sequence++] = data[0].state;
}
})
}
......@@ -66,15 +66,15 @@ globalThis.GetRunningProcessInfoCallback = () => {
globalThis.GetRunningProcessInfoPromise = () => {
globalThis.applicationContext.getRunningProcessInformation().then((data) => {
console.log(TAG, 'Oncreate Promise State: ' + JSON.stringify(data[0].state));
commonStateArr[sequence++] = data[0].state
commonStateArr[sequence++] = data[0].state;
}).catch((err) => {
console.log(TAG, `getRunningProcessInformation err: ` + JSON.stringify(err));
});
console.log(TAG, 'getRunningProcessInformation err: ' + JSON.stringify(err));
})
}
globalThis.PublishStateArray = () => {
commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err))
console.info('====>processState publish err: ' + JSON.stringify(err));
})
}
......@@ -86,8 +86,8 @@ export default class EntryAbility extends Ability {
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.want = want
globalThis.abilityContext = this.context
globalThis.want = want;
globalThis.abilityContext = this.context;
globalThis.applicationContext = this.context.getApplicationContext();
}
......
......@@ -13,8 +13,8 @@
* limitations under the License.
*/
import hilog from '@ohos.hilog';
import Ability from '@ohos.app.ability.UIAbility'
import Window from '@ohos.window'
import Ability from '@ohos.app.ability.UIAbility';
import Window from '@ohos.window';
export default class EntryAbility extends Ability {
onCreate(want, launchParam) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册