• 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         int temp = 0;
94         temp = sprintf_s(buff, sizeof(buff), "%02d : %02d", ss / 60, ss % 60);     /* 60=1s */
95         if (temp != 0) {
96             printf("result is %d\n", temp);
97         };
98         timeLabel_->SetText(buff);
99     }
100 };
101 
102 class CameraAbilitySlice : public AbilitySlice {
103 public:
104     CameraAbilitySlice() = default;
105     ~CameraAbilitySlice() override;
106 
107 protected:
108     void OnStart(const Want &want) override;
109     void OnInactive() override;
110     void OnActive(const Want &want) override;
111     void OnBackground() override;
112     void OnStop() override;
113 
114 private:
115     static constexpr int BUTTON_NUMS = 4;
116     static constexpr int FONT_SIZE = 28;
117 
118     EventListener *buttonListener_ { nullptr };
119     SampleCameraManager *cam_manager;
120     UIImageView *background_;
121     UISurfaceView* surfaceView;
122     UIImageView *backBttn;
123     UIImageView *backIcon;
124     UILabel *txtMsgLabel;
125     UIImageView *recordImage;
126     UILabel *tmLabel;
127 
128     UIImageView* bttnLeft;
129     UIImageView* bttnMidle;
130     UIImageView* bttnRight;
131     UIImageView* bttnRecord;
132     UIScrollView* scroll;
133     UISlider *slider;
134     Animator *animator_;
135     TaskView *gTaskView_;
136     UIView::OnClickListener *bttnImageClick[BUTTON_NUMS];
137 
138     void SetHead();
139     void SetBottom();
140 };
141 }
142 
143 #endif // OHOS_MAIN_ABILITY_SLICE_H
144