From cfadbf708569185c214ea5eaf12cf4bc86f0b99d Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 26 Mar 2025 11:49:01 +0800 Subject: [PATCH] =?utf8?q?=E6=97=A5=E7=A8=8Bslice=E5=90=88=E5=B9=B6?= =?utf8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativelauncher/include/AppViewIDs.h | 2 +- .../nativeui/schedule/include/ScheduleData.h | 54 ++ .../schedule/include/ScheduleListAdapter.h | 32 + .../schedule/include/ScheduleListItem.h | 62 ++ .../nativeui/schedule/include/ScheduleModel.h | 56 ++ .../schedule/include/SchedulePresenter.h | 42 + .../nativeui/schedule/include/ScheduleView.h | 129 +++ .../schedule/src/ScheduleListAdapter.cpp | 88 ++ .../schedule/src/ScheduleListItem.cpp | 157 ++++ .../nativeui/schedule/src/ScheduleModel.cpp | 299 +++++++ .../schedule/src/SchedulePresenter.cpp | 159 ++++ .../nativeui/schedule/src/ScheduleView.cpp | 802 ++++++++++++++++++ 12 files changed, 1881 insertions(+), 1 deletion(-) create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleData.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleListAdapter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleListItem.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleModel.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/SchedulePresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleListAdapter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleListItem.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleModel.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/SchedulePresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleView.cpp diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/AppViewIDs.h index cf9d61579..96c027d17 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/AppViewIDs.h @@ -119,7 +119,7 @@ typedef enum : uint16_t VIEW_DIALING_METHOD, // 拨号方式 VIEW_TEST, // 测试 VIEW_CALCULATOR, // 计算器 - VIEW_SCHEDULE, // schedule + VIEW_SCHEDULE, // 日程 VIEW_SLEEPMODE, // sleep mode VIEW_SET_DESKTOP, // 设置主题 /*屏蔽Slice*/ diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleData.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleData.h new file mode 100644 index 000000000..72e7a26b2 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleData.h @@ -0,0 +1,54 @@ + +#ifndef __SCHEDULEDATA_H__ +#define __SCHEDULEDATA_H__ + +// #include "ohos_types.h" +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +// namespace OHOS +// { + #define SCHEDULE_DATA_FILE "/user/userdata/scheduleData.bin" + #define SCHEDULE_DATA_DIRECTORY "/user/userdata/" + + #define SCHEDULE_DATE_STR_MAX (8) + #define SCHEDULE_TOPIC_STR_MAX (64) + #define SCHEDULE_TIME_STR_MAX (16) + #define SCHEDULE_CONTENT_STR_MAX (256) + + typedef struct + { + char date[SCHEDULE_DATE_STR_MAX]; + char topic[SCHEDULE_TOPIC_STR_MAX]; + char time[SCHEDULE_TIME_STR_MAX]; + char content[SCHEDULE_CONTENT_STR_MAX]; + }C_ScheduleRevData; + + typedef struct + { + std::string date; // 7/8 + std::string topic; // xxxx + std::string time; //10:30-14:00 + std::string content; // yyyyyyy + }ScheduleRevData; + + #define SCHEDULE_DATA_COUNT_MAX (20) + + void C_ScheduleSetByApp(ScheduleRevData * data, uint8_t index, bool is_finish); + int C_ScheduleDataReadFromFile(void); + int C_ScheduleDataWriteToFile(void); +// } + + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleListAdapter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleListAdapter.h new file mode 100644 index 000000000..e60be8630 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleListAdapter.h @@ -0,0 +1,32 @@ + +#ifndef __SCHEDULELISTADAPTER_H__ +#define __SCHEDULELISTADAPTER_H__ + +#include "View.h" +#include "components/abstract_adapter.h" +#include "schedule/include/ScheduleModel.h" +#include "schedule/include/ScheduleListItem.h" + + +namespace OHOS +{ + class ScheduleListAdapter : public AbstractAdapter + { + public: + ScheduleListAdapter(); + ~ScheduleListAdapter() override; + ScheduleListAdapter * GetInstance(); + + UIView * GetView(UIView * inView, int16_t index) override; + uint16_t GetCount() override; + void AddListItem(const ScheduleListItemInfo &item); + void ClearListItem(void); + + void SetItemClickListener(UIView::OnClickListener *itemClickListener); + + private: + List nodeList_; + UIView::OnClickListener * itemClickListener_; + }; +} +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleListItem.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleListItem.h new file mode 100644 index 000000000..3a3c125fd --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleListItem.h @@ -0,0 +1,62 @@ + +#ifndef __SCHEDULELISTITEM_H__ +#define __SCHEDULELISTITEM_H__ + +#include "View.h" +#include "ohos_types.h" +#include "components/ui_view_group.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" + + +namespace OHOS +{ + typedef struct + { + std::string DateStr; + std::string TopicStr; + std::string TimeStr; + std::string ContentStr; + uint8_t OriginalDataIndex; + bool IsDateItem; + uint8_t ChildIndex; // if(false == IsDateItem) + } ScheduleListItemInfo; + + + class ScheduleListItem : public UIViewGroup + { + public: + ScheduleListItem(); + ~ScheduleListItem() override; + void SetItemInfo(const ScheduleListItemInfo &itemInfo); + void ResetItemStyle(const ScheduleListItemInfo &itemInfo); + void ResetHeight(bool val); + + + private: + ScheduleListItem(const ScheduleListItem &); + ScheduleListItem &operator = (const ScheduleListItem &); + + UIViewGroup InfoGroup_; + UILabelExt LabelExtDate_; + UILabelExt LabelExtTopic_; + UILabelExt LabelExtTime_; + UIImageView Image_; + // ScheduleListItemInfo itemInfo_ = { nullptr, nullptr, nullptr, nullptr, 0 }; + + #define ITEM_WIDTH (380) + #define ITEM_HEIGHT (100) + #define ITEM_GAP (20) + + #define ODD_ITEM_BACKGROUND_COLOR (0Xff001833) + #define ODD_ITEM_TOPIC_COLOR (0Xff0176ff) + #define ODD_ITEM_TIME_COLOR (0Xff8bc0ff) + + #define EVEN_ITEM_BACKGROUND_COLOR (0Xff331f00) + #define EVEN_ITEM_TOPIC_COLOR (0Xffff7b01) + #define EVEN_ITEM_TIME_COLOR (0Xffffc28b) + + #define IMAGE_ITEM_ARROW "/user/res/Schedule/IMAGE_ITEM_ARROW.bin" + }; +} +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleModel.h new file mode 100644 index 000000000..3e028f7e5 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleModel.h @@ -0,0 +1,56 @@ + +#ifndef __SCHEDULEMODEL_H__ +#define __SCHEDULEMODEL_H__ + +#include "ohos_types.h" +#include "schedule/include/ScheduleListItem.h" +#include "schedule/include/ScheduleData.h" + + +namespace OHOS +{ + class ScheduleModel + { + public: + static ScheduleModel &GetInstance(void); + + ScheduleListItemInfo * ScheduleAllItemDataGet(void); + uint8_t ScheduleItemDataCountGet(void); + uint8_t ScheduleOriginalDataCountGet(void); + + std::string ScheduleItemDataDateStrGet(uint8_t index); + std::string ScheduleItemDataTopicStrGet(uint8_t index); + std::string ScheduleItemDataTimeStrGet(uint8_t index); + std::string ScheduleItemDataContentStrGet(uint8_t index); + uint8_t ScheduleItemDataOriginalDataIndexGet(uint8_t index); + + void ScheduleOriginalDataSetByApp(ScheduleRevData * data, uint8_t index, bool is_finish); + void ScheduleOriginalDataSetByUI(uint8_t index); + + int ScheduleDataReadFromFile(void); + int ScheduleDataWriteToFile(void); + + void DataStringToCharArray(void); + void DataCharArrayToString(uint8_t DataCount); + + private: + ScheduleModel(); + ~ScheduleModel(); + ScheduleModel(const ScheduleModel &) = delete; + ScheduleModel &operator=(const ScheduleModel &) = delete; + + void ScheduleItemDataCountSet(uint8_t count); + void ScheduleOriginalDataCountSet(uint8_t count); + void ScheduleOriginalDataToItemData(uint8_t DataCount); + + // original data + ScheduleRevData ScheduleOriginalData_[SCHEDULE_DATA_COUNT_MAX] = {nullptr, nullptr, nullptr, nullptr}; + C_ScheduleRevData C_ScheduleOriginalData_[SCHEDULE_DATA_COUNT_MAX] = {0}; + // item data + ScheduleListItemInfo ScheduleItemData_[SCHEDULE_DATA_COUNT_MAX*2] = {nullptr, nullptr, nullptr, nullptr, 0, false, 0}; + uint8_t ItemCount_{0}; + uint8_t DataCount_{0}; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/SchedulePresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/SchedulePresenter.h new file mode 100644 index 000000000..a4e9ed1e7 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/SchedulePresenter.h @@ -0,0 +1,42 @@ + +#ifndef __SCHEDULEPRESENTER_H__ +#define __SCHEDULEPRESENTER_H__ + +#include "Presenter.h" +#include "View.h" + +#include "schedule/include/ScheduleView.h" +#include "schedule/include/ScheduleModel.h" + + +namespace OHOS +{ + class ScheduleView; + class ScheduleModel; + class SchedulePresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener + { + public: + SchedulePresenter(); + virtual ~SchedulePresenter(); + static SchedulePresenter * GetInstance(); + + void OnStart() override; + void OnResume() override; + void OnPause() override; + void OnStop() override; + + private: + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + + ScheduleModel * ScheduleModel_; + bool X_DRAG_FLAG{false}; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleView.h new file mode 100644 index 000000000..fe44f2b8e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/include/ScheduleView.h @@ -0,0 +1,129 @@ + +#ifndef __SCHEDULEVIEW_H__ +#define __SCHEDULEVIEW_H__ + +#include "View.h" +#include "ohos_types.h" +#include "components/ui_view_group.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_list.h" +#include "components/ui_scroll_view.h" +// #include "components/ui_button.h" +#include "components/ui_label_button_ext.h" +#include "common/screen.h" +#include "ui_resource_string.h" + +#include "schedule/include/SchedulePresenter.h" +#include "schedule/include/ScheduleListAdapter.h" +#include "schedule/include/ScheduleListItem.h" + + +namespace OHOS +{ + #define SCHEDULE_ViewId_NoDataGroup_ "SCHEDULE_ViewId_ContentDeleteButton_" + #define SCHEDULE_ViewId_DataGroup_ "SCHEDULE_ViewId_DataGroup_" + #define SCHEDULE_ViewId_ContentGroup_ "SCHEDULE_ViewId_ContentGroup_" + #define SCHEDULE_ViewId_DeleteGroup_ "SCHEDULE_ViewId_DeleteGroup_" + + #define SCHEDULE_ViewId_ContentDeleteButton_ "SCHEDULE_ViewId_ContentDeleteButton_" + #define SCHEDULE_ViewId_ContentCloseButton_ "SCHEDULE_ViewId_ContentCloseButton_" + #define SCHEDULE_ViewId_DeleteCancelButton_ "SCHEDULE_ViewId_DeleteCancelButton_" + #define SCHEDULE_ViewId_DeleteOKButton_ "SCHEDULE_ViewId_DeleteOKButton_" + + class SchedulePresenter; + class ScheduleView : public View + { + public: + ScheduleView(); + ~ScheduleView(); + static ScheduleView * GetInstance(void); + + void OnStart() override; + void OnStop() override; + + void ItemListAdd(const ScheduleListItemInfo &item); + void ItemListClear(void); + void ItemListContentUpdate(void); + void ItemListScrollByUpdate(bool isUpScroll = false); + + void ContentScreenItemIndexSet(uint8_t index); + uint8_t ContentScreenItemIndexGet(void); + + void DisplayDataOrNoScreen(void); + void DisplayContentScreen(void); + void DisplayDeleteScreen(void); + + void SetViewFocus(bool val); + + private: + + void ResetScheduleList(void); + + UIViewGroup * InitNoDataScreen(); + void DeinitNoDataScreen(); + UILabelExt * InitLabel(int16_t x, int16_t y, int16_t width, int16_t height, + uint16_t line_height, uint8_t font_size, uint16_t text_id, uint32_t text_color); + + UIViewGroup * NoDataGroup_{nullptr}; + UILabelExt * LabelExt0_{nullptr}; + UIImageView * ImageView_{nullptr}; + UILabelExt * LabelExt1_{nullptr}; + UILabelExt * LabelExt2_{nullptr}; + + + UIViewGroup * InitDataScreen(); + void DeinitDataScreen(); + UIViewGroup * DataGroup_{nullptr}; + UIList * ScheduleList_{nullptr}; + ScheduleListAdapter * ScheduleListAdapter_{nullptr}; + + + UIScrollView * InitContentScreen(); + void DeinitContentScreen(); + UIScrollView * ContentGroup_{nullptr}; + UILabelExt * ContentDateLabelExt_{nullptr}; + UILabelExt * ContentTopicLabelExt_{nullptr}; + UILabelExt * ContentTopicLabelExt1_{nullptr}; + UILabelExt * ContentTimeLabelExt_{nullptr}; + UILabelExt * ContentTimeLabelExt1_{nullptr}; + UILabelExt * ContentContentLabelExt_{nullptr}; + UILabelExt * ContentContentLabelExt1_{nullptr}; + UILabelButtonExt * ContentDeleteButton_{nullptr}; + UILabelButtonExt * ContentCloseButton_{nullptr}; + uint8_t ContentItemIndex_{0}; + + + UIViewGroup * InitDeleteScreen(); + void DeinitDeleteScreen(); + UIViewGroup * DeleteGroup_{nullptr}; + UILabelExt * DeleteTitleLabelExt_{nullptr}; + UILabelExt * DeletePromptLabelExt_{nullptr}; + UILabelButtonExt * DeleteCancelButton_{nullptr}; + UILabelButtonExt * DeleteOKButton_{nullptr}; + + + void DisplaySelectScreen(uint8_t ScreenIndex); + typedef enum + { + ENUM_SCHEDULE_SCREEN_NO_DATA, + ENUM_SCHEDULE_SCREEN_LIST, + ENUM_SCHEDULE_SCREEN_CONTENT, + ENUM_SCHEDULE_SCREEN_DELETE, + + ENUM_SCHEDULE_SCREEN_MAX + }ENUM_SCHEDULE_SCREEN; + UIViewGroup * ScreenGroupArray_[ENUM_SCHEDULE_SCREEN_MAX]{nullptr}; + + + #define SCREEN_WIDTH (Screen::GetInstance().GetWidth()) + #define SCREEN_HEIGHT (Screen::GetInstance().GetHeight()) + #define LIST_LEFT (43) + #define LIST_TOP (50) + #define LIST_WIDTH (SCREEN_WIDTH - LIST_LEFT * 2) + #define LIST_HEIGHT (SCREEN_HEIGHT - LIST_TOP * 2) + + #define NO_DATA_IMAGE "/user/res/Schedule/schedule_no_data.bin" + }; +} +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleListAdapter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleListAdapter.cpp new file mode 100644 index 000000000..83e52d74f --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleListAdapter.cpp @@ -0,0 +1,88 @@ +#include "schedule/include/ScheduleListAdapter.h" +#include "wearable_log.h" + +namespace OHOS +{ + static ScheduleListAdapter * p_ScheduleListAdapterInstance = nullptr; + + ScheduleListAdapter::ScheduleListAdapter() + { + p_ScheduleListAdapterInstance = this; + } + + ScheduleListAdapter::~ScheduleListAdapter() + { + p_ScheduleListAdapterInstance = nullptr; + nodeList_.Clear(); + } + + ScheduleListAdapter * ScheduleListAdapter::GetInstance() + { + return p_ScheduleListAdapterInstance; + } + + UIView * ScheduleListAdapter::GetView(UIView * inView, int16_t index) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:GetView,%d", __LINE__, index); + if(nodeList_.IsEmpty() || nodeList_.Size() <= index || 0 > index) + { + return nullptr; + } + + ScheduleListItem * item = nullptr; + ListNode * node = nodeList_.Begin(); + for (uint16_t i = 0; i < index; i++) + { + node = node->next_; + } + + if (nullptr == inView) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:GetView", __LINE__); + item = new ScheduleListItem(); + if (nullptr == item) + return nullptr; + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:GetView", __LINE__); + item = static_cast(inView); + } + + if (item != nullptr) + { + item->SetViewIndex(index); + item->ResetItemStyle(node->data_); + item->SetItemInfo(node->data_); + item->SetOnClickListener(itemClickListener_); + } + if(nodeList_.Size() > 2 && index == nodeList_.Size() - 1) + item->ResetHeight(true); + else + item->ResetHeight(false); + + return item; + } + + uint16_t ScheduleListAdapter::GetCount() + { + return nodeList_.Size(); + } + + void ScheduleListAdapter::AddListItem(const ScheduleListItemInfo &item) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:AddListItem", __LINE__); + nodeList_.PushBack(item); + } + + void ScheduleListAdapter::ClearListItem(void) + { + nodeList_.Clear(); + } + + void ScheduleListAdapter::SetItemClickListener(UIView::OnClickListener *itemClickListener) + { + itemClickListener_ = itemClickListener; + } + +} diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleListItem.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleListItem.cpp new file mode 100644 index 000000000..416340289 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleListItem.cpp @@ -0,0 +1,157 @@ + +#include "schedule/include/ScheduleListItem.h" +#include "wearable_log.h" + +namespace OHOS +{ + ScheduleListItem::ScheduleListItem() + { + SetPosition(0, 0, ITEM_WIDTH, ITEM_HEIGHT + ITEM_GAP); + SetStyle(STYLE_BACKGROUND_COLOR, OHOS::Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + // SetStyle(STYLE_BORDER_RADIUS, 20); + // SetTouchable(true); + + InfoGroup_.SetPosition(0, ITEM_GAP>>1, ITEM_WIDTH, ITEM_HEIGHT); + InfoGroup_.SetStyle(STYLE_BACKGROUND_COLOR, OHOS::Color::Black().full); + InfoGroup_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + InfoGroup_.SetStyle(STYLE_BORDER_RADIUS, 20); + InfoGroup_.SetTouchable(true); + + LabelExtDate_.SetPosition((ITEM_WIDTH - 300)>>1, (ITEM_HEIGHT - 55)>>1, 300, 55); + LabelExtDate_.SetStyle(STYLE_TEXT_FONT, 30); + LabelExtDate_.SetStyle(STYLE_LINE_HEIGHT, 35); + // LabelExtDate_.SetTextId(text_id); + LabelExtDate_.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + LabelExtDate_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + LabelExtDate_.SetRollSpeed(23); + LabelExtDate_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + LabelExtDate_.SetStyle(STYLE_TEXT_COLOR, 0xffff5a36); + + LabelExtTopic_.SetPosition(47, 22, 250, 35); + LabelExtTopic_.SetStyle(STYLE_TEXT_FONT, 30); + LabelExtTopic_.SetStyle(STYLE_LINE_HEIGHT, 35); + // LabelExtTopic_.SetTextId(text_id); + LabelExtTopic_.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + LabelExtTopic_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); + LabelExtTopic_.SetRollSpeed(23); + LabelExtTopic_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // LabelExtTopic_.SetStyle(STYLE_TEXT_COLOR, 0xffff5a36); + + LabelExtTime_.SetPosition(47, 57, 115, 24); + LabelExtTime_.SetStyle(STYLE_TEXT_FONT, 20); + LabelExtTime_.SetStyle(STYLE_LINE_HEIGHT, 24); + // LabelExtTime_.SetTextId(text_id); + LabelExtTime_.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + LabelExtTime_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); + LabelExtTime_.SetRollSpeed(23); + LabelExtTime_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + // LabelExtTime_.SetStyle(STYLE_TEXT_COLOR, 0xffff5a36); + + Image_.SetPosition(326, 37, 14, 26); + Image_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + Image_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + Image_.SetResizeMode(UIImageView::CENTER); + Image_.SetAutoEnable(false); + Image_.SetSrc(IMAGE_ITEM_ARROW); + + InfoGroup_.Add(&LabelExtDate_); + InfoGroup_.Add(&LabelExtTopic_); + InfoGroup_.Add(&LabelExtTime_); + InfoGroup_.Add(&Image_); + Add(&InfoGroup_); + } + + ScheduleListItem::~ScheduleListItem() + { + RemoveAll(); + InfoGroup_.RemoveAll(); + } + + void ScheduleListItem::SetItemInfo(const ScheduleListItemInfo &itemInfo) + { + if(true == itemInfo.IsDateItem) + { + LabelExtDate_.SetText(itemInfo.DateStr.c_str()); + } + else + { + if(0 == (itemInfo.ChildIndex % 2)) + { + LabelExtTopic_.SetText(itemInfo.TopicStr.c_str()); + LabelExtTime_.SetText(itemInfo.TimeStr.c_str()); + } + else + { + LabelExtTopic_.SetText(itemInfo.TopicStr.c_str()); + LabelExtTime_.SetText(itemInfo.TimeStr.c_str()); + } + } + } + + void ScheduleListItem::ResetItemStyle(const ScheduleListItemInfo &itemInfo) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:ResetItemStyle,%d,%d", + __LINE__, itemInfo.IsDateItem, itemInfo.ChildIndex); + + if(true == itemInfo.IsDateItem) + { + // SetHeight(ITEM_HEIGHT- ITEM_GAP); + + // InfoGroup_.SetHeight(ITEM_HEIGHT- ITEM_GAP); + InfoGroup_.SetStyle(STYLE_BACKGROUND_COLOR, OHOS::Color::Black().full); + InfoGroup_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + InfoGroup_.SetTouchable(false); + + LabelExtDate_.SetVisible(true); + LabelExtTopic_.SetVisible(false); + LabelExtTime_.SetVisible(false); + Image_.SetVisible(false); + } + else + { + if(0 == (itemInfo.ChildIndex % 2)) + { + InfoGroup_.SetStyle(STYLE_BACKGROUND_COLOR, ODD_ITEM_BACKGROUND_COLOR); + InfoGroup_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + InfoGroup_.SetTouchable(true); + + LabelExtDate_.SetVisible(false); + LabelExtTopic_.SetVisible(true); + LabelExtTime_.SetVisible(true); + Image_.SetVisible(true); + + LabelExtTopic_.SetStyle(STYLE_TEXT_COLOR, ODD_ITEM_TOPIC_COLOR); + LabelExtTime_.SetStyle(STYLE_TEXT_COLOR, ODD_ITEM_TIME_COLOR); + } + else + { + InfoGroup_.SetStyle(STYLE_BACKGROUND_COLOR, EVEN_ITEM_BACKGROUND_COLOR); + InfoGroup_.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + InfoGroup_.SetTouchable(true); + + LabelExtDate_.SetVisible(false); + LabelExtTopic_.SetVisible(true); + LabelExtTime_.SetVisible(true); + Image_.SetVisible(true); + + LabelExtTopic_.SetStyle(STYLE_TEXT_COLOR, EVEN_ITEM_TOPIC_COLOR); + LabelExtTime_.SetStyle(STYLE_TEXT_COLOR, EVEN_ITEM_TIME_COLOR); + } + } + } + + void ScheduleListItem::ResetHeight(bool val) + { + //防止list中元素超过3个后最后一个被遮住,且仅在最后一个元素设置其高度为160 + if (val) + { + SetHeight(ITEM_HEIGHT + ITEM_GAP*3); + } + else + { + SetHeight(ITEM_HEIGHT + ITEM_GAP); + } + } + +} diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleModel.cpp new file mode 100644 index 000000000..fcfd984eb --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleModel.cpp @@ -0,0 +1,299 @@ + +// #include +// #include +// #include +#include "schedule/include/ScheduleModel.h" +#include "wearable_log.h" + +namespace OHOS +{ + ScheduleModel::ScheduleModel(){} + + ScheduleModel::~ScheduleModel(){} + + ScheduleModel &ScheduleModel::GetInstance() + { + static ScheduleModel instance; + return instance; + } + + uint8_t ScheduleModel::ScheduleItemDataCountGet(void) + { + return ItemCount_; + } + + void ScheduleModel::ScheduleItemDataCountSet(uint8_t count) + { + ItemCount_ = count; + } + + uint8_t ScheduleModel::ScheduleOriginalDataCountGet(void) + { + return DataCount_; + } + + void ScheduleModel::ScheduleOriginalDataCountSet(uint8_t count) + { + DataCount_ = count; + } + + ScheduleListItemInfo *ScheduleModel::ScheduleAllItemDataGet(void) + { + return ScheduleItemData_; + } + + std::string ScheduleModel::ScheduleItemDataDateStrGet(uint8_t index) + { + return ScheduleItemData_[index].DateStr.c_str(); + } + + std::string ScheduleModel::ScheduleItemDataTopicStrGet(uint8_t index) + { + return ScheduleItemData_[index].TopicStr.c_str(); + } + + std::string ScheduleModel::ScheduleItemDataTimeStrGet(uint8_t index) + { + return ScheduleItemData_[index].TimeStr.c_str(); + } + + std::string ScheduleModel::ScheduleItemDataContentStrGet(uint8_t index) + { + return ScheduleItemData_[index].ContentStr.c_str(); + } + + uint8_t ScheduleModel::ScheduleItemDataOriginalDataIndexGet(uint8_t index) + { + return ScheduleItemData_[index].OriginalDataIndex; + } + + void ScheduleModel::ScheduleOriginalDataSetByApp(ScheduleRevData *data, uint8_t index, bool is_finish) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScheduleOriginalDataSetByApp,%d,%d", index, is_finish); + uint8_t len = 0; + if (index >= SCHEDULE_DATA_COUNT_MAX) + { + return; + } + + ScheduleOriginalData_[index].date.assign(data->date); + + len = ((SCHEDULE_TOPIC_STR_MAX - 1 > data->topic.length()) ? data->topic.length() : SCHEDULE_TOPIC_STR_MAX - 1); + ScheduleOriginalData_[index].topic.assign(data->topic, 0, len); + + ScheduleOriginalData_[index].time.assign(data->time); + + len = ((SCHEDULE_CONTENT_STR_MAX - 1 > data->content.length()) ? data->content.length() : SCHEDULE_CONTENT_STR_MAX - 1); + ScheduleOriginalData_[index].content.assign(data->content, 0, len); + + if (true == is_finish) + { + uint8_t DataCount = index + 1; + ScheduleOriginalDataCountSet(DataCount); + ScheduleOriginalDataToItemData(DataCount); + } + } + + void ScheduleModel::ScheduleOriginalDataSetByUI(uint8_t index) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScheduleModel::ScheduleOriginalDataSetByUI,%d", index); + + uint8_t DataCount = ScheduleOriginalDataCountGet(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScheduleModel::DataCount:%d", DataCount); + uint8_t i = 0; + for (i = index; i < (DataCount - 1); i++) + { + ScheduleOriginalData_[i].date.assign(ScheduleOriginalData_[i + 1].date); + ScheduleOriginalData_[i].topic.assign(ScheduleOriginalData_[i + 1].topic); + ScheduleOriginalData_[i].time.assign(ScheduleOriginalData_[i + 1].time); + ScheduleOriginalData_[i].content.assign(ScheduleOriginalData_[i + 1].content); + } + + ScheduleOriginalData_[i].date.clear(); + ScheduleOriginalData_[i].topic.clear(); + ScheduleOriginalData_[i].time.clear(); + ScheduleOriginalData_[i].content.clear(); + + DataCount -= 1; + ScheduleOriginalDataCountSet(DataCount); + ScheduleOriginalDataToItemData(DataCount); + } + + void ScheduleModel::ScheduleOriginalDataToItemData(uint8_t DataCount) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScheduleModel::ScheduleOriginalDataToItemData,%d", DataCount); + uint8_t i = 0; + uint8_t j = 0; + + memset(ScheduleItemData_, 0x0, sizeof(ScheduleListItemInfo) * SCHEDULE_DATA_COUNT_MAX * 2); + ScheduleItemDataCountSet(0); + + for (i = 0, j = 0; i < DataCount; i++) + { + if (0 == i) + { + ScheduleItemData_[j].DateStr.assign(ScheduleOriginalData_[i].date); + ScheduleItemData_[j].OriginalDataIndex = i; + ScheduleItemData_[j].IsDateItem = true; + + j++; + ScheduleItemData_[j].DateStr.assign(ScheduleOriginalData_[i].date); + ScheduleItemData_[j].TopicStr.assign(ScheduleOriginalData_[i].topic); + ScheduleItemData_[j].TimeStr.assign(ScheduleOriginalData_[i].time); + ScheduleItemData_[j].ContentStr.assign(ScheduleOriginalData_[i].content); + ScheduleItemData_[j].OriginalDataIndex = i; + ScheduleItemData_[j].IsDateItem = false; + ScheduleItemData_[j].ChildIndex = 0; + } + else + { + if (0 == ScheduleOriginalData_[i].date.compare(ScheduleOriginalData_[i - 1].date)) + { + j++; + ScheduleItemData_[j].DateStr.assign(ScheduleOriginalData_[i].date); + ScheduleItemData_[j].TopicStr.assign(ScheduleOriginalData_[i].topic); + ScheduleItemData_[j].TimeStr.assign(ScheduleOriginalData_[i].time); + ScheduleItemData_[j].ContentStr.assign(ScheduleOriginalData_[i].content); + ScheduleItemData_[j].OriginalDataIndex = i; + ScheduleItemData_[j].IsDateItem = false; + ScheduleItemData_[j].ChildIndex = ScheduleItemData_[j - 1].ChildIndex + 1; + } + else + { + j++; + ScheduleItemData_[j].DateStr.assign(ScheduleOriginalData_[i].date); + ScheduleItemData_[j].OriginalDataIndex = i; + ScheduleItemData_[j].IsDateItem = true; + + j++; + ScheduleItemData_[j].DateStr.assign(ScheduleOriginalData_[i].date); + ScheduleItemData_[j].TopicStr.assign(ScheduleOriginalData_[i].topic); + ScheduleItemData_[j].TimeStr.assign(ScheduleOriginalData_[i].time); + ScheduleItemData_[j].ContentStr.assign(ScheduleOriginalData_[i].content); + ScheduleItemData_[j].OriginalDataIndex = i; + ScheduleItemData_[j].IsDateItem = false; + ScheduleItemData_[j].ChildIndex = 0; + } + } + + if ((SCHEDULE_DATA_COUNT_MAX * 2) <= j) + { + break; + } + } + + if (0 != DataCount) + { + uint8_t ItemCount = j + 1; + ScheduleItemDataCountSet(ItemCount); + } + + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScheduleModel::ScheduleOriginalDataToItemData,%d,%s", j, ScheduleItemData_[0].DateStr.c_str()); + } + + void ScheduleModel::DataStringToCharArray(void) + { + uint8_t DataCount = ScheduleOriginalDataCountGet(); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:DataStringToCharArray,%d", __LINE__, DataCount); + + memset(C_ScheduleOriginalData_, 0x0, sizeof(C_ScheduleRevData) * SCHEDULE_DATA_COUNT_MAX); + + uint8_t i = 0; + for (i = 0; i < DataCount; i++) + { + memcpy(C_ScheduleOriginalData_[i].date, ScheduleOriginalData_[i].date.c_str(), SCHEDULE_DATE_STR_MAX - 1); + memcpy(C_ScheduleOriginalData_[i].topic, ScheduleOriginalData_[i].topic.c_str(), SCHEDULE_TOPIC_STR_MAX - 1); + memcpy(C_ScheduleOriginalData_[i].time, ScheduleOriginalData_[i].time.c_str(), SCHEDULE_TIME_STR_MAX - 1); + memcpy(C_ScheduleOriginalData_[i].content, ScheduleOriginalData_[i].content.c_str(), SCHEDULE_CONTENT_STR_MAX - 1); + } + } + + void ScheduleModel::DataCharArrayToString(uint8_t DataCount) + { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:DataCharArrayToString,%d", __LINE__, DataCount); + + uint8_t i = 0; + for (i = 0; i < DataCount; i++) + { + ScheduleOriginalData_[i].date.assign(C_ScheduleOriginalData_[i].date); + ScheduleOriginalData_[i].topic.assign(C_ScheduleOriginalData_[i].topic); + ScheduleOriginalData_[i].time.assign(C_ScheduleOriginalData_[i].time); + ScheduleOriginalData_[i].content.assign(C_ScheduleOriginalData_[i].content); + } + ScheduleOriginalDataCountSet(DataCount); + } + + // int C_ScheduleDataReadFromFile(void) + int ScheduleModel::ScheduleDataReadFromFile(void) + { + FILE *fp = fopen(SCHEDULE_DATA_FILE, "rb"); + if (fp == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:C_ScheduleDataReadFromFile", __LINE__); + return OHOS_FAILURE; + } + + fseek(fp, 0, SEEK_END); + int len = ftell(fp); + fseek(fp, 0, SEEK_SET); + uint8_t DataCount = len / sizeof(C_ScheduleRevData); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:%d,%d", __LINE__, DataCount, len); + fread((char *)C_ScheduleOriginalData_, sizeof(C_ScheduleRevData), DataCount, fp); + fclose(fp); + + DataCharArrayToString(DataCount); + + ScheduleOriginalDataCountSet(DataCount); + ScheduleOriginalDataToItemData(DataCount); + + return OHOS_SUCCESS; + } + + // int C_ScheduleDataWriteToFile(void) + int ScheduleModel::ScheduleDataWriteToFile(void) + { + uint8_t DataCount = ScheduleOriginalDataCountGet(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:ScheduleDataWriteToFile,%d", __LINE__, DataCount); + if (0 == DataCount) + { + return OHOS_FAILURE; + } + + FILE *fp = fopen(SCHEDULE_DATA_FILE, "wb+"); + if (nullptr == fp) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:ScheduleDataWriteToFile fail", __LINE__); + return OHOS_FAILURE; + } + + DataStringToCharArray(); + + size_t ret = fwrite(C_ScheduleOriginalData_, sizeof(C_ScheduleRevData), DataCount, fp); + if (DataCount != ret) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:ScheduleDataWriteToFile fail", __LINE__); + } + fclose(fp); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:ScheduleDataWriteToFile success", __LINE__); + + return OHOS_SUCCESS; + } +} + +// c func +void C_ScheduleSetByApp(ScheduleRevData *data, uint8_t index, bool is_finish) +{ + OHOS::ScheduleModel::GetInstance().ScheduleOriginalDataSetByApp(data, index, is_finish); +} + +int C_ScheduleDataReadFromFile(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:C_ScheduleDataReadFromFile", __LINE__); + return OHOS::ScheduleModel::GetInstance().ScheduleDataReadFromFile(); +} + +int C_ScheduleDataWriteToFile(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:C_ScheduleDataWriteToFile", __LINE__); + return OHOS::ScheduleModel::GetInstance().ScheduleDataWriteToFile(); +} diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/SchedulePresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/SchedulePresenter.cpp new file mode 100644 index 000000000..15504ed13 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/SchedulePresenter.cpp @@ -0,0 +1,159 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-06-20 15:11:17 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-13 16:28:48 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/SchedulePresenter.cpp + */ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "common/key_code.h" +#include +#include "UiConfig.h" +#include "schedule/include/SchedulePresenter.h" +#include "schedule/include/ScheduleView.h" +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_MENU_PRO(VIEW_SCHEDULE, ScheduleView, SchedulePresenter, + PNG_APPLIST_SCHEDULE_IMAGE_BIG, PNG_APPLIST_SCHEDULE_IMAGE,PNG_APPLIST_SCHEDULE_IMAGE, "日程", STR_SCHEDULE); + + // 当前Presenter属性实例化的内存指针 + static SchedulePresenter * p_SchedulePresenterInstance = nullptr; + + SchedulePresenter::SchedulePresenter() + { + ScheduleModel_ = &ScheduleModel::GetInstance(); + p_SchedulePresenterInstance = this; + } + + SchedulePresenter::~SchedulePresenter() + { + p_SchedulePresenterInstance = nullptr; + } + + SchedulePresenter *SchedulePresenter::GetInstance() + { + return p_SchedulePresenterInstance; + } + + // 启动时执行的逻辑 + void SchedulePresenter::OnStart() + { + } + + // 页面已经展示后的调用逻辑 + void SchedulePresenter::OnResume(void) + { + Presenter::OnResume(); + if (nullptr == view_) + { + return; + } + + view_->ItemListContentUpdate(); + } + + // 页面准备切换到后台前执行的逻辑 + void SchedulePresenter::OnPause(void) + { + Presenter::OnPause(); + } + + // 页面完全置于后台时的逻辑。 + void SchedulePresenter::OnStop(void) + { + } + + bool SchedulePresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:OnClick", __LINE__); + + // if (nullptr == &view) + // { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:OnClick", __LINE__); + // return false; + // } + + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_ContentDeleteButton_)) + { + view_->DisplayDeleteScreen(); + return true; + } + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_ContentCloseButton_)) + { + view_->DisplayDataOrNoScreen(); + return true; + } + + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_DeleteCancelButton_)) + { + view_->DisplayContentScreen(); + return true; + } + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_DeleteOKButton_)) + { + ScheduleModel_->ScheduleOriginalDataSetByUI(view_->ContentScreenItemIndexGet() / 2); + view_->ItemListContentUpdate(); + view_->DisplayDataOrNoScreen(); + view_->ItemListScrollByUpdate(); + return true; + } + + ScheduleListItem * item = static_cast(&view); + view_->ContentScreenItemIndexSet(item->GetViewIndex()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:OnClick,index:%d", __LINE__,item->GetViewIndex()); + view_->DisplayContentScreen(); + + return true; + } + + bool SchedulePresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + SchedulePresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool SchedulePresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SchedulePresenter::X_DRAG_FLAG) + { + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_ContentGroup_)) + { + view_->DisplayDataOrNoScreen(); + return true; + } + if(0 == strcmp(view.GetViewId(), SCHEDULE_ViewId_DeleteGroup_)) + { + view_->DisplayContentScreen(); + return true; + } + + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + SchedulePresenter::X_DRAG_FLAG = false; + } + return true; + } + + bool SchedulePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SchedulePresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleView.cpp new file mode 100644 index 000000000..e1d50d889 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleView.cpp @@ -0,0 +1,802 @@ + +#include "schedule/include/ScheduleView.h" +#include "UiConfig.h" +#include "wearable_log.h" + +namespace OHOS +{ + static ScheduleView * p_ScheduleViewInstance = nullptr; + + ScheduleView::ScheduleView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScheduleView::ScheduleView"); + p_ScheduleViewInstance = this; + } + + ScheduleView::~ScheduleView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScheduleView::~ScheduleView"); + DeinitNoDataScreen(); + DeinitDataScreen(); + DeinitContentScreen(); + DeinitDeleteScreen(); + p_ScheduleViewInstance = nullptr; + } + + ScheduleView * ScheduleView::GetInstance() + { + return p_ScheduleViewInstance; + } + + void ScheduleView::OnStart() + { + ScreenGroupArray_[ENUM_SCHEDULE_SCREEN_NO_DATA] = InitNoDataScreen(); + ScreenGroupArray_[ENUM_SCHEDULE_SCREEN_LIST] = InitDataScreen(); + ScreenGroupArray_[ENUM_SCHEDULE_SCREEN_CONTENT] = InitContentScreen(); + ScreenGroupArray_[ENUM_SCHEDULE_SCREEN_DELETE] = InitDeleteScreen(); + + uint8_t i = 0; + for(i = 0; i < ENUM_SCHEDULE_SCREEN_MAX; i++) + { + if(nullptr != ScreenGroupArray_[i]) + { + AddViewToRootContainer(ScreenGroupArray_[i]); + } + } + + DisplayDataOrNoScreen(); + } + + void ScheduleView::OnStop() + { + + } + + void ScheduleView::DisplaySelectScreen(uint8_t ScreenIndex) + { + if(ENUM_SCHEDULE_SCREEN_MAX <= ScreenIndex) + { + return; + } + + uint8_t i = 0; + for(i = 0; i < ENUM_SCHEDULE_SCREEN_MAX; i++) + { + if(nullptr != ScreenGroupArray_[i]) + { + if(i == ScreenIndex) + { + ScreenGroupArray_[i]->SetVisible(true); + } + else + { + ScreenGroupArray_[i]->SetVisible(false); + } + } + } + } + + void ScheduleView::DisplayDataOrNoScreen(void) + { + if(0 == ScheduleModel::GetInstance().ScheduleItemDataCountGet()) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:DisplayMainScreen", __LINE__); + DisplaySelectScreen(ENUM_SCHEDULE_SCREEN_NO_DATA); + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]:DisplayMainScreen", __LINE__); + DisplaySelectScreen(ENUM_SCHEDULE_SCREEN_LIST); + + ResetScheduleList(); + SetViewFocus(true);//列表获取聚焦 + ScheduleList_->RefreshList(); + } + } + + void ScheduleView::DisplayContentScreen(void) + { + DisplaySelectScreen(ENUM_SCHEDULE_SCREEN_CONTENT); + SetViewFocus(false);//数据显示视图获取聚焦 + + uint8_t index = ContentScreenItemIndexGet(); + ContentDateLabelExt_->SetText(ScheduleModel::GetInstance().ScheduleItemDataDateStrGet(index).c_str()); + + int16_t temp_y = 0; + temp_y = ContentDateLabelExt_->GetY() + ContentDateLabelExt_->GetHeight() + 50; + ContentTopicLabelExt_->SetY(temp_y); + ContentTopicLabelExt1_->SetY(temp_y); + ContentTopicLabelExt1_->SetText(ScheduleModel::GetInstance().ScheduleItemDataTopicStrGet(index).c_str()); + + temp_y = ContentTopicLabelExt_->GetY() + ContentTopicLabelExt_->GetHeight() + 20; + ContentTimeLabelExt_->SetY(temp_y); + ContentTimeLabelExt1_->SetY(temp_y); + ContentTimeLabelExt1_->SetText(ScheduleModel::GetInstance().ScheduleItemDataTimeStrGet(index).c_str()); + + if(true == ScheduleModel::GetInstance().ScheduleItemDataContentStrGet(index).empty()) + { + ContentContentLabelExt_->SetVisible(false); + ContentContentLabelExt1_->SetVisible(false); + + temp_y = ContentTimeLabelExt_->GetY() + ContentTimeLabelExt_->GetHeight() + 50; + ContentDeleteButton_->SetY(temp_y); + } + else + { + ContentContentLabelExt_->SetVisible(true); + ContentContentLabelExt1_->SetVisible(true); + + temp_y = ContentTimeLabelExt_->GetY() + ContentTimeLabelExt_->GetHeight() + 20; + ContentContentLabelExt_->SetY(temp_y); + ContentContentLabelExt1_->SetY(temp_y); + ContentContentLabelExt1_->SetText(ScheduleModel::GetInstance().ScheduleItemDataContentStrGet(index).c_str()); + + temp_y = ContentContentLabelExt1_->GetY() + ContentContentLabelExt1_->GetHeight() + 50; + ContentDeleteButton_->SetY(temp_y); + } + + temp_y = ContentDeleteButton_->GetY() + ContentDeleteButton_->GetHeight() + 20; + ContentCloseButton_->SetY(temp_y); + } + + void ScheduleView::DisplayDeleteScreen(void) + { + DisplaySelectScreen(ENUM_SCHEDULE_SCREEN_DELETE); + } + + void ScheduleView::DeinitNoDataScreen() + { + if (nullptr != NoDataGroup_) + { + NoDataGroup_->RemoveAll(); + if (nullptr != LabelExt0_) + { + delete LabelExt0_; + LabelExt0_ = nullptr; + } + if (nullptr != ImageView_) + { + delete ImageView_; + ImageView_ = nullptr; + } + if (nullptr != LabelExt1_) + { + delete LabelExt1_; + LabelExt1_ = nullptr; + } + if (nullptr != LabelExt2_) + { + delete LabelExt2_; + LabelExt2_ = nullptr; + } + + delete NoDataGroup_; + NoDataGroup_ = nullptr; + } + } + + UIViewGroup * ScheduleView::InitNoDataScreen() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]", __LINE__); + if(nullptr == NoDataGroup_) + { + NoDataGroup_ = new UIViewGroup(); + if(nullptr == NoDataGroup_) + return nullptr; + + NoDataGroup_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + NoDataGroup_->SetViewId(SCHEDULE_ViewId_NoDataGroup_); + NoDataGroup_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + NoDataGroup_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + NoDataGroup_->SetOnDragListener(presenter_); + NoDataGroup_->SetTouchable(true); + NoDataGroup_->SetDraggable(true); + + if(nullptr == LabelExt0_) + { + LabelExt0_ = InitLabel(83, 50, 300, 35, 35, 30, STR_SCHEDULE_TITLE, Color::White().full); + if(nullptr == LabelExt0_) + { + return nullptr; + } + } + + if(nullptr == ImageView_) + { + ImageView_ = new UIImageView(); + if(nullptr == ImageView_) + { + return nullptr; + } + + ImageView_->SetPosition(175, 150, 116, 120); + ImageView_->SetSrc(NO_DATA_IMAGE); + } + + if(nullptr == LabelExt1_) + { + LabelExt1_ = InitLabel(53, 330, 360, 35, 35, 30, STR_SCHEDULE_NO_DATA, 0xff999999); + if(nullptr == LabelExt1_) + { + return nullptr; + } + } + + if(nullptr == LabelExt2_) + { + LabelExt2_ = InitLabel(53, 370, 360, 35, 35, 30, STR_SCHEDULE_NO_DATA_PROMPT, 0xff999999); + if(nullptr == LabelExt2_) + { + return nullptr; + } + } + + NoDataGroup_->Add(LabelExt0_); + NoDataGroup_->Add(ImageView_); + NoDataGroup_->Add(LabelExt1_); + NoDataGroup_->Add(LabelExt2_); + } + + return NoDataGroup_; + } + + void ScheduleView::DeinitDataScreen() + { + if (nullptr != DataGroup_) + { + DataGroup_->RemoveAll(); + if (nullptr != ScheduleListAdapter_) + { + delete ScheduleListAdapter_; + ScheduleListAdapter_ = nullptr; + } + if (nullptr != ScheduleList_) + { + delete ScheduleList_; + ScheduleList_ = nullptr; + } + + delete DataGroup_; + DataGroup_ = nullptr; + } + } + + UIViewGroup * ScheduleView::InitDataScreen() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]", __LINE__); + if(nullptr == DataGroup_) + { + DataGroup_ = new UIViewGroup(); + if(nullptr == DataGroup_) + return nullptr; + + DataGroup_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + DataGroup_->SetViewId(SCHEDULE_ViewId_DataGroup_); + DataGroup_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + DataGroup_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + DataGroup_->SetOnDragListener(presenter_); + DataGroup_->SetTouchable(true); + DataGroup_->SetDraggable(true); + + if(nullptr == ScheduleListAdapter_) + { + ScheduleListAdapter_ = new ScheduleListAdapter(); + if(nullptr == ScheduleListAdapter_) + return nullptr; + + ScheduleListAdapter_->SetItemClickListener(presenter_); + } + + if(nullptr == ScheduleList_) + { + ScheduleList_ = new UIList(); + if(nullptr == ScheduleList_) + { + return nullptr; + } + } + ScheduleList_->SetPosition(LIST_LEFT, LIST_TOP, LIST_WIDTH, LIST_HEIGHT); + // ScheduleList_->SetSelectPosition(VERTICAL_RESOLUTION / 2); + ScheduleList_->SetDraggable(true); + ScheduleList_->SetThrowDrag(true); + // ScheduleList_->EnableAutoAlign(true); + ScheduleList_->SetAdapter(ScheduleListAdapter_); + // ScheduleList_->SetScrollStateListener(presenter_); + ScheduleList_->SetMaxScrollDistance(1000); // 1000: max scroll distance + ScheduleList_->SetSwipeACCLevel(200); // 800: compensation distance + ScheduleList_->SetDragACCLevel(5); // 5: drag acceleration + ScheduleList_->SetYScrollBarVisible(false); + + // ScheduleList_->SetScrollBlankSize(40); + ScheduleList_->SetReboundSize(30); + + ScheduleList_->SetRotateFactor(2); // 增加表冠控制 + ScheduleList_->RequestFocus(); + ResetScheduleList(); + + DataGroup_->Add(ScheduleList_); + } + + return DataGroup_; + } + + void ScheduleView::DeinitContentScreen() + { + if(nullptr != ContentGroup_) + { + ContentGroup_->RemoveAll(); + if(nullptr != ContentDateLabelExt_) + { + delete ContentDateLabelExt_; + ContentDateLabelExt_ = nullptr; + } + if(nullptr != ContentTopicLabelExt_) + { + delete ContentTopicLabelExt_; + ContentTopicLabelExt_ = nullptr; + } + if(nullptr != ContentTopicLabelExt1_) + { + delete ContentTopicLabelExt1_; + ContentTopicLabelExt1_ = nullptr; + } + if(nullptr != ContentTimeLabelExt_) + { + delete ContentTimeLabelExt_; + ContentTimeLabelExt_ = nullptr; + } + if(nullptr != ContentTimeLabelExt1_) + { + delete ContentTimeLabelExt1_; + ContentTimeLabelExt1_ = nullptr; + } + if(nullptr != ContentContentLabelExt_) + { + delete ContentContentLabelExt_; + ContentContentLabelExt_ = nullptr; + } + if(nullptr != ContentContentLabelExt1_) + { + delete ContentContentLabelExt1_; + ContentContentLabelExt1_ = nullptr; + } + if(nullptr != ContentDeleteButton_) + { + delete ContentDeleteButton_; + ContentDeleteButton_ = nullptr; + } + if(nullptr != ContentCloseButton_) + { + delete ContentCloseButton_; + ContentCloseButton_ = nullptr; + } + + delete ContentGroup_; + ContentGroup_ = nullptr; + } + } + + UIScrollView * ScheduleView::InitContentScreen() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]", __LINE__); + if(nullptr == ContentGroup_) + { + ContentGroup_ = new UIScrollView(); + if(nullptr == ContentGroup_) + return nullptr; + + // ContentGroup_->SetViewIndex(ENUM_SCHEDULE_CONTENT_SCREEN); + ContentGroup_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + ContentGroup_->SetViewId(SCHEDULE_ViewId_ContentGroup_); + ContentGroup_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + ContentGroup_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + ContentGroup_->SetOnDragListener(presenter_); + ContentGroup_->SetTouchable(true); + ContentGroup_->SetDraggable(true); + + ContentGroup_->SetScrollBlankSize(40); + ContentGroup_->SetReboundSize(40); + ContentGroup_->SetDirection(1); + ContentGroup_->SetMaxScrollDistance(1000); + ContentGroup_->SetThrowDrag(true); + // ContentGroup_->RequestFocus(); + ContentGroup_->SetRotateFactor(2); + + if(nullptr == ContentDateLabelExt_) + { + ContentDateLabelExt_ = new UILabelExt(); + if(nullptr == ContentDateLabelExt_) + return nullptr; + + ContentDateLabelExt_->SetPosition(83, 50, 300, 35); + ContentDateLabelExt_->SetStyle(STYLE_TEXT_FONT, 30); + ContentDateLabelExt_->SetStyle(STYLE_LINE_HEIGHT, 35); + // ContentDateLabelExt_->SetTextId(text_id); + ContentDateLabelExt_->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + ContentDateLabelExt_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + ContentDateLabelExt_->SetRollSpeed(23); + ContentDateLabelExt_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + ContentDateLabelExt_->SetStyle(STYLE_TEXT_COLOR, 0xffff5a36); + } + + if(nullptr == ContentTopicLabelExt_) + { + ContentTopicLabelExt_ = new UILabelExt(); + if(nullptr == ContentTopicLabelExt_) + return nullptr; + + ContentTopicLabelExt_->SetPosition(53, 0, 360, 35); + ContentTopicLabelExt_->SetStyle(STYLE_TEXT_FONT, 30); + ContentTopicLabelExt_->SetStyle(STYLE_LINE_HEIGHT, 35); + ContentTopicLabelExt_->SetTextId(STR_SCHEDULE_TOPIC); + // ContentTopicLabelExt_->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + ContentTopicLabelExt_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); + ContentTopicLabelExt_->SetRollSpeed(23); + ContentTopicLabelExt_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + ContentTopicLabelExt_->SetStyle(STYLE_TEXT_COLOR, 0xff999999); + + if(nullptr == ContentTopicLabelExt1_) + { + ContentTopicLabelExt1_ = new UILabelExt(); + if(nullptr == ContentTopicLabelExt1_) + return nullptr; + + uint16 x = ContentTopicLabelExt_->GetX(); + uint16 w = ContentTopicLabelExt_->GetTextWidth(); + ContentTopicLabelExt1_->SetPosition(x + w + 5, 0, 360 - w - 5, 35); + ContentTopicLabelExt1_->SetStyle(STYLE_TEXT_FONT, 30); + ContentTopicLabelExt1_->SetStyle(STYLE_LINE_HEIGHT, 35); + ContentTopicLabelExt1_->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + ContentTopicLabelExt1_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); + ContentTopicLabelExt1_->SetRollSpeed(23); + ContentTopicLabelExt1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + ContentTopicLabelExt1_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + } + } + + if(nullptr == ContentTimeLabelExt_) + { + ContentTimeLabelExt_ = new UILabelExt(); + if(nullptr == ContentTimeLabelExt_) + return nullptr; + + ContentTimeLabelExt_->SetPosition(53, 0, 360, 35); + ContentTimeLabelExt_->SetStyle(STYLE_TEXT_FONT, 30); + ContentTimeLabelExt_->SetStyle(STYLE_LINE_HEIGHT, 35); + ContentTimeLabelExt_->SetTextId(STR_SCHEDULE_TIME); + // ContentTimeLabelExt_->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + ContentTimeLabelExt_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); + ContentTimeLabelExt_->SetRollSpeed(23); + ContentTimeLabelExt_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + ContentTimeLabelExt_->SetStyle(STYLE_TEXT_COLOR, 0xff999999); + + if(nullptr == ContentTimeLabelExt1_) + { + ContentTimeLabelExt1_ = new UILabelExt(); + if(nullptr == ContentTimeLabelExt1_) + return nullptr; + + uint16 x = ContentTimeLabelExt_->GetX(); + uint16 w = ContentTimeLabelExt_->GetTextWidth(); + ContentTimeLabelExt1_->SetPosition(x + w + 5, 0, 360 - w - 5, 35); + ContentTimeLabelExt1_->SetStyle(STYLE_TEXT_FONT, 30); + ContentTimeLabelExt1_->SetStyle(STYLE_LINE_HEIGHT, 35); + ContentTimeLabelExt1_->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + ContentTimeLabelExt1_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); + ContentTimeLabelExt1_->SetRollSpeed(23); + ContentTimeLabelExt1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + ContentTimeLabelExt1_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + } + } + + if(nullptr == ContentContentLabelExt_) + { + ContentContentLabelExt_ = new UILabelExt(); + if(nullptr == ContentContentLabelExt_) + return nullptr; + + ContentContentLabelExt_->SetPosition(53, 0, 360, 35); + ContentContentLabelExt_->SetStyle(STYLE_TEXT_FONT, 30); + ContentContentLabelExt_->SetStyle(STYLE_LINE_HEIGHT, 35); + ContentContentLabelExt_->SetTextId(STR_SCHEDULE_NOTES); + // ContentContentLabelExt_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + ContentContentLabelExt_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); + ContentContentLabelExt_->SetRollSpeed(23); + ContentContentLabelExt_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + ContentContentLabelExt_->SetStyle(STYLE_TEXT_COLOR, 0xff999999); + + if(nullptr == ContentContentLabelExt1_) + { + ContentContentLabelExt1_ = new UILabelExt(); + if(nullptr == ContentContentLabelExt1_) + return nullptr; + + uint16 x = ContentContentLabelExt_->GetX(); + uint16 w = ContentContentLabelExt_->GetTextWidth(); + ContentContentLabelExt1_->SetPosition(x + w + 5, 0, 360 - w - 5, 35); + ContentContentLabelExt1_->SetStyle(STYLE_TEXT_FONT, 30); + ContentContentLabelExt1_->SetStyle(STYLE_LINE_HEIGHT, 35); + ContentContentLabelExt1_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + ContentContentLabelExt1_->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); + ContentContentLabelExt1_->SetRollSpeed(23); + ContentContentLabelExt1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + ContentContentLabelExt1_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + } + } + + if(nullptr == ContentDeleteButton_) + { + ContentDeleteButton_ = new UILabelButtonExt(); + if(nullptr == ContentDeleteButton_) + return nullptr; + + ContentDeleteButton_->SetPosition(93, 0, 280, 90); + ContentDeleteButton_->SetViewId(SCHEDULE_ViewId_ContentDeleteButton_); + ContentDeleteButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xfffd5213); + ContentDeleteButton_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + ContentDeleteButton_->SetStyle(STYLE_BORDER_RADIUS, 100); + ContentDeleteButton_->SetTextId(STR_DELETE); + ContentDeleteButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + ContentDeleteButton_->SetStyle(STYLE_LINE_HEIGHT, 35); + ContentDeleteButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffd5213, UIButton::PRESSED); + ContentDeleteButton_->SetOnClickListener(presenter_); + } + + if(nullptr == ContentCloseButton_) + { + ContentCloseButton_ = new UILabelButtonExt(); + if(nullptr == ContentCloseButton_) + return nullptr; + + ContentCloseButton_->SetPosition(93, 0, 280, 90); + ContentCloseButton_->SetViewId(SCHEDULE_ViewId_ContentCloseButton_); + ContentCloseButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + ContentCloseButton_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + ContentCloseButton_->SetStyle(STYLE_BORDER_RADIUS, 100); + ContentCloseButton_->SetTextId(STR_CLOSE); + ContentCloseButton_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + ContentCloseButton_->SetStyle(STYLE_LINE_HEIGHT, 35); + ContentCloseButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); + ContentCloseButton_->SetOnClickListener(presenter_); + } + + ContentGroup_->Add(ContentDateLabelExt_); + ContentGroup_->Add(ContentTopicLabelExt_); + ContentGroup_->Add(ContentTopicLabelExt1_); + ContentGroup_->Add(ContentTimeLabelExt_); + ContentGroup_->Add(ContentTimeLabelExt1_); + ContentGroup_->Add(ContentContentLabelExt_); + ContentGroup_->Add(ContentContentLabelExt1_); + ContentGroup_->Add(ContentDeleteButton_); + ContentGroup_->Add(ContentCloseButton_); + } + + return ContentGroup_; + } + + void ScheduleView::DeinitDeleteScreen() + { + if(nullptr != DeleteGroup_) + { + DeleteGroup_->RemoveAll(); + if(nullptr != DeleteTitleLabelExt_) + { + delete DeleteTitleLabelExt_; + DeleteTitleLabelExt_ = nullptr; + } + if(nullptr != DeletePromptLabelExt_) + { + delete DeletePromptLabelExt_; + DeletePromptLabelExt_ = nullptr; + } + if(nullptr != DeleteCancelButton_) + { + delete DeleteCancelButton_; + DeleteCancelButton_ = nullptr; + } + if(nullptr != DeleteOKButton_) + { + delete DeleteOKButton_; + DeleteOKButton_ = nullptr; + } + + delete DeleteGroup_; + DeleteGroup_ = nullptr; + } + } + + UIViewGroup * ScheduleView::InitDeleteScreen() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d]", __LINE__); + if(nullptr == DeleteGroup_) + { + DeleteGroup_ = new UIViewGroup(); + if(nullptr == DeleteGroup_) + return nullptr; + + DeleteGroup_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + DeleteGroup_->SetViewId(SCHEDULE_ViewId_DeleteGroup_); + DeleteGroup_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + DeleteGroup_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + DeleteGroup_->SetTouchable(true); + DeleteGroup_->SetDraggable(true); + DeleteGroup_->SetOnDragListener(presenter_); + + if(nullptr == DeleteTitleLabelExt_) + { + DeleteTitleLabelExt_ = new UILabelExt(); + if(nullptr == DeleteTitleLabelExt_) + return nullptr; + + DeleteTitleLabelExt_->SetPosition(83, 50, 300, 35); + DeleteTitleLabelExt_->SetStyle(STYLE_TEXT_FONT, 30); + DeleteTitleLabelExt_->SetStyle(STYLE_LINE_HEIGHT, 35); + DeleteTitleLabelExt_->SetTextId(STR_DELETE); + DeleteTitleLabelExt_->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + DeleteTitleLabelExt_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + DeleteTitleLabelExt_->SetRollSpeed(23); + DeleteTitleLabelExt_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + DeleteTitleLabelExt_->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + } + + if(nullptr == DeletePromptLabelExt_) + { + DeletePromptLabelExt_ = new UILabelExt(); + if(nullptr == DeletePromptLabelExt_) + return nullptr; + + DeletePromptLabelExt_->SetPosition(98, 187, 270, 35); + DeletePromptLabelExt_->SetStyle(STYLE_TEXT_FONT, 30); + DeletePromptLabelExt_->SetStyle(STYLE_LINE_HEIGHT, 35); + DeletePromptLabelExt_->SetTextId(STR_SCHEDULE_DELETE_PROMPT); + DeletePromptLabelExt_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + DeletePromptLabelExt_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + DeletePromptLabelExt_->SetRollSpeed(23); + DeletePromptLabelExt_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + DeletePromptLabelExt_->SetStyle(STYLE_TEXT_COLOR, 0xff999999); + } + + if(nullptr == DeleteCancelButton_) + { + DeleteCancelButton_ = new UILabelButtonExt(); + if(nullptr == DeleteCancelButton_) + return nullptr; + + DeleteCancelButton_->SetPosition(111, 299, 100, 100); + DeleteCancelButton_->SetViewId(SCHEDULE_ViewId_DeleteCancelButton_); + DeleteCancelButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + DeleteCancelButton_->SetStyle(STYLE_BACKGROUND_OPA, 25); // 10% + DeleteCancelButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED); + DeleteCancelButton_->SetStyleForState(STYLE_BACKGROUND_OPA, 25, UIButton::PRESSED); + DeleteCancelButton_->SetStyle(STYLE_BORDER_RADIUS, 100); + DeleteCancelButton_->SetImagePosition(0, 0); + DeleteCancelButton_->SetImageSrc(PNG_SYSTEM_CHECK_OFF_IMAGE, PNG_SYSTEM_CHECK_OFF_IMAGE); + DeleteCancelButton_->SetOnClickListener(presenter_); + } + + if(nullptr == DeleteOKButton_) + { + DeleteOKButton_ = new UILabelButtonExt(); + if(nullptr == DeleteOKButton_) + return nullptr; + + DeleteOKButton_->SetPosition(256, 299, 100, 100); + DeleteOKButton_->SetViewId(SCHEDULE_ViewId_DeleteOKButton_); + DeleteOKButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + DeleteOKButton_->SetStyle(STYLE_BACKGROUND_OPA, 25); // 10% + DeleteOKButton_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED); + DeleteOKButton_->SetStyleForState(STYLE_BACKGROUND_OPA, 25, UIButton::PRESSED); + DeleteOKButton_->SetStyle(STYLE_BORDER_RADIUS, 100); + DeleteOKButton_->SetImagePosition(0, 0); + DeleteOKButton_->SetImageSrc(PNG_SYSTEM_CHECK_ON_IMAGE, PNG_SYSTEM_CHECK_ON_IMAGE); + DeleteOKButton_->SetOnClickListener(presenter_); + } + + DeleteGroup_->Add(DeleteTitleLabelExt_); + DeleteGroup_->Add(DeletePromptLabelExt_); + DeleteGroup_->Add(DeleteCancelButton_); + DeleteGroup_->Add(DeleteOKButton_); + } + + return DeleteGroup_; + } + + UILabelExt * ScheduleView::InitLabel(int16_t x, int16_t y, int16_t width, int16_t height, + uint16_t line_height, uint8_t font_size, uint16_t text_id, uint32_t text_color) + { + UILabelExt * LabelExt = new UILabelExt(); + if(nullptr == LabelExt) + { + return nullptr; + } + + LabelExt->SetPosition(x, y, width, height); + LabelExt->SetStyle(STYLE_TEXT_FONT, font_size); + LabelExt->SetStyle(STYLE_LINE_HEIGHT, line_height); + LabelExt->SetTextId(text_id); + LabelExt->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + LabelExt->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + LabelExt->SetRollSpeed(23); + LabelExt->SetFont(DEFAULT_VECTOR_FONT_FILENAME, font_size); + LabelExt->SetStyle(STYLE_TEXT_COLOR, text_color); + + return LabelExt; + } + + void ScheduleView::ContentScreenItemIndexSet(uint8_t index) + { + ContentItemIndex_ = index; + } + + uint8_t ScheduleView::ContentScreenItemIndexGet(void) + { + return ContentItemIndex_; + } + + void ScheduleView::ItemListAdd(const ScheduleListItemInfo &item) + { + ScheduleListAdapter_->AddListItem(item); + } + + void ScheduleView::ItemListClear(void) + { + ScheduleListAdapter_->ClearListItem(); + } + + void ScheduleView::ItemListContentUpdate(void) + { + uint8_t ItemCount = ScheduleModel::GetInstance().ScheduleItemDataCountGet(); + if(0 != ItemCount) + { + ItemListClear(); + ScheduleListItemInfo * ItemInfo = ScheduleModel::GetInstance().ScheduleAllItemDataGet(); + for (uint8_t i = 0; i < ItemCount; i++) + { + ItemListAdd(ItemInfo[i]); + } + } + } + + /// @brief 列表滚动更新 + /// @param isUpScroll true 向上滚动,反之向下滚动 + void ScheduleView::ItemListScrollByUpdate(bool isUpScroll) + { + if(ScheduleList_) + { + ScheduleList_->ScrollBy(isUpScroll ? -240 : 240); + } + } + + void ScheduleView::ResetScheduleList(void) + { + if(ScheduleListAdapter_ == nullptr || ScheduleList_== nullptr) + { + return; + } + + if(ScheduleListAdapter_->GetCount() > 2) + { + ScheduleList_->SetReboundSize(30); + } + else + { + ScheduleList_->SetReboundSize(0); + } + } + + void ScheduleView::SetViewFocus(bool val) + { + if(!ContentGroup_ || !ScheduleList_) + { + return; + } + if(val) + { + ScheduleList_->RequestFocus(); + } + else + { + ContentGroup_->RequestFocus(); + } + } +} \ No newline at end of file -- 2.17.1