/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved. * * Description: * * Author: wuchangxin * * Create: 2025-03-11 *--------------------------------------------------------------------------*/ #include "TjdUiAppFindDeviceView.h" #include "TjdUiImageIds.h" #include "TjdUiMultiLanguageExt.h" // #include "TjdUiScreenManage.h" #include "common/image_cache_manager.h" #include "gfx_utils/mem_check.h" #include "graphic_service.h" #include "motor.h" #include "notification_manager.h" #include "ohos_types.h" #include "player_sample_wrapper.h" #include "style.h" extern "C" { #include "task_ancillary.h" } namespace TJD { using namespace OHOS; #define IF_MEM_CHECK 0 #define FINDP_DEV_ANIMATOR_COUNT 6 #define FIND_DEVICE_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_find_device.bin" int FindDeviceAnimatorId[FINDP_DEV_ANIMATOR_COUNT] = { FIND_DEVICE_FIND_DT_01, FIND_DEVICE_FIND_DT_02, FIND_DEVICE_FIND_DT_03, FIND_DEVICE_FIND_DT_04, FIND_DEVICE_FIND_DT_05, FIND_DEVICE_FIND_DT_06, }; static osTimerId_t g_ExitFindDeviceTimerId{nullptr}; static OHOS::ImageAnimatorInfo g_pv_animatorInfo_[FINDP_DEV_ANIMATOR_COUNT]; static TjdUiAppFindDeviceView *g_pv_AppFindPhoneView = nullptr; typedef void (*FindDevicePostEventHandleFunction)(void); static FindDevicePostEventHandleFunction g_postEventCallback = nullptr; struct FindDeviceEventInfo { signed int (*func_event_handler)(void *param); // 事件处理函数 void *param; // 事件处理函数入参 void (*func_event_debug)(char *str, ...); // 打印 void *payload; }; static signed int EventHandler(void *param) { if (g_postEventCallback != nullptr) { g_postEventCallback(); } return 0; } static void PostEventHandle(FindDevicePostEventHandleFunction event) { FindDeviceEventInfo g_msg_data = { .func_event_handler = EventHandler, .param = NULL, .func_event_debug = NULL, .payload = NULL, }; g_postEventCallback = event; static unsigned int g_msg_size = sizeof(FindDeviceEventInfo); osal_msg_queue_write_copy(tjd_task_ancillary_get_queue_id(), &g_msg_data, g_msg_size, 0); } static void ExitFindDeviceTimerFunc(void *arg) { GraphicService::GetInstance()->PostGraphicEvent([]() { OHOS::NotificationManager::GetInstance()->StopNotify(); }); } TjdUiAppFindDeviceView::TjdUiAppFindDeviceView() { if (IF_MEM_CHECK) OHOS::MemCheck::GetInstance()->EnableLeakCheck(true); g_pv_AppFindPhoneView = this; InitFindDeviceViewImage(); ClearBackgroundBlur(); SetPosition(0, 0, 466, 466); SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); SetBackgroundBlur(10); SetFullScreenBlur(true); backGround_.SetPosition(63, 133, 340, 200); backGround_.SetStyle(STYLE_BACKGROUND_COLOR, 0xFFFFFFFF); backGround_.SetStyle(STYLE_BACKGROUND_OPA, 0xff * 0.2); backGround_.SetStyle(STYLE_BORDER_RADIUS, 30); animatorfindDev_.SetPosition(130, 153, 208, 100); animatorfindDev_.SetImageAnimatorSrc(g_pv_animatorInfo_, FINDP_DEV_ANIMATOR_COUNT, 200); animatorfindDev_.Start(); lblFindDev_.SetFont(TJD_VECTOR_FONT_FILENAME, 28); // lblFindDev_.SetText("查找设备中..."); lblFindDev_.SetTextId(STR_ID_109); lblFindDev_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); lblFindDev_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); lblFindDev_.SetPosition(63, 271,340, 42); g_ExitFindDeviceTimerId = osTimerNew((osTimerFunc_t)ExitFindDeviceTimerFunc, osTimerOnce, NULL, NULL); osTimerStart(g_ExitFindDeviceTimerId, 1000 * 10); motor_param_t motorParam = {.cycle1_on = 200, .cycle1_off = 100, .cycle1_cnt = 0xffff, .duty = 100}; tjd_driver_motor_user_start(&motorParam); PlayerStart(); osDelay(100); LoopPlayerStart(); Add(&backGround_); Add(&animatorfindDev_); Add(&lblFindDev_); } TjdUiAppFindDeviceView::~TjdUiAppFindDeviceView() { ClearBackgroundBlur(); animatorfindDev_.Stop(); tjd_driver_motor_user_stop(); PlayerStop(); RemoveAll(); if (g_ExitFindDeviceTimerId != nullptr) { osTimerDelete(g_ExitFindDeviceTimerId); g_ExitFindDeviceTimerId = nullptr; } g_pv_AppFindPhoneView = nullptr; if (IF_MEM_CHECK) OHOS::MemCheck::GetInstance()->EnableLeakCheck(false); ImageCacheManager::GetInstance().UnloadAllInMultiRes(FIND_DEVICE_IMAGE_BIN_PATH); } TjdUiAppFindDeviceView *TjdUiAppFindDeviceView::GetInstance(void) { return g_pv_AppFindPhoneView; } void TjdUiAppFindDeviceView::InitFindDeviceViewImage() { ImageCacheManager &imgManager = ImageCacheManager::GetInstance(); for (int i = 0; i < FINDP_DEV_ANIMATOR_COUNT; i++) { g_pv_animatorInfo_[i].imageInfo = imgManager.LoadOneInMultiRes(FindDeviceAnimatorId[i], FIND_DEVICE_IMAGE_BIN_PATH); g_pv_animatorInfo_[i].pos = {130, 153}; g_pv_animatorInfo_[i].width = 208; g_pv_animatorInfo_[i].height = 100; g_pv_animatorInfo_[i].imageType = IMG_SRC_IMAGE_INFO; } } int TjdUiAppFindDeviceView::PlayerStart() { PostEventHandle([]() { const char *argv[] = {"xx", "/user/call_music.mp3", "1", "0"}; PlayerSample(ARRAY_SIZE(argv), argv); }); return 0; } int TjdUiAppFindDeviceView::PlayerStop() { PostEventHandle([]() { const char *argv[] = {"stop"}; PlayerSample(ARRAY_SIZE(argv), argv); }); return 0; } int TjdUiAppFindDeviceView::LoopPlayerStart() { PostEventHandle([]() { const char *argv[] = {"loopon"}; PlayerSample(ARRAY_SIZE(argv), argv); }); return 0; } } // namespace TJD