配对弹窗优化,添加一个动画,并适配多国语言
authorluozheng <1732036298@qq.com>
Mon, 2 Sep 2024 07:03:09 +0000 (15:03 +0800)
committerluozheng <1732036298@qq.com>
Mon, 2 Sep 2024 07:03:09 +0000 (15:03 +0800)
code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp

index ff9564d..e276098 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-22 10:04:36
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-31 16:49:39
+ * @LastEditTime: 2024-09-02 14:52:10
  * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp
  */
 #include "notification_manager.h"
 #include <broadcast_feature.h>
 #include <custom_utils.h>
 #include "uicomponents/UIComponents.h"
+#include "ConfigModel.h"
+#include <custom_runtime.h>
+#include "../../../../../../drivers/peripheral/vibrator/service/vibrator_service.h"
+#include <ui_service.h>
 
 namespace OHOS
 {
     UIViewGroup *DeviceBindingView{nullptr};
+    UIScrollView *DeviceBindingScrollView{nullptr};
     UILabelExt *DeviceBindingViewTitleLabel{nullptr}; // 标题 :设备绑定
     UILabelExt *DeviceBindingName{nullptr};           // 绑定的设备名称
-    UILabelExt *DeviceBindingViewLabel{nullptr};      // 标签内容:“想要进行连接是否同意”
     UIButton *DeviceBindingButtonOK{nullptr};         // 设备绑定确认
     UIButton *DeviceBindingButtonCancel{nullptr};     // 设备绑定取消
 
+    UIImageAnimatorView *DeviceBindingAnimatorView{nullptr}; // 设备绑定动画
+    static constexpr int BIND_IMAGE_ANIMATOR_VIEW_X = 183;
+    static constexpr int BIND_IMAGE_ANIMATOR_VIEW_Y = 125;
+    static constexpr int BIND_IMAGE_ANIMATOR_VIEW_W = 100;
+    static constexpr int BIND_IMAGE_ANIMATOR_VIEW_H = 66;
+    static constexpr int BIND_IMAGE_ANIMATOR_VIEW_TIMEOFUPDATE = 70;
+    static constexpr int BIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 25; // 绑定动画帧数
+    const ImageInfo **BindPathsArray{nullptr};
+    ImageAnimatorInfo BindImageInfo[BIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES];
+    static constexpr const char *BIND_IMAGE_SRC = "/user/res/remind/bind/";
+
     UIViewGroup *DeviceUnBindingView{nullptr};
     UILabelExt *DeviceUnBindingViewTitleLabel{nullptr}; // 标题 :设备解绑
     UILabelExt *DeviceUnBindingName{nullptr};           // 解绑的设备名称
@@ -51,6 +66,7 @@ namespace OHOS
     static constexpr int UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 25; // 解绑动画帧数
     const ImageInfo **UnBindPathsArray{nullptr};
     ImageAnimatorInfo UnBindImageInfo[UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES];
+    static constexpr const char *UNBIND_IMAGE_SRC = "/user/res/remind/unbind/";
 
     UIViewGroup *DeviceUnbindingRequestGroupView{nullptr};
     UIScrollView *DeviceUnbindingRequestScrollView{nullptr};   // 设备解除绑定请求(与新设备连接)视图
@@ -155,8 +171,9 @@ namespace OHOS
         }
         button->SetPosition(x, y, w, h);
         button->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
-        button->SetStyle(STYLE_BACKGROUND_OPA, 0x2d);
-        button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff4fc34c, UIButton::PRESSED);
+        button->SetStyle(STYLE_BACKGROUND_OPA, 0x19);
+        button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED);
+        button->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);
         button->SetImageSrc(imageSrc, imageSrc);
         return button;
     }
@@ -202,71 +219,116 @@ namespace OHOS
             DeviceBindingView->SetPosition(0, 0, 466, 466);
             DeviceBindingView->SetDraggable(true);
             DeviceBindingView->SetTouchable(true);
