指南针视图修改
author罗正yun <1732036298@qq.com>
Thu, 18 Jan 2024 08:12:11 +0000 (16:12 +0800)
committer罗正yun <1732036298@qq.com>
Thu, 18 Jan 2024 08:12:11 +0000 (16:12 +0800)
15 files changed:
code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_image.h
code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistView.h
code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassCalibrationView.h
code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassPresenter.h
code/sdk/application/wearable/nativeapp/nativeui/compass/include/CompassView.h
code/sdk/application/wearable/nativeapp/nativeui/compass/include/MainCompassPresenter.h
code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassPresenter.cpp
code/sdk/application/wearable/nativeapp/nativeui/compass/src/CompassView.cpp
code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassPresenter.cpp
code/sdk/application/wearable/nativeapp/nativeui/compass/src/MainCompassView.cpp
code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp
code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp
code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h
code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp
code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/CompassView.h

index 9a1a5e3..c59a407 100755 (executable)
@@ -59,9 +59,9 @@ namespace OHOS {
     static const int DROPDOWN_SAVEPOWER = 0x40000b;             // 省电模式
     static const int DROPDOWN_SETTING = 0x40000c;               // 设置
     /* -------------------------------------------------------------------------- */
-    static const int COMPASS_ROTATE_CENTER_IMAGE = 0x500001;
-    static const int COMPASS_CORRESPONDENCE_DEGREE = 0x500002;
-    static const int COMPASS_COMPASS = 0x500003;
+    static const int COMPASS_COMPASS0 = 0x500001;              //背景
+    static const int COMPASS_COMPASS1 = 0x500002;              //标记点图片
+    static const int COMPASS_COMPASS2 = 0x500003;              //三角
 
 }
 #endif
index 1383e00..08c4bb2 100755 (executable)
@@ -46,11 +46,11 @@ public:
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppList : Can not continue drag!!");
             return false;
         }
-        // if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) &&
-        //     (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) {
-        //     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Applist Ondrag!!");
-        //     NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TRANSITION_ZOOM);
-        // }
+        if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) &&
+            (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Applist Ondrag!!");
+            NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TRANSITION_ZOOM);
+        }
 
         return false;
     }
index b6469cc..7ee91ba 100755 (executable)
@@ -22,7 +22,7 @@ public:
 
     bool CreateUIViewGroup(void);
     static CompassCalibrationView *GetInstance(void);
-    bool InitView(void *caller) override;
+    bool InitView(void *caller);
 private:
     UILabel *labelOne{nullptr};
     UILabel *labelTwo{nullptr};
index 85c5d6f..e742c53 100755 (executable)
@@ -36,9 +36,9 @@ public:
     void DisplayAngleRight(uint16_t angle);
 
 private:
-    int16_t lastRotateAngle{0};
-    int16_t currentRotateAngle{0};
-    int16_t angleDiff{0};
+    int16_t lastRotateAngle{0};     //上一次的旋转角度
+    int16_t currentRotateAngle{0};  //当前的旋转角度
+    int16_t angleDiff{0};           //角度差
     bool getAngleStatus{false};
     bool initDisplayStatus{true};
 };
index 276ae7d..622a74a 100755 (executable)
@@ -29,19 +29,18 @@ public:
     static CompassView *GetInstance(void);
     void CompassStartRotate(int16_t numb);
     bool InitPage(void);
-    bool InitView(void *caller) override;
+    bool InitView(void *caller);
     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<float> VIEW_CENTER = {VIEW_CENTERS, VIEW_CENTERS};
+    UILabel *directionLabel{nullptr};                               //方向标签
+    UILabel *angledLabel{nullptr};                                  //角度标签
+    UIImageView *backGround{nullptr};                               //背景图片
+    UIImageView *PlaceMarkerImage{nullptr};                         //放置标记图片
+    UIImageView *triangulation{nullptr};                            //三角图片
+    const Vector2<float> VIEW_CENTER = {VIEW_CENTERS, VIEW_CENTERS};//二维向量
 };
 }
 #endif
