#include "sys/time.h"
#include "ui_test_video_play.h"
#include "components/root_view.h"
+#include "components/ui_sweep_clock.h"
-namespace OHOS {
-static constexpr int16_t VIDEO_WIDTH = 466;
-static constexpr int16_t VIDEO_HEIGHT = 466;
-static constexpr int16_t STRIDE_ALIGNMENT_VALUE = 64;
-static constexpr int16_t BUFFER_QUEUE_SIZE = 3;
-static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2;
-static constexpr int16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128;
-static constexpr int16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16;
-static constexpr int16_t USEC_TO_MILLI = 1000;
-static constexpr int16_t TIME_CONVERT = 60; // sec to min, and min to hor
-static constexpr int16_t TEXT_BUFFER_SIEZ = 20;
-static constexpr int16_t TEXT_FONT_SIEZ = 40;
-static const int32_t WAIT_MEDIA_EXIT_SUCCESS_US = 10000;
-static const uint32_t WAIT_MEDIA_EXIT_MAX_RETRY_COUNT = 100;
-
-static void GetTime(char* buf, int len)
+namespace OHOS
{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- uint32_t second = tv.tv_sec % TIME_CONVERT;
- uint32_t minute = tv.tv_sec / TIME_CONVERT;
- uint32_t hour = (minute / TIME_CONVERT) % 24; // 24: 24 hours per day
- uint32_t realMilliSecond = tv.tv_usec / USEC_TO_MILLI;
- minute = minute % TIME_CONVERT;
-
- sprintf_s(buf, len, "%02d : %02d : %02d : %03d", hour, minute, second, realMilliSecond);
-}
+ class SweepClockCallback : public AnimatorCallback
+ {
+ public:
+ explicit SweepClockCallback(UISweepClock *clock) : sweepClock(clock) {}
+ ~SweepClockCallback() {}
-void VideoAnimatorCallback::Callback(UIView *view)
-{
- (void)view;
- char buf[TEXT_BUFFER_SIEZ] = {0};
- GetTime(buf, TEXT_BUFFER_SIEZ);
- label_->SetText(buf);
- RootView::GetInstance()->Invalidate();
-}
+ virtual void Callback(UIView *view)
+ {
+ // UNUSED(view);
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ uint64_t second = tv.tv_sec;
+ uint64_t uSecond = tv.tv_usec;
+ uint64_t minute = second / MIN_TO_HOUR;
+ uint64_t hour = minute / MIN_TO_HOUR;
+ uint8_t realHour = static_cast<uint8_t>(hour % HOURLY_SYSTEM);
+ uint8_t realMinute = static_cast<uint8_t>(minute % MIN_TO_HOUR);
+ uint16_t realMilliSecond = static_cast<uint16_t>((second % MIN_TO_HOUR) *
+ SEC_TO_MILLI +
+ uSecond / USEC_TO_MILLI);
+ sweepClock->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1);
+ }
-void UITestVideoPlay::SetUp()
-{
- container_ = new UIScrollView();
- container_->SetThrowDrag(true);
- container_->SetHorizontalScrollState(false);
- container_->Resize(VIDEO_WIDTH, VIDEO_HEIGHT);
- container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
- container_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
-
- label_ = new UILabel();
- char filePath[PATH_MAX];
- if (realpath("/user/video/dial.mp4", filePath) == nullptr) {
- label_->SetPosition(60, 227, 330, 70); // 60, 227, 330, 70: Left, right, width, height.
- label_->SetText("please upload video resource.");
- label_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff505050);
- label_->SetStyle(STYLE_TEXT_COLOR, Color::White().full);
- label_->SetStyle(STYLE_BORDER_RADIUS, 20); // 20: Radius for label border.
- label_->SetStyle(STYLE_BACKGROUND_OPA, 150); // 150: Opacity for background.
- label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 25); // 25: Font size.
- label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
- container_->Add(label_);
- GRAPHIC_LOGE("no video resource\n");
- return;
+ private:
+ static constexpr int16_t SEC_TO_MILLI = 1000;
+ static constexpr int16_t USEC_TO_MILLI = 1000;
+ static constexpr int16_t MIN_TO_HOUR = 60;
+ static constexpr int16_t HOURLY_SYSTEM = 24;
+ static constexpr int16_t INTERVAL = 30;
+ UISweepClock *sweepClock{nullptr};
+ };
+
+ static constexpr int16_t VIDEO_WIDTH = 466;
+ static constexpr int16_t VIDEO_HEIGHT = 466;
+ static constexpr int16_t STRIDE_ALIGNMENT_VALUE = 64;
+ static constexpr int16_t BUFFER_QUEUE_SIZE = 3;
+ static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2;
+ static constexpr int16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128;
+ static constexpr int16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16;
+ static constexpr int16_t USEC_TO_MILLI = 1000;
+ static constexpr int16_t TIME_CONVERT = 60; // sec to min, and min to hor
+ static constexpr int16_t TEXT_BUFFER_SIEZ = 20;
+ static constexpr int16_t TEXT_FONT_SIEZ = 40;
+ static const int32_t WAIT_MEDIA_EXIT_SUCCESS_US = 10000;
+ static const uint32_t WAIT_MEDIA_EXIT_MAX_RETRY_COUNT = 100;
+
+ static void GetTime(char *buf, int len)
+ {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ uint32_t second = tv.tv_sec % TIME_CONVERT;
+ uint32_t minute = tv.tv_sec / TIME_CONVERT;
+ uint32_t hour = (minute / TIME_CONVERT) % 24; // 24: 24 hours per day
+ uint32_t realMilliSecond = tv.tv_usec / USEC_TO_MILLI;
+ minute = minute % TIME_CONVERT;
+
+ sprintf_s(buf, len, "%02d : %02d : %02d : %03d", hour, minute, second, realMilliSecond);
}
- char buf[TEXT_BUFFER_SIEZ] = {0};
- GetTime(buf, TEXT_BUFFER_SIEZ);
- label_->SetText(buf);
- label_->SetPosition(60, 50, 330, 70); // 60, 50, 330, 70: Left, right, width, height.
- label_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
- label_->SetStyle(STYLE_TEXT_COLOR, Color::Silver().full);
- label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TEXT_FONT_SIEZ); // 25: Font size.
- label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
-
- callBack_ = new VideoAnimatorCallback(label_);
- animator_ = new Animator(callBack_, label_, 0, true);
- animator_->Start();
-
- button1_ = new UILabelButton();
- button1_->SetPosition(130, 360, 80, 40); // 130: x, 360: y, 80: width, 40: height
- button1_->SetText("Play");
- button1_->SetTextColor(Color::Silver());
- button1_->SetOnClickListener(this);
-
- button2_ = new UILabelButton();
- button2_->SetPosition(240, 360, 80, 40); // 240: x, 360: y, 80: width, 40: height
- button2_->SetText("Stop");
- button2_->SetTextColor(Color::Silver());
- button2_->SetOnClickListener(this);
-
- surfaceView_ = new UILiteSurfaceView();
- if (surfaceView_ == nullptr) {
- GRAPHIC_LOGE("surfaceView is nullptr\n");
- return;
+ void VideoAnimatorCallback::Callback(UIView *view)
+ {
+ (void)view;
+ char buf[TEXT_BUFFER_SIEZ] = {0};
+ GetTime(buf, TEXT_BUFFER_SIEZ);
+ label_->SetText(buf);
+ RootView::GetInstance()->Invalidate();
}
- colorKey_.full = 0xff202020;
- surfaceView_->SetViewId("sur");
- surfaceView_->SetPosition(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT);
- surfaceView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
- surfaceView_->SetSurfaceColorkey(colorKey_);
- container_->Add(surfaceView_);
- container_->Add(label_);
- container_->Add(button1_);
- container_->Add(button2_);
-
- Surface *surface = surfaceView_->GetSurface();
- surface->SetStrideAlignment(STRIDE_ALIGNMENT_VALUE);
- surface->SetWidthAndHeight(VIDEO_WIDTH, VIDEO_HEIGHT);
- surface->SetQueueSize(BUFFER_QUEUE_SIZE);
- surface->SetFormat(PIXEL_FMT_YCBCR_420_SP);
-
- // jpeg decoder output buffer size calculation formula
- int32_t ySize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * VIDEO_HEIGHT;
- int32_t uvSize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) *
- ALIGN_BYTE(VIDEO_HEIGHT, JPEG_HEIGHT_BYTE_ALIGNMENT) / JPEG_HEIGHT_DIVISOR;
- int32_t bufferSize = ySize + uvSize;
- surface->SetSize(bufferSize);
- if (videoPlay_ == nullptr) {
- std::string uri("/user/video/dial.mp4");
- videoPlay_ = new MediaVideoPlay(surface, button1_, uri);
- if (videoPlay_ == nullptr) {
- GRAPHIC_LOGE("videoPlay_ is nullptr\n");
+
+ void UITestVideoPlay::SetUp()
+ {
+ container_ = new UIScrollView();
+ container_->SetThrowDrag(true);
+ container_->SetHorizontalScrollState(false);
+ container_->Resize(VIDEO_WIDTH, VIDEO_HEIGHT);
+ container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
+ container_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+
+ label_ = new UILabel();
+ char filePath[PATH_MAX];
+ if (realpath("/user/video/dial.mp4", filePath) == nullptr)
+ {
+ label_->SetPosition(60, 227, 330, 70); // 60, 227, 330, 70: Left, right, width, height.
+ label_->SetText("please upload video resource.");
+ label_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff505050);
+ label_->SetStyle(STYLE_TEXT_COLOR, Color::White().full);
+ label_->SetStyle(STYLE_BORDER_RADIUS, 20); // 20: Radius for label border.
+ label_->SetStyle(STYLE_BACKGROUND_OPA, 150); // 150: Opacity for background.
+ label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 25); // 25: Font size.
+ label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ container_->Add(label_);
+ GRAPHIC_LOGE("no video resource\n");
return;
}
- }
-}
-void UITestVideoPlay::TearDown()
-{
- if (animator_ != nullptr) {
- animator_->Stop();
- delete animator_;
- animator_ = nullptr;
- }
+ // char buf[TEXT_BUFFER_SIEZ] = {0};
+ // GetTime(buf, TEXT_BUFFER_SIEZ);
+ // label_->SetText(buf);
+ // label_->SetPosition(60, 50, 330, 70); // 60, 50, 330, 70: Left, right, width, height.
+ // label_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
+ // label_->SetStyle(STYLE_TEXT_COLOR, Color::Silver().full);
+ // label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TEXT_FONT_SIEZ); // 25: Font size.
+ // label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
- if (callBack_ != nullptr) {
- delete callBack_;
- callBack_ = nullptr;
- }
+ // callBack_ = new VideoAnimatorCallback(label_);
+ // animator_ = new Animator(callBack_, label_, 0, true);
+ // animator_->Start();
+
+ button1_ = new UILabelButton();
+ button1_->SetPosition(130, 360, 80, 40); // 130: x, 360: y, 80: width, 40: height
+ button1_->SetText("Play");
+ button1_->SetTextColor(Color::Silver());
+ button1_->SetOnClickListener(this);
+
+ button2_ = new UILabelButton();
+ button2_->SetPosition(240, 360, 80, 40); // 240: x, 360: y, 80: width, 40: height
+ button2_->SetText("Stop");
+ button2_->SetTextColor(Color::Silver());
+ button2_->SetOnClickListener(this);
+
+ surfaceView_ = new UILiteSurfaceView();
+ if (surfaceView_ == nullptr)
+ {
+ GRAPHIC_LOGE("surfaceView is nullptr\n");
+ return;
+ }
+ colorKey_.full = 0xff202020;
+ surfaceView_->SetViewId("sur");
+ surfaceView_->SetPosition(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT);
+ surfaceView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+ surfaceView_->SetSurfaceColorkey(colorKey_);
+ container_->Add(surfaceView_);
+ container_->Add(label_);
+ container_->Add(button1_);
+ container_->Add(button2_);
- if (videoPlay_ != nullptr) {
- videoPlay_->needSendBackgroundFrame_ = false;
- videoPlay_->StopVideoPlay();
- uint32_t count = 0;
- while (!videoPlay_->IsExitCompletely()) {
- count++;
- if (count == WAIT_MEDIA_EXIT_MAX_RETRY_COUNT) {
- GRAPHIC_LOGE("media video play exit timeout\n");
- DeleteChildren(container_);
+ Surface *surface = surfaceView_->GetSurface();
+ surface->SetStrideAlignment(STRIDE_ALIGNMENT_VALUE);
+ surface->SetWidthAndHeight(VIDEO_WIDTH, VIDEO_HEIGHT);
+ surface->SetQueueSize(BUFFER_QUEUE_SIZE);
+ surface->SetFormat(PIXEL_FMT_YCBCR_420_SP);
+
+ // jpeg decoder output buffer size calculation formula
+ int32_t ySize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * VIDEO_HEIGHT;
+ int32_t uvSize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) *
+ ALIGN_BYTE(VIDEO_HEIGHT, JPEG_HEIGHT_BYTE_ALIGNMENT) / JPEG_HEIGHT_DIVISOR;
+ int32_t bufferSize = ySize + uvSize;
+ surface->SetSize(bufferSize);
+ if (videoPlay_ == nullptr)
+ {
+ std::string uri("/user/video/dial.mp4");
+ videoPlay_ = new MediaVideoPlay(surface, button1_, uri);
+ if (videoPlay_ == nullptr)
+ {
+ GRAPHIC_LOGE("videoPlay_ is nullptr\n");
return;
}
- usleep(WAIT_MEDIA_EXIT_SUCCESS_US);
}
- delete videoPlay_;
- videoPlay_ = nullptr;
+
+ // Add SweepClock to App
+ if (sweepClock1_ == nullptr)
+ {
+ sweepClock1_ = new UISweepClock();
+ }
+ sweepClock1_->SetPosition(0, 0); // widget's left position and top position
+ sweepClock1_->Resize(466, 466); // widget's width and height
+ sweepClock1_->SetViewId("sweepClock1"); // Set style
+ sweepClock1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ sweepClock1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+
+ // Set additional property
+ sweepClock1_->SetWorkMode(UISweepClock::WorkMode::NORMAL);
+ sweepClock1_->SetHandLine(UISweepClock::HandType::HOUR_HAND, {233, 101}, {0, 132}, Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff), 5, 132, 255);
+ sweepClock1_->SetHandLine(UISweepClock::HandType::MINUTE_HAND, {233, 56}, {0, 177}, Color::GetColorFromRGBA(0x00, 0xff, 0x00, 0xff), 3, 177, 255);
+ sweepClock1_->SetHandLine(UISweepClock::HandType::SECOND_HAND, {233, 10}, {0, 223}, Color::GetColorFromRGBA(0xff, 0x00, 0x00, 0xff), 1, 223, 255);
+ uint16_t sweepClock1realMilliSecond = 40 * 1000;
+ sweepClock1_->SetSweepTime12Hour(10, 20, sweepClock1realMilliSecond, true);
+
+ sweepClock1callback_ = new SweepClockCallback(sweepClock1_);
+ sweepClock1animator_ = new Animator(sweepClock1callback_, sweepClock1_, 0, true);
+ sweepClock1animator_->Start();
+
+ // Add to rootView
+ container_->Add(sweepClock1_);
+ sweepClock1_->SetVisible(true);
}
- DeleteChildren(container_);
-}
-const UIView* UITestVideoPlay::GetTestView()
-{
- return container_;
-}
+ void UITestVideoPlay::TearDown()
+ {
+ if (animator_ != nullptr)
+ {
+ animator_->Stop();
+ delete animator_;
+ animator_ = nullptr;
+ }
-bool UITestVideoPlay::OnClick(UIView& view, const ClickEvent& event)
-{
- int32_t ret = 0;
- if (videoPlay_ == nullptr) {
- GRAPHIC_LOGE("videoPlay_ is nullptr!\n");
- return false;
+ if (callBack_ != nullptr)
+ {
+ delete callBack_;
+ callBack_ = nullptr;
+ }
+ if (sweepClock1callback_ != nullptr)
+ {
+ delete sweepClock1callback_;
+ sweepClock1callback_ = nullptr;
+ }
+ if (sweepClock1animator_ != nullptr)
+ {
+ delete sweepClock1animator_;
+ sweepClock1animator_ = nullptr;
+ }
+ if (videoPlay_ != nullptr)
+ {
+ videoPlay_->needSendBackgroundFrame_ = false;
+ videoPlay_->StopVideoPlay();
+ uint32_t count = 0;
+ while (!videoPlay_->IsExitCompletely())
+ {
+ count++;
+ if (count == WAIT_MEDIA_EXIT_MAX_RETRY_COUNT)
+ {
+ GRAPHIC_LOGE("media video play exit timeout\n");
+ DeleteChildren(container_);
+ return;
+ }
+ usleep(WAIT_MEDIA_EXIT_SUCCESS_US);
+ }
+ delete videoPlay_;
+ videoPlay_ = nullptr;
+ }
+ DeleteChildren(container_);
}
- if (&view == button1_) {
- if (videoPlay_->isExited_ || !videoPlay_->isEntered_) {
- ret = videoPlay_->StartVideoPlay();
- return true;
+
+ const UIView *UITestVideoPlay::GetTestView()
+ {
+ return container_;
+ }
+
+ bool UITestVideoPlay::OnClick(UIView &view, const ClickEvent &event)
+ {
+ int32_t ret = 0;
+ if (videoPlay_ == nullptr)
+ {
+ GRAPHIC_LOGE("videoPlay_ is nullptr!\n");
+ return false;
}
- if (videoPlay_->isPause_) {
- ret = videoPlay_->ResumeVideoPlay();
- if (ret == 0) {
- button1_->SetText("Pause");
+ if (&view == button1_)
+ {
+ if (videoPlay_->isExited_ || !videoPlay_->isEntered_)
+ {
+ ret = videoPlay_->StartVideoPlay();
+ return true;
+ }
+ if (videoPlay_->isPause_)
+ {
+ ret = videoPlay_->ResumeVideoPlay();
+ if (ret == 0)
+ {
+ button1_->SetText("Pause");
+ }
}
- } else {
- ret = videoPlay_->PauseVideoPlay();
- if (ret == 0) {
- button1_->SetText("Play");
+ else
+ {
+ ret = videoPlay_->PauseVideoPlay();
+ if (ret == 0)
+ {
+ button1_->SetText("Play");
+ }
}
}
- } else if (&view == button2_) {
- videoPlay_->StopVideoPlay();
+ else if (&view == button2_)
+ {
+ videoPlay_->StopVideoPlay();
+ }
+ return true;
}
- return true;
-}
}