From: Caisking <3449750381@qq.com> Date: Mon, 25 Mar 2024 07:08:10 +0000 (+0800) Subject: 增加省电模式UI以及接口 X-Git-Tag: release_V1.2.70_20241020_135402~1269 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=7211e0ddc8e8748c652716b852c6f3ca872ded1a;p=mirrors%2FFD230.git 增加省电模式UI以及接口 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 2eab1065d..502c61547 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -445,6 +445,13 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traingrecord/src/TraingRecordView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traingrecord/src/TraingRecordPresenter.cpp + #saveele + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/saveele/src/SaveEleModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/saveele/src/SaveElePresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/saveele/src/SaveEleView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/saveele/src/SaveBatPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/saveele/src/SaveBatView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phone/src/PhoneView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phone/src/PhonePresenter.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index eb0165092..d9ad7187f 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -63,13 +63,15 @@ typedef enum : uint16_t VIEW_ROTATE, // 模拟表冠 VIEW_BLOODOXY, // 血氧饱和度界面 VIEW_HEART, // 心率监测 + VIEW_SAVEELE, // 省电模式 + VIEW_SAVEBAT, // 省电模式界面 /* ----------------------------------- 训练 ----------------------------------- */ VIEW_TRAINING, // 训练 VIEW_TRAININGMORE, // 更多训练 + VIEW_RUNNING, // 跑步训练之列表 VIEW_TRAININGLIMIT, // 极限运动子列表 VIEW_TRAININGNOMAL, // 正常训练开始界面(除骑行,健走,跑步外) VIEW_TRAININGSET, // 训练目标(时长,卡路里) - VIEW_TRAININGGPSSET, // GPS训练目标(时长,距离,卡路里,步数) VIEW_TRAININGSETTIME, // 设置训练时长 VIEW_TRAININGSETCALULI, // 设置训练卡路里 VIEW_TRAININGSETDIST, // 设置训练路程 @@ -81,14 +83,16 @@ typedef enum : uint16_t VIEW_TRAININGENDNOTE, // 结束训练提醒 VIEW_TRAININGENDNOTE2, // 结束训练时间太短 VIEW_TRAININGENDDATA, // 训练结束详细数据 - VIEW_TRAININGGPS, // GPS训练 - VIEW_TRAININGGPSLACK, // 缺少GPS - VIEW_TRAININGGPSNOTE, // 连接GPS提醒 VIEW_TRAININGSTRONG, // 训练强度介绍 - VIEW_TRAININGGPSLOST, // GPS断联 - VIEW_TRAININGGPSBACK, // GPS回连 VIEW_TRAININGWIN, // 目标达成 VIEW_TRAINING_RECORD, // 训练记录 + /* ---------------------------------- GPS训练 --------------------------------- */ + VIEW_TRAININGGPS, // GPS训练 + VIEW_TRAININGGPSSET, // GPS训练目标(时长,距离,卡路里,步数) + VIEW_TRAININGGPSLACK, // 缺少GPS + VIEW_TRAININGGPSNOTE, // 连接GPS提醒 + VIEW_TRAININGGPSLOST, // GPS断联 + VIEW_TRAININGGPSBACK, // GPS回连 /* -------------------------------------------------------------------------- */ VIEW_MAIN_TEMP, // 体温界面(暂时不用) VIEW_OFFLINEVOICE, // 语音助手界面(暂时不用) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 8f3d529ec..242eb4f2c 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -48,12 +48,14 @@ namespace OHOS void InitDisplayBrightnessSlice(void); /* --------------------------------- 经典蓝牙界面 --------------------------------- */ void InitClassicBluetoothSlice(void); - /* --------------------------------测试界面------------------------------------ */ + /* --------------------------------界面------------------------------------ */ void InitRotateSlice(void); void InitBloodSlice(void); void InitHeartSlice(void); void InitMainAlipaySlice(void); void InitDialUpdateSlice(void); + void InitSaveEleSlice(void); + void InitSaveBatSlice(void); /* ----------------------------------- 训练 ----------------------------------- */ void InitTraingSlice(void); void InitTraingMoreSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index a21030900..81e4f026d 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -133,6 +133,11 @@ #include "producttest/include/testPresenter.h" #include "producttest/include/testView.h" +#include "saveele/include/SaveEleView.h" +#include "saveele/include/SaveElePresenter.h" +#include "saveele/include/SaveBatView.h" +#include "saveele/include/SaveBatPresenter.h" + /* -------------------------------------------------------------------------- */ #include "traing/include/TraingView.h" #include "traing/include/TraingPresenter.h" @@ -246,7 +251,9 @@ namespace OHOS {VIEW_PHONERING, &NativeLauncher::InitPhoneRingSlice}, {VIEW_TEST, &NativeLauncher::InittestSlice}, - + /* ---------------------------------- 省电模式 ---------------------------------- */ + {VIEW_SAVEELE, &NativeLauncher::InitSaveEleSlice}, + {VIEW_SAVEBAT, &NativeLauncher::InitSaveBatSlice}, /* ----------------------------------- 训练 ----------------------------------- */ {VIEW_TRAINING, &NativeLauncher::InitTraingSlice}, // 训练 {VIEW_TRAININGMORE, &NativeLauncher::InitTraingMoreSlice}, // 更多训练 @@ -350,7 +357,7 @@ namespace OHOS RebootModel::GetInstance()->RegisterLongPressEvents(); // 开机检测充电状态 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Power is %d",get_charge_stat()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Power is %d", get_charge_stat()); if (get_charge_stat()) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Power is Charging!"); @@ -971,4 +978,29 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAINING_RECORD, traingrecordview); } /* -------------------------------------------------------------------------- */ + + // 省电模式 + void NativeLauncher::InitSaveEleSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSaveEleSlice"); + SliceProxy *saveeleview = new AbilitySliceProxy; + if (saveeleview == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "saveeleview"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SAVEELE, saveeleview); + } + + void NativeLauncher::InitSaveBatSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSaveBatSlice"); + SliceProxy *savebatview = new AbilitySliceProxy; + if (savebatview == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "savebatview"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SAVEBAT, savebatview); + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp index 149ca8f27..cc03023bc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp @@ -21,16 +21,16 @@ namespace OHOS { const AppItem g_nativeAppList[] = { {VIEW_MAIN_ALARM, PNG_APPLIST_ALARM_IMAGE, PNG_APPLIST_ALARM_IMAGE, "闹钟", nullptr}, - {VIEW_BLOODOXY, PNG_APPLIST_SPO2_IMAGE, PNG_APPLIST_SPO2_IMAGE, "血氧饱和度", nullptr}, + {VIEW_SETTING, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_SETTING_IMAGE, "设置", nullptr}, + {VIEW_DIALUPDATE, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_UI_SAMPLE_IMAGE, "表盘切换", nullptr}, {VIEW_COMPASS, PNG_APPLIST_COMPASS_IMAGE, PNG_APPLIST_COMPASS_IMAGE, "指南针", nullptr}, + {VIEW_BLOODOXY, PNG_APPLIST_SPO2_IMAGE, PNG_APPLIST_SPO2_IMAGE, "血氧饱和度", nullptr}, + {VIEW_HEART, PNG_APPLIST_HEART_IMAGE, PNG_APPLIST_HEART_IMAGE, "心率检测", nullptr}, {VIEW_INDOORWALK, PNG_APPLIST_WALK_IMAGE, PNG_APPLIST_WALK_IMAGE, "室内步行", nullptr}, {VIEW_WEATHER, PNG_APPLIST_WEATHER_IMAGE, PNG_APPLIST_WEATHER_IMAGE, "天气", nullptr}, {VIEW_TRAINING, PNG_APPLIST_TRAINING_IMAGE, PNG_APPLIST_TRAINING_IMAGE, "体能训练", nullptr}, {VIEW_TRAINING_RECORD, PNG_APPLIST_TRAINING_RECORD_IMAGE, PNG_APPLIST_TRAINING_RECORD_IMAGE, "训练记录", nullptr}, - {VIEW_HEART, PNG_APPLIST_HEART_IMAGE, PNG_APPLIST_HEART_IMAGE, "心率检测", nullptr}, {VIEW_RECORD, PNG_APPLIST_RECORD_IMAGE, PNG_APPLIST_RECORD_IMAGE, "录音", nullptr}, - {VIEW_SETTING, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_SETTING_IMAGE, "设置", nullptr}, - {VIEW_DIALUPDATE, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_UI_SAMPLE_IMAGE, "表盘切换", nullptr}, {VIEW_CALLER_LOG, PNG_APPLIST_CALLLOG_IMAGE, PNG_APPLIST_CALLLOG_IMAGE, "通话记录", nullptr}, {VIEW_PHONE, PNG_APPLIST_CALLER_IMAGE, PNG_APPLIST_CALLER_IMAGE, "电话", nullptr}, #ifdef SUPPORT_ALIPAY_SEC diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp index 5b0af19dd..e5962e592 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -37,6 +37,7 @@ namespace OHOS map g_jumpView = { {DROPDOWN_CLICK_SETTING, VIEW_SETTING}, // 设置 {DROPDOWN_CLICK_BLUETOOTH, VIEW_CLASSIC_BLUETOOTH}, // 蓝牙 + {DROPDOWN_CLICK_SAVEELE, VIEW_SAVEELE}, // 省电模式 }; // map g_chanColor = { { DROPDOWN_CLICK_FINDMYPHONE, DROPDOWN_DROPDOWN_FIND_PHONE_B }, diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatPresenter.h new file mode 100644 index 000000000..8136c7555 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatPresenter.h @@ -0,0 +1,40 @@ + +#ifndef _SAVEBAT_PRESENTER_H +#define _SAVEBAT_PRESENTER_H + +#include "Presenter.h" +#include "SaveBatView.h" +#include "ModelListenerSample.h" + +namespace OHOS +{ + class SaveBatView; + + class SaveBatPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UIView::OnLongPressListener, + public ModelListenerSample + { + public: + SaveBatPresenter(); + virtual ~SaveBatPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static SaveBatPresenter *GetInstance(); + virtual void Notify() override; + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnLongPress(UIView &view, const LongPressEvent &event); + }; + +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h new file mode 100644 index 000000000..df762035d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h @@ -0,0 +1,62 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-25 11:15:36 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-25 14:31:53 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#ifndef _SAVEBAT_VIEW_H +#define _SAVEBAT_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_digital_clock.h" +#include "components/ui_box_progress.h" +#include "SaveBatPresenter.h" +#include + +namespace OHOS +{ + class SaveBatPresenter; + class SaveBatView : public View + { + + public: + SaveBatView(); + virtual ~SaveBatView(); + static SaveBatView *GetInstance(void); + void updateClock(); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + void Init(); + void DeInit(); + UIView *GetView(); + void RefreshView(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + + SaveBatView(SaveBatView &&) = delete; + SaveBatView &operator=(SaveBatView &&) = delete; + // UIViewGroup *container_ = nullptr; + UIDigitalClock *labelTime{nullptr}; + UILabel *timelabel = nullptr; // 时间 + UILabel *datelabel = nullptr; // 日期标签 + UILabel *weeklabel = nullptr; // 星期标签 + UILabel *elelabel = nullptr; // 电量标签 + UIBoxProgress *progress{nullptr}; // 电池进度条 + UIImageView *eleicon = nullptr; // 电池框图标 + UIButton *button_exit = nullptr; // 退出按键 + }; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleModel.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleModel.h new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveElePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveElePresenter.h new file mode 100644 index 000000000..2a3894e48 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveElePresenter.h @@ -0,0 +1,35 @@ +#ifndef _SAVEELE_PRESENTER_H +#define _SAVEELE_PRESENTER_H + + +#include "Presenter.h" +#include "SaveEleView.h" + +namespace OHOS +{ + class SaveEleView; + + class SaveElePresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + SaveElePresenter(); + virtual ~SaveElePresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static SaveElePresenter *GetInstance(); + + private: + //因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} //namespace OHOS + + +#endif //SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleView.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleView.h new file mode 100644 index 000000000..02a7630c9 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleView.h @@ -0,0 +1,56 @@ +#ifndef _SAVEELE_VIEW_H +#define _SAVEELE_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" + +#include "SaveElePresenter.h" +namespace OHOS +{ + class SaveElePresenter; + class SaveEleView : public View + { + + public: + SaveEleView(); + virtual ~SaveEleView(); + static SaveEleView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + void Init(); + void DeInit(); + UIView *GetView(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + + // void InitImage(void); + // void InitLable(void); + + // 以下控件属性通过new实例化后,add到对应root属性上; + // SaveEleView(constSaveEleView &) = delete; + // SaveEleView &operator=(constSaveEleView &) = delete; + SaveEleView(SaveEleView &&) = delete; + SaveEleView &operator=(SaveEleView &&) = delete; + + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + UIImageView *image2_ = nullptr; + UIImageView *image1_ = nullptr; + UILabel *label2_ = nullptr; + }; +} // namespace OHOS +#endif // SaveEle_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp new file mode 100644 index 000000000..27435868f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp @@ -0,0 +1,101 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-25 11:15:36 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-25 14:49:31 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-25 11:15:36 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-25 11:27:21 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include "saveele/include/SaveBatPresenter.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static SaveBatPresenter *g_pSaveBatPresenter = nullptr; + + SaveBatPresenter::SaveBatPresenter() + { + + g_pSaveBatPresenter = this; + } + + SaveBatPresenter::~SaveBatPresenter() + { + + g_pSaveBatPresenter = nullptr; + } + + SaveBatPresenter *SaveBatPresenter::GetInstance() + { + + return g_pSaveBatPresenter; + } + + void SaveBatPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void SaveBatPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void SaveBatPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void SaveBatPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool SaveBatPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + // 返回 true 以消耗拖动事件 + return true; + } + + bool SaveBatPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 执行点击事件的处理逻辑 + // 根据控件id查找是哪个控件触发了点击回调 + // if (strcmp(view.GetViewId(), 控件ID) == 0 + // 返回 true 以消耗点击事件 + + return true; + } + bool SaveBatPresenter::OnLongPress(UIView &view, const LongPressEvent &event) + { + // 1.长按三秒button1 + // 2.退出 button1NativeAbility::GetInstance().ChangeSlice(VIEW_SAVEELE); + // 3.返回 true 以消耗点击事件 + if (strcmp(view.GetViewId(), "button_exit") == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + } + return true; + } + void SaveBatPresenter::Notify(void) + { + SaveBatView::GetInstance()->RefreshView(); + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp new file mode 100644 index 000000000..4c5a733aa --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2023 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "saveele/include/SaveBatView.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include +#include +#include +#include "battery_hal.h" +#include "string" +namespace OHOS +{ + static SaveBatView *g_pSaveBatView{nullptr}; + std::string WeekString(int wday) + { + std::string weekDays[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; + return weekDays[wday]; + } + SaveBatView::SaveBatView() + { + g_pSaveBatView = this; + } + + SaveBatView::~SaveBatView() + { + DeInit(); + g_pSaveBatView = nullptr; + } + + SaveBatView *SaveBatView::GetInstance() + { + + return g_pSaveBatView; + } + void SaveBatView::RefreshView() + { + // 获取当前时间 + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + + // 解析时间 + int hour = pTM.tm_hour; + int minute = pTM.tm_min; + + // 构建日期字符串 + std::string yearStr = std::to_string(pTM.tm_year + 1900); + std::string monthStr = (pTM.tm_mon + 1 < 10) ? "0" + std::to_string(pTM.tm_mon + 1) : std::to_string(pTM.tm_mon + 1); + std::string weekStr = WeekString(pTM.tm_wday); + std::string dayStr = (pTM.tm_mday < 10) ? "0" + std::to_string(pTM.tm_mday) : std::to_string(pTM.tm_mday); + std::string dateStr = monthStr + "月" + dayStr + "日"; + + // 将时间和日期转换为字符串 + std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); + + // 获取电量值 + float voltage = 0.0F; + uint8_t value = 0; + value = battery_get_voltage(&voltage); + + // 更新界面组件 + timelabel->SetText(stringtime.c_str()); + datelabel->SetText(dateStr.c_str()); + weeklabel->SetText(weekStr.c_str()); + elelabel->SetText((std::to_string(value) + "%").c_str()); + progress->SetValue(value); + } + + void SaveBatView::Init() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + /* --------------------------------- 电池标签初始化 -------------------------------- */ + if (elelabel == nullptr) + { + elelabel = new UILabel(); + } + elelabel->SetPosition(239, 52); // widget's left position and top position + elelabel->Resize(200, 60); // widget's width and height + elelabel->SetViewId("label1"); // Set style + elelabel->SetStyle(STYLE_TEXT_FONT, 27); + elelabel->SetText("10%"); + elelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + elelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + elelabel->SetRollSpeed(0); + elelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 27); + container_->Add(elelabel); + elelabel->SetVisible(true); + /* -------------------------------- 电池框图标初始化 -------------------------------- */ + if (eleicon == nullptr) + { + eleicon = new UIImageView(); + } + eleicon->SetPosition(179, 52); // widget's left position and top position + eleicon->Resize(48, 30); // widget's width and height + eleicon->SetViewId("image7"); // Set style + // Set additional property + char *image7imagesPath = "/user/res/Save_Ele/Battery-E.bin"; + eleicon->SetSrc(image7imagesPath); + // Add to rootView + container_->Add(eleicon); + eleicon->SetVisible(true); + /* -------------------------------- 电池进度条初始化 -------------------------------- */ + // Add BoxProgress to App + if (progress == nullptr) + { + progress = new UIBoxProgress(); + } + progress->SetPosition(184, 58); // widget's left position and top position + progress->Resize(31, 19); // widget's width and height + progress->SetViewId("progress1"); // Set style + progress->SetValidHeight(19); + progress->SetValidWidth(31); + progress->SetValue(20); + // Set BackgroundStyle + progress->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x00); + progress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xff000000); + // Set ForegroundStyle + progress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6); + progress->SetForegroundStyle(STYLE_TEXT_COLOR, 0xff000000); + progress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff45A5FF); + char *progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin"; + char *progress1BackImageSrc = nullptr; + progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc); + // Add to rootView + container_->Add(progress); + /* --------------------------------- 时间标签初始化 -------------------------------- */ + // Add Label to App + if (timelabel == nullptr) + { + timelabel = new UILabel(); + } + timelabel->SetPosition(118, 148); // widget's left position and top position + timelabel->Resize(231, 115); // widget's width and height + timelabel->SetViewId("label2"); // Set style + timelabel->SetStyle(STYLE_TEXT_FONT, 100); + timelabel->SetStyle(STYLE_LINE_HEIGHT, 115); + // Set additional property + timelabel->SetText("23:59"); + timelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + timelabel->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + timelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timelabel->SetRollSpeed(0); + timelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 100); + // Add to rootView + container_->Add(timelabel); + timelabel->SetVisible(true); + /* --------------------------------- 日期标签初始化 -------------------------------- */ + // Add Label to App + if (datelabel == nullptr) + { + datelabel = new UILabel(); + } + datelabel->SetPosition(125, 268); // widget's left position and top position + datelabel->Resize(210, 35); // widget's width and height + datelabel->SetViewId("label3"); // Set style + datelabel->SetStyle(STYLE_TEXT_FONT, 30); + datelabel->SetStyle(STYLE_LETTER_SPACE, 2); + datelabel->SetStyle(STYLE_LINE_HEIGHT, 35); + // Set additional property + datelabel->SetText("11月3号"); + datelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + datelabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + datelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + datelabel->SetRollSpeed(0); + datelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // Add to rootView + container_->Add(datelabel); + datelabel->SetVisible(true); + + /* --------------------------------- 星期标签初始化 -------------------------------- */ + if (weeklabel == nullptr) + { + weeklabel = new UILabel(); + } + weeklabel->SetPosition(280, 268); // widget's left position and top position + weeklabel->Resize(280, 35); // widget's width and height + weeklabel->SetViewId("label3"); // Set style + weeklabel->SetStyle(STYLE_TEXT_FONT, 30); + weeklabel->SetStyle(STYLE_LETTER_SPACE, 2); + weeklabel->SetStyle(STYLE_LINE_HEIGHT, 35); + + // Set additional property + weeklabel->SetText("星期五"); + weeklabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + weeklabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + weeklabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + weeklabel->SetRollSpeed(0); + weeklabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // Add to rootView + container_->Add(weeklabel); + weeklabel->SetVisible(true); + + /* --------------------------------- 退出按键初始化 -------------------------------- */ + if (button_exit == nullptr) + { + button_exit = new UIButton(); + } + button_exit->SetPosition(204, 350); // widget's left position and top position + button_exit->Resize(60, 60); // widget's width and height + button_exit->SetViewId("button_exit"); // Set style + button_exit->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + button_exit->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + + // Set additional property + char *button1defaultImgSrc = "/user/res/Save_Ele/finger.bin"; + char *button1triggeredImgSrc = nullptr; + button_exit->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + button_exit->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnLongPressListener *button1LongPress = static_cast(SaveBatPresenter::GetInstance()); + button_exit->SetOnLongPressListener(button1LongPress); + // Add to rootView + container_->Add(button_exit); + button_exit->SetVisible(true); + } + + void SaveBatView::DeInit() + { + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (elelabel != nullptr) + { + delete elelabel; + elelabel = nullptr; + } + if (eleicon != nullptr) + { + delete eleicon; + eleicon = nullptr; + } + if (weeklabel != nullptr) + { + delete weeklabel; + weeklabel = nullptr; + } + if (timelabel != nullptr) + { + delete timelabel; + timelabel = nullptr; + } + if (datelabel != nullptr) + { + delete datelabel; + datelabel = nullptr; + } + if (button_exit != nullptr) + { + delete button_exit; + button_exit = nullptr; + } + } + + UIView *SaveBatView::GetView() + { + Init(); + return container_; + } + void SaveBatView::OnStart() + { + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + container_->SetPosition(0, 0); + container_->SetWidth(Screen::GetInstance().GetWidth()); + container_->SetHeight(Screen::GetInstance().GetHeight()); + container_->SetTouchable(true); + container_->SetDraggable(true); + + GetView(); + RootView::GetInstance()->Add(container_); + } + + void SaveBatView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void SaveBatView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void SaveBatView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleModel.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp new file mode 100644 index 000000000..da6f4d97e --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp @@ -0,0 +1,81 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include "saveele/include/SaveElePresenter.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static SaveElePresenter *g_pSaveElePresenter = nullptr; + + SaveElePresenter::SaveElePresenter() + { + + g_pSaveElePresenter = this; + } + + SaveElePresenter::~SaveElePresenter() + { + + g_pSaveElePresenter = nullptr; + } + + SaveElePresenter *SaveElePresenter::GetInstance() + { + + return g_pSaveElePresenter; + } + + void SaveElePresenter::OnStart() + { + + Presenter::OnStart(); + } + + void SaveElePresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void SaveElePresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void SaveElePresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool SaveElePresenter::OnDrag(UIView &view, const DragEvent &event) + { + + // if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + // { + // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + // } + UNUSED(view); + return true; + } + + bool SaveElePresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + // if (strcmp(view.GetViewId(), 控件ID) == 0) + if (strcmp(view.GetViewId(), "button1") == 0) + { + // NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + if (strcmp(view.GetViewId(), "button2") == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_SAVEBAT); + } + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleView.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleView.cpp new file mode 100644 index 000000000..39c6814a1 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleView.cpp @@ -0,0 +1,342 @@ + + +#include "saveele/include/SaveEleView.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include "components/ui_button.h" +namespace OHOS +{ + + static SaveEleView *g_pSaveEleView{nullptr}; + + SaveEleView::SaveEleView() + { + + g_pSaveEleView = this; + } + + SaveEleView::~SaveEleView() + { + DeInit(); + g_pSaveEleView = nullptr; + } + + SaveEleView *SaveEleView::GetInstance() + { + + return g_pSaveEleView; + } + + void SaveEleView::Init() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // Add ScrollView to App + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); // widget's left position and top position + scrollView1_->Resize(466, 466); // widget's width and height + scrollView1_->SetViewId("scrollView1"); // Set style + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + + // Set additional property + scrollView1_->SetDirection(1); + + // Add the CallBack about events + UIView::OnDragListener *scrollView1Drag = static_cast(SaveElePresenter::GetInstance()); + scrollView1_->SetOnDragListener(scrollView1Drag); + // Add to rootView + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + + // Add Label to App + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(173, 52); // widget's left position and top position + label1_->Resize(120, 35); // widget's width and height + label1_->SetViewId("label1"); // Set style + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_SPACE, 0); + label1_->SetStyle(STYLE_LETTER_SPACE, 1); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + + // Set additional property + label1_->SetText("省电模式"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + // Add to scrollView1 + scrollView1_->Add(label1_); + label1_->SetVisible(true); + + // Add Label to App + if (label3_ == nullptr) + { + label3_ = new UILabel(); + } + label3_->SetPosition(33, 440); // widget's left position and top position + label3_->Resize(200, 60); // widget's width and height + label3_->SetViewId("label3"); // Set style + label3_->SetStyle(STYLE_TEXT_FONT, 30); + label3_->SetStyle(STYLE_LINE_HEIGHT, 35); + + // Set additional property + label3_->SetText("长按屏幕3秒以上或充电可退\n出省电模式"); + label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label3_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xc3, 0x00, 0xff)); + label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label3_->SetRollSpeed(0); + label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + // Add to scrollView1 + scrollView1_->Add(label3_); + label3_->SetVisible(true); + + // Add Label to App + if (label4_ == nullptr) + { + label4_ = new UILabel(); + } + label4_->SetPosition(173, 547); // widget's left position and top position + label4_->Resize(400, 395); // widget's width and height + label4_->SetViewId("label4"); // Set style + label4_->SetStyle(STYLE_TEXT_FONT, 30); + label4_->SetStyle(STYLE_LINE_HEIGHT, 35); + + // Set additional property + label4_->SetText("是否开启"); + label4_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label4_->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + label4_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label4_->SetRollSpeed(0); + label4_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + // Add to scrollView1 + scrollView1_->Add(label4_); + label4_->SetVisible(true); + + // Add Button to App + if (button1_ == nullptr) + { + button1_ = new UIButton(); + } + button1_->SetPosition(110, 636); // widget's left position and top position + button1_->Resize(100, 100); // widget's width and height + button1_->SetViewId("button1"); // Set style + button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + + char *button1defaultImgSrc = "/user/res/Save_Ele/Save_Error.bin"; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffff1919, UIButton::PRESSED); + button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button1Click = static_cast(SaveElePresenter::GetInstance()); + button1_->SetOnClickListener(button1Click); + // Add to scrollView1 + scrollView1_->Add(button1_); + button1_->SetVisible(true); + + // Add Button to App + if (button2_ == nullptr) + { + button2_ = new UIButton(); + } + button2_->SetPosition(255, 636); // widget's left position and top position + button2_->Resize(100, 100); // widget's width and height + button2_->SetViewId("button2"); // Set style + button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + button2_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + + char *button2defaultImgSrc = "/user/res/Save_Ele/Save_Right.bin"; + char *button2triggeredImgSrc = nullptr; + button2_->SetImageSrc(button2defaultImgSrc, button2triggeredImgSrc); + button2_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff19ff5e, UIButton::PRESSED); + button2_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button2Click = static_cast(SaveElePresenter::GetInstance()); + button2_->SetOnClickListener(button2Click); + // Add to scrollView1 + scrollView1_->Add(button2_); + button2_->SetVisible(true); + + // Add ImageView to App + if (image2_ == nullptr) + { + image2_ = new UIImageView(); + } + image2_->SetPosition(183, 775); // widget's left position and top position + image2_->Resize(100, 100); // widget's width and height + image2_->SetViewId("image2"); // Set style + + // Set additional property + + // Add to scrollView1 + scrollView1_->Add(image2_); + image2_->SetVisible(true); + + // Add ImageView to App + if (image1_ == nullptr) + { + image1_ = new UIImageView(); + } + image1_->SetPosition(188, 121); // widget's left position and top position + image1_->Resize(90, 90); // widget's width and height + image1_->SetViewId("image1"); // Set style + + // Set additional property + char *image1imagesPath = "/user/res/Save_Ele/SaveEle.bin"; + image1_->SetSrc(image1imagesPath); + + // Add to scrollView1 + scrollView1_->Add(image1_); + image1_->SetVisible(true); + + // Add Label to App + if (label2_ == nullptr) + { + label2_ = new UILabel(); + } + label2_->SetPosition(33, 217); // widget's left position and top position + label2_->Resize(400, 395); // widget's width and height + label2_->SetViewId("label2"); // Set style + label2_->SetStyle(STYLE_TEXT_FONT, 30); + label2_->SetStyle(STYLE_LINE_HEIGHT, 35); + + // Set additional property + label2_->SetText("开启省电模式会关闭非必要的\n蓝牙连接(通话/耳机蓝牙),以\n及传感器监测(心率监测及血\n氧监测等会停止)等功能\n 仅保留时间日期可查看"); + label2_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label2_->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + label2_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label2_->SetRollSpeed(0); + label2_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + // Add to scrollView1 + scrollView1_->Add(label2_); + label2_->SetVisible(true); + } + + void SaveEleView::DeInit() + { + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (label3_ != nullptr) + { + delete label3_; + label3_ = nullptr; + } + if (label4_ != nullptr) + { + delete label4_; + label4_ = nullptr; + } + if (button1_ != nullptr) + { + delete button1_; + button1_ = nullptr; + } + if (button2_ != nullptr) + { + delete button2_; + button2_ = nullptr; + } + if (image2_ != nullptr) + { + delete image2_; + image2_ = nullptr; + } + if (image1_ != nullptr) + { + delete image1_; + image1_ = nullptr; + } + if (label2_ != nullptr) + { + delete label2_; + label2_ = nullptr; + } + } + + UIView *SaveEleView::GetView() + { + Init(); + return container_; + } + void SaveEleView::OnStart() + { + container_ = new UIScrollView(); + if (container_ == nullptr) + { + return; + } + container_->SetPosition(0, 0); + container_->SetWidth(Screen::GetInstance().GetWidth()); + container_->SetHeight(Screen::GetInstance().GetHeight() * 2); + + // 创建 draglistener 实例并设置为拖动监听器 + UIView::OnDragListener *draglistener = static_cast(SaveElePresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + GetView(); + RootView::GetInstance()->Add(container_); + } + + void SaveEleView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void SaveEleView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void SaveEleView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp b/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp index 16fc77fe1..1a98c4c2e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp @@ -13,88 +13,102 @@ #include "ui_screennotify.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -static uint32_t g_back_to_home_interval = 5; + static uint32_t g_back_to_home_interval = 5; -// 需要屏蔽掉的slice,ignore_slice_ids数组中的slice灭屏超时后不会调转到默认界面 -uint16_t ignore_slice_ids[] = { - VIEW_INVALID, - VIEW_SETTING, - VIEW_UISAMPLE, - VIEW_BLOODOXY,//血氧功能 + // 需要屏蔽掉的slice,ignore_slice_ids数组中的slice灭屏超时后不会调转到默认界面 + uint16_t ignore_slice_ids[] = { + VIEW_INVALID, + VIEW_SETTING, + VIEW_UISAMPLE, + VIEW_BLOODOXY, // 血氧功能 + VIEW_HEART, // 心率检测 + VIEW_SAVEBAT, // 省电模式 #ifdef SUPPORT_ALIPAY_SEC - VIEW_MAIN_ALIPAY, + VIEW_MAIN_ALIPAY, #endif -}; + }; -static std::list g_callback; + static std::list g_callback; -static void ChangeToHomeView(void) -{ - screen_context_t *sc = power_display_get_screen_context(); - uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId(); - for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) { - if (ignore_slice_ids[i] == current_slice_id) { - return; + static void ChangeToHomeView(void) + { + screen_context_t *sc = power_display_get_screen_context(); + uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId(); + for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) + { + if (ignore_slice_ids[i] == current_slice_id) + { + return; + } } - } - if (sc->screen_off_time_interval > g_back_to_home_interval) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "screen off time = %u", - sc->screen_off_time_interval); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetNativeAbilityState = %u", - OHOS::NativeAbility::GetInstance().GetNativeAbilityState()); - if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) { - if (current_slice_id != VIEW_MAIN) { // 主表盘 - OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - } else { - // if (!OHOS::MainViewSample::GetInstance()->IsMainClockPage()) { + if (sc->screen_off_time_interval > g_back_to_home_interval) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "screen off time = %u", + sc->screen_off_time_interval); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetNativeAbilityState = %u", + OHOS::NativeAbility::GetInstance().GetNativeAbilityState()); + if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) + { + if (current_slice_id != VIEW_MAIN) + { // 主表盘 + OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + } + else + { + // if (!OHOS::MainViewSample::GetInstance()->IsMainClockPage()) { // 当前页面为主表盘的其他页面时,切换回主表盘页面 // OHOS::MainViewSample::GetInstance()->SwitchToClockPage(); - // } + // } + } } } } -} -void notify_screen_on_event(void) -{ - for (auto callback : g_callback) { - callback(SCREEN_STATUS_ON); + void notify_screen_on_event(void) + { + for (auto callback : g_callback) + { + callback(SCREEN_STATUS_ON); + } + GraphicService::GetInstance()->PostGraphicEvent(ChangeToHomeView); } - GraphicService::GetInstance()->PostGraphicEvent(ChangeToHomeView); -} -void notify_screen_off_event(void) -{ - for (auto callback : g_callback) { - callback(SCREEN_STATUS_OFF); + void notify_screen_off_event(void) + { + for (auto callback : g_callback) + { + callback(SCREEN_STATUS_OFF); + } } -} -void set_back_to_home_interval(uint32_t time_sec) -{ - g_back_to_home_interval = time_sec; -} + void set_back_to_home_interval(uint32_t time_sec) + { + g_back_to_home_interval = time_sec; + } -uint32_t get_back_to_home_interval(void) -{ - return g_back_to_home_interval; -} + uint32_t get_back_to_home_interval(void) + { + return g_back_to_home_interval; + } -void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback) -{ - if (callback != nullptr) { - g_callback.push_back(callback); + void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback) + { + if (callback != nullptr) + { + g_callback.push_back(callback); + } } -} -void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback) -{ - if (callback != nullptr) { - g_callback.remove(callback); + void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback) + { + if (callback != nullptr) + { + g_callback.remove(callback); + } } -} #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingMusicView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingMusicView.h new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingPresenter.h index 012eeffb2..4bfeb011a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingPresenter.h @@ -2,7 +2,7 @@ * @Author: Caisking 3449750381@qq.com * @Date: 2024-03-19 18:18:30 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-03-22 15:24:40 + * @LastEditTime: 2024-03-25 10:26:23 * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/include/TraingPresenter.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataPresenter.cpp index 5004cffe6..52c7ec1f4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataPresenter.cpp @@ -1,3 +1,11 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-19 17:37:19 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-25 10:15:08 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataPresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ #include "AppViewIDs.h" #include "NativeAbility.h" @@ -54,8 +62,7 @@ namespace OHOS bool TraingDataPresenter::OnDragEnd(UIView &view, const DragEvent &event) { - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCONTROL); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataView.cpp index 659715f28..87832a024 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataView.cpp @@ -132,7 +132,7 @@ namespace OHOS InitImageView(image2_, 208, 297, 20, 20, "image2", ARROWS_IMAGE); InitImageView(image3_, 98, 314, 270, 20, "image3", SPORT_STRENGTH_IMAGE); InitImageView(image4_, 225, 396, 16, 10, "image4", INCO_UP_IMAGE); - InitImageView(image5_, 193, 421, 80, 20, "image5", CONTROL_POINT_IMAGE); + InitImageView(image5_, 193, 421, 80, 20, "image5", DATA_POINT_IMAGE); container_->Add(image1_); container_->Add(image2_); container_->Add(image3_); diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingGPSnotePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingGPSnotePresenter.cpp index b9c2babbc..02cb274ce 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingGPSnotePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingGPSnotePresenter.cpp @@ -1,3 +1,11 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-19 17:37:19 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-25 09:46:15 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/src/TraingGPSnotePresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ #include "AppViewIDs.h" #include "NativeAbility.h" @@ -61,8 +69,7 @@ namespace OHOS bool TraingGPSnotePresenter::OnDragEnd(UIView &view, const DragEvent &event) { - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); NativeAbility::GetInstance().ChangeSlice(preSlice); diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingGPSsetPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingGPSsetPresenter.cpp index 66f8f029c..7a9f8484a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingGPSsetPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingGPSsetPresenter.cpp @@ -61,8 +61,7 @@ namespace OHOS bool TraingGPSsetPresenter::OnDragEnd(UIView &view, const DragEvent &event) { - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGGPS); diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingLimitPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingLimitPresenter.cpp index e2cd6a6a3..ea9e62540 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingLimitPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingLimitPresenter.cpp @@ -1,4 +1,4 @@ -/*** +/*** * @Author: Caisking 3449750381@qq.com * @Date: 2024-03-19 17:37:19 * @LastEditors: Caisking 3449750381@qq.com @@ -69,8 +69,7 @@ namespace OHOS bool TraingLimitPresenter::OnDragEnd(UIView &view, const DragEvent &event) { - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 30) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMorePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMorePresenter.cpp index 9a533312b..0f64db9ee 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMorePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMorePresenter.cpp @@ -73,7 +73,10 @@ namespace OHOS // MainViewSample::GetInstance()->SetPage(CardId::TRAINING); return true; } - NativeAbility::GetInstance().ChangeSlice(preSlice); + else + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING); + } } UNUSED(view); return true; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMusicPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMusicPresenter.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMusicView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMusicView.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalPresenter.cpp index 2ec62105f..6ec1cdeeb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalPresenter.cpp @@ -1,3 +1,11 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-19 17:37:19 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-25 09:56:37 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalPresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ #include "AppViewIDs.h" #include "NativeAbility.h" @@ -60,16 +68,21 @@ namespace OHOS } bool TraingNomalPresenter::OnDragEnd(UIView &view, const DragEvent &event) { - - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Id:[%d]", preSlice); - if (preSlice == VIEW_MAIN) + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - // MainViewSample::GetInstance()->SetPage(CardId::TRAINING); - return true; + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Id:[%d]", preSlice); + if (preSlice == VIEW_MAIN) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + // MainViewSample::GetInstance()->SetPage(CardId::TRAINING); + return true; + } + else + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGLIMIT); + } } - NativeAbility::GetInstance().ChangeSlice(preSlice); UNUSED(view); return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingStrongPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingStrongPresenter.cpp index 9e3bdbf7f..6bac03e5d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingStrongPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingStrongPresenter.cpp @@ -1,3 +1,10 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-19 17:37:20 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-25 09:43:53 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/src/TraingStrongPresenter.cpp + */ #include "AppViewIDs.h" #include "NativeAbility.h" @@ -61,8 +68,7 @@ namespace OHOS bool TraingStrongPresenter::OnDragEnd(UIView &view, const DragEvent &event) { - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDATA); } diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Battery-E.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Battery-E.bin new file mode 100644 index 000000000..f6fe312e4 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Battery-E.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Battery-F.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Battery-F.bin new file mode 100644 index 000000000..7b3c3a859 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Battery-F.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/SaveEle.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/SaveEle.bin new file mode 100644 index 000000000..59d8ed98a Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/SaveEle.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Save_Error.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Save_Error.bin new file mode 100644 index 000000000..fb89e49c2 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Save_Error.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Save_Right.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Save_Right.bin new file mode 100644 index 000000000..2e1463050 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/Save_Right.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/finger.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/finger.bin new file mode 100644 index 000000000..9cbfbac9d Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/finger.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/finger2.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/finger2.bin new file mode 100644 index 000000000..b08089fff Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/finger2.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/wathch.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/wathch.bin new file mode 100644 index 000000000..7ae6bf2ac Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Save_Ele/wathch.bin differ