+            /* ------------------------- DeviceBindingScrollView ------------------------ */
+            if (DeviceBindingScrollView == nullptr)
+            {
+                DeviceBindingScrollView = new UIScrollView();
+                if (DeviceBindingScrollView == nullptr)
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DeviceBindingScrollView new fail");
+                    return nullptr;
+                }
+            }
+            DeviceBindingScrollView->SetPosition(0, 0, 466, 466);
+            DeviceBindingScrollView->SetThrowDrag(true);
+            DeviceBindingScrollView->SetDraggable(true);
+            DeviceBindingScrollView->SetTouchable(true);
+            DeviceBindingScrollView->SetReboundSize(30);
+            DeviceBindingScrollView->SetScrollBlankSize(30);
+            DeviceBindingScrollView->SetSwipeACCLevel(800); // 800: compensation distance
+            DeviceBindingScrollView->SetDragACCLevel(5);    // 5: drag acceleration
+            DeviceBindingScrollView->SetMaxScrollDistance(1000);
+            DeviceBindingScrollView->SetDirection(UIScrollView::VERTICAL);
             /* ----------------------- DeviceBindingViewTitleLabel ---------------------- */
-            DeviceBindingViewTitleLabel = new UILabelExt();
             if (DeviceBindingViewTitleLabel == nullptr)
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceBindingView] DeviceBindingViewTitleLabel new fail!!");
-                return nullptr;
+                DeviceBindingViewTitleLabel = new UILabelExt();
+                if (DeviceBindingViewTitleLabel == nullptr)
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceBindingView] DeviceBindingViewTitleLabel new fail!!");
+                    return nullptr;
+                }
             }
-            DeviceBindingViewTitleLabel->SetPosition(173, 52, 120, 35);
+            DeviceBindingViewTitleLabel->SetPosition(83, 50, 300, 35);
             DeviceBindingViewTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
             DeviceBindingViewTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
 
-            DeviceBindingViewTitleLabel->SetText("设备绑定");
-            DeviceBindingViewTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
+            // DeviceBindingViewTitleLabel->SetText("设备绑定");
+            DeviceBindingViewTitleLabel->SetTextId(STR_DEVICE_BINDING);
+            DeviceBindingViewTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
             DeviceBindingViewTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
             DeviceBindingViewTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+            DeviceBindingViewTitleLabel->SetRollSpeed(70);
+            /* ----------------------- DeviceBindingAnimatorView ---------------------- */
+            BindPathsArray = CreateImageInfoArray(BIND_IMAGE_SRC, BIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+            if (DeviceBindingAnimatorView == nullptr)
+            {
+                DeviceBindingAnimatorView = new UIImageAnimatorView();
+                if (DeviceBindingAnimatorView == nullptr)
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView]DeviceBindingAnimatorView new fail");
+                    return nullptr;
+                }
+                for (uint8_t i = 0; i < BIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)
+                {
+                    BindImageInfo[i].imageInfo = (BindPathsArray[i]);
+                    BindImageInfo[i].imageType = IMG_SRC_IMAGE_INFO;
+                    BindImageInfo[i].pos.x = BIND_IMAGE_ANIMATOR_VIEW_X;
+                    BindImageInfo[i].pos.y = BIND_IMAGE_ANIMATOR_VIEW_Y;
+                    BindImageInfo[i].width = BIND_IMAGE_ANIMATOR_VIEW_W;
+                    BindImageInfo[i].height = BIND_IMAGE_ANIMATOR_VIEW_H;
+                }
+                DeviceBindingAnimatorView->SetPosition(BIND_IMAGE_ANIMATOR_VIEW_X, BIND_IMAGE_ANIMATOR_VIEW_Y, BIND_IMAGE_ANIMATOR_VIEW_W, BIND_IMAGE_ANIMATOR_VIEW_H);
+                DeviceBindingAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+                DeviceBindingAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+                DeviceBindingAnimatorView->SetImageAnimatorSrc(BindImageInfo, BIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, BIND_IMAGE_ANIMATOR_VIEW_TIMEOFUPDATE);
+                DeviceBindingAnimatorView->SetRepeat(true);
+                DeviceBindingAnimatorView->SetAutoEnable(false);
+                DeviceBindingAnimatorView->SetResizeMode(UIImageAnimatorView::CENTER);
+                DeviceBindingAnimatorView->Start();
+            }
             /* ---------------------------- DeviceBindingName --------------------------- */
-            DeviceBindingName = new UILabelExt();
             if (DeviceBindingName == nullptr)
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceBindingView] DeviceBindingName new fail!!");
-                return nullptr;
+                DeviceBindingName = new UILabelExt();
+                if (DeviceBindingName == nullptr)
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceBindingView] DeviceBindingName new fail!!");
+                    return nullptr;
+                }
             }
 
             char *devanme = PairingViewEventListener::GetInstance().GetDeviceName();
