101 lines
4.1 KiB
Plaintext
101 lines
4.1 KiB
Plaintext
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
|
|
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
import { window,display,AppStorageV2} from '@kit.ArkUI';
|
|
import {MainScreenDisplayInfo,MainWindowInfo,MainWindowStageInfo} from '../pages/AppStorageV2Class'
|
|
import { IBestInit } from "@ibestservices/ibest-ui-v2"
|
|
const DOMAIN = 0x0000;
|
|
|
|
export default class EntryAbility extends UIAbility {
|
|
private mainWindow: window.Window | undefined;
|
|
|
|
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
|
try {
|
|
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
|
|
} catch (err) {
|
|
hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err));
|
|
}
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
|
|
}
|
|
|
|
onDestroy(): void {
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
|
|
}
|
|
|
|
onWindowStageCreate(windowStage: window.WindowStage): void {
|
|
// Main window is created, set main page for this ability
|
|
hilog.info(DOMAIN, 'Tag', '%{public}s', 'Ability onWindowStageCreate');
|
|
//Get DefaultDispplay width&&height&&id
|
|
const screenDisplayId:number=display.getDefaultDisplaySync().id;
|
|
const screenWidth:number=display.getDefaultDisplaySync().width;
|
|
const screenHeight:number=display.getDefaultDisplaySync().height;
|
|
//Set Main Window Size
|
|
const mainWindowWidth: number = screenWidth-100;
|
|
const mainWindowHeight: number = screenHeight-200;
|
|
//Init&&Save AppStorageV2
|
|
const mainDisplayInfo = AppStorageV2.connect<MainScreenDisplayInfo>(MainScreenDisplayInfo, () => new MainScreenDisplayInfo(
|
|
screenDisplayId,screenWidth,screenHeight
|
|
))!;
|
|
const mainWinInfo=AppStorageV2.connect<MainWindowInfo>(MainWindowInfo, () => new MainWindowInfo(
|
|
mainWindowWidth,mainWindowHeight
|
|
))!;
|
|
const mainWinStage=AppStorageV2.connect<MainWindowStageInfo>(MainWindowStageInfo, () => new MainWindowStageInfo(
|
|
windowStage
|
|
))!;
|
|
|
|
//Get Main Window
|
|
windowStage.getMainWindow((err, data) => {
|
|
if (err.code) {
|
|
console.error(`Failed to obtain the main window. Code: ${err.code}, message: ${err.message}`);
|
|
return;
|
|
}
|
|
this.mainWindow=data;
|
|
//moveWindowTo
|
|
this.mainWindow.moveWindowTo(50,50)
|
|
//resize mainWindow Size
|
|
this.mainWindow.resize(mainWindowWidth, mainWindowHeight, (err) => {
|
|
if (err.code) {
|
|
console.error(`Failed to resize the window. Code: ${err.code}, message: ${err.message}`);
|
|
return;
|
|
}
|
|
console.info(`Succeeded in resizing the window to ${mainWindowWidth}x${mainWindowHeight}.`);
|
|
});
|
|
|
|
// windowSizeChangeListener to Change mainWindowWidth&&mainWindowHeight in AppStorage
|
|
this.mainWindow.on('windowSizeChange', (ListenerData) => {
|
|
// if Size Change save to AppStorage
|
|
mainWinInfo.mainWindowWidth=ListenerData.width;
|
|
mainWinInfo.mainWindowHeight=ListenerData.height;
|
|
console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data));
|
|
});
|
|
});
|
|
|
|
//Load page
|
|
windowStage.loadContent('pages/Index', (err) => {
|
|
if (err.code) {
|
|
hilog.error(DOMAIN, 'Tag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
|
|
return;
|
|
}
|
|
IBestInit(windowStage, this.context);
|
|
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
|
|
});
|
|
}
|
|
|
|
onWindowStageDestroy(): void {
|
|
AppStorageV2.remove<MainWindowStageInfo>(MainWindowStageInfo);
|
|
if (this.mainWindow) {
|
|
this.mainWindow = undefined;
|
|
}
|
|
// Main window is destroyed, release UI related resources
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
|
}
|
|
|
|
onForeground(): void {
|
|
// Ability has brought to foreground
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
|
|
}
|
|
|
|
onBackground(): void {
|
|
// Ability has back to background
|
|
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
|
|
}
|
|
} |