From: Caisking <3449750381@qq.com> Date: Fri, 12 Jan 2024 08:01:22 +0000 (+0800) Subject: 实现表盘切换 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=65ada19054f3be876acd38978489db93181a9c2d;p=mirrors%2FFD230.git 实现表盘切换 --- diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h index af941251f..1b969e5d8 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h @@ -55,7 +55,7 @@ public: void InitBloodErrorSlice(void); void InitBloodNoteSlice(void); void InitDialSlice(void); - + void InitHeartRemindSlice(void); void InitPhoneSlice(void); void InitPhoneCallSlice(void); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp index 26265f6dc..74cf39440 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistModel.cpp @@ -21,7 +21,7 @@ namespace OHOS { const AppItem g_nativeAppList[] = { {VIEW_SETTING, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_SETTING_IMAGE, "系统设置", nullptr}, - {VIEW_DIGITAL, PNG_APPLIST_DIAL_IMAGE, PNG_APPLIST_DIAL_IMAGE, "表盘设置", nullptr}, + {VIEW_DIAL, PNG_APPLIST_DIAL_IMAGE, PNG_APPLIST_DIAL_IMAGE, "表盘设置", nullptr}, {VIEW_COMPASS, PNG_APPLIST_COMPASS_IMAGE, PNG_APPLIST_COMPASS_IMAGE, "指南针", nullptr}, {VIEW_WEATHER, PNG_APPLIST_WEATHER_IMAGE, PNG_APPLIST_WEATHER_IMAGE, "天气", nullptr}, {VIEW_MUSIC, PNG_APPLIST_MUSIC_IMAGE, PNG_APPLIST_MUSIC_IMAGE, "音乐", nullptr}, diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp index c93c7eeb8..31179d25e 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -12,7 +12,6 @@ #include "ui_resource_image.h" #include "common/image_cache_manager.h" #include - namespace OHOS { static MainClockView *g_pMainClockView = nullptr; @@ -112,24 +111,26 @@ namespace OHOS void MainClockView::InitStepValue() { -#if 0 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue"); - uint32_t stepValue; - int weekToday = ActivityModel::GetInstance()->GetWeekToday(); - ActivityModel::GetInstance()->GetStepData((StepDataDistribute)weekToday, &stepValue); - char stepChar[STEP_CHAR_NUM] = {0}; - if (sprintf_s(stepChar, STEP_CHAR_NUM, "%d", stepValue) == -1) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue error"); - return; - } - if (stepLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue nullptr"); - return; - } - stepLabel->SetText(stepChar); - stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); - stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); - stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); +#if 1 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue"); + uint32_t stepValue; + int weekToday = ActivityModel::GetInstance()->GetWeekToday(); + ActivityModel::GetInstance()->GetStepData((StepDataDistribute)weekToday, &stepValue); + char stepChar[STEP_CHAR_NUM] = {0}; + if (sprintf_s(stepChar, STEP_CHAR_NUM, "%d", stepValue) == -1) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue error"); + return; + } + if (stepLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView::InitStepValue nullptr"); + return; + } + stepLabel->SetText(stepChar); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED); + stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE); #endif } @@ -194,7 +195,7 @@ namespace OHOS bool MainClockView::InitCenterCircleView(void) { -#if 0 +#if 1 bigCircle = new Image(); if (bigCircle == nullptr) { @@ -316,14 +317,13 @@ namespace OHOS } curFace->SetPosition(0, 0); - if (LoadClockImage(curFace, CLOCK_MAIN_FACE_IMAGE) == false) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace LoadClockImage CLOCK_MAIN_FACE_IMAGE fail"); return false; } -#if 0 +#if 1 if (InitLabelView() == false) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelView() fail"); @@ -401,7 +401,6 @@ namespace OHOS return false; } - // UIView::OnLongPressListener* longPressListener = (UIView::OnLongPressListener*)OHOS::MainPresenterSample::GetInstance(); // mainSweepClock->SetOnLongPressListener(longPressListener); @@ -412,15 +411,14 @@ namespace OHOS mainSweepClock->Add(button1_); mainSweepClock->Add(curFace); - /* - mainSweepClock->Add(stepLabel); - mainSweepClock->Add(heartRate); - mainSweepClock->Add(weekLabel); - mainSweepClock->Add(heartRateLabel); - mainSweepClock->Add(weekDay); - mainSweepClock->Add(progress); - mainSweepClock->Add(batteryLabel); - */ + + mainSweepClock->Add(stepLabel); + mainSweepClock->Add(heartRate); + mainSweepClock->Add(weekLabel); + mainSweepClock->Add(heartRateLabel); + mainSweepClock->Add(weekDay); + mainSweepClock->Add(progress); + mainSweepClock->Add(batteryLabel); Add(mainSweepClock); @@ -465,7 +463,7 @@ namespace OHOS void MainClockView::RefreshStep(int step) { -#if 0 +#if 1 char stepChar[STEP_CHAR_NUM] = {0}; (void)sprintf_s(stepChar, STEP_CHAR_NUM, "%d", step); @@ -475,7 +473,7 @@ namespace OHOS void MainClockView::RefreshHeartRate(int value) { -#if 0 +#if 1 if (value == 0) { heartRateLabel->SetText("--"); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h index bf688dc75..09b2bc01c 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h @@ -3,14 +3,15 @@ #include "Presenter.h" #include "DialView.h" +#include "dial/include/Digital_clockView.h" namespace OHOS { class DialView; class DialPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnClickListener, + public UIView::OnDragListener { public: DialPresenter(); @@ -24,6 +25,7 @@ namespace OHOS static DialPresenter *GetInstance(); private: + Digital_clockView *g_pDigital_clockView{nullptr}; // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h index ad03e9638..8dd700d89 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h @@ -1,3 +1,13 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-01-11 18:56:47 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-01-12 15:12:59 + * @FilePath: /1.FD230/FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ #ifndef _Dial_VIEW_H #define _Dial_VIEW_H @@ -40,10 +50,11 @@ namespace OHOS UIViewGroup *container_ = nullptr; UIScrollView *scrollView1_ = nullptr; + + UIButton *button5_ = nullptr; + UIButton *button4_ = nullptr; UIButton *button3_ = nullptr; - UIImageView *image2_ = nullptr; UIButton *button2_ = nullptr; - UIImageView *image1_ = nullptr; UIButton *button1_ = nullptr; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h index 25e534741..60b65563f 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h @@ -31,6 +31,8 @@ extern uint8_t battery_get_voltage(float *voltage); namespace OHOS { + +#define CHANGEBUTTON "changebutton" // 切换表盘按键 class SweepClockCallback : public AnimatorCallback { public: @@ -216,22 +218,23 @@ namespace OHOS void FreeImagePathsArray(const char **imagePaths); const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); void addImageView(int left, int top, const char *imagePath, const char *viewId, int offsetX, int offsetY); - - void Initbackground(); // 初始化背景 - void Initpointer(); // 初始化表盘指针 - void Initdigit(); // 初始化数字表盘 - void Initdata(); // 初始化日期 - void Initweek(); // 初始化星期 - void Initbattery(); // 初始化电量 + bool Initbackground(); + bool Initpointer(); + bool Initdigit(); + bool Initdata(); + bool Initweek(); + bool Initbattery(); + bool AddButton(); void PreLoad(void) override; void UnLoad(void) override; + private: TraingWinView *p_TraingWinView{nullptr}; UIView::OnDragListener *draglistener{nullptr}; Digital_clockView(Digital_clockView &&) = delete; Digital_clockView &operator=(Digital_clockView &&) = delete; - UIViewGroup *container_ = nullptr; + // UIViewGroup *container_ = nullptr; UIImageView *background = nullptr; UIImageView *hour1 = nullptr; UIImageView *hour2 = nullptr; @@ -242,6 +245,7 @@ namespace OHOS UILabel *dateLable = nullptr; UILabel *weekLable = nullptr; UILabel *batteryLable = nullptr; + UIButton *changebutton = nullptr; UIBoxProgress *progress = nullptr; UISweepClock *sweepClock1_ = nullptr; UIImageAnimatorView *backgroundAnimator = nullptr; @@ -258,7 +262,7 @@ namespace OHOS const char **imagePaths; std::string digitspath; std::string stringtime; - std::string JosnfilePath = "/user/res/clocks/KUMI.json"; + std::string JosnfilePath = "/user/res/clocks/default.json"; }; } // namespace OHOS #endif // Digital_clock_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialPresenter.cpp index acd7e9ebb..0cb192063 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialPresenter.cpp @@ -65,12 +65,43 @@ namespace OHOS bool DialPresenter::OnClick(UIView &view, const ClickEvent &event) { - // // 根据控件id查找是哪个控件触发了点击回调 - // if (strcmp(view.GetViewId(), "labelButton1") == 0) - // { - // NativeAbility::GetInstance().ChangeSlice(VIEW_BLOOD); - // } - + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), "kumibutton") == 0) + { + printf("join click\n"); + const std::string jsonPath = "/user/res/clocks/KUMI.json"; + g_pDigital_clockView->setJsonFilePath(jsonPath); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } + if (strcmp(view.GetViewId(), "flowerbudbutton") == 0) + { + printf("join click\n"); + const std::string jsonPath = "/user/res/clocks/flowerbud.json"; + g_pDigital_clockView->setJsonFilePath(jsonPath); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } + if (strcmp(view.GetViewId(), "maomaobutton") == 0) + { + printf("join click\n"); + const std::string jsonPath = "/user/res/clocks/maomao.json"; + g_pDigital_clockView->setJsonFilePath(jsonPath); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } + if (strcmp(view.GetViewId(), "momobutton") == 0) + { + printf("join click\n"); + const std::string jsonPath = "/user/res/clocks/momo.json"; + g_pDigital_clockView->setJsonFilePath(jsonPath); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } + if (strcmp(view.GetViewId(), "maliaobutton") == 0) + { + printf("join click\n"); + const std::string jsonPath = "/user/res/clocks/maliao.json"; + g_pDigital_clockView->setJsonFilePath(jsonPath); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + } return true; } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp index 32bf0c353..d8f36a0c5 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp @@ -53,28 +53,70 @@ namespace OHOS container_->Add(scrollView1_); scrollView1_->SetVisible(true); + // Add Button to App + if (button5_ == nullptr) + { + button5_ = new UIButton(); + } + button5_->SetPosition(-480, 103); // widget's left position and top position + button5_->Resize(260, 260); // widget's width and height + button5_->SetViewId("maliaobutton"); // Set style + button5_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + button5_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + // Set additional property + char *button5defaultImgSrc = "/user/res/clocks/Reducedgraph/maliao.bin"; + char *button5triggeredImgSrc = nullptr; + button5_->SetImageSrc(button5defaultImgSrc, button5triggeredImgSrc); + button5_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + button5_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button5Click = static_cast(DialPresenter::GetInstance()); + button5_->SetOnClickListener(button5Click); + // Add to scrollView1 + scrollView1_->Add(button5_); + button5_->SetVisible(true); + + // Add Button to App + if (button4_ == nullptr) + { + button4_ = new UIButton(); + } + button4_->SetPosition(680, 103); // widget's left position and top position + button4_->Resize(260, 260); // widget's width and height + button4_->SetViewId("momobutton"); // Set style + button4_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + button4_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + // Set additional property + char *button4defaultImgSrc = "/user/res/clocks/Reducedgraph/momo.bin"; + char *button4triggeredImgSrc = nullptr; + button4_->SetImageSrc(button4defaultImgSrc, button4triggeredImgSrc); + button4_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + button4_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button4Click = static_cast(DialPresenter::GetInstance()); + button4_->SetOnClickListener(button4Click); + // Add to scrollView1 + scrollView1_->Add(button4_); + button4_->SetVisible(true); + // Add Button to App if (button3_ == nullptr) { button3_ = new UIButton(); } - button3_->SetPosition(390, 103); // widget's left position and top position - button3_->Resize(260, 260); // widget's width and height - button3_->SetViewId("button3"); // Set style + button3_->SetPosition(390, 103); // widget's left position and top position + button3_->Resize(260, 260); // widget's width and height + button3_->SetViewId("maomaobutton"); // Set style button3_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); button3_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - // Set additional property -#ifdef _WIN32 - char *button3defaultImgSrc = "c:/Users/caiking/project/image_converter_tool/output/Dial/dog.bin"; -#else - char *button3defaultImgSrc = "/user/res/Dial/dog.bin"; -#endif + char *button3defaultImgSrc = "/user/res/clocks/Reducedgraph/maomao.bin"; char *button3triggeredImgSrc = nullptr; button3_->SetImageSrc(button3defaultImgSrc, button3triggeredImgSrc); button3_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); button3_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - // Add the CallBack about events UIView::OnClickListener *button3Click = static_cast(DialPresenter::GetInstance()); button3_->SetOnClickListener(button3Click); @@ -82,43 +124,23 @@ namespace OHOS scrollView1_->Add(button3_); button3_->SetVisible(true); - // Add ImageView to App - if (image2_ == nullptr) - { - image2_ = new UIImageView(); - } - image2_->SetPosition(691, 172); // widget's left position and top position - image2_->Resize(100, 100); // widget's width and height - image2_->SetViewId("image2"); // Set style - - // Set additional property - - // Add to scrollView1 - scrollView1_->Add(image2_); - image2_->SetVisible(true); - // Add Button to App if (button2_ == nullptr) { button2_ = new UIButton(); } - button2_->SetPosition(-190, 103); // widget's left position and top position - button2_->Resize(260, 260); // widget's width and height - button2_->SetViewId("button2"); // Set style + button2_->SetPosition(-190, 103); // widget's left position and top position + button2_->Resize(260, 260); // widget's width and height + button2_->SetViewId("flowerbudbutton"); // Set style button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); button2_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); // Set additional property -#ifdef _WIN32 - char *button2defaultImgSrc = "c:/Users/caiking/project/image_converter_tool/output/Dial/Malio.bin"; -#else - char *button2defaultImgSrc = "/user/res/Dial/Malio.bin"; -#endif + char *button2defaultImgSrc = "/user/res/clocks/Reducedgraph/flowerbud.bin"; char *button2triggeredImgSrc = nullptr; button2_->SetImageSrc(button2defaultImgSrc, button2triggeredImgSrc); button2_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); button2_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - // Add the CallBack about events UIView::OnClickListener *button2Click = static_cast(DialPresenter::GetInstance()); button2_->SetOnClickListener(button2Click); @@ -126,38 +148,18 @@ namespace OHOS scrollView1_->Add(button2_); button2_->SetVisible(true); - // Add ImageView to App - if (image1_ == nullptr) - { - image1_ = new UIImageView(); - } - image1_->SetPosition(-343, 183); // widget's left position and top position - image1_->Resize(100, 100); // widget's width and height - image1_->SetViewId("image1"); // Set style - - // Set additional property - - // Add to scrollView1 - scrollView1_->Add(image1_); - image1_->SetVisible(true); - // Add Button to App if (button1_ == nullptr) { button1_ = new UIButton(); } - button1_->SetPosition(103, 103); // widget's left position and top position - button1_->Resize(260, 260); // widget's width and height - button1_->SetViewId("button1"); // Set style + button1_->SetPosition(103, 103); // widget's left position and top position + button1_->Resize(260, 260); // widget's width and height + button1_->SetViewId("kumibutton"); // Set style button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - // Set additional property -#ifdef _WIN32 - char *button1defaultImgSrc = "c:/Users/caiking/project/image_converter_tool/output/Dial/KUMI.bin"; -#else - char *button1defaultImgSrc = "/user/res/Dial/KUMI.bin"; -#endif + char *button1defaultImgSrc = "/user/res/clocks/Reducedgraph/KUMI.bin"; char *button1triggeredImgSrc = nullptr; button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); @@ -165,6 +167,7 @@ namespace OHOS // Add the CallBack about events UIView::OnClickListener *button1Click = static_cast(DialPresenter::GetInstance()); + button1_->SetOnClickListener(button1Click); // Add to scrollView1 scrollView1_->Add(button1_); button1_->SetVisible(true); @@ -183,26 +186,26 @@ namespace OHOS delete scrollView1_; scrollView1_ = nullptr; } + if (button5_ != nullptr) + { + delete button5_; + button5_ = nullptr; + } + if (button4_ != nullptr) + { + delete button4_; + button4_ = nullptr; + } if (button3_ != nullptr) { delete button3_; button3_ = nullptr; } - if (image2_ != nullptr) - { - delete image2_; - image2_ = nullptr; - } if (button2_ != nullptr) { delete button2_; button2_ = nullptr; } - if (image1_ != nullptr) - { - delete image1_; - image1_ = nullptr; - } if (button1_ != nullptr) { delete button1_; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp index ef58e1a87..7dbc6cd99 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp @@ -1,16 +1,15 @@ -/* +/*** * @Author: Caisking 3449750381@qq.com * @Date: 2024-01-02 11:23:34 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-01-11 10:08:21 + * @LastEditTime: 2024-01-11 10:48:05 * @FilePath: /1.FD230/FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp - * @Description: - * - * Copyright (c) 2024 by Caisking , All Rights Reserved. + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. */ #include "dial/include/Digital_clockView.h" - #include "common/image_cache_manager.h" #include "components/ui_view_group.h" #include "UiConfig.h" @@ -35,15 +34,47 @@ namespace OHOS { cJSON *cjson_json = NULL; + /*** + * @description: + * @param {string} &filePath + * @return 设置json文件 + */ void Digital_clockView::setJsonFilePath(const std::string &filePath) { - JosnfilePath = filePath; + PRINT_DEBUG_INFO + std::string defaultFile = "/user/res/clocks/default.json"; + std::ifstream sourceFile(filePath, std::ios::binary); // 打开源文件 + std::ofstream targetFile(defaultFile, std::ios::binary | std::ios::trunc); // 打开目标文件,使用trunc标志来覆盖目标文件 + printf("%s|%s\n", defaultFile.c_str(), filePath.c_str()); // 使用c_str()将std::string转换为C风格字符串 + if (sourceFile && targetFile) + { + char buffer[1024]; // 缓冲区 + while (sourceFile.read(buffer, sizeof(buffer)) || sourceFile.gcount()) + { + targetFile.write(buffer, sourceFile.gcount()); + } + if (sourceFile.eof()) + { + printf("File overwrite success\n"); // 使用printf打印成功消息 + return; // 返回true表示文件拷贝成功 + } + else + { + fprintf(stderr, "File overwrite failed\n"); // 使用fprintf打印错误消息 + } + } + else + { + fprintf(stderr, "Unable to open file\n"); // 使用fprintf打印错误消息 + } + sourceFile.close(); + targetFile.close(); } /** * @description: 加载json文件 * @param {string} &filePath - * @return {*} - */ + * @return 加载json文件是否成功 + */ bool loadJsonData(const std::string &filePath) { @@ -82,7 +113,7 @@ namespace OHOS * @param {char} *basePath * @param {char} *fileExtension * @param {int} numImages - * @return {*} + * @return 动画的资源路径数组 */ const char **Digital_clockView::CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages) { @@ -98,10 +129,10 @@ namespace OHOS imagePaths[numImages] = reinterpret_cast(numImages); // 将数组大小信息存储在最后一个元素中 return imagePaths; } - /** - * @description: 释放动画路径数组 - * @param {char} * - * @return {*} + /*** + * @description: 删除动画资源路径数组 + * @param {char} *imagePaths 动画资源路径数组 + * @return */ void Digital_clockView::FreeImagePathsArray(const char **imagePaths) { @@ -115,7 +146,7 @@ namespace OHOS /** * @description: 判断路径是否为文件夹 * @param {string} &path - * @return {*} + * @return 路径是否为文件夹 */ bool isDirectory(const std::string &path) { @@ -127,9 +158,9 @@ namespace OHOS } /** * @description: 初始化背景 - * @return {*} + * @return 初始化背景是否成功 */ - void Digital_clockView::Initbackground() + bool Digital_clockView::Initbackground() { // 初始化背景 if (background == nullptr) @@ -180,10 +211,11 @@ namespace OHOS } } // 增加背景 - container_->Add(background); - background->SetVisible(true); + Add(background); + return true; + // background->SetVisible(true); } - + /** * @description: 初始化数字图片 * @param {int} left @@ -192,8 +224,8 @@ namespace OHOS * @param {char} *viewId * @param {int} offsetX * @param {int} offsetY - * @return {*} - */ + * @return + */ void Digital_clockView::addImageView(int left, int top, const char *imagePath, const char *viewId, int offsetX, int offsetY) { UIImageView *imageView = new UIImageView(); @@ -201,22 +233,22 @@ namespace OHOS imageView->Resize(100, 100); imageView->SetViewId(viewId); imageView->SetSrc(imagePath); - container_->Add(imageView); - imageView->SetVisible(true); + Add(imageView); + // imageView->SetVisible(true); } /** * @description: 初始化数字表盘 - * @return {*} - */ - void Digital_clockView ::Initdigit() + * @return 初始化数字表盘是否成功 + */ + bool Digital_clockView ::Initdigit() { cJSON *background_cjson = cJSON_GetObjectItem(cjson_json, "background"); std::string backgroundimagesPath = cJSON_GetObjectItem(background_cjson, "backgroundimagesPath")->valuestring; if (isDirectory(backgroundimagesPath)) { backgroundAnimator->Start(); - container_->Add(backgroundAnimator); - backgroundAnimator->SetVisible(true); + Add(backgroundAnimator); + // backgroundAnimator->SetVisible(true); } stringtime = "11:54"; // updateClockTime(stringtime); @@ -237,8 +269,11 @@ namespace OHOS addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(3, 1) + ".bin").c_str(), "minute1", digitsize * 3, 0); addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(4, 1) + ".bin").c_str(), "minute2", digitsize * 4, 0); printf("--%s--\n", digitspath.c_str()); - mytimeimageCallback_ = new mytimeimageCallback(hour1, hour2, minute1, minute2, digitspath, stringtime); - timeimageanimator_ = new Animator(mytimeimageCallback_, container_, 10000, true); + if (mytimeimageCallback_ == nullptr) + { + mytimeimageCallback_ = new mytimeimageCallback(hour1, hour2, minute1, minute2, digitspath, stringtime); + timeimageanimator_ = new Animator(mytimeimageCallback_, minute2, 10000, true); + } // callback.mytimeimageCallback("14:57"); // timeimageanimator_->Start(); } @@ -267,19 +302,23 @@ namespace OHOS timeLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, digitsize); // Add to rootView - container_->Add(timeLable); - timeLable->SetVisible(true); + Add(timeLable); + // timeLable->SetVisible(true); - timeLableCallback_ = new timeLableCallback(timeLable, stringtime); - timeLableanimator_ = new Animator(timeLableCallback_, timeLable, 1000, true); + if (timeLableCallback_ == nullptr) + { + timeLableCallback_ = new timeLableCallback(timeLable, stringtime); + timeLableanimator_ = new Animator(timeLableCallback_, timeLable, 1000, true); + } timeLableanimator_->Start(); } + return true; } /** * @description: 初始化指针表盘 - * @return {*} - */ - void Digital_clockView::Initpointer() + * @return: 初始化指针表盘是否成功 + */ + bool Digital_clockView::Initpointer() { cJSON *hands = cJSON_GetObjectItem(cjson_json, "hands"); cJSON *hourHand = cJSON_GetObjectItem(hands, "hourHand"); @@ -339,14 +378,15 @@ namespace OHOS sweepClock1animator_ = new Animator(sweepClock1callback_, sweepClock1_, 0, true); sweepClock1animator_->Start(); // Add to rootView - container_->Add(sweepClock1_); - sweepClock1_->SetVisible(true); + Add(sweepClock1_); + return true; + // sweepClock1_->SetVisible(true); } /** * @description: 获取格式化日期,根据不同的日期格式获取 * @param {string} &dateStr * @param {string} &displayformat - * @return {*} + * @return 格式化日期 */ std::string FormatDate(const std::string &dateStr, const std::string &displayformat) { @@ -371,14 +411,13 @@ namespace OHOS } // 添加其他显示格式的处理逻辑 - return formattedDate; } /** * @description: 初始化日期 - * @return {*} - */ - void Digital_clockView ::Initdata() + * @return 初始化日期是否成功 + */ + bool Digital_clockView ::Initdata() { // loadJsonData(JosnfilePath); cJSON *date = cJSON_GetObjectItem(cjson_json, "date"); @@ -412,14 +451,15 @@ namespace OHOS dateLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontsize); // Add to rootView - container_->Add(dateLable); - dateLable->SetVisible(true); + Add(dateLable); + return true; + // dateLable->SetVisible(true); }; /** * @description: 初始化星期 - * @return {*} - */ - void Digital_clockView ::Initweek() + * @return 初始化星期是否成功 + */ + bool Digital_clockView ::Initweek() { // loadJsonData(JosnfilePath); cJSON *week = cJSON_GetObjectItem(cjson_json, "week"); @@ -458,14 +498,15 @@ namespace OHOS weekLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontsize); // Add to rootView - container_->Add(weekLable); - weekLable->SetVisible(true); + Add(weekLable); + return true; + // weekLable->SetVisible(true); }; /** * @description: 初始化电量 - * @return {*} - */ - void Digital_clockView ::Initbattery() + * @return 初始化电量是否成功 + */ + bool Digital_clockView ::Initbattery() { // loadJsonData(JosnfilePath); cJSON *battery = cJSON_GetObjectItem(cjson_json, "battery"); @@ -508,8 +549,8 @@ namespace OHOS char *progress1BackImageSrc = nullptr; progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc); // Add to rootView - container_->Add(progress); - progress->SetVisible(true); + Add(progress); + // progress->SetVisible(true); // Add Label to App if (batteryLable == nullptr) @@ -529,23 +570,51 @@ namespace OHOS batteryLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontsize); // Add to rootView - container_->Add(batteryLable); - batteryLable->SetVisible(true); + Add(batteryLable); + // batteryLable->SetVisible(true); progress1callback_ = new myProgressCallback(progress, batteryLable); progress1animator_ = new Animator(progress1callback_, progress, 10000, true); progress1animator_->Start(); + return true; }; + /*** + * @description: 添加切换界面按键 + * @return 添加按键是否成功 + */ + bool Digital_clockView ::AddButton() + { + PRINT_DEBUG_INFO + // Add Button to App + if (changebutton == nullptr) + { + changebutton = new UIButton(); + } + changebutton->SetPosition(0, 0); // widget's left position and top position + changebutton->Resize(466, 466); // widget's width and height + changebutton->SetViewId(CHANGEBUTTON); // Set style + changebutton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + changebutton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + PRINT_DEBUG_INFO + // Set additional property + changebutton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + changebutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + PRINT_DEBUG_INFO + // Add the CallBack about events + UIView::OnLongPressListener *buttonLongPress = static_cast(MainPresenterSample::GetInstance()); + changebutton->SetOnLongPressListener(buttonLongPress); + // Add to rootView + Add(changebutton); + PRINT_DEBUG_INFO + return true; + } /** * @description: 初始化页面 - * @return {*} - */ + * @return 初始化页面是否成功 + */ bool Digital_clockView ::InitView() { - container_ = new UIViewGroup(); - container_->SetPosition(0, 0); - container_->SetWidth(Screen::GetInstance().GetWidth()); - container_->SetHeight(Screen::GetInstance().GetHeight()); + PRINT_DEBUG_INFO if (loadJsonData(JosnfilePath)) { std::string Dialtype = cJSON_GetObjectItem(cjson_json, "Dialtype")->valuestring; @@ -562,31 +631,44 @@ namespace OHOS Initdata(); Initweek(); Initbattery(); + AddButton(); cJSON_Delete(cjson_json); } - - Add(container_); - + // Add(container_); SetCoverable(true); PRINT_DEBUG_INFO return true; } - /* DeInit:删除组件*/ + /** + * @description: 删除组件 + * @return {*} + */ void Digital_clockView::DeInit() { - UIView *view = static_cast(container_)->GetChildrenHead(); - while (view != nullptr) - { - - UIView *tempView = view; - view = view->GetNextSibling(); - if (tempView->GetParent()) - { - static_cast(tempView->GetParent())->Remove(tempView); - } - delete tempView; - } - /********************************************/ + /* -------------------------------------------------------------------------- */ + delete background; + background = nullptr; + delete hour1; + hour1 = nullptr; + delete hour2; + hour2 = nullptr; + delete colon; + colon = nullptr; + delete minute1; + minute1 = nullptr; + delete minute2; + minute2 = nullptr; + delete timeLable; + timeLable = nullptr; + delete dateLable; + dateLable = nullptr; + delete weekLable; + weekLable = nullptr; + delete batteryLable; + batteryLable = nullptr; + delete progress; + progress = nullptr; + /* -------------------------------------------------------------------------- */ if (timeLableanimator_ != nullptr) { timeLableanimator_->Stop(); @@ -598,7 +680,7 @@ namespace OHOS delete timeLableCallback_; timeLableCallback_ = nullptr; } - /********************************************/ + /* -------------------------------------------------------------------------- */ if (mytimeimageCallback_ != nullptr) { delete mytimeimageCallback_; @@ -610,7 +692,7 @@ namespace OHOS delete timeimageanimator_; timeimageanimator_ = nullptr; } - /********************************************/ + /* -------------------------------------------------------------------------- */ if (progress1callback_ != nullptr) { delete progress1callback_; @@ -622,7 +704,7 @@ namespace OHOS delete progress1animator_; progress1animator_ = nullptr; } - /********************************************/ + /* -------------------------------------------------------------------------- */ if (sweepClock1callback_ != nullptr) { delete sweepClock1callback_; @@ -634,15 +716,13 @@ namespace OHOS delete sweepClock1animator_; sweepClock1animator_ = nullptr; } - /********************************************/ + /* -------------------------------------------------------------------------- */ if (backgroundAnimator != nullptr) { backgroundAnimator->Stop(); delete backgroundAnimator; backgroundAnimator = nullptr; } - delete container_; - container_ = nullptr; } void Digital_clockView::PreLoad(void) @@ -656,4 +736,5 @@ namespace OHOS void Digital_clockView::UnLoad(void) { } + } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp index fc3003899..c393ecb36 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp @@ -143,7 +143,7 @@ namespace OHOS string curViewId = view.GetViewId(); //int page = MainViewSample::GetInstance()->GetHorCurrentPage(); //callback_->OnSwipe(view); - if(curViewId== "button1") + if(curViewId== CHANGEBUTTON) { NativeAbility::GetInstance().ChangeSlice(VIEW_DIAL); return true; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp index 21b71039b..a56a7012c 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp @@ -253,7 +253,6 @@ void MainViewSample::OnStop() UICardPage *MainViewSample::InitWatchFacePage(void) { - mainClockView = new MainClockView(); if (mainClockView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h index 16dbd20ed..0763f7388 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h @@ -1,3 +1,13 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2023-12-15 14:33:22 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-01-11 19:29:58 + * @FilePath: /1.FD230/FD230/code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: ScreenModels diff --git a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp index 19b4d6b7f..cffb6433c 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp @@ -176,7 +176,7 @@ bool ScreenModels::LoadAppImages(std::string file, UIImageView *view, uint32_t r void ScreenModels::PreLoadAppimages(void) { LoadAppMultiImages(PLAYER_IAMGES, PLAYER_BACKGROUND, PLAYER_PLAYING); - LoadAppMultiImages(DIAL_CLOCK, CLOCK_HAND24HOUR_IMAGE_PATH, CLOCK_TUESDAY_IMAGE_PATH); + //LoadAppMultiImages(DIAL_CLOCK, CLOCK_HAND24HOUR_IMAGE_PATH, CLOCK_TUESDAY_IMAGE_PATH); //LoadAppMultiImages(CLOCK_IAMGES, CLOCK_HAND24HOUR_IMAGE_PATH, CLOCK_TUESDAY_IMAGE_PATH); LoadAppMultiImages(COMPASS_IAMGES, COMPASS_COMPASS0, COMPASS_START_PATH_RECORD); LoadAppMultiImages(DROPDOWN_IAMGES, DROPDOWN_DROPDOWN_BLUETOOTH, DROPDOWN_DROPDOWN_BRI_SCREEN_B); diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/KUMI.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/KUMI.bin new file mode 100644 index 000000000..6c6260582 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/KUMI.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/flowerbud.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/flowerbud.bin new file mode 100644 index 000000000..330cf7c1d Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/flowerbud.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/maliao.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/maliao.bin new file mode 100644 index 000000000..3c2ba112f Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/maliao.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/maomao.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/maomao.bin new file mode 100644 index 000000000..784adbe27 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/maomao.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/momo.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/momo.bin new file mode 100644 index 000000000..f84214ceb Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/Reducedgraph/momo.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/default.json b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/default.json new file mode 100644 index 000000000..23fb79470 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/default.json @@ -0,0 +1,71 @@ +{ + "Dialtype": "digits", + "digitspath": "/user/res/clocks/KUMI/", + "digits": { + "timeformat": "24format", + "digitsize": 60, + "playformat": "textdisplay", + "fontsize": 55, + "textdisplay": { + "coordinates": { + "left": 161, + "top": 293 + } + } + }, + "date": { + "textdisplay": { + "displayformat": "dd", + "font": "STYLE_TEXT_FONT", + "fontsize": 35, + "coordinates": { + "left": 250, + "top": 365 + } + } + }, + "week": { + "textdisplay": { + "displayformat": { + "weekformat": [ + "Mon ", + "Tue ", + "Wed ", + "Thu ", + "Fri ", + "Sat ", + "Sun" + ] + }, + "fontsize": 35, + "coordinates": { + "left": 181, + "top": 365 + } + } + }, + "battery": { + "progress": { + "size": { + "width": 31, + "height": 19 + }, + "coordinates": { + "left": 180, + "top": 30 + } + }, + "textdisplay": { + "fontsize": 28, + "coordinates": { + "left": 220, + "top": 25 + } + } + }, + "heartrate": {}, + "step": {}, + "background": { + "backgroundimagesPath": "/user/res/clocks/KUMI/background.bin" + } +} \ No newline at end of file diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/maliao.json b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/maliao.json index 4e02537f4..5de64a6ff 100644 --- a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/maliao.json +++ b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/clocks/maliao.json @@ -3,8 +3,7 @@ "digitspath": "/user/res/clocks/maliao/", "digits": { "timeformat": "24format", - "displayformat": "picturesdisplay", - "digitspath": "/user/res/clocks/maliao/", + "playformat": "picturesdisplay", "digitsize": 40, "picturesdisplay": { "coordinates": { diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_view.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_view.cpp index 9e18ed2ad..16a5cbb01 100755 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_view.cpp @@ -476,7 +476,7 @@ void UIImageView::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) void UIImageView::SetSrc(const char* src) { - printf("Function: %s, Line: %d\n", __PRETTY_FUNCTION__, __LINE__); + //printf("Function: %s, Line: %d\n", __PRETTY_FUNCTION__, __LINE__); #ifndef VERSION_LITE if (src == nullptr) { return;