#include "ui_resource_image.h"
#include "common/image_cache_manager.h"
#include <time.h>
-
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+std::string weekdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
namespace OHOS
{
static MainClockView *g_pMainClockView = nullptr;
static constexpr uint16_t STEP_CHAR_NUM = 255;
static constexpr int16_t STEP_LABLE_WIDTH = 75;
static constexpr int16_t STEP_LABLE_SIZE = 35;
- static constexpr uint16_t WEEKLABEL_POSITION_X = 247;
- static constexpr uint16_t WEEKLABEL_POSITION_Y = 122;
+ static constexpr uint16_t WEEKLABEL_POSITION_X = 181;
+ static constexpr uint16_t WEEKLABEL_POSITION_Y = 365;
static constexpr uint16_t HEARTRATELABEL_POSITION_X = 198;
static constexpr uint16_t HEARTRATELABEL_POSITION_Y = 330;
static constexpr uint16_t HEARTRATE_POSITION_X = 156;
MainClockView::~MainClockView()
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::~MainClockView");
- mainSweepClock->RemoveAll();
- delete curFace;
+ /* -------------------------------------------------------------------------- */
+ delete curFace; // 背景
curFace = nullptr;
+ delete timerlabel; // 时间
+ timerlabel = nullptr;
+ delete weekLabel; // 星期
+ weekLabel = nullptr;
+ delete datelabel; // 日期
+ datelabel = nullptr;
+ /* -------------------------------------------------------------------------- */
+#ifdef DEFULTDIAL
+ mainSweepClock->RemoveAll();
delete stepLabel;
stepLabel = nullptr;
- delete batteryLabel;
- batteryLabel = nullptr;
delete secondHand;
secondHand = nullptr;
delete minuteHand;
minuteHand = nullptr;
delete hourHand;
hourHand = nullptr;
- delete weekLabel;
- weekLabel = nullptr;
- delete heartRateLabel;
- heartRateLabel = nullptr;
delete heartRate;
heartRate = nullptr;
delete hand24Hour;
delete mainSweepClock;
mainSweepClock = nullptr;
g_pMainClockView = nullptr;
+#endif
}
MainClockView *MainClockView::GetInstance(void)
return g_pMainClockView;
}
+ bool MainClockView::InitSweepClock(void)
+ {
+ // 背景
+ curFace = new UIImageView();
+ if (curFace == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace new fail");
+ return false;
+ }
+ curFace->SetPosition(0, 0);
+ ImageInfo *image = ImageCacheManager::GetInstance().LoadSingleRes(DEFAULT_DIALBACK_PATH, false);
+ if (image == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail",
+ DEFAULT_DIALBACK_PATH);
+ return false;
+ }
+ curFace->SetSrc(image);
+ Add(curFace);
+
+ // 时间
+ timerlabel = new UILabel();
+ if (timerlabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timerlabel new fail");
+ return false;
+ }
+ timerlabel->SetPosition(150, 290, 200, 150);
+ timerlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ timerlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 65);
+ timerlabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT);
+ timerlabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
+ timerlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ Add(timerlabel);
+
+ // 星期
+ weekLabel = new UILabel();
+ if (weekLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekLabel new fail");
+ return false;
+ }
+ weekLabel->SetPosition(180, 375, TEXT_WIDTH, TEXT_HEIGHT);
+ weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35);
+ weekLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT);
+ weekLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
+ weekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ Add(weekLabel);
+
+ datelabel = new UILabel();
+ if (datelabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "datelabel new fail");
+ return false;
+ }
+ datelabel->SetPosition(250, 375, TEXT_WIDTH, TEXT_HEIGHT);
+ datelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ datelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35);
+ datelabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE);
+ datelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
+ datelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ Add(datelabel);
+
+ InitDateTime();
+ return true;
+ }
+
+ void MainClockView::PreLoad(void)
+ {
+ if (!viewiInitStatus)
+ {
+ InitView();
+ viewiInitStatus = true;
+ }
+ }
+
+ void MainClockView::UnLoad(void)
+ {
+ // Main clock view is commonly used page, so we do not release it's resources inner slice.
+ }
+
+ bool MainClockView::InitView(void)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitView");
+ if (InitSweepClock() == false)
+ {
+ return false;
+ }
+ SetCoverable(true);
+ return true;
+ }
+
+ void MainClockView::InitDateTime(void)
+ {
+ struct tm pTM;
+ time_t seconds;
+ time(&seconds);
+ localtime_r(&seconds, &pTM);
+ // 这里用来初始化时间
+ // 拼接小时和分钟字符串
+ std::ostringstream oss;
+ oss << std::setfill('0') << std::setw(2) << static_cast<int>(pTM.tm_hour) << ":"
+ << std::setfill('0') << std::setw(2) << static_cast<int>(pTM.tm_min);
+
+ std::string timeStr = oss.str();
+ timerlabel->SetText(timeStr.c_str());
+
+ // 日期初始化
+ std::ostringstream dateStr;
+ dateStr << std::setfill('0') << std::setw(2) << static_cast<int>(pTM.tm_mday);
+ datelabel->SetText((dateStr.str()).c_str());
+ // 星期初始化
+ weekLabel->SetText(weekdays[pTM.tm_wday].c_str());
+ }
+
+ void MainClockView::UpdateTime(void)
+ {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ uint64_t second = tv.tv_sec;
+ uint64_t uSecond = tv.tv_usec;
+ uint64_t minute = second / MIN_TO_HOUR;
+ uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR);
+ uint8_t realHour = static_cast<uint8_t>(hour % HOURLY_SYSTEM);
+ uint8_t realMinute = static_cast<uint8_t>(minute % MIN_TO_HOUR);
+
+ // uint16_t realMilliSecond = static_cast<uint16_t>((second % MIN_TO_HOUR) * SEC_TO_MILLI +uSecond / USEC_TO_MILLI);
+
+ // 拼接小时和分钟字符串
+ std::ostringstream oss;
+ oss << std::setfill('0') << std::setw(2) << static_cast<int>(realHour) << ":"
+ << std::setfill('0') << std::setw(2) << static_cast<int>(realMinute);
+
+ std::string timeStr = oss.str();
+ // 更新界面上的文本
+ timerlabel->SetText(timeStr.c_str());
+ // 更新日期需要nextday的消息
+ }
+ /* -------------------------------------------------------------------------- */
+ void MainClockView::RefreshStep(int step)
+ {
+#if DEFULTDIAL
+ char stepChar[STEP_CHAR_NUM] = {0};
+ (void)sprintf_s(stepChar, STEP_CHAR_NUM, "%d", step);
+ stepLabel->SetText(stepChar);
+#endif
+ }
+
+ void MainClockView::RefreshHeartRate(int value)
+ {
+#if DEFULTDIAL
+ if (value == 0)
+ {
+ datelabel->SetText("--");
+ return;
+ }
+ char heartRateChar[STEP_CHAR_NUM] = {0};
+ (void)sprintf_s(heartRateChar, STEP_CHAR_NUM, "%d", value);
+ datelabel->SetText(heartRateChar);
+#endif
+ }
+#ifdef DEFULTDIAL
void MainClockView::InitStepValue()
{
-#if 0
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue");
uint32_t stepValue;
int weekToday = ActivityModel::GetInstance()->GetWeekToday();
stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED);
stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED);
stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE);
-#endif
}
-
bool MainClockView::InitLabelView(void)
{
UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance();
stepLabel->SetOnClickListener(clickListener);
InitStepValue();
- batteryLabel = new UILabel();
- if (batteryLabel == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel new fail");
- return false;
- }
- batteryLabel->SetPosition(BATTERYP_LABEL_X, BATTERYP_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT);
- batteryLabel->SetText("90%");
- batteryLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
- batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
- batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT);
-
- heartRateLabel = new UILabel();
- if (heartRateLabel == nullptr)
+ datelabel = new UILabel();
+ if (datelabel == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRateLabel new fail");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "datelabel new fail");
return false;
}
- heartRateLabel->SetPosition(HEARTRATELABEL_POSITION_X, HEARTRATELABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT);
- heartRateLabel->SetText("--");
- heartRateLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
- heartRateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
- heartRateLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE);
+ datelabel->SetPosition(HEARTRATELABEL_POSITION_X, HEARTRATELABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT);
+ datelabel->SetText("--");
+ datelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ datelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
+ datelabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE);
weekLabel = new UILabel();
if (weekLabel == nullptr)
weekLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT);
return true;
}
-
bool MainClockView::InitCenterCircleView(void)
{
-#if 0
+
bigCircle = new Image();
if (bigCircle == nullptr)
{
{
return false;
}
-#endif
+
return true;
}
bool MainClockView::InitHandView(void)
{
-#if 0
+
secondHand = new Image();
if (secondHand == nullptr)
{
{
return false;
}
-#endif
+
return true;
}
bool MainClockView::LoadClockImage(Image *view, uint32_t resId)
{
-#if 0
+
std::string file = CLOCK_IAMGES;
ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file);
if (image == nullptr)
return false;
}
view->SetSrc(image);
-#endif
+
return true;
}
bool MainClockView::LoadClockImage(UIImageView *view, uint32_t resId)
{
-#if 0
std::string file = CLOCK_IAMGES;
ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file);
if (image == nullptr)
return false;
}
view->SetSrc(image);
-#endif
return true;
}
-
- bool MainClockView::InitSweepClock(void)
- {
- curFace = new UIImageView();
- if (curFace == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace new fail");
- return false;
- }
- curFace->SetPosition(0, 0);
- ImageInfo *image = ImageCacheManager::GetInstance().LoadSingleRes(DEFAULT_DIALBACK_PATH, false);
- if (image == nullptr)
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail",
- DEFAULT_DIALBACK_PATH);
- return false;
- }
- curFace->SetSrc(image);
- Add(curFace);
-#if 0
- // Add SweepClock to App
- if (mainSweepClock == nullptr)
- {
- mainSweepClock = new UISweepClock();
- }
- mainSweepClock->SetPosition(0, 0); // widget's left position and top position
- mainSweepClock->Resize(466, 466); // widget's width and height
- mainSweepClock->SetViewId("sweepClock1"); // Set style
- mainSweepClock->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
- mainSweepClock->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
-
- // Set additional property
- mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL);
- mainSweepClock->SetHandLine(UISweepClock::HandType::HOUR_HAND, {233, 101}, {0, 132}, Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff), 5, 132, 255);
- mainSweepClock->SetHandLine(UISweepClock::HandType::MINUTE_HAND, {233, 56}, {0, 177}, Color::GetColorFromRGBA(0x00, 0xff, 0x00, 0xff), 3, 177, 255);
- mainSweepClock->SetHandLine(UISweepClock::HandType::SECOND_HAND, {233, 10}, {0, 223}, Color::GetColorFromRGBA(0xff, 0x00, 0x00, 0xff), 1, 223, 255);
- uint16_t sweepClock1realMilliSecond = 40 * 1000;
- mainSweepClock->SetSweepTime12Hour(10, 20, sweepClock1realMilliSecond, true);
-
- mainSweepClock->SetInitTime24Hour(0, 0, 0);
- mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL);
- InitDateTime();
-
- if (LoadClockImage(curFace, CLOCK_CLOCK0) == false) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace LoadClockImage CLOCK_MAIN_FACE_IMAGE fail");
- return false;
- }
-
- if (InitLabelView() == false) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelView() fail");
- return false;
- }
- if (InitCenterCircleView() == false) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitCenterCircleView() fail");
- return false;
- }
- heartRate = new UIImageView();
- if (heartRate == nullptr) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRate new fail");
- return false;
- }
- heartRate->SetPosition(HEARTRATE_POSITION_X, HEARTRATE_POSITION_Y);
- if (LoadClockImage(heartRate, CLOCK_HEARTRATE_IMAGE_PATH) == false) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "heartRate LoadClockImage CLOCK_HEARTRATE_IMAGE_PATH fail");
- return false;
- }
-
- progress = new UIImageView();
- if (progress == nullptr) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress new fail");
- return false;
- }
- progress->SetPosition(PROGRESS_POSITION_X, PROGRESS_POSITION_Y);
- if (LoadClockImage(progress, CLOCK_PROGRESS_IMAGE_PATH) == false) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress LoadClockImage CLOCK_PROGRESS_IMAGE_PATH fail");
- return false;
- }
-
- InitHandView();
- weekDay = new UIImageView();
- if (weekDay == nullptr) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekDay new fail");
- return false;
- }
- weekDay->SetPosition(WEEKDAY_POSITION_X, WEEKDAY_POSITION_Y);
- if (LoadClockImage(weekDay, CLOCK_THURSDAY_IMAGE_PATH) == false) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weekDay LoadClockImage CLOCK_THURSDAY_IMAGE_PATH fail");
- return false;
- }
#endif
- InitLabelView();
- return true;
- }
-
- void MainClockView::PreLoad(void)
- {
- if (!viewiInitStatus)
- {
- InitView();
- viewiInitStatus = true;
- }
- }
-
- void MainClockView::UnLoad(void)
- {
- // Main clock view is commonly used page, so we do not release it's resources inner slice.
- }
-
- bool MainClockView::InitView(void)
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitView");
-
- mainSweepClock = new UISweepClock();
- if (mainSweepClock == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail");
- return false;
- }
- if (InitSweepClock() == false)
- {
- return false;
- }
- // mainSweepClock->Add(curFace);
- // Add(mainSweepClock);
-#if 0
- mainSweepClock->Add(stepLabel);
- mainSweepClock->Add(weekLabel);
- mainSweepClock->Add(heartRateLabel);
- mainSweepClock->Add(stepLabel);
- mainSweepClock->Add(curFace);
- mainSweepClock->Add(stepLabel);
- mainSweepClock->Add(heartRate);
- mainSweepClock->Add(weekLabel);
- mainSweepClock->Add(heartRateLabel);
- mainSweepClock->Add(weekDay);
- mainSweepClock->Add(progress);
- Add(mainSweepClock);
- mainSweepClock->SetDragParentInstead(true);
- mainSweepClock->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
-
- // {214, 3}: position x, y {14, 223}: center x, y
- mainSweepClock->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand,
- {POINT_POSITION_X, SECOND_POINT_POSITION_Y}, {POINT_CENTER_X, POINT_CENTER_Y});
- mainSweepClock->SetHandImage(UISweepClock::HandType::MINUTE_HAND, *minuteHand,
- {POINT_POSITION_X, POINT_POSITION_Y}, {POINT_CENTER_X, POINT_CENTER_Y});
- mainSweepClock->SetHandImage(UISweepClock::HandType::HOUR_HAND, *hourHand, {POINT_POSITION_X, POINT_POSITION_Y},
- {POINT_CENTER_X, POINT_CENTER_Y});
- mainSweepClock->SetHandCircleImage(UISweepClock::HandType::SECOND_HAND, *smallCircle,
- {SMALLCIRCLE_POSITION_X, SMALLCIRCLE_POSITION_Y});
- mainSweepClock->SetHandCircleImage(UISweepClock::HandType::MINUTE_HAND, *medCircle,
- {MEDCIRCLE_POSITION_X, MEDCIRCLE_POSITION_Y});
- mainSweepClock->SetHandCircleImage(UISweepClock::HandType::HOUR_HAND, *bigCircle,
- {BIGCIRCLE_POSITION_X, BIGCIRCLE_POSITION_Y});
-
- mainSweepClock->SetInitTime24Hour(0, 0, 0);
- mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL);
- InitDateTime();
-#endif
- SetCoverable(true);
- return true;
- }
-
- void MainClockView::RefreshStep(int step)
- {
-#if 0
- char stepChar[STEP_CHAR_NUM] = {0};
-
- (void)sprintf_s(stepChar, STEP_CHAR_NUM, "%d", step);
- stepLabel->SetText(stepChar);
-#endif
- }
-
- void MainClockView::RefreshHeartRate(int value)
- {
-#if 0
- if (value == 0)
- {
- heartRateLabel->SetText("--");
- return;
- }
- char heartRateChar[STEP_CHAR_NUM] = {0};
-
- (void)sprintf_s(heartRateChar, STEP_CHAR_NUM, "%d", value);
- heartRateLabel->SetText(heartRateChar);
-#endif
- }
-
- void MainClockView::InitDateTime(void)
- {
- struct tm pTM;
- time_t seconds;
- time(&seconds);
- localtime_r(&seconds, &pTM);
- mainSweepClock->SetTime24Hour(pTM.tm_hour, pTM.tm_min, pTM.tm_sec);
- }
-
- void MainClockView::UpdateTime(void)
- {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- uint64_t second = tv.tv_sec;
- uint64_t uSecond = tv.tv_usec;
- uint64_t minute = second / MIN_TO_HOUR;
- uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR);
- uint8_t realHour = static_cast<uint8_t>(hour % HOURLY_SYSTEM);
- uint8_t realMinute = static_cast<uint8_t>(minute % MIN_TO_HOUR);
- uint16_t realMilliSecond = static_cast<uint16_t>((second % MIN_TO_HOUR) *
- SEC_TO_MILLI +
- uSecond / USEC_TO_MILLI);
- mainSweepClock->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1);
- }
}