表盘
authorCaisking <3449750381@qq.com>
Sat, 25 Nov 2023 09:53:41 +0000 (17:53 +0800)
committerCaisking <3449750381@qq.com>
Sat, 25 Nov 2023 09:53:41 +0000 (17:53 +0800)
code/sdk/application/wearable/nativeapp/nativeui/clock/include/DialUserView.h [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/clock/src/DialUserView.cpp [new file with mode: 0644]

diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/DialUserView.h b/code/sdk/application/wearable/nativeapp/nativeui/clock/include/DialUserView.h
new file mode 100644 (file)
index 0000000..590db32
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2023 CompanyNameMagicTag.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DialUserVIEW_H
+#define DialUserVIEW_H
+
+#include <string>
+#include <time.h>
+#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 "components/ui_sweep_clock.h"
+#include "BaseView.h"
+#include "ChangeSliceListener.h"
+#include "font/ui_font_bitmap.h"
+#include "font/ui_font.h"
+#include "graphic_config.h"
+#include "HealthModel.h"
+#include "ActivityModel.h"
+#include "UiConfig.h"
+#include "components/ui_card_page.h"
+#include "animator/animator_manager.h"
+#include "time.h"
+#include "sys/time.h"
+
+namespace OHOS
+{
+    class DialUserView : public UICardPage
+    {
+    public:
+        DialUserView();
+        ~DialUserView();
+        static DialUserView *GetInstance(void);
+        void Init();
+        void DeInit();
+        void OnTimer(void);
+        void PreLoad(void) override;
+        void ClockAnimatorStart(void);
+        void ClockAnimatorStop(void);
+        UIView *GetView();
+
+    private:
+        void InitDateTime(void);
+        DialUserView(const DialUserView &) = delete;
+        DialUserView &operator=(const DialUserView &) = delete;
+        DialUserView(DialUserView &&) = delete;
+        DialUserView &operator=(DialUserView &&) = delete;
+
+        UIViewGroup *container_ = nullptr;
+        UIImageView *image1_ = nullptr;
+        UILabel *label1_ = nullptr;
+        UILabel *label2_ = nullptr;
+        Animator *clockAnimator{nullptr};
+        bool viewiInitStatus{false};
+    };
+} // namespace OHOS
+#endif /* DialUserVIEW_H */
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/DialUserView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/DialUserView.cpp
new file mode 100644 (file)
index 0000000..65a3081
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2023 CompanyNameMagicTag.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "DialUserView.h"
+#include "DialUserView.h"
+#include "MainPresenterSample.h"
+#include "components/ui_label.h"
+#include "wearable_log.h"
+#include "ui_resource_image.h"
+#include "common/image_cache_manager.h"
+#include <time.h>
+
+namespace OHOS
+{
+
+    static DialUserView *g_pDialUserView = nullptr;
+    DialUserView::DialUserView()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DialUserView::DialUserView");
+        SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+        g_pDialUserView = this;
+    }
+
+    DialUserView::~DialUserView()
+    {
+        if (clockAnimator != nullptr)
+        {
+            clockAnimator->Stop();
+            delete clockAnimator;
+            clockAnimator = nullptr;
+        }
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DialUserView::~DialUserView");
+        if (container_ != nullptr)
+        {
+            container_->RemoveAll();
+            delete container_;
+            container_ = nullptr;
+        }
+        if (image1_ != nullptr)
+        {
+            delete image1_;
+            image1_ = nullptr;
+        }
+        if (label1_ != nullptr)
+        {
+            delete label1_;
+            label1_ = nullptr;
+        }
+        if (label2_ != nullptr)
+        {
+            delete label2_;
+            label2_ = nullptr;
+        }
+        delete g_pDialUserView;
+        g_pDialUserView = nullptr;
+    }
+    DialUserView *DialUserView::GetInstance(void)
+    {
+        return g_pDialUserView;
+    }
+    void DialUserView::Init()
+    {
+        // Other initialization code
+        UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance();
+        container_ = new UIViewGroup();
+        if (container_ == nullptr)
+        {
+            return;
+        }
+        container_->SetPosition(0, 0);
+        container_->SetWidth(Screen::GetInstance().GetWidth());
+        container_->SetHeight(Screen::GetInstance().GetHeight());
+        container_->SetTouchable(true);
+        container_->SetDraggable(true);
+
+        RootView::GetInstance()->Add(container_);
+
+        // Add ImageView to App
+        if (image1_ == nullptr)
+        {
+            image1_ = new UIImageView();
+        }
+        image1_->SetPosition(0, 0);   // widget's left position and top position
+        image1_->Resize(100, 100);    // widget's width and height
+        image1_->SetViewId("image1"); // Set style
+
+        // Set additional property
+#ifdef _WIN32
+        char *image1imagesPath = "c:/Users/caiking/project/image_converter_tool/output/Dial/Diallogo.bin";
+#else
+        const char *image1imagesPath = PNG_DIAL_USER_IMAGE;
+#endif
+        image1_->SetSrc(image1imagesPath);
+
+        // Add to rootView
+        container_->Add(image1_);
+        //image1_->SetVisible(true);
+
+        InitDateTime();
+
+        // Add Label to App
+        if (label2_ == nullptr)
+        {
+            label2_ = new UILabel();
+        }
+        label2_->SetPosition(166, 381); // widget's left position and top position
+        label2_->Resize(200, 60);       // widget's width and height
+        label2_->SetViewId("label2");   // Set style
+        label2_->SetStyle(STYLE_TEXT_FONT, 45);
+
+        // Set additional property
+        label2_->SetText("Sat 02");
+        label2_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
+        label2_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        label2_->SetRollSpeed(0);
+        label2_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 45);
+
+        // Add to rootView
+        container_->Add(label2_);
+        //label2_->SetVisible(true);
+
+        SetCoverable(true);
+    }
+
+    void DialUserView::PreLoad(void)
+    {
+        if (!viewiInitStatus)
+        {
+            Init();
+            viewiInitStatus = true;
+        }
+    }
+
+    void DialUserView::InitDateTime(void)
+    {
+        // Add Label to App
+        if (label1_ == nullptr)
+        {
+            label1_ = new UILabel();
+        }
+        label1_->SetPosition(155, 301); // widget's left position and top position
+        label1_->Resize(200, 60);       // widget's width and height
+        label1_->SetViewId("label1");   // Set style
+        label1_->SetStyle(STYLE_TEXT_FONT, 60);
+
+        // Set additional property
+        label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
+        label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        label1_->SetRollSpeed(0);
+        label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 60);
+
+        // Get the current time
+        time_t currentTime = time(NULL);
+        struct tm *localTime = localtime(&currentTime);
+
+        // Format the time as "HH:MM"
+        char timeString[6];
+        sprintf(timeString, "%02d:%02d", localTime->tm_hour, localTime->tm_min);
+
+        // Set the time string to the label1_
+        label1_->SetText(timeString);
+
+        // Add to rootView
+        container_->Add(label1_);
+        //label1_->SetVisible(true);
+    }
+
+}
\ No newline at end of file