• 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 "app_ability_slice.h"
17 #include "gfx_utils/style.h"
18 
19 namespace OHOS {
REGISTER_AS(AppAbilitySlice)20 REGISTER_AS(AppAbilitySlice)
21 
22 AppAbilitySlice::~AppAbilitySlice()
23 {
24     if (scrollView_) {
25         DeleteChildren(scrollView_);
26         scrollView_ = nullptr;
27     }
28     if (headView_) {
29         DeleteChildren(headView_);
30         headView_ = nullptr;
31     }
32     if (buttonBackListener_) {
33         delete buttonBackListener_;
34         buttonBackListener_ = nullptr;
35     }
36     if (buttonAppInfoListener_) {
37         delete buttonAppInfoListener_;
38         buttonAppInfoListener_ = nullptr;
39     }
40     if (pBundleInfos_) {
41         ClearBundleInfo(pBundleInfos_);
42     }
43 }
44 
SetButtonListener(void)45 void AppAbilitySlice::SetButtonListener(void)
46 {
47     auto onClick1 = [this](UIView& view, const Event& event) -> bool {
48         Want want1 = { nullptr };
49         AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("MainAbilitySlice");
50         if (nextSlice == nullptr) {
51             printf("[warning]undefined SettingWifiAbilitySlice\n");
52         } else {
53             Present(*nextSlice, want1);
54         }
55         return true;
56     };
57     buttonBackListener_ = new EventListener(onClick1, nullptr);
58 }
59 
SetAppButtonListener(const char * appName)60 void AppAbilitySlice::SetAppButtonListener(const char* appName)
61 {
62     auto onClick2 = [this, appName](UIView& view, const Event& event) -> bool {
63         Want want1 = { nullptr };
64         bool ret = SetWantData(&want1, appName, strlen(appName) + 1);
65         if (ret != true) {
66             return false;
67         }
68         StartAbility(want1);
69         AbilitySlice* nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("AppInfoAbilitySlice");
70         if (nextSlice == nullptr) {
71             printf("[warning]undefined SettingWifiAbilitySlice\n");
72         } else {
73             Present(*nextSlice, want1);
74         }
75         ClearWant(&want1);
76         return true;
77     };
78     buttonAppInfoListener_ = new EventListener(onClick2, nullptr);
79 }
80 
SetHead()81 void AppAbilitySlice::SetHead()
82 {
83     headView_ = new UIViewGroup();
84     rootView_->Add(headView_);
85     headView_->SetPosition(DE_HEAD_X, DE_HEAD_Y, DE_HEAD_WIDTH, DE_HEAD_HEIGHT);
86     headView_->SetStyle(STYLE_BACKGROUND_OPA, 0);
87     headView_->SetTouchable(true);
88     headView_->SetOnClickListener(buttonBackListener_);
89 
90     UIImageView* imageView = new UIImageView();
91     headView_->Add(imageView);
92     imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT);
93     imageView->SetSrc(DE_IMAGE_BACK);
94 
95     UILabel* lablelFont = new UILabel();
96     lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT);
97     lablelFont->SetText("应用");
98     lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE);
99     lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR);
100     headView_->Add(lablelFont);
101 }
102 
SetAnAppInfo(const int count,BundleInfo & pBundleInfo)103 void AppAbilitySlice::SetAnAppInfo(const int count, BundleInfo& pBundleInfo)
104 {
105     UIViewGroup* itemView = new UIViewGroup();
106     char buff[64] = {0};
107     int useX = 0;
108     int useY = count * DE_ITEM_INTERVAL;
109     itemView->SetPosition(useX, useY, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT);
110     itemView->SetStyle(STYLE_BACKGROUND_COLOR, DE_BUTTON_BACKGROUND_COLOR);
111     itemView->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
112     itemView->SetStyle(STYLE_BORDER_RADIUS, DE_BUTTON_RADIUS);
113     itemView->SetTouchable(true);
114 
115     int err = strcpy_s(buff, sizeof(buff), pBundleInfo.bundleName);
116     if (err != EOK) {
117         printf("[ERROR]strcpy_s pBundleInfo.bundleName failed, err = %d\n", err);
118         return;
119     }
120     SetAppButtonListener(pBundleInfo.bundleName);
121     itemView->SetOnClickListener(buttonAppInfoListener_);
122     scrollView_->Add(itemView);
123 
124     UIImageView* imageIdView = new UIImageView();
125     imageIdView->SetPosition(APP_IMAGE_X, APP_IMAGE_Y, APP_IMAGE_WIDTH, APP_IMAGE_HEIGHT);
126     imageIdView->SetStyle(STYLE_BACKGROUND_OPA, DE_OPACITY_ALL);
127     imageIdView->SetSrc(DE_IMAGE_APP);
128     itemView->Add(imageIdView);
129 
130     int bundleNameOffset = 11;
131     UILabel* name = new UILabel();
132     name->SetPosition(APP_NAME_X, APP_NAME_Y, DE_TITLE_TEXT_WIDTH, DE_TITLE_TEXT_HEIGHT);
133     name->SetText(pBundleInfo.bundleName + bundleNameOffset);
134     name->SetFont(DE_FONT_OTF, DE_TITLE_TEXT_SIZE);
135     name->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR);
136     itemView->Add(name);
137 
138     UIImageView* imageView = new UIImageView();
139     imageView->SetPosition(DE_FORWARD_IMG_X, DE_FORWARD_IMG_Y, DE_FORWARD_IMG_WIDTH, DE_FORWARD_IMG_HEIGHT);
140     imageView->SetSrc(DE_IMAGE_FORWORD);
141     itemView->Add(imageView);
142 }
143 
SetScrollView()144 void AppAbilitySlice::SetScrollView()
145 {
146     scrollView_ = new UIScrollView();
147     scrollView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_SCROLL_COLOR);
148     scrollView_->SetPosition(DE_SCROLL_X, DE_SCROLL_Y, DE_SCROLL_WIDTH, DE_SCROLL_HEIGHT);
149     scrollView_->SetXScrollBarVisible(false);
150     scrollView_->SetYScrollBarVisible(true);
151     rootView_->Add(scrollView_);
152 
153     uint8_t ret = -1;
154     int num = 0;
155     ret = GetBundleInfos(1, &pBundleInfos_, &num);
156     if (ret == 0) {
157         BundleInfo* pBundleInfo = pBundleInfos_;
158         for (int count = 0; count < num; count++, pBundleInfo++) {
159             printf("[LOG]pBundleInfo.bundleName->%s versionName->%s \n",
160                 pBundleInfo->bundleName, pBundleInfo->versionName);
161             if (pBundleInfo->isSystemApp == false) {
162                 SetAnAppInfo(count, *pBundleInfo);
163             }
164         }
165     }
166 }
167 
OnStart(const Want & want)168 void AppAbilitySlice::OnStart(const Want& want)
169 {
170     AbilitySlice::OnStart(want);
171 
172     rootView_ = RootView::GetWindowRootView();
173     rootView_->SetPosition(DE_ROOT_X, DE_ROOT_Y, DE_ROOT_WIDTH, DE_ROOT_HEIGHT);
174     rootView_->SetStyle(STYLE_BACKGROUND_COLOR, DE_ROOT_BACKGROUND_COLOR);
175     SetButtonListener();
176     SetHead();
177     SetScrollView();
178     SetUIContent(rootView_);
179 }
180 
OnInactive()181 void AppAbilitySlice::OnInactive()
182 {
183     AbilitySlice::OnInactive();
184 }
185 
OnActive(const Want & want)186 void AppAbilitySlice::OnActive(const Want &want)
187 {
188     AbilitySlice::OnActive(want);
189 }
190 
OnBackground()191 void AppAbilitySlice::OnBackground()
192 {
193     AbilitySlice::OnBackground();
194 }
195 
OnStop()196 void AppAbilitySlice::OnStop()
197 {
198     AbilitySlice::OnStop();
199 }
200 } // namespace OHOS
201