From 0e9cbd2eda91c9d9e74dd44e40a972afdffd2a48 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Mon, 30 Sep 2024 11:46:08 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B3#832=E6=89=8B=E8=A1=A8?= =?utf8?q?=E4=B8=8EAPP=E8=93=9D=E7=89=99=E6=96=AD=E8=BF=9E=EF=BC=8C?= =?utf8?q?=E6=89=8B=E8=A1=A8=E7=AB=AF=E7=82=B9=E5=87=BB=E6=89=BE=E6=89=8B?= =?utf8?q?=E6=9C=BA=EF=BC=8C=E7=95=8C=E9=9D=A2=E4=B8=8D=E4=BC=9A=E5=BC=B9?= =?utf8?q?=E5=87=BA=E8=93=9D=E7=89=99=E6=96=AD=E8=BF=9E=E6=8F=90=E7=A4=BAb?= =?utf8?q?ug=20=E6=9F=A5=E6=89=BE=E6=89=8B=E6=9C=BA=E7=95=8C=E9=9D=A2?= =?utf8?q?=E4=BC=9A=E6=A0=B9=E6=8D=AE=E6=89=8B=E6=9C=BA=E8=93=9D=E7=89=99?= =?utf8?q?=E6=98=AF=E5=90=A6=E6=9C=89=E6=97=A0=E8=BF=9E=E6=8E=A5=E6=98=BE?= =?utf8?q?=E7=A4=BA=E4=B8=8D=E5=90=8C=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../findphone/include/FindPhoneModel.h | 3 +- .../findphone/include/FindPhoneView.h | 3 +- .../nativeui/findphone/src/FindPhoneModel.cpp | 21 ++- .../findphone/src/FindPhonePresenter.cpp | 18 +-- .../nativeui/findphone/src/FindPhoneView.cpp | 131 ++++++++---------- 5 files changed, 77 insertions(+), 99 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h b/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h index af97544e7..0418fd11d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-27 15:21:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-05-10 16:23:41 + * @LastEditTime: 2024-09-30 11:10:19 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h */ #ifndef FINDPHONE_MODEL_H @@ -16,6 +16,7 @@ namespace OHOS static FindPhoneModel &GetInstance(); void SetBlueToothConnectedState(bool state); bool GetBlueToothConnectedState(); + void start_or_stop_find_phone(int val); private: FindPhoneModel() {} ~FindPhoneModel() {} diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h b/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h index 940f76b64..7a0f7f8a8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-31 09:52:34 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-31 16:38:04 + * @LastEditTime: 2024-09-30 11:15:01 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -51,7 +51,6 @@ namespace OHOS UIImageView *FindPhoneImageView{nullptr}; const ImageInfo **FindPhonePathsArray{nullptr}; ImageAnimatorInfo FindPhoneImageInfo[FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; - bool viewInitStatus{false}; }; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp index b2cbdeea3..eb54d6463 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-27 15:21:30 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-05-10 17:00:42 + * @LastEditTime: 2024-09-30 11:11:00 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp */ @@ -10,6 +10,7 @@ #include "bletest.h" #include #include "wearable_log.h" +#include "bleEvent.h" namespace OHOS { @@ -28,12 +29,22 @@ namespace OHOS /*获取与手机蓝牙是否已连接*/ bool FindPhoneModel::GetBlueToothConnectedState() { - //return ble_is_ready() && ble_is_connect_ready(); + // return ble_is_ready() && ble_is_connect_ready(); uint8_t ret = uapi_dev_runtime_get_ble_connect_stat(); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ble phone connect stat = %d", ret); if (ret == 1) - return true; - else - return false; + return true; + else + return false; + } + + // 开始或停止查找手机 + void FindPhoneModel::start_or_stop_find_phone(int val) + { + // 发送指令停止震动 + if (FindPhoneModel::GetInstance().GetBlueToothConnectedState()) + { + senfindphoneSend(val); + } } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp index 941ba0dd4..635b86ad3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-27 10:47:40 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-31 16:43:28 + * @LastEditTime: 2024-09-30 11:13:11 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp */ #include "AppViewIDs.h" @@ -60,6 +60,7 @@ namespace OHOS void FindPhonePresenter::OnStop(void) { Presenter::OnStop(); + FindPhoneModel::GetInstance().start_or_stop_find_phone(FINDPHONE_STOP); // 发送指令停止震动 } bool FindPhonePresenter::OnClick(UIView &view, const ClickEvent &event) @@ -68,11 +69,6 @@ namespace OHOS UNUSED(event); if (strcmp(view.GetViewId(), FINDPHONE_LABELBUTTON) == 0) { - // 发送指令停止震动 - if (FindPhoneModel::GetInstance().GetBlueToothConnectedState()) - { - senfindphoneSend(FINDPHONE_STOP); - } NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); } return true; @@ -96,11 +92,6 @@ namespace OHOS if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && FindPhonePresenter::X_DRAG_FLAG) { NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); - // 发送指令停止震动 - if (FindPhoneModel::GetInstance().GetBlueToothConnectedState()) - { - senfindphoneSend(FINDPHONE_STOP); - } FindPhonePresenter::X_DRAG_FLAG = false; } return true; @@ -115,11 +106,6 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { - // 发送指令停止震动 - if (FindPhoneModel::GetInstance().GetBlueToothConnectedState()) - { - senfindphoneSend(FINDPHONE_STOP); - } NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); } return true; diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp index 758763a55..706259f02 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp @@ -8,7 +8,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-27 10:47:46 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-31 18:27:22 + * @LastEditTime: 2024-09-30 11:31:16 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp */ #include "findphone/include/FindPhoneView.h" @@ -45,54 +45,47 @@ namespace OHOS void FindPhoneView::ClearAll() { - if (viewInitStatus == true) + if (container_ != nullptr) { - // UIViewGroup *tmpGroup = dynamic_cast(container_); - // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); - // FreeImageInfoArray(FindPhonePathsArray, FIND_PONE_IMAGE_SRC, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + + if (FindPhoneGroupView != nullptr) + { + FindPhoneGroupView->RemoveAll(); - if (container_ != nullptr) + if (FindPhoneTitleLabel != nullptr) { - container_->RemoveAll(); - delete container_; - container_ = nullptr; + delete FindPhoneTitleLabel; + FindPhoneTitleLabel = nullptr; } - if (FindPhoneGroupView != nullptr) + if (FindPhoneImageView != 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; - // FreeImagePathsArray(FindPhonePathsArray, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - 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_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::ClearAll over!!"); + 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_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::ClearAll over!!"); } } @@ -121,12 +114,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!"); return; } - FindPhoneTitleLabel->SetPosition(133, 51, 200, 40); + FindPhoneTitleLabel->SetPosition(83, 50, 300, 35); FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30); FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - // FindPhoneTitleLabel->SetText("查找手机"); - FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE); - FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + 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 ---------------------- */ @@ -145,12 +137,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabel new fail"); return; } - FindPhoneLabel->SetPosition(33, 270, 400, 40); + FindPhoneLabel->SetPosition(53, 270, 360, 35); FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30); FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - // FindPhoneLabel->SetText("蓝牙未连接"); - FindPhoneLabel->SetTextId(STR_BLUETOOTH_DISCONNECTED); - FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + 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); @@ -164,8 +155,7 @@ namespace OHOS FindPhoneLabelButton->SetPosition(0, 366, 466, 100); FindPhoneLabelButton->SetViewId(FINDPHONE_LABELBUTTON); FindPhoneLabelButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE); - // FindPhoneLabelButton->SetText("关闭"); - FindPhoneLabelButton->SetTextId(STR_CLOSE); + 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); @@ -177,7 +167,6 @@ namespace OHOS FindPhoneGroupView->Add(FindPhoneLabelButton); container_->Add(FindPhoneGroupView); } - viewInitStatus = true; } /*蓝牙如果是已连接状态将初始化这个视图*/ @@ -205,12 +194,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!"); return; } - FindPhoneTitleLabel->SetPosition(133, 51, 200, 40); + FindPhoneTitleLabel->SetPosition(83, 50, 300, 35); FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30); FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - // FindPhoneTitleLabel->SetText("查找手机"); - FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE); - FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + 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 ---------------------- */ @@ -247,12 +235,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabel new fail"); return; } - FindPhoneLabel->SetPosition(33, 270, 400, 40); + FindPhoneLabel->SetPosition(53, 270, 360, 35); FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30); FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - // FindPhoneLabel->SetText("手机正在响铃/震动"); - FindPhoneLabel->SetTextId(STR_PHONE_RINGING_VIBRATING); - FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + 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); @@ -279,21 +266,11 @@ namespace OHOS FindPhoneGroupView->Add(FindPhoneLabelButton); container_->Add(FindPhoneGroupView); } - viewInitStatus = true; } void FindPhoneView::OnStart() { View::OnStart(); - // if (FindPhoneModel::GetInstance().GetBlueToothConnectedState() == true) // 判断蓝牙是否是连接状态 - // { - // FindPhoneViewInit_BlueToothConnected(); - // senfindphoneSend(FINDPHONE_START); - // } - // else - // { - // FindPhoneViewInit_BlueToothDisConnected(); - // } SetContainerView(new UIViewGroup()); if (GetContainer() == nullptr) { @@ -304,12 +281,16 @@ namespace OHOS container_->SetTouchable(true); container_->SetDraggable(true); - if (!viewInitStatus) + if (FindPhoneModel::GetInstance().GetBlueToothConnectedState() == true) // 判断蓝牙是否是连接状态 { FindPhoneViewInit_BlueToothConnected(); - senfindphoneSend(FINDPHONE_START); - viewInitStatus = true; + FindPhoneModel::GetInstance().start_or_stop_find_phone(FINDPHONE_START); } + else + { + FindPhoneViewInit_BlueToothDisConnected(); + } + RootView::GetInstance()->SetOnKeyActListener(presenter_); } -- 2.17.1