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 "launcher.h"
17 #include "log.h"
18
19 namespace OHOS {
InitUI()20 void Launcher::InitUI()
21 {
22 rootView_ = RootView::GetInstance();
23 rootView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
24 HILOG_DEBUG(HILOG_MODULE_APP, "rootView %d-%d", rootView_->GetWidth(), rootView_->GetHeight());
25
26 const int img_x = 25;
27 const int img_y = 75;
28 const int img_w = 400;
29 const int img_h = 300;
30 const char LAUNCHER_GIF_PATH[] = "/data/img/launcher.gif";
31
32 gifImageView_ = new UIImageView();
33 gifImageView_->SetPosition(img_x, img_y, img_w, img_h);
34 gifImageView_->SetSrc(LAUNCHER_GIF_PATH);
35 rootView_->Add(gifImageView_);
36 rootView_->Invalidate();
37 }
38
DeleteUI()39 void Launcher::DeleteUI()
40 {
41 HILOG_DEBUG(HILOG_MODULE_APP, "%s", __func__);
42 if (gifImageView_ != nullptr) {
43 delete gifImageView_;
44 gifImageView_ = nullptr;
45 }
46 }
47
~Launcher()48 Launcher::~Launcher()
49 {
50 DeleteUI();
51 }
52
OnCreate(const Want &want)53 void Launcher::OnCreate(const Want &want)
54 {
55 HILOG_DEBUG(HILOG_MODULE_APP, "%s", __func__);
56 }
57
OnForeground(const Want &want)58 void Launcher::OnForeground(const Want &want)
59 {
60 HILOG_DEBUG(HILOG_MODULE_APP, "%s", __func__);
61 InitUI();
62 }
63
OnBackground()64 void Launcher::OnBackground()
65 {
66 HILOG_DEBUG(HILOG_MODULE_APP, "%s", __func__);
67 DeleteUI();
68 }
69
OnDestroy()70 void Launcher::OnDestroy()
71 {
72 HILOG_DEBUG(HILOG_MODULE_APP, "%s", __func__);
73 DeleteUI();
74 }
75 } // namespace OHOS
76
77 extern "C" int InstallNativeAbility(const AbilityInfo *abilityInfo, const OHOS::SliteAbility *ability);
InstallLauncher()78 extern "C" void InstallLauncher()
79 {
80 OHOS::Launcher *launcher = OHOS::Launcher::GetInstance();
81 InstallNativeAbility(NULL, launcher);
82 }
83