保存手电筒设置的信息;手电筒自定义颜色功能,还需要实现两个核心接口:通过坐标获取对应颜色值(GetValueByColorCustomSelectedImage... 907/1 907/head
authorcheng <chengyf@zhihuishixun.com>
Sat, 7 Sep 2024 09:42:54 +0000 (17:42 +0800)
committercheng <chengyf@zhihuishixun.com>
Sat, 7 Sep 2024 09:42:54 +0000 (17:42 +0800)
code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightModel.h
code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightPresenter.h
code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightView.h
code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightModel.cpp
code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/flashlight/src/FlashlightView.cpp
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/flashlight/color_custom_bg.bin [new file with mode: 0644]
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/flashlight/color_custom_selected.bin [new file with mode: 0644]
code/sdk/drivers/peripheral/config/include/ConfigModel.h
code/sdk/drivers/peripheral/config/src/ConfigModel.cpp

index abce5c0..650c84a 100644 (file)
@@ -17,6 +17,7 @@ namespace OHOS
     public:
         static FlashlightModel &GetInstance(void);
 
+        void SaveSettingInfo(void);
         uint8_t GetColorIndex(void);
         void SetColorIndex(uint8_t value);
         int64_t GetColorValue(void);
@@ -26,8 +27,6 @@ namespace OHOS
 
         void FlashlightStartTimer(void);
         void FlashlightStopTimer(void);
-        void FlashlightPauseTimer(void);
-        void FlashlightResumeTimer(uint32_t interval);
 
     private:
         FlashlightModel();
index d272d02..9927f85 100644 (file)
@@ -23,6 +23,8 @@ namespace OHOS
     #define Flashlight_ViewId_GroupColorCustom_ "Flashlight_ViewId_GroupColorCustom_"
     #define Flashlight_ViewId_ScrollFlashingSetting_ "Flashlight_ViewId_ScrollFlashingSetting_"
 
+    #define Flashlight_ViewId_ImageColorCustomBackground_ "Flashlight_ViewId_ImageColorCustomBackground_"
+
     #define FLASHING_SETTING_ITEM_COUNT (3)
     constexpr char * Flashlight_ViewId_FlashingSettingItem_[FLASHING_SETTING_ITEM_COUNT] = 
                                                     {
index 9a51b00..00e53d1 100644 (file)
@@ -42,6 +42,8 @@ namespace OHOS
         void DisplayColorCustomScreen();
         void DisplayFlashingSettingScreen();
 
+        void GetValueByColorCustomSelectedImage(int16_t x, int16_t y, int64_t * value);
+        void GetPointByColorCustomSelectedImage(int16_t * x, int16_t * y, int64_t value);
         void UpdateViewMainScreenFlashing(bool flag);
 
         typedef enum
@@ -98,8 +100,10 @@ namespace OHOS
 
         void DeinitColorCustomData();
         // UIViewGroup * InitColorCustomData();
+        // void UpdateColorCustomSelectedImage(int16_t x, int16_t y);
         UIViewGroup * GroupColorCustom_{nullptr};
-        UIImageView * ImageColorCustom_{nullptr};
+        UIImageView * ImageColorCustomBackground_{nullptr};
+        UIImageView * ImageColorCustomSelected_{nullptr};
 
         void DeinitFlashingSettingData();
         // UIScrollView * InitFlashingSettingData();
@@ -132,6 +136,9 @@ namespace OHOS
                                                         "/user/res/flashlight/color_4.bin", 
                                                         "/user/res/flashlight/color_5.bin",
                                                     };
+
+        #define COLOR_CUSTOM_BACKGROUND_IMAGE "/user/res/flashlight/color_custom_bg.bin"
+        #define COLOR_CUSTOM_SELECTED_IMAGE "/user/res/flashlight/color_custom_selected.bin"                                                    
     };
 }
 #endif
\ No newline at end of file
index 3b894ae..ce84eae 100644 (file)
@@ -5,6 +5,7 @@
 #include "wearable_log.h"
 #include "flashlight/include/FlashlightModel.h"
 #include "flashlight/include/FlashlightPresenter.h"
+#include "ConfigModel.h"
 
 namespace OHOS
 {
@@ -12,7 +13,11 @@ namespace OHOS
     static bool switch_flag = false;
 
 
-    FlashlightModel::FlashlightModel() {}
+    FlashlightModel::FlashlightModel()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:", __LINE__);
+        OHOS::ConfigModel::GetInstance()->GetFlashLightConfigData(&ColorIndex_, &ColorValue_, &FlashingLevel_);
+    }
 
     FlashlightModel::~FlashlightModel() {}
 
