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 #include <cstdio>
17 #include <common/screen.h>
18 #include <components/ui_label.h>
19 #include <components/ui_label_button.h>
20
21 #include "main_ability_slice.h"
22 #include "ability_manager.h"
23
24 namespace OHOS {
REGISTER_AS(MainAbilitySlice)25 REGISTER_AS(MainAbilitySlice)
26
27 MainAbilitySlice::~MainAbilitySlice()
28 {
29 ReleaseView();
30 }
31
ReleaseView()32 void MainAbilitySlice::ReleaseView()
33 {
34 if (swipeView_) {
35 delete swipeView_;
36 swipeView_ = nullptr;
37 }
38 if (uiImageView_) {
39 delete uiImageView_;
40 uiImageView_ = nullptr;
41 }
42 if (lableHead_) {
43 delete lableHead_;
44 lableHead_ = nullptr;
45 }
46 if (lableTail_) {
47 delete lableTail_;
48 lableTail_ = nullptr;
49 }
50 }
51
SetHead()52 void MainAbilitySlice::SetHead()
53 {
54 char tmp[TMP_BUF_SIZE] = { 0 };
55 time_t t = time(nullptr);
56 struct tm* st = nullptr;
57 st = localtime(&t);
58 sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min);
59 UILabel* label = new UILabel();
60 rootview_->Add(label);
61 label->SetPosition(0, 0, Screen::GetInstance().GetWidth(), LABLE_TITLE_HEIGHT);
62 label->SetText(tmp);
63 label->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_TOP);
64 label->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
65 label->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
66 label->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
67
68 lableHead_ = label;
69 }
70
SetTail()71 void MainAbilitySlice::SetTail()
72 {
73 UILabel* label = new UILabel();
74 rootview_->Add(label);
75 label->SetPosition(0, Screen::GetInstance().GetHeight() - LABLE_TAIL_HEIGHT,
76 Screen::GetInstance().GetWidth(), LABLE_TAIL_HEIGHT);
77 char buf[TMP_BUF_SIZE] = { 0 };
78 sprintf_s(buf, sizeof(buf), ".%d.", 1);
79 label->SetText(buf);
80 label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
81 label->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
82 label->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
83 label->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
84
85 lableTail_ = label;
86 }
87
SetImageView()88 void MainAbilitySlice::SetImageView()
89 {
90 uiImageView_ = new UIImageView();
91 // modify image view height
92
93 uiImageView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
94 uiImageView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::White()));
95 uiImageView_->SetSrc(TABLE_BACKGROUND);
96 uiImageView_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY);
97 rootview_->Add(uiImageView_);
98 }
99
SetSwipe()100 void MainAbilitySlice::SetSwipe()
101 {
102 swipeView_ = new SwipeView(lableHead_, lableTail_);
103 swipeView_->OnSetUpView();
104 rootview_->Add(swipeView_->GetSwipeView());
105 }
106
OnStart(const Want & want)107 void MainAbilitySlice::OnStart(const Want& want)
108 {
109 AbilitySlice::OnStart(want);
110 rootview_ = RootView::GetWindowRootView();
111 rootview_->SetPosition(0, 0);
112 rootview_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
113 rootview_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY);
114 rootview_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::GetColorFromRGB(0x30, 0x30, 0x30)));
115
116 SetHead();
117 SetTail();
118 SetSwipe();
119 SetUIContent(rootview_);
120 rootview_->Invalidate();
121 }
122
OnInactive()123 void MainAbilitySlice::OnInactive()
124 {
125 AbilitySlice::OnInactive();
126 }
127
OnActive(const Want & want)128 void MainAbilitySlice::OnActive(const Want& want)
129 {
130 AbilitySlice::OnActive(want);
131 }
132
OnBackground()133 void MainAbilitySlice::OnBackground()
134 {
135 AbilitySlice::OnBackground();
136 }
137
OnStop()138 void MainAbilitySlice::OnStop()
139 {
140 AbilitySlice::OnStop();
141 }
142 } // namespace OHOS
143