• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef OHOS_MAIN_ABILITY_SLICE_H
17 #define OHOS_MAIN_ABILITY_SLICE_H
18 
19 #include <ability_loader.h>
20 #include <functional>
21 #include <utility>
22 #include <securec.h>
23 #include <common/task.h>
24 #include <stdio.h>
25 #include <components/ui_label_button.h>
26 #include <components/ui_label.h>
27 #include <components/ui_checkbox.h>
28 #include <components/ui_image_view.h>
29 #include <components/ui_scroll_view.h>
30 #include <components/ui_surface_view.h>
31 #include <components/ui_slider.h>
32 #include <animator/animator.h>
33 
34 #include "event_listener.h"
35 #include "camera_manager.h"
36 
37 namespace OHOS {
38 class TaskView : public Task {
39 public:
40     TaskView() = delete;
TaskView(UILabel * tmLabel)41     TaskView(UILabel* tmLabel):timeLabel_(tmLabel)
42     {
43         runEnable_ = false;
44         gTimeCount_ = 0;
45         Task::Init();
46     }
47 
~TaskView()48     virtual ~TaskView(){}
TaskStart(void)49     void TaskStart(void)
50     {
51         Task::SetPeriod(1000);    /* 1000=1s */
52         Task::TaskExecute();
53     }
54 
SetStart(void)55     void SetStart(void)
56     {
57         runEnable_ = true;
58         gTimeCount_ = 0;
59     }
60 
SetPause(void)61     void SetPause(void)
62     {
63         runEnable_ = false;
64     }
65 
SetResume(void)66     void SetResume(void)
67     {
68         runEnable_ = true;
69     }
70 
SetStop(void)71     void SetStop(void)
72     {
73         gTimeCount_ = 0;
74         runEnable_ = false;
75         UpdateTimeLabel(gTimeCount_);
76     }
77 
Callback()78     void Callback() override
79     {
80         if (runEnable_)
81             UpdateTimeLabel(gTimeCount_++);
82     }
83 private:
84     UILabel* timeLabel_;
85     bool runEnable_;
86     uint32_t gTimeCount_;
87 
UpdateTimeLabel(int ss)88     void UpdateTimeLabel(int ss)
89     {
90         char buff[20] = { 0 };
91 
92         if (timeLabel_ == nullptr) return;
93 
94         sprintf_s(buff, sizeof(buff), "%02d : %02d", ss / 60, ss % 60);     /* 60=1s */
95         timeLabel_->SetText(buff);
96     }
97 };
98 
99 class CameraAbilitySlice : public AbilitySlice {
100 public:
101     CameraAbilitySlice() = default;
102     ~CameraAbilitySlice() override;
103 
104 protected:
105     void OnStart(const Want &want) override;
106     void OnInactive() override;
107     void OnActive(const Want &want) override;
108     void OnBackground() override;
109     void OnStop() override;
110 
111 private:
112     static constexpr int BUTTON_NUMS = 4;
113     static constexpr int FONT_SIZE = 28;
114 
115     EventListener *buttonListener_ { nullptr };
116     SampleCameraManager *cam_manager;
117     UIImageView *background_;
118     UISurfaceView* surfaceView;
119     UIImageView *backBttn;
120     UIImageView *backIcon;
121     UILabel *txtMsgLabel;
122     UIImageView *recordImage;
123     UILabel *tmLabel;
124 
125     UIImageView* bttnLeft;
126     UIImageView* bttnMidle;
127     UIImageView* bttnRight;
128     UIImageView* bttnRecord;
129     UIScrollView* scroll;
130     UISlider *slider;
131     Animator *animator_;
132     TaskView *gTaskView_;
133     UIView::OnClickListener *bttnImageClick[BUTTON_NUMS];
134 
135     void SetHead();
136     void SetBottom();
137 };
138 }
139 
140 #endif // OHOS_MAIN_ABILITY_SLICE_H
141