mcu_hi3321_watch/tjd/ui/app/main/TjdUiAppMainPageFavorite.cpp
2025-05-31 10:45:15 +08:00

2234 lines
84 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "TjdUiAppMainPageFavorite.h"
#include "NativeAbility.h"
#include "TjdUiAppListModel.h"
#include "TjdUiAppMainView.h"
#include "TjdUiAppSettingModel.h"
#include "TjdUiAppSettingView.h"
#include "TjdUiImageIds.h"
#include "TjdUiMultiLanguageExt.h"
#include "TjdUiScreenDrag.h"
#include "TjdUiSettingCenter.h"
#include "TjdUiUtils.h"
#include "common/image_cache_manager.h"
#include "common/key_code.h"
#include "dock/input_device.h"
#include "graphic_service.h"
#include "hal_tick.h"
#include "rtc_api.h"
#include "sql_fit.h"
#include "sql_setting.h"
#include "sql_weather.h"
#include "ui_screennotify.h"
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <string>
#include <unordered_set>
using namespace OHOS;
namespace TJD {
#define APP_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_menu_list.bin"
#define FAVORITE_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_main_favorite.bin"
#define COMMON_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_loading.bin"
static ImageAnimatorInfo g_imageAnimator1Info[3] = {};
constexpr int16_t MAIN_VIEW_BLANK_SIZE = 30;
constexpr uint8_t REBOUND_SIZE = 200;
// clang-format off
static inline int16_t HorizontalCenter(int16_t width, int16_t parentWidth) { return (parentWidth - width) / 2; }
static inline int16_t VerticalCenter(int16_t height, int16_t parentHeight) { return (parentHeight - height) / 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);
}
static inline void InitLabelVerCenter(OHOS::UILabel &label, uint8_t size, int16_t x, 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(x, VerticalCenter(label.GetHeight(), target));
}
static inline void SetRotateEnable(OHOS::UIScrollView &view)
{
view.SetThrowDrag(true);
view.SetReboundSize(REBOUND_SIZE);
view.SetYScrollBarVisible(true);
view.SetSwipeACCLevel(10);
view.SetDragACCLevel(15);
}
// clang-format on
typedef struct
{
uint32_t hour;
uint32_t minute;
uint32_t second;
} simple_timer_t;
static uint32_t g_start_time = 0;
static uint32_t g_pause_time = 0;
static uint32_t g_simple_timer_sec_count = 0;
static bool g_timeKeepingIsStart = false;
static simple_timer_t g_simple_timer_time = {};
static uint32_t get_hal_tick_time()
{
struct timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
return time.tv_sec * 1000 + time.tv_nsec / 1000000;
}
static void tjd_service_simple_timer_start(void)
{
g_start_time += get_hal_tick_time() - g_pause_time;
g_pause_time = 0;
}
static void tjd_service_simple_timer_pause(void) { g_pause_time = get_hal_tick_time(); }
static void tjd_service_simple_timer_stop(void)
{
g_simple_timer_sec_count = 0;
g_start_time = 0;
g_pause_time = 0;
}
static uint32_t tjd_service_simple_timer_get_count(void)
{
g_simple_timer_sec_count = get_hal_tick_time() - g_start_time;
return g_simple_timer_sec_count / 1000;
}
const simple_timer_t *tjd_service_simple_timer_get_time(void)
{
uint32_t curTime = tjd_service_simple_timer_get_count();
g_simple_timer_time.hour = curTime / 3600;
g_simple_timer_time.minute = (curTime % 3600) / 60;
g_simple_timer_time.second = (curTime % 3600) % 60;
return &g_simple_timer_time;
}
static std::list<FavoriteModel> g_favoriteModelList_;
#pragma region FavoritePresenter
class FavoritePresenter;
static FavoritePresenter *g_favoritePresenter = nullptr;
class FavoritePresenter : public OHOS::UIView::OnClickListener, public TjdUiScreenDragListener
{
public:
FavoritePresenter();
~FavoritePresenter();
static FavoritePresenter *GetInstance(void) { return g_favoritePresenter; }
bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event);
bool OnDragStart(OHOS::UIView &view, const OHOS::DragEvent &event);
bool OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event);
void ScreenDragEventCallback(OHOS::UIView &view, const OHOS::DragEvent &event)
{
auto favortiteView = TjdUiAppMainPageFavorite::GetInstance();
if (favortiteView == nullptr) {
return;
}
if (favortiteView->currentViewIndex_ == FavoriteViewIndex::SORT_VIEW_INDEX) {
SelectEdit();
} else if (favortiteView->currentViewIndex_ == FavoriteViewIndex::CHOOSE_TOP_MODEL_VIEW_INDEX) {
favortiteView->ShowView(FavoriteViewIndex::SORT_VIEW_INDEX);
}
}
void SetTopModelType(TopModelType type)
{
if (topModelType_ != type) {
topModelType_ = type;
isChange_ = true;
}
};
bool IsPlaying()
{
auto playerModel = TjdUiAppPlayerModel::GetInstance();
if (playerModel->GetPlayerCtr() == nullptr) {
return false;
}
return playerModel->GetPlayerCtr()->IsPlaying();
}
TopModelType GetTopModelType() { return topModelType_; };
void UpdateViewData();
void StartJumpTimer(FavoriteViewIndex jumpView);
void DeleteJumpTimer()
{
if (jumpTimerId_ != nullptr) {
osTimerDelete(jumpTimerId_);
jumpTimerId_ = nullptr;
}
}
std::string &GetTemper() { return temper_; }
uint16_t WeartherType() { return weartherType_; }
std::string &GetHeartRate() { return heartRateStr_; }
uint16_t GetHeartRateLevel() { return heartRateLevel_; }
std::string &GetSpo2() { return spo2Str_; }
uint16_t GetSpo2Level() { return spo2Level_; }
std::string &GetSleepHourTime() { return sleepHourTime_; }
std::string &GetSleepMinuteTime() { return sleepMinuteTime_; }
uint16_t GetSleepLevel() { return sleepLevel_; }
std::string &GetStepCount() { return stepCount_; }
std::string &GetDistance() { return distance_; }
std::string &GetCalorie() { return calorie_; }
uint8_t GetHeartRateValue() { return heartRateValue_; }
uint8_t GetSpo2Value() { return spo2Value_; }
uint32_t GetStepProcess() { return stepProcess; }
void SelectEdit(void)
{
if (isChange_) {
isChange_ = false;
TjdUiAppMainPageFavorite::GetInstance()->ShowView(FavoriteViewIndex::BREAK_VIEW_INDEX);
} else {
TjdUiAppMainPageFavorite::GetInstance()->ShowView(FavoriteViewIndex::MAIN_VIEW_INDEX);
}
}
void SetSortIsChange(bool isChange) { isChange_ = isChange; }
void SelectTopModelIndex(int32_t index) { topModelIndex_ = index; };
int32_t GetTopModelIndex() { return topModelIndex_; }
private:
void SelectTopModel(void)
{
if (TjdUiSettingCenter::GetInstance().IsConnectApp()) {
if (topModelType_ == TopModelType::TOP_MODEL_WEATHER) {
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_WEATHER);
} else if (topModelType_ == TopModelType::TOP_MODEL_VOICE) {
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_VOICE_ASSISTANT);
}
} else {
TjdUiAppSettingModel::GetInstance()->SetShowConnectQrCode(true);
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_SETTING_COMMON_CONNECT,
OHOS::TransitionType::TRANSITION_INVALID,
OHOS::gSliceDefaultPriority, true);
}
}
bool isChange_{false};
int32_t topModelIndex_{0};
TopModelType topModelType_{TOP_MODEL_WEATHER};
std::string temper_;
uint16_t weartherType_;
std::string heartRateStr_;
uint16_t heartRateLevel_;
uint8_t heartRateValue_;
std::string spo2Str_;
uint16_t spo2Level_;
uint8_t spo2Value_;
std::string sleepHourTime_;
std::string sleepMinuteTime_;
uint16_t sleepLevel_;
std::string stepCount_;
std::string distance_;
std::string calorie_;
uint32_t curDistance = 0;
uint32_t totalDistance = 0;
uint32_t stepProcess = 0;
osTimerId_t jumpTimerId_{nullptr};
// bool playerInit_{false};
bool isPlayed_{false};
};
FavoritePresenter::FavoritePresenter() { g_favoritePresenter = this; }
FavoritePresenter::~FavoritePresenter()
{
g_favoritePresenter = nullptr;
/* 如果在副一屏播放过并且没有正在播放再退出页面,则析构音乐资源 */
// if (isPlayed_ && !IsPlaying()) {
auto playerModel = TjdUiAppPlayerModel::GetInstance();
playerModel->PlayerStop();
isPlayed_ = false;
// }
}
bool FavoritePresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
{
std::string viewId = view.GetViewId();
if (viewId.empty()) {
return false;
}
TjdUiAppMainPageFavorite *favoriteView = TjdUiAppMainPageFavorite::GetInstance();
if (favoriteView == nullptr) {
return true;
}
auto playerModel = TjdUiAppPlayerModel::GetInstance();
if (viewId == BTN_EDIT_VIEW_ID) { // 进入编辑按钮
/* 进入编辑的时候备份 */
favoriteView->BackupSortItemView();
favoriteView->ShowView(FavoriteViewIndex::SORT_VIEW_INDEX);
} else if (viewId == BTN_SORT_ENTER_VIEW_ID) { // 编辑按钮确认
SelectEdit();
} else if (viewId == BTN_WEATHER_VIEW_ID) { // 选择顶部模组
favoriteView->ShowView(FavoriteViewIndex::CHOOSE_TOP_MODEL_VIEW_INDEX);
} else if (viewId == BTN_TOP_MODEL_VIEW_ID) {
SelectTopModel();
} else if (viewId == BTN_TOP_MODEL_ENTER_VIEW_ID) {
// 顶部模组选择确定
SetTopModelType(static_cast<TopModelType>(topModelIndex_));
favoriteView->ShowView(FavoriteViewIndex::SORT_VIEW_INDEX);
} else if (viewId == BTN_SAVE_SORT_ENTER_VIEW_ID) {
/* 保存排序 */
auto favoriteModelList = favoriteView->GetFavoriteSortModelViewList();
uint8_t sqlSortItem[FAVORITE_MODEL_MAX_NUM] = {0};
int index = 0;
for (auto &item : favoriteModelList) {
sqlSortItem[index++] = static_cast<uint8_t>(item);
if (index >= FAVORITE_MODEL_MAX_NUM) {
break;
}
}
sql_setting_set_favorite_sort(sqlSortItem);
favoriteView->ShowView(FavoriteViewIndex::SETTING_WAIT_VIEW_INDEX);
favoriteView->SetFavoriteModelList(favoriteModelList);
StartJumpTimer(FavoriteViewIndex::MAIN_VIEW_INDEX);
} else if (viewId == BTN_SAVE_SORT_CLOSE_VIEW_ID) {
/* 取消保存排序 */
favoriteView->ResetSortItemView();
favoriteView->ShowView(FavoriteViewIndex::MAIN_VIEW_INDEX);
} else if (viewId == BTN_PLAYER_LEFT_VIEW_ID) {
playerModel->PreviousPlayout();
} else if (viewId == BTN_PLAYER_RIGHT_VIEW_ID) {
playerModel->LoopingPlayout();
} else if (viewId == BTN_PLAYER_PLAY_VIEW_ID) {
isPlayed_ = true;
/* 初始化音频 */
// if (playerInit_ == false) {
// PlayersListGroup::GetInstance()->SetUpListCase();
// playerModel->PlayerInit();
// playerModel->AudioInit();
// playerInit_ = true;
// }
bool isPlay = favoriteView->GetPlayerButtonState() == UICheckBox::UICheckBoxState::SELECTED;
if (isPlay) {
playerModel->PlayerStart();
} else {
if (playerModel->GetPlayerCtr().get() != nullptr) {
playerModel->GetPlayerCtr()->Pause();
}
}
} else if (viewId == BTN_TIME_OUT_BTN_ID) {
favoriteView->ShowView(FavoriteViewIndex::MAIN_VIEW_INDEX);
}
return false;
}
bool FavoritePresenter::OnDragStart(OHOS::UIView &view, const DragEvent &event)
{
if (event.GetDragDirection() == OHOS::DragEvent::DIRECTION_RIGHT_TO_LEFT ||
event.GetDragDirection() == OHOS::DragEvent::DIRECTION_LEFT_TO_RIGHT) {
TjdUiAppMainPageFavorite::GetInstance()->SetVerticalScroll(false);
} else {
TjdUiAppMainPageFavorite::GetInstance()->SetHorizonalScroll(false);
}
return TjdUiScreenDragListener::OnDragStart(view, event);
};
bool FavoritePresenter::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
{
auto favortiteView = TjdUiAppMainPageFavorite::GetInstance();
favortiteView->SetVerticalScroll(true);
favortiteView->SetHorizonalScroll(true);
if (favortiteView->currentViewIndex_ == FavoriteViewIndex::MAIN_VIEW_INDEX) {
favortiteView->SetViewSetIntercept(false);
}
return TjdUiScreenDragListener::OnDragEnd(view, event);
}
static std::string AssertZero(int32_t value)
{
if (value == 0) {
return "-";
}
return std::to_string(value);
}
static std::string AssertFloatValueToZero(float value)
{
if (value == 0) {
return "-";
}
std::ostringstream oss;
oss << std::fixed << std::setprecision(2) << value;
return oss.str();
}
void FavoritePresenter::UpdateViewData()
{
auto type = static_cast<WeatherInfo>(sql_weather_get_forecast_protocol_value(0));
// clang-format off
switch (type) {
case WeatherInfo::SQL_SUNNY: weartherType_ = STR_ID_253;break;
case WeatherInfo::SQL_PARTLY_CLOUDY: weartherType_ = STR_ID_254;break;
case WeatherInfo::SQL_CLOUDY: weartherType_ = STR_ID_255;break;
case WeatherInfo::SQL_LIGHT_RAIN: weartherType_ = STR_ID_256;break;
case WeatherInfo::SQL_MODERATE_RAIN: weartherType_ = STR_ID_257;break;
case WeatherInfo::SQL_HEAVY_RAIN: weartherType_ = STR_ID_258;break;
case WeatherInfo::SQL_SHOWER: weartherType_ = STR_ID_259;break;
case WeatherInfo::SQL_THUNDERSTORM: weartherType_ = STR_ID_260;break;
case WeatherInfo::SQL_SNOWY: weartherType_ = STR_ID_261;break;
case WeatherInfo::SQL_FOGGY: weartherType_ = STR_ID_262;break;
case WeatherInfo::SQL_DUSTSTORM: weartherType_ = STR_ID_263;break;
case WeatherInfo::SQL_TYPHOON: weartherType_ = STR_ID_264;break;
default: weartherType_ = STR_ID_253;break;
}
// clang-format on
struct rtc_time time;
tjd_driver_rtc_get_ops()->get_rtc_time(&time);
auto temperMax = AssertZero(sql_weather_get_forecast_temperature_max(0));
auto temperMin = AssertZero(sql_weather_get_forecast_temperature_min(0));
if (temperMin != "-" && temperMin != "-") {
temper_ = temperMin + "°C-" + temperMax + "°C";
} else {
temper_ = "-";
}
heartRateStr_ = AssertZero(sql_fit_get_last_hr(time.tm_wday));
heartRateValue_ = sql_fit_get_last_hr(time.tm_wday);
switch (heartRateValue_) {
case 40 ... 69:
heartRateLevel_ = STR_ID_604;
break;
case 70 ... 120:
heartRateLevel_ = STR_ID_605;
break;
case 121 ... 140:
heartRateLevel_ = STR_ID_606;
break;
default:
heartRateLevel_ = STR_ID_607;
break;
}
spo2Str_ = AssertZero(sql_fit_get_spo2_curdata(time.tm_wday));
spo2Value_ = sql_fit_get_spo2_curdata(time.tm_wday);
switch (spo2Value_) {
case 90 ... 100:
spo2Level_ = STR_ID_608;
break;
default:
spo2Level_ = STR_ID_607;
break;
}
uint32_t sleepMin;
if (time.tm_wday == 0)
sleepMin = sql_fit_get_total_sleep_daydata(6).mins_total;
else
sleepMin = sql_fit_get_total_sleep_daydata(time.tm_wday - 1).mins_total;
int sleepHour = (int)(sleepMin / 60);
int sleepMinute = (int)(sleepMin % 60);
switch (sleepHour) {
case 6 ... 9:
sleepLevel_ = STR_ID_609;
break;
case 3 ... 5:
sleepLevel_ = STR_ID_610;
break;
default:
sleepLevel_ = STR_ID_607;
break;
}
sleepHourTime_ = AssertZero(sleepHour);
sleepMinuteTime_ = AssertZero(sleepMinute);
if (sleepMinuteTime_ != "-") {
std::ostringstream oss;
oss << std::setw(2) << std::setfill('0') << sleepMinuteTime_;
sleepMinuteTime_ = oss.str();
} else {
sleepMinuteTime_ = "--";
}
stepCount_ = AssertZero(sql_fit_get_day_step(time.tm_wday));
curDistance = sql_fit_get_day_distance(time.tm_wday);
totalDistance = sql_fit_get_goalStepNum_data();
stepProcess = curDistance / totalDistance * 100 >= 100 ? 100 : curDistance / totalDistance * 100;
distance_ = AssertFloatValueToZero(curDistance / 1000.0f);
calorie_ = AssertZero(sql_fit_get_day_calorie(time.tm_wday));
}
void FavoritePresenter::StartJumpTimer(FavoriteViewIndex jumpView)
{
if (jumpTimerId_ == nullptr) {
jumpTimerId_ = osTimerNew(
[](void *arg) {
FavoriteViewIndex jumpView = static_cast<FavoriteViewIndex>(reinterpret_cast<intptr_t>(arg));
GraphicService::GetInstance()->PostGraphicEvent([jumpView]() {
TjdUiAppMainPageFavorite *favoriteView = TjdUiAppMainPageFavorite::GetInstance();
FavoritePresenter *presenter = FavoritePresenter::GetInstance();
if (favoriteView == nullptr) {
return;
}
favoriteView->ShowView(jumpView);
presenter->DeleteJumpTimer();
});
},
osTimerOnce, reinterpret_cast<void *>(static_cast<intptr_t>(jumpView)), nullptr);
if (jumpTimerId_ == nullptr) {
return;
}
}
int32_t ret = osTimerStart(jumpTimerId_, 2000);
if (ret != 0) {
return;
}
}
class FavoriteAppOnClickListener : public OHOS::UIView::OnClickListener
{
public:
FavoriteAppOnClickListener(std::function<bool(OHOS::UIView &view, const OHOS::ClickEvent &event)> onClick)
: onClick_(onClick)
{}
bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
{
if (onClick_ != nullptr) {
return onClick_(view, event);
}
return false;
}
private:
std::function<bool(OHOS::UIView &view, const OHOS::ClickEvent &event)> onClick_;
};
#pragma endregion
#pragma region 排序子项
SortItemView::SortItemView(int16_t y, int16_t index, uint16_t textId, OHOS::UIView::OnClickListener *listener)
{
auto &images = OHOS::ImageCacheManager::GetInstance();
textId_ = textId;
SetPosition(8, y, 450, 110);
SetStyle(STYLE_BACKGROUND_OPA, 0xff);
SetStyle(STYLE_BORDER_RADIUS, 55);
SetStyle(STYLE_BACKGROUND_COLOR, 0xff262626);
SetViewIndex(index);
up_.SetTouchable(true);
up_.SetOnClickListener(listener);
up_.SetPosition(293, 32, 46, 46);
up_.SetViewId(BTN_UP_VIEW_ID);
if (index == 0) {
up_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_UP1, FAVORITE_IMAGE_BIN_PATH));
} else {
up_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_UP, FAVORITE_IMAGE_BIN_PATH));
}
down_.SetTouchable(true);
down_.SetOnClickListener(listener);
down_.SetPosition(360, 32, 46, 46);
down_.SetViewId(BTN_DOWN_VIEW_ID);
if (index == 4) {
down_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_DOWN1, FAVORITE_IMAGE_BIN_PATH));
} else {
down_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_DOWN, FAVORITE_IMAGE_BIN_PATH));
}
name_.SetTextId(textId_);
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
name_.Resize(220, GetHeight());
name_.SetPosition(51, 0);
name_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
name_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER);
Add(&name_);
Add(&up_);
Add(&down_);
}
#pragma endregion
#pragma region 总界面
static TjdUiAppMainPageFavorite *g_favoritePage = nullptr;
TjdUiAppMainPageFavorite::TjdUiAppMainPageFavorite()
{
SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
g_favoritePresenter = new FavoritePresenter();
FavoritePresenter::GetInstance()->UpdateViewData();
g_favoritePage = this;
}
TjdUiAppMainPageFavorite::~TjdUiAppMainPageFavorite()
{
UnLoad();
auto view = dynamic_cast<FavoriteMainView *>(viewManager_[FavoriteViewIndex::MAIN_VIEW_INDEX]);
if (view != nullptr) {
view->musicModel_.StopAnimator();
}
if (g_favoritePage != nullptr) {
delete g_favoritePresenter;
g_favoritePresenter = nullptr;
}
tjd_service_simple_timer_stop();
g_timeKeepingIsStart = false;
}
TjdUiAppMainPageFavorite *TjdUiAppMainPageFavorite::GetInstance(void) { return g_favoritePage; }
static void BleConnectStateEvent(bool isConnect)
{
auto favortiteView = TjdUiAppMainPageFavorite::GetInstance();
if (favortiteView == nullptr) {
return;
}
favortiteView->BleStateChanged(isConnect);
}
void TjdUiAppMainPageFavorite::PreLoad(void)
{
if (!viewiInitStatus) {
InitView();
TjdCardId pageid = TjdUiAppMainView::GetInstance()->GetHorCurrentCard();
if (pageid == TjdCardId::TJD_CARD_FAVORITE) {
auto view = dynamic_cast<FavoriteMainView *>(viewManager_[FavoriteViewIndex::MAIN_VIEW_INDEX]);
if (view != nullptr) {
TjdUiUtils::ViewRequestFocus(*view);
}
}
viewiInitStatus = true;
TjdUiSettingCenter::GetInstance().RegisterBleConnectStateCallback(BleConnectStateEvent);
}
}
bool TjdUiAppMainPageFavorite::OnKeyEvent(const OHOS::KeyEvent &event)
{
uint8_t state = event.GetState();
OHOS::ZliteKeyCode keyId = static_cast<OHOS::ZliteKeyCode>(event.GetKeyId());
if (state != OHOS::InputDevice::STATE_RELEASE || keyId != ZliteKeyCode::ZLITE_KEY_TJD_RIGHTUP) {
return true;
}
auto presenter = FavoritePresenter::GetInstance();
if (presenter == nullptr) {
return true;
}
if (currentViewIndex_ == FavoriteViewIndex::MAIN_VIEW_INDEX) {
if (viewManager_[currentViewIndex_])
viewManager_[currentViewIndex_]->ClearFocus();
return false;
} else if (currentViewIndex_ == FavoriteViewIndex::SORT_VIEW_INDEX) {
presenter->SelectEdit();
} else if (currentViewIndex_ == FavoriteViewIndex::CHOOSE_TOP_MODEL_VIEW_INDEX) {
ShowView(FavoriteViewIndex::SORT_VIEW_INDEX);
}
return true;
}
void TjdUiAppMainPageFavorite::UnLoad(void)
{
TjdUiSettingCenter::GetInstance().UnregisterBleConnectStateCallback(BleConnectStateEvent);
set_back_to_home_interval(5);
if (viewiInitStatus) {
ImageCacheManager::GetInstance().UnloadAllInMultiRes(APP_IMAGE_BIN_PATH);
ImageCacheManager::GetInstance().UnloadAllInMultiRes(FAVORITE_IMAGE_BIN_PATH);
ImageCacheManager::GetInstance().UnloadAllInMultiRes(COMMON_IMAGE_BIN_PATH);
RemoveAll();
if (viewManager_[currentViewIndex_])
viewManager_[currentViewIndex_]->ClearFocus();
if (mainView_ != nullptr) {
mainView_->RemoveAll();
delete mainView_;
mainView_ = nullptr;
}
for (int i = 0; i < FavoriteViewIndex::FAVORITE_UNKNOWN; i++) {
if (viewManager_[i] != nullptr) {
delete viewManager_[i];
viewManager_[i] = nullptr;
}
}
viewiInitStatus = false;
}
}
bool TjdUiAppMainPageFavorite::InitView(void)
{
uint32_t startTime = OHOS::HALTick::GetInstance().GetTime();
uint32_t end = 0;
ImageCacheManager::GetInstance().LoadAllInMultiRes(FAVORITE_IMAGE_BIN_PATH);
ImageCacheManager::GetInstance().LoadAllInMultiRes(COMMON_IMAGE_BIN_PATH);
end = OHOS::HALTick::GetInstance().GetElapseTime(startTime);
static_print_debug("LoadAllInMultiRes time %d", end);
mainView_ = new OHOS::UIScrollView();
mainView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
g_favoriteModelList_.clear();
uint8_t sqlSortItem[FAVORITE_MODEL_MAX_NUM] = {0};
sql_setting_get_favorite_sort(sqlSortItem);
// 判断sqlSortItem是否有重复
bool isRepeat = false;
std::unordered_set<uint8_t> sqlSortItemSet;
for (int i = 0; i < FAVORITE_MODEL_MAX_NUM; i++) {
if (sqlSortItemSet.find(sqlSortItem[i]) != sqlSortItemSet.end()) {
isRepeat = true;
break;
}
sqlSortItemSet.insert(sqlSortItem[i]);
}
if (isRepeat) {
sqlSortItem[0] = FavoriteModel::MUSIC_MODEL;
sqlSortItem[1] = FavoriteModel::HEALTH_MODEL;
sqlSortItem[2] = FavoriteModel::SLEEP_MODEL;
sqlSortItem[3] = FavoriteModel::MOTION_MODEL;
sqlSortItem[4] = FavoriteModel::TIMEKEEPING_MODEL;
}
for (int i = 0; i < FAVORITE_MODEL_MAX_NUM; i++) {
g_favoriteModelList_.push_back({static_cast<FavoriteModel>(sqlSortItem[i])});
}
Add(mainView_);
ShowView(FavoriteViewIndex::MAIN_VIEW_INDEX);
end = OHOS::HALTick::GetInstance().GetElapseTime(startTime);
static_print_debug("TjdUiAppMainPageFavorite::InitView time %d", end);
return true;
}
void TjdUiAppMainPageFavorite::ScrollBegin(bool isActive)
{
if (viewManager_[currentViewIndex_])
viewManager_[currentViewIndex_]->ClearFocus();
}
void TjdUiAppMainPageFavorite::ScrollEnd(bool isActive)
{
auto presenter = FavoritePresenter::GetInstance();
if (presenter == nullptr) {
return;
}
presenter->UpdateViewData();
if (isActive) {
auto mainView = dynamic_cast<FavoriteMainView *>(viewManager_[FavoriteViewIndex::MAIN_VIEW_INDEX]);
if (mainView == nullptr) {
return;
}
TjdUiUtils::ViewRequestFocus(*mainView);
TjdUiAppMainPageFavorite::GetInstance()->FavoriteClockTick();
// if (playerInit_ == false) {
auto playerModel = TjdUiAppPlayerModel::GetInstance();
PlayersListGroup::GetInstance()->SetUpListCase();
playerModel->PlayerInit();
// playerInit_ = true;
// }
mainView->musicModel_.UpdateInfo(playerModel);
}
}
void TjdUiAppMainPageFavorite::FavoriteClockTick(void)
{
struct rtc_time time;
tjd_driver_rtc_get_ops()->get_rtc_time(&time);
auto mainView = dynamic_cast<FavoriteMainView *>(viewManager_[FavoriteViewIndex::MAIN_VIEW_INDEX]);
if (mainView == nullptr) {
return;
} // VIEW在Presenter后创建有空针风险。
char timeStr[6];
sprintf(timeStr, "%02d:%02d", time.tm_hour, time.tm_min);
mainView->time_.SetText(timeStr);
mainView->timekeepingModel_.AddTimekeeping();
if (HALTick::GetInstance().GetElapseTime(mainView->startTime_) >= 1000) {
mainView->UpdateData(); // 1s更新一次数据
mainView->startTime_ = HALTick::GetInstance().GetTime();
}
auto playerModel = TjdUiAppPlayerModel::GetInstance();
bool isPlay = GetPlayerButtonState() == UICheckBox::UICheckBoxState::SELECTED;
if (isPlay) {
mainView->musicModel_.UpdateInfo(playerModel);
}
}
void TjdUiAppMainPageFavorite::SetViewSetIntercept(bool isIntercept) { SetIntercept(isIntercept); }
OHOS::UICheckBox::UICheckBoxState TjdUiAppMainPageFavorite::GetPlayerButtonState()
{
auto mainView = dynamic_cast<FavoriteMainView *>(viewManager_[FavoriteViewIndex::MAIN_VIEW_INDEX]);
if (mainView == nullptr) {
return OHOS::UICheckBox::UICheckBoxState::UNSELECTED;
}
return mainView->GetMusicModelPlayState();
}
void TjdUiAppMainPageFavorite::BleStateChanged(bool isConnect)
{
auto mainView = dynamic_cast<FavoriteMainView *>(viewManager_[FavoriteViewIndex::MAIN_VIEW_INDEX]);
if (mainView == nullptr) {
return;
}
if (isConnect) {
mainView->topModel_.SetType(FavoritePresenter::GetInstance()->GetTopModelType());
} else {
mainView->topModel_.SetType(TopModelType::TOP_MODEL_DISCONNECTED);
}
}
static int FindTargetResource(uint16_t app)
{
TjdUiAppListModel &appListModel = TjdUiAppListModel::GetInstance();
const TjdAppItem *appList = appListModel.GetApplistItems();
if (appList == nullptr) {
return 0;
}
for (uint8_t i = 0; i < appListModel.GetAppListNum(); i++) {
if (appList[i].appItem.id == app) {
return appList[i].resId;
}
}
return 0;
}
void TjdUiAppMainPageFavorite::InitTargetView(FavoriteViewIndex index)
{
if (viewManager_[index] != nullptr) {
return;
}
// clang-format off
switch (index) {
case MAIN_VIEW_INDEX: viewManager_[index] = new FavoriteMainView(); break;
case SORT_VIEW_INDEX: viewManager_[index] = new FavoriteSortModelView(); break;
case CHOOSE_TOP_MODEL_VIEW_INDEX: viewManager_[index] = new FavoriteChooseTopModelView(); break;
case BREAK_VIEW_INDEX: viewManager_[index] = new FavoriteBreakView(); break;
case SETTING_WAIT_VIEW_INDEX: viewManager_[index] = new FavoriteSettingWaitView(); break;
case TIME_OUT_VIEW: viewManager_[index] = new TimeOutView(); break;
default: break;
}
// clang-format on
if (viewManager_[index] == nullptr) {
return;
}
viewManager_[index]->SetPosition(0, 0);
viewManager_[index]->SetVisible(false);
mainView_->Add(viewManager_[index]);
}
void TjdUiAppMainPageFavorite::ShowView(FavoriteViewIndex showIndex)
{
if (showIndex < 0 || showIndex >= FavoriteViewIndex::FAVORITE_UNKNOWN) {
return;
}
InitTargetView(showIndex);
if (currentViewIndex_ >= 0 && currentViewIndex_ < FavoriteViewIndex::FAVORITE_UNKNOWN &&
viewManager_[currentViewIndex_] != nullptr) {
viewManager_[currentViewIndex_]->HideView();
}
if (showIndex != FavoriteViewIndex::MAIN_VIEW_INDEX) {
SetViewSetIntercept(true);
}
if (viewManager_[showIndex] != nullptr) {
viewManager_[showIndex]->ShowView();
}
currentViewIndex_ = showIndex;
}
void TjdUiAppMainPageFavorite::SetFavoriteModelList(std::list<FavoriteModel> &favoriteModelList)
{
g_favoriteModelList_.clear();
for (auto &item : favoriteModelList) {
g_favoriteModelList_.emplace_back(item);
}
}
std::list<FavoriteModel> &TjdUiAppMainPageFavorite::GetFavoriteModelList() { return g_favoriteModelList_; }
std::list<FavoriteModel> &TjdUiAppMainPageFavorite::GetFavoriteSortModelViewList()
{
auto sortView = dynamic_cast<FavoriteSortModelView *>(viewManager_[FavoriteViewIndex::SORT_VIEW_INDEX]);
if (sortView == nullptr) {
return g_favoriteModelList_;
}
return sortView->GetModelSortList();
}
void TjdUiAppMainPageFavorite::SetHorizonalScroll(bool isHorizonal)
{
dynamic_cast<FavoriteMainView *>(viewManager_[FavoriteViewIndex::MAIN_VIEW_INDEX])
->SetHorizontalScrollState(isHorizonal);
}
void TjdUiAppMainPageFavorite::SetVerticalScroll(bool isVertical)
{
dynamic_cast<FavoriteMainView *>(viewManager_[FavoriteViewIndex::MAIN_VIEW_INDEX])
->SetVerticalScrollState(isVertical);
}
void TjdUiAppMainPageFavorite::BackupSortItemView()
{
backupTopModelType_ = FavoritePresenter::GetInstance()->GetTopModelType();
}
void TjdUiAppMainPageFavorite::ResetSortItemView()
{
FavoritePresenter::GetInstance()->SetTopModelType(backupTopModelType_);
}
#pragma endregion
#pragma region 模组
#pragma region 顶部模组
FavoriteTopModel::FavoriteTopModel()
{
listener_ = new FavoriteAppOnClickListener([](OHOS::UIView &view, const OHOS::ClickEvent &event) -> bool {
int sliceId = view.GetViewIndex();
if (sliceId == 0) {
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_LIST);
return false;
}
OHOS::NativeAbility::GetInstance().ChangeSlice(sliceId);
return false;
});
ImageCacheManager &imgManager = ImageCacheManager::GetInstance();
Resize(366, 343);
topModel_.SetPosition(0, 0, 366, 126);
bg_.SetPosition(0, 0, 366, 126);
SetType(FavoritePresenter::GetInstance()->GetTopModelType());
topModelAppList_.resize(6);
std::list<uint16_t> &sliceData = OHOS::NativeAbility::GetInstance().GetRecentAppsList();
std::vector<uint16_t> result;
// 从链表尾部(最新)向头部遍历
auto rit = sliceData.rbegin(); // 反向迭代器
for (int i = 0; i < 5 && rit != sliceData.rend(); ++i, ++rit) {
result.push_back(*rit);
}
int arrIndex = 0;
std::unordered_set<uint16_t> existingItems;
for (auto item : result) {
if (existingItems.find(item) == existingItems.end()) {
topModelAppList_[arrIndex++] = item;
existingItems.insert(item);
if (arrIndex >= 5) {
break;
}
}
}
// 如果前 5 个位置未填满,使用 tmpAppid 填充
const uint16_t tmpAppid[5] = {TJD_APP_VIEW_HR, TJD_APP_VIEW_SPO2, TJD_APP_VIEW_SPORT, TJD_APP_VIEW_SLEEP,
TJD_APP_VIEW_WEATHER};
for (int i = 0; i < 5 && arrIndex < 5; ++i) {
uint16_t addAppid = tmpAppid[i];
if (existingItems.find(addAppid) == existingItems.end()) {
topModelAppList_[arrIndex++] = addAppid;
existingItems.insert(addAppid);
}
}
/* 最后添加0第6位的0是固定的 */
topModelAppList_.emplace_back(0);
topModel_.SetViewId(BTN_TOP_MODEL_VIEW_ID);
topModel_.SetTouchable(true);
topModel_.SetOnClickListener(FavoritePresenter::GetInstance());
topModel_.Add(&bg_);
topModel_.Add(&topModelIcon_);
topModel_.Add(&descOne_);
topModel_.Add(&descTwo_);
Add(&topModel_);
float targetSize = 88.0f;
int16_t startX = 32;
int16_t startY = 19 + 126;
int16_t widthInterval = 28;
int16_t heightInterval = 14;
// 添加6个应用每个应用占用88*88的区域每三个应用换行
OHOS::ImageInfo *imgInfo = nullptr;
for (int i = 0; i < 6; ++i) {
OHOS::UIImageView &appView = appIcon_[i];
appView.SetPosition(startX + (i % 3) * (targetSize + widthInterval),
startY + (i / 3) * (targetSize + heightInterval), targetSize, targetSize);
appView.SetViewIndex(topModelAppList_[i]);
appView.SetTouchable(true);
appView.SetOnClickListener(listener_);
if (topModelAppList_[i] == 0) {
imgInfo = imgManager.LoadOneInMultiRes(IMG_MAIN_FAVORITE_MORE, FAVORITE_IMAGE_BIN_PATH);
} else {
imgInfo = imgManager.LoadOneInMultiRes(FindTargetResource(topModelAppList_[i]), APP_IMAGE_BIN_PATH);
}
if (i < 5) {
appView.Scale({targetSize / imgInfo->header.width, targetSize / imgInfo->header.width}, {0, 0});
}
if (imgInfo != nullptr) {
appView.SetSrc(imgInfo);
}
Add(&appView);
}
}
FavoriteTopModel::~FavoriteTopModel()
{
RemoveAll();
topModel_.RemoveAll();
// topModelAppList_.clear();
delete listener_;
}
void FavoriteTopModel::SetType(TopModelType type)
{
switch (type) {
case TOP_MODEL_DISCONNECTED:
SetDisconnectType();
break;
case TOP_MODEL_WEATHER:
SetWeatherType();
break;
case TOP_MODEL_VOICE:
SetVoiceType();
break;
default:
break;
}
}
uint16_t FavoriteTopModel::GetGreeting(int hour)
{
if (hour > 5 && hour <= 8) {
return STR_ID_620;
} else if (hour > 8 && hour <= 11) {
return STR_ID_621;
} else if (hour > 11 && hour <= 13) {
return STR_ID_622;
} else if (hour > 13 && hour <= 18) {
return STR_ID_623;
} else {
return STR_ID_624;
}
}
void FavoriteTopModel::SetDisconnectType()
{
OHOS::ImageCacheManager &images = OHOS::ImageCacheManager::GetInstance();
bg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_CONNECTION, FAVORITE_IMAGE_BIN_PATH));
topModelIcon_.SetPosition(34, 38, 48, 48);
topModelIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_TISHI, FAVORITE_IMAGE_BIN_PATH));
descOne_.SetTextId(STR_ID_625);
descOne_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
descOne_.SetPosition(100, 42, 230, 45);
descOne_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
descOne_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER);
descOne_.SetVisible(true);
descTwo_.SetVisible(false);
}
void FavoriteTopModel::SetWeatherType()
{
OHOS::ImageCacheManager &images = OHOS::ImageCacheManager::GetInstance();
bg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_WEATHER, FAVORITE_IMAGE_BIN_PATH));
topModelIcon_.SetPosition(53, 20, 88, 88);
topModelIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_W_02, FAVORITE_IMAGE_BIN_PATH));
descOne_.SetTextId(FavoritePresenter::GetInstance()->WeartherType());
descOne_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
descOne_.Resize(180, (topModel_.GetHeight() >> 1));
descOne_.SetPosition(topModelIcon_.GetX() + topModelIcon_.GetWidth() + 10, 0);
descOne_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
descOne_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_BOTTOM);
descTwo_.SetText(FavoritePresenter::GetInstance()->GetTemper().c_str());
descTwo_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
descTwo_.Resize(180, (topModel_.GetHeight() >> 1));
descTwo_.SetPosition(descOne_.GetX(), (topModel_.GetHeight() >> 1));
descTwo_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
descTwo_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP);
descTwo_.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE);
descOne_.SetVisible(true);
descTwo_.SetVisible(true);
}
void FavoriteTopModel::SetVoiceType()
{
OHOS::ImageCacheManager &images = OHOS::ImageCacheManager::GetInstance();
rtc_time time;
tjd_driver_rtc_get_ops()->get_rtc_time(&time);
bg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_VOICE, FAVORITE_IMAGE_BIN_PATH));
topModelIcon_.SetPosition(46, 15, 90, 90);
topModelIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_ICON_VOICE, FAVORITE_IMAGE_BIN_PATH));
descOne_.SetTextId(GetGreeting(time.tm_hour));
descOne_.SetFont(TJD_VECTOR_FONT_FILENAME, 36);
descOne_.Resize(180, (topModel_.GetHeight() >> 1));
descOne_.SetPosition(topModelIcon_.GetX() + topModelIcon_.GetWidth() + 10, 0);
descOne_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
descOne_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_BOTTOM);
descTwo_.SetTextId(STR_ID_86);
descTwo_.SetFont(TJD_VECTOR_FONT_FILENAME, 30);
descTwo_.Resize(180, (topModel_.GetHeight() >> 1));
descTwo_.SetPosition(descOne_.GetX(), (topModel_.GetHeight() >> 1));
descTwo_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
descTwo_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_TOP);
descTwo_.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
descOne_.SetVisible(true);
descTwo_.SetVisible(true);
}
#pragma endregion
#pragma region 音乐模组
FavoriteMusicModel::FavoriteMusicModel()
{
auto &images = OHOS::ImageCacheManager::GetInstance();
Resize(400, 180);
lrcParser_ = new LrcParser();
const int animatorRes[3] = {IMG_MAIN_FAVORITE_BEAT_DT_01_10, IMG_MAIN_FAVORITE_BEAT_DT_02_10,
IMG_MAIN_FAVORITE_BEAT_DT_03_10};
OHOS::ImageAnimatorInfo baseinfo = {nullptr, {324, 33}, 43, 28, OHOS::IMG_SRC_IMAGE_INFO};
for (int i = 0; i < 3; ++i) {
g_imageAnimator1Info[i] = baseinfo;
g_imageAnimator1Info[i].imageInfo =
ImageCacheManager::GetInstance().LoadOneInMultiRes(animatorRes[i], FAVORITE_IMAGE_BIN_PATH);
}
imageAnimator_.SetPosition(324, 33, 43, 28);
imageAnimator_.SetImageAnimatorSrc(g_imageAnimator1Info, 3, 100);
imageAnimator_.SetTimeOfPause(100);
imageAnimator_.Start();
// SetStyle(STYLE_BACKGROUND_OPA, 0xff);
// SetStyle(STYLE_BACKGROUND_COLOR, 0xff262626);
// SetStyle(STYLE_BORDER_RADIUS, 63);
musicBg_.SetPosition(0, 0, 400, 180);
musicBg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_MUSIC, FAVORITE_IMAGE_BIN_PATH));
musicIcon_.SetPosition(43, 15, 25, 25);
musicIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_MUSIC, FAVORITE_IMAGE_BIN_PATH));
song_.SetFont(TJD_VECTOR_FONT_FILENAME, 20);
song_.SetText("...");
song_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
song_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
song_.SetPosition(83, 15, 111, 19);
song_.SetStyle(STYLE_TEXT_COLOR, 0xFF265CFD);
lyric_.SetFont(TJD_VECTOR_FONT_FILENAME, 24);
lyric_.SetText("...");
lyric_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE);
lyric_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER);
lyric_.SetPosition(43, 55, 250, 36);
currentTime_.SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 18);
currentTime_.SetText("00:32");
currentTime_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
currentTime_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
currentTime_.SetPosition(41, 95, 40, 14);
currentTime_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.6);
totalTime_.SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 18);
totalTime_.SetText("04:16");
totalTime_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
totalTime_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
totalTime_.SetPosition(329, 95, 37, 14);
totalTime_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.6);
progress_.SetPosition(90, 101, 221, 20);
progress_.SetStyle(STYLE_BACKGROUND_OPA, 0);
progress_.SetStyle(STYLE_BORDER_RADIUS, 6);
progress_.SetValidWidth(220);
progress_.SetValidHeight(4);
progress_.SetKnobWidth(20);
progress_.SetSliderColor(Color::GetColorFromRGBA(78, 86, 111, 0xff), Color::GetColorFromRGBA(255, 255, 255, 0xff));
progress_.SetKnobImage(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_KNODE, FAVORITE_IMAGE_BIN_PATH));
progress_.SetValue(60);
progress_.SetTouchable(false);
leftIcon_.SetPosition(82, 139, 48, 51);
leftIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_L, FAVORITE_IMAGE_BIN_PATH));
leftIcon_.SetTouchable(true);
leftIcon_.SetViewId(BTN_PLAYER_LEFT_VIEW_ID);
leftIcon_.SetOnClickListener(FavoritePresenter::GetInstance());
leftIcon_.SetAutoEnable(false);
leftIcon_.SetResizeMode(OHOS::UIImageView::ImageResizeMode::CENTER);
rightIcon_.SetPosition(334, 139, 45, 51);
rightIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_R, FAVORITE_IMAGE_BIN_PATH));
rightIcon_.SetTouchable(true);
rightIcon_.SetViewId(BTN_PLAYER_RIGHT_VIEW_ID);
rightIcon_.SetOnClickListener(FavoritePresenter::GetInstance());
rightIcon_.SetAutoEnable(false);
rightIcon_.SetResizeMode(OHOS::UIImageView::ImageResizeMode::CENTER);
playIcon_.SetPosition(185, 130, 30, 34);
playIcon_.SetImages(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_PAUSE, FAVORITE_IMAGE_BIN_PATH),
images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_START, FAVORITE_IMAGE_BIN_PATH));
playIcon_.SetTouchable(true);
playIcon_.SetViewId(BTN_PLAYER_PLAY_VIEW_ID);
playIcon_.SetOnClickListener(FavoritePresenter::GetInstance());
Add(&musicBg_);
Add(&musicIcon_);
Add(&playIcon_);
Add(&leftIcon_);
Add(&rightIcon_);
Add(&song_);
Add(&lyric_);
Add(&progress_);
Add(&totalTime_);
Add(&currentTime_);
Add(&imageAnimator_);
}
void FavoriteMusicModel::StopAnimator(void) { imageAnimator_.Stop(); }
void FavoriteMusicModel::UpdateInfo(TjdUiAppPlayerModel *playerModel)
{
if (playerModel == nullptr) {
return;
}
std::string musicName = PlayersListGroup::GetInstance()->GetCase(playerModel->GetCurrentIndex());
if (musicName.empty()) {
return;
}
song_.SetText(musicName.c_str());
std::string path = TJD_FS_DIR_MUSIC;
std::string pureName = musicName.substr(0, musicName.rfind("."));
path += "/";
path += pureName;
path += ".lrc";
lrcParser_->parseLrc(path.c_str());
// 获取歌曲当前播放时间
uint64_t totalTime = playerModel->GetDuration();
uint64_t curTime = playerModel->GetCurrentPosition();
currentTime_.SetText(ConvertToTimeFormat(curTime).c_str());
totalTime_.SetText(ConvertToTimeFormat(totalTime).c_str());
if (totalTime == 0)
progress_.SetValue(4);
else
progress_.SetValue(static_cast<int>(curTime * 100 / totalTime));
if (curTime > (uint64_t)(lrcParser_->duration() + 1000)) {
return;
}
if (lrcParser_->seek(curTime)) {
LyricPacket data = lrcParser_->readPacket();
if (data.isEmpty()) {
return;
}
if (lrc_ == data.lyric) {
return;
}
lyric_.SetText(data.lyric.c_str());
lrc_ = data.lyric;
}
}
std::string FavoriteMusicModel::ConvertToTimeFormat(uint64_t Seconds)
{
uint64_t minutes = Seconds / 1000 / 60; // 计算分钟数
uint64_t seconds = Seconds / 1000 % 60; // 计算剩余的秒数
// 使用setw设置宽度setfill设置填充字符确保分钟和秒都是两位数
std::stringstream ss;
ss << std::setw(2) << std::setfill('0') << minutes << ":" << std::setw(2) << std::setfill('0') << seconds;
return ss.str();
}
#pragma endregion
#pragma region 健康模组
FavoriteHealthModel::FavoriteHealthModel()
{
auto &images = OHOS::ImageCacheManager::GetInstance();
Resize(400, 378);
healthModel_.SetPosition(0, 0, 400, 180);
bloodOxygenModel_.SetPosition(0, 198, 400, 180);
healthBg_.SetPosition(0, 0, 400, 180);
healthBg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_HR, FAVORITE_IMAGE_BIN_PATH));
healthIcon_.SetPosition(41, 16, 28, 23);
healthIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_HR_ICON, FAVORITE_IMAGE_BIN_PATH));
healthValue_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 42);
healthValue_.SetText("100");
healthValue_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
healthValue_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
healthValue_.SetPosition(42, 52 - 12, 61, 32);
healthUnit_.SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 30);
healthUnit_.SetText("bpm");
healthUnit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
healthUnit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
healthUnit_.SetPosition(112, 58, 51, 26);
healthUnit_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
healthLevel_.SetFont(TJD_VECTOR_FONT_FILENAME, 24);
healthLevel_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
healthLevel_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
healthLevel_.SetPosition(226, 61 - 12, 51, 26);
healthLevel_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
healthTitle_.SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 18);
healthTitle_.SetText("HEART RATE");
healthTitle_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
healthTitle_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
healthTitle_.SetPosition(83, 23, 93, 14);
healthTitle_.SetStyle(STYLE_TEXT_COLOR, 0XFFEA3D35);
healthTitle_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.8);
healthPic_.SetPosition(25, 97, 350, 60);
healthPic_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_HR_PICTURE, FAVORITE_IMAGE_BIN_PATH));
healthModel_.Add(&healthBg_);
healthModel_.Add(&healthIcon_);
healthModel_.Add(&healthValue_);
healthModel_.Add(&healthUnit_);
healthModel_.Add(&healthLevel_);
healthModel_.Add(&healthPic_);
healthModel_.Add(&healthTitle_);
spo2Bg_.SetPosition(0, 0, 400, 180);
spo2Bg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_SPO2, FAVORITE_IMAGE_BIN_PATH));
spo2Icon_.SetPosition(40, 12, 30, 30);
spo2Icon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_SPO2_ICON, FAVORITE_IMAGE_BIN_PATH));
spo2Value_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 42);
spo2Value_.SetText("96");
spo2Value_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
spo2Value_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
spo2Value_.SetPosition(42, 50 - 12, 41, 32);
spo2Unit_.SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 30);
spo2Unit_.SetText("%");
spo2Unit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
spo2Unit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
spo2Unit_.SetPosition(98, 61, 51, 26);
spo2Unit_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
spo2Level_.SetFont(TJD_VECTOR_FONT_FILENAME, 24);
spo2Level_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
spo2Level_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
spo2Level_.SetPosition(141, 59 - 12, 51, 26);
spo2Level_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
spo2Title_.SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 18);
spo2Title_.SetText("BLOOD OXYGEN");
spo2Title_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
spo2Title_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
spo2Title_.SetPosition(83, 23, 118, 14);
spo2Title_.SetStyle(STYLE_TEXT_COLOR, 0XFFEA3D35);
spo2Title_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.8);
spo2Pic_.SetPosition(25, 97, 350, 60);
spo2Pic_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_SPO2_PICTURE, FAVORITE_IMAGE_BIN_PATH));
bloodOxygenModel_.Add(&spo2Bg_);
bloodOxygenModel_.Add(&spo2Icon_);
bloodOxygenModel_.Add(&spo2Value_);
bloodOxygenModel_.Add(&spo2Unit_);
bloodOxygenModel_.Add(&spo2Level_);
bloodOxygenModel_.Add(&spo2Title_);
bloodOxygenModel_.Add(&spo2Pic_);
Add(&healthModel_);
Add(&bloodOxygenModel_);
}
#pragma endregion
#pragma region 睡眠模组
FavoriteSleepModel::FavoriteSleepModel()
{
auto &images = OHOS::ImageCacheManager::GetInstance();
Resize(400, 180);
sleepBg_.SetPosition(0, 0, 400, 180);
sleepBg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_SLEEP, FAVORITE_IMAGE_BIN_PATH));
sleepIcon_.SetPosition(41, 19, 27, 22);
sleepIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_SLEEP_ICON, FAVORITE_IMAGE_BIN_PATH));
sleepTitle_.SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 18);
sleepTitle_.SetText("SLEEP");
sleepTitle_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
sleepTitle_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
sleepTitle_.SetPosition(78, 23, 93, 14);
sleepTitle_.SetStyle(STYLE_TEXT_COLOR, 0XFF7119FF);
sleepTitle_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.8);
sleepHourValue_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 42);
sleepHourValue_.SetText("--");
sleepHourValue_.SetPosition(41, 50, 41, 32);
sleepHourValue_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
sleepHourValue_.SetAlign(OHOS::TEXT_ALIGNMENT_RIGHT, OHOS::TEXT_ALIGNMENT_CENTER);
InitLabelVerCenter(sleepHourUnit_, 30, sleepHourValue_.GetX() + sleepHourValue_.GetWidth() + 6, GetHeight(), "h");
sleepHourUnit_.SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 30);
sleepHourUnit_.SetY(66);
sleepMinValue_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 42);
sleepMinValue_.SetText("--");
sleepMinValue_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
sleepMinValue_.SetAlign(OHOS::TEXT_ALIGNMENT_RIGHT, OHOS::TEXT_ALIGNMENT_CENTER);
sleepMinValue_.SetPosition(107, 50, 42, 32);
InitLabelVerCenter(sleepMinUnit_, 30, sleepMinValue_.GetX() + sleepMinValue_.GetWidth() + 10, GetHeight(), "m");
sleepMinUnit_.SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 30);
sleepMinUnit_.SetY(66);
sleepLevel_.SetFont(TJD_VECTOR_FONT_FILENAME, 24);
sleepLevel_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
sleepLevel_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
sleepLevel_.SetPosition(195, 59, 142, 23);
sleepLevel_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
sleepPic_.SetPosition(51, 108, 297, 38);
sleepPic_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_SLEEP_PICTURE, FAVORITE_IMAGE_BIN_PATH));
Add(&sleepBg_);
Add(&sleepTitle_);
Add(&sleepIcon_);
Add(&sleepHourValue_);
Add(&sleepHourUnit_);
Add(&sleepMinValue_);
Add(&sleepMinUnit_);
Add(&sleepLevel_);
Add(&sleepPic_);
}
#pragma endregion
#pragma region 运动模组
FavoriteMotionModel::FavoriteMotionModel()
{
auto &images = OHOS::ImageCacheManager::GetInstance();
Resize(400, 576);
motionModel_.SetPosition(0, 0, 400, 180);
distanceModel_.SetPosition(0, 198, 400, 180);
calorieModel_.SetPosition(0, 396, 400, 180);
motionBg_.SetPosition(0, 0, 400, 180);
motionBg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_STEP, FAVORITE_IMAGE_BIN_PATH));
motionIcon_.SetPosition(40, 15, 21, 24);
motionIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_STEP_ICON, FAVORITE_IMAGE_BIN_PATH));
motionStepValue_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 42);
motionStepValue_.SetText("18800");
motionStepValue_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
motionStepValue_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
motionStepValue_.SetPosition(42, 50, 41, 32);
motionProcess_.SetFont(TJD_VECTOR_FONT_FILENAME, 24);
motionProcess_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
motionProcess_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
motionProcess_.SetPosition(163, 59, 145, 23);
motionProcess_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
motionTitle_.SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 18);
motionTitle_.SetText("STEPS");
motionTitle_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
motionTitle_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
motionTitle_.SetPosition(79, 23, 48, 14);
motionTitle_.SetStyle(STYLE_TEXT_COLOR, 0XFF02952F);
// motionTitle_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.8);
auto progressBgRes =
ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_MAIN_FAVORITE_RECTANGLE, FAVORITE_IMAGE_BIN_PATH);
motionProgressBg_.SetPosition(40, 117, 322, 24);
if (progressBgRes != nullptr) {
motionProgressBg_.SetSrc(progressBgRes);
}
auto knodeRes =
ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_MAIN_FAVORITE_PROGRESS, FAVORITE_IMAGE_BIN_PATH);
motionProgress_.SetPosition(40, 116, 322, 24);
motionProgress_.SetStyle(STYLE_BACKGROUND_OPA, 0);
motionProgress_.SetStyle(STYLE_BORDER_RADIUS, 6);
motionProgress_.SetValidWidth(303);
motionProgress_.SetValidHeight(3);
motionProgress_.SetKnobWidth(24);
motionProgress_.SetSliderColor(Color::GetColorFromRGBA(0, 177, 36, 51), Color::GetColorFromRGBA(0, 177, 55, 0xff));
// motionProgress_.SetKnobStyle(STYLE_BACKGROUND_COLOR, 0xff3299FE);
// motionProgress_.SetKnobRadius(12);
motionProgress_.SetKnobStyle(STYLE_BORDER_WIDTH, 2);
motionProgress_.SetKnobImage(knodeRes);
motionProgress_.SetValue(60);
motionProgress_.SetTouchable(false);
motionModel_.Add(&motionBg_);
motionModel_.Add(&motionIcon_);
motionModel_.Add(&motionProgressBg_);
motionModel_.Add(&motionProcess_);
motionModel_.Add(&motionStepValue_);
motionModel_.Add(&motionProgress_);
motionModel_.Add(&motionTitle_);
//===================================================================================//distanceModel_
distanceBg_.SetPosition(0, 0, 400, 180);
distanceBg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_DIS, FAVORITE_IMAGE_BIN_PATH));
distanceIcon_.SetPosition(39, 11, 26, 29);
distanceIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_JULI_ICON, FAVORITE_IMAGE_BIN_PATH));
distanceTitle_.SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 18);
distanceTitle_.SetText("DISTANCE");
distanceTitle_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
distanceTitle_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
distanceTitle_.SetPosition(79, 23, 118, 14);
distanceTitle_.SetStyle(STYLE_TEXT_COLOR, 0XFF00C989);
distanceTitle_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.8);
distanceValue_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 42);
distanceValue_.SetText("36.6");
distanceValue_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
distanceValue_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
distanceValue_.SetPosition(42, 48, 76, 32);
distanceUnit_.SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 30);
distanceUnit_.SetText("km");
distanceUnit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
distanceUnit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
distanceUnit_.SetPosition(150, 58, 35, 21);
distanceUnit_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
distancePic_.SetPosition(64, 97, 269, 61);
distancePic_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_DISTANCE_PICTURE, FAVORITE_IMAGE_BIN_PATH));
distanceModel_.Add(&distanceBg_);
distanceModel_.Add(&distanceIcon_);
distanceModel_.Add(&distanceValue_);
distanceModel_.Add(&distanceTitle_);
distanceModel_.Add(&distanceUnit_);
distanceModel_.Add(&distancePic_);
//===================================================================================//calorieModel_
calorieBg_.SetPosition(0, 0, 400, 180);
calorieBg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_CAL, FAVORITE_IMAGE_BIN_PATH));
calorieIcon_.SetPosition(41, 15, 21, 23);
calorieIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_KCAL_ICON, FAVORITE_IMAGE_BIN_PATH));
calorieTitle_.SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 18);
calorieTitle_.SetText("KCAL");
calorieTitle_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
calorieTitle_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
calorieTitle_.SetPosition(79, 23, 41, 14);
calorieTitle_.SetStyle(STYLE_TEXT_COLOR, 0XFFFF751C);
calorieValue_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 42);
calorieValue_.SetText("1230");
calorieValue_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
calorieValue_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
calorieValue_.SetPosition(45, 49, 83, 32);
calorieUnit_.SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 30);
calorieUnit_.SetText("kcal");
calorieUnit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
calorieUnit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
calorieUnit_.SetPosition(136, 59, 50, 22);
calorieUnit_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
calorieLevel_.SetFont(TJD_VECTOR_FONT_FILENAME, 24);
calorieLevel_.SetTextId(STR_ID_617);
calorieLevel_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
calorieLevel_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
calorieLevel_.SetPosition(206, 58, 95, 23);
calorieLevel_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
caloriePic_.SetPosition(41, 106, 311, 52);
caloriePic_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_KCAL_PICTURE, FAVORITE_IMAGE_BIN_PATH));
// InitLabelVerCenter(calorieValue_, 28, 151, 80, "1080");
// InitLabelVerCenter(calorieUnit_, 28, 228, 80, "kcal");
calorieModel_.Add(&calorieBg_);
calorieModel_.Add(&calorieIcon_);
calorieModel_.Add(&calorieValue_);
calorieModel_.Add(&calorieUnit_);
calorieModel_.Add(&calorieLevel_);
calorieModel_.Add(&calorieTitle_);
calorieModel_.Add(&caloriePic_);
Add(&motionModel_);
Add(&distanceModel_);
Add(&calorieModel_);
}
#pragma endregion
#pragma region 秒表模组
FavoriteTimekeepingModel::FavoriteTimekeepingModel()
{
auto &images = OHOS::ImageCacheManager::GetInstance();
Resize(400, 180);
SetTouchable(true);
stopwatchBg_.SetPosition(0, 0, 400, 180);
stopwatchBg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ_STOP_WATCH, FAVORITE_IMAGE_BIN_PATH));
startIcon_.SetPosition(22, 110, 46, 46);
startIcon_.SetImages(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_PAUSE_MID, FAVORITE_IMAGE_BIN_PATH),
images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_START_MID, FAVORITE_IMAGE_BIN_PATH));
startIcon_.SetTouchable(false);
icon_.SetPosition(41, 17, 23, 24);
icon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_STOPWATCH_ICON, FAVORITE_IMAGE_BIN_PATH));
stopwatchTitle_.SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 18);
stopwatchTitle_.SetText("STOPWATCH");
stopwatchTitle_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
stopwatchTitle_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
stopwatchTitle_.SetPosition(78, 23, 94, 14);
stopwatchTitle_.SetStyle(STYLE_TEXT_COLOR, 0XFF00CE4F);
stopwatchTitle_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.8);
title_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 42);
title_.SetText("30");
title_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
title_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
title_.SetPosition(43, 53, 41, 32);
stopwatchUnit_.SetFont(TJD_VECTOR_FONT_FILENAME, 24);
stopwatchUnit_.SetTextId(STR_ID_618);
stopwatchUnit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
stopwatchUnit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
stopwatchUnit_.SetPosition(92, 62, 119, 23);
stopwatchUnit_.SetStyle(STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
time_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 60);
time_.SetText("00:00:00");
time_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
time_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
time_.SetPosition(HorizontalCenter(time_.GetWidth(), 400), 88);
if (g_timeKeepingIsStart) {
startIcon_.SetState(OHOS::UICheckBox::UICheckBoxState::SELECTED);
AddTimekeeping();
}
stopIcon_.SetPosition(334, 110, 46, 46);
stopIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_END, FAVORITE_IMAGE_BIN_PATH));
stopIcon_.SetTouchable(false);
Add(&stopwatchBg_);
Add(&startIcon_);
Add(&icon_);
Add(&title_);
Add(&time_);
Add(&stopIcon_);
Add(&stopwatchTitle_);
Add(&stopwatchUnit_);
}
void FavoriteTimekeepingModel::AddTimekeeping()
{
if (g_timeKeepingIsStart == false) {
return;
}
const simple_timer_t *timerTime = tjd_service_simple_timer_get_time();
std::ostringstream oss;
oss << std::setw(2) << std::setfill('0') << timerTime->hour << ":" << std::setw(2) << std::setfill('0')
<< timerTime->minute << ":" << std::setw(2) << std::setfill('0') << timerTime->second;
timeStr_ = oss.str();
time_.SetText(timeStr_.c_str());
if (timerTime->hour == 0 && timerTime->minute == 30 && timerTime->second == 0) {
StopTimekeeping();
auto favortiteView = TjdUiAppMainPageFavorite::GetInstance();
favortiteView->ShowView(FavoriteViewIndex::TIME_OUT_VIEW);
}
}
void FavoriteTimekeepingModel::StopTimekeeping()
{
g_timeKeepingIsStart = false;
time_.SetText("00:00:00");
startIcon_.SetState(OHOS::UICheckBox::UICheckBoxState::UNSELECTED, false);
}
bool FavoriteTimekeepingModel::OnClickEvent(const OHOS::ClickEvent &event)
{
auto touchX = event.GetCurrentPos().x; // 获取点击的x坐标
auto x = GetX(); // 获取当前控件的x坐标
auto width = GetWidth(); // 获取当前控件的宽度
// 计算左边1/4和右边1/4的边界
auto leftQuarter = x + width / 4;
auto rightQuarter = x + 3 * width / 4;
if (touchX < leftQuarter) {
startIcon_.OnClickEvent(event);
g_timeKeepingIsStart = startIcon_.GetState() == OHOS::UICheckBox::UICheckBoxState::SELECTED;
if (g_timeKeepingIsStart) {
tjd_service_simple_timer_start();
} else {
tjd_service_simple_timer_pause();
}
} else if (touchX > rightQuarter) {
StopTimekeeping();
tjd_service_simple_timer_stop();
}
return UIView::OnClickEvent(event);
}
TimeOutView::TimeOutView()
{
auto &images = OHOS::ImageCacheManager::GetInstance();
SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
timeOut_.SetTextId(STR_ID_619);
timeOut_.SetFont(TJD_VECTOR_FONT_FILENAME, 36);
timeOut_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
timeOut_.SetPosition(68, 68, 330, 330);
timeOut_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff00ff00);
timeOut_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
enterIcon_.SetPosition(77, 378, 312, 88);
enterIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ, FAVORITE_IMAGE_BIN_PATH));
enterIcon_.SetTouchable(true);
enterIcon_.SetViewId(BTN_TIME_OUT_BTN_ID);
enterIcon_.SetOnClickListener(FavoritePresenter::GetInstance());
Add(&timeOut_);
Add(&enterIcon_);
}
#pragma endregion
#pragma endregion
#pragma region 主页面
FavoriteMainView::FavoriteMainView()
{
SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
SetScrollBlankSize(MAIN_VIEW_BLANK_SIZE);
SetRotateEnable(*this);
SetHorizontalScrollState(false);
SetOnDragListener(FavoritePresenter::GetInstance());
struct rtc_time time;
tjd_driver_rtc_get_ops()->get_rtc_time(&time);
std::ostringstream oss;
oss << std::setfill('0') << std::setw(2) << time.tm_hour << ":" << std::setw(2) << time.tm_min;
std::string timeStr = oss.str();
InitLabelHorCenter(time_, 42, 27, OHOS::HORIZONTAL_RESOLUTION, timeStr.c_str());
Add(&time_);
topModel_.SetPosition(50, 102);
Add(&topModel_);
Add(&musicModel_);
Add(&healthModel_);
Add(&sleepModel_);
Add(&motionModel_);
Add(&timekeepingModel_);
btnEdit_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff242424);
btnEdit_.SetStyle(STYLE_BACKGROUND_OPA, 0xff);
btnEdit_.SetStyle(STYLE_BORDER_RADIUS, 33);
btnEdit_.SetPosition(123, 2057 + 40, 220, 66);
btnEdit_.SetTouchable(true);
btnEdit_.SetViewId(BTN_EDIT_VIEW_ID);
btnEdit_.SetOnClickListener(FavoritePresenter::GetInstance());
editDesc_.SetFont(TJD_VECTOR_FONT_FILENAME, 36);
editDesc_.SetTextId(STR_ID_69);
editDesc_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
editDesc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
editDesc_.SetPosition(HorizontalCenter(editDesc_.GetWidth(), btnEdit_.GetWidth()),
VerticalCenter(editDesc_.GetHeight(), btnEdit_.GetHeight()));
editDesc_.SetStyle(STYLE_TEXT_COLOR, 0XFF00b136);
btnEdit_.Add(&editDesc_);
Add(&btnEdit_);
int setY = btnEdit_.GetY() + 233;
hide_.SetPosition(50, setY, 0, 0);
Add(&hide_);
}
void FavoriteMainView::ShowView()
{
startTime_ = HALTick::GetInstance().GetTime();
set_back_to_home_interval(5);
auto presenter = FavoritePresenter::GetInstance();
if (TjdUiSettingCenter::GetInstance().IsConnectApp()) {
topModel_.SetType(FavoritePresenter::GetInstance()->GetTopModelType());
} else {
topModel_.SetType(TopModelType::TOP_MODEL_DISCONNECTED);
}
SetMusicModelPlayState(presenter->IsPlaying() ? OHOS::UICheckBox::UICheckBoxState::SELECTED
: OHOS::UICheckBox::UICheckBoxState::UNSELECTED);
UpdateData();
ScrollBy(0, GetHeight());
SetModelSort(TjdUiAppMainPageFavorite::GetInstance()->GetFavoriteModelList());
SetVisible(true);
TjdCardId pageid = TjdUiAppMainView::GetInstance()->GetHorCurrentCard();
if (pageid == TjdCardId::TJD_CARD_FAVORITE) {
TjdUiUtils::ViewRequestFocus(*this);
}
}
void FavoriteMainView::HideView()
{
SetVisible(false);
ClearFocus();
}
void FavoriteMainView::SetModelSort(std::list<FavoriteModel> &favoriteModelList)
{
bool isFirst = true;
int16_t startY = topModel_.GetY() + 336 + 12;
for (auto it = favoriteModelList.begin(); it != favoriteModelList.end(); it++) {
// clang-format off
UIView *view = nullptr;
switch (*it) {
case FavoriteModel::MUSIC_MODEL: view = &musicModel_; break;
case FavoriteModel::HEALTH_MODEL: view = &healthModel_; break;
case FavoriteModel::SLEEP_MODEL: view = &sleepModel_; break;
case FavoriteModel::MOTION_MODEL: view = &motionModel_; break;
case FavoriteModel::TIMEKEEPING_MODEL: view = &timekeepingModel_; break;
default: break;
}
// clang-format on
if (isFirst) {
startY += (46 - 12);
isFirst = false;
}
if (view != nullptr) {
view->SetPosition(33, startY);
startY += view->GetHeight() + 22;
}
}
}
void FavoriteMainView::UpdateData()
{
auto favoritePresenter = FavoritePresenter::GetInstance();
if (favoritePresenter == nullptr) {
return;
}
healthModel_.healthValue_.SetText(favoritePresenter->GetHeartRate().c_str());
healthModel_.healthLevel_.SetTextId(favoritePresenter->GetHeartRateLevel());
healthModel_.spo2Value_.SetText(favoritePresenter->GetSpo2().c_str());
healthModel_.spo2Level_.SetTextId(favoritePresenter->GetSpo2Level());
sleepModel_.sleepHourValue_.SetText(favoritePresenter->GetSleepHourTime().c_str());
sleepModel_.sleepMinValue_.SetText(favoritePresenter->GetSleepMinuteTime().c_str());
sleepModel_.sleepLevel_.SetTextId(favoritePresenter->GetSleepLevel());
motionModel_.motionStepValue_.SetText(favoritePresenter->GetStepCount().c_str());
motionModel_.motionProgress_.SetValue(favoritePresenter->GetStepProcess()); // 步数进度条
motionModel_.motionProcess_.SetText((std::string(OHOS::FontGlobalManager::GetInstance()->GetText(STR_ID_616)) +
std::to_string(favoritePresenter->GetStepProcess()) + std::string("%"))
.c_str()); // 步数进度条
motionModel_.distanceValue_.SetText(favoritePresenter->GetDistance().c_str());
motionModel_.calorieValue_.SetText(favoritePresenter->GetCalorie().c_str());
}
OHOS::UICheckBox::UICheckBoxState FavoriteMainView::GetMusicModelPlayState() { return musicModel_.GetPlayState(); }
void FavoriteMainView::SetMusicModelPlayState(OHOS::UICheckBox::UICheckBoxState state)
{
musicModel_.SetPlayState(state);
}
#pragma endregion
#pragma region 排序界面
FavoriteSortModelView::FavoriteSortModelView()
{
itemName_[FavoriteModel::MUSIC_MODEL] = STR_ID_627;
itemName_[FavoriteModel::HEALTH_MODEL] = STR_ID_628;
itemName_[FavoriteModel::SLEEP_MODEL] = STR_ID_629;
itemName_[FavoriteModel::MOTION_MODEL] = STR_ID_630;
itemName_[FavoriteModel::TIMEKEEPING_MODEL] = STR_ID_631;
auto &images = OHOS::ImageCacheManager::GetInstance();
SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
SetScrollBlankSize(MAIN_VIEW_BLANK_SIZE);
SetRotateEnable(*this);
SetHorizontalScrollState(false);
SetOnDragListener(FavoritePresenter::GetInstance());
SetReboundSize(0);
title_.SetTextId(STR_ID_88);
title_.SetFont(TJD_VECTOR_FONT_FILENAME, 32);
title_.Resize(200, 100);
title_.SetX((GetWidth() >> 1) - (title_.GetWidth() >> 1));
title_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
Add(&title_);
topIcon_.SetPosition(272, 32, 60, 60);
topIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_TOP, FAVORITE_IMAGE_BIN_PATH));
topModel_.SetViewId(BTN_WEATHER_VIEW_ID);
topModel_.SetPosition(50, 85, 366, 126);
topModel_.SetStyle(STYLE_BACKGROUND_OPA, 0xff);
topModel_.SetStyle(STYLE_BORDER_RADIUS, 63);
topModel_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff262626);
topModel_.SetTouchable(true);
topModel_.SetOnClickListener(FavoritePresenter::GetInstance());
topModelDesc_.SetTextId(STR_ID_626);
topModelDesc_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
topModelDesc_.Resize(180, (topModel_.GetHeight() >> 1));
topModelDesc_.SetPosition(51, 0);
topModelDesc_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
topModelDesc_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_BOTTOM);
topModelValue_.SetTextId(STR_ID_11);
topModelValue_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
topModelValue_.Resize(180, (topModel_.GetHeight() >> 1));
topModelValue_.SetPosition(topModelDesc_.GetX(), (topModel_.GetHeight() >> 1));
topModelValue_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
topModelValue_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_TOP);
topModelValue_.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.5);
topModel_.Add(&topIcon_);
topModel_.Add(&topModelDesc_);
topModel_.Add(&topModelValue_);
Add(&topModel_);
/* 初始化时用全局 */
int startY = 219;
int index = 0;
for (auto item : g_favoriteModelList_) {
sortItemView_[index] = new SortItemView(startY, index, itemName_[item], this);
startY += 118;
Add(sortItemView_[index]);
++index;
}
btnEnter_.SetPosition(77, 958, 312, 88);
btnEnter_.SetSrc(ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ, FAVORITE_IMAGE_BIN_PATH));
btnEnter_.SetTouchable(true);
btnEnter_.SetViewId(BTN_SORT_ENTER_VIEW_ID);
btnEnter_.SetOnClickListener(FavoritePresenter::GetInstance());
Add(&btnEnter_);
}
FavoriteSortModelView::~FavoriteSortModelView()
{
RemoveAll();
for (int i = 0; i < FavoriteModel::MODEL_COUNT; ++i) {
if (sortItemView_[i] != nullptr) {
delete sortItemView_[i];
sortItemView_[i] = nullptr;
}
}
topModel_.RemoveAll();
}
void FavoriteSortModelView::ShowView()
{
auto presenter = FavoritePresenter::GetInstance();
if (presenter == nullptr) {
return;
}
set_back_to_home_interval(0xffffffff);
/* 拷贝一份排序 */
modelSortList_.clear();
for (auto &item : g_favoriteModelList_) {
modelSortList_.emplace_back(item);
}
ScrollBy(0, 1413);
switch (presenter->GetTopModelType()) {
case TopModelType::TOP_MODEL_VOICE:
topModelValue_.SetTextId(STR_ID_614);
break;
default:
topModelValue_.SetTextId(STR_ID_11);
break;
}
int index = 0;
for (auto item : modelSortList_) {
sortItemView_[index]->SetItemName(itemName_[item]);
++index;
}
SetReboundSize(0);
SetVisible(true);
TjdUiUtils::ViewRequestFocus(*this);
}
void FavoriteSortModelView::HideView()
{
SetVisible(false);
ClearFocus();
}
bool FavoriteSortModelView::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
{
auto presenter = FavoritePresenter::GetInstance();
if (presenter == nullptr) {
return false;
}
std::string viewId = view.GetViewId();
if (viewId.empty()) {
return false;
}
int16_t index = view.GetParent()->GetViewIndex();
if (viewId == BTN_UP_VIEW_ID) { // 上移
if (index == 0) {
return true;
}
SortItem(index, true);
presenter->SetSortIsChange(true);
} else if (viewId == BTN_DOWN_VIEW_ID) { // 下移
if (index == 4) {
return true;
}
SortItem(index, false);
presenter->SetSortIsChange(true);
}
return true;
}
void FavoriteSortModelView::SortItem(int index, bool isUp)
{
auto curIt = modelSortList_.begin();
std::advance(curIt, index);
std::function<void(SortItemView *, SortItemView *)> swapItem = [](SortItemView *curItem, SortItemView *targetItem) {
auto text = curItem->GetItemName();
curItem->SetItemName(targetItem->GetItemName());
targetItem->SetItemName(text);
};
if (isUp) {
swapItem(sortItemView_[index], sortItemView_[index - 1]);
auto preIt = std::prev(curIt);
std::iter_swap(curIt, preIt);
} else {
swapItem(sortItemView_[index], sortItemView_[index + 1]);
auto nextIt = std::next(curIt);
std::iter_swap(curIt, nextIt);
}
}
#pragma endregion
#pragma region 顶部排序页面
TopModelItemView::TopModelItemView(const TopModelItemInfo &itemInfo)
{
auto &images = OHOS::ImageCacheManager::GetInstance();
Resize(450, 128);
SetTouchable(true);
SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
SetStyle(OHOS::STYLE_BORDER_RADIUS, 64);
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff202020);
SetViewIndex(itemInfo.index);
name_.SetFont(TJD_VECTOR_FONT_FILENAME, 42);
name_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_STRETCH);
name_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER);
name_.SetHeight(GetHeight());
name_.SetX(42);
selectRes_ = images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_ICON_SELECT, FAVORITE_IMAGE_BIN_PATH);
unSelectRes_ = images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_ICON_NO, FAVORITE_IMAGE_BIN_PATH);
switch_.SetPosition(382, 44, 40, 40);
switch_.SetTouchable(false);
switch_.SetSrc(selectRes_);
Add(&name_);
Add(&switch_);
}
void TopModelItemView::RefreshItem(const TopModelItemInfo &itemInfo, int16_t index)
{
itemInfo_ = itemInfo;
name_.SetTextId(itemInfo.name);
int32_t selectIndex = FavoritePresenter::GetInstance()->GetTopModelType();
if (itemInfo.index == selectIndex) {
switch_.SetSrc(selectRes_);
} else {
switch_.SetSrc(unSelectRes_);
}
}
bool TopModelItemView::OnClickEvent(const OHOS::ClickEvent &event)
{
FavoritePresenter::GetInstance()->SelectTopModelIndex(itemInfo_.index);
OHOS::UIView *childView = static_cast<OHOS::UITransformList *>(GetParent())->GetChildrenHead();
while (childView != nullptr) {
static_cast<TopModelItemView *>(childView)->switch_.SetSrc(unSelectRes_);
childView = childView->GetNextSibling();
}
if (switch_.GetImageInfo()->resId == selectRes_->resId) {
switch_.SetSrc(unSelectRes_);
} else {
switch_.SetSrc(selectRes_);
}
switch_.Invalidate();
return true;
}
FavoriteChooseTopModelView::FavoriteChooseTopModelView()
{
auto &images = OHOS::ImageCacheManager::GetInstance();
auto selectRes = images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_ICON_SELECT, FAVORITE_IMAGE_BIN_PATH);
auto unSelectRes = images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_ICON_NO, FAVORITE_IMAGE_BIN_PATH);
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
SetOnDragListener(FavoritePresenter::GetInstance());
SetHorizontalScrollState(false);
infoList_.push_back({TopModelType::TOP_MODEL_WEATHER, STR_ID_613});
infoList_.push_back({TopModelType::TOP_MODEL_VOICE, STR_ID_612});
enterIcon_.SetPosition(77, 378, 312, 88);
enterIcon_.SetTouchable(true);
enterIcon_.SetViewId(BTN_TOP_MODEL_ENTER_VIEW_ID);
enterIcon_.SetOnClickListener(FavoritePresenter::GetInstance());
enterIcon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_BJ, FAVORITE_IMAGE_BIN_PATH));
title_.SetTextId(STR_ID_88);
title_.SetFont(TJD_VECTOR_FONT_FILENAME, 32);
title_.Resize(200, 100);
title_.SetX((GetWidth() >> 1) - (title_.GetWidth() >> 1));
title_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
auto titleOffset_ = ((OHOS::Screen::GetInstance().GetHeight() >> 1) - (128 >> 1) - 17 - title_.GetHeight());
adapter_ =
new TjdUITransformListGroupAdapter<TopModelItemInfo, TopModelItemView, std::list<TopModelItemInfo>>(infoList_);
listGroup_ = new TjdUITransformListGroup(adapter_);
Add(listGroup_);
listGroup_->AddCustomView(&title_, TjdUITransformListGroup::CustomViewPos::TITLE);
listGroup_->SetTitleOffset(titleOffset_);
Add(&title_);
Add(&enterIcon_);
}
void FavoriteChooseTopModelView::ShowView()
{
SetVisible(true);
listGroup_->RequestFocus();
}
void FavoriteChooseTopModelView::HideView()
{
listGroup_->ClearFocus();
SetVisible(false);
}
#pragma endregion
#pragma region 设置提示页面
FavoriteBreakView::FavoriteBreakView()
{
auto &images = OHOS::ImageCacheManager::GetInstance();
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
SetHorizontalScrollState(false);
desc_.SetTextId(STR_ID_90);
desc_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
desc_.Resize(300, 200);
desc_.SetX((GetWidth() >> 1) - (desc_.GetWidth() >> 1));
desc_.SetY(120);
desc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
btnCancel_.SetPosition(103, 326, 92, 92);
btnCancel_.SetTouchable(true);
btnCancel_.SetViewId(BTN_SAVE_SORT_CLOSE_VIEW_ID);
btnCancel_.SetOnClickListener(FavoritePresenter::GetInstance());
btnCancel_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_QUXIAO, FAVORITE_IMAGE_BIN_PATH));
btnOK_.SetPosition(271, 326, 92, 92);
btnOK_.SetTouchable(true);
btnOK_.SetViewId(BTN_SAVE_SORT_ENTER_VIEW_ID);
btnOK_.SetOnClickListener(FavoritePresenter::GetInstance());
btnOK_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_FAVORITE_QUEDING, FAVORITE_IMAGE_BIN_PATH));
Add(&desc_);
Add(&btnCancel_);
Add(&btnOK_);
}
#pragma endregion
#pragma region 等待页面
FavoriteSettingWaitView::FavoriteSettingWaitView()
{
const int WaitAnimatorId[11] = {
IMG_LOADING_LOADING_01_06, IMG_LOADING_LOADING_02_06, IMG_LOADING_LOADING_03_06, IMG_LOADING_LOADING_04_06,
IMG_LOADING_LOADING_05_06, IMG_LOADING_LOADING_06_06, IMG_LOADING_LOADING_07_06, IMG_LOADING_LOADING_08_06,
IMG_LOADING_LOADING_09_06, IMG_LOADING_LOADING_10_06, IMG_LOADING_LOADING_11_06,
};
auto &imgManager = OHOS::ImageCacheManager::GetInstance();
imgManager.LoadAllInMultiRes(COMMON_IMAGE_BIN_PATH);
for (int i = 0; i < 11; i++) {
waitInfo_[i].imageInfo = imgManager.LoadOneInMultiRes(WaitAnimatorId[i], COMMON_IMAGE_BIN_PATH);
waitInfo_[i].pos = {174, 135};
waitInfo_[i].width = 121;
waitInfo_[i].height = 121;
waitInfo_[i].imageType = OHOS::IMG_SRC_IMAGE_INFO;
}
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
/* 动画页面不允许滑动 */
SetIntercept(true);
animator_.SetPosition(150, 113, 166, 164);
desc_.SetTextId(STR_ID_89);
desc_.SetFont(TJD_VECTOR_FONT_FILENAME, 36);
desc_.Resize(340, 150);
desc_.SetX((GetWidth() >> 1) - (desc_.GetWidth() >> 1));
desc_.SetY(animator_.GetY() + animator_.GetHeight() + 30);
desc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP);
animator_.SetImageAnimatorSrc(waitInfo_, 11, 100);
animator_.Start();
Add(&animator_);
Add(&desc_);
}
FavoriteSettingWaitView::~FavoriteSettingWaitView()
{
animator_.Stop();
OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(COMMON_IMAGE_BIN_PATH);
RemoveAll();
}
void FavoriteSettingWaitView::ShowView()
{
animator_.Start();
SetVisible(true);
}
void FavoriteSettingWaitView::HideView()
{
animator_.Stop();
SetVisible(false);
}
#pragma endregion
} // namespace TJD