#include "TjdUiAppLowPowerView.h" #include "TjdUiImageIds.h" #include "TjdUiMemManage.h" #include "TjdUiMultiLanguageExt.h" #include "animator/animator_manager.h" #include "common/image_cache_manager.h" #include "gfx_utils/mem_check.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 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 #define LOW_POWER_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_low_power.bin" TjdUiAppLowPowerView::TjdUiAppLowPowerView(uint8_t battery, TjdUiAppLowPowerPresenter *presenter) : presenter_(presenter) { TjdUIEnterViewBase::SetEnterViewType(EnterViewType::OK_AND_CANCEL); OHOS::ImageInfo *res = nullptr; SetOnDragListener(presenter); auto &image = OHOS::ImageCacheManager::GetInstance(); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); image.LoadAllInMultiRes(LOW_POWER_IMAGE_BIN_PATH); char descStr[64] = {0}; if (battery <= 0) { snprintf(descStr, sizeof(descStr), "电量下降至0%%\n是否开启省电模式?"); res = image.LoadOneInMultiRes(IMG_LOW_POWER_ICON_0, LOW_POWER_IMAGE_BIN_PATH); }else if (battery <= 5) { snprintf(descStr, sizeof(descStr), "电量下降至5%%\n是否开启省电模式?"); res = image.LoadOneInMultiRes(IMG_LOW_POWER_ICON_5, LOW_POWER_IMAGE_BIN_PATH); } else if (battery <= 10) { snprintf(descStr, sizeof(descStr), "电量下降至10%%\n是否开启省电模式?"); res = image.LoadOneInMultiRes(IMG_LOW_POWER_ICON_10, LOW_POWER_IMAGE_BIN_PATH); } else if (battery <= 20) { snprintf(descStr, sizeof(descStr), "电量下降至20%%\n是否开启省电模式?"); res = image.LoadOneInMultiRes(IMG_LOW_POWER_ICON_20, LOW_POWER_IMAGE_BIN_PATH); } icon_.SetPosition(173, 25, 120, 120); icon_.SetSrc(res); res = image.LoadOneInMultiRes(IMG_LOW_POWER_CANCEL, LOW_POWER_IMAGE_BIN_PATH); TjdUIEnterViewBase::SetCancelSrc(res); res = image.LoadOneInMultiRes(IMG_LOW_POWER_CONFIRM, LOW_POWER_IMAGE_BIN_PATH); TjdUIEnterViewBase::SetOkSrc(res); TjdUIEnterViewBase::SetEnterViewOnClickListener(presenter); InitLabelHorCenter(desc_, 28, 158, 466, descStr); InitLabelHorCenter(descTips_, 24, 250, 466, "开启功能,屏幕亮度将降到最低,震动、\n铃声将关闭,长按3S退出省电模式"); descTips_.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.5); Add(&icon_); Add(&desc_); Add(&descTips_); } TjdUiAppLowPowerView::~TjdUiAppLowPowerView() { if (presenter_ != nullptr) { delete presenter_; presenter_ = nullptr; } RemoveAll(); } } // namespace TJD