From: luozheng <1732036298@qq.com> Date: Sun, 18 Feb 2024 10:40:39 +0000 (+0800) Subject: 屏幕与亮度视图完善,但亮屏时长视图选择一个按钮,打印日志中则显示选择两个,目前不知道什么原因 X-Git-Tag: release_V1.2.70_20241020_135402~1304 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=d5c257039b538559994b74776dc6bfb4b1418808;p=mirrors%2FFD230.git 屏幕与亮度视图完善,但亮屏时长视图选择一个按钮,打印日志中则显示选择两个,目前不知道什么原因 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index ca0834048..0302837ba 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -261,7 +261,6 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/displaybrightness/src/DisplayBrightnessView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/displaybrightness/src/BrightnessControlView.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/displaybrightness/src/ScreenDurationPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/displaybrightness/src/ScreenDurationView.cpp #辅助功能 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 1ac992979..df179b59f 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -50,7 +50,6 @@ typedef enum : uint16_t VIEW_CALL_VOLUME, // 通话音量 VIEW_MEDIA_VOLUME, // 媒体音量 VIEW_DISPLAY_BRIGHTNESS, // 屏幕与亮度 - VIEW_SCREEN_DURATION, // 亮屏时长 VIEW_SECONDARY_FUNCTION, // 辅助功能 VIEW_QUICK_ACCESS, // 快速访问 VIEW_FAST_TRAINING, // 快速训练 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 67c76d3ec..b2133ebb3 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -56,8 +56,7 @@ namespace OHOS void InitMediaVolumeSlice(void); void InitMessageSlice(void); /* -------------------------------------------------------------------------- */ - void InitUIDisplayBrightnessSlice(void); - void InitScreenDurationSlice(void); + void InitDisplayBrightnessSlice(void); /* --------------------------------测试界面------------------------------------ */ void InitDialSlice(void); void InitBloodSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 81cb8d6fa..42f668e6e 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -80,8 +80,6 @@ #include "displaybrightness/include/DisplayBrightnessPresenter.h" #include "displaybrightness/include/DisplayBrightnessView.h" -#include "displaybrightness/include/ScreenDurationPresenter.h" -#include "displaybrightness/include/ScreenDurationView.h" #include "message/include/MessageAdapter.h" #include "message/include/MessageView.h" @@ -146,9 +144,7 @@ namespace OHOS {VIEW_SOUND_VIBRATION, &NativeLauncher::InitSoundAndVibrationSlice}, // 声音与震动实例化地址 {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice}, // 系统音量 - {VIEW_DISPLAY_BRIGHTNESS, &NativeLauncher::InitUIDisplayBrightnessSlice}, // 显示与亮度的实例化地址 - {VIEW_SCREEN_DURATION, &NativeLauncher::InitScreenDurationSlice}, // 亮屏时长实例化地址 - + {VIEW_DISPLAY_BRIGHTNESS, &NativeLauncher::InitDisplayBrightnessSlice}, // 显示与亮度的实例化地址 {VIEW_SECONDARY_FUNCTION, &NativeLauncher::InitSecondaryFunction}, {VIEW_QUICK_ACCESS, &NativeLauncher::InitQuickAccessSlice}, // 快速访问实例化地址 {VIEW_FAST_TRAINING, &NativeLauncher::InitFastTrainingSlice}, @@ -548,7 +544,7 @@ namespace OHOS } // DisplayBrightness的实例化 - void NativeLauncher::InitUIDisplayBrightnessSlice(void) + void NativeLauncher::InitDisplayBrightnessSlice(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitUISampleSlice"); SliceProxy *uidisplaybrightnessView = new AbilitySliceProxy; @@ -560,15 +556,6 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_DISPLAY_BRIGHTNESS, uidisplaybrightnessView); } - void NativeLauncher::InitScreenDurationSlice(void) - { - SliceProxy *ScreenDuration = new AbilitySliceProxy; - if (ScreenDuration == nullptr) - { - return; - } - NativeAbility::GetInstance().AddSliceProxy(VIEW_SCREEN_DURATION, ScreenDuration); - } void NativeLauncher::InitSecondaryFunction(void) // 辅助功能 { diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/BrightnessControlPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/BrightnessControlPresenter.h deleted file mode 100644 index 33f35b322..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/BrightnessControlPresenter.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef BRIGHTNESS_CONTROL_PRESENTER_H -#define BRIGHTNESS_CONTROL_PRESENTER_H - - -#include "Presenter.h" - -#include "BrightnessControlView.h" - -namespace OHOS -{ - class BrightnessControlView; - - class BrightnessControlPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener - { - public: - BrightnessControlPresenter(); - virtual ~BrightnessControlPresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - - static BrightnessControlPresenter *GetInstance(); - - private: - //因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - }; -} //namespace OHOS - - - -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h index fb924aa75..8a60fddbd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h @@ -18,6 +18,27 @@ namespace OHOS static const char *BRINGHTNESSCONTROLBUTTON_VIEW = "BRINGHTNESSCONTROLBUTTON"; // 亮度调节按钮视图id static const char *SCREENDURATIONBUTTON_VIEWID = "SCREENDURATIONBUTTON"; // 亮屏时长按钮视图id static const char *RAISETOBRIGHTNESSCHECKBOXBUTTON_VIEWID = "RAISETOBRIGHTNESSCHECKBOXBUTTON"; // 抬腕亮屏checkbox按钮视图id + + static const char *SCREENDURATION_FIVESECONDS_VIEWID = "SCREENDURATION_FIVESECONDS"; // 5秒时长 + static const char *SCREENDURATION_TENSECONDS_VIEWID = "SCREENDURATION_TENSECONDS"; // 10秒时长 + static const char *SCREENDURATION_FIFTEENSECONDS_VIEWID = "SCREENDURATION_FIFTEENSECONDS"; // 15秒时长 + + class ScreenDurationRadiobuttonOnChangeListener : public UICheckBox::OnChangeListener + { + public: + ScreenDurationRadiobuttonOnChangeListener(){} + ~ScreenDurationRadiobuttonOnChangeListener() {} + bool isRadioButtonSelected(int index); + void SetRadioButton(UIRadioButton *radiobutton, int16_t i) + { + m_radiobutton[i] = radiobutton; + } + bool OnChange(UICheckBox::UICheckBoxState state) override; + + private: + UIRadioButton *m_radiobutton[3]{nullptr}; + }; + class DisplayBrightnessView; class DisplayBrightnessPresenter : public Presenter, public UIView::OnClickListener, diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessView.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessView.h index 0f5160c3e..ab6470fc6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessView.h @@ -8,8 +8,10 @@ #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/BrightnessControlView.h" +#include "displaybrightness/include/ScreenDurationView.h" namespace OHOS { @@ -66,6 +68,7 @@ namespace OHOS bool ClickFunc(int16_t interface); void ChangeView(int16_t hideView, int16_t showView); UIScrollView *GetDisplayBrightnessScrollView(int16_t i); + public: void OnStart() override; void OnSetUpView() override; @@ -74,6 +77,7 @@ namespace OHOS private: BrightnessControlView *p_BrightnessControlView{nullptr}; // 亮度调节视图 + ScreenDurationView *p_ScreenDurationView{nullptr}; // 亮屏时长视图 private: bool SetUpScrollView(void); bool SetTheTitle(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationPresenter.h deleted file mode 100644 index 6d028fab4..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationPresenter.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef SCREEN_DUATION_PRESENTER_H -#define SCREEN_DUATION_PRESENTER_H - -#include "Presenter.h" - -#include "ScreenDurationView.h" -#include "components/ui_checkbox.h" -#include "components/ui_label.h" -namespace OHOS -{ - class ScreenDurationView; - - class ScreenDurationPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener - { - public: - ScreenDurationPresenter(); - virtual ~ScreenDurationPresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - static ScreenDurationPresenter *GetInstance(); - void getcheckbox(UICheckBox *checkbox_5,UICheckBox *checkbox_10,UICheckBox *checkbox_15){ - m_checkbox_5 = checkbox_5; - m_checkbox_10 = checkbox_10; - m_checkbox_15 = checkbox_15; - } - void UpdateCheckBoxState(UICheckBox &checkbox, bool isSelected); - private: - // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - - private: - UICheckBox *m_checkbox_5 = nullptr; - UICheckBox *m_checkbox_10 = nullptr; - UICheckBox *m_checkbox_15 = nullptr; - }; -} // namespace OHOS - -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h index 2b99b6481..e26e89981 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h @@ -1,44 +1,67 @@ #ifndef SCREEN_DUATION_VIEW_H #define SCREEN_DUATION_VIEW_H -//屏幕时长 +// 屏幕时长 #include "BaseView.h" #include "View.h" -#include "components/ui_view_group.h" #include "components/ui_scroll_view.h" #include "components/ui_image_view.h" #include "components/ui_label.h" -#include "components/ui_checkbox.h" +#include "components/ui_radio_button.h" namespace OHOS { - static const char *SECOND5_CHECKBOX = "5secCheckbox"; // 5秒 - static const char *SECOND10_CHECKBOX = "10secCheckbox"; // 10秒 - static const char *SECOND15_CHECKBOX = "15secCheckbox"; // 15秒 - class ScreenDurationPresenter; - class ScreenDurationView : public View + class ScreenDurationView { - public: + struct ImageConfig + { + int16_t x; + int16_t y; + int16_t w; + int16_t h; + const char *ImageSrc; + }; + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + const char *text; // 文本 + 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); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; - - public: - UICheckBox *second5checkbox = nullptr; - UICheckBox *second10checkbox = nullptr; - UICheckBox *second15checkbox = nullptr; - - private: - void InitView(void); + UIScrollView *ScreenDurationViewInit(void); + void ClearAll(void); + UIRadioButton *GetRadioButton(int16_t i); private: - UIViewGroup *container_ = nullptr; + UIImageView *SetUpImageView(ImageConfig &imageconfig); // 设置图片 + UILabel *SetUpLabel(LabelConfig &labelconfig); // 设置标签 + UIRadioButton *SetUpRadioButton(RadioButtonConfig &radiobuttonconfig); // 设置单选框 + bool SetUpScrollView(void); + bool SetUpScreenDurationViewLabel(void); + bool SetUpScreenDurationViewImageView(void); + bool SetUpScreenDurationViewRadioButton(void); UIScrollView *ScreenDurationScrollView = nullptr; - UILabel *ScreenDurationLabel = nullptr; + UILabel *ScreenDurationTitleLabel = nullptr; // 标题 + UILabel *ScreenDurationLabel[3]{nullptr}; // 亮屏时长标签 + UIImageView *BackGroundImage[3]{nullptr}; // 放置组件的背景 + UIRadioButton *ScreenDurationRadioButton[3]{nullptr}; // 三个单选框 + bool initViewStatus{false}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlPresenter.cpp deleted file mode 100644 index c9ffc6f64..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlPresenter.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "displaybrightness/include/BrightnessControlPresenter.h" - -namespace OHOS{ - - //当前Presenter属性实例化的内存指针 - static BrightnessControlPresenter *g_pBrightnessControlPresenter = nullptr; - - BrightnessControlPresenter::BrightnessControlPresenter(){ - - g_pBrightnessControlPresenter = this; - } - - BrightnessControlPresenter::~BrightnessControlPresenter(){ - - g_pBrightnessControlPresenter = nullptr; - } - - BrightnessControlPresenter *BrightnessControlPresenter::GetInstance(){ - - return g_pBrightnessControlPresenter; - } - - void BrightnessControlPresenter::OnStart(){ - - Presenter::OnStart(); - } - - void BrightnessControlPresenter::OnPause(void){ - - Presenter::OnPause(); - } - - void BrightnessControlPresenter::OnResume(void){ - - Presenter::OnResume(); - } - - void BrightnessControlPresenter::OnStop(void){ - - Presenter::OnStop(); - } - - bool BrightnessControlPresenter::OnDrag(UIView &view, const DragEvent &event){ - - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_DISPLAY_BRIGHTNESS);//跳转到显示与亮度view - } - if(strcmp(view.GetViewId(), BRIGHTNESS_CONTROL_SLIDER)) - { - - } - return true; - } - - bool BrightnessControlPresenter::OnClick(UIView &view, const ClickEvent &event){ - - // 根据控件id查找是哪个控件触发了点击回调 - // if (strcmp(view.GetViewId(), 控件ID) == 0) - if(strcmp(view.GetViewId(), BRIGHTNESS_CONTROL_SLIDER)) - { - - } - return true; - } -} - - - - - - diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp index 94aaa7f52..1ef39dc88 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp @@ -94,7 +94,7 @@ namespace OHOS return false; } BrightnessControlViewImageIcon->SetPosition(213, 213, 40, 40); - const char *image = "/user/res/VolumeControlVector.bin"; + const char *image = "/user/res/BringhtnessContuolVector.bin"; BrightnessControlViewImageIcon->SetSrc(image); return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp index a372edc86..5d4d1495b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp @@ -61,7 +61,7 @@ namespace OHOS } if (strcmp(view.GetViewId(), SCREENDURATIONBUTTON_VIEWID) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_SCREEN_DURATION); // 亮屏时长 + p_DisplayBrightnessView->ChangeView(DISPLAYBRIGHTNESSVIEW, SCREENDURATIONVIEW); // 切换到亮屏时长视图 return true; } return false; @@ -79,7 +79,8 @@ namespace OHOS { for (int i = 0; i < MAX_DISPLAYBRIGHTNESSVIEWID; i++) { - if (p_DisplayBrightnessView->GetDisplayBrightnessScrollView(i)->IsVisible() == true) + if (p_DisplayBrightnessView->GetDisplayBrightnessScrollView(i) != nullptr && + p_DisplayBrightnessView->GetDisplayBrightnessScrollView(i)->IsVisible() == true) { if (i == DISPLAYBRIGHTNESSVIEW) { @@ -112,4 +113,48 @@ namespace OHOS } return true; } + + bool ScreenDurationRadiobuttonOnChangeListener::isRadioButtonSelected(int index) + { + if (m_radiobutton[index]->GetState() == UICheckBox::SELECTED) + { + return true; + } + return false; + } + + bool ScreenDurationRadiobuttonOnChangeListener::OnChange(UICheckBox::UICheckBoxState state) + { + switch (state) + { + case UICheckBox::SELECTED: + for (int i = 0; i < 3; i++) + { + if (isRadioButtonSelected(i)) + { + switch (i) + { + case 0: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Switched to 5 seconds"); + break; + case 1: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Switched to 10 seconds"); + break; + case 2: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Switched to 15 seconds"); + break; + default: + break; + } + } + } + case UICheckBox::UNSELECTED: + // Handle unselected state if needed + break; + default: + break; + } + + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp index a2f6d53cf..6abc77df1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp @@ -397,6 +397,19 @@ namespace OHOS // 3.切换到“亮屏时长”视图 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; } /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationPresenter.cpp deleted file mode 100644 index d3442cf59..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationPresenter.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "displaybrightness/include/ScreenDurationPresenter.h" -#include "components/ui_checkbox.h" -namespace OHOS -{ - - // 当前Presenter属性实例化的内存指针 - static ScreenDurationPresenter *g_pScreenDurationPresenter = nullptr; - - ScreenDurationPresenter::ScreenDurationPresenter() - { - - g_pScreenDurationPresenter = this; - } - - ScreenDurationPresenter::~ScreenDurationPresenter() - { - - g_pScreenDurationPresenter = nullptr; - } - - ScreenDurationPresenter *ScreenDurationPresenter::GetInstance() - { - - return g_pScreenDurationPresenter; - } - - - - void ScreenDurationPresenter::OnStart() - { - - Presenter::OnStart(); - } - - void ScreenDurationPresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void ScreenDurationPresenter::OnResume(void) - { - - Presenter::OnResume(); - } - - void ScreenDurationPresenter::OnStop(void) - { - - Presenter::OnStop(); - } - - bool ScreenDurationPresenter::OnDrag(UIView &view, const DragEvent &event) - { - - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_DISPLAY_BRIGHTNESS); // 跳转到显示与亮度view - } - return true; - } - - - - bool ScreenDurationPresenter::OnClick(UIView &view, const ClickEvent &event) - { - // 根据控件id查找是哪个控件触发了点击回调 - if (strcmp(view.GetViewId(), SECOND5_CHECKBOX) == 0) - { - m_checkbox_5->SetState(UICheckBox::SELECTED); - UpdateCheckBoxState(*m_checkbox_10, false); - UpdateCheckBoxState(*m_checkbox_15, false); - return true; - } - else if (strcmp(view.GetViewId(), SECOND10_CHECKBOX) == 0) - { - m_checkbox_10->SetState(UICheckBox::SELECTED); - UpdateCheckBoxState(*m_checkbox_5, false); - UpdateCheckBoxState(*m_checkbox_15, false); - } - else if (strcmp(view.GetViewId(), SECOND15_CHECKBOX) == 0) - { - m_checkbox_15->SetState(UICheckBox::SELECTED); - UpdateCheckBoxState(*m_checkbox_5, false); - UpdateCheckBoxState(*m_checkbox_10, false); - } - return false; - } - void ScreenDurationPresenter::UpdateCheckBoxState(UICheckBox &checkbox, bool isSelected) - { - checkbox.SetState(isSelected ? UICheckBox::SELECTED : UICheckBox::UNSELECTED); - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp index dbebfbc23..6631a548d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp @@ -1,7 +1,6 @@ #include "displaybrightness/include/ScreenDurationView.h" -#include "displaybrightness/include/ScreenDurationPresenter.h" -#include "UiConfig.h" - +#include "displaybrightness/include/DisplayBrightnessPresenter.h" +#include "wearable_log.h" namespace OHOS { @@ -9,19 +8,14 @@ namespace OHOS ScreenDurationView::ScreenDurationView() { - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationView"); g_pScreenDurationView = this; } ScreenDurationView::~ScreenDurationView() { - container_->RemoveAll(); - delete ScreenDurationScrollView; - ScreenDurationScrollView = nullptr; - delete ScreenDurationLabel; - ScreenDurationLabel = nullptr; - delete container_; - container_ = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::~ScreenDurationView"); + ClearAll(); g_pScreenDurationView = nullptr; } @@ -30,242 +24,248 @@ namespace OHOS return g_pScreenDurationView; } - void ScreenDurationView::InitView(void) + void ScreenDurationView::ClearAll(void) { - if (container_ == nullptr) + if (initViewStatus == true) { - container_ = new UIViewGroup(); - container_->SetPosition(0, 0, 466, 466); - container_->SetStyle(STYLE_BACKGROUND_OPA, 0); - UIView::OnDragListener *draglistener = static_cast(ScreenDurationPresenter::GetInstance()); - if (draglistener == nullptr) + ScreenDurationScrollView->RemoveAll(); + + delete ScreenDurationTitleLabel; + ScreenDurationTitleLabel = nullptr; + + for (int i = 0; i < 3; i++) { - return; + delete ScreenDurationLabel[i]; + ScreenDurationLabel[i] = nullptr; + + delete BackGroundImage[i]; + BackGroundImage[i] = nullptr; + + delete ScreenDurationRadioButton[i]; + ScreenDurationRadioButton[i] = nullptr; } - container_->SetOnDragListener(draglistener); - container_->SetTouchable(true); - container_->SetDraggable(true); + + delete ScreenDurationScrollView; + ScreenDurationScrollView = nullptr; } + } - // Add ScrollView to App - if (ScreenDurationScrollView == nullptr) + UIRadioButton *ScreenDurationView::GetRadioButton(int16_t i) + { + if (ScreenDurationRadioButton[i] == nullptr) { - ScreenDurationScrollView = new UIScrollView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationRadioButton[%d] is nullptr!", i); + return nullptr; } - ScreenDurationScrollView->SetPosition(0, 0); - ScreenDurationScrollView->Resize(466, 466); - ScreenDurationScrollView->SetViewId("ScreenDurationScrollView"); - ScreenDurationScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - container_->Add(ScreenDurationScrollView); - ScreenDurationScrollView->SetVisible(true); + return ScreenDurationRadioButton[i]; + } - // Add Label to App - if (ScreenDurationLabel == nullptr) + // 设置图片 + UIImageView *ScreenDurationView::SetUpImageView(ImageConfig &imageconfig) + { + UIImageView *Image = new UIImageView(); + if (Image == nullptr) { - ScreenDurationLabel = new UILabel(); + return nullptr; } - ScreenDurationLabel->SetPosition(173, 52); // widget's left position and top position - ScreenDurationLabel->Resize(120, 35); // widget's width and height - ScreenDurationLabel->SetViewId("ScreenDurationLabel"); // Set style - ScreenDurationLabel->SetStyle(STYLE_TEXT_FONT, 30); - ScreenDurationLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - - // Set additional property - ScreenDurationLabel->SetText("亮屏时长"); - ScreenDurationLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - ScreenDurationLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - ScreenDurationLabel->SetRollSpeed(0); - ScreenDurationLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to scrollView1 - ScreenDurationScrollView->Add(ScreenDurationLabel); - ScreenDurationLabel->SetVisible(true); - /********************************************************************************************************/ - // Add ImageView to App - UIImageView *secImage5 = new UIImageView(); - secImage5->SetPosition(39, 120); - secImage5->Resize(380, 100); - secImage5->SetViewId("5secImage"); - secImage5->SetStyle(STYLE_BORDER_RADIUS, 50); - secImage5->SetSrc(PNG_SETTING_BACKGROUND_IMAGE); - ScreenDurationScrollView->Add(secImage5); - secImage5->SetVisible(true); - // Add Label to App - UILabel *secLabel5 = new UILabel(); - secLabel5->SetPosition(99, 153); - secLabel5->Resize(48, 35); - secLabel5->SetViewId("5secLabel"); - secLabel5->SetStyle(STYLE_TEXT_FONT, 30); - secLabel5->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - secLabel5->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - secLabel5->SetStyle(STYLE_LINE_HEIGHT, 35); - - secLabel5->SetText("5秒"); - secLabel5->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - secLabel5->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - secLabel5->SetRollSpeed(6); - secLabel5->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - ScreenDurationScrollView->Add(secLabel5); - secLabel5->SetVisible(true); - - // Add CheckBox to App - second5checkbox = new UICheckBox(); - second5checkbox->SetPosition(300, 130); - second5checkbox->Resize(80, 80); - second5checkbox->SetViewId(SECOND5_CHECKBOX); - second5checkbox->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - second5checkbox->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - second5checkbox->SetImages(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_OFF_IMAGE); - - ScreenDurationScrollView->Add(second5checkbox); - second5checkbox->SetVisible(true); - /********************************************************************************************************/ - // Add ImageView to App - UIImageView *secImage10 = new UIImageView(); - secImage10->SetPosition(39, 240); - secImage10->Resize(380, 100); - secImage10->SetViewId("10secImage"); - secImage10->SetStyle(STYLE_BORDER_RADIUS, 50); - secImage10->SetSrc(PNG_SETTING_BACKGROUND_IMAGE); - ScreenDurationScrollView->Add(secImage10); - secImage10->SetVisible(true); - - // Add Label to App - UILabel *secLabel10 = new UILabel(); - secLabel10->SetPosition(99, 273); - secLabel10->Resize(65, 35); - secLabel10->SetViewId("10secLabel"); - secLabel10->SetStyle(STYLE_TEXT_FONT, 30); - secLabel10->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - secLabel10->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - secLabel10->SetStyle(STYLE_LINE_HEIGHT, 35); - - secLabel10->SetText("10秒"); - secLabel10->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - secLabel10->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - secLabel10->SetRollSpeed(6); - secLabel10->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - ScreenDurationScrollView->Add(secLabel10); - secLabel10->SetVisible(true); - - // Add CheckBox to App - second10checkbox = new UICheckBox(); - second10checkbox->SetPosition(300, 250); - second10checkbox->Resize(80, 80); - second10checkbox->SetViewId(SECOND10_CHECKBOX); - second10checkbox->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - second10checkbox->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - second10checkbox->SetImages(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_OFF_IMAGE); - - ScreenDurationScrollView->Add(second10checkbox); - second10checkbox->SetVisible(true); - /********************************************************************************************************/ - // Add ImageView to App - UIImageView *secImage15 = new UIImageView(); - secImage15->SetPosition(39, 360); - secImage15->Resize(380, 100); - secImage15->SetViewId("15secImage"); - secImage15->SetStyle(STYLE_BORDER_RADIUS, 50); - secImage15->SetSrc(PNG_SETTING_BACKGROUND_IMAGE); - ScreenDurationScrollView->Add(secImage15); - secImage15->SetVisible(true); - - // Add Label to App - UILabel *secLabel15 = new UILabel(); - secLabel15->SetPosition(99, 393); - secLabel15->Resize(65, 35); - secLabel15->SetViewId("15secLabel"); - secLabel15->SetStyle(STYLE_TEXT_FONT, 30); - secLabel15->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - secLabel15->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - secLabel15->SetStyle(STYLE_LINE_HEIGHT, 35); - - secLabel15->SetText("15秒"); - secLabel15->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - secLabel15->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - secLabel15->SetRollSpeed(6); - secLabel15->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - ScreenDurationScrollView->Add(secLabel15); - secLabel15->SetVisible(true); - - // Add CheckBox to App - second15checkbox = new UICheckBox(); - second15checkbox->SetPosition(300, 370); - second15checkbox->Resize(80, 80); - second15checkbox->SetViewId(SECOND15_CHECKBOX); - second15checkbox->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - second15checkbox->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - second15checkbox->SetImages(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_OFF_IMAGE); - - ScreenDurationScrollView->Add(second15checkbox); - second15checkbox->SetVisible(true); - /********************************************************************************************************/ - // AddLabelImageViewCheckbox(ScreenDurationScrollView, 99, 153, 48, 35, "5秒", "5secLabel", - // 39, 120, 380, 100, "5secImage", PNG_SETTING_BACKGROUND_IMAGE, - // second5checkbox, 300, 130, 80, 80, SECOND5_CHECKBOX, PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_OFF_IMAGE); - /* - AddLabelImageViewCheckbox(ScreenDurationScrollView, 99, 273, 65, 35, "10秒", "10secLabel", - 39, 240, 380, 100, "10secImage", PNG_SETTING_BACKGROUND_IMAGE, - second10checkbox, 300, 250, 80, 80, SECOND10_CHECKBOX, PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_OFF_IMAGE); - - AddLabelImageViewCheckbox(ScreenDurationScrollView, 99, 393, 65, 35, "15秒", "15secLabel", - 39, 360, 380, 100, "15secImage", PNG_SETTING_BACKGROUND_IMAGE, - second15checkbox, 300, 370, 80, 80, SECOND15_CHECKBOX, PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_OFF_IMAGE); - */ - - /********************************************************************************************************/ - UIImageView *image1_ = new UIImageView(); - - image1_->SetPosition(183, 440); - image1_->Resize(100, 100); - image1_->SetViewId("image1"); - ScreenDurationScrollView->Add(image1_); - image1_->SetVisible(true); - /********************************************************************************************************/ - - UIImageView *image2_ = new UIImageView(); + Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); + Image->SetSrc(imageconfig.ImageSrc); + return Image; + } - image2_->SetPosition(183, 19); - image2_->Resize(100, 100); - image2_->SetViewId("image2"); - ScreenDurationScrollView->Add(image2_); - image2_->SetVisible(true); + // 设置标签 + UILabel *ScreenDurationView::SetUpLabel(LabelConfig &labelconfig) + { + UILabel *label = new UILabel(); + 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->SetText(labelconfig.text); // 内容 + label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } - ScreenDurationPresenter::GetInstance()->getcheckbox(second5checkbox,second10checkbox,second15checkbox); - UIView::OnClickListener *checkboxClick = static_cast(ScreenDurationPresenter::GetInstance()); - second5checkbox->SetOnClickListener(checkboxClick); - second10checkbox->SetOnClickListener(checkboxClick); - second15checkbox->SetOnClickListener(checkboxClick); + // 设置单选框 + 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; } - void ScreenDurationView::OnStart() + // 亮屏时长视图“scrollView”初始化 + bool ScreenDurationView::SetUpScrollView(void) { - View::OnStart(); - InitView(); - RootView::GetInstance()->Add(container_); + 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->SetScrollBlankSize(35); + ScreenDurationScrollView->SetReboundSize(50); + ScreenDurationScrollView->SetDirection(1); + 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; } - void ScreenDurationView::OnSetUpView() + // 亮屏时长视图“图片”初始化 + bool ScreenDurationView::SetUpScreenDurationViewImageView(void) { - View::OnSetUpView(); - Draw(); + ImageConfig imageconfig = { + .x = 39, + .y = 120, + .w = 380, + .h = 100, + .ImageSrc = "/user/res/SETTING_BACKGROUND.bin", + }; + + for (int i = 0; i < 3; i++) + { + imageconfig.y = 120 + (i * 120); + BackGroundImage[i] = SetUpImageView(imageconfig); + if (BackGroundImage[i] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::BackGroundImage[%d] is nullptr!", i); + return false; + } + } + return true; } - void ScreenDurationView::OnTearDownView() + // 亮屏时长视图“标签”初始化 + bool ScreenDurationView::SetUpScreenDurationViewLabel(void) { + // 创建ScreenDurationTitleLabel + LabelConfig labelconfig = { + .left = 173, + .top = 52, + .width = 120, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .text = "亮屏时长", + .lineBreakMode = UILabel::LINE_BREAK_ADAPT, + }; + + ScreenDurationTitleLabel = SetUpLabel(labelconfig); + if (nullptr == ScreenDurationTitleLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::SetUpScreenDurationViewLabel is nullptr!"); + return false; + } + + // 创建ScreenDurationLabel + labelconfig = { + .left = 99, + .fontSize = 30, + .lineHeigh = 35, + .lineBreakMode = UILabel::LINE_BREAK_ADAPT, + }; + + const char *durations[] = {"5秒", "10秒", "15秒"}; + + for (int i = 0; i < 3; i++) + { + labelconfig.top = 153 + (i * 120); + labelconfig.text = durations[i]; + ScreenDurationLabel[i] = SetUpLabel(labelconfig); + if (ScreenDurationLabel[i] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationLabel[%d] is nullptr!", i); + return false; + } + } - View::OnTearDownView(); - return; + return true; } - void ScreenDurationView::OnStop() + // 亮屏时长视图“单选框”初始化 + bool ScreenDurationView::SetUpScreenDurationViewRadioButton(void) { + RadioButtonConfig radiobuttonconfig = { + .x = 300, + .w = 80, + .h = 80, + .select = "/user/res/CHECKBOX_ON.bin", + .unselect = "/user/res/CHECKBOX_OFF.bin", + }; + + int y_positions[] = {130, 250, 370}; + const char *viewID[] = {SCREENDURATION_FIVESECONDS_VIEWID, SCREENDURATION_TENSECONDS_VIEWID, SCREENDURATION_FIFTEENSECONDS_VIEWID}; + ScreenDurationRadiobuttonOnChangeListener *p_ScreenDurationRadiobuttonOnChangeListener = new ScreenDurationRadiobuttonOnChangeListener(); + UICheckBox::OnChangeListener *SimplifiedChineseRadioButtonChange = static_cast(p_ScreenDurationRadiobuttonOnChangeListener); + for (int i = 0; i < 3; i++) + { + radiobuttonconfig.y = y_positions[i]; + radiobuttonconfig.viewId = viewID[i]; + ScreenDurationRadioButton[i] = SetUpRadioButton(radiobuttonconfig); + if (ScreenDurationRadioButton[i] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationRadioButton[%d] is nullptr!", i); + return false; + } + p_ScreenDurationRadiobuttonOnChangeListener->SetRadioButton(ScreenDurationRadioButton[i],i); + ScreenDurationRadioButton[i]->SetOnChangeListener(SimplifiedChineseRadioButtonChange); + } - View::OnStop(); - RootView::GetInstance()->RemoveAll(); - return; + return true; + } + + // 亮屏时长视图初始化 + UIScrollView *ScreenDurationView::ScreenDurationViewInit(void) + { + /* ------------------------ ScreenDurationScrollView ------------------------ */ + if (!SetUpScrollView()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationScrollView is nullptr!"); + return nullptr; + } + /* ----------------------------- BackGroundImage[] ---------------------------- */ + if (!SetUpScreenDurationViewImageView()) + { + return nullptr; + } + /* -------------------------- ScreenDurationLabel[] ------------------------- */ + if (!SetUpScreenDurationViewLabel()) + { + return nullptr; + } + /* ----------------------- ScreenDurationRadioButton[] ---------------------- */ + if (!SetUpScreenDurationViewRadioButton()) + { + return nullptr; + } + /* ----------------------------------- Add ---------------------------------- */ + ScreenDurationScrollView->Add(ScreenDurationTitleLabel); + for (int i = 0; i < 3; i++) + { + ScreenDurationScrollView->Add(BackGroundImage[i]); + ScreenDurationScrollView->Add(ScreenDurationLabel[i]); + ScreenDurationScrollView->Add(ScreenDurationRadioButton[i]); + } + initViewStatus = true; + return ScreenDurationScrollView; } } \ No newline at end of file