瀏覽代碼

修复hicar模式下 增加判断用户到底是在手机端还是hicar端打开的变量,以便修复手机播放界面显示有异常

onecold 1 年之前
父節點
當前提交
ae8d232ea6
共有 2 個文件被更改,包括 17 次插入31 次删除
  1. 8 0
      entry/src/main/ets/entryability/EntryAbility.ets
  2. 9 31
      entry/src/main/ets/view/LocalMusic.ets

+ 8 - 0
entry/src/main/ets/entryability/EntryAbility.ets

@@ -26,6 +26,7 @@ import StatusBarViewExtensionAbility from '@hms.pcService.StatusBarViewExtension
 import { SpiderMan } from '@simplepeng/spider-man';
 import { smartMobilityCommon } from '@kit.CarKit';
 import { url } from '@kit.ArkTS';
+import { display } from '@kit.ArkUI';
 
 /**
  * 主Ability类,继承自UIAbility
@@ -184,6 +185,13 @@ export default class EntryAbility extends UIAbility {
             // LogUtil.info( 'getMainWindow = ');
             globalThis.windowClass = data // 赋值给全局变量windowClass
 
+            let curDisplay = display.getDisplayByIdSync(windowClass.getWindowProperties().displayId);
+            if(curDisplay.name =='HiCar'||curDisplay.name =='SuperLauncher'){
+                AppStorage.setOrCreate('curDisplayIsHiCar', true);
+            }else{
+                AppStorage.setOrCreate('curDisplayIsHiCar', false);
+            }
+
             windowClass.setWindowLayoutFullScreen(true).then(() => {
                 console.info('Succeeded in setting the window layout to full-screen mode.');
             }).catch((e: BusinessError) => {

+ 9 - 31
entry/src/main/ets/view/LocalMusic.ets

@@ -208,6 +208,7 @@ export struct LocalMusic {
   @StorageProp('windowWidth') windowWidth: number = 0;
   @StorageProp('windowHeight') windowHeight: number = 0;
   @StorageProp('isHiCarStatus') isHiCarStatus: boolean = false;
+  @StorageProp('curDisplayIsHiCar') curDisplayIsHiCar: boolean = false;
   private UNKONWN:string = '';
   private listArea: Area = {
     width: 0,
@@ -550,7 +551,7 @@ export struct LocalMusic {
       let viewHeight = px2vp(size.height);
       if(this.isPhoneLan()){
         this.is_auto_hide_progress = false
-        if(this.isHiCarStatus){
+        if(this.isHiCar()){
           return
         }
         setTimeout(() => {
@@ -571,7 +572,7 @@ export struct LocalMusic {
   }
 
   startAutoHide() {
-    if(this.isHiCarStatus){
+    if(this.isHiCar()){
       return
     }
     if(PreferencesUtil.getBooleanSync(SettingPage.IS_AUTO_HIDE_PROGRESS,false)){
@@ -627,7 +628,7 @@ export struct LocalMusic {
     this.isSwipe = PreferencesUtil.getBooleanSync(SettingPage.IS_SWIPE, true)
     this.openSkipSongAnimate = PreferencesUtil.getBooleanSync(SettingPage.OPEN_SKIPSONG_ANIMATE, true)
     //如果是hicar连接状态,这些都是false
-    if(this.isHiCarStatus){
+    if(this.isHiCar()){
       this.isShowTitleBar = false//不显示导航栏
       if(!(this.windowWidth>1800&&this.windowHeight>=1200))//小屏幕不可以Grid
       {
@@ -5942,7 +5943,7 @@ export struct LocalMusic {
     LogUtil.info('hicar isPhoneLan height= ' + this.windowHeight);
     LogUtil.info(`twocold  hicarWindow size: ${this.windowWidth}x${this.windowHeight}, this.isHiCarStatus: ${this.isHiCarStatus}`);
     LogUtil.info(`twocold  hicar Window size: ${this.windowWidth}x${this.windowHeight}, isHiCarSmall: ${this.isHiCarSmall()}`);
-    if (this.isHiCarStatus) {
+    if (this.isHiCar()) {
       return false
     }
 
@@ -5971,7 +5972,7 @@ export struct LocalMusic {
       LogUtil.info('twocold Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
       if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
         // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
-        return true&&this.isHiCarStatus;
+        return true&&this.isHiCar();
       }
     }
 
@@ -6009,31 +6010,8 @@ export struct LocalMusic {
 
   isHiCar() {
 
-    return this.isHiCarStatus;
-
-    // const hiCarAspectRatios: HiCarAspectRatio[] = [
-    //   { ratio: 800 / 480, name: "800x480" },
-    //   { ratio: 762 / 752, name: "762x752" },
-    //   { ratio: 968 / 1280, name: "968x1280" },
-    //   { ratio: 1200 / 1200, name: "1200x1200" },
-    //   { ratio: 1280 / 720, name: "1280x720" },
-    //   { ratio: 1920 / 720, name: "1920x720" },
-    //   { ratio: 1920 / 1080, name: "1920x1080" }
-    // ];
-    // const currentRatio: number = this.windowWidth / this.windowHeight;
-    // const RATIO_TOLERANCE: number = 0.18; // 宽高比容差
-    // LogUtil.info('twocold currentRatio = ' + currentRatio)
-    //
-    // for (const hiCarRatio of hiCarAspectRatios) {
-    //   LogUtil.info('twocold hiCarRatio= ' + hiCarRatio.ratio)
-    //   LogUtil.info('twocold Math.abs(currentRatio - hiCarRatio.ratio)= ' + Math.abs(currentRatio - hiCarRatio.ratio))
-    //   if (Math.abs(currentRatio - hiCarRatio.ratio) <= RATIO_TOLERANCE) {
-    //     // LogUtil.info(`HiCar detected: ${hiCarRatio.name}, actual: ${this.windowWidth}x${this.windowHeight}`);
-    //     return true&&this.isHiCarStatus;
-    //   }
-    // }
-    //
-    // return false;
+    return this.isHiCarStatus&&this.curDisplayIsHiCar;
+
   }
 
 
@@ -6217,7 +6195,7 @@ export struct LocalMusic {
     .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
     .onClick(() => {
       // this.startAutoHide()
-      if(this.isHiCarStatus)
+      if(this.isHiCar())
         return
       if(this.is_auto_hide_progress){
         this.is_auto_hide_progress = false