@@ -22,6 +27,11 @@ namespace OHOS
         return instance;
     }
 
+    void FlashlightModel::SaveSettingInfo(void)
+    {
+        OHOS::ConfigModel::GetInstance()->SetFlashLightConfigData(ColorIndex_, ColorValue_, FlashingLevel_);
+    }
+
     uint8_t FlashlightModel::GetColorIndex(void)
     {
         return ColorIndex_;
@@ -140,52 +150,24 @@ namespace OHOS
      */
     void FlashlightModel::FlashlightStopTimer(void)
     {
-        // 检查定时器是否存在
-        if (g_timer != NULL)
-        {
-            // 删除定时器并置为 NULL
-            osStatus_t ret = osTimerDelete(g_timer);
-            if (ret != osOK)
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret);
-            }
-            g_timer = NULL;
-        }
-    }
-    /*
-     * @brief 暂停定时器
-     */
-    void FlashlightModel::FlashlightPauseTimer(void)
-    {
-        // 检查定时器是否存在
         if (g_timer != NULL)
         {
-            // 暂停定时器,但不删除它
-            osStatus_t ret = osTimerStop(g_timer);
+            osStatus_t ret = osOK;
+            ret = osTimerStop(g_timer);
             if (ret != osOK)
             {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightPauseTimer osTimerStop failed, ret = %lx!!", ret);
+                return;
             }
-        }
-    }
-
-    /*
-     * @brief 恢复定时器
-     */
-    void FlashlightModel::FlashlightResumeTimer(uint32_t interval)
-    {
-        // 检查定时器是否存在
-        if (g_timer != NULL)
-        {
-            int tick = osMs2Tick(interval);
-            // 恢复定时器
-            osStatus_t ret = osTimerStart(g_timer, tick);
+            // 删除定时器并置为 NULL
+            ret = osTimerDelete(g_timer);
             if (ret != osOK)
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightResumeTimer osTimerStart failed, ret = %lx!!", ret);
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret);
+                return;
             }
+            g_timer = NULL;
         }
     }
 
-
 }
\ No newline at end of file
index 96b22f4..dfef7f2 100644 (file)
@@ -66,11 +66,12 @@ namespace OHOS
 
         ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
         FlashlightModel::GetInstance().FlashlightStopTimer();
+        FlashlightModel::GetInstance().SaveSettingInfo();
     }
 
     bool FlashlightPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnDrag");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnDrag");
         UNUSED(view);
         if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
         {
@@ -81,7 +82,7 @@ namespace OHOS
 
     bool FlashlightPresenter::OnDragEnd(UIView &view, const DragEvent &event)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnDragEnd");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnDragEnd");
         UNUSED(view);
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && FlashlightPresenter::X_DRAG_FLAG)
         {
@@ -109,7 +110,7 @@ namespace OHOS
 
     bool FlashlightPresenter::OnClick(UIView &view, const ClickEvent &event)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnClick");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnClick");
         UNUSED(event);
 
         if(0 == strcmp(Flashlight_ViewId_ImageColorSetting_, view.GetViewId()))
@@ -129,8 +130,6 @@ namespace OHOS
             if(0 == strcmp(Flashlight_ViewId_FlashingSettingItem_[i], view.GetViewId()))
             {
                 FlashlightModel::GetInstance().SetFlashingLevel(i);
-                // view_->UpdateFlashingSettingItem();
-                // view_->DisplayFlashingSettingScreen();
                 view_->DisplayViewMainScreen();
                 return true;
             }
@@ -140,7 +139,7 @@ namespace OHOS
         {
             if(0 == strcmp(Flashlight_ViewId_ImageColorSettingItem_[COLOR_SETTING_ITEM_COUNT - 1], view.GetViewId()))
             {
-                FlashlightModel::GetInstance().SetColorIndex(i);
+                FlashlightModel::GetInstance().SetColorIndex(COLOR_SETTING_ITEM_COUNT - 1);
                 view_->DisplayColorCustomScreen();
                 return true;
             }
@@ -154,13 +153,27 @@ namespace OHOS
             }
         }
 
+        if(0 == strcmp(Flashlight_ViewId_ImageColorCustomBackground_, view.GetViewId()))
+        {
+            Point point = event.GetCurrentPos();
+            int64_t value = -1;
+            view_->GetValueByColorCustomSelectedImage(point.x, point.y, &value);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnClick.value=%d", value);
+            if(0 > value)
+                return false;
+
+            FlashlightModel::GetInstance().SetColorValue(value);
+            view_->DisplayViewMainScreen();
+            return true;
+        }
+
         return true;
     }
 
     // 增加按键事件
     bool FlashlightPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnKeyAct");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnKeyAct");
         uint16_t keyID = event.GetKeyId();
         uint16_t keyState = event.GetState();
         // 如果是power键就返回上一级