\ No newline at end of file
index 9db65c4..30580af 100755 (executable)
 #include "CompassPresenter.h"
 #include "CompassModel.h"
 #include "CompassCalibrationView.h"
-#include "KeyInputListener.h"
-#include "common/key_code.h"
 
 namespace OHOS {
 class CompassView;
-class MainCompassPresenter : public Presenter<CompassView>, public CompassPresenter,  public RootView::OnKeyActListener,
+class MainCompassPresenter : public Presenter<CompassView>, public CompassPresenter,
     public ModelListenerSample, public UIView::OnDragListener {
 public:
     MainCompassPresenter();
@@ -34,7 +32,6 @@ public:
 
     static MainCompassPresenter *GetInstance(void);
     bool OnDrag(UIView& view, const DragEvent& event) override;
-    bool OnKeyAct(UIView& view, const KeyEvent& event) override;//增加按键事件
     virtual void Notify() override;
 };
 }
index 5c78f26..e920336 100755 (executable)
@@ -69,15 +69,15 @@ 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());
+        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());
+            CompassView::GetInstance()->DirectionSetText(g_compassList[i].dir, ("~" + std::to_string(angle) + "°").c_str());
         }
     }
 }
@@ -93,7 +93,7 @@ void CompassPresenter::DisplayAngleDir(uint16_t angle)
     }
 }
 
-
+//在范围内旋转指南针
 void CompassPresenter::InScopeRotate(void)
 {
     angleDiff = lastRotateAngle - currentRotateAngle;
@@ -138,6 +138,7 @@ void CompassPresenter::InScopeRotate(void)
     }
 }
 
+//在指南针视图初始化的情况下,根据旋转角度的变化来执行指南针的旋转操作,并在需要的时候更新显示的角度和方向。
 void CompassPresenter::DetermineToRotate(void)
 {
     if (CompassView::GetInstance()  == nullptr) {
@@ -166,7 +167,7 @@ void CompassPresenter::DetermineToRotate(void)
         }
     }
     GraphicService::GetInstance()->PostGraphicEvent(std::bind(&CompassModel::SetDisplayAngle,
-                                                              CompassModel::GetInstance(), 1));
+                                                              CompassModel::GetInstance(), 1));//将任务发布到异步线程
 }
 
 }
\ No newline at end of file
index 5f4b901..5fded09 100755 (executable)
@@ -9,19 +9,24 @@
 #include "ui_resource_image.h"
 #include "CompassView.h"
 #include "MainCompassView.h"
-
+#include "CompassPresenter.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 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 = 198;
+static constexpr int16_t DIRECTIONLABEL_Y = 131;
+static constexpr int16_t DIRECTIONLABEL_TEXT_WIDTH = 70;
+static constexpr int16_t DIRECTIONLABEL_TEXT_HEIGH = 42;
+static constexpr int16_t DIRECTIONLABEL_FONT_TEXT_SIZE = 35;
+static constexpr int16_t DIRECTIONLABEL_STYLE_LINE_HEIGHT = 42;
+static constexpr int16_t ANGLEDLABEL_X = 136;
+static constexpr int16_t ANGLEDLABEL_Y = 182;
+static constexpr int16_t ANGLEDLABEL_TEXT_WIDTH = 194;
+static constexpr int16_t ANGLEDLABEL_TEXT_HEIGHT = 94;
+static constexpr int16_t ANGLEDLABEL_FONT_TEXT_SIZE = 80;
+static constexpr int16_t ANGLEDLABEL_STYLE_LINE_HEIGHT = 94;
 static constexpr int16_t RANDOM_NUMBER_720 = 720;
 static constexpr int16_t RANDOM_NUMBER_360 = 360;
 static constexpr int16_t DELAYING_NUMS = 2000;
@@ -56,22 +61,23 @@ 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);
 }
-
+//加载指南针图片
 bool CompassView::LoadCompassImage(UIImageView *view, uint32_t resId)
 {
     std::string file = COMPASS_IAMGES;
@@ -84,7 +90,7 @@ bool CompassView::LoadCompassImage(UIImageView *view, uint32_t resId)
     view->SetSrc(image);
     return true;
 }
