1.优化NativeAbility::GetInstance().Back();函数在后退栈为空时退到主界面
authorluozheng <1732036298@qq.com>
Wed, 17 Apr 2024 07:26:42 +0000 (15:26 +0800)
committerluozheng <1732036298@qq.com>
Wed, 17 Apr 2024 07:26:42 +0000 (15:26 +0800)
2.添加根据ConfigModel开机设置屏幕亮度和亮屏时间函数

code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h
code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp
code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp
code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp
code/sdk/application/wearable/nativeabilityfwk/include/Ability.h
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index 845fb9e..9589a29 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-17 09:32:03
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-04-17 14:52:37
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h
+ */
 #ifndef _CONFIG_MODEL_C_H_
 #define _CONFIG_MODEL_C_H_
 
@@ -24,6 +31,16 @@ bool poweron_cat1_on_bootup_flag(void);
 
 void sync_all_config_to_disk(void);
 
+
+/*
+ * @brief 初始化屏幕亮度 
+ */
+void initScreenBrightness(void);
+/*
+ * @brief 初始化亮屏时间 
+ */
+void initializeScreenDuration(void);
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index cf734c4..87c0202 100644 (file)
@@ -1,6 +1,6 @@
 #include "config/include/ConfigModel.h"
 #include "config/include/ConfigModelC.h"
-
+#include "custom_utils.h"
 namespace OHOS
 {
     ConfigModel::ConfigModel()
@@ -736,6 +736,20 @@ void sync_all_config_to_disk(void)
     OHOS::ConfigModel::GetInstance()->sync_all_to_disk();
 }
 
+
+void initScreenBrightness(void)
+{
+   WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "initScreenBrightness");
+   int brightness = OHOS::ConfigModel::GetInstance()->GetBrightness();
+   uapi_setScreenBrightness(brightness);
+}
+
+void initializeScreenDuration(void)
+{
+   WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "initializeScreenDuration");
+   unsigned int time = OHOS::ConfigModel::GetInstance()->GetScreenDuration();
+   uapi_setScreenDuration(time);
+}
 #ifdef __cplusplus
 #if __cplusplus
 }
index 570a00e..135a2ad 100644 (file)
@@ -147,7 +147,8 @@ namespace OHOS
 
         if (g_jumpView.count(curViewId) != 0)
         {
-            NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]);
+            //NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]);
+            NativeAbility::GetInstance().EnterSlice(g_jumpView[curViewId]);
         }
         return true;
     }
index 24bcea2..bebac1a 100644 (file)
@@ -89,15 +89,16 @@ namespace OHOS
         // 如果是power键就返回上一级
         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
         {
-            uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
-            if (preSlice == VIEW_APPLIST)
-            {
-                NativeAbility::GetInstance().ChangeSlice(preSlice);
-            }
-            else
-            {
-                NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-            }
+            // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
+            // if (preSlice == VIEW_APPLIST)
+            // {
+            //     NativeAbility::GetInstance().ChangeSlice(preSlice);
+            // }
+            // else
+            // {
+            //     NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+            // }
+            NativeAbility::GetInstance().Back();
         }
         return true;
     }
index 7f7e851..5da2763 100755 (executable)
@@ -89,7 +89,12 @@ public:
             ChangeSlice(preSlice,transitionId,priority);
             return true;
         }
-        return false; // 没有更多的Slice可以后退
+        else
+        {
+            // 当backStack为空时,退回到defaultSliceId_
+            ChangeSlice(defaultSliceId_, transitionId, priority);
+            return false; // 返回false表示无前一个slice,退回到默认slice
+        }
     }
 protected:
     struct ProxyStruct {
index 9451686..7127f5d 100644 (file)
@@ -215,6 +215,9 @@ void startup_post_init_task(void)
         start_custom_ble_service();
     }
 
+    initScreenBrightness();
+    initializeScreenDuration();
+
     LOS_Msleep(5000);
     if ( poweron_cat1_on_bootup_flag() )
     {
@@ -557,6 +560,15 @@ void ScreenAlwaysOnCtr(uint8_t turnOnFlag)
     }
 }
 
+/*
+ * @brief 应用设置自定义亮度值. 应用设置的亮度值会覆盖系统默认亮度设置.
+ */
+void uapi_setScreenBrightness(int value)
+{
+    const power_display_svr_api_t *display_api = power_display_svr_get_api();
+    display_api->set_brightness(value);
+}
+
 /*
  * @brief 设置某个Slice亮屏时间,超过时间后屏幕息屏,单位ms 
 */
index 9de742c..80420bc 100644 (file)
@@ -49,6 +49,8 @@ char *uapi_get_local_yyyymmdd_date(void);
 
 void ScreenAlwaysOnCtr(uint8_t turnOnFlag);
 
+void uapi_setScreenBrightness(int value);
+
 void uapi_setScreenDuration(int32_t time);
 
 int32_t uapi_get_screen_state(void);