• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "text_label_adapter.h"
16 #include "language/language_ui.h"
17 #include "log/log.h"
18 #include "updater_ui_const.h"
19 #include "view_api.h"
20 namespace Updater {
TextLabelAdapter(const UxViewInfo & info)21 TextLabelAdapter::TextLabelAdapter(const UxViewInfo &info)
22 {
23     const UxLabelInfo &spec = std::get<UxLabelInfo>(info.specificInfo);
24     SetViewCommonInfo(info.commonInfo);
25     this->SetAlign(GetAlign(spec.align), OHOS::TEXT_ALIGNMENT_CENTER);
26     this->SetText(TranslateText(spec.text).c_str());
27     this->SetFont(DEFAULT_FONT_FILENAME, spec.fontSize);
28     auto fontColor = StrToColor(spec.fontColor);
29     this->SetStyle(OHOS::STYLE_TEXT_COLOR, fontColor.full);
30     this->SetStyle(OHOS::STYLE_TEXT_OPA, fontColor.alpha);
31     auto bgColor = StrToColor(spec.bgColor);
32     this->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, bgColor.full);
33     this->SetStyle(OHOS::STYLE_BACKGROUND_OPA, bgColor.alpha);
34 }
35 
IsValid(const UxLabelInfo & info)36 bool TextLabelAdapter::IsValid(const UxLabelInfo &info)
37 {
38     if (info.fontSize > MAX_FONT_SIZE) {
39         LOG(ERROR) << "label viewinfo check failed, fontSize: " << info.fontSize;
40         return false;
41     }
42 
43     if (!CheckColor(info.bgColor) || !CheckColor(info.fontColor)) {
44         LOG(ERROR) << "label viewinfo check failed, bgColor:" << info.bgColor <<
45             " fontColor:" << info.fontColor;
46         return false;
47     }
48     return true;
49 }
50 
SetText(const std::string & txt)51 void TextLabelAdapter::SetText(const std::string &txt)
52 {
53     // usage of "*" is same as label button's SetText
54     if (txt == "*") {
55         return;
56     }
57     OHOS::UILabel::SetText(txt.c_str());
58 }
59 } // namespace Updater
60