-
+//初始化指南针图片
 bool CompassView::InitCompassImage(void)
 {
     backGround = new UIImageView();
@@ -94,19 +100,19 @@ bool CompassView::InitCompassImage(void)
     }
     backGround->SetPosition(0, 0);
 
-    if (LoadCompassImage(backGround, COMPASS_COMPASS) == false) {
+    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_ROTATE_CENTER_IMAGE) == false) {
-        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,13 +122,13 @@ bool CompassView::InitCompassImage(void)
         return false;
     }
     triangulation->SetPosition(TRIANGULATION_X, TRIANGULATION_Y);
-    if (LoadCompassImage(triangulation, COMPASS_CORRESPONDENCE_DEGREE) == false) {
+    if (LoadCompassImage(triangulation, COMPASS_COMPASS2) == false) {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "triangulation load fail");
         return false;
     }
     return true;
 }
-
+//初始化页面
 bool CompassView::InitPage(void)
 {
     if (InitCompassImage() == false) {
@@ -138,9 +144,12 @@ bool CompassView::InitPage(void)
         return false;
     }
     directionLabel->SetPosition(DIRECTIONLABEL_X, DIRECTIONLABEL_Y);
-    directionLabel->Resize(TEXT_WIDTH, TEXT_HEIGHT);
+    directionLabel->Resize(DIRECTIONLABEL_TEXT_WIDTH, DIRECTIONLABEL_TEXT_HEIGH);
     directionLabel->SetText("北");
-    directionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE);
+    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_ADAPT); 
     directionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
     directionLabel->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE);
     directionLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
@@ -152,17 +161,20 @@ bool CompassView::InitPage(void)
         ClearAll();
         return false;
     }
-    angledLabel->SetPosition(ANGLEDLABEL_X, ANGLEDLABEL_Y);
-    angledLabel->Resize(TEXT_WIDTH, TEXT_HEIGHT);
-    angledLabel->SetText("0°");
-    angledLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE);
+    angledLabel->SetPosition(ANGLEDLABEL_X, ANGLEDLABEL_Y); 
+    angledLabel->Resize(ANGLEDLABEL_TEXT_WIDTH, ANGLEDLABEL_TEXT_HEIGHT);
+    angledLabel->SetText("~0°");
+    angledLabel->SetStyle(STYLE_TEXT_FONT, ANGLEDLABEL_FONT_TEXT_SIZE);
+    angledLabel->SetStyle(STYLE_LINE_HEIGHT, ANGLEDLABEL_STYLE_LINE_HEIGHT);
+    angledLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, ANGLEDLABEL_FONT_TEXT_SIZE);
+    angledLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
     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,7 +184,7 @@ bool CompassView::InitPage(void)
     return true;
 }
 
-
+//初始化视图为可拖拽,可触摸
 bool CompassView::InitView(void *caller)
 {
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CompassView InitView %p", caller);
@@ -194,7 +206,7 @@ CompassView *CompassView::GetInstance(void)
 {
     return g_pCompassView;
 }
-
+//背景图片逆时针旋转numb度
 void CompassView::CompassStartRotate(int16_t numb)
 {
     if (backGround == nullptr) {
index cc0a911..11787e5 100755 (executable)
@@ -47,24 +47,7 @@ bool MainCompassPresenter::OnDrag(UIView& view, const DragEvent& event)
     }
     return true;
 }
-//增加按键事件
-bool MainCompassPresenter::OnKeyAct(UIView& view, const KeyEvent& event)
-{
-    uint16 keyID = event.GetKeyId();
-    WEARABLE_LOGD("","into key! keyID %u\n",keyID);
-#if 0
-    //如果是power键就返回上一级
-    if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER))
-    {
-        uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
-        NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
-    }
-#endif
-    //目前只有一个按键。直接切换
-    uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
-    NativeAbility::GetInstance().ChangeSlice(preSlice);
-    return true;
-}
+
 
 void MainCompassPresenter::Notify()
 {
index 1f8d0d4..9e76280 100755 (executable)
@@ -71,10 +71,6 @@ void MainCompassView::OnStart()
         return;
     }
 
