手电筒slice合并提交
authorluozheng <1732036298@qq.com>
Wed, 26 Mar 2025 09:04:17 +0000 (17:04 +0800)
committerluozheng <1732036298@qq.com>
Wed, 26 Mar 2025 09:04:17 +0000 (17:04 +0800)
code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/include/FlashlightModel.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/include/FlashlightPresenter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/include/FlashlightView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightModel.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightPresenter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightView.cpp [new file with mode: 0644]

diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/include/FlashlightModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/include/FlashlightModel.h
new file mode 100644 (file)
index 0000000..650c84a
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-10 18:13:01
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-04-10 20:03:08
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashlight/include/FlashlightModel.h
+ */
+
+#include <cstdint>
+#ifndef FLASHLIGH_MODEL_H
+#define FLASHLIGH_MODEL_H
+
+namespace OHOS
+{
+    class FlashlightModel
+    {
+    public:
+        static FlashlightModel &GetInstance(void);
+
+        void SaveSettingInfo(void);
+        uint8_t GetColorIndex(void);
+        void SetColorIndex(uint8_t value);
+        int64_t GetColorValue(void);
+        void SetColorValue(int64_t value);
+        uint8_t GetFlashingLevel(void);
+        void SetFlashingLevel(uint8_t value);
+
+        void FlashlightStartTimer(void);
+        void FlashlightStopTimer(void);
+
+    private:
+        FlashlightModel();
+        FlashlightModel(const FlashlightModel &) = delete;
+        FlashlightModel &operator=(const FlashlightModel &) = delete;
+        virtual ~FlashlightModel();
+
+        uint8_t ColorIndex_{0}; // 0~5-fixed;6-custom
+        int64_t ColorValue_ = 0xffffffff; // background color
+        uint8_t FlashingLevel_ = 0; // 0-no; 1-quickly; 2-slowly
+    };
+}
+
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/include/FlashlightPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/include/FlashlightPresenter.h
new file mode 100644 (file)
index 0000000..8508e21
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-10 17:32:31
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-10-10 11:40:08
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashligh/include/FlashlightPresenter.h
+ */
+
+#ifndef FLASHLIGHT_PRESENTER_H
+#define FLASHLIGHT_PRESENTER_H
+
+#include "Presenter.h"
+#include "View.h"
+#include "flashlight/include/FlashlightView.h"
+#include "components/ui_swipe_view.h"
+
+namespace OHOS
+{
+    #define Flashlight_ViewId_ImageColorSetting_ "Flashlight_ViewId_ImageColorSetting_"
+    #define Flashlight_ViewId_ImageFlashingSetting_ "Flashlight_ViewId_ImageFlashingSetting_"
+
+    #define Flashlight_ViewId_GroupColorSetting_ "Flashlight_ViewId_GroupColorSetting_"
+    #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] = 
+                                                    {
+                                                        "Flashlight_ViewId_FlashingSettingItem0_", 
+                                                        "Flashlight_ViewId_FlashingSettingItem1_", 
+                                                        "Flashlight_ViewId_FlashingSettingItem2_"
+                                                    };
+
+    #define COLOR_SETTING_ITEM_COUNT (6)
+    constexpr char * Flashlight_ViewId_ImageColorSettingItem_[COLOR_SETTING_ITEM_COUNT] = 
+                                                    {
+                                                        "Flashlight_ViewId_ImageColorSettingItem0_", 
+                                                        "Flashlight_ViewId_ImageColorSettingItem1_", 
+                                                        "Flashlight_ViewId_ImageColorSettingItem2_", 
+                                                        "Flashlight_ViewId_ImageColorSettingItem3_", 
+                                                        "Flashlight_ViewId_ImageColorSettingItem4_", 
+                                                        "Flashlight_ViewId_ImageColorSettingItem5_"
+                                                    };
+
+    constexpr int64_t ColorValue_ColorSettingItem_[COLOR_SETTING_ITEM_COUNT] = 
+                                                    {
+                                                        0xffffffff, 0xffff5a36, 0xff4fc34c,
+                                                        0xff3549ff, 0xffff8a36, 0xff8120e2
+                                                    };
+
+
+    class FlashlightView;
+    class FlashlightPresenter : public Presenter<FlashlightView>,
+                                public UIView::OnClickListener,
+                                public RootView::OnKeyActListener,
+                                public UIView::OnDragListener,
+                                public UISwipeView::OnSwipeListener
+    {
+    public:
+        FlashlightPresenter();
+        virtual ~FlashlightPresenter();
+        static FlashlightPresenter * GetInstance();
+
+        void OnStart() override;
+        uint8_t GetColorIndex(void);
+        int64_t GetColorValue(void);
+        uint8_t GetFlashingLevel(void);
+        void UpdateViewMainScreenFlashing(bool flag);
+        void StartFlashingTimer(void);
+
+    private:
+        bool OnClick(UIView &view, const ClickEvent &event) override;
+        bool OnDrag(UIView &view, const DragEvent &event) override;
+        bool OnDragEnd(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
+        bool X_DRAG_FLAG{false};
+        void OnSwipe(UISwipeView &view);
+    };
+}
+
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/include/FlashlightView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/include/FlashlightView.h
new file mode 100644 (file)
index 0000000..cd0b39b
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-10 17:32:02
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-10-10 11:42:10
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashligh/include/FlashlightView.h
+ */
+
+#ifndef FLASHLIGH_VIEW_H
+#define FLASHLIGH_VIEW_H
+
+
+#include "View.h"
+#include "flashlight/include/FlashlightPresenter.h"
+
+#include "components/ui_scroll_view.h"
+#include "components/ui_image_view.h"
+#include "components/ui_swipe_view.h"
+#include "components/ui_label_button_ext.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_radio_button.h"
+
+namespace OHOS
+{
+    class FlashlightPresenter;
+    class FlashlightView : public View<FlashlightPresenter>
+    {
+
+    public:
+        FlashlightView();
+        virtual ~FlashlightView();
+        static FlashlightView *GetInstance(void);
+
+        void OnStart() override;
+
+        void DisplayViewMainScreen();
+        void DisplayViewSettingScreen();
+        void DisplayColorSettingScreen();
+        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);
+        void UpdateViewMainScreenColor();
+
+        typedef enum
+        {
+            ENUM_FLASHLIGHT_SCREEN_VIEW_MAIN,
+            ENUM_FLASHLIGHT_SCREEN_VIEW_SETTING,
+            ENUM_FLASHLIGHT_SCREEN_COLOR_SETTING,
+            ENUM_FLASHLIGHT_SCREEN_COLOR_CUSTOM,
+            ENUM_FLASHLIGHT_SCREEN_FLASHING_SETTING,
+
+            ENUM_FLASHLIGHT_SCREEN_MAX
+        }ENUM_FLASHLIGHT_SCREEN;
+
+        UIViewGroup * InitSwipeData();
+        UIViewGroup * InitColorSettingData();
+        UIViewGroup * InitColorCustomData();
+        UIViewGroup * InitFlashingSettingData();
+
+    private:
+        UILabelExt * CreateUILabelExt(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t text_id,
+                                        int64_t font_size, int64_t line_height, int64_t color_value,
+                                        UITextLanguageAlignment hor_align, UITextLanguageAlignment ver_align);
+        UIRadioButton * CreateUIRadioButtonItem(int16_t x, int16_t y, int16_t w, int16_t h);
+        UIViewGroup * CreateUIGroupItem(char * id, int16_t x, int16_t y, int16_t w, int16_t h);
+        UIImageView * CreateImageColorSettingItem_(char * id, int16_t x, int16_t y, int16_t w, int16_t h, char * src);
+
+        
+        UIViewGroup* group{nullptr};
+
+        void DeinitSwipeData();
+        // UISwipeView * InitSwipeData();
+        UISwipeView * SwipeView_{nullptr};
+
+        void DeinitViewMainData();
+        UIViewGroup * InitViewMainData();
+        void UpdateViewMainScreen(void);
+        UIViewGroup * GroupMain_{nullptr};
+        UIImageView * ImageArrow_{nullptr};
+
+        void DeinitViewSettingData();
+        UIViewGroup * InitViewSettingData();
+        UIViewGroup * GroupSetting_{nullptr};
+        UILabelExt * LabelTitle_{nullptr};
+        UIImageView * ImageColorSetting_{nullptr};
+        UIImageView * ImageFlashingSetting_{nullptr};
+        UILabelExt * LabelColorSetting_{nullptr};
+        UILabelExt * LabelFlashingSetting_{nullptr};
+
+        void DeinitColorSettingData();
+        // UIViewGroup * InitColorSettingData();
+        void UpdateColorSettingItem(void);
+        UIViewGroup * GroupColorSetting_{nullptr};
+        UILabelExt * LabelColorSettingTitle_{nullptr};
+        #define COLOR_SETTING_ITEM_COUNT (6)
+        UIImageView * ImageColorSettingItem_[COLOR_SETTING_ITEM_COUNT][2]{nullptr};
+
+        void DeinitColorCustomData();
+        // UIViewGroup * InitColorCustomData();
+        // void UpdateColorCustomSelectedImage(int16_t x, int16_t y);
+        UIViewGroup * GroupColorCustom_{nullptr};
+        UIImageView * ImageColorCustomBackground_{nullptr};
+        UIImageView * ImageColorCustomSelected_{nullptr};
+
+        void DeinitFlashingSettingData();
+        // UIScrollView * InitFlashingSettingData();
+        void UpdateFlashingSettingItem(void);
+        UIScrollView * ScrollFlashingSetting_{nullptr};
+        UILabelExt * LabelFlashingSettingTitle_{nullptr};
+        #define FLASHING_SETTING_ITEM_COUNT (3)
+        UIViewGroup * GroupFlashingSettingItem_[FLASHING_SETTING_ITEM_COUNT]{nullptr};
+        UILabelExt * LabelFlashingSettingItem_[FLASHING_SETTING_ITEM_COUNT]{nullptr};
+        UIRadioButton * RadioButtonFlashingSettingItem_[FLASHING_SETTING_ITEM_COUNT]{nullptr};        
+
+        void DisplaySelectScreen(uint8_t ScreenIndex);
+        UIViewGroup * ScreenGroupArray_[ENUM_FLASHLIGHT_SCREEN_MAX]{nullptr};
+
+
+        #define SCREEN_WIDTH (Screen::GetInstance().GetWidth())
+        #define SCREEN_HEIGHT (Screen::GetInstance().GetHeight())
+
+        #define UP_ARROW_IMAGE "/user/res/flashlight/up_arrow.bin"
+        #define COLOR_SETTING_IMAGE "/user/res/flashlight/color_setting.bin"
+        #define FLASHING_SETTING_IMAGE "/user/res/flashlight/flahing_setting.bin"
+
+        #define COLOR_SETTING_SELECTED_IMAGE "/user/res/flashlight/color_selected.bin"
+        char * ImageColorSettingItemSrc_[COLOR_SETTING_ITEM_COUNT] = 
+                                                    {
+                                                        "/user/res/flashlight/color_0.bin", 
+                                                        "/user/res/flashlight/color_1.bin", 
+                                                        "/user/res/flashlight/color_2.bin", 
+                                                        "/user/res/flashlight/color_3.bin", 
+                                                        "/user/res/flashlight/color_4.bin", 
+                                                        // "/user/res/flashlight/color_5.bin", //自定义颜色
+                                                        "/user/res/flashlight/color_6.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
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightModel.cpp
new file mode 100644 (file)
index 0000000..efc657c
--- /dev/null
@@ -0,0 +1,177 @@
+
+#include "graphic_service.h"
+#include <cmsis_os2.h>
+#include <cmsis_os.h>
+#include "wearable_log.h"
+#include "flashlight/include/FlashlightModel.h"
+#include "flashlight/include/FlashlightPresenter.h"
+#include "ConfigModel.h"
+
+namespace OHOS
+{
+    static osTimerId_t g_timer = NULL;
+    static bool switch_flag = false;
+
+
+    FlashlightModel::FlashlightModel()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:", __LINE__);
+        OHOS::ConfigModel::GetInstance()->GetFlashLightConfigData(&ColorIndex_, &ColorValue_, &FlashingLevel_);
+    }
+
+    FlashlightModel::~FlashlightModel() {}
+
+    FlashlightModel &FlashlightModel::GetInstance()
+    {
+        static FlashlightModel instance;
+        return instance;
+    }
+
+    void FlashlightModel::SaveSettingInfo(void)
+    {
+        OHOS::ConfigModel::GetInstance()->SetFlashLightConfigData(ColorIndex_, ColorValue_, FlashingLevel_);
+    }
+
+    uint8_t FlashlightModel::GetColorIndex(void)
+    {
+        return ColorIndex_;
+    }
+
+    void FlashlightModel::SetColorIndex(uint8_t value)
+    {
+        ColorIndex_ = value;
+    }
+
+    int64_t FlashlightModel::GetColorValue(void)
+    {
+        if((COLOR_SETTING_ITEM_COUNT - 1) > ColorIndex_)
+            return ColorValue_ColorSettingItem_[ColorIndex_];
+
+        return ColorValue_;
+    }
+
+    void FlashlightModel::SetColorValue(int64_t value)
+    {
+        ColorValue_ = value;
+    }
+
+    uint8_t FlashlightModel::GetFlashingLevel(void)
+    {
+        return FlashingLevel_;
+    }
+
+    void FlashlightModel::SetFlashingLevel(uint8_t value)
+    {
+        FlashingLevel_ = value;
+    }    
+
+
+    static void FlashlightTimerCallbackProc(int data)
+    {
+        switch_flag = !(switch_flag);
+        if(FlashlightPresenter::GetInstance())
+        {
+            FlashlightPresenter::GetInstance()->UpdateViewMainScreenFlashing(switch_flag);
+        }
+    }
+
+    /*
+     * @brief 计时器回调函数
+     */
+    static void FlashlightTimerCallback(int data)
+    {
+        GraphicService::GetInstance()->PostGraphicEvent(std::bind(FlashlightTimerCallbackProc, data));
+    }
+
+    /*
+     *  @brief 开启定时器函数
+     *  @param interval 时间间隔,单位ms
+     */
+    void FlashlightModel::FlashlightStartTimer(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d", __LINE__, FlashingLevel_);
+        uint32_t interval = 0;
+        switch (FlashingLevel_)
+        {
+            case 0: // no
+                return;
+                break;
+
+            case 1: // quickly
+                interval = 500;
+                break;
+
+            case 2: // slowly
+                interval = 1000;
+                break;
+
+            default:
+                break;
+        }
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d", __LINE__, interval);
+
+        /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
+        if (g_timer != NULL)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightModel::FlashlightStartTimer Timer already exists!!");
+            return;
+        }
+
+        /* --------------------------------- 2.创建定时器 -------------------------------- */
+        g_timer = osTimerNew((osTimerFunc_t)FlashlightTimerCallback, osTimerPeriodic, NULL, NULL);
+        // 检查定时器创建是否成功
+        if (g_timer == NULL)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightModel::FlashlightStartTimer Timer create failed!!");
+            return;
+        }
+
+        /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */
+        int tick = osMs2Tick(interval);
+
+        /* --------------------------------- 4.启动定时器 -------------------------------- */
+        // g_timerStartTimestamp = GetCurrentTimestamp(); // 假设GetCurrentTimestamp()是获取当前时间戳的函数
+        osStatus_t ret = osTimerStart(g_timer, tick);
+        /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */
+        if (ret != osOK)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FlashlightStartTimer] osTimerDelete failed, ret = %lx!!", ret);
+            if (g_timer != NULL)
+            {
+                ret = osTimerDelete(g_timer);
+                if (ret != osOK)
+                {
+                    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret);
+                }
+                g_timer = NULL;
+            }
+        }
+    }
+
+    /*
+     * @brief 停止定时器
+     */
+    void FlashlightModel::FlashlightStopTimer(void)
+    {
+        if (g_timer != NULL)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightModel::FlashlightStopTimer");
+            osStatus_t ret = osOK;
+            ret = osTimerStop(g_timer);
+            if (ret != osOK)
+            {
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPauseTimer osTimerStop failed, ret = %lx!!", ret);
+                return;
+            }
+            // 删除定时器并置为 NULL
+            ret = osTimerDelete(g_timer);
+            if (ret != osOK)
+            {
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret);
+                return;
+            }
+            g_timer = NULL;
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightPresenter.cpp
new file mode 100644 (file)
index 0000000..fe26aed
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-10 17:32:38
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-11-05 14:19:14
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashligh/src/FlashlightPresenter.cpp
+ */
+
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+#include "UiConfig.h"
+#include "flashlight/include/FlashlightPresenter.h"
+#include "flashlight/include/FlashlightModel.h"
+#include "common/key_code.h"
+#include <custom_utils.h>
+#include "gfx_utils/mem_check.h"
+#include "ConfigModel.h"
+#include "NativeRegisterManager.h"
+#include "ui_resource_string.h"
+namespace OHOS
+{
+    REGIST_MENU_PRO(VIEW_FLASHLIGHT, FlashlightView, FlashlightPresenter,
+                    PNG_APPLIST_FLASHLIGHT_IMAGE_BIG, PNG_APPLIST_FLASHLIGHT_IMAGE, PNG_APPLIST_FLASHLIGHT_IMAGE, "手电筒", STR_FLASHLIGHT);
+
+#define IS_SUPPORT_CUSTOM_COLOR 0 // 是否支持自定义颜色
+
+    // 当前Presenter属性实例化的内存指针
+    static FlashlightPresenter *g_pFlashlightPresenter = nullptr;
+
+    FlashlightPresenter::FlashlightPresenter()
+    {
+        g_pFlashlightPresenter = this;
+#ifdef MEM_CHECK
+        MemCheck::GetInstance()->EnableLeakCheck(true);
+#endif
+    }
+
+    FlashlightPresenter::~FlashlightPresenter()
+    {
+        uapi_setScreenBrightness(ConfigModel::GetInstance()->GetBrightness()); // 退出APP将亮度恢复到ConfigModel中设置的亮度值
+        ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
+        FlashlightModel::GetInstance().FlashlightStopTimer();
+        FlashlightModel::GetInstance().SaveSettingInfo();
+        g_pFlashlightPresenter = nullptr;
+#ifdef MEM_CHECK
+        MemCheck::GetInstance()->EnableLeakCheck(false);
+#endif
+    }
+
+    FlashlightPresenter *FlashlightPresenter::GetInstance()
+    {
+        return g_pFlashlightPresenter;
+    }
+
+    void FlashlightPresenter::OnStart()
+    {
+        uapi_setScreenBrightness(MAX_BRIGHTNESS);
+        FlashlightModel::GetInstance().FlashlightStartTimer();
+        ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
+    }
+
+    bool FlashlightPresenter::OnDrag(UIView &view, const DragEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnDrag");
+        UNUSED(view);
+        if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
+        {
+            FlashlightPresenter::X_DRAG_FLAG = true;
+        }
+        return true;
+    }
+
+    bool FlashlightPresenter::OnDragEnd(UIView &view, const DragEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnDragEnd");
+        UNUSED(view);
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && FlashlightPresenter::X_DRAG_FLAG)
+        {
+            if (0 == strcmp(Flashlight_ViewId_GroupColorSetting_, view.GetViewId()))
+            {
+                view_->DisplayViewSettingScreen();
+                return true;
+            }
+            if (0 == strcmp(Flashlight_ViewId_GroupColorCustom_, view.GetViewId()))
+            {
+                view_->DisplayColorSettingScreen();
+                return true;
+            }
+            if (0 == strcmp(Flashlight_ViewId_ScrollFlashingSetting_, view.GetViewId()))
+            {
+                view_->DisplayViewSettingScreen();
+                return true;
+            }
+
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+            X_DRAG_FLAG = false;
+        }
+        return true;
+    }
+
+    bool FlashlightPresenter::OnClick(UIView &view, const ClickEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnClick");
+        UNUSED(event);
+
+        if (0 == strcmp(Flashlight_ViewId_ImageColorSetting_, view.GetViewId()))
+        {
+            view_->DisplayColorSettingScreen();
+            return true;
+        }
+        if (0 == strcmp(Flashlight_ViewId_ImageFlashingSetting_, view.GetViewId()))
+        {
+            view_->DisplayFlashingSettingScreen();
+            return true;
+        }
+
+        uint8_t i = 0;
+        for (i = 0; i < FLASHING_SETTING_ITEM_COUNT; i++)
+        {
+            if (0 == strcmp(Flashlight_ViewId_FlashingSettingItem_[i], view.GetViewId()))
+            {
+                FlashlightModel::GetInstance().SetFlashingLevel(i);
+                view_->DisplayViewMainScreen();
+                return true;
+            }
+        }
+
+        for (i = 0; i < COLOR_SETTING_ITEM_COUNT; i++)
+        {
+#if IS_SUPPORT_CUSTOM_COLOR
+            if (0 == strcmp(Flashlight_ViewId_ImageColorSettingItem_[COLOR_SETTING_ITEM_COUNT - 1], view.GetViewId()))
+            {
+                FlashlightModel::GetInstance().SetColorIndex(COLOR_SETTING_ITEM_COUNT - 1);
+                view_->DisplayColorCustomScreen();
+                return true;
+            }
+#endif
+            if (0 == strcmp(Flashlight_ViewId_ImageColorSettingItem_[i], view.GetViewId()))
+            {
+                FlashlightModel::GetInstance().SetColorIndex(i);
+                FlashlightModel::GetInstance().SetColorValue(ColorValue_ColorSettingItem_[i]);
+                view_->DisplayViewMainScreen();
+                return true;
+            }
+        }
+
+#if IS_SUPPORT_CUSTOM_COLOR
+        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;
+        }
+#endif
+        return true;
+    }
+
+    // 增加按键事件
+    bool FlashlightPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnKeyAct");
+        uint16_t keyID = event.GetKeyId();
+        uint16_t keyState = event.GetState();
+        // 如果是power键就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+        }
+        return true;
+    }
+
+    void FlashlightPresenter::OnSwipe(UISwipeView &view)
+    {
+        UNUSED(view);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightPresenter::OnSwipe");
+
+        if (0 == view.GetCurrentPage())
+        {
+            uapi_setScreenBrightness(MAX_BRIGHTNESS); // 恢复最高亮度
+            FlashlightModel::GetInstance().FlashlightStartTimer();
+            ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
+        }
+        else
+        {
+            uapi_setScreenBrightness(ConfigModel::GetInstance()->GetBrightness()); // 滑动到手电筒设置页面需要将亮度恢复到ConfigModel中设置的亮度值
+            FlashlightModel::GetInstance().FlashlightStopTimer();
+            ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
+        }
+    }
+
+    uint8_t FlashlightPresenter::GetColorIndex(void)
+    {
+        return FlashlightModel::GetInstance().GetColorIndex();
+    }
+
+    int64_t FlashlightPresenter::GetColorValue(void)
+    {
+        return FlashlightModel::GetInstance().GetColorValue();
+    }
+
+    uint8_t FlashlightPresenter::GetFlashingLevel(void)
+    {
+        return FlashlightModel::GetInstance().GetFlashingLevel();
+    }
+
+    void FlashlightPresenter::StartFlashingTimer(void)
+    {
+        FlashlightModel::GetInstance().FlashlightStartTimer();
+    }
+
+    void FlashlightPresenter::UpdateViewMainScreenFlashing(bool flag)
+    {
+        if (view_)
+        {
+            view_->UpdateViewMainScreenFlashing(flag);
+        }
+    }
+}
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightView.cpp
new file mode 100644 (file)
index 0000000..10c19ea
--- /dev/null
@@ -0,0 +1,878 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-10 17:32:08
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2025-02-24 18:44:55
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/flashligh/src/FlashlightView.cpp
+ */
+#include "flashlight/include/FlashlightView.h"
+#include "wearable_log.h"
+#include "ui_resource_string.h"
+#include "UiConfig.h"
+#include "custom_utils.h"
+#include "common/image_cache_manager.h"
+#include "ConfigModel.h"
+#include "flashlight/include/FlashlightModel.h"
+namespace OHOS
+{
+
+    static FlashlightView *g_pFlashlightView{nullptr};
+
+    FlashlightView::FlashlightView()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightView::FlashlightView");
+        g_pFlashlightView = this;
+    }
+
+    FlashlightView::~FlashlightView()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightView::~FlashlightView");
+        if (group)
+        {
+            group->RemoveAll();
+            delete group;
+            group = nullptr;
+        }
+        DeinitSwipeData();
+        DeinitColorSettingData();
+        DeinitFlashingSettingData();
+        g_pFlashlightView = nullptr;
+    }
+
+    FlashlightView *FlashlightView::GetInstance()
+    {
+        return g_pFlashlightView;
+    }
+
+    void FlashlightView::OnStart()
+    {
+        if (nullptr == group)
+        {
+            group = new UIViewGroup();
+            if (nullptr == group)
+            {
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+                return;
+            }
+            group->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+            group->SetTouchable(true);
+            group->SetDraggable(true);
+            group->SetOnDragListener(presenter_);
+            AddViewToRootContainer(group);
+        }
+        InitSwipeData();
+    }
+
+    void FlashlightView::DeinitSwipeData()
+    {
+        if (nullptr != SwipeView_)
+        {
+            SwipeView_->RemoveAll();
+            delete SwipeView_;
+            SwipeView_ = nullptr;
+
+            DeinitViewMainData();
+            DeinitViewSettingData();
+        }
+    }
+
+    UIViewGroup *FlashlightView::InitSwipeData()
+    {
+        if (nullptr == SwipeView_)
+        {
+            SwipeView_ = new UISwipeView(UISwipeView::VERTICAL);
+            if (nullptr == SwipeView_)
+            {
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+                return nullptr;
+            }
+            SwipeView_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+            SwipeView_->SetTouchable(true);
+            SwipeView_->SetDraggable(true);
+            // SwipeView_->SetThrowDrag(true);
+            SwipeView_->SetOnSwipeListener(presenter_);
+            SwipeView_->SetAnimatorTime(50); // 200:animator drag time(ms)
+            SwipeView_->SetOnDragListener(presenter_);
+            SwipeView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+            SwipeView_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+            SwipeView_->SetStyle(STYLE_BORDER_RADIUS, 100);
+            SwipeView_->SetBlankSize(0);
+
+            UIViewGroup *temp_0 = InitViewMainData();
+            if (nullptr == temp_0)
+                return nullptr;
+            SwipeView_->Add(temp_0);
+
+            UIViewGroup *temp_1 = InitViewSettingData();
+            if (nullptr == temp_1)
+                return nullptr;
+            SwipeView_->Add(temp_1);
+
+            SwipeView_->SetCurrentPage(0);
+            SwipeView_->SetIntercept(false);
+            SwipeView_->SetLoopState(false);
+
+            group->Add(SwipeView_);
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightView::InitSwipeData");
+        }
+
+        return dynamic_cast<UIViewGroup *>(SwipeView_);
+        // return SwipeView_;
+    }
+
+    void FlashlightView::DeinitViewMainData()
+    {
+        if (nullptr != GroupMain_)
+        {
+            GroupMain_->RemoveAll();
+            delete GroupMain_;
+            GroupMain_ = nullptr;
+
+            if (nullptr != ImageArrow_)
+            {
+                delete ImageArrow_;
+                ImageArrow_ = nullptr;
+            }
+        }
+    }
+
+    UIViewGroup *FlashlightView::InitViewMainData(void)
+    {
+        if (nullptr == GroupMain_)
+        {
+            GroupMain_ = new UIViewGroup();
+            if (nullptr == GroupMain_)
+                return nullptr;
+
+            GroupMain_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+            // GroupMain_->SetViewId(S_ViewId_NoDataGroup_);
+            GroupMain_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+            GroupMain_->SetStyle(STYLE_BACKGROUND_COLOR, presenter_->GetColorValue());
+            GroupMain_->SetTouchable(true);
+            GroupMain_->SetDraggable(true);
+            GroupMain_->SetOnDragListener(presenter_);
+
+            if (nullptr == ImageArrow_)
+            {
+                ImageArrow_ = new UIImageView();
+                if (nullptr == ImageArrow_)
+                    return nullptr;
+
+                ImageArrow_->SetPosition(211, 430, 40, 20);
+                ImageArrow_->SetSrc(UP_ARROW_IMAGE);
+            }
+
+            GroupMain_->Add(ImageArrow_);
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightView::InitViewMainData");
+        }
+
+        return GroupMain_;
+    }
+
+    void FlashlightView::UpdateViewMainScreenFlashing(bool flag)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+        if (nullptr == GroupMain_)
+            return;
+
+        if (false == GroupMain_->IsVisible())
+            return;
+
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]:%d", __LINE__, flag);
+        if (true == flag)
+        {
+            // GroupMain_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+            uapi_setScreenBrightness(MAX_BRIGHTNESS_HALF); // 50%
+        }
+        else
+        {
+            // GroupMain_->SetStyle(STYLE_BACKGROUND_COLOR, presenter_->GetColorValue());
+            uapi_setScreenBrightness(MAX_BRIGHTNESS); // 100%
+        }
+
+        Draw();
+    }
+
+    void FlashlightView::UpdateViewMainScreenColor()
+    {
+        if (GroupMain_)
+        {
+            GroupMain_->SetStyle(STYLE_BACKGROUND_COLOR, presenter_->GetColorValue());
+        }
+    }
+
+    void FlashlightView::UpdateViewMainScreen(void)
+    {
+        if (nullptr == SwipeView_)
+            return;
+
+        SwipeView_->SetCurrentPage(0);
+
+        UpdateViewMainScreenColor();
+        if (0 == presenter_->GetFlashingLevel())
+            UpdateViewMainScreenFlashing(false);
+        else
+            presenter_->StartFlashingTimer();
+    }
+
+    void FlashlightView::DeinitViewSettingData()
+    {
+        if (nullptr != GroupSetting_)
+        {
+            GroupSetting_->RemoveAll();
+            delete GroupSetting_;
+            GroupSetting_ = nullptr;
+
+            if (nullptr != LabelTitle_)
+            {
+                delete LabelTitle_;
+                LabelTitle_ = nullptr;
+            }
+            if (nullptr != ImageColorSetting_)
+            {
+                delete ImageColorSetting_;
+                ImageColorSetting_ = nullptr;
+            }
+            if (nullptr != ImageFlashingSetting_)
+            {
+                delete ImageFlashingSetting_;
+                ImageFlashingSetting_ = nullptr;
+            }
+            if (nullptr != LabelColorSetting_)
+            {
+                delete LabelColorSetting_;
+                LabelColorSetting_ = nullptr;
+            }
+            if (nullptr != LabelFlashingSetting_)
+            {
+                delete LabelFlashingSetting_;
+                LabelFlashingSetting_ = nullptr;
+            }
+        }
+    }
+
+    UIViewGroup *FlashlightView::InitViewSettingData()
+    {
+        if (nullptr == GroupSetting_)
+        {
+            GroupSetting_ = new UIViewGroup();
+            if (nullptr == GroupSetting_)
+                return nullptr;
+
+            // GroupSetting_->SetViewId(S_ViewId_NoDataGroup_);
+            GroupSetting_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+            GroupSetting_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+            GroupSetting_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+            GroupSetting_->SetTouchable(true);
+            GroupSetting_->SetDraggable(true);
+            GroupSetting_->SetOnDragListener(presenter_);
+
+            if (nullptr == LabelTitle_)
+            {
+                LabelTitle_ = CreateUILabelExt(83, 50, 300, 35, STR_FLASHLIGHT_SETTING, 30, 35, Color::White().full,
+                                               TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+                if (nullptr == LabelTitle_)
+                    return nullptr;
+            }
+
+            if (nullptr == ImageColorSetting_)
+            {
+                ImageColorSetting_ = new UIImageView();
+                if (nullptr == ImageColorSetting_)
+                    return nullptr;
+
+                ImageColorSetting_->SetViewId(Flashlight_ViewId_ImageColorSetting_);
+                ImageColorSetting_->SetPosition(60, 140, 160, 160);
+                ImageColorSetting_->SetSrc(COLOR_SETTING_IMAGE);
+                ImageColorSetting_->SetTouchable(true);
+                ImageColorSetting_->SetOnClickListener(presenter_);
+            }
+
+            if (nullptr == ImageFlashingSetting_)
+            {
+                ImageFlashingSetting_ = new UIImageView();
+                if (nullptr == ImageFlashingSetting_)
+                    return nullptr;
+
+                ImageFlashingSetting_->SetViewId(Flashlight_ViewId_ImageFlashingSetting_);
+                ImageFlashingSetting_->SetPosition(246, 140, 160, 160);
+                ImageFlashingSetting_->SetSrc(FLASHING_SETTING_IMAGE);
+                ImageFlashingSetting_->SetTouchable(true);
+                ImageFlashingSetting_->SetOnClickListener(presenter_);
+            }
+
+            if (nullptr == LabelColorSetting_)
+            {
+                LabelColorSetting_ = CreateUILabelExt(80, 320, 120, 35, STR_LIGHT_COLOR, 30, 35, 0xff999999,
+                                                      TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+                if (nullptr == LabelColorSetting_)
+                    return nullptr;
+            }
+
+            if (nullptr == LabelFlashingSetting_)
+            {
+                LabelFlashingSetting_ = CreateUILabelExt(266, 320, 120, 35, STR_FLICKER_FREQUENCY, 30, 35, 0xff999999,
+                                                         TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+                if (nullptr == LabelFlashingSetting_)
+                    return nullptr;
+            }
+
+            GroupSetting_->Add(LabelTitle_);
+            GroupSetting_->Add(ImageColorSetting_);
+            GroupSetting_->Add(ImageFlashingSetting_);
+            GroupSetting_->Add(LabelColorSetting_);
+            GroupSetting_->Add(LabelFlashingSetting_);
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FlashlightView::InitViewSettingData");
+        }
+
+        return GroupSetting_;
+    }
+
+    void FlashlightView::DeinitColorSettingData()
+    {
+        if (nullptr != GroupColorSetting_)
+        {
+            GroupColorSetting_->RemoveAll();
+            delete GroupColorSetting_;
+            GroupColorSetting_ = nullptr;
+
+            if (nullptr != LabelColorSettingTitle_)
+            {
+                delete LabelColorSettingTitle_;
+                LabelColorSettingTitle_ = nullptr;
+            }
+
+            uint8_t i = 0;
+            for (i = 0; i < COLOR_SETTING_ITEM_COUNT; i++)
+            {
+                if (nullptr != ImageColorSettingItem_[i][0])
+                {
+                    delete ImageColorSettingItem_[i][0];
+                    ImageColorSettingItem_[i][0] = nullptr;
+                }
+                if (nullptr != ImageColorSettingItem_[i][1])
+                {
+                    delete ImageColorSettingItem_[i][1];
+                    ImageColorSettingItem_[i][1] = nullptr;
+                }
+            }
+        }
+    }
+
+    UIViewGroup *FlashlightView::InitColorSettingData()
+    {
+        if (nullptr == GroupColorSetting_)
+        {
+            GroupColorSetting_ = new UIViewGroup();
+            if (nullptr == GroupColorSetting_)
+                return nullptr;
+
+            GroupColorSetting_->SetViewId(Flashlight_ViewId_GroupColorSetting_);
+            GroupColorSetting_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+            GroupColorSetting_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+            GroupColorSetting_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+            GroupColorSetting_->SetTouchable(true);
+            GroupColorSetting_->SetDraggable(true);
+            GroupColorSetting_->SetOnDragListener(presenter_);
+
+            if (nullptr == LabelColorSettingTitle_)
+            {
+                LabelColorSettingTitle_ = CreateUILabelExt(83, 50, 300, 35, STR_LIGHT_COLOR, 30, 35, Color::White().full,
+                                                           TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+                if (nullptr == LabelColorSettingTitle_)
+                    return nullptr;
+            }
+            GroupColorSetting_->Add(LabelColorSettingTitle_);
+
+            uint8_t i = 0;
+            for (i = 0; i < COLOR_SETTING_ITEM_COUNT; i++)
+            {
+                int16_t x = 0;
+                int16_t y = 0;
+
+                switch (i)
+                {
+                case 0:
+                case 1:
+                case 2:
+                    x = 43 + (120 + 10) * i;
+                    y = 130;
+                    ImageColorSettingItem_[i][0] =
+                        CreateImageColorSettingItem_(nullptr, x, y, 120, 120, COLOR_SETTING_SELECTED_IMAGE);
+                    GroupColorSetting_->Add(ImageColorSettingItem_[i][0]);
+                    x = 43 + (120 + 10) * i + 10;
+                    y = 130 + 10;
+                    ImageColorSettingItem_[i][1] =
+                        CreateImageColorSettingItem_(Flashlight_ViewId_ImageColorSettingItem_[i],
+                                                     x, y, 100, 100, ImageColorSettingItemSrc_[i]);
+                    GroupColorSetting_->Add(ImageColorSettingItem_[i][1]);
+                    break;
+
+                case 3:
+                case 4:
+                    x = 43 + (120 + 10) * (i - 3);
+                    y = 260;
+                    ImageColorSettingItem_[i][0] =
+                        CreateImageColorSettingItem_(nullptr, x, y, 120, 120, COLOR_SETTING_SELECTED_IMAGE);
+                    GroupColorSetting_->Add(ImageColorSettingItem_[i][0]);
+                    x = 43 + (120 + 10) * (i - 3) + 10;
+                    y = 260 + 10;
+                    ImageColorSettingItem_[i][1] =
+                        CreateImageColorSettingItem_(Flashlight_ViewId_ImageColorSettingItem_[i],
+                                                     x, y, 100, 100, ImageColorSettingItemSrc_[i]);
+                    GroupColorSetting_->Add(ImageColorSettingItem_[i][1]);
+                    break;
+
+                case 5:
+                    x = 43 + (120 + 10) * (i - 3);
+                    y = 260;
+                    ImageColorSettingItem_[i][0] =
+                        CreateImageColorSettingItem_(nullptr, x, y, 120, 120, COLOR_SETTING_SELECTED_IMAGE);
+                    GroupColorSetting_->Add(ImageColorSettingItem_[i][0]);
+                    x = 43 + (120 + 10) * (i - 3) + 20;
+                    y = 260 + 20;
+                    ImageColorSettingItem_[i][1] =
+                        CreateImageColorSettingItem_(Flashlight_ViewId_ImageColorSettingItem_[i],
+                                                     x, y, 80, 80, ImageColorSettingItemSrc_[i]);
+                    GroupColorSetting_->Add(ImageColorSettingItem_[i][1]);
+                    break;
+                }
+                if (presenter_->GetColorIndex() == i)
+                    ImageColorSettingItem_[i][0]->SetVisible(true);
+                else
+                    ImageColorSettingItem_[i][0]->SetVisible(false);
+
+                ImageColorSettingItem_[i][1]->SetVisible(true);
+            }
+
+            group->Add(GroupColorSetting_);
+        }
+
+        return GroupColorSetting_;
+    }
+
+    UIImageView *FlashlightView::CreateImageColorSettingItem_(char *id, int16_t x, int16_t y, int16_t w, int16_t h,
+                                                              char *src)
+    {
+        UIImageView *temp_UIImageView = new UIImageView();
+        if (nullptr == temp_UIImageView)
+            return nullptr;
+
+        if (nullptr != id)
+            temp_UIImageView->SetViewId(id);
+        temp_UIImageView->SetPosition(x, y, w, h);
+        temp_UIImageView->SetSrc(src);
+        temp_UIImageView->SetTouchable(true);
+        temp_UIImageView->SetOnClickListener(presenter_);
+
+        return temp_UIImageView;
+    }
+
+    void FlashlightView::UpdateColorSettingItem(void)
+    {
+        uint8_t i = 0;
+        for (i = 0; i < COLOR_SETTING_ITEM_COUNT; i++)
+        {
+            if (nullptr == ImageColorSettingItem_[i][0])
+                return;
+
+            if (presenter_->GetColorIndex() == i)
+                ImageColorSettingItem_[i][0]->SetVisible(true);
+            else
+                ImageColorSettingItem_[i][0]->SetVisible(false);
+        }
+    }
+
+    void FlashlightView::DeinitColorCustomData()
+    {
+        if (nullptr != GroupColorCustom_)
+        {
+            GroupColorCustom_->RemoveAll();
+            delete GroupColorCustom_;
+            GroupColorCustom_ = nullptr;
+
+            if (nullptr != ImageColorCustomBackground_)
+            {
+                ImageCacheManager::GetInstance().UnloadSingleRes(COLOR_CUSTOM_BACKGROUND_IMAGE);
+
+                delete ImageColorCustomBackground_;
+                ImageColorCustomBackground_ = nullptr;
+            }
+            if (nullptr != ImageColorCustomSelected_)
+            {
+                delete ImageColorCustomSelected_;
+                ImageColorCustomSelected_ = nullptr;
+            }
+        }
+    }
+
+    UIViewGroup *FlashlightView::InitColorCustomData()
+    {
+        if (nullptr == GroupColorCustom_)
+        {
+            GroupColorCustom_ = new UIViewGroup();
+            if (nullptr == GroupColorCustom_)
+                return nullptr;
+
+            GroupColorCustom_->SetViewId(Flashlight_ViewId_GroupColorCustom_);
+            GroupColorCustom_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
+            GroupColorCustom_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+            GroupColorCustom_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+            GroupColorCustom_->SetTouchable(true);
+            GroupColorCustom_->SetDraggable(true);
+            GroupColorCustom_->SetOnDragListener(presenter_);
+
+            if (nullptr == ImageColorCustomBackground_)
+            {
+                ImageColorCustomBackground_ = new UIImageView;
+                if (nullptr == ImageColorCustomBackground_)
+                    return nullptr;
+
+                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_);
+            }
+
+            group->Add(GroupColorCustom_);
+        }
+
+        return GroupColorCustom_;
+    }
+
+    void FlashlightView::GetValueByColorCustomSelectedImage(int16_t x, int16_t y, int64_t *value)
+    {
+        *value = -1;
+
+        if (nullptr == ImageColorCustomSelected_)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return;
+        }
+        if (nullptr == ImageColorCustomBackground_)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return;
+        }
+        const ImageInfo *info = ImageColorCustomBackground_->GetImageInfo();
+        if (nullptr == info)
+        {
+            WEARABLE_LOGD(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_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return;
+        }
+        if (nullptr == ImageColorCustomBackground_)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return;
+        }
+        const ImageInfo *info = ImageColorCustomBackground_->GetImageInfo();
+        if (nullptr == info)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[@CHENG][%d]", __LINE__);
+            return;
+        }
+        //
+        //
+        //
+        //  待实现功能
+        //  根据给定的颜色值
+        //  获得对应的 (x,y)值
+        //
+        //
+        //
+    }
+
+    void FlashlightView::DeinitFlashingSettingData()
+    {
+        if (nullptr != ScrollFlashingSetting_)
+        {
+            ScrollFlashingSetting_->RemoveAll();
+            delete ScrollFlashingSetting_;
+            ScrollFlashingSetting_ = nullptr;
+
+            if (nullptr != LabelFlashingSettingTitle_)
+            {
+                delete LabelFlashingSettingTitle_;
+                LabelFlashingSettingTitle_ = nullptr;
+            }
+
+            uint8_t i = 0;
+            for (i = 0; i < FLASHING_SETTING_ITEM_COUNT; i++)
+            {
+                if (nullptr != GroupFlashingSettingItem_[i])
+                {
+                    GroupFlashingSettingItem_[i]->RemoveAll();
+                    delete GroupFlashingSettingItem_[i];
+                    GroupFlashingSettingItem_[i] = nullptr;
+
+                    if (nullptr != LabelFlashingSettingItem_[i])
+                    {
+                        delete LabelFlashingSettingItem_[i];
+                        LabelFlashingSettingItem_[i] = nullptr;
+                    }
+                    if (nullptr != RadioButtonFlashingSettingItem_[i])
+                    {
+                        delete RadioButtonFlashingSettingItem_[i];
+                        RadioButtonFlashingSettingItem_[i] = nullptr;
+                    }
+                }
+            }
+        }
+    }
+
+    UIViewGroup *FlashlightView::InitFlashingSettingData()
+    {
+        if (nullptr == ScrollFlashingSetting_)
+        {
+            ScrollFlashingSetting_ = new UIScrollView();
+            if (nullptr == ScrollFlashingSetting_)
+                return nullptr;
+
+            ScrollFlashingSetting_->SetViewId(Flashlight_ViewId_ScrollFlashingSetting_);
+            ScrollFlashingSetting_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 50);
+            ScrollFlashingSetting_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+            ScrollFlashingSetting_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+            ScrollFlashingSetting_->SetTouchable(true);
+            ScrollFlashingSetting_->SetDraggable(true);
+            ScrollFlashingSetting_->SetOnDragListener(presenter_);
+
+            ScrollFlashingSetting_->SetScrollBlankSize(40);
+            ScrollFlashingSetting_->SetReboundSize(40);
+            ScrollFlashingSetting_->SetMaxScrollDistance(1000);
+            ScrollFlashingSetting_->SetThrowDrag(true);
+            ScrollFlashingSetting_->RequestFocus();
+            ScrollFlashingSetting_->SetRotateFactor(2);
+
+            if (nullptr == LabelFlashingSettingTitle_)
+            {
+                LabelFlashingSettingTitle_ = CreateUILabelExt(83, 50, 300, 35, STR_FLICKER_FREQUENCY, 30, 35, Color::White().full,
+                                                              TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+                if (nullptr == LabelFlashingSettingTitle_)
+                    return nullptr;
+            }
+
+            uint8_t i = 0;
+            uint16_t text_id[FLASHING_SETTING_ITEM_COUNT] = {STR_NO_FLICKER, STR_FAST_FLICKER, STR_SLOW_FLICKER};
+            for (i = 0; i < FLASHING_SETTING_ITEM_COUNT; i++)
+            {
+                LabelFlashingSettingItem_[i] = CreateUILabelExt(47, 33, 230, 35, text_id[i], 30, 35, Color::White().full,
+                                                                TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
+                RadioButtonFlashingSettingItem_[i] = CreateUIRadioButtonItem(300, 30, 40, 40);
+                GroupFlashingSettingItem_[i] = CreateUIGroupItem(Flashlight_ViewId_FlashingSettingItem_[i],
+                                                                 43, 120 + 120 * i, 380, 100);
+
+                GroupFlashingSettingItem_[i]->Add(LabelFlashingSettingItem_[i]);
+                GroupFlashingSettingItem_[i]->Add(RadioButtonFlashingSettingItem_[i]);
+                ScrollFlashingSetting_->Add(GroupFlashingSettingItem_[i]);
+            }
+
+            ScrollFlashingSetting_->Add(LabelFlashingSettingTitle_);
+
+            group->Add(ScrollFlashingSetting_);
+        }
+
+        return dynamic_cast<UIViewGroup *>(ScrollFlashingSetting_);
+        // return ScrollFlashingSetting_;
+    }
+
+    UILabelExt *FlashlightView::CreateUILabelExt(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t text_id,
+                                                 int64_t font_size, int64_t line_height, int64_t color_value,
+                                                 UITextLanguageAlignment hor_align, UITextLanguageAlignment ver_align)
+    {
+        UILabelExt *temp_UILabelExt = new UILabelExt();
+        if (nullptr == temp_UILabelExt)
+            return nullptr;
+
+        temp_UILabelExt->SetPosition(x, y, w, h);
+        temp_UILabelExt->SetStyle(STYLE_TEXT_FONT, font_size);
+        temp_UILabelExt->SetStyle(STYLE_LINE_HEIGHT, line_height);
+        temp_UILabelExt->SetTextId(text_id);
+        temp_UILabelExt->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+        temp_UILabelExt->SetAlign(hor_align, ver_align);
+        temp_UILabelExt->SetRollSpeed(23);
+        temp_UILabelExt->SetFont(DEFAULT_VECTOR_FONT_FILENAME, font_size);
+        temp_UILabelExt->SetStyle(STYLE_TEXT_COLOR, color_value);
+
+        return temp_UILabelExt;
+    }
+
+    UIRadioButton *FlashlightView::CreateUIRadioButtonItem(int16_t x, int16_t y, int16_t w, int16_t h)
+    {
+        UIRadioButton *temp_UIRadioButton = new UIRadioButton();
+        if (nullptr == temp_UIRadioButton)
+            return temp_UIRadioButton;
+
+        temp_UIRadioButton->SetPosition(x, y, w, h);
+        temp_UIRadioButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+        temp_UIRadioButton->SetImages(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_OFF_IMAGE);
+        // temp_UIRadioButton->SetOnChangeListener(presenter_);
+
+        return temp_UIRadioButton;
+    }
+
+    UIViewGroup *FlashlightView::CreateUIGroupItem(char *id, int16_t x, int16_t y, int16_t w, int16_t h)
+    {
+        UIViewGroup *temp_UIViewGroup = new UIViewGroup();
+        if (nullptr == temp_UIViewGroup)
+            return nullptr;
+
+        temp_UIViewGroup->SetViewId(id);
+        temp_UIViewGroup->SetPosition(x, y, w, h);
+        temp_UIViewGroup->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+        temp_UIViewGroup->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+        temp_UIViewGroup->SetStyle(STYLE_BORDER_RADIUS, 52);
+        temp_UIViewGroup->SetTouchable(true);
+        // temp_UIViewGroup->SetDraggable(true);
+        temp_UIViewGroup->SetOnClickListener(presenter_);
+
+        return temp_UIViewGroup;
+    }
+
+    void FlashlightView::UpdateFlashingSettingItem(void)
+    {
+        uint8_t i = 0;
+        for (i = 0; i < FLASHING_SETTING_ITEM_COUNT; i++)
+        {
+            if (nullptr == RadioButtonFlashingSettingItem_[i])
+                return;
+
+            if (presenter_->GetFlashingLevel() == i)
+                RadioButtonFlashingSettingItem_[i]->SetState(UICheckBox::SELECTED);
+            else
+                RadioButtonFlashingSettingItem_[i]->SetState(UICheckBox::UNSELECTED);
+        }
+    }
+
+    struct FlashlightViewMapper
+    {
+        FlashlightView::ENUM_FLASHLIGHT_SCREEN screen_index;
+        UIViewGroup *(FlashlightView::*func)(void);
+    };
+    static const FlashlightViewMapper ViewMapper[] =
+        {
+            {FlashlightView::ENUM_FLASHLIGHT_SCREEN_VIEW_MAIN, &FlashlightView::InitSwipeData},
+            {FlashlightView::ENUM_FLASHLIGHT_SCREEN_VIEW_SETTING, &FlashlightView::InitSwipeData},
+            {FlashlightView::ENUM_FLASHLIGHT_SCREEN_COLOR_SETTING, &FlashlightView::InitColorSettingData},
+            {FlashlightView::ENUM_FLASHLIGHT_SCREEN_COLOR_CUSTOM, &FlashlightView::InitColorCustomData},
+            {FlashlightView::ENUM_FLASHLIGHT_SCREEN_FLASHING_SETTING, &FlashlightView::InitFlashingSettingData},
+    };
+
+    void FlashlightView::DisplaySelectScreen(uint8_t ScreenIndex)
+    {
+        if (ENUM_FLASHLIGHT_SCREEN_MAX <= ScreenIndex)
+        {
+            return;
+        }
+
+        uint8_t i = 0;
+        for (i = 0; i < ENUM_FLASHLIGHT_SCREEN_MAX; i++)
+        {
+            if (nullptr != ScreenGroupArray_[i])
+            {
+                ScreenGroupArray_[i]->SetVisible(false);
+            }
+        }
+
+        if (nullptr == ScreenGroupArray_[ScreenIndex])
+        {
+            ScreenGroupArray_[ScreenIndex] = (this->*(ViewMapper[ScreenIndex].func))();
+            if (nullptr == ScreenGroupArray_[ScreenIndex])
+                return;
+        }
+        ScreenGroupArray_[ScreenIndex]->SetVisible(true);
+
+        switch (ScreenIndex)
+        {
+        case ENUM_FLASHLIGHT_SCREEN_VIEW_MAIN:
+            ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
+            UpdateViewMainScreen();
+            break;
+
+        case ENUM_FLASHLIGHT_SCREEN_VIEW_SETTING:
+            SwipeView_->SetCurrentPage(1);
+            break;
+
+        case ENUM_FLASHLIGHT_SCREEN_COLOR_SETTING:
+            UpdateColorSettingItem();
+            break;
+
+        case ENUM_FLASHLIGHT_SCREEN_COLOR_CUSTOM:
+            break;
+
+        case ENUM_FLASHLIGHT_SCREEN_FLASHING_SETTING:
+            UpdateFlashingSettingItem();
+            break;
+
+            // default:
+            //     break;
+        }
+
+        Draw();
+    }
+
+    void FlashlightView::DisplayViewMainScreen()
+    {
+        DisplaySelectScreen(ENUM_FLASHLIGHT_SCREEN_VIEW_MAIN);
+    }
+
+    void FlashlightView::DisplayViewSettingScreen()
+    {
+        DisplaySelectScreen(ENUM_FLASHLIGHT_SCREEN_VIEW_SETTING);
+    }
+
+    void FlashlightView::DisplayColorSettingScreen()
+    {
+        DisplaySelectScreen(ENUM_FLASHLIGHT_SCREEN_COLOR_SETTING);
+    }
+
+    void FlashlightView::DisplayColorCustomScreen()
+    {
+        DisplaySelectScreen(ENUM_FLASHLIGHT_SCREEN_COLOR_CUSTOM);
+    }
+
+    void FlashlightView::DisplayFlashingSettingScreen()
+    {
+        DisplaySelectScreen(ENUM_FLASHLIGHT_SCREEN_FLASHING_SETTING);
+    }
+
+}
\ No newline at end of file