Explorar el Código

针对hicar连接status的判断
hicar模式下显示的调整

onecold hace 1 año
padre
commit
ff83acffb3

+ 46 - 1
entry/src/main/ets/entryability/EntryAbility.ets

@@ -24,6 +24,7 @@ import Logger from '../common/util/Logger';
 import statusBarManager from '@hms.pcService.statusBarManager';
 import statusBarManager from '@hms.pcService.statusBarManager';
 import StatusBarViewExtensionAbility from '@hms.pcService.StatusBarViewExtensionAbility';
 import StatusBarViewExtensionAbility from '@hms.pcService.StatusBarViewExtensionAbility';
 import { SpiderMan } from '@simplepeng/spider-man';
 import { SpiderMan } from '@simplepeng/spider-man';
+import { smartMobilityCommon } from '@kit.CarKit';
 
 
 /**
 /**
  * 主Ability类,继承自UIAbility
  * 主Ability类,继承自UIAbility
@@ -35,7 +36,7 @@ import { SpiderMan } from '@simplepeng/spider-man';
 export default class EntryAbility extends UIAbility {
 export default class EntryAbility extends UIAbility {
     // UI上下文对象,用于获取窗口信息
     // UI上下文对象,用于获取窗口信息
     private uiContext?: UIContext;
     private uiContext?: UIContext;
-
+    private awareness: smartMobilityCommon.SmartMobilityAwareness = smartMobilityCommon.getSmartMobilityAwareness();
     /**
     /**
      * 窗口尺寸变化回调函数
      * 窗口尺寸变化回调函数
      * @param windowSize 新的窗口尺寸对象
      * @param windowSize 新的窗口尺寸对象
@@ -87,6 +88,8 @@ export default class EntryAbility extends UIAbility {
 
 
         this.handleWeChatCallIfNeed(want)
         this.handleWeChatCallIfNeed(want)
 
 
+        this.getHiCarStatus()
+
     }
     }
 
 
     async onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): Promise<void> {
     async onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): Promise<void> {
@@ -154,6 +157,13 @@ export default class EntryAbility extends UIAbility {
 
 
     onDestroy() {
     onDestroy() {
         hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
         hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
+        let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.CAR_HOP];
+        // 出行连接状态回调函数
+        const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
+            hilog.info(0x0000, 'Received smart mobility info: ', JSON.stringify(info));
+        };
+        // 解注册智慧出行连接状态的监听 示例2
+        this.awareness.off('smartMobilityStatus', types, callBack);
     }
     }
 
 
     onWindowStageCreate(windowStage: window.WindowStage) {
     onWindowStageCreate(windowStage: window.WindowStage) {
@@ -244,6 +254,41 @@ export default class EntryAbility extends UIAbility {
     }
     }
 
 
 
 
+    getHiCarStatus(){
+        this.awareness = smartMobilityCommon.getSmartMobilityAwareness();
+
+        // 业务类型
+        let types: smartMobilityCommon.SmartMobilityType[] = [smartMobilityCommon.SmartMobilityType.HICAR];
+        // 获取出行业务连接状态
+        let info = this.awareness.getSmartMobilityStatus(types[0]);
+
+        hilog.info(0x0000, 'getHiCarStatus  info: ', JSON.stringify(info));
+        if(info&&info.status==1){
+            AppStorage.setOrCreate('isHiCarStatus', true);
+        }else{
+            AppStorage.setOrCreate('isHiCarStatus', false);
+        }
+
+        // 出行连接状态回调函数
+        const callBack = (info: smartMobilityCommon.SmartMobilityInfo) => {
+            hilog.info(0x0000, 'getHiCarStatus Received smart mobility info: ', JSON.stringify(info));
+            if(info&&info.status==1){
+                AppStorage.setOrCreate('isHiCarStatus', true);
+            }else{
+                AppStorage.setOrCreate('isHiCarStatus', false);
+            }
+            this.sendChangeEvent()
+        };
+        // 注册智慧出行连接状态的监听
+        this.awareness.on('smartMobilityStatus', types, callBack);
+
+
+    }
 
 
+    //发送广播通知更新UI
+    sendChangeEvent() {
+        const eventData: emitter.EventData = {};
+        emitter.emit({ eventId: 333 }, eventData); // 发送广播通知更新doSwipBack
+    }
 
 
 }
 }

+ 4 - 2
entry/src/main/ets/pages/NewIndex.ets

@@ -34,7 +34,7 @@ import json from '@ohos.util.json';
 import { UserCenter } from './UserCenter';
 import { UserCenter } from './UserCenter';
 import { ScanFilePage } from './ScanFilePage';
 import { ScanFilePage } from './ScanFilePage';
 import { AboutPage } from './AboutPage';
 import { AboutPage } from './AboutPage';
-
+import { smartMobilityCommon } from '@kit.CarKit';
 
 
 const TAG = 'NewIndex'; // 日志标签
 const TAG = 'NewIndex'; // 日志标签
 
 
@@ -77,6 +77,7 @@ struct NewIndex {
   @Provide isFavMusic: boolean = false
   @Provide isFavMusic: boolean = false
   @StorageProp('windowWidth') windowWidth: number = 0;
   @StorageProp('windowWidth') windowWidth: number = 0;
   @StorageProp('windowHeight') windowHeight: number = 0;
   @StorageProp('windowHeight') windowHeight: number = 0;
+  @StorageProp('windowHeight') isHiCarStatus: boolean = false;
   /** 标题栏配置模型 */
   /** 标题栏配置模型 */
   @State titleBarModel: TitleBar.Model = new TitleBar.Model()
   @State titleBarModel: TitleBar.Model = new TitleBar.Model()
     .setTitleTextStyle(FontStyle.Normal)
     .setTitleTextStyle(FontStyle.Normal)
