From: Caisking Date: Tue, 15 Apr 2025 07:01:14 +0000 (+0800) Subject: 【主界面】UI X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~379 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=7d918a30bc135ddbd841a387a3851dcf7f845294;p=mirrors%2FFD230.git 【主界面】UI --- diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainModel.h index 659ff2467..21112483d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainModel.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainModel.h @@ -1,8 +1,8 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainModel.h - * Author: - * Create: 2021-11-23 +/*** + * @Date: 2024-06-21 09:56:18 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-20 10:44:15 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h */ #ifndef MAIN_MODEL_H @@ -10,28 +10,55 @@ #include #include "UiConfig.h" +#include "ui_resource_string.h" -namespace OHOS { - typedef struct { +namespace OHOS +{ + struct CardInfo + { CardId id; const char *cardImg; - } CardInfo; - - typedef struct { - uint8_t id; + bool isVisible; + UIResourceTextId cardid; + }; + struct CardInfoSet + { + CardId id; + bool isVisible; + }; + // 自定义表盘配置 + typedef struct + { + DialId id; const char *dialName; const char *dialImg; uint8_t freq; - uint8_t capability; } DialInfo; - typedef struct { - uint8_t dialFlag; // 0 在线表盘 1 离线表盘 + typedef struct + { + uint8_t dialFlag; uint8_t dialId; std::string dialFullName; } DialSetting; - class MainModel { + /*表盘状态*/ + enum class DialState + { + DO_NOT_DISTURB, // 勿扰 + SLEEP, // 睡眠 + LOCK, // 锁 + INVALID // 无效状态 + }; + const int STATE_COUNT = 3; // 确保这里的数量与 DialState 状态数相同 + + struct DialStateInfo + { + DialState state; + bool active; // 是否激活 + }; + class MainModel + { public: static MainModel &GetInstance(void); void InitCardSettings(void); @@ -40,32 +67,44 @@ namespace OHOS { void DeleteCardSetting(uint8_t index); void AddCardSetting(uint8_t index); const CardInfo *GetCardInfo(CardId card) const; - const DialInfo *GetDialInfo(uint8_t dial) const; // 获取在线表盘配置 - uint8_t GetDialInfoNum() const; // 获取在线表盘的数量 - void AddDialSetting(const DialSetting &setting); + const DialInfo *GetDialInfo(DialId dial) const; + void AddDialSetting(const DialSetting &setting, const int id); void InitDialSettings(void); DialSetting &GetDialSetting(); bool IsFromSetCardView(void) const; void SetFromSetCardView(bool isFrom); void SetFromCardId(uint8_t cardId); uint8_t GetFromCardId(void); - bool IsAodEnabled(); + void printCardSettings(); + const char *getCardNameFromMap(uint8_t cardId) const; + const bool GetCardInfoSet(uint8_t index) const; + + void setDialState(DialState state, bool value); + DialState getHighestPriorityActiveState(); + bool getMessageActiveState(); + void printDialStates(); + void UpdateDialState(); + void InitDialState(); + bool getVideostate(); + void setVideostate(bool state); + bool IsAodEnabled(); void EnableAod(bool enable); private: - void InitDialSettingDefault(void); + void InitDialSettingDefault(int Id); MainModel(); MainModel(const MainModel &); MainModel &operator=(const MainModel &); virtual ~MainModel(); - CardId cardSettings[CARD_SETTING_COUNT_MAX] = { MAX_CARD }; + CardId cardSettings[CARD_SETTING_COUNT_MAX] = {MAX_CARD}; uint8_t cardSettingCount{0}; DialSetting dialSetting; bool isFromSetCardView{false}; uint8_t fromCardId{MAX_CARD}; - bool isAodEnabled{false}; + bool video_state{false}; + bool isAodEnabled{false}; }; } -#endif \ No newline at end of file +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainPresenterSample.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainPresenterSample.h index aa2f4658e..39e323eb0 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainPresenterSample.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainPresenterSample.h @@ -8,18 +8,19 @@ #ifndef MAIN_PRESENTER_SAMPLE_H #define MAIN_PRESENTER_SAMPLE_H -#include "Presenter.h" +#include "HeartRateView.h" +#include "KeyInputListener.h" +#include "MainCompassPresenter.h" +#include "MainCompassView.h" +#include "MainModel.h" +#include "MainViewSample.h" #include "ModelListenerSample.h" +#include "PlayersView.h" +#include "Presenter.h" #include "components/root_view.h" -#include "drag_event.h" -#include "MainViewSample.h" -#include "MainModel.h" #include "components/ui_swipe_view.h" #include "components/ui_view.h" -#include "MainCompassView.h" -#include "MainCompassPresenter.h" -#include "PlayersView.h" -#include "HeartRateView.h" +#include "drag_event.h" #include "swipe_effect/zoom_effect.h" namespace OHOS { @@ -27,12 +28,31 @@ static constexpr const char *MAIN_CLICK_WEATHER = "mainclickweather"; static constexpr const char *MAIN_CLICK_ACTIVITY = "mainclickactivity"; static constexpr const char *MAIN_CLICK_MESSAGE = "mainclickmessage"; static constexpr const char *MAIN_CLICK_HEARTRATE = "mainclickheartrate"; +static constexpr const char *MAIN_CLICK_BLOOD = "mainclickblood"; // Ѫ����� +static constexpr const char *MAIN_CLICK_SETCARD = + "mainclicksetcard"; // ���ÿ�Ƭ + +static constexpr const char *DROPDOWN_CLICK_DONOTDISTURB = + "dropdownclickdonotdisturb"; +static constexpr const char *DROPDOWN_CLICK_BRIGHTENSCREEN = + "dropdownclickbrightscreen"; + +static constexpr const char *DROPDOWN_CLICK_SETTING = + "dropdownclicksetting"; // ���� +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"; // ���ֻ� + +static constexpr const char *CONNECTEDSTATUSBACKGROUNDBUTTON = + "connectedstatusbackgroundbutton"; // ����״̬��ť +static constexpr const char *CONNECTEDSTATUSVIEWCLOSEBUTTON = + "connectedstatusviewclosebutton"; // ����״̬��ͼ�Ĺرհ�ť -static constexpr const char *DROPDOWN_CLICK_DONOTDISTURB = "dropdownclickdonotdisturb"; -static constexpr const char *DROPDOWN_CLICK_BRIGHTENSCREEN = "dropdownclickbrightscreen"; -static constexpr const char *DROPDOWN_CLICK_FINDMYPHONE = "dropdownclickfindmyphone"; -static constexpr const char *DROPDOWN_CLICK_ALARM = "dropdownclickalarm"; -static constexpr const char *DROPDOWN_CLICK_SETTING = "dropdownclicksetting"; constexpr uint16_t VERTICAL_STATUS = 1; constexpr uint16_t HORIZONTAL_STATUS = 0; enum class MainPresenterState { @@ -62,26 +82,50 @@ public: void SetPage(int8_t id, bool loadAdjacent = true); void SetTaskPeroid(CardId cardId); - void InitCardSettings(void); - uint8_t GetCardSettingCount(void); - CardId *GetCardSettings(void); - void InitDialSettings(void); - DialSetting& GetDialSetting(); - bool IsFromSetCardView(void) const; - void SetFromSetCardView(bool isFrom); - uint8_t GetFromCardId(void); - MainPresenterState GetMainPresenterState(); + void InitCardSettings(void); + uint8_t GetCardSettingCount(void); + CardId *GetCardSettings(void); + void InitDialSettings(void); + DialSetting &GetDialSetting(); + void UpdataTime(); + uint32_t GetWeekStr(char *p_week); + void UpdataBaseData(); + void PullUpDown_StartTimer(uint32_t interval); + void PullUpDown_StopTimer(void); + static uint8_t g_PullUpDownTimes; + + void get_memcheck(); + + bool IsFromSetCardView(void) const; + void SetFromSetCardView(bool isFrom); + uint8_t GetFromCardId(void); + MainPresenterState GetMainPresenterState(); private: - void ProcessDataNotify(void); - void SetCircleProgress(void); - void SetCompassRotate(void); - uint8_t state_ = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; - int64_t playerCurrentTime_{0}; - int64_t playerMusicDuration_{0}; - int64_t playerProgressValue_{0}; - bool isCompassSensorOpened_{false}; - MainPresenterState mainPresenterState_ = MainPresenterState::STOP; + void LogCardTransition(CardId previous, CardId current); + void ResetSleepCardView(); + void ResetWeatherCardView(); + void ResetgoalCardView(); + void StartHeartRateDetection(); + void UpdateWatchFace(); + void UpdateWeather(); + void Updategoal(); + void UpdateSleep(); + void ProcessDataNotify(void); + void SetCircleProgress(void); + void SetCompassRotate(void); + void OpenCompassSensor(void); + void CloseCompassSensor(void); + KeyInputListener *keyActListener_{nullptr}; + uint8_t state_ = UICheckBox::UICheckBoxState::MAX_STATUS_NUM; + int64_t playerCurrentTime_{0}; + int64_t playerMusicDuration_{0}; + int64_t playerProgressValue_{0}; + bool isCompassSensorOpened_{false}; //ָ���봫�����Ƿ��Ѿ��� + CardId previousCardId{WATCH_FACE}; + + int isPullDownPageView{false};//�Ƿ��Ѿ������������� + MainPresenterState mainPresenterState_ = MainPresenterState::STOP; }; } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainViewSample.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainViewSample.h index c482d0309..1d9741afc 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainViewSample.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/MainViewSample.h @@ -10,6 +10,7 @@ #include #include "View.h" +#include "window/window.h" #include "components/root_view.h" #include "swipe_effect/zoom_effect.h" #include "ChangeSliceListener.h" @@ -21,66 +22,110 @@ #include "CompassControlView.h" #include "DialViewGroup.h" #include "MainClockView.h" -#include "PlayersView.h" +#include "player/include/PlayersView.h" #include "MainPresenterSample.h" #include "HeartRateView.h" #include "components/ui_card_page.h" -#include "main/include/PullUpDownView.h" +#include "PullUpDownView.h" #include "components/ui_cross_view.h" +#include "uicomponents/UIComponents.h" + #include "SetCardModel.h" +// #include "heart_blood/BloodCardView.h" +// #include "traing/training_card/include/Training_CardView.h" +// #include "ApplistCardView.h" +#include "weather/include/WeatherControlView.h" +#include "goal/include/goalControlView.h" -namespace OHOS { -class MainPresenterSample; -class MainViewSample : public View { -public: - MainViewSample(); - ~MainViewSample() override; - static MainViewSample *GetInstance(void); - void OnStart() override; - void OnStop() override; - UICardPage *InitWatchFacePage(void); - UICardPage *InitHeartRatePage(void); - UICardPage *InitActivityPage(void); - UICardPage *InitCompassPage(void); - UICardPage *InitMusicPlayerPage(void); - void AnimatorStart(int pageIndex); - void AnimatorStop(void); - CardId GetHorCurrentCard() const; - UIView* GetMainViewGroup(void) const +// #include "message/include/MessageControlView.h" +// #include "sleep/include/SleepCardView.h" +#include "set_card/include/SetMainView.h" +// #include "heartrate/include/HeartRateCardView.h" +namespace OHOS +{ + class MainPresenterSample; + class MainViewSample : public View { - return mainSwipeGroup; - } + public: + MainViewSample(); + ~MainViewSample() override; + static MainViewSample *GetInstance(void); + void OnStart() override; + - UICardPage* GetViewById(int16_t id) const - { - return recordCard[id]; - } + UICardPage *InitWatchFacePage(void); + UICardPage *InitHeartRatePage(void); + UICardPage *InitActivityPage(void); + UICardPage *InitCompassPage(void); + UICardPage *InitMusicPlayerPage(void); + UICardPage *InitBloodOxygenPage(void); + UICardPage *InitWeatherPage(void); + UICardPage *InitGoalPage(void); - void SwitchToClockPage(bool loadAdjacent = true) - { - if (mainClockView != nullptr) { - SetPage(mainClockView->GetViewIndex(), loadAdjacent); + UICardPage *InitSleepPage(void); + UICardPage *InitTrainingPage(void); + UICardPage *InitApplistPage(void); + UICardPage *InitSetMainPage(void); + + void AnimatorStart(int pageIndex); + void AnimatorStop(void); + CardId GetHorCurrentCard() const; + PullUpDownView *GetPullUpView(); + void SetDisturbState(bool state); + // UICrossView::VPage GetVerCurrentCard() const; + UIView *GetMainViewGroup(void) const + { + return mainSwipeGroup; + } + UICardPage *GetViewById(int16_t id) const + { + return recordCard[id]; } - } - void SwitchToCard(uint8_t cardId, bool loadAdjacent = true); - bool IsMainClockPage(void); - void SetDragFg(bool continFg); - bool GetDragFg(void); - void SetPage(int16_t page, bool loadAdjacent = true); + void SwitchToClockPage(void) + { + if (mainClockView != nullptr) + { + SetPage(mainClockView->GetViewIndex()); + } + } + void SwitchToCard(uint8_t cardId); + bool IsMainClockPage(void); + int IsPullUpViewPage(void); + void SetDragFg(bool continFg); + bool GetDragFg(void); + void SetPage(int16_t page, bool loadAdjacent = true); + void UpdateStateShow(UIImageView *&messageicon,UIImageView *&dialstateicon); + void HandOnKeyEventSwitchMainPullDownView(void); + void UpdateStateShow(void); + + private: + PullUpDownView *dropDownView{nullptr}; + UICardPage *mainClockView{nullptr}; + + UILabel *MessageLable = nullptr; + ActivityWeekView *activityWeekView{nullptr}; + PlayersView *playersView{nullptr}; + CompassControlView *compassControlView{nullptr}; + + // HeartRateCardView *heartRateView{nullptr}; + // BloodCardView *bloodView{nullptr}; + // SleepCardView *sleepView{nullptr}; + // Training_CardView *traingView{nullptr}; + // MessageControlView *messageView{nullptr}; + SetMainView *setmainView{nullptr}; + + WeatherControlView *weatherControlView{nullptr}; + goalControlView *GoalControlView{nullptr}; + // ApplistCardView *applistCardView{nullptr}; + UIButton *changebut{nullptr}; -private: - PullUpDownView *dropDownView{nullptr}; - UICardPage *messageView{nullptr}; - UILabel *messageLable{nullptr}; - UICardPage *mainClockView{nullptr}; - ActivityWeekView *activityWeekView{nullptr}; - PlayersView *playersView{nullptr}; - CompassControlView *compassControlView{nullptr}; - HeartRateView *heartRateView{nullptr}; - UICardPage *recordCard[MAX_CARD]{nullptr}; - bool pageStatus[MAX_CARD]{false}; - UICrossView *mainSwipeGroup{nullptr}; - ZoomEffect* callback{nullptr}; + // UIImageView *dialstateicon_{nullptr}; + // UIImageView *messageicon_{nullptr}; + /* -------------------------------------------------------------------------- */ + UICardPage *recordCard[MAX_CARD]{nullptr}; + bool pageStatus[MAX_CARD]{false}; + UICrossView *mainSwipeGroup{nullptr}; + ZoomEffect *callback{nullptr}; bool HorizontalViewInit(void); void VerticalViewInit(void); diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/PullUpDownView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/PullUpDownView.h index 9f330a307..e48d3280b 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/PullUpDownView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/include/PullUpDownView.h @@ -20,7 +20,7 @@ #include "components/ui_box_progress.h" #include "components/ui_image_animator.h" #include "components/ui_swipe_view.h" -#include "battery_hal.h" +// #include "battery_hal.h" #include "main/include/ConnectedStatusView.h" #include "main/include/dropdown/DropDownCardPage1.h" #include "main/include/dropdown/DropDownCardPage2.h" diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainModel.cpp index 521809562..2143ad581 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainModel.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainModel.cpp @@ -10,133 +10,349 @@ #include "kv_store.h" #include "securec.h" #include "wearable_log.h" -#include "DialBinTypesV2.h" +#include "ConfigModel.h" +#include +#include +#include "MainViewSample.h" +#include "ui_service.h" +#include "SetDialModel.h" +#include "dnotdisturb/include/DnotDisturbModel.h" +#include "custom_utils.h" +#include "DialViewGroup.h" + +#ifdef SUPPORT_POWER_MANAGER #include "power_display_service.h" +#endif + +extern "C" void uapi_dev_runtime_set_lock_status(uint8_t status); -namespace OHOS { +namespace OHOS +{ static const int CARD_SETTING_VALUE_LEN = 32; static const int DIAL_SETTING_VALUE_LEN = 64; + /*默认卡片:心率,睡眠,快速训练*/ + // 更新主界面卡片需要更新Map const CardInfo cardInfoMap[] = { - { HEART_RATE, PNG_SET_CARD_HEART }, - { COMPASS, PNG_SET_CARD_COMPASS }, - // { ACTIVITY, PNG_SET_CARD_ACTIVITY }, - { MUSIC_PLAYER, PNG_SET_CARD_PLAYER }, + {HEART_RATE, PNG_SET_CARD_HEART, true,STR_HEART_RATE}, + {TRAINING, PNG_SET_CARD_TRAIN, true,STR_TRAINING}, + {COMPASS, PNG_SET_CARD_COMPASS, false,STR_COMPASS}, + {SLEEP, PNG_SET_CARD_SLEEP, true,STR_SLEEP}, + {BLOODOXGEN, PNG_SET_CARD_BLOOD, false,STR_BLOOD_OXYGEN}, + {GOAL, PNG_SET_CARD_ACTIVITY, false,STR_ACTIVITY}, + {WEATHER, PNG_SET_CARD_WEATHER, false,STR_WEATHER}, + {MUSIC_PLAYER, PNG_SET_CARD_PLAYER, false,STR_MUSIC}, }; - + /*维护卡片*/ + CardInfoSet cardInfoSet[] = { + {HEART_RATE, true}, + {TRAINING, true}, + {COMPASS, false}, + {SLEEP, true}, + {BLOODOXGEN, false}, + {GOAL, false}, + {WEATHER, false}, + {MUSIC_PLAYER, false}, + }; + /*自定义map配置*/ const DialInfo dialInfoMap[] = { - { 0, "扫秒表盘", PNG_SET_DIAL_CLOCK, DEFAULT_TASK_PERIOD, DIAL_DISPLAY_CAPABILITY_NORMAL_ONLY}, - { 1, "aod扫秒表盘", PNG_SET_DIAL_CLOCK, DEFAULT_TASK_PERIOD, DIAL_DISPLAY_CAPABILITY_AMBITIENT_ONLY}, +#ifdef CUSTOM_Z1 + {DIAL_CLOCK, "Z1", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD}, +#else + {DIAL_CLOCK, "KUMI", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 默认表盘 Id 0 +#endif + {DIAL_CLOCK_1, "Custom_1", CUSTOM_CLOCK1_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 1 + {DIAL_CLOCK_2, "Custom_2", CUSTOM_CLOCK2_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 2 + {DIAL_CLOCK_3, "Custom_3", CUSTOM_CLOCK3_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 3 + {DIAL_CLOCK_4, "Custom_4", CUSTOM_CLOCK4_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 4 + {DIAL_CLOCK_5, "Custom_5", CUSTOM_CLOCK5_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 4 }; - - MainModel::MainModel() - { - power_display_gui_enable_aod(IsAodEnabled()); - } - + //默认表盘 + static const char* DEFAULT_CUSTOM_DIAL_PATH = "/user/dial/res_dial/obsidianrhythm.bin"; + //卡片map + const CardInfo printfMap[] = { + {HEART_RATE, "心率卡片"}, + {COMPASS, "指南针"}, + {MUSIC_PLAYER, "音乐"}, + {BLOODOXGEN, "血氧"}, + {WEATHER, "天气"}, + {TRAINING, "训练"}, + {GOAL, "每日目标"}, + {SLEEP, "睡眠"}, + }; + /*表盘显示状态map*/ + std::array dialstateInfo = {{ + {DialState::DO_NOT_DISTURB, false}, + {DialState::SLEEP, false}, + {DialState::LOCK, false}, + }}; + MainModel::MainModel() {} MainModel::~MainModel() {} - MainModel &MainModel::GetInstance() { static MainModel instance; return instance; } + /* + ###卡片配置### - const CardInfo *MainModel::GetCardInfo(CardId card) const + -卡片Id + -卡片默认map + -卡片维护map + */ + void MainModel::printCardSettings(void) { - for (uint8_t i = 0; i < (sizeof(cardInfoMap) / sizeof(cardInfoMap[0])); i++) { - if (card == cardInfoMap[i].id) { - return &cardInfoMap[i]; - } + uint8_t i; + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "_____________________________________________________\r\n"); + for (i = 0; i < cardSettingCount; i++) + { + uint8_t cardId = cardSettings[i]; + const char *cardname = getCardNameFromMap(cardId); + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "cardSettings[%d]:Id: %d, CardName: %s\r\n", i, cardId, cardname); } - return nullptr; + + for (uint8_t m = 0; m < (sizeof(cardInfoSet) / sizeof(cardInfoSet[0])); m++) + { + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "cardInfoSet[%d]:Id %d, Visible: %s\n", m, cardInfoSet[m].id, cardInfoSet[m].isVisible ? "true" : "false"); + } + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "_____________________________________________________\r\n"); } - const DialInfo *MainModel::GetDialInfo(uint8_t dialId) const + const char *MainModel::getCardNameFromMap(uint8_t cardId) const { - for (uint8_t i = 0; i < (sizeof(dialInfoMap) / sizeof(dialInfoMap[0])); i++) { - if (dialId == dialInfoMap[i].id) { - return &dialInfoMap[i]; + for (uint8_t i = 0; i < (sizeof(printfMap) / sizeof(printfMap[0])); i++) + { + if (cardId == printfMap[i].id) + { + return printfMap[i].cardImg; + } + } + return "Unknown"; + } + const CardInfo *MainModel::GetCardInfo(CardId card) const + { + for (uint8_t i = 0; i < (sizeof(cardInfoMap) / sizeof(cardInfoMap[0])); i++) + { + if (card == cardInfoMap[i].id) + { + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "cardInfoMap[%d]:%d\n", i, cardInfoMap[i].id); + return &cardInfoMap[i]; } } return nullptr; } - - uint8_t MainModel::GetDialInfoNum() const + const bool MainModel::GetCardInfoSet(uint8_t index) const { - return sizeof(dialInfoMap) / sizeof(dialInfoMap[0]); + return cardInfoSet[index].isVisible; } - + /*初始化卡片设置*/ void MainModel::InitCardSettings(void) { - char temp[CARD_SETTING_VALUE_LEN] = { 0 }; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardSettings"); + char temp[CARD_SETTING_VALUE_LEN] = {0}; int len; int index = 0; memset_s(cardSettings, CARD_SETTING_COUNT_MAX, 0, CARD_SETTING_COUNT_MAX); len = UtilsGetValue("card_setting", temp, CARD_SETTING_VALUE_LEN); - if (len >= 0 && strlen(temp) > 0) { - /* 读取用户card配置 */ + if (len >= 0) + { + // 更新用户卡片配置及更新卡片可见性 char *setBuffer = nullptr; char *setValue = strtok_s(temp, ",", &setBuffer); - while (setValue != nullptr) { - if (index >= CARD_SETTING_COUNT_MAX) { + index = 0; // 重置 index + while (setValue != nullptr) + { + if (index >= CARD_SETTING_COUNT_MAX) + { break; } cardSettings[index++] = (CardId)atoi(setValue); setValue = strtok_s(nullptr, ",", &setBuffer); } cardSettingCount = index; - } else { - /* 使用默认card配置 */ - cardSettings[index++] = WATCH_FACE; - cardSettings[index++] = HEART_RATE; - cardSettings[index++] = COMPASS; - // cardSettings[index++] = ACTIVITY; - cardSettings[index++] = MUSIC_PLAYER; + + // 更新卡片可见性 + for (size_t i = 0; i < sizeof(cardInfoSet) / sizeof(cardInfoSet[0]); i++) + { + bool visible = false; + for (size_t j = 0; j < cardSettingCount; j++) + { + if (cardInfoSet[i].id == cardSettings[j]) + { + // WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "CardSettings:cardInfoSet[%d] is set cardSettings[%d]\r\n", i, j); + visible = true; + break; + } + } + cardInfoSet[i].isVisible = visible; + } + } + else + { + for (uint8_t i = 0; i < (sizeof(cardInfoMap) / sizeof(cardInfoMap[0])); i++) + { + if (index == 0) + { + /* 表盘卡片[不被卡片管理,必须设置] */ + cardSettings[index++] = WATCH_FACE; + } + if (cardInfoMap[i].isVisible) + { + cardSettings[index++] = cardInfoMap[i].id; + } + // 配置维护卡片的可见 与默认 保持一致 {没有kv文件} + cardInfoSet[i].isVisible = cardInfoMap[i].isVisible; + } + + /*设置卡片[不被卡片管理,必须设置] */ + cardSettings[index++] = SETCARD; + cardSettingCount = index; } - } + // printCardSettings(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitCardSettings"); + } void MainModel::DeleteCardSetting(uint8_t index) { - char temp[CARD_SETTING_VALUE_LEN] = { 0 }; - for (uint8_t i = 0; i < cardSettingCount; i++) { - if (i == index + 1) { - uint8_t j = i; - for (; j < cardSettingCount - 1; j++) { - cardSettings[j] = cardSettings[j + 1]; - } - cardSettings[j] = MAX_CARD; - cardSettingCount--; + /*设置卡片类型为false cardsetting 重新遍历map里面为ture的卡片{表盘必须存在}*/ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DeleteCardSetting"); + + if (cardSettingCount > CARD_SETTING_COUNT_MAX) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cardSettingCount %d is error", cardSettingCount); + return; + } + // 检查要插入的位置是否有效 + int count = sizeof(cardInfoSet) / sizeof(cardInfoSet[0]); + if (index < 0 || index > count) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index %d is error or count %d is error", index, count); + return; + } + // 删除的卡片 + cardInfoSet[index].isVisible = false; +#if 0 + int count = sizeof(cardInfoSet) / sizeof(cardInfoSet[0]); + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "count:%d\r\n", count); + // 设置map里面的属性 + for (uint8_t i = 0; i < count; i++) + { + // 需要被删除的卡片 + if (cardInfoMap[index].id == cardInfoSet[i].id) + { + cardInfoSet[i].isVisible = false; + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "删除卡片:cardSettings[%d] is %d \r\n", index + 1, cardSettings[index + 1]); + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "设置删除卡片属性:cardInfoSet[%d] is %d \r\n", i, cardInfoSet[i].isVisible); } + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "cardInfoSet[%d]:id%d\r\n", i, cardInfoSet[i].id); } +#endif + int mapindex = 0; + // 重新生成cardSettings + for (uint8_t i = 0; i < CARD_SETTING_COUNT_MAX; i++) + { + cardSettings[i] = MAX_CARD; + } + // printCardSettings(); + for (uint8_t i = 0; i < (sizeof(cardInfoSet) / sizeof(cardInfoSet[0])); i++) + { + if (mapindex == 0) + { + /* 表盘卡片[不被卡片管理,必须设置] */ + cardSettings[mapindex++] = WATCH_FACE; + } + // 设置其他卡片 + if (cardInfoSet[i].isVisible) + { + // WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "cardSettings[%d]\r\n", i); + cardSettings[mapindex++] = cardInfoSet[i].id; + } + } + /*设置卡片[不被卡片管理,必须设置] */ + cardSettings[mapindex++] = SETCARD; - for (uint8_t i = 0; i < cardSettingCount; i++) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardSettings[%d] = %d", i, cardSettings[i]); - (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[i]); + cardSettingCount = mapindex; + + // 更新存储内容 + char temp[CARD_SETTING_VALUE_LEN] = {0}; + for (uint8_t k = 0; k < cardSettingCount; k++) + { + (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[k]); } (void)UtilsSetValue("card_setting", temp); + + // printCardSettings(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DeleteCardSetting"); } void MainModel::AddCardSetting(uint8_t index) { - char temp[CARD_SETTING_VALUE_LEN] = { 0 }; - if (cardSettingCount >= CARD_SETTING_COUNT_MAX) { + /*设置卡片类型为ture cardsetting 重新遍历map里面为ture的卡片{表盘必须存在}*/ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardSetting"); + + if (cardSettingCount > CARD_SETTING_COUNT_MAX) + { return; } - for (int i = 0; i < cardSettingCount; i++) { - if (cardSettings[i] == cardInfoMap[index].id) { - return; + + // 检查要插入的位置是否有效 + int count = sizeof(cardInfoSet) / sizeof(cardInfoSet[0]); + if (index < 0 || index > count) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index %d is error or count %d is error", index, count); + return; + } + // 设置map里面的属性 + cardInfoSet[index].isVisible = true; +#if 0 + int count = sizeof(cardInfoSet) / sizeof(cardInfoSet[0]); + for (uint8_t i = 0; i < count; i++) + { + // 需要被添加的卡片 因为添加是显示所有卡片,所以是使用map + if (cardInfoMap[index].id == cardInfoSet[i].id) + { + cardInfoSet[i].isVisible = true; + WEARABLE_LOGE(WEARABL_LOG_MODULE_APP, "添加卡片:cardSettings[%d] is %d \r\n", index, cardInfoMap[index].id); + WEARABLE_LOGE(WEARABL_LOG_MODULE_APP, "设置添加卡片属性:cardInfoSet[%d] is %d \r\n", i, cardInfoSet[i].isVisible); + break; } + WEARABLE_LOGE(WEARABL_LOG_MODULE_APP, "cardInfoSet[%d]:id%d\r\n", i, cardInfoSet[i].id); } - cardSettings[cardSettingCount++] = cardInfoMap[index].id; - for (uint8_t i = 0; i < cardSettingCount; i++) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardSettings[%d] = %d", i, cardSettings[i]); - (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[i]); +#endif + + // 设置map里面的属性 + int mapindex = 0; + for (uint8_t i = 0; i < (sizeof(cardInfoSet) / sizeof(cardInfoSet[0])); i++) + { + if (mapindex == 0) + { + /* 表盘卡片[不被卡片管理,必须设置] */ + cardSettings[mapindex++] = WATCH_FACE; + } + // 设置其他卡片 + if (cardInfoSet[i].isVisible) + { + cardSettings[mapindex++] = cardInfoSet[i].id; + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "set cardInfoSet[%d]\r\n", i); + } + } + /*设置卡片[不被卡片管理,必须设置] */ + cardSettings[mapindex++] = SETCARD; + + cardSettingCount = mapindex; + + // 更新存储内容 + char temp[CARD_SETTING_VALUE_LEN] = {0}; + for (uint8_t j = 0; j < cardSettingCount; j++) + { + (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[j]); } (void)UtilsSetValue("card_setting", temp); - } + // printCardSettings(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardSetting"); + } uint8_t MainModel::GetCardSettingCount(void) { return cardSettingCount; @@ -146,92 +362,338 @@ namespace OHOS { { return cardSettings; } + bool MainModel::IsFromSetCardView(void) const + { + return isFromSetCardView; + } + + void MainModel::SetFromSetCardView(bool isFrom) + { + isFromSetCardView = isFrom; + } + + void MainModel::SetFromCardId(uint8_t cardId) + { + fromCardId = cardId; + } + + uint8_t MainModel::GetFromCardId(void) + { + return fromCardId; + } + + /* + ###表盘配置### - void MainModel::InitDialSettingDefault(void) + -表盘名称 + -表盘列表 + -表盘Id + */ + const DialInfo *MainModel::GetDialInfo(DialId dialId) const { + for (uint8_t i = 0; i < (sizeof(dialInfoMap) / sizeof(dialInfoMap[0])); i++) + { + if (dialId == dialInfoMap[i].id) + { + return &dialInfoMap[i]; + } + } + return nullptr; + } + + void MainModel::InitDialSettingDefault(int id) + { + //黑耀表盘 + if(id == DEFAULT_DIAL_ID) + { + dialSetting.dialFlag = 1; + dialSetting.dialId = id; + dialSetting.dialFullName = DEFAULT_CUSTOM_DIAL_PATH; + return; + } + //自定义表盘 + if (id < DIAL_CLOCK || id >= DIAL_MAX) + id = DIAL_CLOCK; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitDialSettingDefault"); dialSetting.dialFlag = 0; - dialSetting.dialId = 0; - dialSetting.dialFullName = ""; + dialSetting.dialId = id; + dialSetting.dialFullName.clear(); // 用 clear() 替代空字符串 } - void MainModel::AddDialSetting(const DialSetting &setting) + /* 更新表盘设置 */ + void MainModel::AddDialSetting(const DialSetting &setting, const int id) { - std::string tmp; - tmp += std::to_string(setting.dialFlag); - tmp += ","; - tmp += std::to_string(setting.dialId); - tmp += ","; - tmp += setting.dialFullName; - tmp += ","; - (void)UtilsSetValue("dial_setting", tmp.c_str()); + std::string tmp = std::to_string(setting.dialFlag) + "," + std::to_string(setting.dialId) + "," + setting.dialFullName + ","; + + (void)UtilsSetValue("dial_setting", tmp.c_str()); // 存储表盘配置 + (void)UtilsSetValue("dial_id", std::to_string(id).c_str()); // 存储当前表盘Id } + /* 加载 kvstore 里面的 dial */ void MainModel::InitDialSettings(void) { - char temp[DIAL_SETTING_VALUE_LEN] = { 0 }; - int32_t len = UtilsGetValue("dial_setting", temp, DIAL_SETTING_VALUE_LEN); - if (len >= 0) { - char *setBuffer = nullptr; - char *setValue = strtok_s(temp, ",", &setBuffer); - if (setValue != nullptr) { - dialSetting.dialFlag = atoi(setValue); - } else { - InitDialSettingDefault(); - return; + char temp[DIAL_SETTING_VALUE_LEN] = {0}; // 创建一个临时字符数组用于存储拨号设置的字符串 + int len = UtilsGetValue("dial_setting", temp, DIAL_SETTING_VALUE_LEN); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Attempting to load dial settings from kvstore. Length: %d\r\n", len); + + if (len < 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Failed to retrieve dial settings. Initializing to default settings.\r\n"); + //判断黑耀表盘是否存在 + if(SetDialModel::GetInstance().IsDialInstalled(DEFAULT_DIAL_ID)) + { + InitDialSettingDefault(DEFAULT_DIAL_ID); + } + else + { + InitDialSettingDefault(DIAL_CLOCK); } + return; + } - setValue = strtok_s(nullptr, ",", &setBuffer); - if (setValue != nullptr) { - dialSetting.dialId = atoi(setValue); - } else { - InitDialSettingDefault(); - return; + char *setBuffer = nullptr; // 字符指针用于 strtok_s 的存储 + char *setValue; + + // 从字符串中读取三个值 + // 1.读取表盘标志位 + setValue = strtok_s(temp, ",", &setBuffer); + if (setValue) + { + dialSetting.dialFlag = atoi(setValue); // 将字符串转换为整数 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Dial flag loaded: %d\r\n", dialSetting.dialFlag); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: First value is empty. Initializing to default settings.\r\n"); + //判断黑耀表盘是否存在 + if(SetDialModel::GetInstance().IsDialInstalled(DEFAULT_DIAL_ID)) + { + InitDialSettingDefault(DEFAULT_DIAL_ID); + } + else + { + InitDialSettingDefault(DIAL_CLOCK); } + return; + } - setValue = strtok_s(nullptr, ",", &setBuffer); - if (setValue != nullptr) { - dialSetting.dialFullName = setValue; - if (!((dialSetting.dialFullName.length() > 0) && - (access(dialSetting.dialFullName.c_str(), F_OK) == 0))) { - InitDialSettingDefault(); - return; - } - } else { - InitDialSettingDefault(); - return; + // 读取表盘Id + setValue = strtok_s(nullptr, ",", &setBuffer); + if (setValue) + { + dialSetting.dialId = atoi(setValue); // 将字符串转换为整数 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Dial ID loaded: %d\r\n", dialSetting.dialId); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Second value is empty. Initializing to default settings.\r\n"); + //判断黑耀表盘是否存在 + if(SetDialModel::GetInstance().IsDialInstalled(DEFAULT_DIAL_ID)) + { + InitDialSettingDefault(DEFAULT_DIAL_ID); } - } else { - InitDialSettingDefault(); + else + { + InitDialSettingDefault(DIAL_CLOCK); + } + return; + } + + // 读取表盘名 + setValue = strtok_s(nullptr, ",", &setBuffer); + if (setValue) + { + dialSetting.dialFullName = setValue; // 将完整名称赋值 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Dial full name loaded: %s\r\n", dialSetting.dialFullName.c_str()); + + if (dialSetting.dialFullName.empty() || access(dialSetting.dialFullName.c_str(), F_OK) != 0) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error: Dial full name is invalid or file does not exist. Initializing to default settings.\r\n"); + InitDialSettingDefault(dialSetting.dialId); + } + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Error: Third value is empty. Initializing to default settings.\r\n"); + InitDialSettingDefault(dialSetting.dialId); } } - DialSetting& MainModel::GetDialSetting() + DialSetting &MainModel::GetDialSetting() { return dialSetting; } - bool MainModel::IsFromSetCardView(void) const + /* + ###表盘状态### + + 接口 1 设置某个项的属性为ture or false + 接口 2 获取最高优先级为ture的状态为哪一个 并且返回 + 接口 3 打印状态 + + 管理状态:勿扰 睡眠 密码锁 + */ + + // 开机读取手表配置 + void MainModel::InitDialState(void) { + // 获取加锁状态 + int lockstate = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "lockstate = %d", lockstate); + + // 判断加锁状态 + if (lockstate == 1) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Device is locked (lock state == 1)"); + uapi_dev_runtime_set_lock_status(1); // 上锁 + dialstateInfo[static_cast(DialState::LOCK)].active = true; // 设置锁定状态为真 + } + + // 判断勿扰模式 + dialstateInfo[static_cast(DialState::DO_NOT_DISTURB)].active = DnotDisturbModel::GetInstance().GetDoNotDisturbModeEnabled(); + + // 判断睡眠状态 + } + + // 接口 1: 设置某个状态的属性 + void MainModel::setDialState(DialState state, bool value) { - return isFromSetCardView; + // // 将 state 转换为整数以进行比较 + // int stateIndex = static_cast(state); + // if (stateIndex >= 0 && stateIndex < STATE_COUNT) // 确保 index 在有效范围 + // { + // // 检查当前状态是否与要设置的状态一致 + // if (dialstateInfo[stateIndex].active != value) + // { + // dialstateInfo[stateIndex].active = value; // 使用转换后的索引 + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Set dialstateInfo[%d].active = %d", stateIndex, value); + // SendMsgToUIService(UI_UPDATE_DIALSTATE_DATA, 0, nullptr, 0); // 发送更新消息 + // } + // else + // { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "State %d is unchanged, no update needed.", stateIndex); + // } + // } + // else + // { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "state %d is error", stateIndex); + // } } - void MainModel::SetFromSetCardView(bool isFrom) + // 接口 2: 获取最高优先级为 true 的状态 + DialState MainModel::getHighestPriorityActiveState() { - isFromSetCardView = isFrom; + for (int i = STATE_COUNT - 1; i >= 0; i--) + { + if (dialstateInfo[i].active) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "high dialstateInfo[%d].active", i); + return dialstateInfo[i].state; // 返回活跃状态中优先级最高的 + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "no have high dialstateInfo.active"); + return DialState::INVALID; // 如果没有找到活跃状态,返回无效状态 } - void MainModel::SetFromCardId(uint8_t cardId) + // 接口 3: 打印所有状态及其是否激活 + void MainModel::printDialStates() { - fromCardId = cardId; + for (int i = 0; i < STATE_COUNT; ++i) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dialstateInfo[%d].active = %d", i, dialstateInfo[i].active); + } } - uint8_t MainModel::GetFromCardId(void) + // 未读状态判断 + bool MainModel::getMessageActiveState() { - return fromCardId; + bool unread_state = ConfigModel::GetInstance()->get_configData_bool(ConfigModel::CONFIGMODEL_ITEM_MESSAGE_UNREAD); + return unread_state; + } + + void MainModel::UpdateDialState() + { + /*进行主界面UI更新通知 如果在主界面*/ + if (MainViewSample::GetInstance() != nullptr) + MainViewSample::GetInstance()->UpdateStateShow(); + } + //主界面获取视频频率 + bool MainModel::getVideostate() { + return video_state; + } + void MainModel::setVideostate(bool state) { + video_state = state; + } + + +#if 0 + void MainModel::DeleteCardSetting(uint8_t index) + { + char temp[CARD_SETTING_VALUE_LEN] = {0}; + for (uint8_t i = 0; i < cardSettingCount; i++) + { + if (i == index + 1) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "i:%d index:%d", i, index); + uint8_t j = i; + for (; j < cardSettingCount - 1; j++) + { + cardSettings[j] = cardSettings[j + 1]; + } + cardSettings[j] = MAX_CARD; + cardSettingCount--; + } + } + + for (uint8_t i = 0; i < cardSettingCount; i++) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardSettings[%d] = %d", i, cardSettings[i]); + (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[i]); + } + (void)UtilsSetValue("card_setting", temp); + + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "\r\n***************DeleteCardSetting********************\r\n"); + printCardSettings(); + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "\r\n_____________________________________________________\r\n"); + } + + void MainModel::AddCardSetting(uint8_t index) + { + char temp[CARD_SETTING_VALUE_LEN] = {0}; + if (cardSettingCount >= CARD_SETTING_COUNT_MAX) + { + return; + } + for (int i = 0; i < cardSettingCount; i++) + { + if (cardSettings[i] == cardInfoMap[index].id) + { + return; + } + } + cardSettings[cardSettingCount++] = cardInfoMap[index].id; + for (uint8_t i = 0; i < cardSettingCount; i++) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cardSettings[%d] = %d", i, cardSettings[i]); + (void)sprintf_s(temp + strlen(temp), CARD_SETTING_VALUE_LEN, "%d,", cardSettings[i]); + } + (void)UtilsSetValue("card_setting", temp); + + WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "\r\n***************AddCardSetting********************\r\n"); + printCardSettings(); + else + { + /* 使用默认card配置 */ + cardSettings[index++] = WATCH_FACE; + cardSettings[index++] = HEART_RATE; + cardSettings[index++] = COMPASS; + cardSettings[index++] = MUSIC_PLAYER; + cardSettings[index++] = SETCARD; // 默认卡片增加设置卡片 + cardSettingCount = index; + } } +#endif - bool MainModel::IsAodEnabled() + bool MainModel::IsAodEnabled() { char temp[DIAL_SETTING_VALUE_LEN] = { 0 }; int32_t len = UtilsGetValue("enable_aod", temp, DIAL_SETTING_VALUE_LEN); diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainPresenterSample.cpp index 93585ef7f..17021a1d7 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainPresenterSample.cpp @@ -10,9 +10,8 @@ #include "HeartRateView.h" #include "PlayersModel.h" #include "PlayersPresenter.h" -#include "MainCompassPresenter.h" -#include "NativeRegisterManager.h" -#include "CompassModel.h" +#include "CompassPresenter.h" +#include "compass/include/CompassModel.h" #include "CompassCalibrationView.h" #include "drag_event.h" #include "graphic_service.h" @@ -23,310 +22,778 @@ #include #include "ModelDialDataFactory.h" #include "DialModelTime.h" +#include "DialModelPower.h" +#include "heartrate/include/HeartModel.h" +#include "gfx_utils/mem_check.h" +#include "custom_utils.h" +// #include "traing/training_card/include/Training_CardView.h" +// #include "dnotdisturb/include/DnotDisturbModel.h" +#include "weather/include/WeatherModel.h" +// #include "heart_blood/health_service/health_service.h" +// #include "sleep/include/SleepControlView.h" +// #include "sleep/include/SleepCardView.h" +// #include "sleep/include/SleepModel.h" +#include "MainModel.h" +// #include "../../../../../../../drivers/peripheral/utils/custom_runtime.h" +// #include "rebootandshutdown/include/RebootAndShutdownModelC.h" + +#if USE_OFFLINE_DIAL #include "DialViewGroup.h" +#endif #include "ui_service.h" -#include "PageTransitionMgr.h" - -namespace OHOS { +#include "time.h" +#define TESTCHECK 0 +//心率弹窗 +#define HEART_RATE_CHECK_TIMEOUT 0 +#include "NativeRegisterManager.h" +#ifdef SUPPORT_POWER_MANAGER +#include "power_display_service.h" +#endif +namespace OHOS +{ REGIST_SLICE(VIEW_MAIN, MainViewSample, MainPresenterSample); -std::map g_jumpView = { { MAIN_CLICK_WEATHER, VIEW_MAIN }, // 天气界面 - { MAIN_CLICK_ACTIVITY, VIEW_MAIN_ACTIVITY }, // 活动记录界面 - { MAIN_CLICK_MESSAGE, VIEW_MAIN }, // 消息app - { MAIN_CLICK_HEARTRATE, VIEW_MAIN }, // 心率界面 - { DROPDOWN_CLICK_ALARM, VIEW_MAIN_ALARM }, // 闹钟app - { DROPDOWN_CLICK_SETTING, VIEW_SETTING } }; // 设置界面 - -// std::map g_chanColor = { { DROPDOWN_CLICK_FINDMYPHONE, DROPDOWN_DROPDOWN_FIND_PHONE_B }, -// { DROPDOWN_CLICK_ALARM, DROPDOWN_DROPDOWN_ALARM_B }, -// { DROPDOWN_CLICK_SETTING, DROPDOWN_DROPDOWN_SETTING_B } }; - -static MainPresenterSample *g_pMainPresenterSample = nullptr; + std::map g_jumpView = { + {MAIN_CLICK_BLOOD, VIEW_BLOOD_CHECK}, // 血氧检查 + {MAIN_CLICK_SETCARD, VIEW_ADD_CARD}, // 卡片管理 + }; -static constexpr uint16_t DROP_X_MAX = 360; -static constexpr uint16_t PROGRESS_PERCENTAGE = 100; -static constexpr uint16_t HORIZONTAL_SWIPE = 1; -static constexpr uint16_t PLAYER_PERIOD = 500; -static constexpr uint16_t MAX_PERIOD = 1000; + static MainPresenterSample *g_pMainPresenterSample = nullptr; -MainPresenterSample::MainPresenterSample() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample :%p", this); - g_pMainPresenterSample = this; -} - -MainPresenterSample::~MainPresenterSample() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~MainPresenterSample"); -} + static constexpr uint16_t DROP_X_MAX = 360; + static constexpr uint16_t PROGRESS_PERCENTAGE = 100; + static constexpr uint16_t HORIZONTAL_SWIPE = 1; + static constexpr uint16_t PLAYER_PERIOD = 500; + static constexpr uint16_t MAX_PERIOD = 1000; -MainPresenterSample *MainPresenterSample::GetInstance(void) -{ - return g_pMainPresenterSample; -} + MainPresenterSample::MainPresenterSample() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample :%p", this); + g_pMainPresenterSample = this; + } -void MainPresenterSample::OnStart() -{ - mainPresenterState_ = MainPresenterState::START; -} + MainPresenterSample::~MainPresenterSample() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~MainPresenterSample"); + g_pMainPresenterSample = nullptr; + // /*从主界面退出,关闭心率检测*/ + // HeartModel::GetInstance()->Heart_Stop(); + // HeartModel::GetInstance()->Heart_Control(HeartState::End, + // HeartCheck::CARDCHECK); + } -void MainPresenterSample::OnPause() -{ - Presenter::OnPause(); - // Save watchface content for slide back - UIView* watchFace = view_->GetViewById(WATCH_FACE)->GetParent(); - uint8_t opaScale = watchFace->GetOpaScale(); - watchFace->SetOpaScale(OPA_OPAQUE); - PageTransitionMgr::GetInstance().SaveSlideBackSnapShotIfNecessary(watchFace); - watchFace->SetOpaScale(opaScale); - - mainPresenterState_ = MainPresenterState::PAUSE; -} + MainPresenterSample *MainPresenterSample::GetInstance(void) + { + return g_pMainPresenterSample; + } + + void MainPresenterSample::OnStart() + { + mainPresenterState_ = MainPresenterState::START; + } + + void MainPresenterSample::OnPause() + { + Presenter::OnPause(); + // Save watchface content for slide back + UIView* watchFace = view_->GetViewById(WATCH_FACE)->GetParent(); + uint8_t opaScale = watchFace->GetOpaScale(); + watchFace->SetOpaScale(OPA_OPAQUE); + PageTransitionMgr::GetInstance().SaveSlideBackSnapShotIfNecessary(watchFace); + watchFace->SetOpaScale(opaScale); + + mainPresenterState_ = MainPresenterState::PAUSE; + + //进行视频表盘的暂停 + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "暂停视频") ; + // DialSetting &setting = GetDialSetting(); + // if (setting.dialFlag) { + // DialModelTime::GetInstance()->UpdateTime(); + // dynamic_cast(view_->GetViewById(WATCH_FACE))->StopDial(); + // } + } + + void MainPresenterSample::OnResume(void) + { + Presenter::OnResume(); + mainPresenterState_ = MainPresenterState::RESUME; + // Set current page again to invoke OnActive method. + uint8_t curCardId = view_->GetHorCurrentCard(); + view_->SwitchToCard(curCardId); + + #if IS_SUPPORT_BIND_VOTE +if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true) { + uapi_remove_bind_vote(); //页面已经展示后的调用逻辑。取消绑定投票 + ConfigModel::GetInstance()->SetisFirstTimeStart(false); + } +#endif + // //进行视频表盘的恢复 + // DialSetting &setting = GetDialSetting(); + // if (setting.dialFlag) { + // DialModelTime::GetInstance()->UpdateTime(); + // dynamic_cast(view_->GetViewById(WATCH_FACE))->StartDial(); + // } + } + + void MainPresenterSample::OnStop(void) + { + mainPresenterState_ = MainPresenterState::STOP; + if (isCompassSensorOpened_) { + CompassModel::GetInstance()->CloseCompassSensor(); + } -void MainPresenterSample::OnResume(void) -{ - Presenter::OnResume(); - mainPresenterState_ = MainPresenterState::RESUME; - // Set current page again to invoke OnActive method. - uint8_t curCardId = view_->GetHorCurrentCard(); - view_->SwitchToCard(curCardId); -} + PullUpDown_StopTimer(); + CloseCompassSensor(); //切换Slice时要关闭指南针传感器 + } -void MainPresenterSample::OnStop(void) -{ - mainPresenterState_ = MainPresenterState::STOP; - if (isCompassSensorOpened_) { - CompassModel::GetInstance()->CloseCompassSensor(); + MainPresenterState MainPresenterSample::GetMainPresenterState(void) + { + return mainPresenterState_; } -} -MainPresenterState MainPresenterSample::GetMainPresenterState(void) -{ - return mainPresenterState_; -} -bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event) -{ - // UNUSED(event); - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusButtonClickListener: %s", view.GetViewId()); - // std::string curViewId = view.GetViewId(); - - // UIImageView *imgView = static_cast(&view); - // if (HealthModel::GetInstance() == nullptr) { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr"); - // return false; - // } - // if (curViewId == DROPDOWN_CLICK_DONOTDISTURB) { - // if (HealthModel::GetInstance()->GetDntDistStatus() == 0) { - // ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB_B); - // HealthModel::GetInstance()->UpdateDntDistStatus(1); - // } else { - // ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_DN_DISTURB); - // HealthModel::GetInstance()->UpdateDntDistStatus(0); - // } - // } - // if (curViewId == DROPDOWN_CLICK_BRIGHTENSCREEN) { - // if (HealthModel::GetInstance()->GetBriScrStatus() == 0) { - // ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN_B); - // HealthModel::GetInstance()->UpdateBriScrStatus(1); - // ScreenOffEnable(0); - // } else { - // ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, imgView, DROPDOWN_DROPDOWN_BRI_SCREEN); - // HealthModel::GetInstance()->UpdateBriScrStatus(0); - // ScreenOffEnable(1); - // } - // } + + bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusButtonClickListener: %s", view.GetViewId()); + std::string curViewId = view.GetViewId(); + + // UIImageView *imgView = static_cast(&view); + // if (HealthModel::GetInstance() == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr"); + // return false; + // } + + // /*发生点击进入密码锁*/ + // if (uapi_dev_runtime_get_lock_status()) + // { + // /*进入密码锁*/ + // NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK); + // return true; + // } + + // if (curViewId == CONNECTEDSTATUSBACKGROUNDBUTTON) + // { + // PullUpDownView::GetInstance()->ChangeView(DROPDOWNVIEW, CONNECTEDSTATUSVIEW); + // PullUpDown_StopTimer(); // 切换到连接状态视图时停止定时器 + // return true; + // } + // else if (curViewId == CONNECTEDSTATUSVIEWCLOSEBUTTON) + // { + // PullUpDownView::GetInstance()->ChangeView(CONNECTEDSTATUSVIEW, DROPDOWNVIEW); + // PullUpDown_StartTimer(1000); // 切回下拉控制中心视图开启定时器 + // return true; + // } + // // 设置血氧进入 + // else if (curViewId == MAIN_CLICK_BLOOD) + // { + // MainModel::GetInstance().SetFromSetCardView(true); + // MainModel::GetInstance().SetFromCardId(BLOODOXGEN); + // // 如果正在充电进入提醒界面 + // if (get_charge_stat()) + // { + // HealthState highHealthState; + // highHealthState.checkType = CHARGE; + // HealthService::GetInstance()->SetHealthCurrent(highHealthState); + // NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_INVALID, TransitionType::TRANSITION_ZOOM); + // } + // } + // 设置卡片管理进入 + if (curViewId == MAIN_CLICK_SETCARD) + { + MainModel::GetInstance().SetFromSetCardView(true); + MainModel::GetInstance().SetFromCardId(SETCARD); + } + if (g_jumpView.count(curViewId) != 0) + { + NativeAbility::GetInstance().EnterSlice(g_jumpView[curViewId]); + } + return true; + } - // if (g_jumpView.count(curViewId) != 0) { - // if (g_jumpView[curViewId] == VIEW_SETTING) { - // NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId], TransitionType::TRANSITION_INVALID, - // gSliceDefaultPriority, true); - // } else { - // NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]); - // } - // } - return true; -} + bool MainPresenterSample::OnLongPress(UIView &view, const LongPressEvent &event) + { + UNUSED(event); + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress"); + uint8_t cardId = view_->GetHorCurrentCard(); + /* + 卡片进入管理卡片界面 + if (cardId != WATCH_FACE) + { + SetCardModel::GetInstance().SetSelectedCard(cardId); + NativeAbility::GetInstance().ChangeSlice(VIEW_ADD_CARD); + } + */ + if (cardId == WATCH_FACE) + { + // if (uapi_dev_runtime_get_lock_status()) + // { + // /*进入密码锁*/ + // NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK); + // } + // else + // { + /*进入表盘设置*/ + NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL); + // } + } + return true; + } -bool MainPresenterSample::OnLongPress(UIView& view, const LongPressEvent& event) -{ - UNUSED(event); - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress"); - uint8_t cardId = view_->GetHorCurrentCard(); - if (cardId != WATCH_FACE) { - SetCardModel::GetInstance().SetSelectedCard(cardId); - NativeAbility::GetInstance().ChangeSlice(VIEW_SET_CARD); - } else { - NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL); - } - return true; -} -void MainPresenterSample::SetPage(int8_t id, bool loadAdjacent) -{ - if (view_ != nullptr) { - view_->SetPage(id, loadAdjacent); + void MainPresenterSample::SetPage(int8_t id, bool loadAdjacent) + { + if (view_ != nullptr) { + view_->SetPage(id, loadAdjacent); + } } -} -void MainPresenterSample::SetTaskPeroid(CardId cardId) -{ - if (cardId == COMPASS) { - SetPeriod(DEFAULT_TASK_PERIOD); - } else if (cardId == WATCH_FACE) { - uint32_t time; - DialSetting &setting = GetDialSetting(); - if (setting.dialFlag) { - time = dynamic_cast(view_->GetViewById(WATCH_FACE))->GetPeriod(); - } else { - time = DEFAULT_TASK_PERIOD; + void MainPresenterSample::SetTaskPeroid(CardId cardId) + { + if (cardId == COMPASS) + { + SetPeriod(DEFAULT_TASK_PERIOD); + } + else if (cardId == WATCH_FACE) + { + uint32_t time; + DialSetting &setting = GetDialSetting(); + if (setting.dialFlag) + { + time = dynamic_cast(view_->GetViewById(WATCH_FACE))->GetPeriod(); + } + else + { + time = DEFAULT_TASK_PERIOD; + } + SetPeriod(time); + } + else if (cardId == MUSIC_PLAYER) + { + SetPeriod(PLAYER_PERIOD); + } + else + { + SetPeriod(MAX_PERIOD); } - SetPeriod(time); - } else if (cardId == MUSIC_PLAYER) { - SetPeriod(PLAYER_PERIOD); - } else { - SetPeriod(MAX_PERIOD); } -} -void MainPresenterSample::OnSwipe(UISwipeView &view) -{ - UNUSED(view); - CardId cardId = view_->GetHorCurrentCard(); - SetTaskPeroid(cardId); - if (cardId == COMPASS) { - if (!isCompassSensorOpened_) { - CompassModel::GetInstance()->OpenCompassSensor(); - isCompassSensorOpened_ = true; + void MainPresenterSample::ResetgoalCardView() + { + if(goalControlView::GetInstance()) + { + auto goalSwipView = goalControlView::GetInstance()->GetGoalControlSwipView(); + if (goalSwipView->GetCurrentPage() != 0) + { + goalSwipView->SetCurrentPage(0); + } } - } else if (isCompassSensorOpened_) { - CompassModel::GetInstance()->CloseCompassSensor(); - isCompassSensorOpened_ = false; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe"); - return; -} + void MainPresenterSample::OnSwipe(UISwipeView &view) + { + // UNUSED(view); + /* -------------------------------------------------------------------------- */ + /* + * @brief 如果当前是下拉界面,先更新一次下拉窗口的数据包括,电池电量,时间,信号强度等等数据, + * 然后开启一个每2秒更新数据的定时器。 + * 如果不在下拉界面了停止定时器 + */ + if (MainViewSample::GetInstance()->IsPullUpViewPage() == PULLUP) { + if (!isPullDownPageView) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始下拉更新"); + isPullDownPageView = true; + UpdataBaseData(); + PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition(); + PullUpDown_StartTimer(2000); + } + } else if (MainViewSample::GetInstance()->IsPullUpViewPage() == DROPDOWN) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始上拉更新"); + isPullDownPageView = false; + PullUpDown_StopTimer(); + } else { + isPullDownPageView = false; + PullUpDown_StopTimer(); + } + /* -------------------------------------------------------------------------- */ -void MainPresenterSample::ProcessDataNotify(void) -{ - HealthMsg healthMsg; - uint16_t len; + CardId cardId = view_->GetHorCurrentCard(); + SetTaskPeroid(cardId); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe"); + return; + } - while ((HealthModel::GetInstance()->FetchedHealthData(&healthMsg))) { - switch (healthMsg.type) { + void MainPresenterSample::ProcessDataNotify(void) + { + HealthMsg healthMsg; + uint16_t len; + + while ((HealthModel::GetInstance()->FetchedHealthData(&healthMsg) == true)) + { + switch (healthMsg.type) + { case BATTERY_LIFE: break; default: break; + } } } -} -void MainPresenterSample::SetCircleProgress() -{ - PlayersView *playersView = dynamic_cast(view_->GetViewById(MUSIC_PLAYER)); - if (playersView == nullptr) { - return; + void MainPresenterSample::SetCircleProgress() + { + #if 0 + PlayersView *playersView = dynamic_cast(view_->GetViewById(MUSIC_PLAYER)); + if (playersView == nullptr) + { + return; + } + UICircleProgress *playbackProgress = playersView->GetPlaybackProgress(); + if (playbackProgress == nullptr) + { + return; + } + if(PlayersModel::GetInstance()->GetMusicSource() == false) { + int32_t playerState; + PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); + state_ = playersView->GetPlayerButtonState(); + if ((playerState != PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::SELECTED)) + { + playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); + } + else if ((playerState == PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::UNSELECTED)) + { + playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); + } + } + if (state_ == UICheckBox::UICheckBoxState::SELECTED) + { + PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_); + PlayersModel::GetInstance()->GetDuration(playerMusicDuration_); + if (playerMusicDuration_ != 0) + { + playerProgressValue_ = (playerCurrentTime_ * PROGRESS_PERCENTAGE) / playerMusicDuration_; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_); + } + else + { + playerProgressValue_ = 100; // 100: max progress value + } + PlayersModel::GetInstance()->SetCircleProgress(playerProgressValue_); + PlayersPresenter::GetInstance()->SetPlaybackProgress(playerProgressValue_); + } + #endif } - UICircleProgress *playbackProgress = playersView->GetPlaybackProgress(); - if (playbackProgress == nullptr) { - return; + + void MainPresenterSample::SetCompassRotate() + { + bool status = CompassModel::GetInstance()->GetCalibrationStatus(); + dynamic_cast(view_->GetViewById(COMPASS))->SetCalibrationView(status); + if (!status) + { + DetermineToRotate(); + } } - int32_t playerState; - PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState); - state_ = playersView->GetPlayerButtonState(); - if ((playerState != PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::SELECTED)) { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED); - } else if ((playerState == PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::UNSELECTED)) { - playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED); - } - if (state_ == UICheckBox::UICheckBoxState::SELECTED) { - PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_); - PlayersModel::GetInstance()->GetDuration(playerMusicDuration_); - if (playerMusicDuration_ != 0) { - playerProgressValue_ = (playerCurrentTime_ * PROGRESS_PERCENTAGE) / playerMusicDuration_; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_); - } else { - playerProgressValue_ = 100; // 100: max progress value - } - PlayersModel::GetInstance()->SetCircleProgress(playerProgressValue_); - PlayersPresenter::GetInstance()->SetPlaybackProgress(playerProgressValue_); + + // 滑动到指南针卡片开启指南针传感器 + void MainPresenterSample::OpenCompassSensor(void) + { + if (!isCompassSensorOpened_) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OpenCompassSensor"); + isCompassSensorOpened_ = true; + CompassModel::GetInstance()->OpenCompassSensor(); + ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); //滑动到指南针页面时开启屏幕常亮 + } } -} + // 关闭指南针传感器 + void MainPresenterSample::CloseCompassSensor(void) + { + if(isCompassSensorOpened_) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CloseCompassSensor"); + isCompassSensorOpened_ = false; + CompassModel::GetInstance()->CloseCompassSensor(); + ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); //滑动到指南针页面时取消屏幕常亮 + } + } + /* --------------------------------- 主界面卡片功能 -------------------------------- */ + void MainPresenterSample::Notify(void) + { + CardId currentCardId = view_->GetHorCurrentCard(); + + // 从心率卡片变为其他卡片时关闭心率检测 + if (previousCardId == HEART_RATE && currentCardId != HEART_RATE) + { + LogCardTransition(previousCardId, currentCardId); + // HeartModel::GetInstance()->Heart_Stop(); + // HeartModel::GetInstance()->Heart_Control(HeartState::End,HeartCheck::CARDCHECK); //主动检测心率 + } + // 从指南针卡片跳转到其他卡片时切换到关闭长亮屏 + if (previousCardId == COMPASS && currentCardId != COMPASS) + { + CloseCompassSensor(); + } -void MainPresenterSample::SetCompassRotate() -{ - bool status = CompassModel::GetInstance()->GetCalibrationStatus(); - dynamic_cast(view_->GetViewById(COMPASS))->SetCalibrationView(status); - if (!status) { - DetermineToRotate(); + // 从睡眠卡片跳转到其他卡片时切换到睡眠卡片主界面 + if (previousCardId == SLEEP && currentCardId != SLEEP) + { + LogCardTransition(previousCardId, currentCardId); + ResetSleepCardView(); + } + if (previousCardId == WEATHER && currentCardId != WEATHER) + { + LogCardTransition(previousCardId, currentCardId); + ResetWeatherCardView(); + } + if (previousCardId == GOAL && currentCardId != GOAL) + { + LogCardTransition(previousCardId, currentCardId); + ResetgoalCardView(); + } + + + // 更新上一个卡片的值 + previousCardId = currentCardId; + + switch (currentCardId) + { + case HEART_RATE: + StartHeartRateDetection(); + break; + + case COMPASS: + OpenCompassSensor(); + SetCompassRotate(); + break; + + case MUSIC_PLAYER: + // PlayersModel::GetInstance()->SetCircleProgress(); + break; + + case WATCH_FACE: + UpdateWatchFace(); + break; + + case WEATHER: + UpdateWeather(); + break; + + case GOAL: + // Updategoal(); + break; + + case SLEEP: + UpdateSleep(); + break; + + } + } + /*打印日志*/ + void MainPresenterSample::LogCardTransition(CardId previous, CardId current) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[MainCard slide]previousCardId:%d cardId:%d", previous, current); + } + /*睡眠卡片*/ + void MainPresenterSample::ResetSleepCardView() + { + // if (SleepCardView::GetInstance() != nullptr) + // { + // auto sleepCardView = SleepCardView::GetInstance()->GetSleepCardView(); + // if (sleepCardView->GetCurrentPage() != 0) + // { + // sleepCardView->SetCurrentPage(0); + // } + // } + + // SleepModel::GetInstance().msg_save_sleep_data(); + } + /*天气卡片*/ + void MainPresenterSample::ResetWeatherCardView() + { + if(WeatherControlView::GetInstance()) + { + auto weatherSwipView = WeatherControlView::GetInstance()->GetWeatherSwipView(); + if (weatherSwipView->GetCurrentPage() != 0) + { + weatherSwipView->SetCurrentPage(0); + } + } } -} -void MainPresenterSample::Notify(void) -{ - CardId cardId = view_->GetHorCurrentCard(); - if (cardId == COMPASS) { - SetCompassRotate(); - } else if (cardId == MUSIC_PLAYER) { - SetCircleProgress(); - } else if (cardId == WATCH_FACE) { + + /*心率卡片*/ + void MainPresenterSample::StartHeartRateDetection() + { + // HeartModel::GetInstance()->Heart_Control(HeartState::End, HeartCheck::PASSIVITY); +#if HEART_RATE_CHECK_TIMEOUT + HeartModel::GetInstance()->Heart_Control(HeartState::Start,HeartCheck::CARDCHECK); +#else + // HeartModel::GetInstance()->Heart_Start(HeartCheck::CARDCHECK); +#endif + } + /*主表盘*/ + void MainPresenterSample::UpdateWatchFace() + { DialSetting &setting = GetDialSetting(); - if (setting.dialFlag) { + if (setting.dialFlag) + { DialModelTime::GetInstance()->UpdateTime(); - DialViewGroup* group = dynamic_cast(view_->GetViewById(WATCH_FACE)); - if (group != nullptr) { - group->UpdateViewsByPeriodicUpdateData(); + dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData(); + } + else + { + dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateTime(); + } + } + + void MainPresenterSample::Updategoal() + { + if(GoalView::GetInstance()) + { + GoalView::GetInstance()->GoalViewrefresh(); + } + if(GoalotherView::GetInstance()) + { + GoalotherView::GetInstance()->GoalViewrefresh(); + } + } + + /*睡眠*/ + void MainPresenterSample::UpdateSleep() + { + // GraphicService::GetInstance()->PostGraphicEvent( + // std::bind(&OHOS::SleepModel::UpdateSleepView, &OHOS::SleepModel::GetInstance())); + } + + /*天气*/ + void MainPresenterSample::UpdateWeather() + { + if (WeatherModel::GetInstance().GetWeatherDataIsValid()) + { + WeatherModel::GetInstance().UpdateWeatherCurTime(); + } + } + /* -------------------------------------------------------------------------- */ + void MainPresenterSample::InitCardSettings(void) + { + MainModel::GetInstance().InitCardSettings(); + } + + uint8_t MainPresenterSample::GetCardSettingCount(void) + { + return MainModel::GetInstance().GetCardSettingCount(); + } + + CardId *MainPresenterSample::GetCardSettings(void) + { + return MainModel::GetInstance().GetCardSettings(); + } + + void MainPresenterSample::InitDialSettings(void) + { + return MainModel::GetInstance().InitDialSettings(); + } + DialSetting &MainPresenterSample::GetDialSetting() + { + return MainModel::GetInstance().GetDialSetting(); + } + + static const char *weekDays_ch[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; + static const char *weekDays_other[] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"}; + uint32_t MainPresenterSample::GetWeekStr(char *p_week) + { + time_t currtime; + struct tm *timeinfo; + time(&currtime); + timeinfo = localtime(&currtime); + + // 获取星期信息 + int language = ConfigModel::GetInstance()->GetLanguage(); + if (language == 0) + { + strcpy(p_week, weekDays_ch[timeinfo->tm_wday]); + } + else + { + strcpy(p_week, weekDays_other[timeinfo->tm_wday]); + } + + return ERRCODE_SUCC; // 假设成功获取星期信息 + } + + void MainPresenterSample::UpdataBaseData() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdataBaseData"); + // 解析日期信息 + char *dateStr = (char *)malloc(9); + if (uapi_get_YYMMDD_Time(dateStr, '/') != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start date"); + free(dateStr); + return; + } + // 获取当前时间 + char *timeStr = (char *)malloc(9); + if (uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start time"); + free(dateStr); + free(timeStr); + return; + } + // 解析星期信息 + char *weekStr = (char *)malloc(10); + if (GetWeekStr(weekStr) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get week information"); + free(dateStr); + free(timeStr); + free(weekStr); + return; + } + + // 获取电池电量信息 + float voltage = 0.0F; + uint8_t value = 0; + // value = battery_get_voltage(&voltage); + value = 0; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "battery_get_voltage = %d", value); + std::string dateAndweek = std::string(dateStr) + " " + std::string(weekStr); + if (PullUpDownView::GetInstance() != nullptr) + { + PullUpDownView::GetInstance()->GetProgress()->SetValue(value); + PullUpDownView::GetInstance()->GetDateAndWeekLabel()->SetText(dateAndweek.c_str()); + } + + // 释放动态分配的内存 + free(dateStr); + free(timeStr); + free(weekStr); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ALLData are refresh!\n"); + } + void MainPresenterSample::get_memcheck() + { + MemCheck::GetInstance()->DumpMemInfo(); + } + /* -------------------------------------------------------------------------- */ + // 声明定时器变量 + static osTimerId_t g_timer = nullptr; + static uint8_t UPDATETIME = 20; // 20秒 + uint8_t MainPresenterSample::g_PullUpDownTimes = UPDATETIME; + + /*定时器到期时的处理*/ + static void PullUpDown_TimerCallbackProc(int data) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDown_TimerCallbackProc"); + if (uapi_get_screen_state() == 1) // 息屏状态下若停留在下拉界面,20s后无操作停止更新数据 + { + MainPresenterSample::g_PullUpDownTimes -= 2; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", MainPresenterSample::g_PullUpDownTimes); + if (MainPresenterSample::g_PullUpDownTimes <= 0) { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&MainPresenterSample::PullUpDown_StopTimer, MainPresenterSample::GetInstance())); } - } else { - MainClockView* clock = dynamic_cast(view_->GetViewById(WATCH_FACE)); - if (clock != nullptr) { - clock->UpdateTime(); + } + else //亮屏状态下每2s刷新一次下拉数据 + { + if (PullUpDownView::GetInstance() != nullptr) + { + PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition(); } + if (MainPresenterSample::g_PullUpDownTimes != UPDATETIME) // 如果是亮屏后息屏再亮屏(此时息屏时间没超过 UPDATETIME)则恢复 + MainPresenterSample::g_PullUpDownTimes = UPDATETIME; } + return; } -} -void MainPresenterSample::InitCardSettings(void) -{ - MainModel::GetInstance().InitCardSettings(); -} + /* + * @brief 回调函数 + */ + static void PullUpDown_TimerCallback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(PullUpDown_TimerCallbackProc, data)); + } -uint8_t MainPresenterSample::GetCardSettingCount(void) -{ - return MainModel::GetInstance().GetCardSettingCount(); -} + /* + * @brief 开启定时器函数 + * @param interval 时间间隔,单位ms + */ + void MainPresenterSample::PullUpDown_StartTimer(uint32_t interval) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer"); + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_timer != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer already exists!!"); + return; + } -CardId *MainPresenterSample::GetCardSettings(void) -{ - return MainModel::GetInstance().GetCardSettings(); -} + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_timer = osTimerNew((osTimerFunc_t)PullUpDown_TimerCallback, osTimerPeriodic, nullptr, nullptr); + // 检查定时器创建是否成功 + if (g_timer == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer create failed!!"); + return; + } -void MainPresenterSample::InitDialSettings(void) -{ - return MainModel::GetInstance().InitDialSettings(); -} -DialSetting& MainPresenterSample::GetDialSetting() -{ - return MainModel::GetInstance().GetDialSetting(); -} + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + /* --------------------------------- 4.启动定时器 -------------------------------- */ + osStatus_t ret = osTimerStart(g_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PullUpDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret); + if (g_timer != nullptr) + { + ret = osTimerDelete(g_timer); + } + g_timer = nullptr; + return; + } + return; + } -bool MainPresenterSample::IsFromSetCardView(void) const -{ - return MainModel::GetInstance().IsFromSetCardView(); -} + /* + * @brief 停止定时器 + */ + void MainPresenterSample::PullUpDown_StopTimer(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StopTimer"); + // 检查定时器是否存在 + if (g_timer != nullptr) + { + osTimerStop(g_timer); + // 删除定时器并置为 nullptr + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_timer stop success"); + } + } -void MainPresenterSample::SetFromSetCardView(bool isFrom) -{ - MainModel::GetInstance().SetFromSetCardView(isFrom); -} + bool MainPresenterSample::IsFromSetCardView(void) const + { + return MainModel::GetInstance().IsFromSetCardView(); + } -uint8_t MainPresenterSample::GetFromCardId(void) -{ - return MainModel::GetInstance().GetFromCardId(); -} + void MainPresenterSample::SetFromSetCardView(bool isFrom) + { + MainModel::GetInstance().SetFromSetCardView(isFrom); + } + + uint8_t MainPresenterSample::GetFromCardId(void) + { + return MainModel::GetInstance().GetFromCardId(); + } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainViewSample.cpp index fa88864aa..ffdfe0456 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainViewSample.cpp @@ -7,348 +7,621 @@ #include "wearable_log.h" #include "MainViewSample.h" #include "graphic_service.h" +// #include "dialupdate/include/DialUpdateModel.h" +#include "uicomponents/UIComponents.h" +#include "ui_service.h" +// extern DialInfo_1 dialInfo_1[MAX_DIALNUM_1]; -namespace OHOS { -static MainViewSample *g_pMainView = nullptr; -static constexpr uint16_t MESLABLE_X_TMP = 177; -static constexpr uint16_t MESLABLE_Y_TMP = 212; -static constexpr uint16_t MESLABLE_WIDTH_TMP = 100; -static constexpr uint16_t MESLABLE_HEIGHT_TMP = 30; -static constexpr uint8_t FONT_SIZE_TMP = 24; -static constexpr uint8_t PULL_MIDDLE_VIEW_OPA = 0; - -struct MainViewMapper { - CardId id; - UICardPage *(MainViewSample::*func)(void); -}; - -static const MainViewMapper CardMapper[] = { - {WATCH_FACE, &MainViewSample::InitWatchFacePage}, - {HEART_RATE, &MainViewSample::InitHeartRatePage}, - {COMPASS, &MainViewSample::InitCompassPage}, - // {ACTIVITY, &MainViewSample::InitActivityPage}, - {MUSIC_PLAYER, &MainViewSample::InitMusicPlayerPage}, -}; - -MainViewSample::MainViewSample() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::MainViewSample"); - g_pMainView = this; -} +extern "C" uint8_t uapi_dev_runtime_get_lock_status(void); -MainViewSample::~MainViewSample() +namespace OHOS { - dropDownView->ClearBackgroundBlur(); - messageView->ClearBackgroundBlur(); - - for (int32_t i = 0; i < MAX_CARD; i++) { - recordCard[i] = nullptr; - pageStatus[i] = false; - } - - if (mainSwipeGroup != nullptr) { - delete mainSwipeGroup; - mainSwipeGroup = nullptr; - } - - if (mainClockView != nullptr) { - delete mainClockView; - mainClockView = nullptr; - } - if (activityWeekView != nullptr) { - delete activityWeekView; - activityWeekView = nullptr; + static MainViewSample *g_pMainView = nullptr; + static constexpr uint16_t MESLABLE_X_TMP = 177; + static constexpr uint16_t MESLABLE_Y_TMP = 212; + static constexpr uint16_t MESLABLE_WIDTH_TMP = 100; + static constexpr uint16_t MESLABLE_HEIGHT_TMP = 30; + static constexpr uint8_t FONT_SIZE_TMP = 24; + static constexpr uint8_t PULL_MIDDLE_VIEW_OPA = 0; + +#define DIALSTATE 1 + + struct MainViewMapper + { + CardId id; + UICardPage *(MainViewSample::*func)(void); + }; + // 严格按照Id对应 + static const MainViewMapper CardMapper[] = { + {WATCH_FACE, &MainViewSample::InitWatchFacePage}, + // {HEART_RATE, &MainViewSample::InitHeartRatePage}, + {TRAINING, &MainViewSample::InitTrainingPage}, + {COMPASS, &MainViewSample::InitCompassPage}, + // {SLEEP, &MainViewSample::InitSleepPage}, + // {BLOODOXGEN, &MainViewSample::InitBloodOxygenPage}, + {GOAL, &MainViewSample::InitGoalPage}, + {WEATHER, &MainViewSample::InitWeatherPage}, + {MUSIC_PLAYER, &MainViewSample::InitMusicPlayerPage}, + {SETCARD, &MainViewSample::InitSetMainPage}, + +#if 0 + {ACTIVITY, &MainViewSample::InitActivityPage}, +#endif + }; + MainViewSample::MainViewSample() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::MainViewSample"); + g_pMainView = this; } - if (playersView != nullptr) { - delete playersView; - playersView = nullptr; - } - - if (heartRateView != nullptr) { - delete heartRateView; - heartRateView = nullptr; - } + MainViewSample::~MainViewSample() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainViewSample::~MainViewSample"); + mainSwipeGroup->RemoveAll(); - if (dropDownView != nullptr) { - delete dropDownView; - dropDownView = nullptr; - } + for (int32_t i = 0; i < MAX_CARD; i++) + { + recordCard[i] = nullptr; + pageStatus[i] = false; + } + if (activityWeekView != nullptr) + { + activityWeekView->RemoveAll(); + delete activityWeekView; + activityWeekView = nullptr; + } - if (messageView != nullptr) { - messageView->RemoveAll(); - delete messageView; - messageView = nullptr; - } + if (playersView != nullptr) + { + playersView->RemoveAll(); + delete playersView; + playersView = nullptr; + } - if (messageLable != nullptr) { - delete messageLable; - messageLable = nullptr; - } + // if (heartRateView != nullptr) + // { + // heartRateView->RemoveAll(); + // delete heartRateView; + // heartRateView = nullptr; + // } + if (dropDownView != nullptr) + { + dropDownView->ClearBackgroundBlur(); + delete dropDownView; + dropDownView = nullptr; + } - if (compassControlView != nullptr) { - delete compassControlView; - compassControlView = nullptr; + if (activityWeekView != nullptr) + { + activityWeekView->RemoveAll(); + delete activityWeekView; + activityWeekView = nullptr; + } + // if (messageView != nullptr) + // { + // messageView->ClearBackgroundBlur(); + // messageView->RemoveAll(); + // delete messageView; + // messageView = nullptr; + // } + // if (MessageLable != nullptr) + // { + // delete MessageLable; + // MessageLable = nullptr; + // } + // if (dialstateicon != nullptr) + // { + // mainClockView->Remove(dialstateicon); + // delete dialstateicon; + // dialstateicon = nullptr; + // } + // if (messageicon != nullptr) + // { + // mainClockView->Remove(messageicon); + // delete messageicon; + // messageicon = nullptr; + // } + if (compassControlView != nullptr) + { + compassControlView->RemoveAll(); + delete compassControlView; + compassControlView = nullptr; + } + if (mainClockView != nullptr) + { + mainClockView->RemoveAll(); + delete mainClockView; + mainClockView = nullptr; + } + // if (bloodView != nullptr) + // { + // bloodView->RemoveAll(); + // delete bloodView; + // bloodView = nullptr; + // } + if (setmainView != nullptr) + { + setmainView->RemoveAll(); + delete setmainView; + setmainView = nullptr; + } + // if (sleepView != nullptr) + // { + // sleepView->RemoveAll(); + // delete sleepView; + // sleepView = nullptr; + // } + // if (traingView != nullptr) + // { + // traingView->RemoveAll(); + // delete traingView; + // traingView = nullptr; + // } + if (weatherControlView != nullptr) + { + delete weatherControlView; + weatherControlView = nullptr; + } + if (GoalControlView != nullptr) + { + GoalControlView->RemoveAll(); + delete GoalControlView; + GoalControlView = nullptr; + } + // if (applistCardView != nullptr) + // { + // delete applistCardView; + // applistCardView = nullptr; + // } + if (mainSwipeGroup != nullptr) + { + delete mainSwipeGroup; + mainSwipeGroup = nullptr; + } + if (callback != nullptr) + { + delete callback; + callback = nullptr; + } + g_pMainView = nullptr; } - - if (callback != nullptr) { - delete callback; - callback = nullptr; + MainViewSample *MainViewSample::GetInstance(void) + { + return g_pMainView; } - g_pMainView = nullptr; -} + void MainViewSample::OnStart() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainViewSample::OnStart"); -MainViewSample *MainViewSample::GetInstance(void) -{ - return g_pMainView; -} + if (mainSwipeGroup == nullptr) { + mainSwipeGroup = new UICrossView(); + if (mainSwipeGroup == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSwipeGroup new fail"); + return; + } + } -void MainViewSample::OnStart() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::OnStart"); - View::OnStart(); + // UIView::OnDragListener *listener = static_cast(MainPresenterSample::GetInstance()); + // if (listener == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmSetWeekView:: new alarmDragListener fail"); + // return; + // } + // mainSwipeGroup->SetOnDragListener(listener); + + if (callback == nullptr) + { + callback = new ZoomEffect(); + if (callback == nullptr) + { + delete mainSwipeGroup; + mainSwipeGroup = nullptr; + GRAPHIC_LOGE("SwipeCallback new fail\n"); + return; + } + } + callback->isNeedClip_ = true; + callback->SetContainer(mainSwipeGroup); + HorizontalViewInit(); + HorViewLoad(); + VerticalViewInit(); // 初始化上下拉界面 + VertViewLoad(); // 添加上下拉界面 + mainSwipeGroup->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + mainSwipeGroup->SetAnimatorTime(50); + mainSwipeGroup->SetLoopState(false); // 主界面循环 + mainSwipeGroup->EnableScreenCap(true); // 主界面截屏滑动 + mainSwipeGroup->RegisterSwipeCallback(callback); // 主界面动画回调 + // /*密码锁上锁*/ + // if (uapi_dev_runtime_get_lock_status()) + // { + // // 回到表盘 + // SwitchToClockPage(); + // // printf("密码锁\r\n"); + // mainClockView->SetIntercept(true); + // mainSwipeGroup->SetDraggable(false); + // mainSwipeGroup->SetOnSwipeListener(nullptr); + // mainSwipeGroup->SetOnClickListener(presenter_); + // } + // else + // { + // 判断是否为从主界面前往的其他Slice + if (presenter_->IsFromSetCardView()) + { + // 回退标志位 + presenter_->SetFromSetCardView(false); + // 设置Id为主界面显示索引 + SwitchToCard(presenter_->GetFromCardId()); + } + else + { + // 回到表盘 + SwitchToClockPage(); + } + // } - mainSwipeGroup = new UICrossView(); - if (mainSwipeGroup == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSwipeGroup new fail"); - return; + AddViewToRootContainer(mainSwipeGroup); } - if (callback == nullptr) { - callback = new ZoomEffect(); - if (callback == nullptr) { - delete mainSwipeGroup; - mainSwipeGroup = nullptr; - GRAPHIC_LOGE("SwipeCallback new fail\n"); - return; + void MainViewSample::UpdateStateShow() { + DialSetting &setting = presenter_->GetDialSetting(); + //离线表盘 + if (setting.dialFlag) { + if (mainClockView != nullptr) { + // dynamic_cast(mainClockView)->UpdateStateShow(); + } + } + //在线表盘 + else { + if (mainClockView != nullptr) { + dynamic_cast(mainClockView)->UpdateStateShow(); + } + } } - callback->SetContainer(mainSwipeGroup); - - HorizontalViewInit(); - HorViewLoad(); - VerticalViewInit(); - VertViewLoad(); - mainSwipeGroup->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - mainSwipeGroup->SetAnimatorTime(50); // 50: animator drag time(ms); - mainSwipeGroup->SetLoopState(true); - mainSwipeGroup->EnableScreenCap(true); - mainSwipeGroup->RegisterSwipeCallback(callback); - if (presenter_->IsFromSetCardView()) { - presenter_->SetFromSetCardView(false); - SwitchToCard(presenter_->GetFromCardId(), false); - } else { - SwitchToClockPage(false); - } - AddViewToRootContainer(mainSwipeGroup); -} - -bool MainViewSample::HorizontalViewInit(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::HorizontalViewInit"); - presenter_->InitDialSettings(); - presenter_->InitCardSettings(); - uint8_t cardSettingNum = presenter_->GetCardSettingCount(); - CardId *cardSettings = presenter_->GetCardSettings(); - uint8_t cardMapNumber = sizeof(CardMapper) / sizeof(CardMapper[0]); - for (int16_t i = 0; i < cardSettingNum; i++) { - for (uint8_t j = 0; j < cardMapNumber; j++) { - if (cardSettings[i] == CardMapper[j].id) { - recordCard[j] = (this->*(CardMapper[j].func))(); - if (recordCard[j] == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "MainViewSample:: recordCard %d error", j); - return false; + + bool MainViewSample::HorizontalViewInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::HorizontalViewInit"); + /*读取kvstore里面的配置*/ + presenter_->InitDialSettings(); + presenter_->InitCardSettings(); + uint8_t cardSettingNum = presenter_->GetCardSettingCount(); + CardId *cardSettings = presenter_->GetCardSettings(); + uint8_t cardMapNumber = sizeof(CardMapper) / sizeof(CardMapper[0]); + for (int16_t i = 0; i < cardSettingNum; i++) + { + for (uint8_t j = 0; j < cardMapNumber; j++) + { + if (cardSettings[i] == CardMapper[j].id) + { + recordCard[j] = (this->*(CardMapper[j].func))(); + if (recordCard[j] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MainViewSample:: recordCard %d error", j); + return false; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "MainViewSample:: recordCard[%d]:%p", j, recordCard[j]); + break; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "MainViewSample:: recordCard[%d]:%p", j, recordCard[j]); - break; } } + + mainSwipeGroup->SetOnSwipeListener(presenter_); + mainSwipeGroup->SetOnLongPressListener(presenter_); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitPage over"); + return true; } - mainSwipeGroup->SetOnSwipeListener(presenter_); - mainSwipeGroup->SetOnLongPressListener(presenter_); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitPage over"); - return true; -} -void MainViewSample::HorViewLoad(void) -{ - uint8_t cardSettingNum = presenter_->GetCardSettingCount(); - CardId *cardSettings = presenter_->GetCardSettings(); - for (int16_t i = 0; i < cardSettingNum; i++) { - CardId cardId = cardSettings[i]; - if (recordCard[cardId] != nullptr) { - mainSwipeGroup->HorAdd(recordCard[cardId]); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample:: HorViewLoad cardid = %d ViewIndex = %d", - cardId, recordCard[cardId]->GetViewIndex()); + void MainViewSample::HorViewLoad(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::HorViewLoad"); + uint8_t cardSettingNum = presenter_->GetCardSettingCount(); + CardId *cardSettings = presenter_->GetCardSettings(); + for (int16_t i = 0; i < cardSettingNum; i++) + { + CardId cardId = cardSettings[i]; + if (recordCard[cardId] != nullptr) + { + mainSwipeGroup->HorAdd(recordCard[cardId]); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample:: HorViewLoad cardid = %d ViewIndex = %d", + cardId, recordCard[cardId]->GetViewIndex()); + } } } -} -void MainViewSample::VerticalViewInit(void) -{ - dropDownView = new PullUpDownView(); - if (dropDownView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dropDownView new fail"); - return; + void MainViewSample::VerticalViewInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::VerticalViewInit"); +#ifdef FD230 + if (dropDownView == nullptr) { + dropDownView = new PullUpDownView(); + if (dropDownView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dropDownView new fail"); + return; + } + } + dropDownView->PreLoad(); + dropDownView->SetViewId("dropDownView"); + dropDownView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + dropDownView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + /* -------------------------------------------------------------------------- */ + // if (messageView == nullptr) { + // messageView = new MessageControlView(); + // if (messageView == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageView new fail"); + // return; + // } + // } + + // messageView->SetViewId("messageView"); + // messageView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + // messageView->PreLoad(); + // messageView->SetDraggable(false); + // // messageView->SetIntercept(true); + // messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); +#endif } - dropDownView->PreLoad(); - dropDownView->SetViewId("dropDownView"); - dropDownView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - dropDownView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - - messageView = new UICardPage(); - if (messageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageView new fail"); - return; + + PullUpDownView *MainViewSample::GetPullUpView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::GetPullUpView"); + return dropDownView; } - messageView->SetPosition(0, 0); - messageView->SetWidth(Screen::GetInstance().GetWidth()); - messageView->SetHeight(Screen::GetInstance().GetHeight()); - messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - messageView->SetViewId("messageView"); - messageView->SetTouchable(true); - messageView->SetIntercept(true); - messageLable = new UILabel(); - if (messageLable == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLable new fail"); - return; + + void MainViewSample::VertViewLoad(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::VertViewLoad"); + mainSwipeGroup->VerAdd(dropDownView, UICrossView::VPage::UP_PAGE); + // mainSwipeGroup->VerAdd(messageView, UICrossView::VPage::DOWN_PAGE); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::PullViewLoad::Pull View Load complete"); } - messageLable->SetPosition(MESLABLE_X_TMP, MESLABLE_Y_TMP, MESLABLE_WIDTH_TMP, MESLABLE_HEIGHT_TMP); - messageLable->SetText("无消息"); - messageLable->SetAlign(TEXT_ALIGNMENT_CENTER); - messageLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_SIZE_TMP); - messageLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - messageView->Add(messageLable); -} + + UICardPage *MainViewSample::InitWatchOffDial(DialSetting &setting) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitWathOffDial"); + DialViewGroup *dial = new DialViewGroup(); + dial->SetDial(setting.dialFullName); + // dial->SetDial(DEFAULT_DIAL_PATH); + return dial; + } + /*初始化自定义表盘*/ + UICardPage *MainViewSample::InitWatchDial(DialSetting &setting) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitWathDial"); + + MainClockView *clock = new MainClockView(); + clock->SetCustomId(setting.dialId); + return clock; + } + UICardPage *MainViewSample::InitWatchFacePage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitWatchFacePage"); + DialSetting &setting = presenter_->GetDialSetting(); + if (setting.dialFlag) + { + mainClockView = InitWatchOffDial(setting); + } + else + { + mainClockView = InitWatchDial(setting); + } + if (mainClockView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); + return nullptr; + } -void MainViewSample::VertViewLoad(void) -{ - mainSwipeGroup->VerAdd(dropDownView, UICrossView::VPage::UP_PAGE); - mainSwipeGroup->VerAdd(messageView, UICrossView::VPage::DOWN_PAGE); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::PullViewLoad::Pull View Load complete"); -} + mainClockView->SetViewId("mainClockView"); + return mainClockView; + } + // 指南针卡片 + UICardPage *MainViewSample::InitCompassPage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitCompassPage"); + compassControlView = new CompassControlView(); + if (compassControlView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "compassControlView new fail"); + return nullptr; + } + return compassControlView; + } + // 音乐卡片 + UICardPage *MainViewSample::InitMusicPlayerPage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitMusicPlayerPage"); + playersView = new PlayersView(); + if (playersView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView new fail"); + return nullptr; + } + return playersView; + } -void MainViewSample::OnStop() -{ - messageView->RemoveAll(); - return; -} + // 主界面血氧卡片 + UICardPage *MainViewSample::InitBloodOxygenPage(void) + { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitBloodOxygenPage"); + // bloodView = new BloodCardView(); + // if (bloodView == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView new fail"); + // return nullptr; + // } + // return bloodView; + return nullptr; + } -UICardPage *MainViewSample::InitWatchOffDial(DialSetting &setting) -{ - DialViewGroup *dial = new DialViewGroup(); - dial->SetDial(setting.dialFullName); - return dial; -} + // 主界面训练卡片 + UICardPage *MainViewSample::InitTrainingPage(void) + { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitTrainingPage"); + // traingView = new Training_CardView(); + // if (traingView == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "traingView new fail"); + // return nullptr; + // } + // return traingView; + return nullptr; + } -UICardPage *MainViewSample::InitWatchDial(DialSetting &setting) -{ - switch (setting.dialId) { - case DIAL_CLOCK: - return new MainClockView(); - default: + // 主界面天气卡片 + UICardPage *MainViewSample::InitWeatherPage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitWeatherPage"); + weatherControlView = new WeatherControlView(); + if (weatherControlView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherControlView new fail"); return nullptr; + } + return weatherControlView; } -} -UICardPage *MainViewSample::InitWatchFacePage(void) -{ - DialSetting &setting = presenter_->GetDialSetting(); - if (setting.dialFlag) { - mainClockView = InitWatchOffDial(setting); - } else { - mainClockView = InitWatchDial(setting); + // 主界面每日目标卡片 + UICardPage *MainViewSample::InitGoalPage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitGoalPage"); + GoalControlView = new goalControlView(); + if (GoalControlView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalControlView new fail"); + return nullptr; + } + return GoalControlView; } - if (mainClockView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); - return nullptr; + // 主界面心率卡片 + UICardPage *MainViewSample::InitHeartRatePage(void){ + // { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitHeartRatePage"); + // heartRateView = new HeartRateCardView(); + // if (heartRateView == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateView new fail"); + // return nullptr; + // } + // return heartRateView; + return nullptr; } - return mainClockView; -} -UICardPage *MainViewSample::InitHeartRatePage(void) -{ - heartRateView = new HeartRateView(); - if (heartRateView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateView new fail"); - return nullptr; + // 主界面运动卡片 + UICardPage *MainViewSample::InitActivityPage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitActivityPage"); + activityWeekView = new ActivityWeekView(); + if (activityWeekView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "activityWeekView new fail"); + return nullptr; + } + return activityWeekView; } - return heartRateView; -} -UICardPage *MainViewSample::InitActivityPage(void) -{ - activityWeekView = new ActivityWeekView(); - if (activityWeekView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "activityWeekView new fail"); - return nullptr; + /*主界面设置卡片*/ + UICardPage *MainViewSample::InitSetMainPage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitSetMainPage"); + setmainView = new SetMainView(); + if (setmainView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "setmainView new fail"); + return nullptr; + } + return setmainView; } - return activityWeekView; -} -UICardPage *MainViewSample::InitCompassPage(void) -{ - compassControlView = new CompassControlView(); - if (compassControlView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "compassControlView new fail"); + /*主界面睡眠卡片*/ + UICardPage *MainViewSample::InitSleepPage(void) + { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitSetMainPage"); + // sleepView = new SleepCardView(); + // if (sleepView == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepView new fail"); + // return nullptr; + // } + // return sleepView; return nullptr; } - return compassControlView; -} -UICardPage *MainViewSample::InitMusicPlayerPage(void) -{ - playersView = new PlayersView(); - if (playersView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView new fail"); - return nullptr; + void MainViewSample::SetPage(int16_t page, bool loadAdjacent) + { + if (mainSwipeGroup != nullptr) { + mainSwipeGroup->SetHorCurrentPage(page, loadAdjacent); + } + + if (presenter_ != nullptr) { + CardId *cardSettings = presenter_->GetCardSettings(); + /* page 与CardId 没有对应关系,需要一次转换 */ + presenter_->SetTaskPeroid(cardSettings[page]); + } } - return playersView; -} -void MainViewSample::SetPage(int16_t page, bool loadAdjacent) -{ - if (mainSwipeGroup != nullptr) { - mainSwipeGroup->SetHorCurrentPage(page, loadAdjacent); + bool MainViewSample::IsMainClockPage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::IsMainClockPage"); + if (mainSwipeGroup->GetCurrentPageId(0) == mainClockView->GetViewIndex() && + mainSwipeGroup->GetCurrentPageId(1) == 1) + { // 0: horizontal; 1: vertical + return true; + } + else + { + return false; + } } - - if (presenter_ != nullptr) { + int MainViewSample::IsPullUpViewPage(void) { + //主界面->下拉界面 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::IsPullUpViewPage"); + if (mainSwipeGroup->GetCurrentPageId(0) == mainClockView->GetViewIndex() && + mainSwipeGroup->GetCurrentPageId(1) == 0) + { + return PULLUP; + } + //主界面->上拉界面 + else if(mainSwipeGroup->GetCurrentPageId(0) == mainClockView->GetViewIndex() && + mainSwipeGroup->GetCurrentPageId(1) == 2) + { + return DROPDOWN; + } + //其他狀態 + return UNKOWNPAG; + } + CardId MainViewSample::GetHorCurrentCard() const + { CardId *cardSettings = presenter_->GetCardSettings(); - /* page 与CardId 没有对应关系,需要一次转换 */ - presenter_->SetTaskPeroid(cardSettings[page]); + int pageId = mainSwipeGroup->GetCurrentPageId(UISwipeView::HORIZONTAL); // 0: horizontal; 1: vertical + /* pageId 与CardId 没有对应关系,需要一次转换 */ + return cardSettings[pageId]; } -} -bool MainViewSample::IsMainClockPage(void) -{ - if (mainSwipeGroup->GetCurrentPageId(0) == mainClockView->GetViewIndex() && - mainSwipeGroup->GetCurrentPageId(1) == 1) { // 0: horizontal; 1: vertical - return true; - } else { - return false; + void MainViewSample::SwitchToCard(uint8_t cardId) + { + if ((cardId < MAX_CARD) && (recordCard[cardId] != nullptr)) + { + SetPage(recordCard[cardId]->GetViewIndex()); + } + else + { + SwitchToClockPage(); + } } -} - -CardId MainViewSample::GetHorCurrentCard() const -{ - CardId *cardSettings = presenter_->GetCardSettings(); - int pageId = mainSwipeGroup->GetCurrentPageId(UISwipeView::HORIZONTAL); // 0: horizontal; 1: vertical - /* pageId 与CardId 没有对应关系,需要一次转换 */ - return cardSettings[pageId]; -} -void MainViewSample::SwitchToCard(uint8_t cardId, bool loadAdjacent) -{ - if ((cardId < MAX_CARD) && (recordCard[cardId] != nullptr)) { - SetPage(recordCard[cardId]->GetViewIndex(), loadAdjacent); - } else { - SwitchToClockPage(loadAdjacent); + void MainViewSample::HandOnKeyEventSwitchMainPullDownView(void) + { + if(dropDownView) + { + dropDownView->HandOnKeyEventSwitchMainPullDownView(); + } } } - -} diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/PullUpDownView.cpp index a55c3ea7c..c6606f156 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/PullUpDownView.cpp @@ -894,7 +894,8 @@ namespace OHOS return; } - bool isCharging = get_charge_stat(); // 获取充电状态 + // bool isCharging = get_charge_stat(); // 获取充电状态 + bool isCharging = true; if (isCharging) {