* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ui_test_opacity.h"
#include "common/screen.h"
#include "components/ui_swipe_view.h"
#include "font/ui_font.h"
#include "test_resource_config.h"
namespace OHOS {
namespace {
const int16_t TITLE_HEIGHT = 20;
const uint16_t LABEL_WIDTH = 200;
const uint16_t LABEL_HEIGHT = 50;
const uint16_t BUTTON_WIDTH = 150;
const uint16_t BUTTON_HEIGHT = 160;
const uint16_t CENTER_X = 100;
const uint16_t CENTER_Y = 100;
const uint16_t RADIUS = 80;
static ImageAnimatorInfo g_imageAnimatorInfo[4] = {
{GREEN_IMAGE_PATH, {50, 50}, 94, 94, IMG_SRC_FILE_PATH},
{YELLOW_IMAGE_PATH, {50, 50}, 94, 94, IMG_SRC_FILE_PATH},
{BLUE_IMAGE_PATH, {50, 50}, 94, 94, IMG_SRC_FILE_PATH},
{RED_IMAGE_PATH, {50, 50}, 94, 94, IMG_SRC_FILE_PATH},
};
static ImageAnimatorInfo g_imageAnimatorInfo2[4] = {
{GREEN_IMAGE_PATH, {200, 50}, 94, 94, IMG_SRC_FILE_PATH},
{YELLOW_IMAGE_PATH, {200, 50}, 94, 94, IMG_SRC_FILE_PATH},
{BLUE_IMAGE_PATH, {200, 50}, 94, 94, IMG_SRC_FILE_PATH},
{RED_IMAGE_PATH, {200, 50}, 94, 94, IMG_SRC_FILE_PATH},
};
}
void UITestOpacity::SetUp()
{
if (container_ == nullptr) {
container_ = new UIScrollView();
container_->SetThrowDrag(true);
container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
}
}
void UITestOpacity::TearDown()
{
DeleteChildren(container_);
container_ = nullptr;
}
UIViewGroup* UITestOpacity::CreateTestCaseGroup(const char* title) const
{
UIViewGroup* group = new UIViewGroup();
group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
group->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
group->SetPosition(0, 0);
UILabel* titleLabel = new UILabel();
titleLabel->SetPosition(0, 0, Screen::GetInstance().GetWidth(), TITLE_LABEL_DEFAULT_HEIGHT);
titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
titleLabel->SetText(title);
group->Add(titleLabel);
return group;
}
const UIView* UITestOpacity::GetTestView()
{
UIKitOpacityTestUILabel001();
UIKitOpacityTestUILabel002();
UIKitOpacityTestUIButton001();
UIKitOpacityTestUIButton002();
UIKitOpacityTestUILabelButton001();
UIKitOpacityTestUIArcLabel001();
UIKitOpacityTestUIImageView001();
UIKitOpacityTestUIImageAnimator001();
UIKitOpacityTestUIView001();
UIKitOpacityTestUIViewGroup001();
UIKitOpacityTestUIList001();
UIKitOpacityTestUIScrollView001();
UIKitOpacityTestUISwipeView001();
return container_;
}
UILabel* UITestOpacity::CreateTestCaseUILabel(const char* title, uint8_t opaScale) const
{
UILabel* label = new UILabel();
label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
label->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
label->SetPosition(10, 30);
label->Resize(LABEL_WIDTH, LABEL_HEIGHT);
label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
label->SetText(title);
label->SetOpaScale(opaScale);
return label;
}
void UITestOpacity::UIKitOpacityTestUILabel001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display dynamic text with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), LABEL_HEIGHT + 50);
group->SetViewId("UIKitOpacityTestUILabel001");
UILabel* label = CreateTestCaseUILabel("轻量级GUI-200", 200);
UILabel* label2 = CreateTestCaseUILabel("轻量级GUI-100", 100);
label2->SetX(220);
group->Add(label);
group->Add(label2);
container_->Add(group);
}
}
void UITestOpacity::UIKitOpacityTestUILabel002()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display dynamic text with opacity 256 and -1, uint8_t");
group->Resize(Screen::GetInstance().GetWidth(), LABEL_HEIGHT + 50);
group->SetViewId("UIKitOpacityTestUILabel002");
UILabel* label = CreateTestCaseUILabel("轻量级GUI-200", 256);
UILabel* label2 = CreateTestCaseUILabel("轻量级GUI-100", -1);
label2->SetX(220);
group->Add(label);
group->Add(label2);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUILabel001", 10);
}
}
void UITestOpacity::UIKitOpacityTestUIButton001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UIButton with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT);
group->SetViewId("UIKitOpacityTestUIButton001");
UIButton* button = new UIButton();
button->SetPosition(10, 30, BUTTON_WIDTH, BUTTON_HEIGHT >> 1);
button->SetOpaScale(200);
UIButton* button2 = new UIButton();
button2->SetPosition(200, 30, BUTTON_WIDTH, BUTTON_HEIGHT >> 1);
button2->SetOpaScale(100);
group->Add(button);
group->Add(button2);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUILabel002", 10);
}
}
UIButton* UITestOpacity::CreateTestCaseUIButton(uint8_t opaScale) const
{
UIButton* button = new UIButton();
button->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
button->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
button->SetPosition(10, 30, BUTTON_WIDTH, BUTTON_HEIGHT);
button->SetImageSrc(BLUE_IMAGE_PATH, YELLOW_IMAGE_PATH);
button->SetOpaScale(opaScale);
return button;
}
void UITestOpacity::UIKitOpacityTestUIButton002()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UIButton Image with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT + 50);
group->SetViewId("UIKitOpacityTestUIButton002");
UIButton* button = CreateTestCaseUIButton(200);
group->Add(button);
UIButton* button2 = CreateTestCaseUIButton(100);
button2->SetPosition(200, 30);
group->Add(button2);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUIButton001", 10);
}
}
UILabelButton* UITestOpacity::CreateTestCaseUILabelButton(const char* title, uint8_t opaScale) const
{
UILabelButton* labelButton = new UILabelButton();
labelButton->SetPosition(10, 30, BUTTON_WIDTH, BUTTON_HEIGHT >> 1);
labelButton->SetText(title);
labelButton->SetOpaScale(opaScale);
return labelButton;
}
void UITestOpacity::UIKitOpacityTestUILabelButton001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UILabelButton with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT);
group->SetViewId("UIKitOpacityTestUILabelButton001");
UILabelButton* labelButton = CreateTestCaseUILabelButton("200", 200);
group->Add(labelButton);
UILabelButton* labelButton2 = CreateTestCaseUILabelButton("100", 100);
labelButton2->SetX(200);
group->Add(labelButton2);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUIButton002", 10);
}
}
UIArcLabel* UITestOpacity::CreateTestCaseUIArcLabel(const char* title, uint8_t opaScale) const
{
UIArcLabel* label = new UIArcLabel();
label->SetArcTextCenter(CENTER_X, CENTER_Y + 20);
label->SetArcTextRadius(RADIUS);
label->SetArcTextAngle(270, 0);
label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
label->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
label->SetText(title);
label->SetStyle(STYLE_LETTER_SPACE, 30);
label->SetOpaScale(opaScale);
return label;
}
void UITestOpacity::UIKitOpacityTestUIArcLabel001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UIArcLabel with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT + 50);
group->SetViewId("UIKitOpacityTestUIArcLabel001");
UIArcLabel* label = CreateTestCaseUIArcLabel("01234567", 200);
group->Add(label);
UIArcLabel* label2 = CreateTestCaseUIArcLabel("01234567", 100);
label2->SetArcTextCenter(CENTER_X + 200, CENTER_Y + 20);
group->Add(label2);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUILabelButton001", 10);
}
}
UIImageView* UITestOpacity::CreateTestCaseUIImageView(const char* path, uint8_t opaScale) const
{
UIImageView* imageView = new UIImageView();
imageView->SetPosition(10, 30, 130, 130);
imageView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
imageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
imageView->SetSrc(path);
imageView->SetOpaScale(opaScale);
return imageView;
}
void UITestOpacity::UIKitOpacityTestUIImageView001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UIImageView with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT + 50);
group->SetViewId("UIKitOpacityTestUIImageView001");
UIImageView* imageView = CreateTestCaseUIImageView(BLUE_IMAGE_PATH, 200);
group->Add(imageView);
UIImageView* imageView2 = CreateTestCaseUIImageView(BLUE_ARGB8888_IMAGE_PATH, 100);
imageView2->SetX(200);
group->Add(imageView2);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUIArcLabel001", 10);
}
}
UIImageAnimatorView* UITestOpacity::CreateTestCaseUIImageAnimator(const ImageAnimatorInfo imageAnimatorInfo[],
uint8_t opaScale) const
{
UIImageAnimatorView* imageAnimator = new UIImageAnimatorView();
imageAnimator->SetPosition(10, 30, 200, 200);
imageAnimator->SetOpaScale(opaScale);
imageAnimator->SetImageAnimatorSrc(imageAnimatorInfo, 4, 10);
imageAnimator->Start();
return imageAnimator;
}
void UITestOpacity::UIKitOpacityTestUIImageAnimator001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UIImageAnimator with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT + 50);
group->SetViewId("UIKitOpacityTestUIImageAnimator001");
UIImageAnimatorView* imageAnimator = CreateTestCaseUIImageAnimator(g_imageAnimatorInfo, 200);
group->Add(imageAnimator);
UIImageAnimatorView* imageAnimator2 = CreateTestCaseUIImageAnimator(g_imageAnimatorInfo2, 100);
imageAnimator2->SetPosition(230, 30);
group->Add(imageAnimator2);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUIImageView001", 10);
}
}
UIView* UITestOpacity::CreateTestCaseUIView(uint8_t opaScale) const
{
UIView* view = new UIView();
view->SetPosition(10, 30, BUTTON_WIDTH, BUTTON_HEIGHT);
view->SetStyle(STYLE_BACKGROUND_COLOR, (Color::White()).full);
view->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
view->SetOpaScale(opaScale);
return view;
}
void UITestOpacity::UIKitOpacityTestUIView001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UIView with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT + 50);
group->SetViewId("UIKitOpacityTestUIView001");
UIView* view = CreateTestCaseUIView(200);
group->Add(view);
UIView* view2 = CreateTestCaseUIView(100);
view2->SetX(200);
group->Add(view2);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUIImageAnimator001", 10);
}
}
void UITestOpacity::UIKitOpacityTestUIViewGroup001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UIViewGroup with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), (BUTTON_HEIGHT << 1) + 100);
group->SetViewId("UIKitOpacityTestUIViewGroup001");
UIViewGroup* group1 = new UIViewGroup();
group1->SetPosition(10, 30, (BUTTON_WIDTH << 1) + 50, (BUTTON_HEIGHT << 1) + 100);
group1->SetStyle(STYLE_BACKGROUND_COLOR, (Color::Red()).full);
UIViewGroup* group2 = new UIViewGroup();
group2->SetPosition(170, 250, 150, 150);
group2->SetStyle(STYLE_BACKGROUND_COLOR, (Color::White()).full);
UILabelButton* labelButton = new UILabelButton();
labelButton->SetPosition(10, 10, 60, 30);
labelButton->SetText("Test1");
UILabelButton* labelButton2 = new UILabelButton();
labelButton2->SetPosition(170, 10, 60, 30);
labelButton2->SetText("Test2");
labelButton2->SetOpaScale(100);
UIButton* button = new UIButton();
button->SetPosition(10, 60, BUTTON_WIDTH, BUTTON_HEIGHT);
UIButton* button2 = new UIButton();
button2->SetPosition(170, 60, BUTTON_WIDTH, BUTTON_HEIGHT);
button2->SetImageSrc(BLUE_IMAGE_PATH, YELLOW_IMAGE_PATH);
button2->SetOpaScale(100);
UIImageView* imageView = new UIImageView();
imageView->SetPosition(10, 250, 50, 50);
imageView->SetSrc(BLUE_IMAGE_PATH);
imageView->SetOpaScale(100);
UIImageView* imageView2 = new UIImageView();
imageView2->SetPosition(10, 10, 50, 50);
imageView2->SetSrc(YELLOW_IMAGE_PATH);
group2->Add(imageView2);
group1->Add(labelButton);
group1->Add(labelButton2);
group1->Add(button);
group1->Add(button2);
group1->Add(imageView);
group1->Add(group2);
group2->SetOpaScale(100);
group1->SetOpaScale(200);
group->Add(group1);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUIView001", 10);
}
}
UIList* UITestOpacity::CreateTestCaseUIList(uint8_t opaScale) const
{
List<const char*>* adapterData = new List<const char*>();
adapterData->PushBack("000");
adapterData->PushBack("111");
adapterData->PushBack("222");
adapterData->PushBack("333");
adapterData->PushBack("444");
adapterData->PushBack("555");
adapterData->PushBack("666");
adapterData->PushBack("777");
adapterData->PushBack("888");
adapterData->PushBack("999");
TextAdapter* adapter = new TextAdapter();
adapter->SetData(adapterData);
UIList* list = new UIList(UIList::VERTICAL);
list->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
list->SetPosition(10, 30, BUTTON_WIDTH, BUTTON_HEIGHT);
list->SetAdapter(adapter);
list->SetOpaScale(opaScale);
return list;
}
void UITestOpacity::UIKitOpacityTestUIList001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UIList with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT + 100);
group->SetViewId("UIKitOpacityTestUIList001");
UIList* list = CreateTestCaseUIList(200);
group->Add(list);
UIList* list2 = CreateTestCaseUIList(100);
list2->SetX(200);
group->Add(list2);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUIViewGroup001", 10);
}
}
void UITestOpacity::UIKitOpacityTestUIScrollView001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UIScrollView with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT << 1);
group->SetViewId("UIKitOpacityTestUIScrollView001");
UIScrollView* group1 = new UIScrollView();
group1->SetPosition(10, 30, (BUTTON_WIDTH << 1) + 50, (BUTTON_HEIGHT) + 100);
group1->SetStyle(STYLE_BACKGROUND_COLOR, (Color::Red()).full);
UIScrollView* group2 = new UIScrollView();
group2->SetPosition(170, 80, 150, 150);
group2->SetStyle(STYLE_BACKGROUND_COLOR, (Color::White()).full);
UILabelButton* labelButton = new UILabelButton();
labelButton->SetPosition(10, 10, 80, 40);
labelButton->SetText("test1");
UILabelButton* labelButton2 = new UILabelButton();
labelButton2->SetPosition(170, 10, 80, 40);
labelButton2->SetText("test2");
labelButton2->SetOpaScale(100);
UIImageView* imageView = new UIImageView();
imageView->SetPosition(10, 80, 50, 50);
imageView->SetSrc(BLUE_IMAGE_PATH);
imageView->SetOpaScale(100);
UIImageView* imageView2 = new UIImageView();
imageView2->SetPosition(10, 10, 50, 50);
imageView2->SetSrc(YELLOW_IMAGE_PATH);
group2->Add(imageView2);
group1->Add(labelButton);
group1->Add(labelButton2);
group1->Add(imageView);
group1->Add(group2);
group2->SetOpaScale(100);
group1->SetOpaScale(200);
group->Add(group1);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUIList001", 10);
}
}
void UITestOpacity::UIKitOpacityTestUISwipeView001()
{
if (container_ != nullptr) {
UIViewGroup* group = CreateTestCaseGroup(" display UISwipeView with opacity 200 and 100");
group->Resize(Screen::GetInstance().GetWidth(), BUTTON_HEIGHT);
group->SetViewId("UIKitOpacityTestUISwipeView001");
UISwipeView* swipe = new UISwipeView(UISwipeView::HORIZONTAL);
swipe->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
swipe->SetPosition(10, 30, BUTTON_WIDTH << 1, BUTTON_HEIGHT);
swipe->SetBlankSize(50);
group->Add(swipe);
UILabelButton* button1 = new UILabelButton();
button1->SetPosition(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT >> 1);
button1->SetText("button1");
swipe->Add(button1);
UILabelButton* button2 = new UILabelButton();
button2->SetPosition(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT >> 1);
button2->SetText("button2");
button2->SetOpaScale(200);
swipe->Add(button2);
UILabelButton* button3 = new UILabelButton();
button3->SetPosition(0, 0, BUTTON_WIDTH, BUTTON_HEIGHT >> 1);
button3->SetText("button3");
button3->SetOpaScale(100);
swipe->Add(button3);
swipe->SetOpaScale(200);
container_->Add(group);
group->LayoutBottomToSibling("UIKitOpacityTestUIScrollView001", 10);
}
}
}