325 lines
11 KiB
C++
325 lines
11 KiB
C++
#include "TjdUiAppChargerView.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMemManage.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "animator/animator_manager.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "graphic_service.h"
|
|
#include "sys_config.h"
|
|
|
|
namespace TJD {
|
|
|
|
#define ENABLE_PRINT_INFO 1
|
|
#if ENABLE_PRINT_INFO
|
|
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
|
|
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
|
|
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
|
|
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印一般常开
|
|
#else
|
|
#define static_print_info(...)
|
|
#define static_print_warn(...)
|
|
#define static_print_error(...)
|
|
#define static_print_debug(...)
|
|
#endif
|
|
|
|
#define CHARGER_BIN_PATH TJD_IMAGE_PATH "img_charger.bin"
|
|
#define BED_SIDE_CLOCK_BIN_PATH TJD_IMAGE_PATH "img_bedside.bin"
|
|
|
|
// clang-format off
|
|
static inline int16_t HorizontalCenter(int16_t width, int16_t parentWidth) { return (parentWidth - width) / 2; }
|
|
|
|
static inline void InitLabelHorCenter(OHOS::UILabel &label, uint8_t size, int16_t y, int16_t target, const char *text)
|
|
{
|
|
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
|
label.SetText(text);
|
|
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
|
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
label.SetPosition(HorizontalCenter(label.GetWidth(), target), y);
|
|
}
|
|
// clang-format on
|
|
|
|
#pragma region 充电动画
|
|
TjdUiAppChargerAnimatorView::TjdUiAppChargerAnimatorView(int value)
|
|
{
|
|
int animatorRes[12] = {IMG_CHARGER_BAT_DT_01_03, IMG_CHARGER_BAT_DT_02_03, IMG_CHARGER_BAT_DT_03_03,
|
|
IMG_CHARGER_BAT_DT_04_03, IMG_CHARGER_BAT_DT_05_03, IMG_CHARGER_BAT_DT_06_03,
|
|
IMG_CHARGER_BAT_DT_07_03, IMG_CHARGER_BAT_DT_08_03, IMG_CHARGER_BAT_DT_09_03,
|
|
IMG_CHARGER_BAT_DT_10_03, IMG_CHARGER_BAT_DT_11_03, IMG_CHARGER_BAT_DT_12_03};
|
|
auto &image = OHOS::ImageCacheManager::GetInstance();
|
|
|
|
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
image.LoadAllInMultiRes(CHARGER_BIN_PATH);
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
animatorInfo_[i].imageInfo = image.LoadOneInMultiRes(animatorRes[i], CHARGER_BIN_PATH);
|
|
animatorInfo_[i].pos = {42, 41};
|
|
animatorInfo_[i].width = 349;
|
|
animatorInfo_[i].height = 326;
|
|
animatorInfo_[i].imageType = OHOS::IMG_SRC_IMAGE_INFO;
|
|
}
|
|
animator_.SetPosition(42, 41, 349, 326);
|
|
animator_.SetImageAnimatorSrc(animatorInfo_, 12, 100);
|
|
Add(&animator_);
|
|
animator_.Start();
|
|
|
|
InitLabelHorCenter(value_, 60, 157, 466, "0%");
|
|
InitLabelHorCenter(status_, 28, 368, 466, "正在充电...");
|
|
value_.SetX(value_.GetX() + 10);
|
|
SetValue(value);
|
|
|
|
Add(&value_);
|
|
Add(&status_);
|
|
}
|
|
|
|
TjdUiAppChargerAnimatorView::~TjdUiAppChargerAnimatorView()
|
|
{
|
|
animator_.Stop();
|
|
RemoveAll();
|
|
OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(CHARGER_BIN_PATH);
|
|
}
|
|
|
|
void TjdUiAppChargerAnimatorView::SetValue(int value)
|
|
{
|
|
valueStr_ = std::to_string(value) + "%";
|
|
value_.SetText(valueStr_.c_str());
|
|
value_.SetX(HorizontalCenter(value_.GetWidth(), 466));
|
|
value_.SetX(value_.GetX() + 10);
|
|
if (value == 100) {
|
|
status_.SetText("充电完成!");
|
|
status_.SetX(HorizontalCenter(status_.GetWidth(), 466));
|
|
} else {
|
|
status_.SetText("正在充电...");
|
|
status_.SetX(HorizontalCenter(status_.GetWidth(), 466));
|
|
}
|
|
}
|
|
#pragma endregion
|
|
|
|
#pragma region 床头钟
|
|
static int timeNumRes[] = {
|
|
[0] = IMG_BEDSIDE_TIME_NUM_01, [1] = IMG_BEDSIDE_TIME_NUM_02, [2] = IMG_BEDSIDE_TIME_NUM_03,
|
|
[3] = IMG_BEDSIDE_TIME_NUM_04, [4] = IMG_BEDSIDE_TIME_NUM_05, [5] = IMG_BEDSIDE_TIME_NUM_06,
|
|
[6] = IMG_BEDSIDE_TIME_NUM_07, [7] = IMG_BEDSIDE_TIME_NUM_08, [8] = IMG_BEDSIDE_TIME_NUM_09,
|
|
[9] = IMG_BEDSIDE_TIME_NUM_10,
|
|
};
|
|
static int dateNumRes[] = {
|
|
[0] = IMG_BEDSIDE_DATE_NUM_01, [1] = IMG_BEDSIDE_DATE_NUM_02, [2] = IMG_BEDSIDE_DATE_NUM_03,
|
|
[3] = IMG_BEDSIDE_DATE_NUM_04, [4] = IMG_BEDSIDE_DATE_NUM_05, [5] = IMG_BEDSIDE_DATE_NUM_06,
|
|
[6] = IMG_BEDSIDE_DATE_NUM_07, [7] = IMG_BEDSIDE_DATE_NUM_08, [8] = IMG_BEDSIDE_DATE_NUM_09,
|
|
[9] = IMG_BEDSIDE_DATE_NUM_10,
|
|
};
|
|
static int powerRes[] = {
|
|
[0] = IMG_BEDSIDE_BAT_01, [1] = IMG_BEDSIDE_BAT_02, [2] = IMG_BEDSIDE_BAT_03, [3] = IMG_BEDSIDE_BAT_04,
|
|
[4] = IMG_BEDSIDE_BAT_05, [5] = IMG_BEDSIDE_BAT_06, [6] = IMG_BEDSIDE_BAT_07, [7] = IMG_BEDSIDE_BAT_08,
|
|
[8] = IMG_BEDSIDE_BAT_09, [9] = IMG_BEDSIDE_BAT_10, [10] = IMG_BEDSIDE_BAT_11,
|
|
};
|
|
static int weekRes[] = {
|
|
[0] = IMG_BEDSIDE_WEEK_EN_01, [1] = IMG_BEDSIDE_WEEK_EN_02, [2] = IMG_BEDSIDE_WEEK_EN_03,
|
|
[3] = IMG_BEDSIDE_WEEK_EN_04, [4] = IMG_BEDSIDE_WEEK_EN_05, [5] = IMG_BEDSIDE_WEEK_EN_06,
|
|
[6] = IMG_BEDSIDE_WEEK_EN_07,
|
|
};
|
|
|
|
TjdUiAppBedSideClockView::TjdUiAppBedSideClockView(int value, ChargerTime &time)
|
|
{
|
|
auto &image = OHOS::ImageCacheManager::GetInstance();
|
|
image.LoadAllInMultiRes(BED_SIDE_CLOCK_BIN_PATH);
|
|
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
SetTouchable(true);
|
|
SetDraggable(true);
|
|
|
|
int hourFir = time.hour / 10;
|
|
int hourSec = time.hour % 10;
|
|
int minFir = time.min / 10;
|
|
int minSec = time.min % 10;
|
|
|
|
hourFir_.SetPosition(7, 153, 102, 164);
|
|
auto numRes = image.LoadOneInMultiRes(timeNumRes[hourFir], BED_SIDE_CLOCK_BIN_PATH);
|
|
hourFir_.SetSrc(numRes);
|
|
|
|
hourSec_.SetPosition(hourFir_.GetX() + hourFir_.GetWidth(), 153, 102, 164);
|
|
numRes = image.LoadOneInMultiRes(timeNumRes[hourSec], BED_SIDE_CLOCK_BIN_PATH);
|
|
hourSec_.SetSrc(numRes);
|
|
|
|
minFir_.SetPosition(256, 153, 102, 164);
|
|
numRes = image.LoadOneInMultiRes(timeNumRes[minFir], BED_SIDE_CLOCK_BIN_PATH);
|
|
minFir_.SetSrc(numRes);
|
|
|
|
minSec_.SetPosition(minFir_.GetX() + minFir_.GetWidth(), 153, 102, 164);
|
|
numRes = image.LoadOneInMultiRes(timeNumRes[minSec], BED_SIDE_CLOCK_BIN_PATH);
|
|
minSec_.SetSrc(numRes);
|
|
|
|
split.SetPosition(211, 153, 45, 164);
|
|
numRes = image.LoadOneInMultiRes(IMG_BEDSIDE_TIME_NUM_11, BED_SIDE_CLOCK_BIN_PATH);
|
|
split.SetSrc(numRes);
|
|
|
|
dateFir_.SetPosition(166, 359, 20, 32);
|
|
numRes = image.LoadOneInMultiRes(dateNumRes[time.date / 10], BED_SIDE_CLOCK_BIN_PATH);
|
|
dateFir_.SetSrc(numRes);
|
|
|
|
dateSec_.SetPosition(dateFir_.GetX() + dateFir_.GetWidth(), 359, 20, 32);
|
|
numRes = image.LoadOneInMultiRes(dateNumRes[time.date % 10], BED_SIDE_CLOCK_BIN_PATH);
|
|
dateSec_.SetSrc(numRes);
|
|
|
|
week_.SetPosition(228, 359, 20, 32);
|
|
numRes = image.LoadOneInMultiRes(weekRes[time.week], BED_SIDE_CLOCK_BIN_PATH);
|
|
week_.SetSrc(numRes);
|
|
|
|
power_.SetPosition(180, 19, 114, 114);
|
|
numRes = image.LoadOneInMultiRes(powerRes[value / 10], BED_SIDE_CLOCK_BIN_PATH);
|
|
power_.SetSrc(numRes);
|
|
|
|
Add(&hourFir_);
|
|
Add(&hourSec_);
|
|
Add(&minFir_);
|
|
Add(&minSec_);
|
|
Add(&split);
|
|
Add(&dateFir_);
|
|
Add(&dateSec_);
|
|
Add(&week_);
|
|
Add(&power_);
|
|
}
|
|
|
|
TjdUiAppBedSideClockView::~TjdUiAppBedSideClockView()
|
|
{
|
|
RemoveAll();
|
|
OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(BED_SIDE_CLOCK_BIN_PATH);
|
|
}
|
|
|
|
void TjdUiAppBedSideClockView::SetValue(int value)
|
|
{
|
|
auto &image = OHOS::ImageCacheManager::GetInstance();
|
|
int power = value / 10;
|
|
auto numRes = image.LoadOneInMultiRes(powerRes[power], BED_SIDE_CLOCK_BIN_PATH);
|
|
power_.SetSrc(numRes);
|
|
}
|
|
|
|
void TjdUiAppBedSideClockView::SetTime(ChargerTime &time)
|
|
{
|
|
auto &image = OHOS::ImageCacheManager::GetInstance();
|
|
|
|
int hourFir = time.hour / 10;
|
|
int hourSec = time.hour % 10;
|
|
int minFir = time.min / 10;
|
|
int minSec = time.min % 10;
|
|
|
|
auto numRes = image.LoadOneInMultiRes(timeNumRes[hourFir], BED_SIDE_CLOCK_BIN_PATH);
|
|
hourFir_.SetSrc(numRes);
|
|
|
|
numRes = image.LoadOneInMultiRes(timeNumRes[hourSec], BED_SIDE_CLOCK_BIN_PATH);
|
|
hourSec_.SetSrc(numRes);
|
|
|
|
numRes = image.LoadOneInMultiRes(timeNumRes[minFir], BED_SIDE_CLOCK_BIN_PATH);
|
|
minFir_.SetSrc(numRes);
|
|
|
|
numRes = image.LoadOneInMultiRes(timeNumRes[minSec], BED_SIDE_CLOCK_BIN_PATH);
|
|
minSec_.SetSrc(numRes);
|
|
|
|
numRes = image.LoadOneInMultiRes(dateNumRes[time.date / 10], BED_SIDE_CLOCK_BIN_PATH);
|
|
dateFir_.SetSrc(numRes);
|
|
|
|
numRes = image.LoadOneInMultiRes(dateNumRes[time.date % 10], BED_SIDE_CLOCK_BIN_PATH);
|
|
dateSec_.SetSrc(numRes);
|
|
|
|
numRes = image.LoadOneInMultiRes(weekRes[time.week], BED_SIDE_CLOCK_BIN_PATH);
|
|
week_.SetSrc(numRes);
|
|
}
|
|
|
|
void TjdUiAppBedSideClockView::SetRotateView(GsensorDir dir)
|
|
{
|
|
const OHOS::Vector2<float> pivot = {466 / 2, 466 / 2};
|
|
int16_t angle = 0;
|
|
// clang-format off
|
|
switch (dir) {
|
|
case GsensorDir::UP: angle = 0; break;
|
|
case GsensorDir::DOWN: angle = 180; break;
|
|
case GsensorDir::LEFT: angle = 90; break;
|
|
case GsensorDir::RIGHT: angle = 270; break;
|
|
default: angle = 0; break;
|
|
}
|
|
// clang-format on
|
|
Rotate(angle, pivot);
|
|
Invalidate();
|
|
}
|
|
#pragma endregion
|
|
|
|
#pragma region 充电动画上层
|
|
ChargerMeassageView::ChargerMeassageView(int value)
|
|
{
|
|
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
|
|
/* 显示充电动画 */
|
|
chargerView = new TjdUiAppChargerAnimatorView(value);
|
|
chargerView->SetPosition(0, 0);
|
|
chargerView->GetBitmap(imageInfo_);
|
|
chargerView->HideView();
|
|
|
|
/* 显示静态图,用于动画透明度 */
|
|
staticChargeView = new OHOS::UIImageView();
|
|
staticChargeView->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
staticChargeView->SetSrc(&imageInfo_);
|
|
staticChargeView->SetVisible(true);
|
|
|
|
enterAnimatorCallback = new ChargerExitAnimatorCallback();
|
|
enterAnimator = new OHOS::Animator(enterAnimatorCallback, this, 300, true);
|
|
enterAnimatorCallback->SetAnimator(enterAnimator);
|
|
|
|
Add(chargerView);
|
|
Add(staticChargeView);
|
|
}
|
|
|
|
ChargerMeassageView::~ChargerMeassageView()
|
|
{
|
|
RemoveAll();
|
|
OHOS::ImageCacheFree(imageInfo_);
|
|
delete chargerView;
|
|
delete staticChargeView;
|
|
delete enterAnimatorCallback;
|
|
delete enterAnimator;
|
|
chargerView = nullptr;
|
|
staticChargeView = nullptr;
|
|
enterAnimatorCallback = nullptr;
|
|
enterAnimator = nullptr;
|
|
}
|
|
|
|
void ChargerMeassageView::SetOpa(uint32_t opa)
|
|
{
|
|
SetStyle(OHOS::STYLE_BACKGROUND_OPA, opa);
|
|
if (opa < OHOS::OPA_OPAQUE) {
|
|
staticChargeView->SetStyle(OHOS::STYLE_IMAGE_OPA, opa);
|
|
} else {
|
|
staticChargeView->SetVisible(false);
|
|
chargerView->ShowView();
|
|
}
|
|
Invalidate();
|
|
}
|
|
|
|
void ChargerMeassageView::SetChargeHide()
|
|
{
|
|
OHOS::ImageCacheFree(imageInfo_);
|
|
imageInfo_ = {{0}};
|
|
chargerView->GetBitmap(imageInfo_);
|
|
staticChargeView->SetSrc(&imageInfo_);
|
|
staticChargeView->SetStyle(OHOS::STYLE_IMAGE_OPA, OHOS::OPA_OPAQUE);
|
|
staticChargeView->SetVisible(true);
|
|
chargerView->HideView();
|
|
}
|
|
|
|
void ChargerMeassageView::SetRotateView(GsensorDir dir)
|
|
{
|
|
const OHOS::Vector2<float> pivot = {466 / 2, 466 / 2};
|
|
int16_t angle = 0;
|
|
// clang-format off
|
|
switch (dir) {
|
|
case GsensorDir::UP: angle = 0; break;
|
|
case GsensorDir::DOWN: angle = 180; break;
|
|
case GsensorDir::LEFT: angle = 90; break;
|
|
case GsensorDir::RIGHT: angle = 270; break;
|
|
default: angle = 0; break;
|
|
}
|
|
// clang-format on
|
|
Rotate(angle, pivot);
|
|
Invalidate();
|
|
}
|
|
#pragma endregion
|
|
|
|
} // namespace TJD
|