1/* 2* Copyright (c) 2024 Huawei Device Co., Ltd. 3* Licensed under the Apache License, Version 2.0 (the "License"); 4* you may not use this file except in compliance with the License. 5* You may obtain a copy of the License at 6* 7* http://www.apache.org/licenses/LICENSE-2.0 8* 9* Unless required by applicable law or agreed to in writing, software 10* distributed under the License is distributed on an "AS IS" BASIS, 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12* See the License for the specific language governing permissions and 13* limitations under the License. 14*/ 15import common from '@ohos.app.ability.common'; 16import display from '@ohos.display'; 17import settings from '@ohos.settings'; 18import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 19import deviceInfo from '@ohos.deviceInfo'; 20import { BusinessError } from '@ohos.base'; 21import mediaQuery from '@ohos.mediaquery'; 22import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'; 23import CommonConstants, { FontSizeScale } from '../common/constants/CommonConstants'; 24import { logger } from '../utils/Logger'; 25import { TipsJumpUtils } from '../utils/TipsJumpUtils'; 26import systemParameterEnhance from '@ohos.systemParameterEnhance'; 27import i18n from '@ohos.i18n'; 28import { LengthMetrics } from '@ohos.arkui.node'; 29import { DeviceUtil } from '../utils/DeviceUtil'; 30 31const TAG = '[ContinueSwitch_Page] : '; 32let context = getContext(this) as common.UIAbilityContext; 33let localStorage = LocalStorage.getShared(); 34 35interface switchStatus { 36 open: string; 37 close: string; 38} 39 40let switchState: switchStatus = { 41 open: CommonConstants.SWITCH_STATUS_OPEN, 42 close: CommonConstants.SWITCH_STATUS_CLOSE 43} 44 45@Entry(localStorage) 46@Component 47struct ContinueSwitch { 48 @StorageLink('isSwitchOn') isSwitchOn: boolean | undefined = true; 49 @StorageLink('continueSession') continueSession: UIExtensionContentSession | undefined = undefined; 50 @State title: string = ''; 51 @State screenHeight: number = 0; 52 @State screenWidth: number = 0; 53 @State shortSideSize: number = 0; 54 @State imageAnimatorHeight: number = this.getImageAnimatorHeight(); 55 @State imageAnimatorWidth: number = this.getImageAnimatorWidth(); 56 @State textWidth: number = 0; 57 @State gapLength: number = 0; 58 @State isShow: boolean = false; 59 @State isPC: boolean = DeviceUtil.isPC(); 60 @State portraitFunc: mediaQuery.MediaQueryResult | void | null = null; 61 @State isVideoVisible: Visibility = Visibility.Hidden; 62 @State contentHeight: number = 0; 63 @State imageArray: Array<ImageFrameInfo> = []; 64 @State animationState: AnimationStatus = AnimationStatus.Running; 65 @State reverse: boolean = false; 66 @State iterations: number = -1; 67 @State isEnabled: boolean = true; 68 @State isShowBack: boolean = true; 69 @StorageProp('currentFontSizeScale') @Watch('onFontSizeScaleChange') fontSizeScale: number = 1; 70 @State phoneSwitchTextTopMargin: string = '17vp'; 71 @State phoneSwitchTextBottomMargin: string = '18vp'; 72 @State titleBarMargin: LocalizedMargin = { 73 start: LengthMetrics.resource($r('sys.float.margin_left')), 74 } 75 @State titleBarMarginPc: LocalizedMargin = { 76 start: LengthMetrics.vp(16), 77 } 78 @State paddingStartNormal: LengthMetrics = LengthMetrics.resource($r('sys.float.margin_left')); 79 @State paddingStartPc: LengthMetrics = LengthMetrics.vp(16); 80 @State isBacked: boolean = false; 81 private listener: mediaQuery.MediaQueryListener = mediaQuery.matchMediaSync('(dark-mode:true)'); 82 private extContext?: common.UIExtensionContext; 83 private scroller: Scroller = new Scroller(); 84 private learnMore: ResourceStr = $r('app.string.learn_more'); 85 private continueDesc: ResourceStr = $r('app.string.continue_desc_text', ''); 86 private startReason?: string = ''; 87 private isSmallFoldProduct: boolean = DeviceUtil.isSmallFoldProduct(); 88 private pageInfos: NavPathStack = new NavPathStack(); 89 private transitionType: NavigationSystemTransitionType = NavigationSystemTransitionType.TITLE; 90 91 onPortrait(mediaQueryResult: mediaQuery.MediaQueryResult): void { 92 logger.info(`${TAG} 'onPortrait in`); 93 if (mediaQueryResult.matches as boolean) { 94 this.extContext?.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); 95 } else { 96 this.extContext?.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT); 97 } 98 } 99 100 onFontSizeScaleChange(): void { 101 logger.info(`${TAG} onFontSizeScaleChange`); 102 this.phoneSwitchTextTopMargin = this.UpdateMarginBasedOnFontSize(17, this.fontSizeScale); 103 this.phoneSwitchTextBottomMargin = this.UpdateMarginBasedOnFontSize(18, this.fontSizeScale); 104 } 105 106 /** 107 * Update the margins of the switch list according to the font size. 108 */ 109 public UpdateMarginBasedOnFontSize(fontFp: number, fontSizeScale: number): string { 110 logger.info(`${TAG} getlistSpace, fontSizeScale: ${fontSizeScale} ; fontFp: ${fontFp}`); 111 switch (fontSizeScale) { 112 case FontSizeScale.XXL1: 113 return '16vp'; 114 case FontSizeScale.XXL2: 115 return '20vp'; 116 case FontSizeScale.XXL3: 117 return '24vp'; 118 default: 119 return `${fontFp}vp`; 120 } 121 } 122 123 /** 124 * Initialize the switch list spacing size 125 */ 126 public phoneSwitchTextMarginInit(): void { 127 let fontSizeScale = parseFloat(systemParameterEnhance.getSync(CommonConstants.FONT_SIZE_SCALE_PARAM, '1')); 128 this.phoneSwitchTextTopMargin = this.UpdateMarginBasedOnFontSize(17, fontSizeScale); 129 this.phoneSwitchTextBottomMargin = this.UpdateMarginBasedOnFontSize(18, fontSizeScale); 130 } 131 132 getStringSync(): void { 133 logger.info(`${TAG} getStringSync in`); 134 try { 135 context.resourceManager.getStringValue($r('app.string.continue_title') 136 .id, (error: BusinessError, value: string) => { 137 if (error != null) { 138 logger.error(TAG + 'error is ' + error); 139 } else { 140 this.title = value; 141 logger.info(`${TAG} <aboutToAppear> this.title : ${this.title}`); 142 } 143 }) 144 } catch (error) { 145 let code: number = (error as BusinessError).code; 146 let message: string = (error as BusinessError).message; 147 logger.error(`${TAG} callback getStringValue failed,error code: ${code},message: ${message}.`); 148 } 149 } 150 151 getImageArray(): void { 152 logger.info(`${TAG} getImageArray in`); 153 if (deviceInfo.deviceType === '2in1') { 154 for (let i = 0; i <= CommonConstants.IMAGE_COUNT; ++i) { 155 this.imageArray.push({ 156 src: $r(`app.media.continuePC_${i}`), 157 duration: (i == CommonConstants.IMAGE_COUNT) ? CommonConstants.IMG_ANIMATOR_OVER_DURATION 158 : CommonConstants.IMG_ANIMATOR_NORMAL_DURATION 159 }) 160 } 161 } else { 162 for (let i = 0; i <= CommonConstants.IMAGE_COUNT; ++i) { 163 this.imageArray.push({ 164 src: $r(`app.media.continue_${i}`), 165 duration: (i == CommonConstants.IMAGE_COUNT) ? CommonConstants.IMG_ANIMATOR_OVER_DURATION 166 : CommonConstants.IMG_ANIMATOR_NORMAL_DURATION 167 }) 168 } 169 } 170 } 171 172 getGapLength(): void { 173 logger.info(`${TAG} getGapLength in, deviceInfo.deviceType : ${deviceInfo.deviceType}`); 174 this.gapLength = 175 DeviceUtil.isPhone() ? CommonConstants.GENERAL_PHONE_GAP_LENGTH : CommonConstants.PC_PAD_GAP_LENGTH; 176 logger.info(`${TAG} this.gapLength : ${this.gapLength}`); 177 } 178 179 initSwitchStatus(): void { 180 logger.info(`${TAG} initSwitchStatus in`); 181 try { 182 let value = settings.getValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, switchState.open, 183 settings.domainName.USER_SECURITY); 184 this.isSwitchOn = value != switchState.close ? true : false; 185 logger.info(`${TAG} <initSwitchStatus> this.isSwitchOn : ${this.isSwitchOn}; value: ${value}`); 186 187 AppStorage.setOrCreate('isSwitchOn', this.isSwitchOn); 188 logger.info(`${TAG} AppStorage.get<boolean>(isSwitchOn) : ${AppStorage.get<boolean>('isSwitchOn')}`); 189 190 if (this.isSwitchOn) { 191 let status: boolean = settings.setValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, switchState.open, 192 settings.domainName.USER_SECURITY); 193 logger.info(`${TAG} set value success :${status}; set:Continue_Switch_Status is 1`); 194 } 195 } catch (error) { 196 logger.error(`${TAG} settings set or get failed. error.message: ${error.message}`); 197 } 198 } 199 200 onPageShow() { 201 logger.info(`${TAG} onPageShow in`); 202 this.getGapLength(); 203 display.getAllDisplays((err, data) => { 204 this.screenWidth = px2vp(data[0].width); 205 this.screenHeight = px2vp(data[0].height); 206 this.contentHeight = this.screenHeight; 207 logger.info(`${TAG} screenWidth = ${this.screenWidth}; screenHeight = ${this.screenHeight}`); 208 }) 209 } 210 211 aboutToAppear() { 212 logger.info(`${TAG} aboutToAppear in`); 213 this.initSwitchStatus(); 214 this.getStringSync(); 215 this.getImageArray(); 216 this.listener.on('change', (mediaQueryResult: mediaQuery.MediaQueryResult) => { 217 this.onPortrait(mediaQueryResult); 218 }) 219 this.registerFoldChangeListener(); 220 this.extContext = localStorage.get<common.UIExtensionContext>('context'); 221 this.startReason = AppStorage.get<string>('startReason'); 222 this.isShowBack = AppStorage.get<boolean>('isShowBack') ?? true; 223 logger.info(`${TAG} aboutToAppear: startReason is ${this.startReason}, isShowBack: ${this.isShowBack}`); 224 this.phoneSwitchTextMarginInit(); 225 } 226 227 aboutToDisappear() { 228 logger.info(`${TAG} aboutToDisappear in`); 229 this.unRegisterFoldChangeListener(); 230 } 231 232 onBackPress() { 233 logger.info(`${TAG} onBackPress in`); 234 } 235 236 @Builder 237 PageMap(name: string) { 238 if (name === CommonConstants.SETTING_PAGE_NAME) { 239 this.NormalDestination(); 240 } 241 } 242 243 @Builder 244 NormalRootContent() { 245 Navigation(this.pageInfos) { 246 } 247 .mode(NavigationMode.Stack) 248 .onAppear(()=>{ 249 this.pageInfos.pushPathByName(CommonConstants.SETTING_PAGE_NAME, undefined); 250 }) 251 .navDestination(this.PageMap) 252 } 253 254 @Builder 255 NormalDestination() { 256 NavDestination() { 257 this.ContentBuilder(); 258 } 259 .hideTitleBar(false) 260 .title(this.title, { 261 paddingStart: this.isPC ? this.paddingStartPc : this.paddingStartNormal, 262 }) 263 .backgroundColor($r('sys.color.ohos_id_color_titlebar_sub_bg')) 264 .onShown(()=>{ 265 this.transitionType = NavigationSystemTransitionType.DEFAULT; 266 }) 267 .systemTransition(this.transitionType) 268 .onBackPressed(()=>{ 269 logger.info(`${TAG} onBackPressed in.`); 270 if (this.isBacked) { 271 logger.info(`${TAG} onBackPressed: The back button has been clicked.`); 272 return true; 273 } 274 this.transitionType = NavigationSystemTransitionType.TITLE; 275 this.pageInfos.pop(true); 276 try { 277 if (this.continueSession) { 278 this.continueSession.sendData({ 'action': 'pop' }); 279 this.isBacked = true; 280 } else { 281 logger.error(`${TAG} continueSession is undefined`); 282 } 283 } catch (error) { 284 let code: number = (error as BusinessError).code; 285 let message: string = (error as BusinessError).message; 286 logger.error(`${TAG} continueSession sendData failed. error.code: ${code}, message: ${message}`); 287 } 288 return false; 289 }) 290 } 291 292 @Builder 293 SearchRootContent() { 294 NavDestination() { 295 this.ContentBuilder(); 296 } 297 .hideTitleBar(false) 298 .title(this.title, { 299 paddingStart: this.isPC ? this.paddingStartPc : this.paddingStartNormal, 300 }) 301 .backgroundColor($r('sys.color.ohos_id_color_titlebar_sub_bg')) 302 } 303 304 @Builder 305 ContentBuilder() { 306 Scroll(this.scroller) { 307 Column() { 308 ImageAnimator() 309 .images(this.imageArray) 310 .state(this.animationState) 311 .reverse(this.reverse) 312 .fillMode(this.iterations) 313 .iterations(this.iterations) 314 .width(this.imageAnimatorWidth) 315 .height(this.imageAnimatorHeight) 316 .onStart(() => { 317 logger.info(`${TAG} ImageAnimator Start`); 318 }) 319 .onFinish(() => { 320 logger.info(`${TAG} ImageAnimator Finish`); 321 }) 322 323 Text() { 324 Span(this.continueDesc) 325 .fontFamily('HarmonyHeiTi') 326 .fontSize($r('sys.float.ohos_id_text_size_body2')) 327 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 328 .fontWeight(FontWeight.Regular) 329 Span(this.learnMore) 330 .fontFamily('HarmonyHeiTi') 331 .fontSize($r('sys.float.ohos_id_text_size_body2')) 332 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 333 .fontWeight(FontWeight.Medium) 334 .onClick(() => { 335 logger.info(`${TAG} onClick learnMore`); 336 TipsJumpUtils.jumpTips(getContext(this) as common.UIAbilityContext, CommonConstants.FUN_NUM, 337 CommonConstants.TIPS_TYPE); 338 }) 339 } 340 .margin({ 341 bottom: CommonConstants.CONTINUE_DESC_TEXT_MARGIN_BOTTOM, 342 top: CommonConstants.CONTINUE_DESC_TEXT_MARGIN_TOP, 343 }) 344 .padding({ 345 left: DeviceUtil.isPhone() ? $r('app.float.margin_8') : 0, 346 right: DeviceUtil.isPhone() ? $r('app.float.margin_8') : 0 347 }) 348 .textAlign(TextAlign.Center) 349 .width('100%') 350 351 Column() { 352 Flex({ 353 direction: FlexDirection.Row, 354 justifyContent: FlexAlign.SpaceBetween, 355 alignItems: ItemAlign.Center 356 }) { 357 Text($r('app.string.continue_title')) 358 .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) 359 .fontWeight(FontWeight.Medium) 360 .fontColor($r('sys.color.ohos_id_color_text_primary')) 361 .accessibilityLevel('no') 362 .padding({ 363 top: this.isPC ? CommonConstants.ITEM_LIST_PADDING_TOP_PC : this.phoneSwitchTextTopMargin, 364 bottom: this.isPC ? CommonConstants.ITEM_LIST_PADDING_BOTTOM_PC : this.phoneSwitchTextBottomMargin 365 }) 366 367 Toggle({ type: ToggleType.Switch, isOn: this.isSwitchOn }) 368 .width(CommonConstants.CONTINUE_SWITCH_WIDTH) 369 .height(CommonConstants.CONTINUE_SWITCH_HEIGHT) 370 .hoverEffect(HoverEffect.None) 371 .enabled(this.isEnabled) 372 .onChange((isOn: boolean) => { 373 logger.info(`${TAG} isOn: ${isOn}`); 374 this.isSwitchOn = isOn; 375 AppStorage.setAndLink('isSwitchOn', isOn); 376 try { 377 if (isOn) { 378 let status: boolean = settings.setValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, 379 switchState.open, settings.domainName.USER_SECURITY); 380 logger.info(`${TAG} is set success :${status}; set:Continue_Switch_Status is open`); 381 } else { 382 let status: boolean = settings.setValueSync(context, CommonConstants.CONTINUE_SWITCH_KEY, 383 switchState.close, settings.domainName.USER_SECURITY); 384 logger.info(`${TAG} is set success :${status}; set:Continue_Switch_Status is close`); 385 } 386 } catch (error) { 387 logger.error(`${TAG} settings.setValueSync failed. error.message: ${error.message}`); 388 } 389 }) 390 } 391 .width('100%') 392 .padding({ 393 left: CommonConstants.TEXT_LIST_ALIGN_DISTANCE, 394 right: CommonConstants.TEXT_LIST_ALIGN_DISTANCE 395 }) 396 .backgroundColor($r('sys.color.ohos_id_color_list_card_bg')) 397 .borderRadius(this.isPC ? CommonConstants.PC_BORDER_RADIUS : CommonConstants.NON_PC_BORDER_RADIUS) 398 .accessibilityText(this.title) 399 } 400 .width('100%') 401 .constraintSize({ 402 minHeight: CommonConstants.PC_LIST_HEIGHT 403 }) 404 405 Column() { 406 Flex({ 407 direction: FlexDirection.Row, 408 justifyContent: FlexAlign.Start, 409 alignItems: ItemAlign.Center 410 }) { 411 SymbolGlyph($r('sys.symbol.info_circle_fill')) 412 .fontWeight(FontWeight.Medium) 413 .fontSize(CommonConstants.SYMBOL_INFO_CIRCLE) 414 .fontColor([$r('sys.color.ohos_id_color_activated')]) 415 .margin(this.isMirrorLanguages() ? { left: CommonConstants.SYMBOL_MARGIN_RIGHT } : 416 { right: CommonConstants.SYMBOL_MARGIN_RIGHT }) 417 .width(CommonConstants.SYMBOL_INFO_CIRCLE) 418 .height(CommonConstants.SYMBOL_INFO_CIRCLE) 419 .accessibilityLevel('no') 420 421 Text($r('app.string.update_version_prompt')) 422 .fontSize($r('sys.float.ohos_id_text_size_body3')) 423 .fontWeight(FontWeight.Medium) 424 .fontColor($r('sys.color.ohos_id_color_text_primary')) 425 .textAlign(TextAlign.Start) 426 .lineHeight(-1) 427 } 428 .margin({ top: CommonConstants.UPDATE_PROMPT_MARGIN_TOP }) 429 } 430 .padding({ 431 left: CommonConstants.TEXT_LIST_ALIGN_DISTANCE, 432 right: CommonConstants.TEXT_LIST_ALIGN_DISTANCE 433 }) 434 435 Column() { 436 Row() { 437 Text($r('app.string.continue_privacy_text')) 438 .fontSize($r('sys.float.ohos_id_text_size_body3')) 439 .fontWeight(FontWeight.Regular) 440 .margin({ top: CommonConstants.CONTINUE_PRIVACY_TEXT_MARGIN_TOP }) 441 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 442 .textAlign(TextAlign.Start) 443 .width('100%') 444 .lineHeight(this.isTibetanLanguages() ? 19 : 0) 445 } 446 .padding({ 447 left: CommonConstants.TEXT_LIST_ALIGN_DISTANCE, 448 right: CommonConstants.TEXT_LIST_ALIGN_DISTANCE 449 }) 450 }.width('100%') 451 452 } 453 .width('100%') 454 .padding({ left: this.gapLength, right: this.gapLength }) 455 .margin({ bottom: '44vp' }) 456 .backgroundColor($r('sys.color.ohos_id_color_sub_background')) 457 } 458 .width('100%') 459 .height('100%') 460 .scrollable(ScrollDirection.Vertical) 461 .scrollBar(BarState.Off) 462 .align(Alignment.TopStart) 463 .friction(0.6) 464 .edgeEffect(EdgeEffect.Spring) 465 .onScrollEdge(() => { 466 logger.info('To the edge'); 467 }) 468 .onScrollStop(() => { 469 logger.info('Scroll Stop'); 470 }) 471 .onAreaChange((oldArea: Area, newArea: Area) => { 472 logger.info(`${TAG} Scroll, oldArea.height = ${oldArea.height}, newArea.height = ${newArea.height}`); 473 }) 474 475 ScrollBar({ 476 scroller: this.scroller, 477 direction: ScrollBarDirection.Vertical, 478 state: BarState.Auto 479 }) 480 .position({ end: LengthMetrics.vp(0) }) 481 .margin({bottom: 28}) 482 } 483 484 build() { 485 Column() { 486 if (this.isShowBack) { 487 this.NormalRootContent(); 488 } else { 489 this.SearchRootContent(); 490 } 491 } 492 .width('100%') 493 .height('100%') 494 .backgroundColor($r('sys.color.ohos_id_color_sub_background')) 495 .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) 496 .onAreaChange((oldArea: Area, newArea: Area) => { 497 logger.info(`${TAG} onAreaChange: newArea.width = ${newArea.width}, newArea.height = ${newArea.height}`); 498 this.getImageAnimatorSize(newArea); 499 }) 500 } 501 502 private getImageAnimatorSize(compArea:Area) { 503 logger.info(`${TAG} getImageAnimatorSize in.`); 504 if (typeof compArea.width === 'number' && typeof compArea.height === 'number') { 505 let width = compArea.width as number; 506 let halfHeight = (compArea.height as number) / 2; 507 try { 508 let displayInfo: display.Display | undefined = display.getDefaultDisplaySync(); 509 if (displayInfo) { 510 halfHeight = !this.isPC && displayInfo.height > 0 ? px2vp(displayInfo.height / 2) : (compArea.height / 2); 511 logger.info(`${TAG} display: halfHeight = ${halfHeight}`); 512 } 513 } catch (error) { 514 logger.error(`${TAG} getDefaultDisplaySync failed. error.message: ${error.message}`); 515 } 516 if (width > halfHeight) { 517 this.imageAnimatorWidth = halfHeight * 0.8; 518 this.imageAnimatorHeight = this.imageAnimatorWidth * 2 / 3; 519 } else { 520 this.imageAnimatorWidth = width * 0.8; 521 this.imageAnimatorHeight = this.imageAnimatorWidth * 2 / 3; 522 } 523 } 524 logger.info(`${TAG} this.imageAnimatorWidth = ${this.imageAnimatorWidth}, this.imageAnimatorHeight = ${this.imageAnimatorHeight}`); 525 } 526 527 private getImageAnimatorHeight(): number { 528 if (deviceInfo.deviceType === 'phone') { 529 return CommonConstants.ANIMATOR_HEIGHT_PHONE; 530 } else if (deviceInfo.deviceType === '2in1') { 531 return CommonConstants.ANIMATOR_HEIGHT_PC; 532 } else if (deviceInfo.deviceType === 'tablet') { 533 return CommonConstants.ANIMATOR_HEIGHT_PAD; 534 } 535 return CommonConstants.ANIMATOR_HEIGHT_PHONE; 536 } 537 538 private getImageAnimatorWidth(): number { 539 if (deviceInfo.deviceType === 'phone') { 540 return CommonConstants.ANIMATOR_WIDTH_PHONE; 541 } else if (deviceInfo.deviceType === '2in1') { 542 return CommonConstants.ANIMATOR_WIDTH_PC; 543 } else if (deviceInfo.deviceType === 'tablet') { 544 return CommonConstants.ANIMATOR_WIDTH_PAD; 545 } 546 return CommonConstants.ANIMATOR_WIDTH_PHONE; 547 } 548 549 /** 550 * 根据折叠状态更新是否显示返回按钮 551 */ 552 private refreshFoldStatus(foldStatus: display.FoldStatus): void { 553 logger.info(`${TAG} refreshFoldStatus in. foldStatus: ${foldStatus}. startReason: ${this.startReason}`); 554 this.isShowBack = (this.startReason !== 'from_search' || foldStatus === display.FoldStatus.FOLD_STATUS_FOLDED); 555 logger.info(`${TAG} refreshFoldStatus end. this.isShowBack: ${this.isShowBack}.`); 556 } 557 558 /** 559 * 折叠状态发生变化 560 */ 561 private displayCallback: Callback<display.FoldStatus> = (data: display.FoldStatus) => { 562 this.refreshFoldStatus(data); 563 } 564 565 private registerFoldChangeListener(): void { 566 logger.info(`${TAG} registerFoldChangeListener in.isSmallFoldProduct: ${this.isSmallFoldProduct}`); 567 try { 568 // 首次非L+V折叠刷新isShowBack 569 if (!this.isSmallFoldProduct && display.isFoldable()) { 570 let data: display.FoldStatus = display.getFoldStatus(); 571 this.refreshFoldStatus(data); 572 } 573 display.on('foldStatusChange', this.displayCallback); 574 } catch (err) { 575 logger.error(`${TAG} registerFoldChangeListener failed. err.message: ${err.message}`); 576 } 577 } 578 579 private unRegisterFoldChangeListener(): void { 580 logger.info(`${TAG} unRegisterFoldChangeListener in.`); 581 try { 582 display.off('foldStatusChange', this.displayCallback); 583 } catch (err) { 584 logger.error(`${TAG} unRegisterFoldChangeListener failed. err.message: ${err.message}`); 585 } 586 } 587 588 private isMirrorLanguages(): 589 boolean { 590 logger.info(`${TAG} isMirrorLanguages in`); 591 let locale = new Intl.Locale(i18n.System.getSystemLanguage()).toString(); 592 return CommonConstants.MIRROR_LANGUAGES.includes(locale); 593 } 594 595 private isTibetanLanguages(): 596 boolean { 597 logger.info(`${TAG} isTibetanLanguages in`); 598 let locale = new Intl.Locale(i18n.System.getSystemLanguage()).toString(); 599 logger.info(`${TAG} isTibetanLanguages: ${locale}`); 600 return CommonConstants.TIBETAN_LANGUAGES.includes(locale); 601 } 602}