@@ -168,9 +169,10 @@ struct NewIndex {
     this.hasActiveSubscription = PreferencesUtil.getBooleanSync('hasActiveSubscription', false);
     this.hasActiveSubscription = PreferencesUtil.getBooleanSync('hasActiveSubscription', false);
   }
   }
 
 
+
   onPageShow() {
   onPageShow() {
 
 
-    if(this.isHiCar()||this.isBigScreen()){
+    if(this.isHiCarStatus||this.isBigScreen()){
       this.isShowDrawer = true
       this.isShowDrawer = true
       this.isShowTitleBar = false
       this.isShowTitleBar = false
     }
     }

+ 20 - 11
entry/src/main/ets/view/LocalMusic.ets

@@ -203,6 +203,7 @@ export struct LocalMusic {
   @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
   @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
   @StorageProp('windowWidth') windowWidth: number = 0;
   @StorageProp('windowWidth') windowWidth: number = 0;
   @StorageProp('windowHeight') windowHeight: number = 0;
   @StorageProp('windowHeight') windowHeight: number = 0;
+  @StorageProp('windowHeight') isHiCarStatus: boolean = false;
   private listArea: Area = {
   private listArea: Area = {
     width: 0,
     width: 0,
     height: 0,
     height: 0,
@@ -602,6 +603,13 @@ export struct LocalMusic {
     this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
     this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
     this.isPlayListBgGrass = PreferencesUtil.getBooleanSync(SettingPage.IS_PLAYLIST_BG_GRASS, true)
     this.isPlayListBgGrass = PreferencesUtil.getBooleanSync(SettingPage.IS_PLAYLIST_BG_GRASS, true)
     this.isShowHeader = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HEADER, true)
     this.isShowHeader = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_HEADER, true)
+
+    //如果是hicar连接状态,这些都是false
+    if(this.isHiCarStatus){
+      this.isShowTitleBar = false//不显示导航栏
+      this.isShowHeader = false//二级菜单不显示头部
+      this.isGridMusic= false//用list不用网格
+    }
     if (this.isSavePlayMode) {
     if (this.isSavePlayMode) {
       this.playType = PreferencesUtil.getNumberSync('musicPlayType', 0)
       this.playType = PreferencesUtil.getNumberSync('musicPlayType', 0)
     }
     }
@@ -4331,7 +4339,7 @@ export struct LocalMusic {
 
 
           Column() {
           Column() {
             Text(this.currentSong?.name)
             Text(this.currentSong?.name)
-              .fontSize(13)
+              .fontSize(16)
               .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
               .textOverflow({ overflow: TextOverflow.MARQUEE })//超长滚动
               .maxLines(1)
               .maxLines(1)
               .fontColor($r('app.color.text_color'))
               .fontColor($r('app.color.text_color'))
@@ -4339,7 +4347,7 @@ export struct LocalMusic {
             Row() {
             Row() {
               Text(this.currentSong?.artist)
               Text(this.currentSong?.artist)
                 .margin({ top: 2 })
                 .margin({ top: 2 })
-                .fontSize(11)
+                .fontSize(13)
                 .fontColor($r('app.color.text_color'))
                 .fontColor($r('app.color.text_color'))
             }
             }
           }
           }
@@ -4363,8 +4371,8 @@ export struct LocalMusic {
 
 
         Row() {
         Row() {
           Image($r('app.media.hm_previous'))
           Image($r('app.media.hm_previous'))
-            .height(24)
-            .width(24)
+            .height(28)
+            .width(28)
             .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
             .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
             .margin({ left: 8, right: 16 })
             .margin({ left: 8, right: 16 })
             .fillColor(this.themeColor)
             .fillColor(this.themeColor)
@@ -4390,8 +4398,8 @@ export struct LocalMusic {
               .height(36)
               .height(36)
               .aspectRatio(CommonConstants.ASPECT_RATIO)
               .aspectRatio(CommonConstants.ASPECT_RATIO)
             Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
             Image(this.CONTROL_PlayStatus === PlayStatus.PLAY ? $r('app.media.hm_pause') : $r('app.media.hm_play2'))
-              .height(32)
-              .width(32)
+              .height(38)
+              .width(38)
               .displayPriority(3)
               .displayPriority(3)
               .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
               .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
               .fillColor(this.themeColor)
               .fillColor(this.themeColor)
@@ -4406,8 +4414,8 @@ export struct LocalMusic {
 
 
 
 
           Image($r('app.media.hm_next'))
           Image($r('app.media.hm_next'))
-            .height(24)
-            .width(24)
+            .height(28)
+            .width(28)
             .margin({
             .margin({
               right: 16,
               right: 16,
               left: 16
               left: 16
@@ -4425,8 +4433,8 @@ export struct LocalMusic {
             })
             })
 
 
           Image($r('app.media.hm_playlist'))
           Image($r('app.media.hm_playlist'))
-            .height(24)
-            .width(24)
+            .height(28)
+            .width(28)
             .displayPriority(1)
             .displayPriority(1)
             .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
             .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.5 })
             .fillColor(this.themeColor)
             .fillColor(this.themeColor)
@@ -5602,7 +5610,7 @@ export struct LocalMusic {
   @State barBottomOpacity: number = 1
   @State barBottomOpacity: number = 1
   private hideDone: boolean = false;
   private hideDone: boolean = false;
   @State currentYOffset: number = 0;
   @State currentYOffset: number = 0;
-  @State bottomBarHeight: number = 55;
+  @State bottomBarHeight: number = 60;
   private isHiding: boolean = false;
   private isHiding: boolean = false;
 
 
   //是否是Pura X外屏,或者小屏幕
   //是否是Pura X外屏,或者小屏幕
@@ -5663,6 +5671,7 @@ export struct LocalMusic {
 
 
   //是不是hicar的屏幕分辨率
   //是不是hicar的屏幕分辨率
   isHiCar() {
   isHiCar() {
+
     const hiCarAspectRatios: HiCarAspectRatio[] = [
     const hiCarAspectRatios: HiCarAspectRatio[] = [
       { ratio: 800 / 480, name: "800x480" },
       { ratio: 800 / 480, name: "800x480" },
       { ratio: 762 / 752, name: "762x752" },
       { ratio: 762 / 752, name: "762x752" },

+ 2 - 2
entry/src/main/ets/view/RotatingCover.ets

@@ -52,8 +52,8 @@ export struct RotatingCover {
   build() {
   build() {
     Column() {
     Column() {
       Image(this.songLabel === undefined ||StrUtil.isEmpty(this.songLabel)? $r('app.media.music_red') : this.songLabel)
       Image(this.songLabel === undefined ||StrUtil.isEmpty(this.songLabel)? $r('app.media.music_red') : this.songLabel)
-        .height(32)
-        .width(32)
+        .height(38)
+        .width(38)
         .alt( $r('app.media.music_red'))
         .alt( $r('app.media.music_red'))
         .fillColor(this.themeColor)
         .fillColor(this.themeColor)
         .borderRadius(16)
         .borderRadius(16)

+ 6 - 1
entry/src/main/module.json5

@@ -113,7 +113,12 @@
         }
         }
       },
       },
 
 
-
+      {
+        "name": "ohos.permission.ACCESS_CAR_DISTRIBUTED_ENGINE"
+      },
+      {
+        "name": "ohos.permission.ACCESS_SERVICE_NAVIGATION_INFO"
+      }
 
 
 
 
     ],
     ],