index e317e85..885f26f 100644 (file)
@@ -10,6 +10,7 @@
 #include "ui_resource_string.h"
 #include "UiConfig.h"
 #include "custom_utils.h"
+#include "common/image_cache_manager.h"
 
 namespace OHOS
 {
@@ -500,10 +501,17 @@ namespace OHOS
             delete GroupColorCustom_;
             GroupColorCustom_ = nullptr;
 
-            if(nullptr != ImageColorCustom_)
+            if(nullptr != ImageColorCustomBackground_)
             {
-                delete ImageColorCustom_;
-                ImageColorCustom_ = nullptr;
+                ImageCacheManager::GetInstance().UnloadSingleRes(COLOR_CUSTOM_BACKGROUND_IMAGE);
+
+                delete ImageColorCustomBackground_;
+                ImageColorCustomBackground_ = nullptr;
+            }
+            if(nullptr != ImageColorCustomSelected_)
+            {
+                delete ImageColorCustomSelected_;
+                ImageColorCustomSelected_ = nullptr;
             }
         }
     }
@@ -524,13 +532,35 @@ namespace OHOS
             GroupColorCustom_->SetDraggable(true);
             GroupColorCustom_->SetOnDragListener(presenter_);
 
-            if(nullptr == ImageColorCustom_)
+            if(nullptr == ImageColorCustomBackground_)
             {
-                ImageColorCustom_ = new UIImageView;
-                if(nullptr == ImageColorCustom_)
+                ImageColorCustomBackground_ = new UIImageView;
+                if(nullptr == ImageColorCustomBackground_)
                     return nullptr;
 
-                ImageColorCustom_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+                ImageColorCustomBackground_->SetViewId(Flashlight_ViewId_ImageColorCustomBackground_);
+                ImageColorCustomBackground_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+                ImageInfo* info = ImageCacheManager::GetInstance().LoadSingleRes(COLOR_CUSTOM_BACKGROUND_IMAGE);
+                ImageColorCustomBackground_->SetSrc(info);
+                ImageColorCustomBackground_->SetTouchable(true);
+                ImageColorCustomBackground_->SetOnClickListener(presenter_);
+
+                GroupColorCustom_->Add(ImageColorCustomBackground_);
+            }
+            if(nullptr == ImageColorCustomSelected_)
+            {
+                ImageColorCustomSelected_ = new UIImageView();
+                if(nullptr == ImageColorCustomSelected_)
+                    return nullptr;
+
+                int16_t x = -1;
+                int16_t y = -1;
+                int64_t value = presenter_->GetColorValue();
+                GetPointByColorCustomSelectedImage(&x, &y, value);
+                ImageColorCustomSelected_->SetPosition(x, y, 70, 70);
+                ImageColorCustomSelected_->SetSrc(COLOR_CUSTOM_SELECTED_IMAGE);
+
+                GroupColorCustom_->Add(ImageColorCustomSelected_);
             }
 
             container_->Add(GroupColorCustom_);
@@ -539,6 +569,69 @@ namespace OHOS
         return GroupColorCustom_;
     }
 