-    //增加按键监听
-       RootView::OnKeyActListener*keyactListener = (RootView::OnKeyActListener*)OHOS::MainCompassPresenter::GetInstance();
-       RootView::GetInstance()->SetOnKeyActListener(keyactListener);
-
     UIView::OnDragListener *compassCalibrationDragListener = (UIView::OnDragListener *)
         OHOS::MainCompassPresenter::GetInstance();
     if (compassCalibrationDragListener == nullptr) {
index 96f4a9a..920ebd2 100755 (executable)
@@ -27,7 +27,9 @@ map<string, AppViewId> g_jumpView = { { MAIN_CLICK_WEATHER, VIEW_MAIN_SAMPLE },
                                       { MAIN_CLICK_ACTIVITY, VIEW_MAIN_ACTIVITY },         // 活动记录界面
                                       { MAIN_CLICK_MESSAGE, VIEW_MAIN_SAMPLE },            // 消息app
                                       { MAIN_CLICK_HEARTRATE, VIEW_MAIN_SAMPLE },          // 心率界面
-                                     };
+                                      { DROPDOWN_CLICK_SETTING,VIEW_SETTING},              // 设置
+                                      { DROPDOWN_CLICK_BLUETOOTH,VIEW_BLUETOOTH_EARPHONE}, // 蓝牙
+                                      };
 
 // map<string, int> g_chanColor = {         { DROPDOWN_CLICK_FINDMYPHONE, DROPDOWN_DROPDOWN_FIND_PHONE_B },
 //                                          { DROPDOWN_CLICK_APPLIST, DROPDOWN_DROPDOWN_FIND_PHONE_B},
@@ -115,9 +117,9 @@ bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event)
     //     }
     // }
 
-    // if (g_jumpView.count(curViewId) != 0) {
-    //     NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]);
-    // }
+    if (g_jumpView.count(curViewId) != 0) {
+        NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]);
+    }
     return true;
 }
  bool MainPresenterSample::OnLongPress(UIView& view, const LongPressEvent& event)
index bcd2c56..a642c80 100755 (executable)
@@ -31,7 +31,7 @@ namespace OHOS
         {COMPASS, &MainViewSample::InitCompassPage},
         {BloodOxygen, &MainViewSample::InitBloodOxygenPage},
         {TRAINING, &MainViewSample::InitTrainingPage},
-        {APPLIST,&MainViewSample::InitApplistPage}
+        //{APPLIST,&MainViewSample::InitApplistPage}
     };
 
     MainViewSample::MainViewSample()
index 670d63f..6913973 100755 (executable)
@@ -170,7 +170,7 @@ void ScreenModels::PreLoadAppimages(void)
 {
     LoadAppMultiImages(PLAYER_IAMGES, PLAYER_PLAYERSMODEL_RANDOM, PLAYER_PLAYERHIGHLIGHT);
     LoadAppMultiImages(CLOCK_IAMGES, CLOCK_CLASSIC_GEOMETRY, CLOCK_SECOND);
-    LoadAppMultiImages(COMPASS_IAMGES, COMPASS_ROTATE_CENTER_IMAGE, COMPASS_COMPASS);
+    LoadAppMultiImages(COMPASS_IAMGES, COMPASS_COMPASS0, COMPASS_COMPASS2);
     LoadAppMultiImages(DROPDOWN_IAMGES, DROPDOWN_BLUETOOTHCONNECTED, DROPDOWN_SETTING);
     LoadAppMultiImages(HEART_IAMGES, HEART_HEARTRATECOOR, HEART_HEARTRATE_TOP);
 }
index b452585..a1263f0 100755 (executable)
@@ -13,8 +13,8 @@
  * limitations under the License.
  */
 
-#ifndef COMPASS_VIEW_H
-#define COMPASS_VIEW_H
+#ifndef COMPASS_VIEW_H_
+#define COMPASS_VIEW_H_
 
 #include "components/root_view.h"
 #include "components/ui_label.h"