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 
16 #include "logo_strategy.h"
17 #include <functional>
18 #include "component/box_progress_adapter.h"
19 #include "component/img_view_adapter.h"
20 #include "component/text_label_adapter.h"
21 #include "log/log.h"
22 #include "updater_ui_env.h"
23 
24 namespace Updater {
Factory(const std::string & type,const ComInfo & id)25 std::unique_ptr<LogoStrategy> LogoStrategy::Factory(const std::string &type, const ComInfo &id)
26 {
27     using Fun = std::function<std::unique_ptr<LogoStrategy>(const ComInfo &)>;
28     const static std::unordered_map<std::string, Fun> logoMap {
29         { "img", [] (const ComInfo &id) { return std::make_unique<ImageLogo>(id); }},
30         { "anim", [] (const ComInfo &id) { return std::make_unique<AnimatorLogo>(id); }},
31     };
32     if (auto it = logoMap.find(type); it != logoMap.end()) {
33         return it->second(id);
34     }
35     LOG(ERROR) << "not recognized logo type " << type;
36     return std::make_unique<ImageLogo>(id);
37 }
38 
Show() const39 void AnimatorLogo::Show() const
40 {
41     pgMgr_[id_]->SetVisible(true);
42     pgMgr_[id_].As<ImgViewAdapter>()->Start();
43 }
44 
Hide() const45 void AnimatorLogo::Hide() const
46 {
47     pgMgr_[id_].As<ImgViewAdapter>()->Stop();
48     pgMgr_[id_]->SetVisible(false);
49 }
50 
Show() const51 void ImageLogo::Show() const
52 {
53     pgMgr_[id_]->SetVisible(true);
54 }
55 
Hide() const56 void ImageLogo::Hide() const
57 {
58     pgMgr_[id_]->SetVisible(false);
59 }
60 } // namespace Updater