diff --git a/entry/src/main/ets/common/constants/StyleConstants.ets b/entry/src/main/ets/common/constants/StyleConstants.ets index 13059b66f1d91b2f7743b8118e4526d76aa0eb5e..9b25ce8e88bd5163cd3efc143680bb9a266b65ce 100644 --- a/entry/src/main/ets/common/constants/StyleConstants.ets +++ b/entry/src/main/ets/common/constants/StyleConstants.ets @@ -17,7 +17,6 @@ * Style constants for all Component. */ -const uiContext: UIContext | undefined = AppStorage.get('uiContext'); export default class StyleConstants { /** @@ -48,5 +47,7 @@ export default class StyleConstants { /** * Arc text size. */ - static readonly ARC_TEXT_SIZE: number = uiContext!.fp2px(14); + static getARCTextSize(uiContext: UIContext): number { + return uiContext.fp2px(14) + } } \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ts b/entry/src/main/ets/entryability/EntryAbility.ts index abea97bbc7bb24627951af94d7871890fd8fd67e..1a37a35c7405edabd3f0da004fa5bc0bc75a5fc9 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ts +++ b/entry/src/main/ets/entryability/EntryAbility.ts @@ -37,7 +37,6 @@ export default class EntryAbility extends UIAbility { return; } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - AppStorage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); }); } diff --git a/entry/src/main/ets/pages/CanvasPage.ets b/entry/src/main/ets/pages/CanvasPage.ets index 3f53eb5cf8c02b42677b4d190361327a2be2954d..afea0f1af2da1b883fc11918e9d7d7c2897ef41a 100644 --- a/entry/src/main/ets/pages/CanvasPage.ets +++ b/entry/src/main/ets/pages/CanvasPage.ets @@ -20,11 +20,6 @@ import PrizeDialog from '../view/PrizeDialog'; import PrizeData from '../viewmodel/PrizeData'; import StyleConstants from '../common/constants/StyleConstants'; import CommonConstants from '../common/constants/CommonConstants'; -import { Context } from '@kit.AbilityKit'; - -// Get context. -const uiContext: UIContext | undefined = AppStorage.get('uiContext'); -let context: Context = uiContext!.getHostContext()!; @Entry @Component @@ -48,7 +43,7 @@ struct CanvasPage { aboutToAppear() { // Obtains the width and height of the screen, excluding the height of the navigation view. - window.getLastWindow(context) + window.getLastWindow(this.getUIContext().getHostContext()) .then((windowClass: window.Window) => { windowClass.setWindowLayoutFullScreen(true); let windowProperties = windowClass.getWindowProperties(); @@ -66,7 +61,7 @@ struct CanvasPage { .width(StyleConstants.FULL_PERCENT) .height(StyleConstants.FULL_PERCENT) .onReady(() => { - this.drawModel.draw(this.canvasContext, this.screenWidth, this.screenHeight); + this.drawModel.draw(this.canvasContext, this.screenWidth, this.screenHeight,this.getUIContext()); }) .rotate({ x: 0, diff --git a/entry/src/main/ets/viewmodel/DrawModel.ets b/entry/src/main/ets/viewmodel/DrawModel.ets index 9da3e46fccfbb44358a4a6668fec168737433362..9df0432447d3942a733b52184b5227f1aac26016 100644 --- a/entry/src/main/ets/viewmodel/DrawModel.ets +++ b/entry/src/main/ets/viewmodel/DrawModel.ets @@ -39,7 +39,7 @@ export default class DrawModel { * @param screenWidth screenWidth. * @param screenHeight screenHeight. */ - draw(canvasContext: CanvasRenderingContext2D, screenWidth: number, screenHeight: number) { + draw(canvasContext: CanvasRenderingContext2D, screenWidth: number, screenHeight: number, uiContext:UIContext) { if (CheckEmptyUtils.isEmptyObj(canvasContext)) { Logger.error('[DrawModel][draw] canvasContext is empty.'); return; @@ -59,7 +59,7 @@ export default class DrawModel { // Draw the interior fan-shaped raffle area. this.drawInnerArc(); // Draw text in the internal fan area. - this.drawArcText(); + this.drawArcText(uiContext); // Draw the picture corresponding to the prize in the internal fan area. this.drawImage(); this.canvasContext.translate(-this.screenWidth / CommonConstants.TWO, @@ -160,12 +160,12 @@ export default class DrawModel { /** * Draw text in the internal fan area. */ - drawArcText() { + drawArcText(uiContext:UIContext) { if (this.canvasContext !== undefined) { this.canvasContext.textAlign = CommonConstants.TEXT_ALIGN; this.canvasContext.textBaseline = CommonConstants.TEXT_BASE_LINE; this.canvasContext.fillStyle = ColorConstants.TEXT_COLOR; - this.canvasContext.font = StyleConstants.ARC_TEXT_SIZE + CommonConstants.CANVAS_FONT; + this.canvasContext.font = StyleConstants.getARCTextSize(uiContext) + CommonConstants.CANVAS_FONT; } let textArrays = [ $r('app.string.text_smile'),