* @Date: 2024-04-15 10:55:58
* @LastEditors: Caisking 3449750381@qq.com
* @LastEditTime: 2024-08-09 14:41:32
- * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockView.cpp
+ * @FilePath:
+ * /FD230/code/sdk/application/wearable/fd230app/nativeui/codedlock/src/CodedLockView.cpp
*/
#include "codedlock/include/CodedLockView.h"
#include "codedlock/include/CodedLockPresenter.h"
-#include "common/image_cache_manager.h"
#include "UiConfig.h"
-#include "ui_resource_image.h"
+#include "common/image_cache_manager.h"
#include "components/ui_button.h"
-#include "uicomponents/UIComponents.h"
-#include "ui_resource_string.h"
#include "components/ui_scroll_view.h"
+#include "ui_resource_image.h"
+#include "ui_resource_string.h"
+#include "uicomponents/UIComponents.h"
-namespace OHOS
-{
+namespace OHOS {
- static CodedLockView *g_pCodedLockView{nullptr};
+static CodedLockView *g_pCodedLockView{nullptr};
- static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
+static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6;
- // 定义默认颜色和激活颜色
- static const uint32_t activeColor = 0xffaaaaaa;
- static const uint32_t defaultColor = 0xff191919;
+// 定义默认颜色和激活颜色
+static const uint32_t activeColor = 0xffaaaaaa;
+static const uint32_t defaultColor = 0xff191919;
#define UI_IMAGE_TEST 1
- CodedLockView::CodedLockView()
- {
- g_pCodedLockView = this;
- }
+CodedLockView::CodedLockView() { g_pCodedLockView = this; }
- CodedLockView::~CodedLockView()
- {
- UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(container_);
- UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
- g_pCodedLockView = nullptr;
- }
+CodedLockView::~CodedLockView() {
+ UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(container_);
+ UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
+ g_pCodedLockView = nullptr;
+}
- CodedLockView *CodedLockView::GetInstance()
- {
- return g_pCodedLockView;
- }
+CodedLockView *CodedLockView::GetInstance() { return g_pCodedLockView; }
- void CodedLockView::InitButtonsView()
- {
- // 第一行
- InitLabelButton(button_one, 30, 90, 130, 88, LOCK_BUTTON_ONE, "1", 40);
- button_one->SetOnClickListener(presenter_);
- container_->Add(button_one);
-
- InitLabelButton(button_two, 168, 90, 130, 88, LOCK_BUTTON_TWO, "2", 40);
- button_two->SetOnClickListener(presenter_);
- container_->Add(button_two);
-
- InitLabelButton(button_three, 305, 90, 130, 88, LOCK_BUTTON_THREE, "3", 40);
- button_three->SetOnClickListener(presenter_);
- container_->Add(button_three);
-
- // 第二行
- InitLabelButton(button_four, 30, 185, 130, 88, LOCK_BUTTON_FOUR, "4", 40);
- button_four->SetOnClickListener(presenter_);
- container_->Add(button_four);
-
- InitLabelButton(button_five, 168, 185, 130, 88, LOCK_BUTTON_FIVE, "5", 40);
- button_five->SetOnClickListener(presenter_);
- container_->Add(button_five);
-
- InitLabelButton(button_six, 305, 185, 130, 88, LOCK_BUTTON_SIX, "6", 40);
- button_six->SetOnClickListener(presenter_);
- container_->Add(button_six);
-
- // 第三行
- InitLabelButton(button_seven, 30, 280, 130, 88, LOCK_BUTTON_SEVEN, "7", 40);
- button_seven->SetOnClickListener(presenter_);
- container_->Add(button_seven);
-
- InitLabelButton(button_eight, 168, 280, 130, 88, LOCK_BUTTON_EIGHT, "8", 40);
- button_eight->SetOnClickListener(presenter_);
- container_->Add(button_eight);
-
- InitLabelButton(button_nine, 305, 280, 130, 88, LOCK_BUTTON_NINE, "9", 40);
- button_nine->SetOnClickListener(presenter_);
- container_->Add(button_nine);
-
- // 第四行 (0)
- InitLabelButton(button_zero, 168, 375, 130, 88, LOCK_BUTTON_ZERO, "0", 40);
- button_zero->SetOnClickListener(presenter_);
- container_->Add(button_zero);
-
- // InitLabelButton(button_delete, 230, 390, 130, 88, LOCK_BUTTON_DELETE, " ", 40);
- // button_delete->SetOnClickListener(presenter_);
- // container_->Add(button_delete);
- }
- void CodedLockView::InitImagesView()
- {
- std::vector<PointConfig> points = {
- {&point_one, 140, 55, "image1", defaultColor, 0xff, 100},
- {&point_two, 175, 55, "image1", defaultColor, 0xff, 100},
- {&point_three, 210, 55, "image1", defaultColor, 0xff, 100},
- {&point_four, 245, 55, "image1", defaultColor, 0xff, 100},
- {&point_five, 280, 55, "image1", defaultColor, 0xff, 100},
- {&point_six, 310, 55, "image1", defaultColor, 0xff, 100},
- };
-
- for (const auto &config : points)
- {
- InitializePoint(config.imageView, config.x, config.y, (config.viewId).c_str(), config.backgroundColor, config.backgroundOpa, config.borderRadius);
- }
- }
+void CodedLockView::InitButtonsView() {
+ // 第一行
+ InitLabelButton(button_one, 30, 90, 130, 88, LOCK_BUTTON_ONE, "1", 40);
+ button_one->SetOnClickListener(presenter_);
+ container_->Add(button_one);
- void CodedLockView::InitializePoint(UIImageView **imageView, int x, int y, const char *viewId, uint32_t backgroundColor, uint8_t backgroundOpa, int borderRadius)
- {
- if (*imageView == nullptr)
- {
- *imageView = new UIImageView();
- }
-
- (*imageView)->SetPosition(x, y);
- (*imageView)->Resize(20, 20);
- (*imageView)->SetViewId(viewId);
- (*imageView)->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor);
- (*imageView)->SetStyle(STYLE_BACKGROUND_OPA, backgroundOpa);
- (*imageView)->SetStyle(STYLE_BORDER_RADIUS, borderRadius);
-
- container_->Add(*imageView);
- }
- void CodedLockView::UpdatePointShow(int num)
- {
+ InitLabelButton(button_two, 168, 90, 130, 88, LOCK_BUTTON_TWO, "2", 40);
+ button_two->SetOnClickListener(presenter_);
+ container_->Add(button_two);
+
+ InitLabelButton(button_three, 305, 90, 130, 88, LOCK_BUTTON_THREE, "3", 40);
+ button_three->SetOnClickListener(presenter_);
+ container_->Add(button_three);
+
+ // 第二行
+ InitLabelButton(button_four, 30, 185, 130, 88, LOCK_BUTTON_FOUR, "4", 40);
+ button_four->SetOnClickListener(presenter_);
+ container_->Add(button_four);
+
+ InitLabelButton(button_five, 168, 185, 130, 88, LOCK_BUTTON_FIVE, "5", 40);
+ button_five->SetOnClickListener(presenter_);
+ container_->Add(button_five);
+
+ InitLabelButton(button_six, 305, 185, 130, 88, LOCK_BUTTON_SIX, "6", 40);
+ button_six->SetOnClickListener(presenter_);
+ container_->Add(button_six);
+
+ // 第三行
+ InitLabelButton(button_seven, 30, 280, 130, 88, LOCK_BUTTON_SEVEN, "7", 40);
+ button_seven->SetOnClickListener(presenter_);
+ container_->Add(button_seven);
+
+ InitLabelButton(button_eight, 168, 280, 130, 88, LOCK_BUTTON_EIGHT, "8", 40);
+ button_eight->SetOnClickListener(presenter_);
+ container_->Add(button_eight);
- if (point_one == nullptr || point_two == nullptr || point_three == nullptr ||
- point_four == nullptr || point_five == nullptr || point_six == nullptr)
- return;
+ InitLabelButton(button_nine, 305, 280, 130, 88, LOCK_BUTTON_NINE, "9", 40);
+ button_nine->SetOnClickListener(presenter_);
+ container_->Add(button_nine);
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdatePointShow Num %d", num);
+ // 第四行 (0)
+ InitLabelButton(button_zero, 168, 375, 130, 88, LOCK_BUTTON_ZERO, "0", 40);
+ button_zero->SetOnClickListener(presenter_);
+ container_->Add(button_zero);
+
+ // InitLabelButton(button_delete, 230, 390, 130, 88, LOCK_BUTTON_DELETE, " ",
+ // 40); button_delete->SetOnClickListener(presenter_);
+ // container_->Add(button_delete);
+}
+void CodedLockView::InitImagesView() {
+ std::vector<PointConfig> points = {
+ {&point_one, 140, 55, "image1", defaultColor, 0xff, 100},
+ {&point_two, 175, 55, "image1", defaultColor, 0xff, 100},
+ {&point_three, 210, 55, "image1", defaultColor, 0xff, 100},
+ {&point_four, 245, 55, "image1", defaultColor, 0xff, 100},
+ {&point_five, 280, 55, "image1", defaultColor, 0xff, 100},
+ {&point_six, 310, 55, "image1", defaultColor, 0xff, 100},
+ };
+
+ for (const auto &config : points) {
+ InitializePoint(config.imageView, config.x, config.y,
+ (config.viewId).c_str(), config.backgroundColor,
+ config.backgroundOpa, config.borderRadius);
+ }
+}
+
+void CodedLockView::InitializePoint(UIImageView **imageView, int x, int y,
+ const char *viewId,
+ uint32_t backgroundColor,
+ uint8_t backgroundOpa, int borderRadius) {
+ if (*imageView == nullptr) {
+ *imageView = new UIImageView();
+ }
+
+ (*imageView)->SetPosition(x, y);
+ (*imageView)->Resize(20, 20);
+ (*imageView)->SetViewId(viewId);
+ (*imageView)->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor);
+ (*imageView)->SetStyle(STYLE_BACKGROUND_OPA, backgroundOpa);
+ (*imageView)->SetStyle(STYLE_BORDER_RADIUS, borderRadius);
+
+ container_->Add(*imageView);
+}
+void CodedLockView::UpdatePointShow(int num) {
+
+ if (point_one == nullptr || point_two == nullptr || point_three == nullptr ||
+ point_four == nullptr || point_five == nullptr || point_six == nullptr)
+ return;
+
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdatePointShow Num %d", num);
#if UI_IMAGE_TEST
- switch (num)
- {
- case 0:
- point_one->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
- point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
- point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
- point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
- point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
- point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
- break;
- case 1:
- point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- break;
- case 2:
- point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- break;
- case 3:
- point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- break;
- case 4:
- point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- break;
- case 5:
- point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- break;
- case 6:
- point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- point_six->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- break;
- default:
- break;
- }
+ switch (num) {
+ case 0:
+ point_one->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ break;
+ case 1:
+ point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_two->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ break;
+ case 2:
+ point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_three->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ break;
+ case 3:
+ point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_four->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ break;
+ case 4:
+ point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_five->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ break;
+ case 5:
+ point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_six->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ break;
+ case 6:
+ point_one->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_two->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_three->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_four->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_five->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ point_six->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ break;
+ default:
+ break;
+ }
#else
- // 更新所有点的颜色
- for (int i = 1; i <= 6; ++i)
- {
- UIImageView *point = nullptr;
- switch (i)
- {
- case 1:
- point = point_one;
- break;
- case 2:
- point = point_two;
- break;
- case 3:
- point = point_three;
- break;
- case 4:
- point = point_four;
- break;
- case 5:
- point = point_five;
- break;
- case 6:
- point = point_six;
- break;
- default:
- continue;
- }
-
- if (point != nullptr)
- {
- if (i <= num)
- {
- // 如果是前 num 个点,则设置为激活颜色
- point->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
- }
- else
- {
- // 其他点设置为默认颜色
- point->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
- }
- }
- }
-#endif
- /*ui刷新*/
- point_one->Invalidate();
- point_two->Invalidate();
- point_three->Invalidate();
- point_four->Invalidate();
- point_five->Invalidate();
- point_six->Invalidate();
+ // 更新所有点的颜色
+ for (int i = 1; i <= 6; ++i) {
+ UIImageView *point = nullptr;
+ switch (i) {
+ case 1:
+ point = point_one;
+ break;
+ case 2:
+ point = point_two;
+ break;
+ case 3:
+ point = point_three;
+ break;
+ case 4:
+ point = point_four;
+ break;
+ case 5:
+ point = point_five;
+ break;
+ case 6:
+ point = point_six;
+ break;
+ default:
+ continue;
}
- void CodedLockView::OnStart()
- {
- View<CodedLockPresenter>::OnStart();
-
- container_ = new UIScrollView();
- if (container_ == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail");
- return;
- }
- container_->SetScrollBlankSize(35);
- container_->SetReboundSize(50);
- container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-
- container_->SetTouchable(false);
- container_->SetDraggable(false);
- container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
- container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
-
- InitButtonsView();
- InitImagesView();
-
- SetContainerView(container_);
+ if (point != nullptr) {
+ if (i <= num) {
+ // 如果是前 num 个点,则设置为激活颜色
+ point->SetStyle(STYLE_BACKGROUND_COLOR, activeColor);
+ } else {
+ // 其他点设置为默认颜色
+ point->SetStyle(STYLE_BACKGROUND_COLOR, defaultColor);
+ }
}
+ }
+#endif
+ /*ui刷新*/
+ point_one->Invalidate();
+ point_two->Invalidate();
+ point_three->Invalidate();
+ point_four->Invalidate();
+ point_five->Invalidate();
+ point_six->Invalidate();
+}
- void CodedLockView::OnSetUpView()
- {
- View<CodedLockPresenter>::OnSetUpView();
- Draw();
- }
+void CodedLockView::OnStart() {
+ View<CodedLockPresenter>::OnStart();
- void CodedLockView::OnTearDownView()
- {
- View<CodedLockPresenter>::OnTearDownView();
- return;
- }
+ container_ = new UIScrollView();
+ if (container_ == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail");
+ return;
+ }
+ container_->SetScrollBlankSize(35);
+ container_->SetReboundSize(50);
+ container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
+ Screen::GetInstance().GetHeight());
- void CodedLockView::OnStop()
- {
- View<CodedLockPresenter>::OnStop();
- if (container_ != nullptr)
- {
- container_->RemoveAll();
- delete container_;
- container_ = nullptr;
- }
- RootView::GetInstance()->RemoveAll();
- return;
- }
+ container_->SetTouchable(false);
+ container_->SetDraggable(false);
+ container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);
+ container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+
+ InitButtonsView();
+ InitImagesView();
+
+ SetContainerView(container_);
+}
+
+void CodedLockView::OnSetUpView() {
+ View<CodedLockPresenter>::OnSetUpView();
+ Draw();
+}
+
+void CodedLockView::OnTearDownView() {
+ View<CodedLockPresenter>::OnTearDownView();
+ return;
+}
+
+void CodedLockView::OnStop() {
+ View<CodedLockPresenter>::OnStop();
+ if (container_ != nullptr) {
+ container_->RemoveAll();
+ delete container_;
+ container_ = nullptr;
+ }
+ RootView::GetInstance()->RemoveAll();
+ return;
}
+} // namespace OHOS