* @Author: luozheng 1732036298@qq.com
* @Date: 2024-03-27 10:47:46
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-27 14:34:02
+ * @LastEditTime: 2024-03-27 19:39:53
* @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"
namespace OHOS
{
{
if (viewInitStatus == true)
{
- FindPhoneGroupView->RemoveAll();
+ if (FindPhoneGroupView != nullptr)
+ {
+ FindPhoneGroupView->RemoveAll();
- delete FindPhoneTitleLabel;
- FindPhoneTitleLabel = nullptr;
+ if (FindPhoneTitleLabel == nullptr)
+ {
+ delete FindPhoneTitleLabel;
+ FindPhoneTitleLabel = nullptr;
+ }
- FindPhoneImageAnimator->Stop();
- delete FindPhoneImageAnimator;
- FindPhoneImageAnimator = nullptr;
- FreeImagePathsArray(FindPhonePathsArray, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+ if (FindPhoneImageView != nullptr)
+ {
+ delete FindPhoneImageView;
+ FindPhoneImageView = nullptr;
+ }
- delete FindPhoneLabel;
- FindPhoneLabel = nullptr;
+ if (FindPhoneImageAnimator != nullptr)
+ {
+ FindPhoneImageAnimator->Stop();
+ delete FindPhoneImageAnimator;
+ FindPhoneImageAnimator = nullptr;
+ FreeImagePathsArray(FindPhonePathsArray, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+ }
- delete FindPhoneLabelButton;
- FindPhoneLabelButton = nullptr;
+ if (FindPhoneLabel != nullptr)
+ {
+ delete FindPhoneLabel;
+ FindPhoneLabel = nullptr;
+ }
- delete FindPhoneGroupView;
- FindPhoneGroupView = nullptr;
+ if (FindPhoneLabelButton != nullptr)
+ {
+ delete FindPhoneLabelButton;
+ FindPhoneLabelButton = nullptr;
+ }
+
+ delete FindPhoneGroupView;
+ FindPhoneGroupView = nullptr;
+ }
}
}
}
}
- void FindPhoneView::FindPhoneViewInit(void)
+ /*蓝牙如果是未连接状态*/
+ void FindPhoneView::FindPhoneViewInit_BlueToothDisConnected(void)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::FindPhoneViewInit");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::FindPhoneViewInit_BlueToothConnected");
if (FindPhoneGroupView == nullptr)
{
/* --------------------------- FindPhoneGroupView --------------------------- */
FindPhoneGroupView = new UIViewGroup();
if (FindPhoneGroupView == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit] FindPhoneGroupView new fail!!");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneGroupView new fail!!");
return;
}
FindPhoneGroupView->SetPosition(0, 0, 466, 466);
FindPhoneTitleLabel = new UILabelExt();
if (FindPhoneTitleLabel == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit] FindPhoneTitleLabel new fail!!");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
+ return;
+ }
+ FindPhoneTitleLabel->SetPosition(133, 51, 200, 40);
+ FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ FindPhoneTitleLabel->SetText("查找手机");
+ FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+ FindPhoneTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ FindPhoneTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ /* ----------------------- FindPhoneImageView ---------------------- */
+ FindPhoneImageView = new UIImageView();
+ if (FindPhoneImageView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
+ return;
+ }
+ FindPhoneImageView->SetPosition(193, 140, 80, 80);
+ const char *imagesPath = "/user/res/FastTrainingAttentionVector.bin";
+ FindPhoneImageView->SetSrc(imagesPath);
+ /* ----------------------------- FindPhoneLabel ----------------------------- */
+ FindPhoneLabel = new UILabelExt();
+ if (FindPhoneLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabel new fail");
+ return;
+ }
+ FindPhoneLabel->SetPosition(33, 270, 400, 40);
+ FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ FindPhoneLabel->SetText("蓝牙未连接");
+ FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+ 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_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabelButton new fail");
+ return;
+ }
+ FindPhoneLabelButton->SetPosition(0, 366, 466, 100);
+ FindPhoneLabelButton->SetViewId(FINDPHONE_LABELBUTTON);
+ const char *ImgSrc = "/user/res/466x100button.bin";
+ FindPhoneLabelButton->SetImageSrc(ImgSrc, ImgSrc);
+ FindPhoneLabelButton->SetText("关闭");
+ FindPhoneLabelButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff));
+ FindPhoneLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ FindPhoneLabelButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+ UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(FindPhonePresenter::GetInstance());
+ FindPhoneLabelButton->SetOnClickListener(clickListener);
+ /* ----------------------------------- Add ---------------------------------- */
+ FindPhoneGroupView->Add(FindPhoneTitleLabel);
+ FindPhoneGroupView->Add(FindPhoneImageView);
+ FindPhoneGroupView->Add(FindPhoneLabel);
+ FindPhoneGroupView->Add(FindPhoneLabelButton);
+ }
+ viewInitStatus = true;
+ }
+
+ /*蓝牙如果是已连接状态将初始化这个视图*/
+ void FindPhoneView::FindPhoneViewInit_BlueToothConnected(void)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::FindPhoneViewInit_BlueToothConnected");
+ if (FindPhoneGroupView == nullptr)
+ {
+ /* --------------------------- FindPhoneGroupView --------------------------- */
+ FindPhoneGroupView = new UIViewGroup();
+ if (FindPhoneGroupView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneGroupView new fail!!");
+ return;
+ }
+ FindPhoneGroupView->SetPosition(0, 0, 466, 466);
+ FindPhoneGroupView->SetStyle(STYLE_BACKGROUND_OPA, 0);
+ /* --------------------------- FindPhoneTitleLabel -------------------------- */
+ FindPhoneTitleLabel = new UILabelExt();
+ if (FindPhoneTitleLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
return;
}
FindPhoneTitleLabel->SetPosition(133, 51, 200, 40);
void FindPhoneView::OnStart()
{
View<FindPhonePresenter>::OnStart();
- FindPhoneViewInit();
+ if (FindPhoneModel::GetInstance().GetBlueToothConnectedState() == true) // 判断蓝牙是否是连接状态
+ {
+ FindPhoneViewInit_BlueToothConnected();
+ }
+ else
+ {
+ FindPhoneViewInit_BlueToothDisConnected();
+ }
// 增加按键监听
RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::FindPhonePresenter::GetInstance();
RootView::GetInstance()->SetOnKeyActListener(keyactListener);