--- /dev/null
+/*
+ * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
+ * Description: WomenHealthPresenter.cpp
+ * Author:
+ * Create: 2021-10-12
+ */
+
+ #include "womenhealth/include/WomenHealthView.h"
+ #include "womenhealth/include/WomenHealthModel.h"
+ #include "gfx_utils/mem_check.h"
+ #include "common/key_code.h"
+ #include "womenhealth/include/WomenHealthPresenter.h"
+ #include "custom_utils.h"
+ #include "NativeRegisterManager.h"
+
+ namespace OHOS
+ {
+
+ REGIST_MENU_PRO(VIEW_WOMEN_HEALTH, WomenHealthView, WomenHealthPresenter,
+ PNG_APPLIST_CALENDAR_IMAGE_BIG, PNG_APPLIST_CALENDAR_IMAGE, PNG_APPLIST_CALENDAR_IMAGE, "日历", STR_CALENDAR);
+
+ static WomenHealthPresenter *g_pMainView = nullptr;
+ WomenHealthPresenter::WomenHealthPresenter()
+ {
+ g_pMainView = this;
+ #ifdef MEM_CHECK
+ MemCheck::GetInstance()->EnableLeakCheck(true);
+ #endif
+ }
+
+ WomenHealthPresenter::~WomenHealthPresenter()
+ {
+ g_pMainView = nullptr;
+ #ifdef MEM_CHECK
+ MemCheck::GetInstance()->EnableLeakCheck(false);
+ #endif
+ }
+
+ WomenHealthPresenter *WomenHealthPresenter::GetInstance(void)
+ {
+ return g_pMainView;
+ }
+
+ void WomenHealthPresenter::OnStart()
+ {
+ }
+
+ void WomenHealthPresenter::OnResume()
+ {
+ RootView::GetInstance()->SetOnKeyActListener(this);
+ }
+
+ bool WomenHealthPresenter::OnClick(UIView &view, const ClickEvent &event)
+ {
+ UNUSED(event);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick");
+
+ return false;
+ }
+
+ bool WomenHealthPresenter::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCallingPresenter OnDragEnd");
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+ {
+ if (event.GetPreLastPoint().x - event.GetStartPoint().x > 100)
+ NativeAbility::GetInstance().Back();
+ }
+ if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP)
+ {
+ // if(event.GetPreLastPoint().y-event.GetStartPoint().y>100)
+ WomenHealthView::GetInstance()->updata_label(2);
+ }
+ if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM)
+ {
+ // if(event.GetPreLastPoint().y-event.GetStartPoint().y>100)
+ WomenHealthView::GetInstance()->updata_label(1);
+ }
+ return true;
+ }
+
+ bool WomenHealthPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::OnKeyAct");
+ uint16 keyID = event.GetKeyId();
+ uint16_t keyState = event.GetState();
+ // 如果是power键就返回上一级
+ if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
+ {
+ uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
+ NativeAbility::GetInstance().Back();
+ }
+ return true;
+ }
+ }
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
+ * Description: WomenHealthView.cpp
+ * Author:
+ * Create: 2021-10-12
+ */
+
+ #include "womenhealth/include/WomenHealthView.h"
+ #include "womenhealth/include/WomenHealthModel.h"
+ #include "uicomponents/UIComponents.h"
+
+ #include "wearable_log.h"
+ #include "UiConfig.h"
+ #include "NativeAbility.h"
+ #include "ConfigModel.h"
+ #include "languagecode/LanguageInit.h"
+ namespace OHOS
+ {
+
+ static WomenHealthView *g_pMainView_WomenHealthView = nullptr;
+
+ static char *dial_id_str[] = {"7", "8", "9", "C", "%", "4", "5", "6", "÷", "x", "1", "2", "3", "-", "+", "", "0", ".", "=", ""};
+
+ static constexpr int16_t PULLUP_ANIMATOR_VIEW_X = 213;
+ static constexpr int16_t PULLUP_ANIMATOR_VIEW_Y = 380;
+ static constexpr int16_t PULLUP_ANIMATOR_VIEW_W = 40;
+ static constexpr int16_t PULLUP_ANIMATOR_VIEW_H = 40;
+ static constexpr int16_t PULLUP_ANIMATOR_VIEW_NUM_FRAMES = 70;
+ static constexpr int16_t PULLUP_ANIMATOR_VIEW_TIME = 100;
+
+ static constexpr const char *PullUpPaths = "/user/res/weather/PullUp/PullUp_";
+
+ static constexpr const char *stepPaths = "/user/res/step/";
+
+ WomenHealthView::WomenHealthView()
+ {
+ g_pMainView_WomenHealthView = this;
+ }
+
+ WomenHealthView::~WomenHealthView()
+ {
+ g_pMainView_WomenHealthView = nullptr;
+ if (group)
+ {
+ group->RemoveAll();
+
+ if (mon_label)
+ {
+ delete mon_label;
+ mon_label = nullptr;
+ }
+
+ if (imageview)
+ {
+ delete imageview;
+ imageview = nullptr;
+ }
+
+ for (int i = 0; i < 7; i++)
+ {
+ if (week_label[i])
+ {
+ delete week_label[i];
+ week_label[i] = nullptr;
+ }
+ }
+
+ for (int i = 0; i < 31; i++)
+ {
+ if (day_label[i])
+ {
+ delete day_label[i];
+ day_label[i] = nullptr;
+ }
+ }
+
+ if (PullUpAnimatorView != nullptr)
+ {
+ PullUpAnimatorView->Stop();
+ delete PullUpAnimatorView;
+ PullUpAnimatorView = nullptr;
+ }
+
+ FreeImageInfoArray(PullUpimageAnimator_imageInfo, PullUpPaths, PULLUP_ANIMATOR_VIEW_NUM_FRAMES);
+
+ delete group;
+ group = nullptr;
+ }
+
+ g_pMainView_WomenHealthView = nullptr;
+ }
+
+ WomenHealthView *WomenHealthView::GetInstance()
+ {
+ return g_pMainView_WomenHealthView;
+ }
+ static char *week_Z_str[] = {"一", "二", "三", "四", "五", "六", "日"};
+ static char *week_E_str[] = {"MON", "THE", "WED", "THU", "FRI", "SAT", "SUN"};
+
+ bool WomenHealthView::updata_label(int8_t type)
+ {
+ for (int i = 0; i < 31; i++)
+ {
+ day_label[i]->SetVisible(false);
+ }
+ imageview->SetVisible(false);
+
+ if (type == 1)
+ {
+ show_m--;
+ if (show_m == 0)
+ {
+ show_m = 12;
+ show_y--;
+ }
+ }
+ else
+ {
+ show_m++;
+ if (show_m == 13)
+ {
+ show_m = 1;
+ show_y++;
+ }
+ }
+ uint8_t mon_max_day = 0;
+ uint8_t is_run = 0;
+ if (show_y % 4 == 0 && show_y % 100 != 0 || show_y % 400 == 0)
+ {
+ is_run = 1;
+ }
+
+ if (show_m == 2)
+ {
+ mon_max_day = 28 + is_run;
+ }
+ else if (show_m == 1 || show_m == 3 || show_m == 5 || show_m == 7 || show_m == 8 || show_m == 10 || show_m == 12)
+ {
+ mon_max_day = 31;
+ }
+ else
+ {
+ mon_max_day = 30;
+ }
+
+ int y = show_y;
+ int m = show_m;
+ int week = 0;
+ {
+ if (m == 1 || m == 2)
+ {
+ m += 12;
+ y--;
+ }
+ week = (1 + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
+ }
+
+ char mon[20] = {0};
+ sprintf(mon, "%d.%d", show_y, show_m);
+ mon_label->SetText(mon);
+
+ for (int i = 0; i < mon_max_day; i++)
+ {
+ int x = ((i + week) % 7);
+ int y = ((i + week) / 7);
+ day_label[i]->SetPosition(58 + 50 * x, 140 + 44 * y); // widget's left position and top position
+ char day[5];
+ sprintf(day, "%d", i + 1);
+ ;
+ day_label[i]->SetText(day);
+ time_t currtime;
+ time(&currtime);
+ struct tm *timeinfo;
+ timeinfo = localtime(&currtime);
+ int y_ = timeinfo->tm_year + 1900;
+ int m_ = timeinfo->tm_mon + 1;
+ int d_ = timeinfo->tm_mday;
+ if (i + 1 == d_ && show_y == y_ && show_m == m_)
+ {
+ imageview->SetPosition(58 + 50 * x, 140 + 44 * y);
+ imageview->SetVisible(true);
+ }
+ day_label[i]->SetVisible(true);
+ }
+ RootView::GetInstance()->Invalidate();
+ return true;
+ }
+ bool WomenHealthView::Label_init()
+ {
+ // Add Label to App
+ uint8_t mon_max_day = 0;
+
+ uint8_t is_run = 0;
+ time_t currtime;
+ time(&currtime);
+ struct tm *timeinfo;
+ timeinfo = localtime(&currtime);
+ int y = timeinfo->tm_year + 1900;
+ int m = timeinfo->tm_mon + 1;
+ int d = timeinfo->tm_mday;
+ int h = timeinfo->tm_hour;
+ int min = timeinfo->tm_min;
+ int week = timeinfo->tm_wday;
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d,%d,%d,%d", y, m, d, week);
+ if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) //
+ {
+ is_run = 1;
+ }
+
+ if (m == 2)
+ {
+ mon_max_day = 28 + is_run;
+ }
+ else if (m == 1 ||
+ m == 3 ||
+ m == 5 ||
+ m == 7 ||
+ m == 8 ||
+ m == 10 ||
+ m == 12)
+ {
+ mon_max_day = 31;
+ }
+ else
+ {
+ mon_max_day = 30;
+ }
+
+ show_y = y;
+ show_m = m;
+ show_d = d;
+
+ if (mon_label == nullptr)
+ {
+ mon_label = new UILabel();
+ }
+ mon_label->SetPosition(83, 50); // widget's left position and top position
+ mon_label->Resize(300, 35); // widget's width and height
+ mon_label->SetViewId("label1"); // Set style
+ mon_label->SetStyle(STYLE_TEXT_FONT, 30);
+
+ char mon[20] = {0};
+ sprintf(mon, "%d.%d", y, m);
+
+ if (m == 1 || m == 2)
+ {
+ m += 12;
+ y--;
+ }
+ week = (1 + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
+
+ mon_label->SetText(mon);
+ mon_label->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ mon_label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ mon_label->SetRollSpeed(0);
+ mon_label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+
+ // Add to rootView
+ group->Add(mon_label);
+
+ for (int i = 0; i < 7; i++)
+ {
+ if (week_label[i] == nullptr)
+ {
+ week_label[i] = new UILabel();
+ }
+ week_label[i]->SetPosition(58 + 50 * (i), 110); // widget's left position and top position
+ week_label[i]->Resize(50, 30); // widget's width and height
+ week_label[i]->SetViewId("label3"); // Set style
+ week_label[i]->SetStyle(STYLE_TEXT_FONT, 20);
+
+ if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN)
+ week_label[i]->SetText(week_Z_str[i]);
+ else
+ week_label[i]->SetText(week_E_str[i]);
+
+ week_label[i]->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ week_label[i]->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff));
+ week_label[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ week_label[i]->SetRollSpeed(0);
+ week_label[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
+
+ group->Add(week_label[i]);
+ week_label[i]->SetVisible(true);
+ }
+ // Add Label to App
+ if (imageview == nullptr)
+ {
+ imageview = new UIImageView();
+ }
+
+ imageview->SetPosition(58, 140);
+ imageview->Resize(50, 50);
+ imageview->SetViewId("image1");
+ imageview->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff5a36);
+ imageview->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ imageview->SetStyle(STYLE_BORDER_RADIUS, 100);
+ group->Add(imageview);
+ imageview->SetVisible(false);
+
+ for (int i = 0; i < 31; i++)
+ {
+ if (day_label[i] == nullptr)
+ {
+ day_label[i] = new UILabel();
+ }
+
+ day_label[i]->SetPosition(58, 140); // widget's left position and top position
+ day_label[i]->Resize(50, 44); // widget's width and height
+ day_label[i]->SetViewId("label3"); // Set style
+ day_label[i]->SetStyle(STYLE_TEXT_FONT, 20);
+
+ day_label[i]->SetStyle(STYLE_BORDER_RADIUS, 100);
+
+ day_label[i]->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+ day_label[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ day_label[i]->SetRollSpeed(0);
+ day_label[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+
+ group->Add(day_label[i]);
+ day_label[i]->SetVisible(false);
+ }
+ for (int i = 0; i < mon_max_day; i++)
+ {
+ int x = ((i + week) % 7);
+ int y = ((i + week) / 7);
+ day_label[i]->SetPosition(58 + 50 * x, 140 + 44 * y); // widget's left position and top position
+ char day[5];
+ sprintf(day, "%d", i + 1);
+ ;
+ day_label[i]->SetText(day);
+ if (i + 1 == d)
+ {
+ imageview->SetPosition(58 + 50 * x, 140 + 44 * y);
+ imageview->SetVisible(true);
+ }
+ day_label[i]->SetVisible(true);
+ }
+
+ PullUpimageAnimator_imageInfo = CreateImageInfoArray(PullUpPaths, PULLUP_ANIMATOR_VIEW_NUM_FRAMES);
+ if (PullUpAnimatorView == nullptr)
+ {
+ PullUpAnimatorView = new UIImageAnimatorView();
+ if (PullUpAnimatorView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpAnimatorView new fail");
+ return false;
+ }
+ for (uint8_t i = 0; i < PULLUP_ANIMATOR_VIEW_NUM_FRAMES; i++)
+ {
+ // PullUpimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(PullUpPathsArray[i]);
+ // PullUpimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO;
+ PullUpimageAnimatorInfo[i].imageInfo = PullUpimageAnimator_imageInfo[i];
+ // PullUpPathsArray[i];
+ PullUpimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO;
+ PullUpimageAnimatorInfo[i].pos.x = PULLUP_ANIMATOR_VIEW_X;
+ PullUpimageAnimatorInfo[i].pos.y = PULLUP_ANIMATOR_VIEW_Y;
+ PullUpimageAnimatorInfo[i].width = PULLUP_ANIMATOR_VIEW_W;
+ PullUpimageAnimatorInfo[i].height = PULLUP_ANIMATOR_VIEW_H;
+ }
+ PullUpAnimatorView->SetPosition(PULLUP_ANIMATOR_VIEW_X, PULLUP_ANIMATOR_VIEW_Y, PULLUP_ANIMATOR_VIEW_W, PULLUP_ANIMATOR_VIEW_H);
+ PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+ PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ PullUpAnimatorView->SetImageAnimatorSrc(PullUpimageAnimatorInfo, PULLUP_ANIMATOR_VIEW_NUM_FRAMES, PULLUP_ANIMATOR_VIEW_TIME);
+ PullUpAnimatorView->SetRepeat(true);
+ PullUpAnimatorView->Start();
+ }
+ group->Add(PullUpAnimatorView);
+
+ return true;
+ }
+
+ void WomenHealthView::OnStart()
+ {
+ group = new UIViewGroup();
+ if (group == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error");
+ return;
+ }
+ group->SetPosition(0, 0);
+ group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); // 454 : value
+ group->SetTouchable(true);
+ group->SetDraggable(true);
+ group->SetOnDragListener(presenter_);
+ AddViewToRootContainer(group);
+
+ if (!Label_init())
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error");
+ return;
+ }
+ }
+ }
\ No newline at end of file