2 * @Author: luozheng 1732036298@qq.com
3 * @Date: 2024-04-23 17:28:52
4 * @LastEditors: luozheng 1732036298@qq.com
5 * @LastEditTime: 2024-11-05 14:24:02
6 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionView.cpp
8 #include "motionrecognition/include/MotionRecognitionPresenter.h"
9 #include "motionrecognition/include/MotionRecognitionView.h"
10 #include "wearable_log.h"
11 #include "ConfigModel.h"
12 #include <ui_resource_string.h>
14 #include "common/screen.h"
18 static MotionRecognitionView *g_pMotionRecognitionView{nullptr};
20 MotionRecognitionView::MotionRecognitionView()
22 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionView");
23 g_pMotionRecognitionView = this;
26 MotionRecognitionView::~MotionRecognitionView()
28 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::~MotionRecognitionView");
30 g_pMotionRecognitionView = nullptr;
33 MotionRecognitionView *MotionRecognitionView::GetInstance()
35 return g_pMotionRecognitionView;
38 void MotionRecognitionView::ClearAll(void)
40 if (scrollView != nullptr)
42 scrollView->RemoveAll();
50 if (MotionRecognitionImage != nullptr)
52 delete MotionRecognitionImage;
53 MotionRecognitionImage = nullptr;
55 if (MotionRecognitionLabel != nullptr)
57 delete MotionRecognitionLabel;
58 MotionRecognitionLabel = nullptr;
61 if (MotionRecognitionToggleButton != nullptr)
63 delete MotionRecognitionToggleButton;
64 MotionRecognitionToggleButton = nullptr;
72 scrollView->ClearFocus();
78 void MotionRecognitionView::MotionRecognitionViewInit(void)
80 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionViewInit");
81 if (scrollView == nullptr)
83 scrollView = new UIScrollView();
84 scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
85 scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
86 scrollView->SetScrollBlankSize(50);
87 scrollView->SetHorizontalScrollState(false);
88 scrollView->SetReboundSize(35);
89 scrollView->SetOnDragListener(presenter_);
90 scrollView->RequestFocus();
91 scrollView->SetRotateFactor(1.0);
92 /* -------------------------------------------------------------------------- */
93 Title = new UILabelExt();
96 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::Title can not be nullptr!");
99 Title->SetPosition(83, 50, 300, 40);
100 Title->SetStyle(STYLE_TEXT_FONT, 30);
101 Title->SetStyle(STYLE_LINE_HEIGHT, 35);
102 Title->SetTextId(STR_MOTION_RECOGNITION); /*运动识别*/
103 Title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
104 Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
105 Title->SetRollSpeed(23);
106 Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
107 Title->SetVisible(true);
108 /* -------------------------------------------------------------------------- */
109 if (MotionRecognitionImage == nullptr)
111 MotionRecognitionImage = new UIImageView();
113 MotionRecognitionImage->SetPosition(43, 120, 380, 100);
114 MotionRecognitionImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
115 MotionRecognitionImage->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
116 MotionRecognitionImage->SetStyle(STYLE_BORDER_RADIUS, 100);
117 /* -------------------------------------------------------------------------- */
118 MotionRecognitionLabel = new UILabelExt();
119 if (MotionRecognitionLabel == nullptr)
121 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionLabel can not be nullptr!");
124 MotionRecognitionLabel->SetPosition(90, 153, 180, 40);
125 MotionRecognitionLabel->SetStyle(STYLE_TEXT_FONT, 30);
126 MotionRecognitionLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
127 MotionRecognitionLabel->SetTextId(STR_AUTO_DETECT); /*自动识别*/
128 MotionRecognitionLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
129 MotionRecognitionLabel->SetRollSpeed(23);
130 MotionRecognitionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
131 /* -------------------------------------------------------------------------- */
132 MotionRecognitionToggleButton = new UIToggleButton();
133 if (MotionRecognitionToggleButton == nullptr)
135 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LanguageSwitchView::MotionRecognitionToggleButton is nullptr!");
138 MotionRecognitionToggleButton->SetPosition(298, 145, 100, 50);
139 MotionRecognitionToggleButton->SetState(ConfigModel::GetInstance()->GetMotionRecognition());
140 MotionRecognitionToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
141 MotionRecognitionToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE);
142 /* ----------------------------- onclickListener ---------------------------- */
143 // MotionRecognitionToggleButton->SetOnClickListener(presenter_);
144 MotionRecognitionToggleButton->SetOnChangeListener(presenter_);
145 /* -------------------------------------------------------------------------- */
148 note = new UILabelExt();
151 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::note can not be nullptr!");
155 note->SetPosition(63, MotionRecognitionImage->GetY() + MotionRecognitionImage->GetHeight() + 20, 340, 80);
156 note->SetStyle(STYLE_TEXT_FONT, 20);
157 note->SetStyle(STYLE_LINE_HEIGHT, 40);
158 note->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
159 // note->SetTextId(STR_MOTION_RECOGNITION_NOTE);//开启后,手表会在检测到你处于运动状态时发出提醒。支持的运动包括:走路、跑步、骑车、划船机、椭圆机。
160 if(ConfigModel::GetInstance()->GetLanguage() == 0)
162 note->SetText("开启后,手表会在检测到你处于运动状态时发出提醒。支持的运动包括:走路、跑步、骑车、划船机、椭圆机。");
166 note->SetText("When enabled, the watch will send a reminder when it detects that you are in a sports state. Supported sports include: walking, running, cycling, rowing machine, elliptical trainer.");
168 note->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
169 note->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
170 /* -------------------------------------------------------------------------- */
172 viewInitStatus = true;
173 /* -------------------------------------------------------------------------- */
177 void MotionRecognitionView::OnStart()
179 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStart");
180 View<MotionRecognitionPresenter>::OnStart();
186 MotionRecognitionViewInit();
190 // GetRootContainer()->SetOnKeyActListener(presenter_);
192 scrollView->Add(Title);
193 scrollView->Add(MotionRecognitionImage);
194 scrollView->Add(MotionRecognitionLabel);
195 scrollView->Add(MotionRecognitionToggleButton);
196 scrollView->Add(note);
197 AddViewToRootContainer(scrollView);
201 UIToggleButton *MotionRecognitionView::GetMotionRecognitionToggleButton(void)
203 return MotionRecognitionToggleButton;