--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-27 10:47:40
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2025-02-25 17:43:45
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp
+ */
+#include "AppViewIDs.h"
+#include "UiConfig.h"
+#include "components/ui_label_ext.h"
+#include "ui_resource_string.h"
+#include "NativeAbility.h"
+#include "findphone/include/FindPhonePresenter.h"
+#include "findphone/include/FindPhoneModel.h"
+#include "findphone/include/FindPhoneView.h"
+#include "gfx_utils/mem_check.h"
+#include "bluetooth/include/BluetoothModel.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
+#include "NativeRegisterManager.h"
+
+#ifdef SUPPORT_BLE_SERVICE
+#include "bleEvent.h"
+#endif
+
+namespace OHOS
+{
+ REGIST_MENU_PRO(VIEW_FIND_PHONE, FindPhoneView, FindPhonePresenter, PNG_APPLIST_FINDPHONE_IMAGE_BIG,
+ PNG_APPLIST_FINDPHONE_IMAGE, PNG_APPLIST_FINDPHONE_IMAGE, "查找手机", STR_FIND_PHONE);
+
+ // 当前Presenter属性实例化的内存指针
+ static FindPhonePresenter *g_pFindPhonePresenter = nullptr;
+
+ FindPhonePresenter::FindPhonePresenter()
+ {
+ g_pFindPhonePresenter = this;
+#ifdef MEM_CHECK
+ MemCheck::GetInstance()->EnableLeakCheck(true);
+#endif
+ }
+
+ FindPhonePresenter::~FindPhonePresenter()
+ {
+ g_pFindPhonePresenter = nullptr;
+#ifdef MEM_CHECK
+ MemCheck::GetInstance()->EnableLeakCheck(false);
+#endif
+ }
+
+ FindPhonePresenter *FindPhonePresenter::GetInstance()
+ {
+ return g_pFindPhonePresenter;
+ }
+
+ void FindPhonePresenter::OnStart()
+ {
+#ifdef SUPPORT_BLE_SERVICE
+ if (FindPhoneModel::GetInstance().GetBlueToothConnectedState() &&
+ uapi_a2dp_snk_get_device_connect_state()) // 判断与手机蓝牙是否连接和判断a2dp是否是已连接状态
+ {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnStart a2dp is connected");
+ uapi_a2dp_snk_disconnect(); // 先断开a2dp
+ }
+#endif
+ }
+
+ void FindPhonePresenter::OnPause(void)
+ {
+ Presenter<FindPhoneView>::OnPause();
+ }
+
+ void FindPhonePresenter::OnResume(void)
+ {
+ Presenter<FindPhoneView>::OnResume();
+ }
+
+ void FindPhonePresenter::OnStop(void)
+ {
+#ifdef SUPPORT_BLE_SERVICE
+ FindPhoneModel::GetInstance().start_or_stop_find_phone(FINDPHONE_STOP); // 发送指令停止震动
+ if (FindPhoneModel::GetInstance().GetBlueToothConnectedState() &&
+ !uapi_a2dp_snk_get_device_connect_state()) // 判断与手机蓝牙是否连接和判断a2dp是为连接状态
+ {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnStop a2dp is not connected");
+ uapi_a2dp_snk_connect(); // 主动连接a2dp
+ }
+#endif
+ }
+
+ bool FindPhonePresenter::OnClick(UIView &view, const ClickEvent &event)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnClick");
+ UNUSED(event);
+ if (strcmp(view.GetViewId(), FINDPHONE_LABELBUTTON) == 0)
+ {
+ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ }
+ return true;
+ }
+
+ bool FindPhonePresenter::OnDrag(UIView &view, const DragEvent &event)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnDrag");
+ UNUSED(view);
+ if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
+ {
+ FindPhonePresenter::X_DRAG_FLAG = true;
+ }
+ return true;
+ }
+
+ bool FindPhonePresenter::OnDragEnd(UIView &view, const DragEvent &event)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnDragEnd");
+ UNUSED(event);
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && FindPhonePresenter::X_DRAG_FLAG)
+ {
+ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ FindPhonePresenter::X_DRAG_FLAG = false;
+ }
+ return true;
+ }
+
+ bool FindPhonePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件
+ {
+ UNUSED(view);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnKeyAct");
+ unsigned short keyID = event.GetKeyId();
+ unsigned short keyState = event.GetState();
+ // 如果是power键,且是亮屏状态,按键释放就返回上一级
+ if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
+ {
+ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ }
+ return true;
+ }
+}
\ No newline at end of file
--- /dev/null
+/***
+ * @Date: 2024-06-19 19:25:22
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-08-30 19:23:15
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp
+ */
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-27 10:47:46
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2025-02-25 16:19:36
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp
+ */
+#include "findphone/include/FindPhoneView.h"
+#include "findphone/include/FindPhonePresenter.h"
+#include "wearable_log.h"
+#include "findphone/include/FindPhoneModel.h"
+#include "UiConfig.h"
+#include "ui_resource_string.h"
+#include "uicomponents/UIComponents.h"
+
+#ifdef SUPPORT_BLE_SERVICE
+#include "bletest.h"
+#include "bleEvent.h"
+#endif
+namespace OHOS
+{
+
+ static FindPhoneView *g_pFindPhoneView{nullptr};
+ static constexpr const char *FIND_PONE_IMAGE_SRC = "/user/res/findphone/";
+
+ FindPhoneView::FindPhoneView()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::FindPhoneView");
+ g_pFindPhoneView = this;
+ }
+
+ FindPhoneView::~FindPhoneView()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::~FindPhoneView");
+ ClearAll();
+ g_pFindPhoneView = nullptr;
+ }
+
+ FindPhoneView *FindPhoneView::GetInstance()
+ {
+ return g_pFindPhoneView;
+ }
+
+ void FindPhoneView::ClearAll()
+ {
+ if (FindPhoneGroupView != nullptr)
+ {
+ FindPhoneGroupView->RemoveAll();
+
+ if (FindPhoneTitleLabel != nullptr)
+ {
+ delete FindPhoneTitleLabel;
+ FindPhoneTitleLabel = nullptr;
+ }
+ if (FindPhoneImageView != nullptr)
+ {
+ delete FindPhoneImageView;
+ FindPhoneImageView = nullptr;
+ }
+ if (FindPhoneImageAnimator != nullptr)
+ {
+ FindPhoneImageAnimator->Stop();
+ delete FindPhoneImageAnimator;
+ FindPhoneImageAnimator = nullptr;
+ FreeImageInfoArray(FindPhonePathsArray, FIND_PONE_IMAGE_SRC, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+ }
+ if (FindPhoneLabel != nullptr)
+ {
+ delete FindPhoneLabel;
+ FindPhoneLabel = nullptr;
+ }
+ if (FindPhoneLabelButton != nullptr)
+ {
+ delete FindPhoneLabelButton;
+ FindPhoneLabelButton = nullptr;
+ }
+ delete FindPhoneGroupView;
+ FindPhoneGroupView = nullptr;
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneView::ClearAll over!!");
+ }
+ }
+
+ /*蓝牙如果是未连接状态*/
+ void FindPhoneView::FindPhoneViewInit_BlueToothDisConnected(void)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneView::FindPhoneViewInit_BlueToothConnected");
+ if (FindPhoneGroupView == nullptr)
+ {
+ /* --------------------------- FindPhoneGroupView --------------------------- */
+ FindPhoneGroupView = new UIViewGroup();
+ if (FindPhoneGroupView == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneGroupView new fail!!");
+ return;
+ }
+ FindPhoneGroupView->SetPosition(0, 0, 466, 466);
+ FindPhoneGroupView->SetStyle(STYLE_BACKGROUND_OPA, 0);
+ FindPhoneGroupView->SetTouchable(true);
+ FindPhoneGroupView->SetDraggable(true);
+ FindPhoneGroupView->SetOnDragListener(presenter_);
+ /* --------------------------- FindPhoneTitleLabel -------------------------- */
+ FindPhoneTitleLabel = new UILabelExt();
+ if (FindPhoneTitleLabel == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
+ return;
+ }
+ FindPhoneTitleLabel->SetPosition(83, 50, 300, 35);
+ FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE); // 查找手机
+ FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ FindPhoneTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ FindPhoneTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ /* ----------------------- FindPhoneImageView ---------------------- */
+ FindPhoneImageView = new UIImageView();
+ if (FindPhoneImageView == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
+ return;
+ }
+ FindPhoneImageView->SetPosition(193, 140, 80, 80);
+#ifdef FD230
+ FindPhoneImageView->SetSrc(PNG_ATTENTION_IMAGE);
+#endif
+ /* ----------------------------- FindPhoneLabel ----------------------------- */
+ FindPhoneLabel = new UILabelExt();
+ if (FindPhoneLabel == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabel new fail");
+ return;
+ }
+ FindPhoneLabel->SetPosition(83, 270, 300, 35);
+ FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ FindPhoneLabel->SetTextId(STR_BLUETOOTH_DISCONNECTED); // 蓝牙未连接
+ FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ FindPhoneLabel->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff));
+ FindPhoneLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ FindPhoneLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ /* -------------------------- FindPhoneLabelButton -------------------------- */
+ FindPhoneLabelButton = new UILabelButtonExt();
+ if (FindPhoneLabelButton == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabelButton new fail");
+ return;
+ }
+ FindPhoneLabelButton->SetPosition(0, 366, 466, 100);
+ FindPhoneLabelButton->SetViewId(FINDPHONE_LABELBUTTON);
+#ifdef FD230
+ FindPhoneLabelButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE);
+#endif
+ FindPhoneLabelButton->SetTextId(STR_CLOSE); // 关闭
+ FindPhoneLabelButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff));
+ FindPhoneLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ FindPhoneLabelButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+ FindPhoneLabelButton->SetOnClickListener(presenter_);
+ /* ----------------------------------- Add ---------------------------------- */
+ FindPhoneGroupView->Add(FindPhoneTitleLabel);
+ FindPhoneGroupView->Add(FindPhoneImageView);
+ FindPhoneGroupView->Add(FindPhoneLabel);
+ FindPhoneGroupView->Add(FindPhoneLabelButton);
+ AddViewToRootContainer(FindPhoneGroupView);
+ }
+ }
+
+ /*蓝牙如果是已连接状态将初始化这个视图*/
+ void FindPhoneView::FindPhoneViewInit_BlueToothConnected(void)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhoneView::FindPhoneViewInit_BlueToothConnected");
+ if (FindPhoneGroupView == nullptr)
+ {
+ /* --------------------------- FindPhoneGroupView --------------------------- */
+ FindPhoneGroupView = new UIViewGroup();
+ if (FindPhoneGroupView == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneGroupView new fail!!");
+ return;
+ }
+ FindPhoneGroupView->SetPosition(0, 0, 466, 466);
+ FindPhoneGroupView->SetStyle(STYLE_BACKGROUND_OPA, 0);
+ FindPhoneGroupView->SetTouchable(true);
+ FindPhoneGroupView->SetDraggable(true);
+ FindPhoneGroupView->SetOnDragListener(presenter_);
+ /* --------------------------- FindPhoneTitleLabel -------------------------- */
+ FindPhoneTitleLabel = new UILabelExt();
+ if (FindPhoneTitleLabel == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
+ return;
+ }
+ FindPhoneTitleLabel->SetPosition(83, 50, 300, 35);
+ FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE); // 查找手机
+ FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ FindPhoneTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ FindPhoneTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ /* ----------------------- FindPhoneImageAnimator ---------------------- */
+ FindPhonePathsArray = CreateImageInfoArray(FIND_PONE_IMAGE_SRC, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+ if (FindPhoneImageAnimator == nullptr)
+ {
+ FindPhoneImageAnimator = new UIImageAnimatorView();
+ if (FindPhoneImageAnimator == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneImageAnimator new fail");
+ return;
+ }
+ for (uint8_t i = 0; i < FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)
+ {
+ // FindPhoneImageInfo[i].imagePath = (FindPhonePathsArray[i]);
+ // FindPhoneImageInfo[i].imageType = IMG_SRC_FILE_PATH;
+ FindPhoneImageInfo[i].imageInfo = (FindPhonePathsArray[i]);
+ FindPhoneImageInfo[i].imageType = IMG_SRC_IMAGE_INFO;
+ FindPhoneImageInfo[i].pos.x = FINDPHONE_IMAGE_ANIMATOR_VIEW_X;
+ FindPhoneImageInfo[i].pos.y = FINDPHONE_IMAGE_ANIMATOR_VIEW_Y;
+ FindPhoneImageInfo[i].width = FINDPHONE_IMAGE_ANIMATOR_VIEW_W;
+ FindPhoneImageInfo[i].height = FINDPHONE_IMAGE_ANIMATOR_VIEW_H;
+ }
+ FindPhoneImageAnimator->SetPosition(FINDPHONE_IMAGE_ANIMATOR_VIEW_X, FINDPHONE_IMAGE_ANIMATOR_VIEW_Y, FINDPHONE_IMAGE_ANIMATOR_VIEW_W, FINDPHONE_IMAGE_ANIMATOR_VIEW_H);
+ FindPhoneImageAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+ FindPhoneImageAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ FindPhoneImageAnimator->SetImageAnimatorSrc(FindPhoneImageInfo, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, FINDPHONE_IMAGE_ANIMATOR_VIEW_TIMEOFUPDATE);
+ FindPhoneImageAnimator->SetRepeat(true);
+ FindPhoneImageAnimator->Start();
+ }
+ /* ----------------------------- FindPhoneLabel ----------------------------- */
+ FindPhoneLabel = new UILabelExt();
+ if (FindPhoneLabel == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabel new fail");
+ return;
+ }
+ FindPhoneLabel->SetPosition(83, 270, 300, 35);
+ FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ FindPhoneLabel->SetTextId(STR_PHONE_RINGING_VIBRATING); // 手机正在响铃/震动
+ FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ FindPhoneLabel->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff));
+ FindPhoneLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ FindPhoneLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ /* -------------------------- FindPhoneLabelButton -------------------------- */
+ FindPhoneLabelButton = new UILabelButtonExt();
+ if (FindPhoneLabelButton == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabelButton new fail");
+ return;
+ }
+ FindPhoneLabelButton->SetPosition(0, 366, 466, 100);
+ FindPhoneLabelButton->SetViewId(FINDPHONE_LABELBUTTON);
+#ifdef FD230
+ FindPhoneLabelButton->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE);
+#endif
+ // FindPhoneLabelButton->SetText("停止");
+ FindPhoneLabelButton->SetTextId(STR_STOP);
+ FindPhoneLabelButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff));
+ FindPhoneLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ FindPhoneLabelButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+ FindPhoneLabelButton->SetOnClickListener(presenter_);
+ /* ----------------------------------- Add ---------------------------------- */
+ FindPhoneGroupView->Add(FindPhoneTitleLabel);
+ FindPhoneGroupView->Add(FindPhoneImageAnimator);
+ FindPhoneGroupView->Add(FindPhoneLabel);
+ FindPhoneGroupView->Add(FindPhoneLabelButton);
+ AddViewToRootContainer(FindPhoneGroupView);
+ }
+ }
+
+ void FindPhoneView::OnStart()
+ {
+ if (FindPhoneModel::GetInstance().GetBlueToothConnectedState() == true) // 判断蓝牙是否是连接状态
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phone is connected");
+ FindPhoneViewInit_BlueToothConnected();
+ FindPhoneModel::GetInstance().start_or_stop_find_phone(FINDPHONE_START);
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phone is not connected");
+ FindPhoneViewInit_BlueToothDisConnected();
+ }
+ return;
+ }
+}
\ No newline at end of file