• 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 #include "setting_about_ability_slice.h"
17 #include "gfx_utils/style.h"
18 
19 namespace OHOS {
REGISTER_AS(SettingAboutAbilitySlice)20 REGISTER_AS(SettingAboutAbilitySlice)
21 
22 SettingAboutAbilitySlice::~SettingAboutAbilitySlice()
23 {
24     if (scrollView_) {
25         DeleteChildren(scrollView_);
26         scrollView_ = nullptr;
27     }
28 
29     if (headView_) {
30         DeleteChildren(headView_);
31         headView_ = nullptr;
32     }
33     if (buttonBackListener_) {
34         delete buttonBackListener_;
35         buttonBackListener_ = nullptr;
36     }
37     for (int count = 0; count < SCROLL_ITEM_NUM; count++) {
38         if (!itemInfo_[count][1]) {
39             itemInfo_[count][1] = nullptr;
40         }
41     }
42 }
43 
SetButtonListener()44 void SettingAboutAbilitySlice::SetButtonListener()
45 {
46     auto onClick = [this](UIView& view, const Event& event) -> bool {
47         Terminate();
48         return true;
49     };
50     buttonBackListener_ = new EventListener(onClick, nullptr);
51 }
52 
SetItemInfo()53 void SettingAboutAbilitySlice::SetItemInfo()
54 {
55     itemInfo_[0][0] = (char*) "设备名称"; // 0
56     itemInfo_[0][1] = GetDeviceType(); // 0
57     itemInfo_[1][0] = (char*) "厂家信息"; // 1
58     itemInfo_[1][1] = GetManufacture(); // 1
59     itemInfo_[2][0] = (char*) "品牌信息"; // 2
60     itemInfo_[2][1] = GetBrand(); // 2
61     itemInfo_[3][0] = (char*) "硬件版本号"; // 3
62     itemInfo_[3][1] = GetHardwareModel(); // 3
63     itemInfo_[4][0] = (char*) "设备序列号"; // 4
64     itemInfo_[4][1] = GetSerial(); // 4
65     itemInfo_[5][0] = (char*) "操作系统名"; // 5
66     itemInfo_[5][1] = GetOSFullName(); // 5
67     itemInfo_[6][0] = (char*) "软件版本号"; // 6
68     itemInfo_[6][1] = GetDisplayVersion(); // 6
69     itemInfo_[7][0] = (char*) "BootLoader版本号"; // 7
70     itemInfo_[7][1] = GetBootloaderVersion(); // 7
71     itemInfo_[8][0] = (char*) "构建时间"; // 8
72     itemInfo_[8][1] = GetBuildTime(); // 8
73 }
74 
SetHead()75 void SettingAboutAbilitySlice::SetHead()
76 {
77     headView_ = new UIViewGroup();
78     rootView_->Add(headView_);
79     headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
80     headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
81     headView_->SetTouchable(true);
82     headView_->SetOnClickListener(buttonBackListener_);
83 
84     UIImageView* imageView = new UIImageView();
85     headView_->Add(imageView);
86     imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
87     imageView->SetSrc(DE_IMAGE_BACK);
88 
89     UILabel* lablelFont = new UILabel();
90     lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
91     lablelFont->SetText("关于");
92     lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
93     lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
94     headView_->Add(lablelFont);
95 }
96 
SetScrollItem(int count)97 void SettingAboutAbilitySlice::SetScrollItem(int count)
98 {
99     int myPositonY = count * DE_ITEM_INTERVAL;
100 
101     UIViewGroup* itemView = new UIViewGroup();
102     itemView->SetPosition(ITEM_X, myPositonY, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
103     itemView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
104     itemView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
105     scrollView_->Add(itemView);
106 
107     UILabel* lablelFontName = new UILabel();
108     lablelFontName->SetPosition(DE_TITLE_TEXT_X, DE_TITLE_TEXT_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
109     lablelFontName->SetText(itemInfo_[count][0]);
110     lablelFontName->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
111     lablelFontName->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
112     itemView->Add(lablelFontName);
113 
114     UILabel* lablelFontInfo = new UILabel();
115     lablelFontInfo->SetPosition(ITEM_INFO_X, ITEM_INFO_Y, DE_SUBTITLE_TEXT_WIDTH, DE_SUBTITLE_TEXT_HEIGHT);
116     lablelFontInfo->SetText(itemInfo_[count][1]);
117     lablelFontInfo->SetFont(DE_FONT_OTF, DE_SUBTITLE_TEXT_SIZE);
118     lablelFontInfo->SetAlign(TEXT_ALIGNMENT_RIGHT);
119     lablelFontInfo->SetStyle(STYLE_TEXT_COLOR, DE_SUBTITLE_TEXT_COLOR);
120     itemView->Add(lablelFontInfo);
121 }
122 
SetScroll()123 void SettingAboutAbilitySlice::SetScroll()
124 {
125     scrollView_ = new UIScrollView();
126     scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_SCROLL_COLOR);
127     scrollView_->SetPosition(DE_SCROLL_X, DE_SCROLL_Y, DE_SCROLL_WIDTH, DE_SCROLL_HEIGHT);
128     scrollView_->SetXScrollBarVisible(false);
129     scrollView_->SetYScrollBarVisible(true);
130     rootView_->Add(scrollView_);
131     for (int count = 0; count < SCROLL_ITEM_NUM; count++) {
132         SetScrollItem(count);
133     }
134 }
135 
OnStart(const Want & want)136 void SettingAboutAbilitySlice::OnStart(const Want& want)
137 {
138     AbilitySlice::OnStart(want);
139     SetButtonListener();
140     SetItemInfo();
141 
142     rootView_ = RootView::GetWindowRootView();
143     rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
144     rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
145     SetHead();
146     SetScroll();
147 
148     SetUIContent(rootView_);
149 }
150 
OnInactive()151 void SettingAboutAbilitySlice::OnInactive()
152 {
153     AbilitySlice::OnInactive();
154 }
155 
OnActive(const Want & want)156 void SettingAboutAbilitySlice::OnActive(const Want& want)
157 {
158     AbilitySlice::OnActive(want);
159 }
160 
OnBackground()161 void SettingAboutAbilitySlice::OnBackground()
162 {
163     AbilitySlice::OnBackground();
164 }
165 
OnStop()166 void SettingAboutAbilitySlice::OnStop()
167 {
168     AbilitySlice::OnStop();
169 }
170 } // namespace OHOS
171