-            DeviceBindingName->SetPosition(33, 180, 400, 40);
+            DeviceBindingName->SetPosition(53, 230, 360, 70);
             DeviceBindingName->SetStyle(STYLE_TEXT_FONT, 30);
             DeviceBindingName->SetStyle(STYLE_LINE_HEIGHT, 35);
 
             if (strlen(devanme))
             {
-                DeviceBindingName->SetText(devanme);
+                // DeviceBindingName->SetText("Iphone 14 Pro MAX 想要与你进行连接绑定Iphone 14 Pro MAX 想要与你进行连接绑定Iphone 14 Pro MAX 想要与你进行连接绑定Iphone 14 Pro MAX 想要与你进行连接绑定");
+                // DeviceBindingName->SetText(devanme);
+                DeviceBindingName->SetTextId(STR_DEVICE_BINDING_NOTE); // XX想要与你进行连接绑定
+                UpdateLabel(DeviceBindingName, devanme, STR_DEVICE_BINDING_NOTE);
             }
             else
             {
-                DeviceBindingName->SetText(" ");
+                // DeviceBindingName->SetText(" ");
+                UpdateLabel(DeviceBindingName, " ", STR_DEVICE_BINDING_NOTE);
             }
-
-            DeviceBindingName->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
+            DeviceBindingName->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
             DeviceBindingName->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
-            DeviceBindingName->SetRollSpeed(60);
             DeviceBindingName->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
-            /* ------------------------- DeviceBindingViewLabel ------------------------- */
-            DeviceBindingViewLabel = new UILabelExt();
-            if (DeviceBindingViewLabel == nullptr)
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceBindingView] DeviceBindingViewLabel new fail!!");
-                return nullptr;
-            }
-            DeviceBindingViewLabel->SetPosition(33, 240, 400, 40);
-            DeviceBindingViewLabel->SetStyle(STYLE_TEXT_FONT, 30);
-            DeviceBindingViewLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-            DeviceBindingViewLabel->SetText("想要进行连接是否同意");
-            DeviceBindingViewLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
-            DeviceBindingViewLabel->SetTextColor(Color::GetColorFromRGBA(0xAA, 0xAA, 0xAA, 0xff));
-            DeviceBindingViewLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
-            DeviceBindingViewLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+            DeviceBindingName->SetRollSpeed(70);
             /* ------------------------------ DeviceBindingButtonCancel ------------------------------ */
-            DeviceBindingButtonCancel = CreateButton(111, 320, 100, 100, "/user/res/SYSTEM_CheckOff.bin");
+            int y = DeviceBindingName->GetY() + DeviceBindingName->GetTextHeight() + 20;
+            DeviceBindingButtonCancel = CreateButton(111, y, 100, 100, "/user/res/SYSTEM_CheckOff.bin");
             if (DeviceBindingButtonCancel == nullptr)
             {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceBindingView] DeviceBindingButtonCancel new fail!!");
                 return nullptr;
             }
             /* -------------------------------- DeviceBindingButtonOK -------------------------------- */
-            DeviceBindingButtonOK = CreateButton(256, 320, 100, 100, "/user/res/SYSTEM_CheckOn.bin");
+            DeviceBindingButtonOK = CreateButton(256, y, 100, 100, "/user/res/SYSTEM_CheckOn.bin");
             if (DeviceBindingButtonOK == nullptr)
             {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceBindingView] DeviceBindingButtonOK new fail!!");
@@ -274,19 +336,32 @@ namespace OHOS
             }
 
             UIView::OnClickListener *listener = static_cast<UIView::OnClickListener *>(&PairingViewEventListener::GetInstance());
+            if (listener == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceBindingView] PairingViewEventListener::GetInstance fail!!");
+                return nullptr;
+            }
             DeviceBindingButtonCancel->SetOnClickListener(listener);
             DeviceBindingButtonOK->SetOnClickListener(listener);
             /* ----------------------------------- Add ---------------------------------- */
