diff --git a/build-profile.json5 b/build-profile.json5 index 0d463240ceed43ec7623f93af5b3091cc1765393..d0bff52383098706f0e74d26393552619fa7a872 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -12,20 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Copyright (c) 2022 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. - */ { diff --git a/product/default/src/main/ets/MainAbility/MainAbility.ts b/product/default/src/main/ets/MainAbility/MainAbility.ts index 3f1c48cb9e008832f98cadbc39cf86a17da5f584..9554abdd8c653e9396ea892ce1ee7103b970b216 100644 --- a/product/default/src/main/ets/MainAbility/MainAbility.ts +++ b/product/default/src/main/ets/MainAbility/MainAbility.ts @@ -21,6 +21,7 @@ import inputMethod from '@ohos.inputmethod'; import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil' import { atob } from 'js-base64' import display from '@ohos.display'; +import window from '@ohos.window'; globalThis.rdbStore = undefined @@ -29,6 +30,11 @@ export default class MainAbility extends Ability { private Tag = "MainAbility_Tablet" onCreate(want, launchParam) { + // @ts-ignore + window.getLastWindow(this.context,(err,data)=>{ + let windowWidth = data.getWindowProperties().windowRect.width + this.screenBreakPoints(windowWidth) + }) AppStorage.SetOrCreate('closeEditContentDialog', true) LogUtil.info(this.Tag, " onCreate, launchReason is " + launchParam.launchReason) LogUtil.info(this.Tag, " onCreate, deviceType" + deviceInfo.deviceType) @@ -69,22 +75,11 @@ export default class MainAbility extends Ability { } onWindowStageCreate(windowStage) { - let displayClass = null - let screenDpi = null - displayClass = display.getDefaultDisplaySync() - screenDpi = displayClass.densityDPI windowStage.getMainWindow((err, data) => { let windowClass = data try { windowClass.on('windowSizeChange', (data) => { - let windowWidth = data.width / (screenDpi / 160) - if (windowWidth >= 320 && windowWidth < 520 || windowWidth < 320) { - AppStorage.SetOrCreate('breakPoint', 'sm') - } else if (windowWidth >= 520 && windowWidth < 840) { - AppStorage.SetOrCreate('breakPoint', 'md') - } else if (windowWidth >= 840) { - AppStorage.SetOrCreate('breakPoint', 'lg') - } + this.screenBreakPoints(data.width) }) } catch (exception) { LogUtil.info(this.Tag, 'windowSizeChange fail') @@ -201,4 +196,19 @@ export default class MainAbility extends Ability { LogUtil.warn(this.Tag, " onContinue, writeToDisFileDir, copyFile failed : " + err) } } + + screenBreakPoints(data){ + let displayClass = null + let screenDpi = null + displayClass = display.getDefaultDisplaySync() + screenDpi = displayClass.densityDPI + let windowWidth = data / (screenDpi / 160) + if (windowWidth >= 320 && windowWidth < 520 || windowWidth < 320) { + AppStorage.SetOrCreate('breakPoint', 'sm') + } else if (windowWidth >= 520 && windowWidth < 840) { + AppStorage.SetOrCreate('breakPoint', 'md') + } else if (windowWidth >= 840) { + AppStorage.SetOrCreate('breakPoint', 'lg') + } + } } \ No newline at end of file