From: Caisking Date: Mon, 28 Apr 2025 10:00:53 +0000 (+0800) Subject: 【屏幕与亮度】UI X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~330 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=982974c62edf8265eab42abda2d1f50114fc370e;p=mirrors%2FFD230.git 【屏幕与亮度】UI --- diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/BrightnessControlView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/BrightnessControlView.h new file mode 100644 index 000000000..2f5262d7d --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/BrightnessControlView.h @@ -0,0 +1,75 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-27 15:07:34 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/BrightnessControlView.h + */ +#ifndef BRIGHTNESS_CONTROL_VIEW_H +#define BRIGHTNESS_CONTROL_VIEW_H + + +#include "View.h" +#include "components/ui_scroll_view.h" +#include "components/ui_slider.h" +#include "components/ui_image_view.h" +#include +#include "map" +namespace OHOS +{ +#define BRIGHTNESS_MIN 51 +#define BRIGHTNESS_MAX 0xff +#define BRIGHTNESS_PROGRESS "progress" + + // 步骤 1: 定义策略接口.定义一个策略接口,所有的亮度调整策略都需要实现这个接口 + class BrightnessControlView; + class BrightnessChangeStrategy + { + public: + virtual void ApplyChange(BrightnessControlView *view, UISlider *slider, uint8_t value) = 0; + virtual ~BrightnessChangeStrategy() = default; + }; + + static const char *BRIGHTNESS_CONTROL_SLIDER = "BrightnessControlViewSlider"; + class BrightnessSliderEventListener : public UISlider::UISliderEventListener, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UIView::OnRotateListener + { + public: + BrightnessSliderEventListener(); + ~BrightnessSliderEventListener(); + static BrightnessSliderEventListener *GetInstance(); + void ChangeBrightness(uint8_t status, uint8_t value); + void OnChange(int32_t value) override; + void OnRelease(int32_t value) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnRotateEnd(UIView& view, const RotateEvent& event); + + private: + std::map> strategyMap; + }; + class BrightnessControlView + { + public: + BrightnessControlView(); + virtual ~BrightnessControlView(); + static BrightnessControlView *GetInstance(void); + UIScrollView *BrightnessControlViewInit(void); + void ClearAll(void); + UISlider *GetBrightnessControlViewSlider(void); + + private: + bool SetUpScrollView(void); + bool SetUpSlider(void); + bool SetUpImageView(void); + BrightnessSliderEventListener *rawPointer{nullptr}; + UIScrollView *BrightnessControlScrollView{nullptr}; + UISlider *BrightnessControlViewSlider = nullptr; + UIImageView *BrightnessControlViewImageIcon = nullptr; + bool initViewStatus{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/DisplayBrightnessModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/DisplayBrightnessModel.h new file mode 100644 index 000000000..94af90d64 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/DisplayBrightnessModel.h @@ -0,0 +1,33 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-12 20:11:04 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-18 15:14:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessModel.h + */ +#ifndef DISPLAY_BRIGHTNESS_MODEL_H_ +#define DISPLAY_BRIGHTNESS_MODEL_H_ + +#include "ConfigModel.h" +namespace OHOS +{ + class DisplayBrightnessModel + { + public: + static DisplayBrightnessModel *GetInstance(void); + bool UpdateRaiseToBrightnessCheckBoxButtonStatus(void); + bool UpdateScreenDurationRadioButtonSlectStatus(void); + bool UpdateSelectScreenDurationLabel(void); + bool UpdateBrightnessValueOfSlider(void); + void SetScreenDurationTime(unsigned int time); + unsigned int GetScreenDurationTime(void); + + private: + DisplayBrightnessModel(); + DisplayBrightnessModel(const DisplayBrightnessModel &) = delete; + DisplayBrightnessModel &operator=(const DisplayBrightnessModel &) = delete; + virtual ~DisplayBrightnessModel(); + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h new file mode 100644 index 000000000..bf14d29b3 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h @@ -0,0 +1,109 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-18 09:10:05 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-07-22 16:24:31 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h + */ +#ifndef _DISPLAY_BRIGHTNESS_PRESENTER_H +#define _DISPLAY_BRIGHTNESS_PRESENTER_H + +/*显示与亮度*/ +#include "Presenter.h" +#include "DisplayBrightnessView.h" +#include "components/ui_slider.h" + +namespace OHOS +{ + static constexpr uint8_t WRIST_RAISE_TO_WAKE_ENABLED = 1; + static constexpr uint8_t WRIST_RAISE_TO_WAKE_DISENABLED = 0; + typedef enum + { + DISPLAYBRIGHTNESSVIEW = 0, // 屏幕与亮度视图(slice) + SCREENDURATIONVIEW, // 亮屏时长视图(subView) + MAX_DISPLAYBRIGHTNESSVIEWID, + } DISPLAYBRIGHTNESSVIEWID; + + /// @brief 亮度状态改变 + typedef enum : uint8_t + { + BRIGHTNESSLOWERS = 0, // 亮度降低 + BRIGHTNESSEVATED = 1, // 亮度增加 + BRIGHTNESSDRAG = 2, // 亮度拖动状态 + } BrightnessChangeStatus; + + /// @brief 亮屏时长 + typedef enum : uint32_t + { + SCREENDURATION_FIVE = 1000 * 5, // 5秒后熄屏 + SCREENDURATION_TEN = 1000 * 10, // 10秒后熄屏 + SCREENDURATION_FIFTEENTH = 1000 * 15, // 15秒后熄屏 + SCREENDURATION_THIRTY = 1000 * 30, // 30秒后熄屏 + SCREENDURATION_SIXTY = 1000 * 60, // 60秒后熄屏 + SCREENDURATION_THREE_HUNDRED = 1000 * 300, // 300秒后熄屏 + } ScreenDurationTime; + + typedef enum + { + ScreenDurationRadioButton1 = 0, + ScreenDurationRadioButton2, + ScreenDurationRadioButton3, + ScreenDurationRadioButton4, + ScreenDurationRadioButton5, + ScreenDurationRadioButton6, + Max_ScreenDurationRadioButton, + } ScreenDurationRadioButton; + + static const char *BRINGHTNESSCONTROLBUTTON_VIEW = "BRINGHTNESSCONTROLBUTTON"; // 亮度调节按钮视图id + static const char *SCREENDURATIONBUTTON_VIEWID = "SCREENDURATIONBUTTON"; // 亮屏时长按钮视图id + static const char *RAISETOBRIGHTNESSCHECKBOXBUTTON_VIEWID = "RAISETOBRIGHTNESSCHECKBOXBUTTON"; // 抬腕亮屏checkbox按钮视图id + + class ScreenDurationRadiobuttonOnChangeListener : public UICheckBox::OnChangeListener, public UIView::OnClickListener + { + public: + ScreenDurationRadiobuttonOnChangeListener() {} + ScreenDurationRadiobuttonOnChangeListener(UIView *view) + { + m_view = view; + } + ~ScreenDurationRadiobuttonOnChangeListener() {} + bool OnChange(UICheckBox::UICheckBoxState state) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + + private: + UIView *m_view{nullptr}; + }; + + class DisplayBrightnessView; + class DisplayBrightnessPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener, + public UICheckBox::OnChangeListener + { + public: + DisplayBrightnessPresenter(); + virtual ~DisplayBrightnessPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static DisplayBrightnessPresenter *GetInstance(); + void SetRaiseToBrightnessState(bool value); + void SetScreenDurationRadioButtonSelectStatus(uint32_t value); + void SetSelectScreenDurationLabel(uint32_t value); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + 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 OnChange(UICheckBox::UICheckBoxState state) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + bool X_DRAG_FLAG{false}; + }; +} // namespace OHOS + +#endif //_DisplayBrightness_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/DisplayBrightnessView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/DisplayBrightnessView.h new file mode 100644 index 000000000..2378bf1f9 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/DisplayBrightnessView.h @@ -0,0 +1,109 @@ +#ifndef _DISPLAY_BRIGHTNESS_VIEW_H +#define _DISPLAY_BRIGHTNESS_VIEW_H + + +#include "View.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_scroll_view.h" +#include "components/ui_checkbox.h" +#include "components/ui_radio_button.h" +#include "DisplayBrightnessPresenter.h" +#include "displaybrightness/include/ScreenDurationView.h" +#include "memory" +namespace OHOS +{ + static constexpr const char *DISPLAY_BRIGHTNESS_VIEW = "DisplayBrightnessView"; + class DisplayBrightnessPresenter; + class DisplayBrightnessView : public View + { + public: + struct ImageConfig + { + int16_t x; + int16_t y; + int16_t w; + int16_t h; + const char *ImageSrc; + }; + struct ButtonConfig + { + int16_t x; + int16_t y; + int16_t w; + int16_t h; + const char *ViewId; + // const char *ImageSrc; + }; + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + // std::string text; // 文本 + int16_t textId; + uint8_t lineBreakMode; // 断行模式。 + }; + struct CheckBoxConfig + { + int16_t x; + int16_t y; + int16_t w; + int16_t h; + const char *ViewId; + const char *select; + const char *unselect; + }; + DisplayBrightnessView(); + virtual ~DisplayBrightnessView(); + static DisplayBrightnessView *GetInstance(void); + + bool ChangeDisplayBrightnessView(int16_t thisView); // 切换到“屏幕与亮度”视图 + bool ChangeScreenDurationView(int16_t thisView); // 切换到亮屏时长视图 + bool ClickFunc(int16_t interface); + void ChangeView(int16_t hideView, int16_t showView); + void SetRaiseToBrightnessCheckBoxButtonState(UICheckBox::UICheckBoxState state); + ScreenDurationView *GetScreenDurationView(void); + UILabelExt *GetSelectScreenDurationLabel(void); + + public: + void OnStart() override; + + + private: + ScreenDurationView *p_ScreenDurationView{nullptr}; // 亮屏时长视图 + + private: + UILabelExt *SetUpLabel(LabelConfig &labelconfig); // 设置标签 + UIImageView *SetUpImageView(ImageConfig &imageconfig); // 设置图片 + UICheckBox *SetUpCheckBox(CheckBoxConfig &checkboxconfig); // 设置复选框 + UIButton *SetTheButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener); + bool SetTheTitle(void); + bool InitDisplayBrightnessViewButton(void); + bool InitDisplayBrightnessViewLabel(void); + bool InitDisplayBrightnessViewImage(void); + bool InitDisplayBrightnessViewCheckBox(void); + bool SetUpScrollView(void); + void DisplayAndBrightnessViewInit(void); + void ClearAll(void); + UIScrollView *DisplayBrightnessScrollView[2]{nullptr}; + UILabelExt *DisplayBrightnessTitleLabel = nullptr; // 显示与亮度标题 + UIButton *BringhtnessControlButton = nullptr; // 亮度调节按钮 + UIButton *ScreenDurationButton = nullptr; // 亮屏时长按钮 + UILabelExt *BringhtnessControlLabel = nullptr; // 亮度调节标签 + UILabelExt *ScreenDurationLabel = nullptr; // 亮屏时长标签 + UILabelExt *selectScreenDurationLabel = nullptr; // 选择的亮屏时间 + UILabelExt *RaiseToBrightnessLabel = nullptr; // 抬腕亮屏标签 + UIImageView *NextImage[2]{nullptr}; + UIImageView *RaiseToBrightnessImage = nullptr; // 抬腕亮屏图片 + UICheckBox *RaiseToBrightnessCheckBoxButton = nullptr; // 抬腕亮屏按钮 + uint8_t state = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; + bool initViewStatus{false}; + }; +} // namespace OHOS +#endif // DisplayBrightness_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/ScreenDurationView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/ScreenDurationView.h new file mode 100644 index 000000000..37cdafd24 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/include/ScreenDurationView.h @@ -0,0 +1,81 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-07-22 16:30:36 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h + */ +#ifndef SCREEN_DUATION_VIEW_H +#define SCREEN_DUATION_VIEW_H +// 屏幕时长 + +#include "View.h" +#include "components/ui_scroll_view.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_radio_button.h" +#include "components/ui_button.h" +namespace OHOS +{ +#define DURATIONS 6 + static constexpr const char *SCREENDURATIONSCROLLVIEW = "ScreenDurationView"; + class ScreenDurationView + { + public: + struct ButtonConfig + { + int16_t x; + int16_t y; + int16_t w; + int16_t h; + }; + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + int16_t textId; // 文本id + uint8_t lineBreakMode; // 断行模式。 + }; + struct RadioButtonConfig + { + int16_t x; + int16_t y; + int16_t w; + int16_t h; + // const char *viewId; + const char *select; + const char *unselect; + }; + ScreenDurationView(); + virtual ~ScreenDurationView(); + static ScreenDurationView *GetInstance(void); + UIScrollView *ScreenDurationViewInit(void); + void ClearAll(void); + UIRadioButton *GetRadioButton(int16_t i); + void SetRadioButtonSelectStatus(int16_t i); + UIButton *GetScreenDurationButton(int16_t i); + + private: + UIButton *SetUpButtonView(ButtonConfig &buttonConfig); // 设置按钮 + UILabelExt *SetUpLabel(LabelConfig &labelconfig); // 设置标签 + UIRadioButton *SetUpRadioButton(RadioButtonConfig &radiobuttonconfig); // 设置单选框 + bool SetUpScrollView(void); + bool SetUpScreenDurationViewLabel(void); + bool SetUpScreenDurationViewImageView(void); + bool SetUpScreenDurationViewRadioButton(void); + UIScrollView *ScreenDurationScrollView = nullptr; + UILabelExt *ScreenDurationTitleLabel = nullptr; // 标题 + UILabelExt *ScreenDurationLabel[DURATIONS]{nullptr}; // 亮屏时长标签 + UIButton *ScreenDurationButton[DURATIONS]{nullptr}; // 放置组件的按钮 + UIRadioButton *ScreenDurationRadioButton[DURATIONS]{nullptr}; // 单选框 + UICheckBox::OnChangeListener *SimplifiedChineseRadioButtonChange[DURATIONS]{nullptr}; + UIView::OnClickListener *ScreenDurationButtonClickListener{nullptr}; + bool initViewStatus{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/BrightnessControlView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/BrightnessControlView.cpp new file mode 100644 index 000000000..da7923cd4 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/BrightnessControlView.cpp @@ -0,0 +1,303 @@ +#include "displaybrightness/include/BrightnessControlView.h" +#include "displaybrightness/include/DisplayBrightnessPresenter.h" +#include "wearable_log.h" +#include +#include "power_display_service.h" +#include "ConfigModel.h" +#include "map" +#include "iostream" +#include "vibrator_service.h" +namespace OHOS +{ + static BrightnessControlView *g_pBrightnessControlView{nullptr}; + BrightnessControlView::BrightnessControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BrightnessControlView::BrightnessControlView"); + g_pBrightnessControlView = this; + } + + BrightnessControlView::~BrightnessControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BrightnessControlView::~BrightnessControlView"); + ClearAll(); + g_pBrightnessControlView = nullptr; + } + + BrightnessControlView *BrightnessControlView::GetInstance() + { + return g_pBrightnessControlView; + } + + void BrightnessControlView::ClearAll(void) + { + if (initViewStatus == true) + { + BrightnessControlScrollView->RemoveAll(); + + delete BrightnessControlViewSlider; + BrightnessControlViewSlider = nullptr; + + delete BrightnessControlViewImageIcon; + BrightnessControlViewImageIcon = nullptr; + + delete rawPointer; + rawPointer = nullptr; + + delete BrightnessControlScrollView; + BrightnessControlScrollView = nullptr; + } + } + + // 显示与亮度视图scrollView初始化 + bool BrightnessControlView::SetUpScrollView(void) + { + BrightnessControlScrollView = new UIScrollView(); + if (BrightnessControlScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BrightnessControlView::BrightnessControlScrollView new fail!"); + return false; + } + BrightnessControlScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + BrightnessControlScrollView->SetTouchable(true); + BrightnessControlScrollView->SetDraggable(true); + return true; + } + + // 亮度滑动条设置 + bool BrightnessControlView::SetUpSlider(void) + { + BrightnessControlViewSlider = new UISlider(); + if (BrightnessControlViewSlider == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BrightnessControlViewSlider new fail"); + return false; + } + BrightnessControlViewSlider->SetSliderColor(Color::Gray(), Color::Silver()); + BrightnessControlViewSlider->SetPosition(167, 77, 130, 310); + BrightnessControlViewSlider->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); + BrightnessControlViewSlider->SetViewId(BRIGHTNESS_PROGRESS); + BrightnessControlViewSlider->SetRange(BRIGHTNESS_MAX, BRIGHTNESS_MIN); + + BrightnessControlViewSlider->SetStyle(STYLE_BORDER_RADIUS, 100); + BrightnessControlViewSlider->SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); + BrightnessControlViewSlider->SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); + BrightnessControlViewSlider->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); + BrightnessControlViewSlider->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); + BrightnessControlViewSlider->SetValue(ConfigModel::GetInstance()->GetBrightness()); + BrightnessControlViewSlider->SetRotateFactor(1); + BrightnessControlViewSlider->RequestFocus(); + BrightnessControlViewSlider->SetIntercept(true); + + if (rawPointer == nullptr) + { + rawPointer = new BrightnessSliderEventListener(); + if (rawPointer == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rawPointer new fail"); + return false; + } + } + BrightnessControlViewSlider->SetSliderEventListener(rawPointer); + BrightnessControlViewSlider->SetOnClickListener(rawPointer); + BrightnessControlViewSlider->SetOnDragListener(rawPointer); + BrightnessControlViewSlider->SetOnRotateListener(rawPointer); + BrightnessControlViewSlider->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); + return true; + } + + bool BrightnessControlView::SetUpImageView(void) + { + BrightnessControlViewImageIcon = new UIImageView(); + if (BrightnessControlViewImageIcon == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BrightnessControlViewImageIcon new fail"); + return false; + } + BrightnessControlViewImageIcon->SetPosition(213, 213, 40, 40); + const char *image = "/user/res/BringhtnessContuolVector.bin"; + BrightnessControlViewImageIcon->SetSrc(image); + return true; + } + + UISlider *BrightnessControlView::GetBrightnessControlViewSlider(void) + { + return BrightnessControlViewSlider; + } + + + // 亮度调节视图初始化 + UIScrollView *BrightnessControlView::BrightnessControlViewInit(void) + { + /* ----------------------- BrightnessControlScrollView ---------------------- */ + if (!SetUpScrollView()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BrightnessControlView::BrightnessControlScrollView is nullptr!"); + return nullptr; + } + + /* ----------------------- BrightnessControlViewSlider ---------------------- */ + if (!SetUpSlider()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BrightnessControlView::BrightnessControlViewSlider is nullptr!"); + return nullptr; + } + + /* ------------------------------- BrightnessControlViewImageIcon ------------------------------ */ + if (!SetUpImageView()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BrightnessControlView::BrightnessControlViewImageIcon is nullptr!"); + return nullptr; + } + /* ----------------------------------- Add ---------------------------------- */ + BrightnessControlScrollView->Add(BrightnessControlViewSlider); + BrightnessControlScrollView->Add(BrightnessControlViewImageIcon); + initViewStatus = true; + return BrightnessControlScrollView; + } + + /* -------------------------------------------------------------------------- */ + + static constexpr int16_t BRIGHTNESS_CHANGE = 10; + // 步骤 2: 实现具体的策略 + class LowerBrightnessStrategy : public BrightnessChangeStrategy + { + public: + void ApplyChange(BrightnessControlView *view, UISlider *slider, uint8_t value) override + { + // Implement the logic similar to the BRIGHTNESSLOWERS case + uint8_t newBrightnessValue = slider->GetValue() - BRIGHTNESS_CHANGE; + if (newBrightnessValue < BRIGHTNESS_MIN) + { + newBrightnessValue = BRIGHTNESS_MIN; + } + + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api->set_brightness(newBrightnessValue) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LowerBrightness: set_brightness fail!"); + } + else + { + slider->SetValue(newBrightnessValue); + } + } + }; + + class ElevateBrightnessStrategy : public BrightnessChangeStrategy + { + public: + void ApplyChange(BrightnessControlView *view, UISlider *slider, uint8_t value) override + { + // Implement the logic similar to the BRIGHTNESSEVATED case + uint8_t newBrightnessValue = slider->GetValue() + BRIGHTNESS_CHANGE; + if (newBrightnessValue > BRIGHTNESS_MAX) + { + newBrightnessValue = BRIGHTNESS_MAX; + } + + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api->set_brightness(newBrightnessValue) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ElevateBrightness: set_brightness fail!"); + } + else + { + slider->SetValue(newBrightnessValue); + } + } + }; + + class DragBrightnessStrategy : public BrightnessChangeStrategy + { + public: + void ApplyChange(BrightnessControlView *view, UISlider *slider, uint8_t value) override + { + // Implement the logic similar to the BRIGHTNESSDRAG case + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + // 更新进度条的显示: + slider->SetValue(value); + if (display_api->set_brightness(value) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChangeBrightness: set_brightness fail!"); + return; + } + } + }; + /* -------------------------------------------------------------------------- */ + static BrightnessSliderEventListener *g_pBrightnessSliderEventListener{nullptr}; + BrightnessSliderEventListener::BrightnessSliderEventListener() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BrightnessSliderEventListener::BrightnessSliderEventListener"); + // 步骤 3: 创建一个映射表将状态映射到策略 + strategyMap[BRIGHTNESSLOWERS] = std::make_shared(); + strategyMap[BRIGHTNESSEVATED] = std::make_shared(); + strategyMap[BRIGHTNESSDRAG] = std::make_shared(); + g_pBrightnessSliderEventListener = this; + } + + BrightnessSliderEventListener::~BrightnessSliderEventListener() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BrightnessSliderEventListener::~BrightnessSliderEventListener"); + g_pBrightnessSliderEventListener = nullptr; + } + + BrightnessSliderEventListener *BrightnessSliderEventListener::GetInstance(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BrightnessSliderEventListener::GetInstance"); + return g_pBrightnessSliderEventListener; + } + + // 步骤 4: 使用映射表简化 ChangeBrightness + void BrightnessSliderEventListener::ChangeBrightness(uint8_t status, uint8_t value) + { + auto it = strategyMap.find(status); + if (it != strategyMap.end()) + { + // 确保 BrightnessControlView 和 UISlider 都不为 nullptr + BrightnessControlView *view = BrightnessControlView::GetInstance(); + UISlider *slider = view ? view->GetBrightnessControlViewSlider() : nullptr; + if (view && slider) + { + it->second->ApplyChange(view, slider, value); + } + } + } + + /// @brief 当滑动条被拖动或点击时调用 + /// @param value 滑块的当前值。 + void BrightnessSliderEventListener::OnChange(int32_t value) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnChange %d", value); + ChangeBrightness(BRIGHTNESSDRAG, value); + ConfigModel::GetInstance()->SetBrightness(value); + } + + /// @brief 当滑动条被释放时调用 + /// @param value 滑块的当前值。 + void BrightnessSliderEventListener::OnRelease(int32_t value) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRelease %d", value); + ChangeBrightness(BRIGHTNESSDRAG, value); + ConfigModel::GetInstance()->SetBrightness(value); + } + + bool BrightnessSliderEventListener::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + UNUSED(view); + return true; + } + bool BrightnessSliderEventListener::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(event); + UNUSED(view); + return true; + } + + bool BrightnessSliderEventListener::OnRotateEnd(UIView& view, const RotateEvent& event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRotateEnd %d", value); + ui_api_vibrate_once_func();//受设置中震动强度控制 + return true; + } +} diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp new file mode 100644 index 000000000..3ad165040 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp @@ -0,0 +1,107 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-12 20:11:04 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-07-22 12:00:13 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp + */ +#include "displaybrightness/include/DisplayBrightnessModel.h" +#include "displaybrightness/include/DisplayBrightnessPresenter.h" +#include "brightnesslevel/include/BrightnessLevelView.h" +#include "wearable_log.h" +#include "ConfigModel.h" +#include "ConfigModelC.h" +#include "custom_runtime.h" + +namespace OHOS +{ + + DisplayBrightnessModel::DisplayBrightnessModel() {} + + DisplayBrightnessModel::~DisplayBrightnessModel() {} + + DisplayBrightnessModel *DisplayBrightnessModel::GetInstance(void) + { + static DisplayBrightnessModel instance; + return &instance; + } + + // 更新抬腕亮屏按钮状态 + bool DisplayBrightnessModel::UpdateRaiseToBrightnessCheckBoxButtonStatus(void) + { + DisplayBrightnessPresenter *displayBrightnessPresent = DisplayBrightnessPresenter::GetInstance(); + if (displayBrightnessPresent == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessViewAndSubViewComponentsStatusInit DisplayBrightnessPresenter GetInstance fail"); + return false; + } + bool t_value = mmi_flip_wrist_switch_get(); + if(uapi_sleep_mode_flag_get()) + { + t_value = false; + } + displayBrightnessPresent->SetRaiseToBrightnessState(t_value); + return true; + } + + // 更新亮屏时长按钮选中状态 + bool DisplayBrightnessModel::UpdateScreenDurationRadioButtonSlectStatus(void) + { + DisplayBrightnessPresenter *displayBrightnessPresent = DisplayBrightnessPresenter::GetInstance(); + if (displayBrightnessPresent == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessViewAndSubViewComponentsStatusInit DisplayBrightnessPresenter GetInstance fail"); + return false; + } + displayBrightnessPresent->SetScreenDurationRadioButtonSelectStatus(GetScreenDurationTime()); + return true; + } + + // 更新选择的亮屏时长标签内容 + bool DisplayBrightnessModel::UpdateSelectScreenDurationLabel(void) + { + DisplayBrightnessPresenter *displayBrightnessPresent = DisplayBrightnessPresenter::GetInstance(); + if (displayBrightnessPresent == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessViewAndSubViewComponentsStatusInit DisplayBrightnessPresenter GetInstance fail"); + return false; + } + displayBrightnessPresent->SetSelectScreenDurationLabel(GetScreenDurationTime()); + // UpdateRaiseToBrightnessCheckBoxButtonStatus(); + UpdateScreenDurationRadioButtonSlectStatus(); + return true; + } + + //更新亮度条的亮度值值 + bool DisplayBrightnessModel::UpdateBrightnessValueOfSlider(void) + { + BrightnessLevelView *p_BrightnessLevelView= BrightnessLevelView::GetInstance(); + if (p_BrightnessLevelView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BrightnessLevelView::GetInstance fail!!"); + return false; + } + UISlider *slider = p_BrightnessLevelView->GetBrightnessControlView()->GetBrightnessControlViewSlider(); + if (slider == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "slider is nullptr!!"); + return false; + } + uint8_t value = ConfigModel::GetInstance()->GetBrightness(); + slider->SetValue(value); + return true; + } + + /// @brief 保存设置的亮屏时间,单位ms + /// @param time + void DisplayBrightnessModel::SetScreenDurationTime(unsigned int time) + { + ConfigModel::GetInstance()->SetScreenDuration(time); + } + + // 获取亮屏时长,单位ms + unsigned int DisplayBrightnessModel::GetScreenDurationTime(void) + { + return ConfigModel::GetInstance()->GetScreenDuration(); + } +} diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp new file mode 100644 index 000000000..0aba5f4ca --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp @@ -0,0 +1,352 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-07-22 16:37:02 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp + */ +#include "AppViewIDs.h" +#include "UiConfig.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" +#include "graphic_math.h" +#include "string.h" +#include "displaybrightness/include/DisplayBrightnessPresenter.h" +#include "cat1_ctl.h" +#include "displaybrightness/include/DisplayBrightnessModel.h" +#include "power_display_service.h" +#include "common/key_code.h" +#include +#include "map" +#include "iostream" +#include "string" +#include "ConfigModel.h" +#include "ConfigModelC.h" +#include "custom_runtime.h" + +#include "NativeRegisterManager.h" + +namespace OHOS +{ + REGIST_SLICE(VIEW_DISPLAY_BRIGHTNESS, DisplayBrightnessView, DisplayBrightnessPresenter); + // 当前Presenter属性实例化的内存指针 + static DisplayBrightnessPresenter *g_pDisplayBrightnessPresenter = nullptr; + + DisplayBrightnessPresenter::DisplayBrightnessPresenter() + { + + g_pDisplayBrightnessPresenter = this; + } + + DisplayBrightnessPresenter::~DisplayBrightnessPresenter() + { + + g_pDisplayBrightnessPresenter = nullptr; + } + + DisplayBrightnessPresenter *DisplayBrightnessPresenter::GetInstance() + { + + return g_pDisplayBrightnessPresenter; + } + + /// @brief 设置抬腕亮屏状态 + /// @param value + void DisplayBrightnessPresenter::SetRaiseToBrightnessState(bool value) + { + DisplayBrightnessView *displayBrightnessView = DisplayBrightnessView::GetInstance(); + if (displayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetRaiseToBrightnessState displayBrightnessView GetInstance fail"); + return; + } + displayBrightnessView->SetRaiseToBrightnessCheckBoxButtonState(value != false ? UICheckBox::UICheckBoxState::SELECTED : UICheckBox::UICheckBoxState::UNSELECTED); + } + + /// @brief 根据value值设置哪个按钮被选中 + /// @param value + void DisplayBrightnessPresenter::SetScreenDurationRadioButtonSelectStatus(uint32_t value) + { + ScreenDurationView *p_ScreenDurationView = ScreenDurationView::GetInstance(); + if (p_ScreenDurationView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView GetInstance fail"); + return; + } + + // 映射表将value映射到特定的单选按钮 + const std::map radioButtonMap = { + {SCREENDURATION_FIVE, ScreenDurationRadioButton1}, + {SCREENDURATION_TEN, ScreenDurationRadioButton2}, + {SCREENDURATION_FIFTEENTH, ScreenDurationRadioButton3}, + {SCREENDURATION_THIRTY, ScreenDurationRadioButton4}, + {SCREENDURATION_SIXTY, ScreenDurationRadioButton5}, + {SCREENDURATION_THREE_HUNDRED, ScreenDurationRadioButton6}, + }; + + auto iter = radioButtonMap.find(value); + if (iter != radioButtonMap.end()) + { + p_ScreenDurationView->SetRadioButtonSelectStatus(iter->second); + } + else + { + // 处理未知值 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unexpected duration value"); + } + } + + /* + * @brief 根据value值出设置选择的亮屏时长内容 + */ + void DisplayBrightnessPresenter::SetSelectScreenDurationLabel(uint32_t value) + { + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView GetInstance fail"); + return; + } + + if (p_DisplayBrightnessView->GetSelectScreenDurationLabel() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_DisplayBrightnessView->GetSelectScreenDurationLabel() is nullptr!"); + return; + } + + const std::map durationMap = { + {SCREENDURATION_FIVE, STR_5_SECONDS}, + {SCREENDURATION_TEN, STR_10_SECONDS}, + {SCREENDURATION_FIFTEENTH, STR_15_SECONDS}, + {SCREENDURATION_THIRTY, STR_30_SECONDS}, + {SCREENDURATION_SIXTY, STR_60_SECONDS}, + {SCREENDURATION_THREE_HUNDRED, STR_300_SECONDS}}; + + auto iter = durationMap.find(value); + if (iter != durationMap.end()) + { + p_DisplayBrightnessView->GetSelectScreenDurationLabel()->SetTextId(iter->second); + } + else + { + // Handle unexpected value + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Unexpected duration value"); + } + + p_DisplayBrightnessView->GetSelectScreenDurationLabel()->Invalidate(); + return; + } + + void DisplayBrightnessPresenter::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnStart"); + Presenter::OnStart(); + } + + void DisplayBrightnessPresenter::OnPause(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnPause"); + Presenter::OnPause(); + } + + void DisplayBrightnessPresenter::OnResume(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnResume"); + Presenter::OnResume(); + } + + void DisplayBrightnessPresenter::OnStop(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnStop"); + Presenter::OnStop(); + } + + bool DisplayBrightnessPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnClick"); + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!!"); + return false; + } + if (strcmp(view.GetViewId(), BRINGHTNESSCONTROLBUTTON_VIEW) == 0) + { + if(uapi_sleep_mode_flag_get()) + { + return false; + } + NativeAbility::GetInstance().EnterSlice(VIEW_BRIGHTNESSLEVEL); /*切换到亮度调节slice*/ + } + else if (strcmp(view.GetViewId(), SCREENDURATIONBUTTON_VIEWID) == 0) + { + p_DisplayBrightnessView->ChangeView(DISPLAYBRIGHTNESSVIEW, SCREENDURATIONVIEW); // 屏幕与亮度视图切换到亮屏时长视图 + } + return true; + } + + bool DisplayBrightnessPresenter::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + DisplayBrightnessPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool DisplayBrightnessPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnDragEnd"); + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView GetInstance fail"); + return false; + } + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && DisplayBrightnessPresenter::X_DRAG_FLAG) + { + if (strcmp(view.GetViewId(), SCREENDURATIONSCROLLVIEW) == 0) + { + p_DisplayBrightnessView->ChangeView(SCREENDURATIONVIEW, DISPLAYBRIGHTNESSVIEW); + } + else if (strcmp(view.GetViewId(), DISPLAY_BRIGHTNESS_VIEW) == 0) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + DisplayBrightnessPresenter::X_DRAG_FLAG = false; + } + return true; + } + + /*处理抬腕亮屏开关*/ + bool DisplayBrightnessPresenter::OnChange(UICheckBox::UICheckBoxState state) + { + switch (state) + { + case UICheckBox::SELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched on!"); + uapi_take_to_wake(WRIST_RAISE_TO_WAKE_ENABLED); + mmi_flip_wrist_switch_set(true); + break; + case UICheckBox::UNSELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched off!"); + uapi_take_to_wake(WRIST_RAISE_TO_WAKE_DISENABLED); + mmi_flip_wrist_switch_set(false); + break; + default: + break; + } + return true; + } + + bool DisplayBrightnessPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnKeyAct"); + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(); + } + return true; + } + + /* + * @brief 用于处理亮屏时长单选按钮的状态改变.根据用户选择的单选按钮,更新屏幕持续显示时间 + */ + bool ScreenDurationRadiobuttonOnChangeListener::OnChange(UICheckBox::UICheckBoxState state) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationRadiobuttonOnChangeListener::OnChange"); + if (state != UICheckBox::SELECTED) + { + return true; // 如果不是选中状态,无需处理 + } + + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!"); + return false; + } + + ScreenDurationView *p_ScreenDurationView = p_DisplayBrightnessView->GetScreenDurationView(); + if (p_ScreenDurationView == nullptr) + { + return false; // 相关视图不存在,直接返回 + } + + // 关联单选按钮视图和对应的持续时间 + std::map durationMap = { + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton1), SCREENDURATION_FIVE}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton2), SCREENDURATION_TEN}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton3), SCREENDURATION_FIFTEENTH}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton4), SCREENDURATION_THIRTY}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton5), SCREENDURATION_SIXTY}, + {p_ScreenDurationView->GetRadioButton(ScreenDurationRadioButton6), SCREENDURATION_THREE_HUNDRED}}; + + auto it = durationMap.find((UIView *)m_view); + if (it != durationMap.end()) + { + uapi_setScreenDuration(it->second); + DisplayBrightnessModel::GetInstance()->SetScreenDurationTime(it->second); + // 此处可以根据需要,添加对 WEARABLE_LOGE 的调用,打印日志 + DisplayBrightnessPresenter::GetInstance()->SetSelectScreenDurationLabel(it->second); + } + else + { + // 如果没有找到对应的映射项,可能是逻辑错误或数据不一致 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "No matching screen duration found for selected radiobutton."); + } + + return true; + } + + bool ScreenDurationRadiobuttonOnChangeListener::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationRadiobuttonOnChangeListener::OnClick"); + UIButton *button = dynamic_cast(&view); + if (button == nullptr) + { + return false; + } + + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!"); + return false; + } + + ScreenDurationView *p_ScreenDurationView = p_DisplayBrightnessView->GetScreenDurationView(); + if (p_ScreenDurationView == nullptr) + { + return false; // 相关视图不存在,直接返回 + } + // 关联单选按钮视图和对应的持续时间 + std::map durationMap = { + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton1), ScreenDurationRadioButton1}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton2), ScreenDurationRadioButton2}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton3), ScreenDurationRadioButton3}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton4), ScreenDurationRadioButton4}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton5), ScreenDurationRadioButton5}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton6), ScreenDurationRadioButton6}}; + + auto it = durationMap.find((UIButton *)button); + if (it != durationMap.end()) + { + p_ScreenDurationView->SetRadioButtonSelectStatus(it->second); + } + else + { + // 如果没有找到对应的映射项,可能是逻辑错误或数据不一致 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Logic error or data inconsistency."); + } + + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessView.cpp new file mode 100644 index 000000000..b62557f8c --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/DisplayBrightnessView.cpp @@ -0,0 +1,510 @@ +#include "displaybrightness/include/DisplayBrightnessView.h" +#include "displaybrightness/include/DisplayBrightnessModel.h" +#include "wearable_log.h" +#include "ConfigModel.h" +#include "ConfigModelC.h" +#include "ui_resource_string.h" +#include +#include "custom_runtime.h" + +namespace OHOS +{ + static DisplayBrightnessView *g_pDisplayBrightnessView{nullptr}; + + DisplayBrightnessView::DisplayBrightnessView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::DisplayBrightnessView"); + g_pDisplayBrightnessView = this; + } + + DisplayBrightnessView::~DisplayBrightnessView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::~DisplayBrightnessView"); + ClearAll(); + g_pDisplayBrightnessView = nullptr; + } + + DisplayBrightnessView *DisplayBrightnessView::GetInstance() + { + return g_pDisplayBrightnessView; + } + + void DisplayBrightnessView::ClearAll(void) + { + if (initViewStatus == true) + { + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->RemoveAll(); + + delete DisplayBrightnessTitleLabel; + DisplayBrightnessTitleLabel = nullptr; + + delete BringhtnessControlButton; + BringhtnessControlButton = nullptr; + + delete ScreenDurationButton; + ScreenDurationButton = nullptr; + + delete BringhtnessControlLabel; + BringhtnessControlLabel = nullptr; + + delete ScreenDurationLabel; + ScreenDurationLabel = nullptr; + + delete selectScreenDurationLabel; + selectScreenDurationLabel = nullptr; + + delete RaiseToBrightnessLabel; + RaiseToBrightnessLabel = nullptr; + + for (int i = 0; i < 2; i++) + { + delete NextImage[i]; + NextImage[i] = nullptr; + } + + delete RaiseToBrightnessImage; + RaiseToBrightnessImage = nullptr; + + delete RaiseToBrightnessCheckBoxButton; + RaiseToBrightnessCheckBoxButton = nullptr; + + delete DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]; + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW] = nullptr; + } + if (p_ScreenDurationView != nullptr) + { + delete p_ScreenDurationView; + p_ScreenDurationView = nullptr; + } + for (int i = DISPLAYBRIGHTNESSVIEW; i < MAX_DISPLAYBRIGHTNESSVIEWID; i++) + { + DisplayBrightnessScrollView[i] = nullptr; + } + } + + // 显示与亮度视图scrollView初始化 + bool DisplayBrightnessView::SetUpScrollView(void) + { + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW] = new UIScrollView(); + if (DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW] new fail!"); + return false; + } + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetViewId(DISPLAY_BRIGHTNESS_VIEW); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetScrollBlankSize(75); + // DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetReboundSize(35); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetDirection(1); + // DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetMaxScrollDistance(1000); + // DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetThrowDrag(true); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->RequestFocus(); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetRotateFactor(1.0); + UIView::OnDragListener *draglistener = static_cast(DisplayBrightnessPresenter::GetInstance()); + if (draglistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::draglistener can not be nullptr!"); + return false; + } + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetOnDragListener(draglistener); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetTouchable(true); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetDraggable(true); + return true; + } + + /// @brief 设置显示与亮度标题 + /// @param void + /// @return true 设置成功,false 失败 + bool DisplayBrightnessView::SetTheTitle(void) + { + DisplayBrightnessTitleLabel = new UILabelExt(); + if (DisplayBrightnessTitleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::DisplayBrightnessTitleLabel new fail!"); + return false; + } + DisplayBrightnessTitleLabel->SetPosition(83, 50, 300, 35); + DisplayBrightnessTitleLabel->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + DisplayBrightnessTitleLabel->SetStyle(STYLE_TEXT_FONT, 30); + DisplayBrightnessTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + DisplayBrightnessTitleLabel->SetTextId(STR_SCREEN_AND_BRIGHTNESS); /*屏幕与亮度*/ + DisplayBrightnessTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + DisplayBrightnessTitleLabel->SetRollSpeed(23); + DisplayBrightnessTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + DisplayBrightnessTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + return true; + } + + /// @brief 设置按钮 + /// @param button + /// @return true 设置成功,false 失败 + UIButton *DisplayBrightnessView::SetTheButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener) + { + UIButton *button = new UIButton(); + if (button == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " DisplayBrightnessView::SetTheButton: button new fail!"); + return nullptr; + } + button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); + button->SetViewId(buttonconfig.ViewId); + button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + button->SetOnClickListener(clickListener); + return button; + } + + /// @brief 初始化显示与亮度视图按钮 + /// @param void + /// @return true 设置成功,false 失败 + bool DisplayBrightnessView::InitDisplayBrightnessViewButton(void) + { + /* -------------------------------------------------------------------------- */ + ButtonConfig buttonconfig; + buttonconfig.x = 43; + buttonconfig.y = 120; + buttonconfig.w = 380; + buttonconfig.h = 100; + buttonconfig.ViewId = BRINGHTNESSCONTROLBUTTON_VIEW; + BringhtnessControlButton = SetTheButton(buttonconfig, presenter_); + if (nullptr == BringhtnessControlButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::BringhtnessControlButton new fail!"); + return false; + } + /* -------------------------------------------------------------------------- */ + buttonconfig.y = 240; + buttonconfig.ViewId = SCREENDURATIONBUTTON_VIEWID; + ScreenDurationButton = SetTheButton(buttonconfig, presenter_); + if (nullptr == ScreenDurationButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::ScreenDurationButton new fail!"); + return false; + } + return true; + } + + // 设置标签LabelConfig &labelconfig + UILabelExt *DisplayBrightnessView::SetUpLabel(LabelConfig &labelconfig) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小 + label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); // 字体大小 + label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高 + label->SetTextId(labelconfig.textId); + label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 + label->SetRollSpeed(23); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } + + /// @brief 初始化显示与亮度标签 + /// @param void + /// @return true 设置成功,false 失败 + bool DisplayBrightnessView::InitDisplayBrightnessViewLabel(void) + { + LabelConfig labelconfig = { + .left = 90, + .top = 153, + .width = 250, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_BRIGHTNESS_ADJUSTMENT, /*亮度调节*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + BringhtnessControlLabel = SetUpLabel(labelconfig); + if (BringhtnessControlLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::BringhtnessControlLabel new fail!"); + return false; + } + /* -------------------------------------------------------------------------- */ + labelconfig.top = 273; + labelconfig.width = 180; + labelconfig.textId = STR_SCREEN_ON_DURATION; /*亮屏时长*/ + ScreenDurationLabel = SetUpLabel(labelconfig); + if (ScreenDurationLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::ScreenDurationLabel new fail!"); + return false; + } + /* -------------------------------------------------------------------------- */ + labelconfig.top = 393; + labelconfig.textId = STR_RAISE_TO_WAKE; /*抬腕亮屏*/ + RaiseToBrightnessLabel = SetUpLabel(labelconfig); + if (RaiseToBrightnessLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::RaiseToBrightnessLabel new fail!"); + return false; + } + /* -------------------------------------------------------------------------- */ + labelconfig = { + .left = 291, + .top = 273, + .width = 65, + .height = 40, + .fontSize = 30, + .lineHeigh = 35, + .textId = 0, + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + selectScreenDurationLabel = SetUpLabel(labelconfig); + if (selectScreenDurationLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::selectScreenDurationLabel new fail!"); + return false; + } + selectScreenDurationLabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + /* -------------------------------------------------------------------------- */ + return true; + } + + // 设置图片 + UIImageView *DisplayBrightnessView::SetUpImageView(ImageConfig &imageconfig) + { + UIImageView *Image = new UIImageView(); + if (Image == nullptr) + { + return nullptr; + } + Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); + Image->SetSrc(imageconfig.ImageSrc); + return Image; + } + + /// @brief 初始化显示与亮度图片 + /// @param void + /// @return true 设置成功,false 失败 + bool DisplayBrightnessView::InitDisplayBrightnessViewImage(void) + { + ImageConfig imageconfig = { + .x = 369, + .y = 157, + .w = 14, + .h = 26, + .ImageSrc = PNG_SETTING_NEXT_IMAGE, + }; + NextImage[0] = SetUpImageView(imageconfig); + if (nullptr == NextImage[0]) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::NextImage[0] is nullptr!"); + return false; + } + /* -------------------------------------------------------------------------- */ + imageconfig.y = 277; + NextImage[1] = SetUpImageView(imageconfig); + if (nullptr == NextImage[1]) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::NextImage[1] is nullptr!"); + return false; + } + /* -------------------------------------------------------------------------- */ + imageconfig = { + .x = 43, + .y = 360, + .w = 380, + .h = 100, + .ImageSrc = PNG_SETTING_BACKGROUND_IMAGE, + }; + RaiseToBrightnessImage = SetUpImageView(imageconfig); + if (nullptr == RaiseToBrightnessImage) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::RaiseToBrightnessImage is nullptr!"); + return false; + } + return true; + } + + UICheckBox *DisplayBrightnessView::SetUpCheckBox(CheckBoxConfig &checkboxconfig) // 设置复选框 + { + UICheckBox *checkbox = new UICheckBox(); + if (nullptr == checkbox) + { + return nullptr; + } + checkbox->SetPosition(checkboxconfig.x, checkboxconfig.y, checkboxconfig.w, checkboxconfig.h); + checkbox->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + checkbox->SetViewId(checkboxconfig.ViewId); + checkbox->SetImages(checkboxconfig.select, checkboxconfig.unselect); + return checkbox; + } + + /// @brief 初始化抬腕亮屏checkbox + /// @param void + /// @return true 设置成功,false 失败 + bool DisplayBrightnessView::InitDisplayBrightnessViewCheckBox(void) + { + CheckBoxConfig checkboxconfig = { + .x = 298, + .y = 385, + .w = 100, + .h = 50, + .ViewId = RAISETOBRIGHTNESSCHECKBOXBUTTON_VIEWID, + .select = PNG_TOGGLEBUTTON_ON_IMAGE, + .unselect = PNG_TOGGLEBUTTON_OFF_IMAGE, + }; + RaiseToBrightnessCheckBoxButton = SetUpCheckBox(checkboxconfig); + if (nullptr == RaiseToBrightnessCheckBoxButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::RaiseToBrightnessCheckBoxButton is nullptr"); + return false; + } + RaiseToBrightnessCheckBoxButton->SetOnChangeListener(presenter_); + return true; + } + + // 显示与亮度视图初始化 + void DisplayBrightnessView::DisplayAndBrightnessViewInit() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayAndBrightnessViewInit"); + + if (!SetUpScrollView() || !SetTheTitle() || !InitDisplayBrightnessViewButton() || !InitDisplayBrightnessViewLabel() || + !InitDisplayBrightnessViewImage() || !InitDisplayBrightnessViewCheckBox()) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayAndBrightnessViewInit fail!!"); + return; + } + DisplayBrightnessModel::GetInstance()->UpdateRaiseToBrightnessCheckBoxButtonStatus(); + DisplayBrightnessModel::GetInstance()->UpdateSelectScreenDurationLabel(); + } + + void DisplayBrightnessView::OnStart() + { + View::OnStart(); + if (!initViewStatus) + { + DisplayAndBrightnessViewInit(); + initViewStatus = true; + } + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::DisplayBrightnessPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + + if (DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW] == nullptr) + { + return; + } + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(DisplayBrightnessTitleLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(BringhtnessControlButton); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(ScreenDurationButton); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(BringhtnessControlLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(ScreenDurationLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(selectScreenDurationLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(NextImage[0]); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(NextImage[1]); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(RaiseToBrightnessImage); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(RaiseToBrightnessLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(RaiseToBrightnessCheckBoxButton); + + if (uapi_sleep_mode_flag_get()) + { + RaiseToBrightnessCheckBoxButton->SetTouchable(false); + } + else + { + RaiseToBrightnessCheckBoxButton->SetTouchable(true); + } + + RootView::GetInstance()->Add(DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]); + } + + + + + /// @brief 设置抬腕亮屏按钮状态 + /// @param state + void DisplayBrightnessView::SetRaiseToBrightnessCheckBoxButtonState(UICheckBox::UICheckBoxState state) + { + RaiseToBrightnessCheckBoxButton->SetState(state); + } + + ScreenDurationView *DisplayBrightnessView::GetScreenDurationView(void) + { + return p_ScreenDurationView; + } + + UILabelExt *DisplayBrightnessView::GetSelectScreenDurationLabel(void) + { + return selectScreenDurationLabel; + } + + // 1.切换到“屏幕与亮度”视图 + bool DisplayBrightnessView::ChangeDisplayBrightnessView(int16_t thisView) + { + if (DisplayBrightnessScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::ChangeDisplayBrightnessView"); + RootView::GetInstance()->Add(DisplayBrightnessScrollView[thisView]); + } + return true; + } + + // 2.切换到“亮屏时长”视图 + bool DisplayBrightnessView::ChangeScreenDurationView(int16_t thisView) + { + if (DisplayBrightnessScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::ChangeScreenDurationView"); + p_ScreenDurationView = new ScreenDurationView(); + if (p_ScreenDurationView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView:: new scrollView[%d] fail", thisView); + return false; + } + DisplayBrightnessScrollView[thisView] = p_ScreenDurationView->ScreenDurationViewInit(); + RootView::GetInstance()->Add(DisplayBrightnessScrollView[thisView]); + } + return true; + } + + // 1.DisplayBrightnessViewMapper:结构体定义了一个将视图ID映射到特定成员函数指针的映射表。 + struct DisplayBrightnessViewMapper + { + const int16_t viewId; + bool (DisplayBrightnessView::*func)(int16_t thisView); + }; + + // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与DisplayBrightnessViewMapper类中的特定成员函数指针进行了绑定。 + static const DisplayBrightnessViewMapper ViewMapper[] = { + {DISPLAYBRIGHTNESSVIEW, &DisplayBrightnessView::ChangeDisplayBrightnessView}, + {SCREENDURATIONVIEW, &DisplayBrightnessView::ChangeScreenDurationView}, + }; + + // 3.根据传入的interface参数执行相应视图ID关联的成员函数。 + bool DisplayBrightnessView::ClickFunc(int16_t interface) + { + int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); + for (int i = 0; i < funcSize; i++) + { + if (interface == ViewMapper[i].viewId) + { + bool jug = (this->*(ViewMapper[i].func))(interface); + if (jug == false) + { + return false; + } + return true; + } + } + return false; + } + + // 4.切换视图 + void DisplayBrightnessView::ChangeView(int16_t hideView, int16_t showView) + { + if (hideView > MAX_DISPLAYBRIGHTNESSVIEWID) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView:: SystemViewId Overstep ones bounds"); + return; + } + DisplayBrightnessScrollView[hideView]->SetVisible(false); + ClickFunc(showView); + DisplayBrightnessScrollView[showView]->SetVisible(true); + Draw(); + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/ScreenDurationView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/ScreenDurationView.cpp new file mode 100644 index 000000000..165721e39 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/displaybrightness/src/ScreenDurationView.cpp @@ -0,0 +1,323 @@ +#include "displaybrightness/include/ScreenDurationView.h" +#include "displaybrightness/include/DisplayBrightnessPresenter.h" +#include "displaybrightness/include/DisplayBrightnessModel.h" +#include "wearable_log.h" +#include "ui_resource_string.h" +#include +namespace OHOS +{ + + static ScreenDurationView *g_pScreenDurationView{nullptr}; + + ScreenDurationView::ScreenDurationView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationView"); + g_pScreenDurationView = this; + } + + ScreenDurationView::~ScreenDurationView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::~ScreenDurationView"); + ClearAll(); + g_pScreenDurationView = nullptr; + } + + ScreenDurationView *ScreenDurationView::GetInstance() + { + return g_pScreenDurationView; + } + + void ScreenDurationView::ClearAll(void) + { + if (initViewStatus == true) + { + if (ScreenDurationScrollView != nullptr) + { + ScreenDurationScrollView->RemoveAll(); + if (ScreenDurationTitleLabel != nullptr) + { + delete ScreenDurationTitleLabel; + ScreenDurationTitleLabel = nullptr; + } + for (int i = 0; i < DURATIONS; i++) + { + if (ScreenDurationLabel[i] != nullptr) + { + delete ScreenDurationLabel[i]; + ScreenDurationLabel[i] = nullptr; + } + if (ScreenDurationButton[i]) + { + delete ScreenDurationButton[i]; + ScreenDurationButton[i] = nullptr; + } + if (SimplifiedChineseRadioButtonChange[i] != nullptr) + { + delete SimplifiedChineseRadioButtonChange[i]; + SimplifiedChineseRadioButtonChange[i] = nullptr; + } + if (ScreenDurationRadioButton[i]) + { + delete ScreenDurationRadioButton[i]; + ScreenDurationRadioButton[i] = nullptr; + } + } + if (ScreenDurationButtonClickListener != nullptr) + { + delete ScreenDurationButtonClickListener; + ScreenDurationButtonClickListener = nullptr; + } + delete ScreenDurationScrollView; + ScreenDurationScrollView = nullptr; + } + } + } + + // 设置图片 + UIButton *ScreenDurationView::SetUpButtonView(ButtonConfig &buttonConfig) + { + UIButton *button = new UIButton(); + if (button == nullptr) + { + return nullptr; + } + button->SetPosition(buttonConfig.x, buttonConfig.y, buttonConfig.w, buttonConfig.h); + button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + + return button; + } + + // 设置标签 + UILabelExt *ScreenDurationView::SetUpLabel(LabelConfig &labelconfig) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小 + label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); // 字体大小 + label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高 + label->SetTextId(labelconfig.textId); // 内容 + label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 + label->SetRollSpeed(23); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } + + // 设置单选框 + UIRadioButton *ScreenDurationView::SetUpRadioButton(RadioButtonConfig &radiobuttonconfig) + { + UIRadioButton *radiobutton = new UIRadioButton("ScreenDuration"); + if (nullptr == radiobutton) + { + return nullptr; + } + radiobutton->SetPosition(radiobuttonconfig.x, radiobuttonconfig.y, radiobuttonconfig.w, radiobuttonconfig.h); + radiobutton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + radiobutton->SetImages(radiobuttonconfig.select, radiobuttonconfig.unselect); + return radiobutton; + } + + // 亮屏时长视图“scrollView”初始化 + bool ScreenDurationView::SetUpScrollView(void) + { + ScreenDurationScrollView = new UIScrollView(); + if (ScreenDurationScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationScrollView new fail!"); + return false; + } + ScreenDurationScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + ScreenDurationScrollView->SetViewId(SCREENDURATIONSCROLLVIEW); + ScreenDurationScrollView->SetScrollBlankSize(75); + ScreenDurationScrollView->SetReboundSize(35); + ScreenDurationScrollView->SetDirection(1); + ScreenDurationScrollView->SetMaxScrollDistance(1000); + ScreenDurationScrollView->SetThrowDrag(true); + ScreenDurationScrollView->RequestFocus(); + ScreenDurationScrollView->SetRotateFactor(2); + UIView::OnDragListener *draglistener = static_cast(DisplayBrightnessPresenter::GetInstance()); + if (draglistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::draglistener can not be nullptr!"); + return false; + } + ScreenDurationScrollView->SetOnDragListener(draglistener); + ScreenDurationScrollView->SetTouchable(true); + ScreenDurationScrollView->SetDraggable(true); + return true; + } + + // 亮屏时长视图“图片”初始化 + bool ScreenDurationView::SetUpScreenDurationViewImageView(void) + { + ButtonConfig buttonConfig = { + .x = 39, + .y = 120, + .w = 380, + .h = 100, + }; + + ScreenDurationButtonClickListener = static_cast(new ScreenDurationRadiobuttonOnChangeListener()); + + for (int i = 0; i < DURATIONS; i++) + { + buttonConfig.y = 120 + (i * 120); + ScreenDurationButton[i] = SetUpButtonView(buttonConfig); + if (ScreenDurationButton[i] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationButton[%d] is nullptr!", i); + return false; + } + ScreenDurationButton[i]->SetOnClickListener(ScreenDurationButtonClickListener); + } + return true; + } + + // 亮屏时长视图“标签”初始化 + bool ScreenDurationView::SetUpScreenDurationViewLabel(void) + { + // 创建ScreenDurationTitleLabel + LabelConfig labelconfig = { + .left = 83, + .top = 50, + .width = 300, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_SCREEN_ON_DURATION, /*亮屏时长*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + + ScreenDurationTitleLabel = SetUpLabel(labelconfig); + if (nullptr == ScreenDurationTitleLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::SetUpScreenDurationViewLabel is nullptr!"); + return false; + } + ScreenDurationTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + + // 创建ScreenDurationLabel + labelconfig = { + .left = 103, + .top = 153, + .width = 210, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_SCREEN_ON_DURATION, + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + + // const char *durations[DURATIONS] = {"5秒", "10秒", "15秒", "30秒", "60秒", "300秒"}; + UIResourceTextId durations[DURATIONS] = {STR_5_SECONDS, STR_10_SECONDS, STR_15_SECONDS, STR_30_SECONDS, STR_60_SECONDS, STR_300_SECONDS}; + + for (int i = 0; i < DURATIONS; i++) + { + labelconfig.top = 153 + (i * 120); + labelconfig.textId = durations[i]; + ScreenDurationLabel[i] = SetUpLabel(labelconfig); + if (ScreenDurationLabel[i] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationLabel[%d] is nullptr!", i); + return false; + } + ScreenDurationLabel[i]->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + } + + return true; + } + + // 亮屏时长视图“单选框”初始化 + bool ScreenDurationView::SetUpScreenDurationViewRadioButton(void) + { + RadioButtonConfig radiobuttonconfig = { + .x = 300, + .w = 80, + .h = 80, + .select = PNG_CHECKBOX_ON_IMAGE, + .unselect = PNG_CHECKBOX_OFF_IMAGE, + }; + + int y_positions = 130; + for (int i = 0; i < DURATIONS; i++) + { + radiobuttonconfig.y = y_positions + 120 * i; + ScreenDurationRadioButton[i] = SetUpRadioButton(radiobuttonconfig); + if (ScreenDurationRadioButton[i] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationRadioButton[%d] is nullptr!", i); + return false; + } + SimplifiedChineseRadioButtonChange[i] = static_cast(new ScreenDurationRadiobuttonOnChangeListener(ScreenDurationRadioButton[i])); + ScreenDurationRadioButton[i]->SetOnChangeListener(SimplifiedChineseRadioButtonChange[i]); + } + + return true; + } + + // 亮屏时长视图初始化 + UIScrollView *ScreenDurationView::ScreenDurationViewInit(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationViewInit"); + if (!SetUpScrollView() || !SetUpScreenDurationViewImageView() || + !SetUpScreenDurationViewLabel() || !SetUpScreenDurationViewRadioButton()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationViewInit fail!!"); + return nullptr; + } + + if (!DisplayBrightnessModel::GetInstance()->UpdateScreenDurationRadioButtonSlectStatus()) + { + return nullptr; + } + + /* ----------------------------------- Add ---------------------------------- */ + ScreenDurationScrollView->Add(ScreenDurationTitleLabel); + for (int i = 0; i < DURATIONS; i++) + { + ScreenDurationScrollView->Add(ScreenDurationButton[i]); + ScreenDurationScrollView->Add(ScreenDurationLabel[i]); + ScreenDurationScrollView->Add(ScreenDurationRadioButton[i]); + } + initViewStatus = true; + return ScreenDurationScrollView; + } + + // 设置哪个单选按钮被选中 + void ScreenDurationView::SetRadioButtonSelectStatus(int16_t index) + { + if (index >= DURATIONS || index < 0) + { + return; + } + + if (ScreenDurationRadioButton[index] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationRadioButton[%d] is nullptr!", index); + return; + } + + for (int i = 0; i < DURATIONS; i++) + { + ScreenDurationRadioButton[i]->SetState(i == index ? UICheckBox::SELECTED : UICheckBox::UNSELECTED); + } + } + + UIRadioButton *ScreenDurationView::GetRadioButton(int16_t i) + { + if (ScreenDurationRadioButton[i] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationRadioButton[%d] is nullptr!", i); + return nullptr; + } + return ScreenDurationRadioButton[i]; + } + + UIButton *ScreenDurationView::GetScreenDurationButton(int16_t i) + { + return ScreenDurationButton[i]; + } +} \ No newline at end of file