• 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 "ability_window.h"
17 
18 #include "log.h"
19 
20 namespace OHOS {
SetRootView(RootView * rootView,int16_t x,int16_t y)21 void AbilityWindow::SetRootView(RootView *rootView, int16_t x, int16_t y)
22 {
23     if (rootView == nullptr) {
24         return;
25     }
26 
27     if (window_ == nullptr) {
28         WindowConfig config = {};
29         config.rect = rootView->GetRect();
30         config.rect.SetPosition(x, y);
31         window_ = Window::CreateWindow(config);
32         if (window_ == nullptr) {
33             return;
34         }
35     } else {
36         Rect rect = rootView->GetRect();
37         window_->Resize(rect.GetWidth(), rect.GetHeight());
38         window_->MoveTo(x, y);
39     }
40 
41     window_->UnbindRootView();
42     window_->BindRootView(rootView);
43     rootView->Invalidate();
44 
45     isWindowAttached_ = true;
46 }
47 
EnsureLatestUIAttached() const48 void AbilityWindow::EnsureLatestUIAttached() const
49 {
50     if (!isWindowAttached_ || (window_ == nullptr)) {
51         HILOG_ERROR(HILOG_MODULE_APP, "Should SetUIContent before slice active");
52         exit(-1);
53     }
54 }
55 
OnPostAbilityStart()56 void AbilityWindow::OnPostAbilityStart()
57 {
58     EnsureLatestUIAttached();
59 
60     window_->Show();
61 }
62 
OnPostAbilityActive()63 void AbilityWindow::OnPostAbilityActive()
64 {
65     EnsureLatestUIAttached();
66 
67     window_->RaiseToTop();
68     window_->Show();
69 }
70 
OnPostAbilityBackground()71 void AbilityWindow::OnPostAbilityBackground()
72 {
73     EnsureLatestUIAttached();
74 
75     window_->Hide();
76 }
77 
OnPostAbilityStop()78 void AbilityWindow::OnPostAbilityStop()
79 {
80     EnsureLatestUIAttached();
81 
82     window_->UnbindRootView();
83     Window::DestoryWindow(window_);
84     window_ = nullptr;
85 }
86 } // namespace OHOS
87