勿扰模式和查找手机视图优化
authorluozheng <1732036298@qq.com>
Fri, 7 Jun 2024 11:01:05 +0000 (19:01 +0800)
committerluozheng <1732036298@qq.com>
Fri, 7 Jun 2024 11:01:05 +0000 (19:01 +0800)
code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/include/DnotDisturbPresenter.h
code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/include/DnotDisturbView.h
code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbView.cpp
code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhonePresenter.h
code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp

index 37d9ba9..ca7b7bf 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-10 11:58:32
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-10 16:26:47
+ * @LastEditTime: 2024-06-07 18:54:26
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/include/DnotDisturbPresenter.h
  */
 
@@ -38,6 +38,7 @@ namespace OHOS
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
         bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
+        bool X_DRAG_FLAG{false};
     };
 }
 
index e6c78af..2fdaf4b 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-10 11:58:15
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-05-10 15:42:00
+ * @LastEditTime: 2024-06-07 18:46:54
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/include/DnotDisturbView.h
  */
 #ifndef DNOTDISTURB_VIEW_H
@@ -40,7 +40,7 @@ namespace OHOS
         void DnotDisturbViewInit(void);
         void ClearAll(void);
         UIScrollView *scrollView = nullptr;
-        UILabelExt *showTimeLabel{nullptr}; // 显示系统时间的标签
+        UILabelExt *showTitleLabel{nullptr}; 
         UIImageView *background{nullptr};
         UIImageView *DnotDisturbImage{nullptr};
         UILabel *AttentionLabel{nullptr};
index c91d337..1e8240b 100644 (file)
@@ -2,11 +2,12 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-10 11:58:37
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-25 16:39:57
+ * @LastEditTime: 2024-06-07 18:54:14
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbPresenter.cpp
  */
 #include "AppViewIDs.h"
 #include "NativeAbility.h"
+#include "UiConfig.h"
 #include "dnotdisturb/include/DnotDisturbView.h"
 #include "dnotdisturb/include/DnotDisturbPresenter.h"
 #include "dnotdisturb/include/DnotDisturbModel.h"
@@ -55,15 +56,24 @@ namespace OHOS
 
     bool DnotDisturbPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnDrag");
         UNUSED(view);
-        UNUSED(event);
+        if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
+        {
+            DnotDisturbPresenter::X_DRAG_FLAG = true;
+        }
         return true;
     }
 
     bool DnotDisturbPresenter::OnDragEnd(UIView &view, const DragEvent &event)
     {
-        UNUSED(view);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DnotDisturbPresenter::OnDragEnd");
         UNUSED(event);
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && DnotDisturbPresenter::X_DRAG_FLAG)
+        {
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+            DnotDisturbPresenter::X_DRAG_FLAG = false;
+        }
         return true;
     }
 
@@ -76,15 +86,16 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::GetInstance fail!!");
             return false;
         }
-        if (&view == p_DnotDisturbView->GetButtonOn())//开启勿扰模式
+        if (&view == p_DnotDisturbView->GetButtonOn()) // 开启勿扰模式
         {
             DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(true);
-            NativeAbility::GetInstance().Back();
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
         }
         else if (&view == p_DnotDisturbView->GetButtonOff())
         {
-           NativeAbility::GetInstance().Back();
+            // NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
         }
+        NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
         return true;
     }
 
@@ -97,13 +108,13 @@ namespace OHOS
         // 如果是power键就返回上一级
         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
         {
-           NativeAbility::GetInstance().Back();
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
         }
         return true;
     }
 
     void DnotDisturbPresenter::Notify()
     {
-        DnotDisturbView::GetInstance()->UpdataTime();
+        // DnotDisturbView::GetInstance()->UpdataTime();
     }
 }
\ No newline at end of file
index b6a9bae..0599c15 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-10 11:58:21
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-05-10 15:43:25
+ * @LastEditTime: 2024-06-07 18:51:22
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/dnotdisturb/src/DnotDisturbView.cpp
  */
 #include "dnotdisturb/include/DnotDisturbView.h"
@@ -42,10 +42,10 @@ namespace OHOS
         {
             scrollView->RemoveAll();
 
-            if (showTimeLabel != nullptr)
+            if (showTitleLabel != nullptr)
             {
-                delete showTimeLabel;
-                showTimeLabel = nullptr;
+                delete showTitleLabel;
+                showTitleLabel = nullptr;
             }
 
             if (background != nullptr)
@@ -93,20 +93,29 @@ namespace OHOS
             }
             scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
             scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+            scrollView->SetTouchable(true);
+            scrollView->SetDraggable(true);
+            UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(DnotDisturbPresenter::GetInstance());
+            if (dragListener == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::dragListener new fail!!");
+                return;
+            }
+            scrollView->SetOnDragListener(dragListener);
             /* -------------------------------------------------------------------------- */
-            showTimeLabel = new UILabelExt();
-            if (showTimeLabel == nullptr)
+            showTitleLabel = new UILabelExt();
+            if (showTitleLabel == nullptr)
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::showTimeLabel new fail!!");
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DnotDisturbView::showTitleLabel new fail!!");
                 return;
             }
-            showTimeLabel->SetPosition(83, 52, 300, 46);
-            showTimeLabel->SetStyle(STYLE_TEXT_FONT, 40);
-            showTimeLabel->SetStyle(STYLE_LINE_HEIGHT, 46);
-            showTimeLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
-            showTimeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
-            showTimeLabel->SetRollSpeed(40);
-            showTimeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40);
+            showTitleLabel->SetPosition(83, 52, 300, 35);
+            showTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+            showTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+            showTitleLabel->SetTextId(STR_DO_NOT_DISTURB);
+            showTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
+            showTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+            showTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
             /* -------------------------------------------------------------------------- */
             background = new UIImageView();
             if (background == nullptr)
