8564bb5a02014ba2c85253c0638e4493e5cb157f
[mirrors/FD230.git] /
1 /*
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
7  */
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>
13 #include <UiConfig.h>
14 #include "common/screen.h"
15 namespace OHOS
16 {
17
18     static MotionRecognitionView *g_pMotionRecognitionView{nullptr};
19
20     MotionRecognitionView::MotionRecognitionView()
21     {
22         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionView");
23         g_pMotionRecognitionView = this;
24     }
25
26     MotionRecognitionView::~MotionRecognitionView()
27     {
28         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::~MotionRecognitionView");
29
30         g_pMotionRecognitionView = nullptr;
31     }
32
33     MotionRecognitionView *MotionRecognitionView::GetInstance()
34     {
35         return g_pMotionRecognitionView;
36     }
37
38     void MotionRecognitionView::ClearAll(void)
39     {
40         if (scrollView != nullptr)
41         {
42             scrollView->RemoveAll();
43
44             if (Title != nullptr)
45             {
46                 delete Title;
47                 Title = nullptr;
48             }
49
50             if (MotionRecognitionImage != nullptr)
51             {
52                 delete MotionRecognitionImage;
53                 MotionRecognitionImage = nullptr;
54             }
55             if (MotionRecognitionLabel != nullptr)
56             {
57                 delete MotionRecognitionLabel;
58                 MotionRecognitionLabel = nullptr;
59             }
60
61             if (MotionRecognitionToggleButton != nullptr)
62             {
63                 delete MotionRecognitionToggleButton;
64                 MotionRecognitionToggleButton = nullptr;
65             }
66             if (note != nullptr)
67             {
68                 delete note;
69                 note = nullptr;
70             }
71
72             scrollView->ClearFocus();
73             delete scrollView;
74             scrollView = nullptr;
75         }
76     }
77
78     void MotionRecognitionView::MotionRecognitionViewInit(void)
79     {
80         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionViewInit");
81         if (scrollView == nullptr)
82         {
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();
94             if (Title == nullptr)
95             {
96                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::Title can not be nullptr!");
97                 return;
98             }
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)
110             {
111                 MotionRecognitionImage = new UIImageView();
112             }
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)
120             {
121                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionLabel can not be nullptr!");
122                 return;
123             }
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)
134             {
135                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LanguageSwitchView::MotionRecognitionToggleButton is nullptr!");
136                 return;
137             }
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             /* -------------------------------------------------------------------------- */
146             if (note == nullptr)
147             {
148                 note = new UILabelExt();
149                 if (note == nullptr)
150                 {
151                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::note can not be nullptr!");
152                     return;
153                 }
154             }
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)
161             {
162                 note->SetText("开启后,手表会在检测到你处于运动状态时发出提醒。支持的运动包括:走路、跑步、骑车、划船机、椭圆机。");
163             }
164             else 
165             {
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.");
167             }
168             note->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
169             note->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
170             /* -------------------------------------------------------------------------- */
171
172             viewInitStatus = true;
173             /* -------------------------------------------------------------------------- */
174         }
175     }
176
177     void MotionRecognitionView::OnStart()
178     {
179         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStart");
180         View<MotionRecognitionPresenter>::OnStart();
181       
182        
183
184         if (!viewInitStatus)
185         {
186             MotionRecognitionViewInit();
187         }
188
189         // 增加按键监听
190         // GetRootContainer()->SetOnKeyActListener(presenter_);
191
192         scrollView->Add(Title);
193         scrollView->Add(MotionRecognitionImage);
194         scrollView->Add(MotionRecognitionLabel);
195         scrollView->Add(MotionRecognitionToggleButton);
196         scrollView->Add(note);
197         AddViewToRootContainer(scrollView);
198     }
199
200
201     UIToggleButton *MotionRecognitionView::GetMotionRecognitionToggleButton(void)
202     {
203         return MotionRecognitionToggleButton;
204     }
205 }