• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class UITestAnalogClock : public UITest {
44 public:
UITestAnalogClock()45     UITestAnalogClock() {}
~UITestAnalogClock()46     ~UITestAnalogClock() {}
47     void SetUp() override;
48     void TearDown() override;
49     const UIView* GetTestView() override;
50     void CreateButtons001(UIViewGroup* group, UIImageView* curFace, UIAnalogClock* clock);
51     void CreateButtons002(UIViewGroup* group, UIImageView* curFace, UIAnalogClock* clock);
52 
53     void UIKit_TestLineHandAnalogClock_001();
54     void UIKit_TestImageHandAnalogClock_002();
55 
56 private:
57     UIScrollView* container_ = nullptr;
58     ClockAnimatorCallback* callback_ = nullptr;
59     Animator* animator_ = nullptr;
60     ClockAnimatorCallback* callback2_ = nullptr;
61     Animator* animator2_ = nullptr;
62     UIView::OnClickListener* changeModeListener_ = nullptr;
63     UIView::OnClickListener* clickMoveLeftListener_ = nullptr;
64     UIView::OnClickListener* clickMoveRightListener_ = nullptr;
65     UIView::OnClickListener* clickMoveTopListener_ = nullptr;
66     UIView::OnClickListener* clickMoveBottomListener_ = nullptr;
67     UIView::OnClickListener* changeModeListener1_ = nullptr;
68     UIView::OnClickListener* clickMoveLeftListener1_ = nullptr;
69     UIView::OnClickListener* clickMoveRightListener1_ = nullptr;
70     UIView::OnClickListener* clickMoveTopListener1_ = nullptr;
71     UIView::OnClickListener* clickMoveBottomListener1_ = nullptr;
SetUpButton(const char * title)72     UILabelButton* SetUpButton(const char* title)
73     {
74         UILabelButton* btn = new UILabelButton();
75         btn->Resize(BUTTON_WIDHT2, BUTTON_HEIGHT2);
76         btn->SetText(title);
77         btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE);
78         btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED);
79         btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED);
80         btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE);
81         btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::RELEASED);
82         btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::PRESSED);
83         btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::INACTIVE);
84         return btn;
85     }
86 };
87 }
88 #endif // UI_TEST_ANALOG_CLOCK_H
89