@@ -137,7 +146,7 @@ namespace OHOS
             AttentionLabel->SetPosition(33, 228, 400, 70);
             AttentionLabel->SetStyle(STYLE_TEXT_FONT, 30);
             AttentionLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-            //AttentionLabel->SetText("开启勿扰模式,手表将不会发出震动与铃声,是否开启");
+            // AttentionLabel->SetText("开启勿扰模式,手表将不会发出震动与铃声,是否开启");
             SetLabelId(AttentionLabel, STR_DO_NOT_DISTURB_MODE);
             AttentionLabel->SetLineBreakMode(UILabelExt::LINE_BREAK_WRAP);
             AttentionLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
@@ -183,6 +192,7 @@ namespace OHOS
     /*更新当前时间*/
     void DnotDisturbView::UpdataTime()
     {
+#if 0
         // 获取当前时间
         struct tm pTM;
         time_t seconds;
@@ -195,7 +205,8 @@ namespace OHOS
 
         // 将时间和日期转换为字符串
         std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
-        showTimeLabel->SetText(stringtime.c_str());
+        showTitleLabel->SetText(stringtime.c_str());
+#endif
     }
 
     UILabelButtonExt *DnotDisturbView::GetButtonOn(void)
@@ -221,13 +232,14 @@ namespace OHOS
     void DnotDisturbView::OnSetUpView()
     {
         View<DnotDisturbPresenter>::OnSetUpView();
-        scrollView->Add(showTimeLabel);
+        scrollView->Add(showTitleLabel);
         scrollView->Add(background);
         scrollView->Add(DnotDisturbImage);
         scrollView->Add(AttentionLabel);
         scrollView->Add(ButtonOn);
         scrollView->Add(ButtonOff);
         RootView::GetInstance()->Add(scrollView);
+        container_ = scrollView;
         Draw();
     }
 
index 6fce8bb..2fa4cfa 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 10:47:24
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-05-10 16:22:33
+ * @LastEditTime: 2024-06-07 18:18:38
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhonePresenter.h
  */
 
@@ -20,7 +20,8 @@ namespace OHOS
     class FindPhoneView;
     class FindPhonePresenter : public Presenter<FindPhoneView>,
                                public UIView::OnClickListener,
-                               public RootView::OnKeyActListener
+                               public RootView::OnKeyActListener,
+                               public UIView::OnDragListener
     {
     public:
         FindPhonePresenter();
@@ -35,7 +36,10 @@ namespace OHOS
 
     private:
         bool OnClick(UIView &view, const ClickEvent &event) override;
+        bool OnDrag(UIView &view, const DragEvent &event) override;
+        bool OnDragEnd(UIView &view, const DragEvent &event) override;
         bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
+        bool X_DRAG_FLAG{false};
     };
 }
 #endif
index 312ffae..0e1b57b 100644 (file)
@@ -2,10 +2,11 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 10:47:40
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-05-10 16:29:37
+ * @LastEditTime: 2024-06-07 18:21:37
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp
  */
 #include "AppViewIDs.h"
+#include "UiConfig.h"
 #include "components/ui_label_ext.h"
 #include "language/font/ui_resource_string.h"
 #include "NativeAbility.h"
@@ -57,6 +58,7 @@ namespace OHOS
 
     bool FindPhonePresenter::OnClick(UIView &view, const ClickEvent &event)
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnClick");
         UNUSED(event);
         if (strcmp(view.GetViewId(), FINDPHONE_LABELBUTTON) == 0)
         {
@@ -65,7 +67,30 @@ namespace OHOS
             {
                 senfindphoneSend(FINDPHONE_STOP);
             }
-            NativeAbility::GetInstance().Back();
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+        }
+        return true;
+    }
+
+    bool FindPhonePresenter::OnDrag(UIView &view, const DragEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnDrag");
+        UNUSED(view);
+        if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
+        {
+            FindPhonePresenter::X_DRAG_FLAG = true;
+        }
+        return true;
+    }
+    
+    bool FindPhonePresenter::OnDragEnd(UIView &view, const DragEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FindPhonePresenter::OnDragEnd");
+        UNUSED(event);
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && FindPhonePresenter::X_DRAG_FLAG)
+        {
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+            FindPhonePresenter::X_DRAG_FLAG = false;
         }
         return true;
     }
@@ -84,7 +109,7 @@ namespace OHOS
             {
                 senfindphoneSend(FINDPHONE_STOP);
             }
-            NativeAbility::GetInstance().Back();
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
         }
         return true;
     }
index 03779a7..a263088 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 10:47:46
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-05-10 16:36:28
+ * @LastEditTime: 2024-06-07 18:33:39
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp
  */
 #include "findphone/include/FindPhoneView.h"
@@ -303,6 +303,12 @@ namespace OHOS
         {
             FindPhoneViewInit_BlueToothDisConnected();
         }
+
+        FindPhoneGroupView->SetTouchable(true);
+        FindPhoneGroupView->SetDraggable(true);
+        UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(FindPhonePresenter::GetInstance());
+        FindPhoneGroupView->SetOnDragListener(dragListener);
+
         // 增加按键监听
         RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::FindPhonePresenter::GetInstance();
         RootView::GetInstance()->SetOnKeyActListener(keyactListener);
@@ -312,6 +318,7 @@ namespace OHOS
     {
         View<FindPhonePresenter>::OnSetUpView();
         RootView::GetInstance()->Add(FindPhoneGroupView);
+        container_ = FindPhoneGroupView;
         Draw();
     }