• 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 "screensaver_ability_slice.h"
17 #include "common/screen.h"
18 
19 namespace OHOS {
20 REGISTER_AS(ScreensaverAbilitySlice)
21 namespace {
22     int16_t screenWidth = static_cast<int16_t>(Screen::GetInstance().GetWidth());
23     int16_t screenHeight = static_cast<int16_t>(Screen::GetInstance().GetHeight());
24 }
25 static ImageAnimatorInfo g_imageAnimatorInfo[IMAGE_TOTEL_NUM] = {
26     {{IMG_DEFAULT_001_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
27     {{IMG_DEFAULT_002_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
28     {{IMG_DEFAULT_003_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
29     {{IMG_DEFAULT_004_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
30     {{IMG_DEFAULT_005_PATH}, {0, 0}, screenWidth, screenHeight, IMG_SRC_FILE_PATH},
31 };
32 
~ScreensaverAbilitySlice()33 ScreensaverAbilitySlice::~ScreensaverAbilitySlice()
34 {
35     if (imageAnimator_ != nullptr) {
36         delete imageAnimator_;
37         imageAnimator_ = nullptr;
38     }
39 
40     if (exitListener_ != nullptr) {
41         delete exitListener_;
42         exitListener_ = nullptr;
43     }
44 }
45 
SetCyclePlayView()46 void ScreensaverAbilitySlice::SetCyclePlayView()
47 {
48     imageAnimator_ = new UIImageAnimatorView();
49     imageAnimator_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
50     imageAnimator_->SetImageAnimatorSrc(g_imageAnimatorInfo, IMAGE_TOTEL_NUM, IMAGE_ANIMATOR_TIME_S);
51     rootView_->Add(imageAnimator_);
52 
53     auto onClick = [this] (UIView& view, const Event& event) -> bool {
54         TerminateAbility();
55         return true;
56     };
57     exitListener_ = new EventListener(onClick, nullptr);
58     imageAnimator_->SetOnClickListener(exitListener_);
59     imageAnimator_->SetTouchable(true);
60 
61     imageAnimator_->Start();
62 }
63 
OnStart(const Want & want)64 void ScreensaverAbilitySlice::OnStart(const Want &want)
65 {
66     rootView_ = RootView::GetWindowRootView();
67     rootView_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
68     rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
69 
70     SetCyclePlayView();
71     SetUIContent(rootView_);
72     rootView_->Invalidate();
73     AbilitySlice::OnStart(want);
74 }
75 
OnInactive()76 void ScreensaverAbilitySlice::OnInactive()
77 {
78     printf("ScreensaverAbilitySlice::OnInactive\n");
79     AbilitySlice::OnInactive();
80 }
81 
OnActive(const Want & want)82 void ScreensaverAbilitySlice::OnActive(const Want &want)
83 {
84     printf("ScreensaverAbilitySlice::OnActive\n");
85     AbilitySlice::OnActive(want);
86 }
87 
OnBackground()88 void ScreensaverAbilitySlice::OnBackground()
89 {
90     printf("ScreensaverAbilitySlice::OnBackground\n");
91     AbilitySlice::OnBackground();
92 }
93 
OnStop()94 void ScreensaverAbilitySlice::OnStop()
95 {
96     printf("ScreensaverAbilitySlice::OnStop\n");
97     AbilitySlice::OnStop();
98 }
99 } // namespace OHOS
100