From 788eadddf386411eb7e910d4140076bd370ef469 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Mon, 19 May 2025 17:41:33 +0800 Subject: [PATCH] =?utf8?q?=E5=90=84=E4=B8=AA=E7=95=8C=E9=9D=A2=E7=9A=84?= =?utf8?q?=E6=8C=89=E9=94=AE=E7=9B=91=E5=90=AC=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeabilityfwk/include/Presenter.h | 3 +- .../nativeui/add_card/src/AddCardView.cpp | 3 +- .../nativeui/assistant/src/AssistantView.cpp | 2 +- .../bloodoxygen/src/BloodDetectionView.cpp | 1 + .../bloodoxygen/src/BloodResultView.cpp | 1 + .../bluetooth/src/MainBluetoothView.cpp | 18 +- .../src/BrightnessLevelView.cpp | 4 +- .../nativeui/calendar/src/CalendarView.cpp | 1 + .../src/BluetoothServiceOptionsView.cpp | 2 + .../src/ClassicBlueToothView.cpp | 1 + .../compass/include/CompassCalibrationView.h | 69 ++-- .../compass/include/CompassControlView.h | 72 ++-- .../nativeui/compass/include/CompassModel.h | 73 ++-- .../compass/include/CompassPresenter.h | 93 ++--- .../nativeui/compass/include/CompassView.h | 99 ++--- .../compass/include/MainCompassPresenter.h | 70 ++-- .../compass/include/MainCompassView.h | 86 ++-- .../compass/src/CompassCalibrationView.cpp | 132 ++++--- .../compass/src/CompassControlView.cpp | 31 +- .../nativeui/compass/src/CompassModel.cpp | 47 ++- .../nativeui/compass/src/CompassPresenter.cpp | 374 ++++++++++-------- .../nativeui/compass/src/CompassView.cpp | 164 ++++++-- .../compass/src/MainCompassPresenter.cpp | 56 ++- .../nativeui/compass/src/MainCompassView.cpp | 10 +- .../countdown/src/MainCountDownView.cpp | 1 + .../dnotdisturb/src/DnotDisturbView.cpp | 1 + .../nativeui/findphone/src/FindPhoneView.cpp | 1 + .../flashlight/src/FlashlightView.cpp | 1 + .../nativeui/goal/src/Maingoalview.cpp | 1 + .../heartrate/src/HeartDetectionView.cpp | 2 +- .../heartrate/src/HeartResultView.cpp | 2 +- .../nativeui/message/src/MessageShowView.cpp | 1 + .../src/MotionRecognitionView.cpp | 1 + .../networkandcall/src/NetworkAndCallView.cpp | 2 +- .../src/RebootAndShutdownView.cpp | 2 +- .../nativeui/record/src/RecordingView.cpp | 1 + .../src/RespiratoryTrainingView.cpp | 1 + .../nativeui/saveele/src/SaveBatView.cpp | 2 +- .../nativeui/saveele/src/SaveEleView.cpp | 1 + .../nativeui/schedule/src/ScheduleView.cpp | 1 + .../set_time_format/src/SetTimeFormatView.cpp | 1 + .../soundandvibration/src/CallVolumeView.cpp | 1 + .../src/SoundAndVibrationView.cpp | 1 + .../src/SystemVolumeView.cpp | 1 + .../stopwatch/src/MainStopWatchView.cpp | 1 + .../takephotos/src/TakephotosView.cpp | 1 + .../nativeui/weather/src/MainWeatherView.cpp | 1 + 47 files changed, 866 insertions(+), 574 deletions(-) diff --git a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Presenter.h b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Presenter.h index 76276cc2e..405702479 100644 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Presenter.h +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Presenter.h @@ -51,7 +51,8 @@ public: RootView::GetInstance()->Add(view_->GetRootContainer()); } // Reset the default key listener - RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance()); + if(NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN || NativeAbility::GetInstance().GetCurSliceId() == VIEW_APPLIST) + RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance());//加判断条件是解决其他界面按键监听被覆盖的问题 UIView* backView = PageTransitionMgr::GetInstance().GetTopSlideBackImage(); if (backView == nullptr) { return; diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/add_card/src/AddCardView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/add_card/src/AddCardView.cpp index 5498e6d3e..62fe5ba0d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/add_card/src/AddCardView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/add_card/src/AddCardView.cpp @@ -34,7 +34,8 @@ namespace OHOS SetUpListInfo(); SetUpListView(); SetUpToast(); -//按键监听 + //按键监听 + RootView::GetInstance()->SetOnKeyActListener(presenter_); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantView.cpp index 50e4d7824..ae7bbd7e8 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantView.cpp @@ -241,7 +241,7 @@ void AssistantView::OnStart() { InitView(); - //RootView::GetInstance()->SetOnKeyActListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); AddViewToRootContainer(AssistantScrollView[ASSISTANT_MAIN_VIEW]); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodDetectionView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodDetectionView.cpp index 76075bf74..835b3288f 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodDetectionView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodDetectionView.cpp @@ -163,6 +163,7 @@ namespace OHOS // 增加按键监听 // presenter_->SetOnKeyActListener(keyactListener); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodResultView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodResultView.cpp index 8d5a118f3..500ccffba 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodResultView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bloodoxygen/src/BloodResultView.cpp @@ -209,6 +209,7 @@ namespace OHOS // 增加按键监听 // RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::BloodResultPresenter::GetInstance(); //RootView::GetInstance()->SetOnKeyActListener(keyactListener); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp index bd59fb640..bab8aed35 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp @@ -76,7 +76,7 @@ void MainBluetoothView::OnStart() } else { ChangeView(unusedValue, BLUETOOTHEARPHONEVIEW);//若一个都没有连接过就进行搜索 } - RootView::GetInstance()->Invalidate(); + RootView::GetInstance()->SetOnKeyActListener(presenter_); return; } @@ -98,7 +98,7 @@ bool MainBluetoothView::ChangeBluetoothDeviceListView(int16_t hideView, int16_t return false; } container[thisView] = group; - RootView::GetInstance()->Add(container[thisView]); + AddViewToRootContainer(container[thisView]); } // else { // // 刷新列表 @@ -132,7 +132,7 @@ bool MainBluetoothView::ChangeTipsFailMessageView(int16_t hideView, int16_t this return false; } container[thisView] = group; - RootView::GetInstance()->Add(container[thisView]); + AddViewToRootContainer(container[thisView]); } return true; } @@ -154,7 +154,7 @@ bool MainBluetoothView::ChangeTipsConnFailMessageView(int16_t hideView, int16_t return false; } container[thisView] = group; - RootView::GetInstance()->Add(container[thisView]); + AddViewToRootContainer(container[thisView]); } if (bluetoothReconnectView == nullptr) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback bluetoothReconnectView == nullptr"); @@ -183,7 +183,7 @@ bool MainBluetoothView::ChangeTipsSuccMessageView(int16_t hideView, int16_t this return false; } container[thisView] = group; - RootView::GetInstance()->Add(container[thisView]); + AddViewToRootContainer(container[thisView]); } return true; } @@ -205,7 +205,7 @@ bool MainBluetoothView::ChangeBluetoothEarPhoneView(int16_t hideView, int16_t th return false; } container[thisView] = group; - RootView::GetInstance()->Add(container[thisView]); + AddViewToRootContainer(container[thisView]); } // 动画开始 bluetoothEarPhoneView->BtAnimatorStart(); @@ -230,7 +230,7 @@ bool MainBluetoothView::ChangeBluetoothEarListView(int16_t hideView, int16_t thi return false; } container[thisView] = group; - RootView::GetInstance()->Add(container[thisView]); + AddViewToRootContainer(container[thisView]); } // else { // // 刷新列表 @@ -265,7 +265,7 @@ bool MainBluetoothView::ChangeBluetoothOptionsView(int16_t hideView, int16_t thi return false; } container[thisView] = group; - RootView::GetInstance()->Add(container[thisView]); + AddViewToRootContainer(container[thisView]); } return true; } @@ -287,7 +287,7 @@ bool MainBluetoothView::ChangeBluetoothReconnectView(int16_t hideView, int16_t t return false; } container[thisView] = group; - RootView::GetInstance()->Add(container[thisView]); + AddViewToRootContainer(container[thisView]); } BluetoothModel::GetInstance()->SetTagDisconnectView(true); bluetoothReconnectView->RefreshBluetoothNameLabel(); diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/brightnesslevel/src/BrightnessLevelView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/brightnesslevel/src/BrightnessLevelView.cpp index 71d08a097..bc91dd71f 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/brightnesslevel/src/BrightnessLevelView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/brightnesslevel/src/BrightnessLevelView.cpp @@ -73,8 +73,10 @@ namespace OHOS BrightnessLevelViewInit(); // 增加按键监听 - RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::BrightnessLevelPresenter::GetInstance(); + // RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::BrightnessLevelPresenter::GetInstance(); //RootView::GetInstance()->SetOnKeyActListener(keyactListener); + RootView::GetInstance()->SetOnKeyActListener(presenter_); + AddViewToRootContainer(scorllView); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/calendar/src/CalendarView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calendar/src/CalendarView.cpp index 8a922b3b7..c9adc983e 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/calendar/src/CalendarView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calendar/src/CalendarView.cpp @@ -394,5 +394,6 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error"); return; } + RootView::GetInstance()->SetOnKeyActListener(presenter_); } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp index 6522078c6..9b038aa1b 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp @@ -432,6 +432,8 @@ namespace OHOS connectingScrollView->SetDraggable(false); BlueToothScrollView->Add(connectingScrollView); AddViewToRootContainer(BlueToothScrollView); + + RootView::GetInstance()->SetOnKeyActListener(presenter_); } void BluetoothServiceOptionsView::show_connecting_view(bool data) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp index 23f7e8e2b..90f492c19 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp @@ -307,5 +307,6 @@ namespace OHOS BlueToothScrollView->Add(AttentionLabel); BlueToothScrollView->Add(TradionalBlueToothToggleButton); AddViewToRootContainer(BlueToothScrollView); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassCalibrationView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassCalibrationView.h index 704e60d96..fb80d8dfb 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassCalibrationView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassCalibrationView.h @@ -1,34 +1,37 @@ -/* - * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. - * Description: CompassCalibrationView.h - * Author: - * Create: 2022-04-02 - */ - -#ifndef COMPASS_CALIBRATION_VIEW_H -#define COMPASS_CALIBRATION_VIEW_H - -#include "components/ui_label.h" -#include "View.h" -#include "ohos_types.h" -#include "AppGroupView.h" -#include "components/ui_image_view.h" - -namespace OHOS { -class CompassCalibrationView : public AppGroupView { -public: - CompassCalibrationView(); - ~CompassCalibrationView() override; - - bool CreateUIViewGroup(void); - static CompassCalibrationView *GetInstance(void); - bool InitView(void *caller) override; -private: - UILabel *labelOne{nullptr}; - UILabel *labelTwo{nullptr}; - UIImageView *imageView{nullptr}; - - void ClearAll(void); -}; -} +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: CompassCalibrationView.h + * Author: + * Create: 2022-04-02 + */ + +#ifndef COMPASS_CALIBRATION_VIEW_H +#define COMPASS_CALIBRATION_VIEW_H + +#include "components/ui_label.h" +#include "View.h" +#include "ohos_types.h" +#include "AppGroupView.h" +#include "components/ui_image_view.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" + +namespace OHOS { +class CompassCalibrationView : public AppGroupView { +public: + CompassCalibrationView(); + ~CompassCalibrationView() override; + + bool CreateUIViewGroup(void); + static CompassCalibrationView *GetInstance(void); + bool InitView(void *caller) override; +private: + UILabelExt *labelOne{nullptr}; + UILabelExt *labelTwo{nullptr}; + UIImageView *imageView{nullptr}; + UIScrollView *scrollView{nullptr}; + + void ClearAll(void); +}; +} #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassControlView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassControlView.h index 3dc43f20f..9c776e9be 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassControlView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassControlView.h @@ -1,36 +1,36 @@ -/* - * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. - * Description: CompassControlView.h - * Author: - * Create: 2022-04-02 - */ - -#ifndef COMPASS_CONTROL_VIEW_H -#define COMPASS_CONTROL_VIEW_H - -#include "components/root_view.h" -#include "UiConfig.h" -#include "components/ui_card_page.h" -#include "CompassCalibrationView.h" -#include "CompassView.h" - -namespace OHOS { - -class CompassControlView : public UICardPage { -public: - CompassControlView(); - ~CompassControlView() override; - bool InitView(void); - void PreLoad(void) override; - void UnLoad(void) override; - void SetCalibrationView(bool flag); -private: - CompassCalibrationView *compassCalibrationView{nullptr}; - CompassView *compassView{nullptr}; - bool viewiInitStatus{false}; - bool isCalibration{false}; - - void ClearAll(void); -}; -} -#endif +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: CompassControlView.h + * Author: + * Create: 2022-04-02 + */ + +#ifndef COMPASS_CONTROL_VIEW_H +#define COMPASS_CONTROL_VIEW_H + +#include "components/root_view.h" +#include "UiConfig.h" +#include "components/ui_card_page.h" +#include "CompassCalibrationView.h" +#include "CompassView.h" + +namespace OHOS { + +class CompassControlView : public UICardPage { +public: + CompassControlView(); + ~CompassControlView() override; + bool InitView(void); + void PreLoad(void) override; + void UnLoad(void) override; + void SetCalibrationView(bool flag); +private: + CompassCalibrationView *compassCalibrationView{nullptr}; + CompassView *compassView{nullptr}; + bool viewiInitStatus{false}; + bool isCalibration{false}; + + void ClearAll(void); +}; +} +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassModel.h index 80cfd2f6a..12f2ed53d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassModel.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassModel.h @@ -1,38 +1,35 @@ -/* - * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. - * Description: CompassModel.h - * Author: - * Create: 2022-04-02 - */ - -#ifndef COMPASS_MODEL_H -#define COMPASS_MODEL_H - -#include - -namespace OHOS { -class CompassModel { -public: - static CompassModel *GetInstance(void); - bool OpenCompassSensor(void); - bool CloseCompassSensor(void); - void SetCalibrationStatus(uint8_t status); - uint8_t GetCalibrationStatus(void); - void SetDisplayAngle(uint16_t angle); - uint16_t GetDisplayAngle(void); -#if defined(_WIN32) -#undef GetCurrentTime -#endif - time_t GetCurrentTime(void); - void SetLastTime(time_t value); - time_t GetLastTime(void); - -private: - uint8_t calibrationStatus{1}; - uint16_t displayAngle{0}; - time_t lastTime{0}; -}; -} - -#endif - +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: CompassModel.h + * Author: + * Create: 2022-04-02 + */ + +#ifndef COMPASS_MODEL_H +#define COMPASS_MODEL_H + +#include + +namespace OHOS { +class CompassModel { +public: + static CompassModel *GetInstance(void); + bool OpenCompassSensor(void); + bool CloseCompassSensor(void); + void SetCalibrationStatus(uint8_t status); + uint8_t GetCalibrationStatus(void); + void SetDisplayAngle(uint16_t angle); + uint16_t GetDisplayAngle(void); + time_t GetCurrentTime(void); + void SetLastTime(time_t value); + time_t GetLastTime(void); + +private: + uint8_t calibrationStatus{1}; + uint16_t displayAngle{0}; + time_t lastTime{0}; +}; +} + +#endif + diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassPresenter.h index 68d6877d8..16a46417a 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassPresenter.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassPresenter.h @@ -1,46 +1,49 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: CompassPresenter.h - * Author: - * Create: 2021-12-21 - */ -#ifndef COMPASS_PRESENTER_H -#define COMPASS_PRESENTER_H - -#include "Presenter.h" -#include "components/ui_view.h" -#include "components/ui_image_view.h" -#include "ohos_types.h" -#include "UiConfig.h" -#include "AppViewIDs.h" -#include "CompassView.h" - -namespace OHOS { -typedef struct { - uint16_t beginAngle; - uint16_t endAngle; - const char *dir; -} CompassItem; - -class CompassView; -class CompassPresenter { -public: - CompassPresenter(); - virtual ~CompassPresenter(); - - static CompassPresenter *GetInstance(void); - void DisplayAngleDir(uint16_t angle); - void DetermineToRotate(void); - void InScopeRotate(void); - void TimeCreateRandomNum(void); - void DisplayAngleRight(uint16_t angle); - -private: - int16_t lastRotateAngle{0}; - int16_t currentRotateAngle{0}; - int16_t angleDiff{0}; - bool getAngleStatus{false}; - bool initDisplayStatus{true}; -}; -} +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CompassPresenter.h + * Author: + * Create: 2021-12-21 + */ +#ifndef COMPASS_PRESENTER_H +#define COMPASS_PRESENTER_H + +#include "Presenter.h" +#include "components/ui_view.h" +#include "components/ui_image_view.h" +#include "ohos_types.h" +#include "UiConfig.h" +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include"ui_resource_string.h" +#include "CompassView.h" + +namespace OHOS { +typedef struct { + uint16_t beginAngle; + uint16_t endAngle; + const char *dir; + int dir_textId;//方向的textid +} CompassItem; + +class CompassView; +class CompassPresenter { +public: + CompassPresenter(); + virtual ~CompassPresenter(); + + static CompassPresenter *GetInstance(void); + void DisplayAngleDir(uint16_t angle); + void DetermineToRotate(void); + void InScopeRotate(void); + void TimeCreateRandomNum(void); + void DisplayAngleRight(uint16_t angle); + +private: + int16_t lastRotateAngle{0}; //上一次的旋转角度 + int16_t currentRotateAngle{0}; //当前的旋转角度 + int16_t angleDiff{0}; //角度差 + bool getAngleStatus{false}; + bool initDisplayStatus{true}; +}; +} #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassView.h index 97cd957d1..a139a2523 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/CompassView.h @@ -1,47 +1,54 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: CompassView.h - * Author: - * Create: 2021-12-21 - */ - -#ifndef COMPASS_VIEW_H -#define COMPASS_VIEW_H - -#include "View.h" -#include "components/root_view.h" -#include "components/ui_label.h" -#include "components/ui_image_view.h" -#include "ChangeSliceListener.h" -#include "UiConfig.h" -#include "AppGroupView.h" -#include "CompassCalibrationView.h" - -namespace OHOS { -static constexpr float VIEW_CENTERS = 227; - -class CompassView : public AppGroupView { -public: - CompassView(); - ~CompassView() override; - - void DirectionSetText(const char *text, const char *angle); - static CompassView *GetInstance(void); - void CompassStartRotate(int16_t numb); - bool InitPage(void); - bool InitView(void *caller) override; - bool GetInitViewState(void); - bool InitCompassImage(void); - -private: - bool LoadCompassImage(UIImageView *view, uint32_t resId); - void ClearAll(void); - UILabel *directionLabel{nullptr}; - UILabel *angledLabel{nullptr}; - UIImageView *backGround{nullptr}; - UIImageView *rotateShaft{nullptr}; - UIImageView *triangulation{nullptr}; - const Vector2 VIEW_CENTER = {VIEW_CENTERS, VIEW_CENTERS}; -}; -} +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CompassView.h + * Author: + * Create: 2021-12-21 + */ + +#ifndef COMPASS_VIEW_H +#define COMPASS_VIEW_H + +#include "View.h" +#include "components/root_view.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "ChangeSliceListener.h" +#include "UiConfig.h" +#include "AppGroupView.h" +#include "CompassCalibrationView.h" + +namespace OHOS { +static constexpr float VIEW_CENTERS = 233;/*233代表分辨率为466的屏幕*/ + +class CompassView : public AppGroupView { +public: + CompassView(); + ~CompassView() override; + + void DirectionSetText(const char *text, const char *angle); + void DirectionSetTextId(int textId, const char *angle); + static CompassView *GetInstance(void); + void CompassStartRotate(int16_t numb); + bool InitPage(void); + bool InitView(void *caller) override; + bool GetInitViewState(void); + bool InitCompassImage(void); + + bool GetResLoadStatus(void); + void SetResLoadStatus(bool state); + void PreLoadCompassImageRes(void); + void UnLoadCompassImageRes(void); +private: + bool LoadCompassImage(UIImageView *view, uint32_t resId); + void ClearAll(void); + UILabelExt *directionLabel{nullptr}; //方向标签 + UILabel *angledLabel{nullptr}; //角度标签 + UIImageView *backGround{nullptr}; //背景图片 + UIImageView *PlaceMarkerImage{nullptr}; //放置标记图片 + UIImageView *triangulation{nullptr}; //三角图片 + const Vector2 VIEW_CENTER = {VIEW_CENTERS, VIEW_CENTERS};//二维向量 + bool resLoadStatus{false}; +}; +} #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/MainCompassPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/MainCompassPresenter.h index cd025a41b..0a4b2d4a3 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/MainCompassPresenter.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/MainCompassPresenter.h @@ -1,32 +1,40 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainCompassPresenter.h - * Author: - * Create: 2021-12-21 - */ -#ifndef COMPASS_MAINPRESENTER_H -#define COMPASS_MAINPRESENTER_H - -#include "Presenter.h" -#include "ModelListenerSample.h" -#include "ohos_types.h" -#include "UiConfig.h" -#include "AppViewIDs.h" -#include "MainCompassView.h" -#include "CompassPresenter.h" -#include "CompassModel.h" -#include "CompassCalibrationView.h" - -namespace OHOS { -class MainCompassPresenter : public Presenter, public CompassPresenter, - public ModelListenerSample, public UIView::OnDragListener { -public: - MainCompassPresenter(); - ~MainCompassPresenter() override; - - static MainCompassPresenter *GetInstance(void); - bool OnDrag(UIView& view, const DragEvent& event) override; - void Notify() override; -}; -} +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-06-07 09:21:47 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-27 09:42:42 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/compass/include/MainCompassPresenter.h + */ +#ifndef COMPASS_MAINPRESENTER_H +#define COMPASS_MAINPRESENTER_H + +#include "Presenter.h" +#include "ModelListenerSample.h" +#include "ohos_types.h" +#include "UiConfig.h" +#include "AppViewIDs.h" +#include "MainCompassView.h" +#include "CompassPresenter.h" +#include "CompassModel.h" +#include "CompassCalibrationView.h" +#include "KeyInputListener.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" + +namespace OHOS { +class MainCompassPresenter : public Presenter, public CompassPresenter, + public RootView::OnKeyActListener, + public ModelListenerSample, public UIView::OnDragListener { +public: + MainCompassPresenter(); + ~MainCompassPresenter() override; + + static MainCompassPresenter *GetInstance(void); + bool OnDrag(UIView& view, const DragEvent& event) override; + void Notify() override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + bool X_DRAG_FLAG{false}; +}; +} #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/MainCompassView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/MainCompassView.h index 7ccfa7183..304c8ffe7 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/MainCompassView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/include/MainCompassView.h @@ -1,44 +1,44 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainCompassView - * Author: - * Create: 2021-12-23 - */ - -#ifndef MAIN_COMPASS_VIEW_H -#define MAIN_COMPASS_VIEW_H - -#include -#include "View.h" -#include "components/ui_label.h" -#include "components/root_view.h" -#include "components/ui_view_group.h" -#include "components/ui_image_view.h" -#include "components/ui_label_button.h" -#include "ChangeSliceListener.h" -#include "graphic_config.h" -#include "CompassView.h" -#include "CompassModel.h" -#include "CompassCalibrationView.h" - -namespace OHOS { -class MainCompassPresenter; -class CompassView; -class MainCompassView : public View { -public: - MainCompassView(); - ~MainCompassView() override; - - void OnStart() override; - - - static MainCompassView *GetInstance(void); - void SetDisplayTure(void); - void SetDisplayFalse(void); - -private: - CompassView *compassView{nullptr}; - CompassCalibrationView *compassCalibrationView{nullptr}; -}; -} // namespace OHOS +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: MainCompassView + * Author: + * Create: 2021-12-23 + */ + +#ifndef MAIN_COMPASS_VIEW_H +#define MAIN_COMPASS_VIEW_H + +#include +#include "View.h" +#include "components/ui_label.h" +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" +#include "ChangeSliceListener.h" +#include "graphic_config.h" +#include "compass/include/CompassView.h" +#include "compass/include/CompassModel.h" +#include "compass/include/CompassCalibrationView.h" + +namespace OHOS { +class MainCompassPresenter; +class CompassView; +class MainCompassView : public View { +public: + MainCompassView(); + ~MainCompassView() override; + + void OnStart() override; + + + static MainCompassView *GetInstance(void); + void SetDisplayTure(void); + void SetDisplayFalse(void); + +private: + CompassView *compassView{nullptr}; + CompassCalibrationView *compassCalibrationView{nullptr}; +}; +} // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassCalibrationView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassCalibrationView.cpp index 390c0ae82..248fe4fdc 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassCalibrationView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassCalibrationView.cpp @@ -6,8 +6,9 @@ */ #include "UiConfig.h" #include "wearable_log.h" -#include "CompassCalibrationView.h" +#include "compass/include/CompassCalibrationView.h" #include "CompassModel.h" +#include "ui_resource_string.h" namespace OHOS { // 标签设置 @@ -40,17 +41,24 @@ CompassCalibrationView::~CompassCalibrationView() void CompassCalibrationView::ClearAll(void) { RemoveAll(); - if (labelOne != nullptr) { - delete labelOne; - labelOne = nullptr; - } - if (imageView != nullptr) { - delete imageView; - imageView = nullptr; - } - if (labelTwo != nullptr) { - delete labelTwo; - labelTwo = nullptr; + if(scrollView!=nullptr) + { + scrollView->RemoveAll(); + if (labelOne != nullptr) { + delete labelOne; + labelOne = nullptr; + } + if (imageView != nullptr) { + delete imageView; + imageView = nullptr; + } + if (labelTwo != nullptr) { + delete labelTwo; + labelTwo = nullptr; + } + scrollView->ClearFocus(); + delete scrollView; + scrollView = nullptr; } } @@ -62,47 +70,77 @@ CompassCalibrationView *CompassCalibrationView::GetInstance(void) bool CompassCalibrationView::CreateUIViewGroup(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::CreateUIViewGroup"); - imageView = new UIImageView(); - if (imageView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new UIImageView fail"); - return false; + if (scrollView == nullptr) + { + scrollView = new UIScrollView(); + if (scrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView new fail"); + return false; + } } - imageView->SetPosition(0, 0); - imageView->SetSrc(COMPASS_CALIBRATE_IMAGE); - - labelOne = new UILabel(); - if (labelOne == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new labelOne fail"); - ClearAll(); - return false; + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetScrollBlankSize(50); + scrollView->SetReboundSize(35); + scrollView->SetThrowDrag(true); + scrollView->SetMaxScrollDistance(1000); + scrollView->SetDirection(UIScrollView::VERTICAL); + scrollView->RequestFocus(); + scrollView->SetRotateFactor(1.0); + /* -------------------------------------------------------------------------- */ + if (labelOne == nullptr) + { + labelOne = new UILabelExt(); + if (labelOne == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new labelOne fail"); + ClearAll(); + return false; + } } - - labelOne->SetPosition(LABEL_POSITION_X, LABEL_POSITION_Y, LABEL_POSITION_WIDTH, LABEL_POSITION_HEIGHT); - labelOne->SetText("请按图示"); - labelOne->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + labelOne->SetPosition(83, 50,300,35); + labelOne->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + labelOne->SetStyle(STYLE_TEXT_FONT, 30); + labelOne->SetStyle(STYLE_LINE_HEIGHT, 35); + labelOne->SetTextId(STR_CALIBRATE_COMPASS); + labelOne->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); labelOne->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - labelOne->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - labelOne->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - labelOne->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - - labelTwo = new UILabel(); - if (labelTwo == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new labelTwo fail"); - ClearAll(); - return false; + labelOne->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + if (imageView == nullptr) { + imageView = new UIImageView(); + if (imageView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new UIImageView fail"); + return false; + } } - - labelTwo->SetPosition(LABEL_POSITION_X1, LABEL_POSITION_Y1, LABEL_POSITION_WIDTH1, LABEL_POSITION_HEIGHT1); - labelTwo->SetText("旋转手表进行校准"); - labelTwo->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); + imageView->SetPosition(78, 140,310,120); + imageView->SetSrc(COMPASS_CALIBRATE_IMAGE); + /* -------------------------------- labelTwo -------------------------------- */ + if (labelTwo == nullptr) + { + labelTwo = new UILabelExt(); + if (labelTwo == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CompassCalibrationView::new labelTwo fail"); + ClearAll(); + return false; + } + } + labelTwo->SetPosition(53, 300,360,70); + labelTwo->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + labelTwo->SetStyle(STYLE_TEXT_FONT, 30); + labelTwo->SetStyle(STYLE_LINE_HEIGHT, 35); + labelTwo->SetTextId(STR_CALIBRATE_COMPASS_NOTE); + labelTwo->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + labelTwo->SetTextColor(Color::GetColorFromRGBA(0xcc, 0xcc, 0xcc, 0xff)); labelTwo->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - labelTwo->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - labelTwo->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - labelTwo->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + labelTwo->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - Add(imageView); - Add(labelOne); - Add(labelTwo); + scrollView->Add(imageView); + scrollView->Add(labelOne); + scrollView->Add(labelTwo); + Add(scrollView); SetDraggable(false); SetTouchable(false); initViewStatus = true; diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassControlView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassControlView.cpp index 546dd33f8..49f0e156a 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassControlView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassControlView.cpp @@ -1,11 +1,13 @@ /* - * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. - * Description: CompassControlView.cpp - * Author: - * Create: 2022-04-02 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-06-12 11:44:23 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-05 11:48:01 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassControlView.cpp */ -#include "CompassControlView.h" -#include "CompassModel.h" +#include "compass/include/CompassControlView.h" +#include "compass/include/CompassModel.h" +#include "wearable_log.h" namespace OHOS { CompassControlView::CompassControlView() @@ -70,9 +72,9 @@ bool CompassControlView::InitView(void) void CompassControlView::SetCalibrationView(bool flag) { - if (flag == isCalibration) { - return; - } + // if (flag == isCalibration) { + // return; + // } if (flag) { compassCalibrationView->SetVisible(true); @@ -85,14 +87,23 @@ void CompassControlView::SetCalibrationView(bool flag) void CompassControlView::PreLoad(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassControlView::PreLoad"); if (!viewiInitStatus) { InitView(); viewiInitStatus = true; } + if( compassView != nullptr) + { + compassView->PreLoadCompassImageRes(); + } } void CompassControlView::UnLoad(void) { - // Compass's usage scenes is complicated, so we do not release it's resources inner slice. + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassControlView::UnLoad"); + if( compassView != nullptr) + { + compassView->UnLoadCompassImageRes(); + } } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassModel.cpp index e9ff3f5c8..ee4c99b5a 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassModel.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassModel.cpp @@ -6,12 +6,15 @@ */ #include -#include "CompassModel.h" +#include "compass/include/CompassModel.h" #include #ifdef __cplusplus extern "C" { #endif +#ifdef MAG_MMC5603 +#include "mag_service.h" +#endif using namespace OHOS; @@ -26,24 +29,50 @@ CompassModel *CompassModel::GetInstance(void) return &instance; } +/* + * @brief 设置校准状态 +*/ void CompassModel::SetCalibrationStatus(uint8_t status) { + calibrationStatus = status; } +/* + * @brief 获取校准状态 + * @param void + * @return 如果校准精度小于3,返回1,否则返回0 +*/ uint8_t CompassModel::GetCalibrationStatus(void) { + #ifdef MAG_MMC5603 + if( mag_service_get_iAccuracy() < 3) + return 1; + else + return 0; + #else return 0; + #endif } +/* + * @brief 设置显示的角度,通常表示为从地磁北方向到设备当前朝向的角度。 +*/ void CompassModel::SetDisplayAngle(uint16_t angle) { + #ifdef MAG_MMC5603 + displayAngle = (int16_t)mag_service_get_fAzimuth(); + #else displayAngle += angle; if (displayAngle > 359) { displayAngle = 0; } + #endif } +/* + * @brief 获取显示角度 +*/ uint16_t CompassModel::GetDisplayAngle(void) { return displayAngle; @@ -66,13 +95,29 @@ time_t CompassModel::GetCurrentTime(void) return tv.tv_sec; } +/* + * @brief 打开指南针传感器 + * @param void + * @return 如果指南针传感器打开成功则返回true,否则返回false +*/ bool CompassModel::OpenCompassSensor(void) { + #ifdef MAG_MMC5603 + do_mag_service_check_msg(MAG_SERVICE_CMD_START_CHECK); + #endif return true; } +/* + * @brief 关闭指南针传感器 + * @param void + * @return 如果指南针传感器关闭成功则返回true,否则返回false +*/ bool CompassModel::CloseCompassSensor(void) { + #ifdef MAG_MMC5603 + do_mag_service_check_msg(MAG_SERVICE_CMD_STOP_CHECK); + #endif return true; } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassPresenter.cpp index 4a48b5458..9b8c4b87d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassPresenter.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassPresenter.cpp @@ -1,171 +1,205 @@ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: CompassPresenter.cpp - * Author: - * Create: 2021-12-21 - */ -#include "CompassView.h" -#include "CompassPresenter.h" -#include "CompassModel.h" -#include "graphic_service.h" - -namespace OHOS { -static constexpr int16_t RIGHT_NORTH_DOWN_23 = 23; -static constexpr int16_t RIGHT_EASTNORTH_UP_68 = 68; -static constexpr int16_t RIGHT_WESTNORTH_UP_338 = 338; -static constexpr int16_t RIGHT_SOUTH_UP_203 = 203; -static constexpr int16_t RIGHT_EASTSOUTH_UP_158 = 158; -static constexpr int16_t RIGHT_WESTSOUTH_UP_248 = 248; -static constexpr int16_t RIGHT_WEST_UP_293 = 293; -static constexpr int16_t RIGHT_EAST_UP_113 = 113; -static constexpr int16_t RIGHT_MAX_ANGLE_360 = 360; -static constexpr int16_t RIGHT_HALF_ANGLE_180 = 180; -static constexpr int16_t RIGHT_ROTATION_INTERVAL = 2; -static constexpr int16_t DIRECTION_COUNT = 7; -static constexpr int16_t LEFT_NORTH_DOWN_23 = -23; -static constexpr int16_t LEFT_EASTNORTH_DOWN_337 = -337; -static constexpr int16_t LEFT_WESTNORTH_DOWN_68 = -68; -static constexpr int16_t LEFT_SOUTH_DOWN_202 = -202; -static constexpr int16_t LEFT_EASTSOUTH_DOWN_247 = -247; -static constexpr int16_t LEFT_WESTSOUTH_DOWN_157 = -157; -static constexpr int16_t LEFT_WEST_DOWN_113 = -113; -static constexpr int16_t LEFT_EAST_DOWN_292 = -292; -static constexpr int16_t RIGHT_MIN_ANGLE_360 = -360; -static constexpr int16_t LEFT_HALF_ANGLE_180 = -180; -static constexpr int16_t LEFT_ROTATION_INTERVAL = -2; - -static constexpr const char *NORTH_DIRECTION = (char *)"北"; -static constexpr const char *SOUTH_DIRECTION = (char *)"南"; -static constexpr const char *WEST_DIRECTION = (char *)"西"; -static constexpr const char *EAST_DIRECTION = (char *)"东"; -static constexpr const char *WESTNORTH_DIRECTION = (char *)"西北"; -static constexpr const char *WESTSOUTH_DIRECTION = (char *)"西南"; -static constexpr const char *EASTSOUTH_DIRECTION = (char *)"东南"; -static constexpr const char *EASTNORTH_DIRECTION = (char *)"东北"; - -const CompassItem g_compassList[] = { - {RIGHT_NORTH_DOWN_23, RIGHT_EASTNORTH_UP_68, EASTNORTH_DIRECTION}, - {RIGHT_EASTNORTH_UP_68, RIGHT_EAST_UP_113, EAST_DIRECTION}, - {RIGHT_EAST_UP_113, RIGHT_EASTSOUTH_UP_158, EASTSOUTH_DIRECTION}, - {RIGHT_EASTSOUTH_UP_158, RIGHT_SOUTH_UP_203, SOUTH_DIRECTION}, - {RIGHT_SOUTH_UP_203, RIGHT_WESTSOUTH_UP_248, WESTSOUTH_DIRECTION}, - {RIGHT_WESTSOUTH_UP_248, RIGHT_WEST_UP_293, WEST_DIRECTION}, - {RIGHT_WEST_UP_293, RIGHT_WESTNORTH_UP_338, WESTNORTH_DIRECTION} -}; - -static CompassPresenter *g_pMainView = nullptr; - -CompassPresenter::CompassPresenter() -{ - g_pMainView = this; -} - -CompassPresenter::~CompassPresenter() -{ - g_pMainView = nullptr; -} - -CompassPresenter* CompassPresenter::GetInstance(void) -{ - return g_pMainView; -} - -void CompassPresenter::DisplayAngleRight(uint16_t angle) -{ - if ((angle >= RIGHT_WESTNORTH_UP_338) || (angle >= 0 && angle < RIGHT_NORTH_DOWN_23)) { - CompassView::GetInstance()->DirectionSetText(NORTH_DIRECTION, (std::to_string(angle) + "°").c_str()); - } - for (int i = 0; i < DIRECTION_COUNT; i++) { - if ((angle >= g_compassList[i].beginAngle) && (angle < g_compassList[i].endAngle)) { - CompassView::GetInstance()->DirectionSetText(g_compassList[i].dir, (std::to_string(angle) + "°").c_str()); - } - } -} - -void CompassPresenter::DisplayAngleDir(uint16_t angle) -{ - if (CompassView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DisplayAngleDir]CompassView::GetInstance() is nullptr"); - return; - } - if (angle >= 0 && angle <= RIGHT_MAX_ANGLE_360) { - DisplayAngleRight(angle); - } -} - - -void CompassPresenter::InScopeRotate(void) -{ - angleDiff = lastRotateAngle - currentRotateAngle; - if (angleDiff > LEFT_HALF_ANGLE_180 && angleDiff < RIGHT_HALF_ANGLE_180) { - if (lastRotateAngle < currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - if (angleDiff <= LEFT_ROTATION_INTERVAL) { - lastRotateAngle+=RIGHT_ROTATION_INTERVAL; - } else { - lastRotateAngle++; - } - } else if (lastRotateAngle != currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - if (angleDiff >= RIGHT_ROTATION_INTERVAL) { - lastRotateAngle-=RIGHT_ROTATION_INTERVAL; - } else { - lastRotateAngle--; - } - } - } else { - if (lastRotateAngle < currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - if (angleDiff <= LEFT_ROTATION_INTERVAL) { - lastRotateAngle-=RIGHT_ROTATION_INTERVAL; - } else { - lastRotateAngle--; - } - if (lastRotateAngle <= 0) { - lastRotateAngle = RIGHT_MAX_ANGLE_360; - } - } else if (lastRotateAngle != currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - if (angleDiff >= RIGHT_ROTATION_INTERVAL) { - lastRotateAngle+=RIGHT_ROTATION_INTERVAL; - } else { - lastRotateAngle++; - } - if (lastRotateAngle >= RIGHT_MAX_ANGLE_360) { - lastRotateAngle = 0; - } - } - } -} - -void CompassPresenter::DetermineToRotate(void) -{ - if (CompassView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DetermineToRotate]CompassView::GetInstance() is nullptr"); - return; - } - bool initState = CompassView::GetInstance()->GetInitViewState(); - if (initState) { - if (initDisplayStatus) { - currentRotateAngle = CompassModel::GetInstance()->GetDisplayAngle(); - lastRotateAngle = currentRotateAngle; - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - DisplayAngleDir(currentRotateAngle); - initDisplayStatus = false; - } else { - if (!getAngleStatus) { - currentRotateAngle = CompassModel::GetInstance()->GetDisplayAngle(); - } - InScopeRotate(); - getAngleStatus = true; - if (lastRotateAngle == currentRotateAngle) { - CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); - DisplayAngleDir(currentRotateAngle); - getAngleStatus = false; - } - } - } - CompassModel::GetInstance()->SetDisplayAngle(1); -} - +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CompassPresenter.cpp + * Author: + * Create: 2021-12-21 + */ +#include "compass/include/CompassView.h" +#include "compass/include/CompassPresenter.h" +#include "compass/include/CompassModel.h" +#include "graphic_service.h" +#include "gfx_utils/mem_check.h" +#include "ui_resource_string.h" +namespace OHOS { +static constexpr int16_t RIGHT_NORTH_DOWN_23 = 23; +static constexpr int16_t RIGHT_EASTNORTH_UP_68 = 68; +static constexpr int16_t RIGHT_WESTNORTH_UP_338 = 338; +static constexpr int16_t RIGHT_SOUTH_UP_203 = 203; +static constexpr int16_t RIGHT_EASTSOUTH_UP_158 = 158; +static constexpr int16_t RIGHT_WESTSOUTH_UP_248 = 248; +static constexpr int16_t RIGHT_WEST_UP_293 = 293; +static constexpr int16_t RIGHT_EAST_UP_113 = 113; +static constexpr int16_t RIGHT_MAX_ANGLE_360 = 360; +static constexpr int16_t RIGHT_HALF_ANGLE_180 = 180; +static constexpr int16_t RIGHT_ROTATION_INTERVAL = 2; +static constexpr int16_t DIRECTION_COUNT = 7; +static constexpr int16_t LEFT_NORTH_DOWN_23 = -23; +static constexpr int16_t LEFT_EASTNORTH_DOWN_337 = -337; +static constexpr int16_t LEFT_WESTNORTH_DOWN_68 = -68; +static constexpr int16_t LEFT_SOUTH_DOWN_202 = -202; +static constexpr int16_t LEFT_EASTSOUTH_DOWN_247 = -247; +static constexpr int16_t LEFT_WESTSOUTH_DOWN_157 = -157; +static constexpr int16_t LEFT_WEST_DOWN_113 = -113; +static constexpr int16_t LEFT_EAST_DOWN_292 = -292; +static constexpr int16_t RIGHT_MIN_ANGLE_360 = -360; +static constexpr int16_t LEFT_HALF_ANGLE_180 = -180; +static constexpr int16_t LEFT_ROTATION_INTERVAL = -2; + +static constexpr const char *NORTH_DIRECTION = (char *)"北"; +static constexpr const char *SOUTH_DIRECTION = (char *)"南"; +static constexpr const char *WEST_DIRECTION = (char *)"西"; +static constexpr const char *EAST_DIRECTION = (char *)"东"; +static constexpr const char *WESTNORTH_DIRECTION = (char *)"西北"; +static constexpr const char *WESTSOUTH_DIRECTION = (char *)"西南"; +static constexpr const char *EASTSOUTH_DIRECTION = (char *)"东南"; +static constexpr const char *EASTNORTH_DIRECTION = (char *)"东北"; + +static constexpr const int NORTH_DIRECTION_TEXTID = STR_NORTH;//北 +static constexpr const int SOUTH_DIRECTION_TEXTID = STR_SOUTH;//南 +static constexpr const int WEST_DIRECTION_TEXTID = STR_WEST;//西 +static constexpr const int EAST_DIRECTION_TEXTID = STR_EAST;//东 +static constexpr const int WESTNORTH_DIRECTION_TEXTID = STR_NORTHWEST;//西北 +static constexpr const int WESTSOUTH_DIRECTION_TEXTID = STR_SOUTHWEST;//西南 +static constexpr const int EASTSOUTH_DIRECTION_TEXTID = STR_SOUTHEAST;//西南 +static constexpr const int EASTNORTH_DIRECTION_TEXTID = STR_NORTHEAST;//东北 + +const CompassItem g_compassList[] = { + {RIGHT_NORTH_DOWN_23, RIGHT_EASTNORTH_UP_68, EASTNORTH_DIRECTION,EASTNORTH_DIRECTION_TEXTID}, + {RIGHT_EASTNORTH_UP_68, RIGHT_EAST_UP_113, EAST_DIRECTION,EAST_DIRECTION_TEXTID}, + {RIGHT_EAST_UP_113, RIGHT_EASTSOUTH_UP_158, EASTSOUTH_DIRECTION,EASTSOUTH_DIRECTION_TEXTID}, + {RIGHT_EASTSOUTH_UP_158, RIGHT_SOUTH_UP_203, SOUTH_DIRECTION,SOUTH_DIRECTION_TEXTID}, + {RIGHT_SOUTH_UP_203, RIGHT_WESTSOUTH_UP_248, WESTSOUTH_DIRECTION,WESTSOUTH_DIRECTION_TEXTID}, + {RIGHT_WESTSOUTH_UP_248, RIGHT_WEST_UP_293, WEST_DIRECTION,WEST_DIRECTION_TEXTID}, + {RIGHT_WEST_UP_293, RIGHT_WESTNORTH_UP_338, WESTNORTH_DIRECTION,WESTNORTH_DIRECTION_TEXTID} +}; + +static CompassPresenter *g_pMainView = nullptr; + +CompassPresenter::CompassPresenter() +{ + g_pMainView = this; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif +} + +CompassPresenter::~CompassPresenter() +{ + g_pMainView = nullptr; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif +} + +CompassPresenter* CompassPresenter::GetInstance(void) +{ + return g_pMainView; +} +//显示指南针的角度 + +/* + * @brief 根据传入的角度值 angle 来更新指南针的显示方向 + * @param angle 角度值 +*/ +void CompassPresenter::DisplayAngleRight(uint16_t angle) +{ + if ((angle >= RIGHT_WESTNORTH_UP_338) || (angle >= 0 && angle < RIGHT_NORTH_DOWN_23)) { + //CompassView::GetInstance()->DirectionSetText(NORTH_DIRECTION, ("~" + std::to_string(angle) + "°").c_str()); + // CompassView::GetInstance()->DirectionSetText(NORTH_DIRECTION, (std::to_string(angle) + "°").c_str()); + CompassView::GetInstance()->DirectionSetTextId(NORTH_DIRECTION_TEXTID, (std::to_string(angle) + "°").c_str()); + } + for (int i = 0; i < DIRECTION_COUNT; i++) { + if ((angle >= g_compassList[i].beginAngle) && (angle < g_compassList[i].endAngle)) { + // CompassView::GetInstance()->DirectionSetText(g_compassList[i].dir, ("~" + std::to_string(angle) + "°").c_str()); + // CompassView::GetInstance()->DirectionSetText(g_compassList[i].dir, (std::to_string(angle) + "°").c_str()); + CompassView::GetInstance()->DirectionSetTextId(g_compassList[i].dir_textId, (std::to_string(angle) + "°").c_str()); + } + } +} + +/* + * @brief 校验 CompassView 的实例是否存在,并确定传入的角度值是否有效 +*/ +void CompassPresenter::DisplayAngleDir(uint16_t angle) +{ + if (CompassView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DisplayAngleDir]CompassView::GetInstance() is nullptr"); + return; + } + if (angle >= 0 && angle <= RIGHT_MAX_ANGLE_360) { + DisplayAngleRight(angle); + } +} + +/* + * @brief 根据上一次和当前的旋转角度来判断如何旋转指南针,使其指向正确的方向 +*/ +void CompassPresenter::InScopeRotate(void) +{ + angleDiff = lastRotateAngle - currentRotateAngle; + if (angleDiff > LEFT_HALF_ANGLE_180 && angleDiff < RIGHT_HALF_ANGLE_180) { + if (lastRotateAngle < currentRotateAngle) { + CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); + if (angleDiff <= LEFT_ROTATION_INTERVAL) { + lastRotateAngle+=RIGHT_ROTATION_INTERVAL; + } else { + lastRotateAngle++; + } + } else if (lastRotateAngle != currentRotateAngle) { + CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); + if (angleDiff >= RIGHT_ROTATION_INTERVAL) { + lastRotateAngle-=RIGHT_ROTATION_INTERVAL; + } else { + lastRotateAngle--; + } + } + } else { + if (lastRotateAngle < currentRotateAngle) { + CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); + if (angleDiff <= LEFT_ROTATION_INTERVAL) { + lastRotateAngle-=RIGHT_ROTATION_INTERVAL; + } else { + lastRotateAngle--; + } + if (lastRotateAngle <= 0) { + lastRotateAngle = RIGHT_MAX_ANGLE_360; + } + } else if (lastRotateAngle != currentRotateAngle) { + CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); + if (angleDiff >= RIGHT_ROTATION_INTERVAL) { + lastRotateAngle+=RIGHT_ROTATION_INTERVAL; + } else { + lastRotateAngle++; + } + if (lastRotateAngle >= RIGHT_MAX_ANGLE_360) { + lastRotateAngle = 0; + } + } + } +} + +/* + * @brief 在指南针视图初始化的情况下,根据旋转角度的变化来执行指南针的旋转操作,并在需要的时候更新显示的角度和方向。 +*/ +void CompassPresenter::DetermineToRotate(void) +{ + if (CompassView::GetInstance() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[DetermineToRotate]CompassView::GetInstance() is nullptr"); + return; + } + bool initState = CompassView::GetInstance()->GetInitViewState(); + if (initState == true) { + if (initDisplayStatus == true) { + currentRotateAngle = CompassModel::GetInstance()->GetDisplayAngle(); + lastRotateAngle = currentRotateAngle; + CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); + DisplayAngleDir(currentRotateAngle); + initDisplayStatus = false; + } else { + if (getAngleStatus == false) { + currentRotateAngle = CompassModel::GetInstance()->GetDisplayAngle(); + } + InScopeRotate(); + getAngleStatus = true; + if (lastRotateAngle == currentRotateAngle) { + CompassView::GetInstance()->CompassStartRotate(lastRotateAngle); + DisplayAngleDir(currentRotateAngle); + getAngleStatus = false; + } + } + } + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&CompassModel::SetDisplayAngle, + CompassModel::GetInstance(), 1));//将任务发布到异步线程 +} + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassView.cpp index 0a87fd18a..1f76a77ca 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/CompassView.cpp @@ -7,21 +7,32 @@ #include #include "common/image_cache_manager.h" #include "ui_resource_image.h" -#include "CompassView.h" -#include "MainCompassView.h" - +#include "compass/include/CompassView.h" +#include "compass/include/MainCompassView.h" +#include "compass/include/CompassPresenter.h" +#include "ui_resource_string.h" namespace OHOS { -static constexpr int16_t POINT_CENTER_IMAGE_X = 150; -static constexpr int16_t POINT_CENTER_IMAGE_Y = 150; -static constexpr int16_t TRIANGULATION_X = 210; +static constexpr int16_t COMPASSVIEW_W = 466; +static constexpr int16_t COMPASSVIEW_H = 466; +static constexpr int16_t POINT_CENTER_IMAGE_X = 192; +static constexpr int16_t POINT_CENTER_IMAGE_Y = 282; +static constexpr int16_t TRIANGULATION_X = 221; static constexpr int16_t TRIANGULATION_Y = 0; -static constexpr int16_t DIRECTIONLABEL_X = 160; -static constexpr int16_t DIRECTIONLABEL_Y = 215; -static constexpr int16_t FONT_TEXT_SIZE = 25; -static constexpr int16_t ANGLEDLABEL_X = 215; -static constexpr int16_t ANGLEDLABEL_Y = 215; -static constexpr int16_t TEXT_WIDTH = 90; -static constexpr int16_t TEXT_HEIGHT = 35; + +static constexpr int16_t DIRECTIONLABEL_X = 83; +static constexpr int16_t DIRECTIONLABEL_Y = 161; +static constexpr int16_t DIRECTIONLABEL_TEXT_WIDTH = 300; +static constexpr int16_t DIRECTIONLABEL_TEXT_HEIGH = 76; +static constexpr int16_t DIRECTIONLABEL_FONT_TEXT_SIZE = 65; +static constexpr int16_t DIRECTIONLABEL_STYLE_LINE_HEIGHT = 76; + +static constexpr int16_t ANGLEDLABEL_X = 83; +static constexpr int16_t ANGLEDLABEL_Y = 240; +static constexpr int16_t ANGLEDLABEL_TEXT_WIDTH = 300; +static constexpr int16_t ANGLEDLABEL_TEXT_HEIGHT = 76; +static constexpr int16_t ANGLEDLABEL_FONT_TEXT_SIZE = 65; +static constexpr int16_t ANGLEDLABEL_STYLE_LINE_HEIGHT = 76; + static constexpr int16_t RANDOM_NUMBER_720 = 720; static constexpr int16_t RANDOM_NUMBER_360 = 360; static constexpr int16_t DELAYING_NUMS = 2000; @@ -44,6 +55,7 @@ CompassView::~CompassView() void CompassView::ClearAll(void) { RemoveAll(); + UnLoadCompassImageRes(); if (directionLabel != nullptr) { delete directionLabel; directionLabel= nullptr; @@ -56,22 +68,34 @@ void CompassView::ClearAll(void) delete backGround; backGround = nullptr; } - if (rotateShaft != nullptr) { - delete rotateShaft; - rotateShaft = nullptr; + if(PlaceMarkerImage != nullptr) + { + delete PlaceMarkerImage; + PlaceMarkerImage = nullptr; } if (triangulation != nullptr) { delete triangulation; triangulation = nullptr; } } - +//方向和角度设置 void CompassView::DirectionSetText(const char *text, const char *angle) { directionLabel->SetText(text); angledLabel->SetText(angle); } +void CompassView::DirectionSetTextId(int textId, const char *angle) +{ + if(directionLabel && angledLabel) + { + directionLabel->SetTextId(textId); + directionLabel->Invalidate(); + angledLabel->SetText(angle); + angledLabel->Invalidate(); + } +} +//加载指南针图片 bool CompassView::LoadCompassImage(UIImageView *view, uint32_t resId) { std::string file = COMPASS_IAMGES; @@ -84,7 +108,51 @@ bool CompassView::LoadCompassImage(UIImageView *view, uint32_t resId) view->SetSrc(image); return true; } - +bool CompassView::GetResLoadStatus(void) +{ + return resLoadStatus; +} +void CompassView::SetResLoadStatus(bool state) +{ + resLoadStatus = state; +} +/*预加载指南针图片资源*/ +void CompassView::PreLoadCompassImageRes(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassView::PreLoadCompassImageRes"); + if(!GetResLoadStatus()){ + if (LoadCompassImage(backGround, COMPASS_COMPASS0) == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], triangulation load fail", __LINE__); + return; + } + if (LoadCompassImage(PlaceMarkerImage, COMPASS_COMPASS1) == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], PlaceMarkerImage load fail", __LINE__); + return; + } + if (LoadCompassImage(triangulation, COMPASS_COMPASS2) == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "triangulation load fail"); + return ; + } + SetResLoadStatus(true); + } +} +/*卸载指南针图片资源*/ +void CompassView::UnLoadCompassImageRes(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassView::UnLoadCompassImageRes"); + if(GetResLoadStatus()) + { + ImageInfo* image = nullptr; + backGround->SetSrc(image); + PlaceMarkerImage->SetSrc(image); + triangulation->SetSrc(image); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(COMPASS_COMPASS0,COMPASS_IAMGES); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(COMPASS_COMPASS1,COMPASS_IAMGES); + ImageCacheManager::GetInstance().UnloadOneInMultiRes(COMPASS_COMPASS2,COMPASS_IAMGES); + SetResLoadStatus(false); + } +} +//初始化指南针图片 bool CompassView::InitCompassImage(void) { backGround = new UIImageView(); @@ -94,19 +162,19 @@ bool CompassView::InitCompassImage(void) } backGround->SetPosition(0, 0); - if (!LoadCompassImage(backGround, COMPASS_COMPASS0)) { + if (LoadCompassImage(backGround, COMPASS_COMPASS0) == false) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], triangulation load fail", __LINE__); return false; } - rotateShaft = new UIImageView(); - if (rotateShaft == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], rotateShaft new fail", __LINE__); + PlaceMarkerImage = new UIImageView(); + if (PlaceMarkerImage == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], PlaceMarkerImage new fail", __LINE__); return false; } - rotateShaft->SetPosition(POINT_CENTER_IMAGE_X, POINT_CENTER_IMAGE_Y); - if (!LoadCompassImage(rotateShaft, COMPASS_COMPASS1)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], rotateShaft load fail", __LINE__); + PlaceMarkerImage->SetPosition(POINT_CENTER_IMAGE_X, POINT_CENTER_IMAGE_Y); + if (LoadCompassImage(PlaceMarkerImage, COMPASS_COMPASS1) == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], PlaceMarkerImage load fail", __LINE__); return false; } @@ -116,35 +184,42 @@ bool CompassView::InitCompassImage(void) return false; } triangulation->SetPosition(TRIANGULATION_X, TRIANGULATION_Y); - if (!LoadCompassImage(triangulation, COMPASS_COMPASS2)) { + if (LoadCompassImage(triangulation, COMPASS_COMPASS2) == false) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "triangulation load fail"); return false; } + + SetResLoadStatus(true); + return true; } - +//初始化页面 bool CompassView::InitPage(void) -{ - if (!InitCompassImage()) { +{ + if (InitCompassImage() == false) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitCompassImage fail"); ClearAll(); return false; } - directionLabel = new UILabel(); + directionLabel = new UILabelExt(); if (directionLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "directionLabel new fail"); ClearAll(); return false; } directionLabel->SetPosition(DIRECTIONLABEL_X, DIRECTIONLABEL_Y); - directionLabel->Resize(TEXT_WIDTH, TEXT_HEIGHT); - directionLabel->SetText("北"); - directionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); + directionLabel->Resize(DIRECTIONLABEL_TEXT_WIDTH, DIRECTIONLABEL_TEXT_HEIGH); + directionLabel->SetTextId(STR_NORTH); + directionLabel->SetStyle(STYLE_TEXT_FONT, DIRECTIONLABEL_FONT_TEXT_SIZE); + directionLabel->SetStyle(STYLE_LINE_HEIGHT, DIRECTIONLABEL_STYLE_LINE_HEIGHT); + directionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIRECTIONLABEL_FONT_TEXT_SIZE); + directionLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + directionLabel->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); directionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - directionLabel->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - directionLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - directionLabel->SetStyle(STYLE_TEXT_COLOR, Color::White().full); + // directionLabel->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); + // directionLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + // directionLabel->SetStyle(STYLE_TEXT_COLOR, Color::White().full); angledLabel = new UILabel(); if (angledLabel == nullptr) { @@ -152,17 +227,20 @@ bool CompassView::InitPage(void) ClearAll(); return false; } - angledLabel->SetPosition(ANGLEDLABEL_X, ANGLEDLABEL_Y); - angledLabel->Resize(TEXT_WIDTH, TEXT_HEIGHT); + angledLabel->SetPosition(ANGLEDLABEL_X, ANGLEDLABEL_Y); + angledLabel->Resize(ANGLEDLABEL_TEXT_WIDTH, ANGLEDLABEL_TEXT_HEIGHT); angledLabel->SetText("0°"); - angledLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE); + angledLabel->SetStyle(STYLE_TEXT_FONT, ANGLEDLABEL_FONT_TEXT_SIZE); + angledLabel->SetStyle(STYLE_LINE_HEIGHT, ANGLEDLABEL_STYLE_LINE_HEIGHT); + angledLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, ANGLEDLABEL_FONT_TEXT_SIZE); + angledLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); angledLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); angledLabel->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); angledLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); angledLabel->SetStyle(STYLE_TEXT_COLOR, Color::White().full); Add(backGround); - Add(rotateShaft); + //Add(PlaceMarkerImage); Add(triangulation); Add(directionLabel); Add(angledLabel); @@ -172,11 +250,11 @@ bool CompassView::InitPage(void) return true; } - +//初始化视图为可拖拽,可触摸 bool CompassView::InitView(void *caller) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassView InitView %p", caller); - if (!InitPage()) { + if (InitPage() == false) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitPage fail"); return false; } @@ -194,7 +272,7 @@ CompassView *CompassView::GetInstance(void) { return g_pCompassView; } - +//背景图片逆时针旋转numb度 void CompassView::CompassStartRotate(int16_t numb) { if (backGround == nullptr) { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp index 85eb0a2b3..d4ec6c62b 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp @@ -1,12 +1,18 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainCompassPresenter.cpp - * Author: - * Create: 2021-12-21 - */ -#include "CompassView.h" -#include "MainCompassPresenter.h" -#include "MainCompassView.h" +* @Author: luozheng 1732036298@qq.com +* @Date: 2024-03-14 15:02:03 +* @LastEditors: luozheng 1732036298@qq.com +* @LastEditTime: 2024-10-28 18:25:42 +* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/compass/src/MainCompassPresenter.cpp +*/ + +#include "compass/include/CompassView.h" +#include "compass/include/MainCompassPresenter.h" +#include "compass/include/MainCompassView.h" +#include "wearable_log.h" +#include "common/key_code.h" +#include "custom_utils.h" +#include "UiConfig.h" #include "NativeRegisterManager.h" #include "ui_resource_string.h" @@ -19,11 +25,13 @@ static MainCompassPresenter *g_pMainView = nullptr; MainCompassPresenter::MainCompassPresenter() { + ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); g_pMainView = this; } MainCompassPresenter::~MainCompassPresenter() { + ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); g_pMainView = nullptr; } @@ -33,11 +41,37 @@ MainCompassPresenter* MainCompassPresenter::GetInstance() return g_pMainView; } -bool MainCompassPresenter::OnDrag(UIView& view, const DragEvent& event) +bool MainCompassPresenter::OnDrag(UIView &view, const DragEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCompassPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + MainCompassPresenter::X_DRAG_FLAG = true; + } + return true; +} + +bool MainCompassPresenter::OnDragEnd(UIView& view, const DragEvent& event) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCompassPresenter::OnDragEnd"); UNUSED(view); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainCompassPresenter::X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(); + } + return true; +} + +bool MainCompassPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCompassPresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(); } return true; } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/MainCompassView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/MainCompassView.cpp index 16d8338ff..211ec13f2 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/MainCompassView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/compass/src/MainCompassView.cpp @@ -5,8 +5,9 @@ * Create: 2021-12-23 */ -#include "MainCompassView.h" -#include "MainCompassPresenter.h" +#include "compass/include/MainCompassView.h" +#include "compass/include/MainCompassPresenter.h" +#include "compass/include/CompassModel.h" namespace OHOS { static constexpr int16_t TWO_HOUR_SECOND = 7200; @@ -20,6 +21,7 @@ MainCompassView::MainCompassView() MainCompassView::~MainCompassView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCompassView::~MainCompassView"); + CompassModel::GetInstance()->CloseCompassSensor(); delete compassView; compassView = nullptr; delete compassCalibrationView; @@ -102,6 +104,10 @@ void MainCompassView::OnStart() compassCalibrationView->SetVisible(false); } CompassModel::GetInstance()->OpenCompassSensor(); + + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainCompassPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/countdown/src/MainCountDownView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/countdown/src/MainCountDownView.cpp index 42617ac30..c34600fb8 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/countdown/src/MainCountDownView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/countdown/src/MainCountDownView.cpp @@ -430,6 +430,7 @@ namespace OHOS { ChangeView(COUNTDOWN_MAX, MAIN_COUNTDOWN); // 如果倒计时的timer已经结束,则跳转到主界面 } + RootView::GetInstance()->SetOnKeyActListener(presenter_); /* -------------------------------------------------------------------------- */ } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/dnotdisturb/src/DnotDisturbView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/dnotdisturb/src/DnotDisturbView.cpp index bf7413376..39118c53e 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/dnotdisturb/src/DnotDisturbView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/dnotdisturb/src/DnotDisturbView.cpp @@ -252,5 +252,6 @@ namespace OHOS { AddViewToRootContainer(scrollView); } + RootView::GetInstance()->SetOnKeyActListener(presenter_); } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/findphone/src/FindPhoneView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/findphone/src/FindPhoneView.cpp index ea029b8e9..7b6c54256 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/findphone/src/FindPhoneView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/findphone/src/FindPhoneView.cpp @@ -285,6 +285,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phone is not connected"); FindPhoneViewInit_BlueToothDisConnected(); } + RootView::GetInstance()->SetOnKeyActListener(presenter_); return; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightView.cpp index 10c19eae4..30aa9d456 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/flashlight/src/FlashlightView.cpp @@ -61,6 +61,7 @@ namespace OHOS AddViewToRootContainer(group); } InitSwipeData(); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } void FlashlightView::DeinitSwipeData() diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalview.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalview.cpp index 9e52ac710..54e370baf 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalview.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalview.cpp @@ -135,6 +135,7 @@ namespace OHOS /* --------------------------------- 添加按键监听 --------------------------------- */ // RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MaingoalPresenter::GetInstance(); //RootView::GetInstance()->SetOnKeyActListener(keyactListener); + RootView::GetInstance()->SetOnKeyActListener(presenter_); /* -------------------------------------------------------------------------- */ } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/heartrate/src/HeartDetectionView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/heartrate/src/HeartDetectionView.cpp index c6aa90ddd..935818d7d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/heartrate/src/HeartDetectionView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/heartrate/src/HeartDetectionView.cpp @@ -141,7 +141,7 @@ namespace OHOS GetRootContainer()->SetDraggable(true); GetRootContainer()->SetTouchable(true); GetRootContainer()->SetOnDragListener(presenter_); - //RootView::GetInstance()->SetOnKeyActListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); if (imageAnimator != nullptr) { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/heartrate/src/HeartResultView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/heartrate/src/HeartResultView.cpp index 0f8523811..e467e1776 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/heartrate/src/HeartResultView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/heartrate/src/HeartResultView.cpp @@ -197,7 +197,7 @@ namespace OHOS GetRootContainer()->SetDraggable(true); GetRootContainer()->SetTouchable(true); GetRootContainer()->SetOnDragListener(presenter_); - //RootView::GetInstance()->SetOnKeyActListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/message/src/MessageShowView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/message/src/MessageShowView.cpp index f103b59cb..29be8add0 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/message/src/MessageShowView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/message/src/MessageShowView.cpp @@ -275,6 +275,7 @@ namespace OHOS UpdateShowConfig(); AddViewToRootContainer(scrollView_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/motionrecognition/src/MotionRecognitionView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/motionrecognition/src/MotionRecognitionView.cpp index cd6134a68..41e5a6f02 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/motionrecognition/src/MotionRecognitionView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/motionrecognition/src/MotionRecognitionView.cpp @@ -186,6 +186,7 @@ namespace OHOS scrollView->Add(MotionRecognitionToggleButton); scrollView->Add(note); AddViewToRootContainer(scrollView); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/networkandcall/src/NetworkAndCallView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/networkandcall/src/NetworkAndCallView.cpp index 32a6b8e09..e32c11ce4 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/networkandcall/src/NetworkAndCallView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/networkandcall/src/NetworkAndCallView.cpp @@ -237,7 +237,7 @@ namespace OHOS NetworkAndCallScrollView[NETWORKANDCALLVIEW]->Add(MobileData_toggleButton); NetworkAndCallScrollView[NETWORKANDCALLVIEW]->Add(note); AddViewToRootContainer(NetworkAndCallScrollView[NETWORKANDCALLVIEW]); - //RootView::GetInstance()->SetOnKeyActListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp index ee24848e7..78b0b7765 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp @@ -385,7 +385,7 @@ namespace OHOS viewInitStatus = true; } - //RootView::GetInstance()->SetOnKeyActListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); return; } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/record/src/RecordingView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/record/src/RecordingView.cpp index 6e218152a..f0a0a89ad 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/record/src/RecordingView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/record/src/RecordingView.cpp @@ -455,6 +455,7 @@ namespace OHOS void RecordingView::OnStart() { RecordingViewInit(); + RootView::GetInstance()->SetOnKeyActListener(presenter_); return; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/respiratorytraining/src/RespiratoryTrainingView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/respiratorytraining/src/RespiratoryTrainingView.cpp index 99a6a41ad..4c1a273bd 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/respiratorytraining/src/RespiratoryTrainingView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/respiratorytraining/src/RespiratoryTrainingView.cpp @@ -576,6 +576,7 @@ namespace OHOS RootView::GetInstance()->SetDraggable(true); RootView::GetInstance()->SetTouchable(true); RootView::GetInstance()->SetOnDragListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); RespiratoryTrainingViewInit(); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp index dab7179f9..734c4e1e4 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp @@ -845,7 +845,7 @@ namespace OHOS Draw(); - //GetRootContainer()->SetOnKeyActListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp index 74524024c..6556815a0 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp @@ -143,6 +143,7 @@ void SaveEleView::OnStart() { AddViewToRootContainer(scrollview_); InitView(); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleView.cpp index e1d50d889..9ad5f3c69 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/schedule/src/ScheduleView.cpp @@ -45,6 +45,7 @@ namespace OHOS } DisplayDataOrNoScreen(); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } void ScheduleView::OnStop() diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatView.cpp index f163dcbce..abb5ca54c 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatView.cpp @@ -30,6 +30,7 @@ void SetTimeFormatView::OnStart() { GetRootContainer()->SetOnDragListener(presenter_); GetRootContainer()->SetTouchable(true); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } bool SetTimeFormatView::SetTimeFormatInit() { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/CallVolumeView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/CallVolumeView.cpp index cf6910abd..7db2953c2 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/CallVolumeView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/CallVolumeView.cpp @@ -80,6 +80,7 @@ namespace OHOS } UpdateCallVolumeSliderValue(); AddViewToRootContainer(CallVolumeScrollView); + RootView::GetInstance()->SetOnKeyActListener(presenter_); return; } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationView.cpp index e3b7621b3..e40f3f078 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationView.cpp @@ -340,6 +340,7 @@ namespace OHOS GetRootContainer()->SetTouchable(true); GetRootContainer()->SetDraggable(true); GetRootContainer()->SetOnDragListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); if (!initViewStatus) { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/SystemVolumeView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/SystemVolumeView.cpp index 541b56616..5efcec417 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/SystemVolumeView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/soundandvibration/src/SystemVolumeView.cpp @@ -83,6 +83,7 @@ namespace OHOS GetRootContainer()->SetTouchable(true); GetRootContainer()->SetDraggable(true); GetRootContainer()->SetOnDragListener(presenter_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); if (!initViewStatus) { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp index 547ddf7af..1f39e561d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp @@ -413,5 +413,6 @@ namespace OHOS scrollView[MAIN_STOPWATCH]->Add(ResetOrMarkbutton); group->Add(scrollView[MAIN_STOPWATCH]); AddViewToRootContainer(group); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/takephotos/src/TakephotosView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/takephotos/src/TakephotosView.cpp index e27ee4f25..cf1586ce9 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/takephotos/src/TakephotosView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/takephotos/src/TakephotosView.cpp @@ -341,6 +341,7 @@ namespace OHOS PreLoad(); AddViewToRootContainer(scrollview_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TakephotosView OnStart is ok"); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherView.cpp index 591a5054b..16b80cf07 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherView.cpp @@ -152,6 +152,7 @@ namespace OHOS weatherSwipeViewList->SetOnSwipeListener(presenter_); } UpdateMainWeatherViewVisibility(); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } WeatherView *MainWeatherView::GetWeatherView(void) -- 2.17.1