From 2a91eeb2ce9bd7189cbec1cdb98d799c347d5902 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sat, 29 Jun 2024 15:19:06 +0800 Subject: [PATCH] =?utf8?q?=E4=B8=8B=E6=8B=89=E8=AF=95=E5=9B=BE=E4=BF=AE?= =?utf8?q?=E6=94=B9=EF=BC=8C=E5=9B=BE=E7=89=87=E9=87=87=E7=94=A8=E7=9B=B4?= =?utf8?q?=E6=8E=A5=E8=AF=BB=E5=8F=96=E5=86=85=E5=AD=98=E5=8F=96=E6=B6=88?= =?utf8?q?=E9=87=87=E7=94=A8Imagecach?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../main/include/MainPresenterSample.h | 4 +- .../nativeui/main/include/PullUpDownView.h | 137 +++ .../nativeui/main/src/MainPresenterSample.cpp | 2 +- .../nativeui/main/src/PullUpDownView.cpp | 1085 ++++++++++++++++- .../user/res/dropdown/DROPDOWN_BLUETOOTH.bin | 3 + .../dropdown/DROPDOWN_BLUETOOTHCONNECTED.bin | 3 + .../DROPDOWN_BLUETOOTHDISCONNECTED.bin | 3 + .../res/dropdown/DROPDOWN_DNOTDISTURB.bin | 3 + .../dropdown/DROPDOWN_EARPHONESCONNECTED.bin | 3 + .../DROPDOWN_EARPHONESDISCONNECTED.bin | 3 + .../user/res/dropdown/DROPDOWN_FINDPHONE.bin | 3 + .../fs/user/res/dropdown/DROPDOWN_LINE.bin | 3 + .../user/res/dropdown/DROPDOWN_NOSIGNAL.bin | 3 + .../res/dropdown/DROPDOWN_PHONECONNECTED.bin | 3 + .../dropdown/DROPDOWN_PHONEDISCONNECTED.bin | 3 + .../user/res/dropdown/DROPDOWN_SAVEPOWER.bin | 3 + .../fs/user/res/dropdown/DROPDOWN_SETTING.bin | 3 + 17 files changed, 1262 insertions(+), 5 deletions(-) create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTH.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTHCONNECTED.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTHDISCONNECTED.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_DNOTDISTURB.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_EARPHONESCONNECTED.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_EARPHONESDISCONNECTED.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_FINDPHONE.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_LINE.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_NOSIGNAL.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_PHONECONNECTED.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_PHONEDISCONNECTED.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_SAVEPOWER.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_SETTING.bin diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h index e71f14310..7f3bb11d2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-01 15:10:34 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-05-09 10:00:40 + * @LastEditTime: 2024-06-29 11:19:40 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h */ @@ -35,7 +35,7 @@ namespace OHOS static constexpr const char *DROPDOWN_CLICK_BRIGHTENSCREEN = "dropdownclickbrightscreen"; static constexpr const char *DROPDOWN_CLICK_SETTING = "dropdownclicksetting"; // 设置 - static constexpr const char *DROPDOWN_CLICK_LIGHTING = "dropdownclicklighting"; // 手电筒 + static constexpr const char *DROPDOWN_CLICK_BLUETOOTH = "dropdownclickbluetooth"; // 蓝牙 static constexpr const char *DROPDOWN_CLICK_DNOTDISTURB = "dropdownclickdnotdisturb"; // 勿扰 static constexpr const char *DROPDOWN_CLICK_SAVEELE = "dropdownclicksaveele"; // 省电 static constexpr const char *DROPDOWN_CLICK_FINDMYPHONE = "dropdownclickfindmyphone"; // 找手机 diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h index 905d4e8d3..378d4450b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h @@ -1,3 +1,139 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-17 15:26:49 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-29 15:08:34 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h + */ + +#if 1 +#ifndef PULL_UP_DOWN_VIEW_H +#define PULL_UP_DOWN_VIEW_H + +#include "graphic_types.h" +#include "wearable_log.h" +#include "components/ui_card_page.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_button.h" +#include "components/ui_box_progress.h" +#include "components/ui_image_animator.h" +#include "battery_hal.h" +#include "main/include/ConnectedStatusView.h" + +extern uint8_t battery_get_voltage(float *voltage); + +namespace OHOS +{ + static constexpr int16_t SETTING_INDEX = 0; + static constexpr int16_t LIGHTING_INDEX = 1; + static constexpr int16_t DNOTDISTURB_INDEX = 2; + static constexpr int16_t SAVEPOWER_INDEX = 3; + static constexpr int16_t FINDPHONE_INDEX = 4; + static constexpr int16_t MAX_INDEX = 5; + + typedef enum : uint8_t + { + DROPDOWNVIEW = 0, + CONNECTEDSTATUSVIEW, + MAX_DROPDOWNVIEWID, + } DROPDOWNVIEWID; + + class PullUpDownView : public UICardPage + { + public: + PullUpDownView(); + ~PullUpDownView() override; + static PullUpDownView *GetInstance(void); + void PreLoad(void) override; + void UnLoad(void) override; + void UpdatePhoneStatus(int status); + void UpdateEarPhoneStatus(int status); + void UpdateBlueToothStatus(int status); + void UpdateDnotDisturbStatus(int status); + void UpdateSignalStrengthStatusAndBatteryPosition(); + bool ChangeDropDownView(int16_t thisView); // 切换到"下拉控制中心"视图 + bool ChangeConnectedStatusView(int16_t thisView); // 切换到"连接状态"视图 + bool ClickFunc(int16_t interface); + void ChangeView(int16_t hideView, int16_t showView); + ConnectedStatusView *GetConnectedStatusView(void); + + UILabel *GetTimeLabel(); + UILabel *GetDateLabel(); + UILabel *GetWeekLabel(); + UIBoxProgress *GetProgress(); + + bool GetPhoneConnectedStatus(void); + bool GetEarPhoneConnectedStatus(void); + bool GetBlueToothConnectedStatus(void); + struct ImageConfig + { + int16_t x; + int16_t y; + int16_t w; + int16_t h; + const char *viewid; + const char *src; + UIView::OnClickListener *clicklistener; + }; + + private: + bool PullUpDownViewInit(); + bool InitBaseData(); // 初始化基础数据组件 + UIImageView *dropDownIconImageViweInit(ImageConfig &imageconfig); + void createDropDownIconImageViwe(void); + UIImageView *dropDownConnectedStatusImageViweInit(int16_t x, int16_t y, int16_t w, int16_t h); + void createDropDownConnectedStatusImageViwe(void); + + bool InitSingalComponentsView(); + void ClearAllConnectedStatusComponentsView(); + void ClearAllSingalComponentsView(); + void ClearAll(); + + int GetSignalStrength(void); + int CalculateSignalBars(int signalStrength); + void UpdateSignalBarDisplay(int signalBars, bool state); + void UpdateBatteryPosition(int signalBars); + void updateSignalDisplay(); + void UpdateCat1NoSignalisplay(bool state); + void UpdateCat14GDisplay(bool state); + + void PreLoadPullUpDownImageRes(void); + void UnLoadPullUpDownImageRes(void); + + private: + ConnectedStatusView *connectedStatusView{nullptr}; + + private: + UIViewGroup *group[MAX_DROPDOWNVIEWID]{nullptr}; + UIImageView *dropSetting{nullptr}; // 设置 + UIImageView *dropBluetooth{nullptr}; // 蓝牙 + UIImageView *dropDnotDisturb{nullptr}; // 勿扰模式 + UIImageView *dropSavePower{nullptr}; // 省电 + UIImageView *drofindPhone{nullptr}; // 找手机 + UIImageView *dropLine{nullptr}; // 线 + UIButton *connectedStatusBackgroundButton{nullptr}; // 放置连接状态icon的背景按钮 + UIImageView *showPhoneConnectedStatus{nullptr}; // 显示手机连接状态 + UIImageView *showEarPhoneConnectedStatus{nullptr}; // 显示耳机连接状态 + UIImageView *showBluetoothConnectedStatus{nullptr}; // 显示蓝牙连接状态 + UILabel *showTimeLabel{nullptr}; // 显示时间 + UILabel *showDateLabel{nullptr}; // 显示日期 + UILabel *showWeekLabel{nullptr}; // 显示星期 + UIImageView *showSignalStrength[4]{nullptr}; // 信号强度 + UILabel *Singal_4{nullptr}; // 4G图标 + UIImageView *NoSignal{nullptr}; // 无信号 + + UIImageView *batteryimage = nullptr; + UIBoxProgress *progress = nullptr; + + bool viewiInitStatus{false}; + }; +} +#endif + +#else /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-17 15:26:49 @@ -129,3 +265,4 @@ namespace OHOS }; } #endif +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp index cc060b91e..b38cca956 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -39,7 +39,7 @@ namespace OHOS std::map g_jumpView = { {DROPDOWN_CLICK_SETTING, VIEW_SETTING}, // 设置 - {DROPDOWN_CLICK_LIGHTING, VIEW_CLASSIC_BLUETOOTH}, // 蓝牙 + {DROPDOWN_CLICK_BLUETOOTH, VIEW_CLASSIC_BLUETOOTH}, // 蓝牙 {DROPDOWN_CLICK_DNOTDISTURB, VIEW_DNOTDISTURB}, // 勿扰 {DROPDOWN_CLICK_SAVEELE, VIEW_SAVEELE}, // 省电模式 {DROPDOWN_CLICK_FINDMYPHONE, VIEW_FIND_PHONE}, // 查找手机 diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp index b9bb68b9d..744133766 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp @@ -1,3 +1,1083 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-06-26 18:14:24 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-29 15:08:41 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp + */ + +#if 1 +#include "PullUpDownView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "common/screen.h" +#include "main/include/MainPresenterSample.h" +#include "screensetting/include/ScreenModels.h" +#include "settings/include/SettingModel.h" +#include "ui_resource_image.h" +#include "dnotdisturb/include/DnotDisturbModel.h" +#include "custom_utils.h" +#include "custom_runtime.h" +namespace OHOS +{ + + /* ---------------------------------- 坐标位置 ---------------------------------- */ + // 设置 + static constexpr uint16_t SETTING_IMG_X = 30; + static constexpr uint16_t SETTING_IMG_Y = 186; + static constexpr const char *DROPDOWN_SETTING_IMAGE = "/user/res/dropdown/DROPDOWN_SETTING.bin"; + + // 蓝牙 + static constexpr uint16_t BLUETOOTH_IMG_X = 76; + static constexpr uint16_t BLUETOOTH_IMG_Y = 76; + static constexpr const char *DROPDOWN_BLUETOOTH_IMAGE = "/user/res/dropdown/DROPDOWN_BLUETOOTH.bin"; + + // 勿扰 + static constexpr uint16_t DNOTDISTURB_IMG_X = 186; + static constexpr uint16_t DNOTDISTURB_IMG_Y = 30; + static constexpr const char *DROPDOWN_DNOTDISTURB_IMAGE = "/user/res/dropdown/DROPDOWN_DNOTDISTURB.bin"; + + // 省电 + static constexpr uint16_t SAVEPOWER_IMG_X = 296; + static constexpr uint16_t SAVEPOWER_IMG_Y = 76; + static constexpr const char *DROPDOWN_SAVEPOWER_IMAGE = "/user/res/dropdown/DROPDOWN_SAVEPOWER.bin"; + + // 找手机 + static constexpr uint16_t FINDPHONE_IMG_X = 342; + static constexpr uint16_t FINDPHONE_IMG_Y = 186; + static constexpr const char *DROPDOWN_FINDPHONE_IMAGE = "/user/res/dropdown/DROPDOWN_FINDPHONE.bin"; + + // line + static constexpr uint16_t LINE_IMG_X = 193; + static constexpr uint16_t LINE_IMG_Y = 430; + static constexpr const char *DROPDOWN_LINE_IMAGE = "/user/res/dropdown/DROPDOWN_LINE.bin"; + + // icon图片大小 + static constexpr uint16_t ICON_IMG_SIZE_W = 94; + static constexpr uint16_t ICON_IMG_SIZE_H = 94; + + // 电池 + static constexpr uint16_t BATTERY_X = 209; + static constexpr uint16_t BATTERY_Y = 180; + + // 时间 + static constexpr uint16_t TIME_LABEL_X = 172; + static constexpr uint16_t TIME_LABEL_Y = 230; + + // 日期 + static constexpr uint16_t DATE_LABEL_X = 110; + static constexpr uint16_t DATE_LABEL_Y = 300; + + // 星期 + static constexpr uint16_t WEEK_LABEL_X = 295; + static constexpr uint16_t WEEK_LABEL_Y = 300; + + // 手机连接状态 + static constexpr uint16_t PHONECONNECTSTATUS_IMG_X = 123; + static constexpr uint16_t PHONECONNECTSTATUS_IMG_Y = 350; + static constexpr const char *DROPDOWN_PHONECONNECTED_IMAGE = "/user/res/dropdown/DROPDOWN_PHONECONNECTED.bin"; + static constexpr const char *DROPDOWN_PHONEDISCONNECTED_IMAGE = "/user/res/dropdown/DROPDOWN_PHONEDISCONNECTED.bin"; + + // 耳机连接状态 + static constexpr uint16_t EARPHONESCONNECTSTATUS_IMG_X = 203; + static constexpr uint16_t EARPHONESCONNECTSTATUS_IMG_Y = 350; + static constexpr const char *DROPDOWN_EARPHONESCONNECTED_IMAGE = "/user/res/dropdown/DROPDOWN_EARPHONESCONNECTED.bin"; + static constexpr const char *DROPDOWN_EARPHONESDISCONNECTED_IMAGE = "/user/res/dropdown/DROPDOWN_EARPHONESDISCONNECTED.bin"; + + // 蓝牙连接状态 + static constexpr uint16_t BLUETOOTHCONNECTSTATUS_IMG_X = 283; + static constexpr uint16_t BLUETOOTHCONNECTSTATUS_IMG_Y = 350; + static constexpr const char *DROPDOWN_BLUETOOTHCONNECTED_IMAGE = "/user/res/dropdown/DROPDOWN_BLUETOOTHCONNECTED.bin"; + static constexpr const char *DROPDOWN_BLUETOOTHDISCONNECTED_IMAGE = "/user/res/dropdown/DROPDOWN_BLUETOOTHDISCONNECTED.bin"; + + static constexpr uint16_t CONNECTSTATUS_IMG_W = 60; + static constexpr uint16_t CONNECTSTATUS_IMG_H = 60; + + static constexpr const char *DROPDOWN_NOSIGNAL_IMAGE = "/user/res/dropdown/DROPDOWN_NOSIGNAL.bin"; + static const int64_t COLOR_SIGNAL_ON = 0xffffffff; + static const int64_t COLOR_SIGNAL_OFF = 0xff383838; + static const int BATTERY_IMAGE_WIDTH = 48; + static const int BATTERY_IMAGE_HEIGHT = 30; + static const int PROGRESS_WIDTH = 30; + static const int PROGRESS_HEIGHT = 18; + /* -------------------------------------------------------------------------- */ + std::string getWeekString(int wday) + { + std::string weekDays[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; + return weekDays[wday]; + } + /* -------------------------------------------------------------------------- */ + static PullUpDownView *g_pPullUpDownView = nullptr; + PullUpDownView::PullUpDownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::PullUpDownView"); + g_pPullUpDownView = this; + } + + PullUpDownView::~PullUpDownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::~PullUpDownView"); + ClearAll(); + g_pPullUpDownView = nullptr; + } + + PullUpDownView *PullUpDownView::GetInstance(void) + { + return g_pPullUpDownView; + } + + // 清除信号强度相关组件 + void PullUpDownView::ClearAllSingalComponentsView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ClearAllSingalComponentsView"); + if (NoSignal != nullptr) + { + delete NoSignal; + NoSignal = nullptr; + } + + for (int i = 0; i < 4; i++) + { + if (showSignalStrength[i] != nullptr) + { + delete showSignalStrength[i]; + showSignalStrength[i] = nullptr; + } + } + + if (Singal_4 != nullptr) + { + delete Singal_4; + Singal_4 = nullptr; + } + } + + // 清除所有与连接状态相关的视图组件 + void PullUpDownView::ClearAllConnectedStatusComponentsView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ClearAllConnectedStatusComponentsView"); + if (connectedStatusBackgroundButton != nullptr) + { + delete connectedStatusBackgroundButton; + connectedStatusBackgroundButton = nullptr; + } + + if (showPhoneConnectedStatus != nullptr) + { + delete showPhoneConnectedStatus; + showPhoneConnectedStatus = nullptr; + } + + if (showEarPhoneConnectedStatus != nullptr) + { + delete showEarPhoneConnectedStatus; + showEarPhoneConnectedStatus = nullptr; + } + + if (showBluetoothConnectedStatus != nullptr) + { + delete showBluetoothConnectedStatus; + showBluetoothConnectedStatus = nullptr; + } + } + + void PullUpDownView::ClearAll() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ClearAll"); + RemoveAll(); + if (group[DROPDOWNVIEW] != nullptr) + { + group[DROPDOWNVIEW]->RemoveAll(); + group[DROPDOWNVIEW]->ClearBackgroundBlur(); + delete group[DROPDOWNVIEW]; + group[DROPDOWNVIEW] = nullptr; + } + + if (dropSetting != nullptr) + { + delete dropSetting; + dropSetting = nullptr; + } + + if (dropBluetooth != nullptr) + { + delete dropBluetooth; + dropBluetooth = nullptr; + } + + if (dropDnotDisturb != nullptr) + { + delete dropDnotDisturb; + dropDnotDisturb = nullptr; + } + + if (dropSavePower != nullptr) + { + delete dropSavePower; + dropSavePower = nullptr; + } + + if (drofindPhone != nullptr) + { + delete drofindPhone; + drofindPhone = nullptr; + } + + if (dropLine != nullptr) + { + delete dropLine; + dropLine = nullptr; + } + + if (showTimeLabel != nullptr) + { + delete showTimeLabel; + showTimeLabel = nullptr; + } + + if (showDateLabel != nullptr) + { + delete showDateLabel; + showDateLabel = nullptr; + } + + if (showWeekLabel != nullptr) + { + delete showWeekLabel; + showWeekLabel = nullptr; + } + /* -------------------------------------------------------------------------- */ + ClearAllSingalComponentsView(); + ClearAllConnectedStatusComponentsView(); + /* -------------------------------------------------------------------------- */ + if (batteryimage != nullptr) + { + delete batteryimage; + batteryimage = nullptr; + } + + if (progress != nullptr) + { + delete progress; + progress = nullptr; + } + + if (connectedStatusView != nullptr) + { + delete connectedStatusView; + connectedStatusView = nullptr; + group[CONNECTEDSTATUSVIEW] = nullptr; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ClearAll end!!"); + } + + UIImageView *PullUpDownView::dropDownIconImageViweInit(ImageConfig &imageconfig) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::dropDownIconImageViweInit"); + UIImageView *Image = new UIImageView(); + if (Image == nullptr) + { + return nullptr; + } + Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); + Image->SetViewId(imageconfig.viewid); + Image->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + Image->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + Image->SetStyle(STYLE_BORDER_RADIUS, 100); + Image->SetAutoEnable(false); + Image->SetResizeMode(UIImageView::CENTER); + Image->SetSrc(imageconfig.src); + Image->SetTouchable(true); + Image->SetOnClickListener(imageconfig.clicklistener); + + return Image; + } + + /// @brief 创建icon图标 + void PullUpDownView::createDropDownIconImageViwe(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitViewImg"); + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + if (clickListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::GetInstance fail!!"); + return; + } + /* ---------------------------------- 下拉设置图片 ---------------------------------- */ + ImageConfig imageconfig = { + .x = SETTING_IMG_X, + .y = SETTING_IMG_Y, + .w = ICON_IMG_SIZE_W, + .h = ICON_IMG_SIZE_H, + .viewid = DROPDOWN_CLICK_SETTING, + .src = DROPDOWN_SETTING_IMAGE, + .clicklistener = clickListener, + }; + dropSetting = dropDownIconImageViweInit(imageconfig); + if (dropSetting == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::dropSetting new fail"); + return; + } + /* ----------------------------------- 蓝牙 ----------------------------------- */ + imageconfig = { + .x = BLUETOOTH_IMG_X, + .y = BLUETOOTH_IMG_Y, + .w = ICON_IMG_SIZE_W, + .h = ICON_IMG_SIZE_H, + .viewid = DROPDOWN_CLICK_BLUETOOTH, + .src = DROPDOWN_BLUETOOTH_IMAGE, + .clicklistener = clickListener, + }; + dropBluetooth = dropDownIconImageViweInit(imageconfig); + if (dropBluetooth == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::dropBluetooth new fail"); + return; + } + /* ----------------------------------- 勿扰模式 ----------------------------------- */ + imageconfig = { + .x = DNOTDISTURB_IMG_X, + .y = DNOTDISTURB_IMG_Y, + .w = ICON_IMG_SIZE_W, + .h = ICON_IMG_SIZE_H, + .viewid = DROPDOWN_CLICK_DNOTDISTURB, + .src = DROPDOWN_DNOTDISTURB_IMAGE, + .clicklistener = clickListener, + }; + dropDnotDisturb = dropDownIconImageViweInit(imageconfig); + if (dropDnotDisturb == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::dropDnotDisturb new fail"); + return; + } + UpdateDnotDisturbStatus(DnotDisturbModel::GetInstance().GetDoNotDisturbModeEnabled()); + /* ----------------------------------- 省电 ----------------------------------- */ + imageconfig = { + .x = SAVEPOWER_IMG_X, + .y = SAVEPOWER_IMG_Y, + .w = ICON_IMG_SIZE_W, + .h = ICON_IMG_SIZE_H, + .viewid = DROPDOWN_CLICK_SAVEELE, + .src = DROPDOWN_DNOTDISTURB_IMAGE, + .clicklistener = clickListener, + }; + dropSavePower = dropDownIconImageViweInit(imageconfig); + if (dropSavePower == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::dropSavePower new fail"); + return; + } + /* ----------------------------------- 找手机 ---------------------------------- */ + imageconfig = { + .x = FINDPHONE_IMG_X, + .y = FINDPHONE_IMG_Y, + .w = ICON_IMG_SIZE_W, + .h = ICON_IMG_SIZE_H, + .viewid = DROPDOWN_CLICK_FINDMYPHONE, + .src = DROPDOWN_DNOTDISTURB_IMAGE, + .clicklistener = clickListener, + }; + drofindPhone = dropDownIconImageViweInit(imageconfig); + if (drofindPhone == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::drofindPhone new fail"); + return; + } + /* -------------------------------- dropLine -------------------------------- */ + dropLine = new UIImageView(); + if (dropLine == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dropLine new fail"); + return; + } + dropLine->SetPosition(LINE_IMG_X, LINE_IMG_Y, ICON_IMG_SIZE_W, ICON_IMG_SIZE_H); + dropLine->SetSrc(DROPDOWN_LINE_IMAGE); + /* -------------------------------- 添加组件到视图上 -------------------------------- */ + group[DROPDOWNVIEW]->Add(dropSetting); + group[DROPDOWNVIEW]->Add(dropBluetooth); + group[DROPDOWNVIEW]->Add(dropDnotDisturb); + group[DROPDOWNVIEW]->Add(dropSavePower); + group[DROPDOWNVIEW]->Add(drofindPhone); + group[DROPDOWNVIEW]->Add(dropLine); + } + + // 获取手机连接状态 + bool PullUpDownView::GetPhoneConnectedStatus(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::GetPhoneConnectedStatus"); + // uint8_t ret = uapi_dev_runtime_get_ble_connect_stat(); + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ble phone connect stat = %d", ret); + // if (ret == 1) + // return true; + // else + // return false; + + return SettingModel::GetInstance().GetPhoneConnectStatus(); + } + + // 获取蓝牙耳机连接状态 + bool PullUpDownView::GetEarPhoneConnectedStatus(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::GetEarPhoneConnectedStatus"); + // uint8_t ret = uapi_dev_runtime_get_earphone_connect_stat(); + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "earphone connect stat = %d", ret); + // if (ret == 1) + // return true; + // else + // return false; + + return SettingModel::GetInstance().GetEarPhoneConnectStatus(); + } + + // 获取蓝牙连接状态 + bool PullUpDownView::GetBlueToothConnectedStatus(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::GetBlueToothConnectedStatus"); + // uint8_t ret = uapi_dev_runtime_get_br_connect_stat(); + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "br connect stat = %d [0 no connect, 1 a2dp, 2 hfp, 3 both]", ret); + // if (ret != 0) + // return true; + // else + // return false; + + return SettingModel::GetInstance().GetBlueToothConnectStatus(); + } + + UIImageView *PullUpDownView::dropDownConnectedStatusImageViweInit(int16_t x, int16_t y, int16_t w, int16_t h) + { + UIImageView *img = new UIImageView(); + if (img == nullptr) + { + return nullptr; + } + img->SetPosition(x, y, w, h); + img->SetAutoEnable(false); + img->SetResizeMode(UIImageView::CENTER); + img->SetStyle(STYLE_BORDER_RADIUS, 100); + + return img; + } + + /// @brief 创建与连接状态相关组件 + void PullUpDownView::createDropDownConnectedStatusImageViwe(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitConnectedStatusImage"); + connectedStatusBackgroundButton = new UIButton(); + if (connectedStatusBackgroundButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "connectedStatusBackgroundButton new fail"); + return; + } + connectedStatusBackgroundButton->SetPosition(113, 348, 240, 64); + connectedStatusBackgroundButton->SetViewId(CONNECTEDSTATUSBACKGROUNDBUTTON); + connectedStatusBackgroundButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + connectedStatusBackgroundButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + connectedStatusBackgroundButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED); + connectedStatusBackgroundButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + connectedStatusBackgroundButton->SetStyleForState(STYLE_BORDER_COLOR, 0xffffffff, UIButton::PRESSED); + connectedStatusBackgroundButton->SetStyleForState(STYLE_BORDER_OPA, 0x00, UIButton::PRESSED); + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + if (clickListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::GetInstance fail!!"); + return; + } + connectedStatusBackgroundButton->SetOnClickListener(clickListener); + /* -------------------------------- 显示手机连接状态 -------------------------------- */ + + showPhoneConnectedStatus = dropDownConnectedStatusImageViweInit(PHONECONNECTSTATUS_IMG_X, PHONECONNECTSTATUS_IMG_Y, CONNECTSTATUS_IMG_W, CONNECTSTATUS_IMG_H); + if (showPhoneConnectedStatus == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showPhoneConnectedStatus new fail"); + return; + } + /* -------------------------------- 显示耳机连接状态 -------------------------------- */ + showEarPhoneConnectedStatus = dropDownConnectedStatusImageViweInit(EARPHONESCONNECTSTATUS_IMG_X, EARPHONESCONNECTSTATUS_IMG_Y, CONNECTSTATUS_IMG_W, CONNECTSTATUS_IMG_H); + if (showEarPhoneConnectedStatus == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showEarPhoneConnectedStatus new fail"); + return; + } + /* -------------------------------- 显示蓝牙连接状态 -------------------------------- */ + showBluetoothConnectedStatus = dropDownConnectedStatusImageViweInit(BLUETOOTHCONNECTSTATUS_IMG_X, BLUETOOTHCONNECTSTATUS_IMG_Y, CONNECTSTATUS_IMG_W, CONNECTSTATUS_IMG_H); + if (showBluetoothConnectedStatus == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showBluetoothConnectedStatus new fail"); + return; + } + /* -------------------------------------------------------------------------- */ + UpdatePhoneStatus(GetPhoneConnectedStatus()); + UpdateEarPhoneStatus(GetEarPhoneConnectedStatus()); + UpdateBlueToothStatus(GetBlueToothConnectedStatus()); + /* -------------------------------------------------------------------------- */ + group[DROPDOWNVIEW]->Add(connectedStatusBackgroundButton); + group[DROPDOWNVIEW]->Add(showPhoneConnectedStatus); + group[DROPDOWNVIEW]->Add(showEarPhoneConnectedStatus); + group[DROPDOWNVIEW]->Add(showBluetoothConnectedStatus); + } + + /*** + * @brief 初始化时间,日期,星期,电池,信号强度 + */ + bool PullUpDownView::InitBaseData() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitBaseData"); + if (!InitSingalComponentsView()) + { + return false; + } + + /* ---------------------------------- 时间显示 ---------------------------------- */ + showTimeLabel = new UILabel(); + if (showTimeLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showTimeLabel new fail"); + return false; + } + showTimeLabel->SetPosition(TIME_LABEL_X, TIME_LABEL_Y); + showTimeLabel->SetStyle(STYLE_TEXT_FONT, 50); + showTimeLabel->SetStyle(STYLE_LINE_HEIGHT, 59); + showTimeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + showTimeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + showTimeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 50); + /* ---------------------------------- 日期显示 ---------------------------------- */ + showDateLabel = new UILabel(); + if (showDateLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showDateLabel new fail"); + return false; + } + showDateLabel->SetPosition(DATE_LABEL_X, DATE_LABEL_Y); + showDateLabel->SetStyle(STYLE_TEXT_FONT, 30); + showDateLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + showDateLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + showDateLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + showDateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ---------------------------------- 星期显示 ---------------------------------- */ + showWeekLabel = new UILabel(); + if (showWeekLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showWeekLabel new fail"); + return false; + } + showWeekLabel->SetPosition(WEEK_LABEL_X, WEEK_LABEL_Y); + showWeekLabel->SetStyle(STYLE_TEXT_FONT, 30); + showWeekLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + showWeekLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + showWeekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + showWeekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + /* ----------------------------------- 电池 ----------------------------------- */ + batteryimage = new UIImageView(); + if (batteryimage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryimage new fail"); + return false; + } + batteryimage->SetPosition(258, 180, BATTERY_IMAGE_WIDTH, BATTERY_IMAGE_HEIGHT); + std::string batteryimagesPath = "/user/res/Battery/Battery-E.bin"; + batteryimage->SetSrc(batteryimagesPath.c_str()); + /* -------------------------------------------------------------------------- */ + progress = new UIBoxProgress(); + if (progress == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress new fail"); + return false; + } + progress->SetPosition(206, 180, PROGRESS_WIDTH, PROGRESS_HEIGHT); + progress->SetValidHeight(PROGRESS_HEIGHT); + progress->SetValidWidth(PROGRESS_WIDTH); + + // progress->SetValue(value); + const char *progressImageSrc = "/user/res/Battery/Battery_Normal.bin"; + progress->SetImage(progressImageSrc, nullptr); + progress->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x00); + progress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xff000000); + progress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + progress->SetForegroundStyle(STYLE_TEXT_COLOR, 0xff000000); + progress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff45A5FF); + + group[DROPDOWNVIEW]->Add(progress); + group[DROPDOWNVIEW]->Add(batteryimage); + group[DROPDOWNVIEW]->Add(showTimeLabel); + group[DROPDOWNVIEW]->Add(showDateLabel); + group[DROPDOWNVIEW]->Add(showWeekLabel); + + /* -------------------------------------------------------------------------- */ + UpdateSignalStrengthStatusAndBatteryPosition(); + /* -------------------------------------------------------------------------- */ + + return true; + } + + // 初始化信号强度相关组件 + bool PullUpDownView::InitSingalComponentsView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitSingalComponentsView"); + /* -------------------------------------------------------------------------- */ + NoSignal = new UIImageView(); + if (NoSignal == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NoSignal new fail"); + return false; + } + NoSignal->SetPosition(160, 176, 36, 38); + NoSignal->SetAutoEnable(false); + NoSignal->SetResizeMode(UIImageView::CENTER); + NoSignal->SetSrc(DROPDOWN_NOSIGNAL_IMAGE); + NoSignal->SetVisible(false); + group[DROPDOWNVIEW]->Add(NoSignal); + /* -------------------------------------------------------------------------- */ + // 定义一个结构体,用于存储 ImageView 的信息 + struct ImageViewInfo + { + int posX; + int posY; + int width; + int height; + }; + // 待添加的 ImageView 信息列表 + std::vector imageViewList = { + {160, 204, 6, 6}, + {170, 196, 6, 14}, + {180, 188, 6, 22}, + {190, 180, 6, 30}, + }; + + // 循环添加 ImageView 到相应的容器中 + for (int i = 0; i < 4; i++) + { + if (showSignalStrength[i] == nullptr) + { + showSignalStrength[i] = new UIImageView(); + if (showSignalStrength[i] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showSignalStrength[%d] new fail", i); + return false; + } + } + showSignalStrength[i]->SetPosition(imageViewList[i].posX, imageViewList[i].posY, imageViewList[i].width, imageViewList[i].height); + showSignalStrength[i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + showSignalStrength[i]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + showSignalStrength[i]->SetStyle(STYLE_BORDER_RADIUS, 10); + group[DROPDOWNVIEW]->Add(showSignalStrength[i]); + showSignalStrength[i]->SetVisible(false); + } + /* -------------------------------------------------------------------------- */ + if (Singal_4 == nullptr) + { + Singal_4 = new UILabel(); + } + Singal_4->SetPosition(201, 176, 40, 47); + Singal_4->SetStyle(STYLE_TEXT_FONT, 34); + Singal_4->SetStyle(STYLE_LINE_HEIGHT, 40); + Singal_4->SetText("4G"); + Singal_4->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + Singal_4->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Singal_4->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 34); + Singal_4->SetVisible(false); + group[DROPDOWNVIEW]->Add(Singal_4); + + return true; + } + + // 获取信号强度 + int PullUpDownView::GetSignalStrength(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::GetSignalStrength"); + int SignalStrength = uapi_dev_runtime_get_cat1_signal(); // 信号强度 + return CalculateSignalBars(SignalStrength); + } + + // 计算信号格 + int PullUpDownView::CalculateSignalBars(int signalStrength) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::CalculateSignalBars"); + if (signalStrength < 0 || signalStrength > 32 || signalStrength == 0) + return 99; // 无信号 or Invalid signal strength + + // if (signalStrength == 32) + // return 4; // Edge case where signalStrength is exactly at the upper boundary + + return (signalStrength / 8) + 1; + } + +#if 0 + // 函数用于更新信号显示的UI + void PullUpDownView::updateSignalDisplay() + { + int sim = uapi_dev_runtime_get_cat1_simstat(); + int cat1_powerOn = uapi_dev_runtime_get_cat1_powerstat(); + int signal = uapi_dev_runtime_get_cat1_signal(); + int network_on = uapi_dev_runtime_get_cat1_networkstat(); + int cat1_network_type = uapi_dev_runtime_get_cat1_networtype(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sim = %d", sim); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cat1_powerOn = %d", cat1_powerOn); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "signal = %d", signal); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "network_on = %d", network_on); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cat1_network_type = %d", cat1_network_type); + + const int SIGNAL_NO_SIGNAL = 99; + const int NETWORK_TYPE_NO_NETWORK = 0; + const int NETWORK_TYPE_4G = 4; + + if (sim == 0 || cat1_powerOn == 0) + { + // 无信号,无4G图标 + UpdateCat1NoSignalisplay(true); + UpdateCat14GDisplay(false); + UpdateSignalBarDisplay(CalculateSignalBars(signal), false); + } + else if (cat1_powerOn == 1 && sim == 1) + { + if (signal == SIGNAL_NO_SIGNAL) + { + // 无信号UI显示 + UpdateCat1NoSignalisplay(true); + UpdateCat14GDisplay(false); + UpdateSignalBarDisplay(CalculateSignalBars(signal), false); + } + else + { + // 信号强度显示 + UpdateCat1NoSignalisplay(false); + UpdateCat14GDisplay(true); + UpdateSignalBarDisplay(CalculateSignalBars(signal), true); + } + if (network_on == 0) + { + // 无信号,无4G图标 显示 + UpdateCat1NoSignalisplay(true); + UpdateCat14GDisplay(false); + UpdateSignalBarDisplay(CalculateSignalBars(signal), false); + } + else + { + if (cat1_network_type == NETWORK_TYPE_NO_NETWORK) + { + // 无信号,无4G图标 显示 + UpdateCat1NoSignalisplay(true); + UpdateCat14GDisplay(false); + UpdateSignalBarDisplay(CalculateSignalBars(signal), false); + } + else if (cat1_network_type == NETWORK_TYPE_4G) + { + // 有4G图标,正常显示信号 + UpdateCat1NoSignalisplay(false); + UpdateCat14GDisplay(true); + UpdateSignalBarDisplay(CalculateSignalBars(signal), true); + } + else + { + // 无4G图标,正常显示信号 + UpdateCat1NoSignalisplay(false); + UpdateCat14GDisplay(false); + UpdateSignalBarDisplay(CalculateSignalBars(signal), true); + } + } + } + } +#else + // 函数用于更新信号显示的UI + void PullUpDownView::updateSignalDisplay() + { + int sim = uapi_dev_runtime_get_cat1_simstat(); + int cat1_powerOn = uapi_dev_runtime_get_cat1_powerstat(); + int signal = uapi_dev_runtime_get_cat1_signal(); + int network_on = uapi_dev_runtime_get_cat1_networkstat(); + int cat1_network_type = uapi_dev_runtime_get_cat1_networtype(); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sim = %d", sim); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cat1_powerOn = %d", cat1_powerOn); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "signal = %d", signal); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "network_on = %d", network_on); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cat1_network_type = %d", cat1_network_type); + + const int SIGNAL_NO_SIGNAL = 99; + const int NETWORK_TYPE_NO_NETWORK = 0; + const int NETWORK_TYPE_4G = 4; + + bool showNoSignalUI = (sim == 0 || cat1_powerOn == 0 || signal == SIGNAL_NO_SIGNAL); + bool showNoNetworkUI = (network_on == 0 || cat1_network_type == NETWORK_TYPE_NO_NETWORK); + + bool show4GIcon = (cat1_network_type == NETWORK_TYPE_4G); + + UpdateCat1NoSignalisplay(showNoSignalUI); + UpdateCat14GDisplay(show4GIcon); + UpdateSignalBarDisplay(CalculateSignalBars(signal), !(showNoSignalUI || showNoNetworkUI)); + } +#endif + + // 更新信号强度显示 + void PullUpDownView::UpdateSignalBarDisplay(int signalBars, bool state) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateSignalBarDisplay"); + for (int i = 0; i < 4; i++) + { + showSignalStrength[i]->SetStyle(STYLE_BACKGROUND_COLOR, (i < signalBars) ? COLOR_SIGNAL_ON : COLOR_SIGNAL_OFF); + showSignalStrength[i]->Invalidate(); + showSignalStrength[i]->SetVisible(state); + } + } + + // 更新无信号图标显示 + void PullUpDownView::UpdateCat1NoSignalisplay(bool state) + { + if (NoSignal != nullptr) + { + NoSignal->SetVisible(state); + } + } + + // 更新4G图标显示 + void PullUpDownView::UpdateCat14GDisplay(bool state) + { + if (Singal_4 != nullptr) + { + Singal_4->SetVisible(state); + } + } + + // 更新电池位置 + void PullUpDownView::UpdateBatteryPosition(int signalBars) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateBatteryPosition"); + if (signalBars == 99) + { + batteryimage->SetPosition(209, 180, BATTERY_IMAGE_WIDTH, BATTERY_IMAGE_HEIGHT); + progress->SetPosition(215, 186, PROGRESS_WIDTH, PROGRESS_HEIGHT); + } + else + { + batteryimage->SetPosition(258, 180, BATTERY_IMAGE_WIDTH, BATTERY_IMAGE_HEIGHT); + progress->SetPosition(264, 186, PROGRESS_WIDTH, PROGRESS_HEIGHT); + } + batteryimage->Invalidate(); + progress->Invalidate(); + } + + // 更新信号强度和电池位置 + void PullUpDownView::UpdateSignalStrengthStatusAndBatteryPosition() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateSignalStrengthStatusAndBatteryPosition"); + updateSignalDisplay(); + UpdateBatteryPosition(GetSignalStrength()); + } + + // 下拉视图初始化 + bool PullUpDownView::PullUpDownViewInit() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitView"); + + group[DROPDOWNVIEW] = new UIViewGroup(); + if (group[DROPDOWNVIEW] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group[DROPDOWNVIEW] new fail!!"); + return false; + } + group[DROPDOWNVIEW]->SetPosition(0, 0, 466, 466); + group[DROPDOWNVIEW]->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + group[DROPDOWNVIEW]->SetViewIndex(0); + group[DROPDOWNVIEW]->SetFullScreenBlur(true); + createDropDownIconImageViwe(); + createDropDownConnectedStatusImageViwe(); + + if (InitBaseData()) + { + MainPresenterSample::GetInstance()->UpdataBaseData(); + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitBaseData Error!"); + return false; + } + SetTouchable(true); + SetIntercept(true); + Add(group[DROPDOWNVIEW]); + return true; + } + + void PullUpDownView::PreLoad(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::PreLoad"); + if (!viewiInitStatus) + { + PullUpDownViewInit(); + viewiInitStatus = true; + } + } + + void PullUpDownView::UnLoad(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UnLoad"); + } + + // 更新手机连接状态 + void PullUpDownView::UpdatePhoneStatus(int status) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdatePhoneStatus"); + if (showPhoneConnectedStatus == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showPhoneConnectedStatus nullptr"); + return; + } + showPhoneConnectedStatus->SetSrc(status ? DROPDOWN_PHONECONNECTED_IMAGE : DROPDOWN_PHONEDISCONNECTED_IMAGE); + showPhoneConnectedStatus->Invalidate(); + + if (GetConnectedStatusView() != nullptr) + GetConnectedStatusView()->UpdatePhoneConnectedStatus(status); + + return; + } + + // 更新蓝牙耳机连接状态 + void PullUpDownView::UpdateEarPhoneStatus(int status) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateEarPhoneStatus"); + if (showEarPhoneConnectedStatus == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showEarPhoneConnectedStatus nullptr"); + return; + } + showEarPhoneConnectedStatus->SetSrc(status ? DROPDOWN_EARPHONESCONNECTED_IMAGE : DROPDOWN_EARPHONESDISCONNECTED_IMAGE); + showEarPhoneConnectedStatus->Invalidate(); + + if (GetConnectedStatusView() != nullptr) + GetConnectedStatusView()->UpdateEarPhoneConnectedStatus(status); + + return; + } + + // 更新蓝牙连接状态 + void PullUpDownView::UpdateBlueToothStatus(int status) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateBlueToothStatus"); + if (showBluetoothConnectedStatus == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showBluetoothConnectedStatus nullptr"); + return; + } + showBluetoothConnectedStatus->SetSrc(status ? DROPDOWN_BLUETOOTHCONNECTED_IMAGE : DROPDOWN_BLUETOOTHDISCONNECTED_IMAGE); + showBluetoothConnectedStatus->Invalidate(); + + if (GetConnectedStatusView() != nullptr) + GetConnectedStatusView()->UpdateBlueToothConnectedStatus(status); + + return; + } + + /*更新勿扰模式状态*/ + void PullUpDownView::UpdateDnotDisturbStatus(int status) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateDnotDisturbStatus"); + if (dropDnotDisturb != nullptr) + { + dropDnotDisturb->SetStyle(STYLE_BACKGROUND_COLOR, status ? 0xff8e20e2 : 0xff191919); + dropDnotDisturb->Invalidate(); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dropIconBackground[DNOTDISTURB_INDEX] is nullptr"); + return; + } + } + + UILabel *PullUpDownView::GetTimeLabel() + { + return showTimeLabel; + } + UILabel *PullUpDownView::GetDateLabel() + { + return showDateLabel; + } + UILabel *PullUpDownView::GetWeekLabel() + { + return showWeekLabel; + } + UIBoxProgress *PullUpDownView::GetProgress() + { + return progress; + } + /* ------------------------------ 下拉界面切换到连接状态视图 ----------------------------- */ + // 切换到"下拉控制中心"视图 + bool PullUpDownView::ChangeDropDownView(int16_t thisView) + { + if (group[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ChangeDropDownView"); + Add(group[thisView]); + } + return true; + } + + // 切换到"连接状态"视图 + bool PullUpDownView::ChangeConnectedStatusView(int16_t thisView) + { + if (group[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ChangeConnectedStatusView"); + connectedStatusView = new ConnectedStatusView(); + if (connectedStatusView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView:: new scrollView[%d] fail", thisView); + return false; + } + group[thisView] = connectedStatusView->ConnectedStatusViewInit(); + Add(group[thisView]); + } + return true; + } + + struct PullUpDownViewMapper + { + const int16_t viewId; + bool (PullUpDownView::*func)(int16_t thisView); + }; + + static const PullUpDownViewMapper ViewMapper[] = { + {DROPDOWNVIEW, &PullUpDownView::ChangeDropDownView}, + {CONNECTEDSTATUSVIEW, &PullUpDownView::ChangeConnectedStatusView}, + }; + + bool PullUpDownView::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; + } + + void PullUpDownView::ChangeView(int16_t hideView, int16_t showView) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ChangeView"); + if (hideView > MAX_DROPDOWNVIEWID) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView:: SystemViewId Overstep ones bounds"); + return; + } + group[hideView]->SetVisible(false); + ClickFunc(showView); + group[showView]->SetVisible(true); + Invalidate(); + } + + ConnectedStatusView *PullUpDownView::GetConnectedStatusView(void) + { + return connectedStatusView; + } + /* -------------------------------------------------------------------------- */ +} +#else /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: WeekStep @@ -173,7 +1253,7 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ClearAll"); RemoveAll(); - UnLoadPullUpDownImageRes(); //切换slice的时候也要卸载资源放在ImageCach空间不够 + UnLoadPullUpDownImageRes(); // 切换slice的时候也要卸载资源放在ImageCach空间不够 if (group[DROPDOWNVIEW] != nullptr) { group[DROPDOWNVIEW]->RemoveAll(); @@ -348,7 +1428,7 @@ namespace OHOS dropLighting->SetAutoEnable(false); dropLighting->SetResizeMode(UIImageView::CENTER); // ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropLighting, DROPDOWN_BLUETOOTH); - dropLighting->SetViewId(DROPDOWN_CLICK_LIGHTING); // 进入亮屏界面 + dropLighting->SetViewId(DROPDOWN_CLICK_BLUETOOTH); // 进入亮屏界面 dropLighting->SetTouchable(true); dropLighting->SetOnClickListener(clickListener); /* ----------------------------------- 勿扰模式 ----------------------------------- */ @@ -1206,3 +2286,4 @@ namespace OHOS } /* -------------------------------------------------------------------------- */ } +#endif diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTH.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTH.bin new file mode 100644 index 000000000..f85034587 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTH.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6db591e3eb1bb54b9010e4c57c5b0f40d28a1290e95f28a9c0920ba7369e0171 +size 792 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTHCONNECTED.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTHCONNECTED.bin new file mode 100644 index 000000000..1e71c6442 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTHCONNECTED.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b21cd7b0da5006062af8f7efe3e791ee290322f31cde7581eed65bcc9ebf9df7 +size 2424 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTHDISCONNECTED.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTHDISCONNECTED.bin new file mode 100644 index 000000000..f6c06917e --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_BLUETOOTHDISCONNECTED.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:78a4a48c22d14d85354d1fe4d84b0c13244c47d9b1f5858227b63403fbad404d +size 2424 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_DNOTDISTURB.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_DNOTDISTURB.bin new file mode 100644 index 000000000..776256e8e --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_DNOTDISTURB.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50053d273b582b274ff2e748de6940cc52312ee25adff7bf2bbd2a9e9e27960f +size 1560 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_EARPHONESCONNECTED.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_EARPHONESCONNECTED.bin new file mode 100644 index 000000000..4d3430d5c --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_EARPHONESCONNECTED.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:34a4e1b063eda3fcb6ca9c2e223173e4550620182ecec675ddf8b4971bb6b1af +size 2424 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_EARPHONESDISCONNECTED.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_EARPHONESDISCONNECTED.bin new file mode 100644 index 000000000..5e3af0c6c --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_EARPHONESDISCONNECTED.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9fce27e93e1538cccc7da3120837858f59f48a9df2cedfc07992cacff34ae507 +size 2424 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_FINDPHONE.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_FINDPHONE.bin new file mode 100644 index 000000000..7343389b7 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_FINDPHONE.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5be34fcd358e742d3a3cab6986d844cb5ccfc33f9c422b7c0ff22f35d63c3ea0 +size 1560 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_LINE.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_LINE.bin new file mode 100644 index 000000000..0704bbcdf --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_LINE.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:492d2eb4af52cf3ef0ddb43cb09a8af13629ec7d5b8d5f723358771f3441e65c +size 472 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_NOSIGNAL.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_NOSIGNAL.bin new file mode 100644 index 000000000..33ed4e860 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_NOSIGNAL.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:905a252082ea4a712d68b34df64ce107350ba8def9e77b31e93d468d0cd6fe63 +size 984 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_PHONECONNECTED.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_PHONECONNECTED.bin new file mode 100644 index 000000000..ef27e321c --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_PHONECONNECTED.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52855c1d10dc754e635bc180a5ea72459697a83de535633b6fafd5bc8be26836 +size 2424 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_PHONEDISCONNECTED.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_PHONEDISCONNECTED.bin new file mode 100644 index 000000000..85a601ff2 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_PHONEDISCONNECTED.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:923ae93925394df078d1451f332acf9e74c49a23f881ae222c30b790d217fe24 +size 2424 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_SAVEPOWER.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_SAVEPOWER.bin new file mode 100644 index 000000000..c403103de --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_SAVEPOWER.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08218c18c5b6abb4d2427c0e9694e0d97f0046f30ce7f7f3e291f322bc10542d +size 1560 diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_SETTING.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_SETTING.bin new file mode 100644 index 000000000..cbd0a861f --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/dropdown/DROPDOWN_SETTING.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:167523518e00aceaa0522319bbb7320b209c46a822635ddf99a1ac1041b967a1 +size 1560 -- 2.17.1