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_info.h"
17 #include "ui_config.h"
18
19 namespace OHOS {
AppInfo()20 AppInfo::AppInfo()
21 {
22 ReSet();
23 }
Release()24 void AppInfo::Release()
25 {
26 if (button_) {
27 delete button_;
28 button_ = nullptr;
29 }
30 if (lable_) {
31 delete lable_;
32 lable_ = nullptr;
33 }
34 if (appClickListener_) {
35 delete appClickListener_;
36 appClickListener_ = nullptr;
37 }
38 if (appLpListener_) {
39 delete appLpListener_;
40 appLpListener_ = nullptr;
41 }
42 }
43
~AppInfo()44 AppInfo::~AppInfo()
45 {
46 Release();
47 }
48
ReSet()49 void AppInfo::ReSet()
50 {
51 button_ = nullptr;
52 lable_ = nullptr;
53 appClickListener_ = nullptr;
54 appLpListener_ = nullptr;
55 }
56
SetButton(UILabelButton * button)57 void AppInfo::SetButton(UILabelButton* button)
58 {
59 button->SetPosition(buttonXY_.x, buttonXY_.y, buttonHV_.x, buttonHV_.y);
60 button->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
61 button->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED);
62 button->SetStyleForState(STYLE_BACKGROUND_OPA, TOTAL_OPACITY, UIButton::PRESSED);
63 button->SetStyleForState(STYLE_BORDER_OPA, TOTAL_OPACITY, UIButton::PRESSED);
64 button->SetStyle(STYLE_BORDER_RADIUS, BUTTON_RADIUS);
65 button->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
66 button->SetStyle(STYLE_BORDER_OPA, TOTAL_OPACITY);
67 button->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White()));
68 button->SetImageSrc(appIconDir_, appIconDir_);
69 button_ = button;
70 }
71
SetLable(UILabel * lable)72 void AppInfo::SetLable(UILabel* lable)
73 {
74 lable->SetPosition(lableXY_.x, lableXY_.y, lableHV_.x, lableHV_.y);
75 char* p = strrchr(appName_, static_cast<int>('.'));
76 if (p != nullptr) {
77 lable->SetText(p + 1);
78 } else {
79 lable->SetText(appName_);
80 }
81 lable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP);
82 lable->SetFont(FOND_PATH, APP_FOND_ID);
83 lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS);
84 lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
85 lable_ = lable;
86 }
87
SetListener(AppInfo * app)88 void AppInfo::SetListener(AppInfo* app)
89 {
90 AppClickListener* clickListener = new AppClickListener(app->funcclick_, this);
91 button_->SetOnClickListener(clickListener);
92 appClickListener_ = static_cast<UIView::OnClickListener*>(clickListener);
93 AppLongPressListener* lPListener = new AppLongPressListener(app->funclPress_, this);
94 button_->SetOnLongPressListener(lPListener);
95 appLpListener_ = static_cast<UIView::OnLongPressListener*>(lPListener);
96 button_->SetDraggable(true);
97 }
98
SetLocation(int16_t r,int16_t c)99 void AppInfo::SetLocation(int16_t r, int16_t c)
100 {
101 row_col_.x = r;
102 row_col_.y = c;
103 }
104 } // namespace OHOS
105