1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef UI_TEST_ANALOG_CLOCK_H
17 #define UI_TEST_ANALOG_CLOCK_H
18 
19 #include "ui_test.h"
20 
21 #include "components/ui_analog_clock.h"
22 #include "components/ui_label_button.h"
23 #include "components/ui_scroll_view.h"
24 
25 namespace OHOS {
26 class ClockAnimatorCallback : public AnimatorCallback {
27 public:
ClockAnimatorCallback(UIAnalogClock * clock)28     explicit ClockAnimatorCallback(UIAnalogClock* clock) : clock_(clock) {}
~ClockAnimatorCallback()29     ~ClockAnimatorCallback() {}
Callback(UIView * view)30     virtual void Callback(UIView* view)
31     {
32         count_++;
33         if ((count_ == 30) && (clock_ != nullptr)) { // 30: run every tick (~30ms)
34             clock_->IncOneSecond();
35             count_ = 0;
36         }
37     }
38 private:
39     UIAnalogClock* clock_;
40     int16_t count_ = 0;
41 };
42 
43 constexpr char* UI_TEST_SWITCH_MODE_1 = "switch_mode_1";
44 constexpr char* UI_TEST_SHIF_LEFT_1 = "shift_left_1";
45 constexpr char* UI_TEST_SHIF_RIGHT_1 = "shift_right_1";
46 constexpr char* UI_TEST_SHIF_UP_1 = "shift_up_1";
47 constexpr char* UI_TEST_SHIF_DOWN_1 = "shift_down_1";
48 
49 constexpr char* UI_TEST_SWITCH_MODE_2 = "switch_mode_2";
50 constexpr char* UI_TEST_SHIF_LEFT_2 = "shift_left_2";
51 constexpr char* UI_TEST_SHIF_RIGHT_2 = "shift_right_2";
52 constexpr char* UI_TEST_SHIF_UP_2 = "shift_up_2";
53 constexpr char* UI_TEST_SHIF_DOWN_2 = "shift_down_2";
54 
55 class UITestAnalogClock : public UITest {
56 public:
UITestAnalogClock()57     UITestAnalogClock() {}
~UITestAnalogClock()58     ~UITestAnalogClock() {}
59     void SetUp() override;
60     void TearDown() override;
61     const UIView* GetTestView() override;
62     void CreateButtons001(UIViewGroup* group, UIImageView* curFace, UIAnalogClock* clock);
63     void CreateButtons002(UIViewGroup* group, UIImageView* curFace, UIAnalogClock* clock);
64 
65     void UIKitTestLineHandAnalogClock001();
66     void UIKitTestImageHandAnalogClock002();
67 
68 private:
69     UIScrollView* container_ = nullptr;
70     ClockAnimatorCallback* callback_ = nullptr;
71     Animator* animator_ = nullptr;
72     ClockAnimatorCallback* callback2_ = nullptr;
73     Animator* animator2_ = nullptr;
74     UIView::OnClickListener* changeModeListener_ = nullptr;
75     UIView::OnClickListener* clickMoveLeftListener_ = nullptr;
76     UIView::OnClickListener* clickMoveRightListener_ = nullptr;
77     UIView::OnClickListener* clickMoveTopListener_ = nullptr;
78     UIView::OnClickListener* clickMoveBottomListener_ = nullptr;
79     UIView::OnClickListener* changeModeListener1_ = nullptr;
80     UIView::OnClickListener* clickMoveLeftListener1_ = nullptr;
81     UIView::OnClickListener* clickMoveRightListener1_ = nullptr;
82     UIView::OnClickListener* clickMoveTopListener1_ = nullptr;
83     UIView::OnClickListener* clickMoveBottomListener1_ = nullptr;
SetUpButton(const char * title,const char * id)84     UILabelButton* SetUpButton(const char* title, const char* id)
85     {
86         UILabelButton* btn = new UILabelButton();
87         btn->Resize(BUTTON_WIDHT2, BUTTON_HEIGHT2);
88         btn->SetText(title);
89         btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE);
90         btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED);
91         btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED);
92         btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE);
93         btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::RELEASED);
94         btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::PRESSED);
95         btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::INACTIVE);
96         btn->SetViewId(id);
97         return btn;
98     }
99     void TearDown001();
100 };
101 }
102 #endif // UI_TEST_ANALOG_CLOCK_H
103