• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.statusbar;
18 
19 import android.content.Context;
20 import android.view.LayoutInflater;
21 import android.view.ViewGroup;
22 
23 import com.android.systemui.R;
24 import com.android.systemui.dagger.SysUISingleton;
25 import com.android.systemui.statusbar.notification.row.dagger.NotificationShelfComponent;
26 import com.android.systemui.statusbar.phone.NotificationPanelView;
27 import com.android.systemui.statusbar.phone.NotificationShadeWindowView;
28 import com.android.systemui.statusbar.phone.StatusBarWindowView;
29 import com.android.systemui.util.InjectionInflationController;
30 
31 import javax.inject.Inject;
32 
33 /**
34  * Creates a single instance of super_status_bar and super_notification_shade that can be shared
35  * across various system ui objects.
36  */
37 @SysUISingleton
38 public class SuperStatusBarViewFactory {
39 
40     private final Context mContext;
41     private final InjectionInflationController mInjectionInflationController;
42     private final NotificationShelfComponent.Builder mNotificationShelfComponentBuilder;
43 
44     private NotificationShadeWindowView mNotificationShadeWindowView;
45     private StatusBarWindowView mStatusBarWindowView;
46     private NotificationShelfController mNotificationShelfController;
47 
48     @Inject
SuperStatusBarViewFactory(Context context, InjectionInflationController injectionInflationController, NotificationShelfComponent.Builder notificationShelfComponentBuilder)49     public SuperStatusBarViewFactory(Context context,
50             InjectionInflationController injectionInflationController,
51             NotificationShelfComponent.Builder notificationShelfComponentBuilder) {
52         mContext = context;
53         mInjectionInflationController = injectionInflationController;
54         mNotificationShelfComponentBuilder = notificationShelfComponentBuilder;
55     }
56 
57     /**
58      * Gets the inflated {@link NotificationShadeWindowView} from
59      * {@link R.layout#super_notification_shade}.
60      * Returns a cached instance, if it has already been inflated.
61      */
getNotificationShadeWindowView()62     public NotificationShadeWindowView getNotificationShadeWindowView() {
63         if (mNotificationShadeWindowView != null) {
64             return mNotificationShadeWindowView;
65         }
66 
67         mNotificationShadeWindowView = (NotificationShadeWindowView)
68                 mInjectionInflationController.injectable(
69                 LayoutInflater.from(mContext)).inflate(R.layout.super_notification_shade,
70                 /* root= */ null);
71         if (mNotificationShadeWindowView == null) {
72             throw new IllegalStateException(
73                     "R.layout.super_notification_shade could not be properly inflated");
74         }
75 
76         return mNotificationShadeWindowView;
77     }
78 
79     /**
80      * Gets the inflated {@link StatusBarWindowView} from {@link R.layout#super_status_bar}.
81      * Returns a cached instance, if it has already been inflated.
82      */
getStatusBarWindowView()83     public StatusBarWindowView getStatusBarWindowView() {
84         if (mStatusBarWindowView != null) {
85             return mStatusBarWindowView;
86         }
87 
88         mStatusBarWindowView =
89                 (StatusBarWindowView) mInjectionInflationController.injectable(
90                 LayoutInflater.from(mContext)).inflate(R.layout.super_status_bar,
91                 /* root= */ null);
92         if (mStatusBarWindowView == null) {
93             throw new IllegalStateException(
94                     "R.layout.super_status_bar could not be properly inflated");
95         }
96         return mStatusBarWindowView;
97     }
98 
99     /**
100      * Gets the inflated {@link NotificationShelf} from
101      * {@link R.layout#status_bar_notification_shelf}.
102      * Returns a cached instance, if it has already been inflated.
103      *
104      * @param container the expected container to hold the {@link NotificationShelf}. The view
105      *                  isn't immediately attached, but the layout params of this view is used
106      *                  during inflation.
107      */
getNotificationShelfController(ViewGroup container)108     public NotificationShelfController getNotificationShelfController(ViewGroup container) {
109         if (mNotificationShelfController != null) {
110             return mNotificationShelfController;
111         }
112 
113         NotificationShelf view = (NotificationShelf) LayoutInflater.from(mContext)
114                 .inflate(R.layout.status_bar_notification_shelf, container, /* attachToRoot= */
115                         false);
116 
117         if (view == null) {
118             throw new IllegalStateException(
119                     "R.layout.status_bar_notification_shelf could not be properly inflated");
120         }
121 
122         NotificationShelfComponent component = mNotificationShelfComponentBuilder
123                 .notificationShelf(view)
124                 .build();
125         mNotificationShelfController = component.getNotificationShelfController();
126         mNotificationShelfController.init();
127 
128         return mNotificationShelfController;
129     }
130 
getNotificationPanelView()131     public NotificationPanelView getNotificationPanelView() {
132         NotificationShadeWindowView notificationShadeWindowView = getNotificationShadeWindowView();
133         if (notificationShadeWindowView == null) {
134             return null;
135         }
136 
137         return mNotificationShadeWindowView.findViewById(R.id.notification_panel);
138     }
139 }
140