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_IMAGE_ANIMATOR_H
17 #define UI_TEST_IMAGE_ANIMATOR_H
18 
19 #include "components/ui_image_animator.h"
20 #include "components/ui_label.h"
21 #include "components/ui_label_button.h"
22 #include "components/ui_scroll_view.h"
23 #include "layout/grid_layout.h"
24 #include "ui_test.h"
25 
26 namespace OHOS {
27 class TestAnimatorStopListener : public UIImageAnimatorView::AnimatorStopListener {
28 public:
TestAnimatorStopListener(UIViewGroup * viewGroup)29     explicit TestAnimatorStopListener(UIViewGroup* viewGroup) : viewGroup_(viewGroup)
30     {
31         viewGroup_ = viewGroup;
32     }
~TestAnimatorStopListener()33     ~TestAnimatorStopListener() {}
34 
Init()35     void Init()
36     {
37         label_ = new UILabel();
38         viewGroup_->Add(label_);
39         label_->SetPosition(24, 50, 200, 29); // 24: position x 50: position y 200: width 29: height
40         label_->SetText("OnAnimatorStop");
41         label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
42         label_->SetStyle(STYLE_TEXT_COLOR, Color::Black().full);
43         label_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
44         label_->SetStyle(STYLE_BACKGROUND_OPA, 255); // 255: value
45         label_->SetVisible(false);
46     }
47 
OnAnimatorStop(UIView & view)48     void OnAnimatorStop(UIView& view) override
49     {
50         label_->SetVisible(true);
51         label_->Invalidate();
52     }
53 
54 private:
55     UILabel* label_ = nullptr;
56     UIViewGroup* viewGroup_ = nullptr;
57 };
58 
59 class UITestImageAnimator : public UITest, public UIView::OnClickListener {
60 public:
UITestImageAnimator()61     UITestImageAnimator() {}
~UITestImageAnimator()62     ~UITestImageAnimator() {}
63     void SetUp() override;
64     void TearDown() override;
65     const UIView* GetTestView() override;
66 
67     void SetUpButton(UILabelButton* btn, const char* title);
68 
69     bool OnClick(UIView& view, const ClickEvent& event) override;
70 
71     void UIKitImageAnimatorTestStart001();
72     void UIKitImageAnimatorTestStop002();
73     void UIKitImageAnimatorTestPause003();
74     void UIKitImageAnimatorTestResume004();
75     void UIKitImageAnimatorTestSetImageAnimatorSrc005();
76     void UIKitImageAnimatorTestSetTickOfUpdate006();
77     void UIKitImageAnimatorTestSetSizeFixed007();
78     void UIKitImageAnimatorTestSetRepeat008();
79     void UIKitImageAnimatorTestSetReverse009();
80     void UIKitImageAnimatorTestSetAnimatorStopListener010();
81     void UIKitImageAnimatorTestSetRepeatTimes011();
82     void UIKitImageAnimatorTestSetFillModeTrueForward012();
83     void UIKitImageAnimatorTestSetFillModeTrueBackward013();
84     void UIKitImageAnimatorTestSetFillModeFalseForward014();
85     void UIKitImageAnimatorTestSetFillModeFalseBackward015();
86     void UIKitImageAnimatorTestSetImageInfo016();
87 
88 private:
89     void InitImageInfo();
90     void SetSrcData3(uint8_t* srcData3, uint8_t* srcData2, uint8_t* srcData1,
91                      uint32_t dataSize, bool& isReturn, const uint16_t pixelByteSize);
92     void SetImageInfoPara(ImageInfo* imageInfo,
93                           const uint16_t width,
94                           const uint16_t height,
95                           uint32_t dataSize,
96                           uint8_t* srcData);
97     void SetimageAnimatorImageInfos();
98     UIScrollView* container_ = nullptr;
99     GridLayout* layout_ = nullptr;
100     UIImageAnimatorView* imageAnimator_ = nullptr;
101     TestAnimatorStopListener* listener_ = nullptr;
102 
103     UILabelButton* startBtn_ = nullptr;
104     UILabelButton* stopBtn_ = nullptr;
105     UILabelButton* pauseBtn_ = nullptr;
106     UILabelButton* resumeBtn_ = nullptr;
107     UILabelButton* setImageBtn_ = nullptr;
108     UILabelButton* setSpeedBtn_ = nullptr;
109     UILabelButton* fixedBtn_ = nullptr;
110     UILabelButton* repeatBtn_ = nullptr;
111     UILabelButton* noRepeatBtn_ = nullptr;
112     UILabelButton* reverseOrderBtn_ = nullptr;
113     UILabelButton* positiveOrderBtn_ = nullptr;
114     UILabelButton* listenerBtn_ = nullptr;
115     UILabelButton* repeatTimesBtn_ = nullptr;
116     UILabelButton* fillModeTrueForwardBtn_ = nullptr;
117     UILabelButton* fillModeTrueBackwardBtn_ = nullptr;
118     UILabelButton* fillModeFalseForwardBtn_ = nullptr;
119     UILabelButton* fillModeFalseBackwardBtn_ = nullptr;
120     UILabelButton* setImageInfoBtn_ = nullptr;
121 
122     ImageInfo* imageInfo1_ = nullptr;
123     ImageInfo* imageInfo2_ = nullptr;
124     ImageInfo* imageInfo3_ = nullptr;
125     ImageAnimatorInfo imageAnimatorImageInfo_[3] = { 0 };
126 };
127 } // namespace OHOS
128 #endif // UI_TEST_IMAGE_ANIMATOR_H
129