-            DeviceBindingView->Add(DeviceBindingViewTitleLabel);
-            DeviceBindingView->Add(DeviceBindingName);
-            DeviceBindingView->Add(DeviceBindingViewLabel);
-            DeviceBindingView->Add(DeviceBindingButtonCancel);
-            DeviceBindingView->Add(DeviceBindingButtonOK);
+            DeviceBindingScrollView->Add(DeviceBindingViewTitleLabel);
+            DeviceBindingScrollView->Add(DeviceBindingAnimatorView);
+            DeviceBindingScrollView->Add(DeviceBindingName);
+            DeviceBindingScrollView->Add(DeviceBindingButtonCancel);
+            DeviceBindingScrollView->Add(DeviceBindingButtonOK);
+            DeviceBindingView->Add(DeviceBindingScrollView);
 #if NO_LCD_TEST_CONNECT
             PairingViewEventListener::GetInstance().Pairing_StartTimer();
 #endif
         }
 
+        if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get()))
+        {
+            ui_api_vibrate_once_func();
+        }
+
+        ScreenTurnOn(40 * 1000); // 亮屏操作  40秒关闭
+
         NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDeviceBindingView);
         return DeviceBindingView;
     }
@@ -310,7 +385,7 @@ namespace OHOS
             DeviceUnBindingView->SetDraggable(true);
             DeviceUnBindingView->SetTouchable(true);
             /* ----------------------- DeviceUnBindingAnimatorView ---------------------- */
-            UnBindPathsArray = CreateImageInfoArray("/user/res/remind/unbind/", UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+            UnBindPathsArray = CreateImageInfoArray(UNBIND_IMAGE_SRC, UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
             if (DeviceUnBindingAnimatorView == nullptr)
             {
                 DeviceUnBindingAnimatorView = new UIImageAnimatorView();
@@ -557,28 +632,44 @@ namespace OHOS
      */
     void FreeDeviceBindingView(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FreeDeviceBindingView]");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[FreeDeviceBindingView]");
         if (DeviceBindingView != nullptr)
         {
             DeviceBindingView->RemoveAll();
-
-            delete DeviceBindingViewTitleLabel;
-            DeviceBindingViewTitleLabel = nullptr;
-
-            delete DeviceBindingName;
-            DeviceBindingName = nullptr;
-
-            delete DeviceBindingViewLabel;
-            DeviceBindingViewLabel = nullptr;
-
-            delete DeviceBindingButtonCancel;
-            DeviceBindingButtonCancel = nullptr;
-
-            delete DeviceBindingButtonOK;
-            DeviceBindingButtonOK = nullptr;
-
+            if (DeviceBindingScrollView != nullptr)
+            {
+                DeviceBindingScrollView->RemoveAll();
+                if (DeviceBindingViewTitleLabel)
+                {
+                    delete DeviceBindingViewTitleLabel;
+                    DeviceBindingViewTitleLabel = nullptr;
+                }
+                if (DeviceBindingName)
+                {
+                    delete DeviceBindingName;
+                    DeviceBindingName = nullptr;
+                }
+                if (DeviceBindingAnimatorView)
+                {
+                    DeviceBindingAnimatorView->Stop();
+                    delete DeviceBindingAnimatorView;
+                    DeviceBindingAnimatorView = nullptr;
+                    FreeImageInfoArray(BindPathsArray, BIND_IMAGE_SRC, BIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+                }
+                if (DeviceBindingButtonCancel)
+                {
+                    delete DeviceBindingButtonCancel;
+                    DeviceBindingButtonCancel = nullptr;
+                }
+                if (DeviceBindingButtonOK)
+                {
+                    delete DeviceBindingButtonOK;
+                    DeviceBindingButtonOK = nullptr;
+                }
+                delete DeviceBindingScrollView;
+                DeviceBindingScrollView = nullptr;
+            }
             RootView::GetInstance()->Remove(DeviceBindingView);
-
             delete DeviceBindingView;
             DeviceBindingView = nullptr;
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FreeDeviceBindingView] success");
@@ -598,11 +689,10 @@ namespace OHOS
             delete DeviceUnBindingViewTitleLabel;
             DeviceUnBindingViewTitleLabel = nullptr;
 
-            FreeImageInfoArray(UnBindPathsArray, "/user/res/remind/unbind/", UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
-
             DeviceUnBindingAnimatorView->Stop();
             delete DeviceUnBindingAnimatorView;
             DeviceUnBindingAnimatorView = nullptr;
+            FreeImageInfoArray(UnBindPathsArray, UNBIND_IMAGE_SRC, UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
 
             delete DeviceUnBindingName;
             DeviceUnBindingName = nullptr;