+    void FlashlightView::GetValueByColorCustomSelectedImage(int16_t x, int16_t y, int64_t * value)
+    {
+        * value = -1;
+
+        if(nullptr == ImageColorCustomSelected_)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return ;
+        }            
+        if(nullptr == ImageColorCustomBackground_)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return ;
+        } 
+        const ImageInfo * info = ImageColorCustomBackground_->GetImageInfo();
+        if(nullptr == info)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return ;
+        } 
+// 
+// 
+// 
+//  待实现功能
+//  获得 (x,y) 处的颜色值
+//  赋值给 value
+// 
+// 
+// 
+    }
+
+    void FlashlightView::GetPointByColorCustomSelectedImage(int16_t * x, int16_t * y, int64_t value)
+    {
+        * x = -1;
+        * y = -1;
+
+        if(nullptr == ImageColorCustomSelected_)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return ;
+        }            
+        if(nullptr == ImageColorCustomBackground_)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return ;
+        } 
+        const ImageInfo * info = ImageColorCustomBackground_->GetImageInfo();
+        if(nullptr == info)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return ;
+        } 
+// 
+// 
+// 
+//  待实现功能
+//  根据给定的颜色值
+//  获得对应的 (x,y)值
+// 
+// 
+// 
+    }    
+
     void FlashlightView::DeinitFlashingSettingData()
     {
         if(nullptr != ScrollFlashingSetting_)
diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/flashlight/color_custom_bg.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/flashlight/color_custom_bg.bin
new file mode 100644 (file)
index 0000000..59e1c5a
--- /dev/null
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:50e7503c027d75d76a2e75b6cc072d99c905fe85aeb41181ae711b5aa9183599
+size 146040
diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/flashlight/color_custom_selected.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/flashlight/color_custom_selected.bin
new file mode 100644 (file)
index 0000000..dc3d000
--- /dev/null
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a7afdeb79c87a94eb6f14864cfccff79b9473435206577eb4218c7cb5106ba4f
+size 3480
index 162c261..60d9723 100644 (file)
@@ -131,6 +131,12 @@ namespace OHOS
             CONFIGMODEL_ITEM_APPLIST_STYLE,//applist的显示样式
             CONFIGMODEL_ITEM_BLE_IOS_OR_ANDROID,//绑定设备为安卓或者ios 0:安卓 1:苹果
             CONFIGMODEL_ITEM_BR_PAIR,//br第一次绑定
+
+            // flashlight
+            CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_INDEX, // color index
+            CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_VALUE, // color value
+            CONFIGMODEL_ITEM_FLASHLIGHT_FLASHING_LEVEL, // flashing level
+
             CONFIGMODEL_ITEM_MAX,
 
            
@@ -277,6 +283,11 @@ namespace OHOS
         /* ---------------------------- 设置OpenAI APIKeys ---------------------------- */
         void SetOpenAIAPIKeys(const char * value);
         std::string GetOpenAIAPIKeys(void);
+
+        // flash light config data
+        void GetFlashLightConfigData(uint8_t * ColorIndex, int64_t * ColorValue, uint8_t * FlashingLevel);
+        void SetFlashLightConfigData(uint8_t ColorIndex, int64_t ColorValue, uint8_t FlashingLevel);
+
         /* --------------------------------- 用户配置信息 --------------------------------- */
         void SetUserAge(int age);
         int GetUserAge();
@@ -377,6 +388,10 @@ namespace OHOS
             {ConfigDataType::DATATYPE_STRING,     "applist_style",       "list"    }, //CONFIGMODEL_ITEM_APPLIST_STYLE 
             {ConfigDataType::DATATYPE_INT,     "android_or_ios",       "0"    },//CONFIGMODEL_ITEM_BLE_IOS_OR_ANDROID
             {ConfigDataType::DATATYPE_INT,         "br_pari"            ,     "0"},
+            {ConfigDataType::DATATYPE_INT,     "color_index",             "0" }, // CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_INDEX, // color index
+            {ConfigDataType::DATATYPE_INT,     "color_value",             "0" }, // CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_VALUE, // color value
+            {ConfigDataType::DATATYPE_INT,     "flashing_level",             "0" }, // CONFIGMODEL_ITEM_FLASHLIGHT_FLASHING_LEVEL, // flashing level
+
         };
         ConfigModel();                                        // 私有构造函数,确保无法在外部实例化
         ConfigModel(const ConfigModel &) = delete;            // 禁止拷贝构造
index 7cd6097..f1eeac9 100644 (file)
@@ -1169,6 +1169,22 @@ namespace OHOS
     {
        return get_configData_string(CONFIGMODEL_ITEM_OPEN_AI_API_KEYS);
     }
+
+    // flash light config data
+    void ConfigModel::GetFlashLightConfigData(uint8_t * ColorIndex, int64_t * ColorValue, uint8_t * FlashingLevel)
+    {
+        * ColorIndex = get_configData_int(CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_INDEX);
+        * ColorValue = get_configData_int(CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_VALUE);
+        * FlashingLevel = get_configData_int(CONFIGMODEL_ITEM_FLASHLIGHT_FLASHING_LEVEL);
+    }
+
+    void ConfigModel::SetFlashLightConfigData(uint8_t ColorIndex, int64_t ColorValue, uint8_t FlashingLevel)
+    {
+        set_condigData_Int(CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_INDEX, ColorIndex);
+        set_condigData_Int(CONFIGMODEL_ITEM_FLASHLIGHT_COLOR_VALUE, ColorValue);
+        set_condigData_Int(CONFIGMODEL_ITEM_FLASHLIGHT_FLASHING_LEVEL, FlashingLevel);
+    }
+
 /* -------------------------------------------------------------------------- */
     /*设置用户年龄[后续使用结构体统一配置]*/
     void ConfigModel::SetUserAge(int age)