1 /*
2 * Copyright (c) 2020 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 #include "acelite_config.h"
16 #if (FEATURE_COMPONENT_VIDEO == 1)
17
18 #include "panel_view.h"
19 #include "graphic_config.h"
20
21 namespace OHOS {
22 namespace ACELite {
23 const char * const PanelView::DEFAULT_PLAY_TIME = "00:00";
24 const uint16_t PanelView::DEFAULT_VOLUME_VALUE = 50;
25 const uint16_t PanelView::DEFAULT_PANEL_HEIGHT = 51;
26 const uint8_t PanelView::SECONDS_PER_MINUTE = 60;
27 const uint16_t PanelView::MILLIONS_PER_SECOND = 1000;
28 const uint16_t PanelView::SECONDS_PER_HOUR = 3600;
29 const uint8_t PanelView::MAX_HOURS = 9;
30 const int64_t PanelView::MAX_SHOW_TIME = MAX_HOURS * SECONDS_PER_HOUR * MILLIONS_PER_SECOND;
31 const uint16_t PanelView::UPDATE_CYCLE = 250;
32 const uint32_t PanelView::UPDATE_CYCLE_MICRO_SECONDS = UPDATE_CYCLE * MILLIONS_PER_SECOND;
33
PanelView()34 PanelView::PanelView()
35 : curTimeLabel_(nullptr),
36 playImage_(nullptr),
37 videoSlider_(nullptr),
38 totalTimeLabel_(nullptr),
39 mutedImage_(nullptr)
40 {
41 }
42
InitView()43 bool PanelView::InitView()
44 {
45 curTimeLabel_ = new UILabel();
46 playImage_ = new UIImageView();
47 videoSlider_ = new UISlider();
48 totalTimeLabel_ = new UILabel();
49 mutedImage_ = new UIImageView();
50 if (curTimeLabel_ == nullptr || playImage_ == nullptr || videoSlider_ == nullptr || totalTimeLabel_ == nullptr ||
51 mutedImage_ == nullptr) {
52 return false;
53 }
54 /* add to panel & layout */
55 Add(playImage_);
56 Add(curTimeLabel_);
57 Add(videoSlider_);
58 Add(totalTimeLabel_);
59 Add(mutedImage_);
60 LayoutChildren();
61 return true;
62 }
63
64
~PanelView()65 PanelView::~PanelView()
66 {
67 ACE_DELETE(curTimeLabel_);
68 ACE_DELETE(playImage_);
69 ACE_DELETE(videoSlider_);
70 ACE_DELETE(totalTimeLabel_);
71 ACE_DELETE(mutedImage_);
72 }
73
GetCurTimeText() const74 const UILabel *PanelView::GetCurTimeText() const
75 {
76 return curTimeLabel_;
77 }
78
GetVideoPlayImage() const79 const UIImageView *PanelView::GetVideoPlayImage() const
80 {
81 return playImage_;
82 }
83
GetVideoSlider() const84 const UISlider *PanelView::GetVideoSlider() const
85 {
86 return videoSlider_;
87 }
88
GetVideoTotalTimeText() const89 const UILabel *PanelView::GetVideoTotalTimeText() const
90 {
91 return totalTimeLabel_;
92 }
93
GetVideoMutedImage() const94 const UIImageView *PanelView::GetVideoMutedImage() const
95 {
96 return mutedImage_;
97 }
98
99
SetImageInPanel(UIImageView * image,int16_t imageWidth,int16_t imageHeight,const ImageInfo * imageSrc)100 void PanelView::SetImageInPanel(
101 UIImageView *image,
102 int16_t imageWidth,
103 int16_t imageHeight,
104 const ImageInfo* imageSrc)
105 {
106 if (image == nullptr || imageSrc == nullptr) {
107 return;
108 }
109 image->SetSrc(imageSrc);
110 image->SetWidth(imageWidth);
111 image->SetHeight(imageHeight);
112 }
113
SetTextInPanel(UILabel * label)114 void PanelView::SetTextInPanel(UILabel *label)
115 {
116 if (label == nullptr) {
117 return;
118 }
119 label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
120 uint8_t fontSize = 18;
121 label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontSize);
122 label->SetText(DEFAULT_PLAY_TIME);
123 }
124
SetVideoSlider()125 void PanelView::SetVideoSlider()
126 {
127 if (videoSlider_ == nullptr || curTimeLabel_ == nullptr || totalTimeLabel_ == nullptr ||
128 playImage_ == nullptr || mutedImage_ == nullptr) {
129 return;
130 }
131 const int8_t sliderWidth = 5; // default slider width
132 const int8_t knobWidth = 18; // default knob width
133 const int8_t defaultBorderRadius = 0;
134 const int8_t knobRadius = 10;
135 const int8_t hundred = 100;
136 const int8_t margin = 75;
137 int16_t visibleHeight = 30;
138 const int8_t miniVisibleWidth = 100;
139 int16_t visibleWidth = (GetWidth() - (curTimeLabel_->GetWidth()) - (totalTimeLabel_->GetWidth()) -
140 (playImage_->GetWidth()) - (mutedImage_->GetWidth()) - margin);
141 if (visibleWidth < miniVisibleWidth) {
142 visibleWidth = miniVisibleWidth;
143 }
144 videoSlider_->SetHeight(visibleHeight);
145 videoSlider_->SetWidth(visibleWidth);
146 videoSlider_->SetRange(hundred, 0);
147 videoSlider_->SetValue(0);
148 videoSlider_->SetValidHeight(sliderWidth);
149 videoSlider_->SetValidWidth(visibleWidth - knobWidth);
150 videoSlider_->SetKnobWidth(knobWidth);
151 videoSlider_->SetSliderRadius(defaultBorderRadius, defaultBorderRadius);
152 videoSlider_->SetKnobRadius(knobRadius);
153 const uint8_t alpha = OPA_OPAQUE;
154 /* set videoSlider_ background color */
155 videoSlider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
156 videoSlider_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, alpha);
157 /* set videoSlider_ selected color */
158 videoSlider_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::Green().full);
159 videoSlider_->SetForegroundStyle(STYLE_BACKGROUND_OPA, alpha);
160 }
161 } // namespace ACELite
162 } // namespace OHOS
163
164 #endif // FEATURE_COMPONENT_VIDEO
165