• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.notification.row;
18 
19 import static com.android.systemui.statusbar.NotificationLockscreenUserManager.REDACTION_TYPE_NONE;
20 import static com.android.systemui.statusbar.NotificationLockscreenUserManager.RedactionType;
21 import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_CONTRACTED;
22 import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_EXPANDED;
23 
24 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
25 
26 /**
27  * Parameters for {@link RowContentBindStage}.
28  */
29 public final class RowContentBindParams {
30     private boolean mUseMinimized;
31     private boolean mViewsNeedReinflation;
32     private @InflationFlag int mContentViews = DEFAULT_INFLATION_FLAGS;
33     private @RedactionType int mRedactionType = REDACTION_TYPE_NONE;
34 
35     /**
36      * Content views that are out of date and need to be rebound.
37      *
38      * TODO: This should go away once {@link NotificationRowContentBinder} is broken down into
39      * smaller stages as then the stage itself would be invalidated.
40      */
41     private @InflationFlag int mDirtyContentViews = mContentViews;
42 
43     /**
44      * Set whether content should use a minimized version of its content views.
45      */
setUseMinimized(boolean useMinimized)46     public void setUseMinimized(boolean useMinimized) {
47         if (mUseMinimized != useMinimized) {
48             mDirtyContentViews |= (FLAG_CONTENT_VIEW_CONTRACTED | FLAG_CONTENT_VIEW_EXPANDED);
49         }
50         mUseMinimized = useMinimized;
51     }
52 
53     /**
54      * @return Whether the row uses the minimized style.
55      */
useMinimized()56     public boolean useMinimized() {
57         return mUseMinimized;
58     }
59 
60     /**
61      * @return What type of redaction should be used by the public view (if requested)
62      */
getRedactionType()63     public @RedactionType int getRedactionType() {
64         return mRedactionType;
65     }
66 
67     /**
68      * Set the redaction type, which controls what sort of public view is shown.
69      */
setRedactionType(@edactionType int redactionType)70     public void setRedactionType(@RedactionType int redactionType) {
71         mRedactionType = redactionType;
72     }
73 
74     /**
75      * Require the specified content views to be bound after the rebind request.
76      *
77      * @see InflationFlag
78      */
requireContentViews(@nflationFlag int contentViews)79     public void requireContentViews(@InflationFlag int contentViews) {
80         @InflationFlag int newContentViews = contentViews &= ~mContentViews;
81         mContentViews |= contentViews;
82         mDirtyContentViews |= newContentViews;
83     }
84 
85     /**
86      * Mark the content view to be freed. The view may not be immediately freeable since it may
87      * be visible and animating out but this lets the binder know to free the view when safe.
88      * Note that the callback passed into {@link RowContentBindStage#requestRebind}
89      * may return before the view is actually freed since the view is considered up-to-date.
90      *
91      * @see InflationFlag
92      */
markContentViewsFreeable(@nflationFlag int contentViews)93     public void markContentViewsFreeable(@InflationFlag int contentViews) {
94         @InflationFlag int existingFreeableContentViews = contentViews &= mContentViews;
95         mContentViews &= ~contentViews;
96         mDirtyContentViews |= existingFreeableContentViews;
97     }
98 
getContentViews()99     public @InflationFlag int getContentViews() {
100         return mContentViews;
101     }
102 
103     /**
104      * Request that all content views be rebound. This may happen if, for example, the underlying
105      * layout has changed.
106      */
rebindAllContentViews()107     public void rebindAllContentViews() {
108         mDirtyContentViews = mContentViews;
109     }
110 
111     /**
112      * Clears all dirty content views so that they no longer need to be rebound.
113      */
clearDirtyContentViews()114     void clearDirtyContentViews() {
115         mDirtyContentViews = 0;
116     }
117 
getDirtyContentViews()118     public @InflationFlag int getDirtyContentViews() {
119         return mDirtyContentViews;
120     }
121 
122     /**
123      * Set whether all content views need to be reinflated even if cached.
124      *
125      * TODO: This should probably be a more global config on {@link NotifBindPipeline} since this
126      * generally corresponds to a Context/Configuration change that all stages should know about.
127      */
setNeedsReinflation(boolean needsReinflation)128     public void setNeedsReinflation(boolean needsReinflation) {
129         mViewsNeedReinflation = needsReinflation;
130         @InflationFlag int currentContentViews = mContentViews;
131         mDirtyContentViews |= currentContentViews;
132     }
133 
needsReinflation()134     public boolean needsReinflation() {
135         return mViewsNeedReinflation;
136     }
137 
138     @Override
toString()139     public String toString() {
140         return String.format("RowContentBindParams[mContentViews=%x mDirtyContentViews=%x "
141                 + "mUseMinimized=%b mViewsNeedReinflation=%b]",
142                 mContentViews, mDirtyContentViews, mUseMinimized, mViewsNeedReinflation);
143     }
144 
145     /**
146      * Content views that should be inflated by default for all notifications.
147      */
148     @InflationFlag private static final int DEFAULT_INFLATION_FLAGS =
149             FLAG_CONTENT_VIEW_CONTRACTED | FLAG_CONTENT_VIEW_EXPANDED;
150 }
151