|
@@ -1,5 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 应用主Ability入口文件
|
|
|
|
|
+ * 功能:
|
|
|
|
|
+ * 1. 管理应用生命周期
|
|
|
|
|
+ * 2. 处理窗口创建和尺寸变化
|
|
|
|
|
+ * 3. 响应外部调用请求
|
|
|
|
|
+ * 4. 全局状态管理
|
|
|
|
|
+ */
|
|
|
import UIAbility from '@ohos.app.ability.UIAbility';
|
|
import UIAbility from '@ohos.app.ability.UIAbility';
|
|
|
import hilog from '@ohos.hilog';
|
|
import hilog from '@ohos.hilog';
|
|
|
import window from '@ohos.window';
|
|
import window from '@ohos.window';
|
|
@@ -11,15 +19,35 @@ import { DemoConstants } from './DemoConstants';
|
|
|
import { Utility } from '../common/util/Utility';
|
|
import { Utility } from '../common/util/Utility';
|
|
|
import { SpiderMan } from '@simplepeng/spider-man';
|
|
import { SpiderMan } from '@simplepeng/spider-man';
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 主Ability类,继承自UIAbility
|
|
|
|
|
+ * 负责:
|
|
|
|
|
+ * - 应用初始化
|
|
|
|
|
+ * - 窗口管理
|
|
|
|
|
+ * - 事件分发
|
|
|
|
|
+ */
|
|
|
export default class EntryAbility extends UIAbility {
|
|
export default class EntryAbility extends UIAbility {
|
|
|
- //一多断点开发
|
|
|
|
|
|
|
+ // UI上下文对象,用于获取窗口信息
|
|
|
private uiContext?: UIContext;
|
|
private uiContext?: UIContext;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 窗口尺寸变化回调函数
|
|
|
|
|
+ * @param windowSize 新的窗口尺寸对象
|
|
|
|
|
+ * 功能:
|
|
|
|
|
+ * 1. 获取最新的窗口断点尺寸
|
|
|
|
|
+ * 2. 更新AppStorage中的尺寸状态
|
|
|
|
|
+ * 3. 记录尺寸变化日志
|
|
|
|
|
+ */
|
|
|
private onWindowSizeChange: (windowSize: window.Size) => void = (windowSize: window.Size) => {
|
|
private onWindowSizeChange: (windowSize: window.Size) => void = (windowSize: window.Size) => {
|
|
|
|
|
+ // 获取宽度断点并更新全局状态
|
|
|
let widthBp: WidthBreakpoint = this.uiContext!.getWindowWidthBreakpoint();
|
|
let widthBp: WidthBreakpoint = this.uiContext!.getWindowWidthBreakpoint();
|
|
|
AppStorage.setOrCreate('currentWidthBreakpoint', widthBp);
|
|
AppStorage.setOrCreate('currentWidthBreakpoint', widthBp);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取高度断点并更新全局状态
|
|
|
let heightBp: HeightBreakpoint = this.uiContext!.getWindowHeightBreakpoint();
|
|
let heightBp: HeightBreakpoint = this.uiContext!.getWindowHeightBreakpoint();
|
|
|
AppStorage.setOrCreate('currentHeightBreakpoint', heightBp);
|
|
AppStorage.setOrCreate('currentHeightBreakpoint', heightBp);
|
|
|
|
|
|
|
|
|
|
+ // 记录尺寸变化日志
|
|
|
LogUtil.info('pura onWindowSizeChange currentHeightBreakpoint= '+heightBp);
|
|
LogUtil.info('pura onWindowSizeChange currentHeightBreakpoint= '+heightBp);
|
|
|
LogUtil.info( 'pura onWindowSizeChange currentWidthBreakpoint= '+widthBp);
|
|
LogUtil.info( 'pura onWindowSizeChange currentWidthBreakpoint= '+widthBp);
|
|
|
};
|
|
};
|