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.notification.row;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 
23 import androidx.annotation.VisibleForTesting;
24 
25 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
26 
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 
30 /**
31  * Binder that takes a notifications {@link ExpandableNotificationRow} and binds the appropriate
32  * content to it based off the bind parameters passed to it.
33  */
34 public interface NotificationRowContentBinder {
35 
36     /**
37      * Inflate notification content views and bind to the row.
38      *
39      * @param entry notification
40      * @param row notification row to bind views to
41      * @param contentToBind content views that should be inflated and bound
42      * @param bindParams parameters for binding content views
43      * @param forceInflate true to force reinflation even if views are cached
44      * @param callback callback after inflation is finished
45      */
bindContent( @onNull NotificationEntry entry, @NonNull ExpandableNotificationRow row, @InflationFlag int contentToBind, BindParams bindParams, boolean forceInflate, @Nullable InflationCallback callback)46     void bindContent(
47             @NonNull NotificationEntry entry,
48             @NonNull ExpandableNotificationRow row,
49             @InflationFlag int contentToBind,
50             BindParams bindParams,
51             boolean forceInflate,
52             @Nullable InflationCallback callback);
53 
54     /**
55      * Cancel any on-going bind operation.
56      *
57      * @param entry notification
58      * @param row notification row to cancel bind on
59      * @return true if an on-going bind operation was cancelled
60      */
cancelBind( @onNull NotificationEntry entry, @NonNull ExpandableNotificationRow row)61     boolean cancelBind(
62             @NonNull NotificationEntry entry,
63             @NonNull ExpandableNotificationRow row);
64 
65     /**
66      * Unbind content views from the row.
67      *
68      * @param entry notification
69      * @param row notification row to unbind content views from
70      * @param contentToUnbind content views that should be unbound
71      */
unbindContent( @onNull NotificationEntry entry, @NonNull ExpandableNotificationRow row, @InflationFlag int contentToUnbind)72     void unbindContent(
73             @NonNull NotificationEntry entry,
74             @NonNull ExpandableNotificationRow row,
75             @InflationFlag int contentToUnbind);
76 
77     /** For testing, ensure all inflation is synchronous. */
78     @VisibleForTesting
setInflateSynchronously(boolean inflateSynchronously)79     void setInflateSynchronously(boolean inflateSynchronously);
80 
81     @Retention(RetentionPolicy.SOURCE)
82     @IntDef(flag = true,
83             prefix = {"FLAG_CONTENT_VIEW_"},
84             value = {
85                     FLAG_CONTENT_VIEW_CONTRACTED,
86                     FLAG_CONTENT_VIEW_EXPANDED,
87                     FLAG_CONTENT_VIEW_HEADS_UP,
88                     FLAG_CONTENT_VIEW_PUBLIC,
89                     FLAG_CONTENT_VIEW_SINGLE_LINE,
90                     FLAG_GROUP_SUMMARY_HEADER,
91                     FLAG_LOW_PRIORITY_GROUP_SUMMARY_HEADER,
92                     FLAG_CONTENT_VIEW_ALL})
93     @interface InflationFlag {}
94     /**
95      * The default, contracted view.  Seen when the shade is pulled down and in the lock screen
96      * if there is no worry about content sensitivity.
97      */
98     int FLAG_CONTENT_VIEW_CONTRACTED = 1;
99     /**
100      * The expanded view.  Seen when the user expands a notification.
101      */
102     int FLAG_CONTENT_VIEW_EXPANDED = 1 << 1;
103     /**
104      * The heads up view.  Seen when a high priority notification peeks in from the top.
105      */
106     int FLAG_CONTENT_VIEW_HEADS_UP = 1 << 2;
107     /**
108      * The public view.  This is a version of the contracted view that hides sensitive
109      * information and is used on the lock screen if we determine that the notification's
110      * content should be hidden.
111      */
112     int FLAG_CONTENT_VIEW_PUBLIC = 1 << 3;
113 
114     /**
115      * The single line notification view. Show when the notification is shown as a child in group.
116      */
117     int FLAG_CONTENT_VIEW_SINGLE_LINE = 1 << 4;
118 
119     /**
120      * The notification group summary header view
121      */
122     int FLAG_GROUP_SUMMARY_HEADER = 1 << 5;
123 
124     /**
125      * The notification low-priority group summary header view
126      */
127     int FLAG_LOW_PRIORITY_GROUP_SUMMARY_HEADER = 1 << 6;
128 
129     int FLAG_CONTENT_VIEW_ALL = (1 << 7) - 1;
130 
131     /**
132      * Parameters for content view binding
133      */
134     class BindParams {
135 
136         /**
137          * Bind a minimized version of the content views.
138          */
139         public boolean isMinimized;
140 
141         /**
142          * Use increased height when binding contracted view.
143          */
144         public boolean usesIncreasedHeight;
145 
146         /**
147          * Use increased height when binding heads up views.
148          */
149         public boolean usesIncreasedHeadsUpHeight;
150     }
151 
152     /**
153      * Callback for inflation finishing
154      */
155     interface InflationCallback {
156 
157         /**
158          * Callback for when there is an inflation exception
159          *
160          * @param entry notification which failed to inflate content
161          * @param e exception
162          */
handleInflationException(NotificationEntry entry, Exception e)163         void handleInflationException(NotificationEntry entry, Exception e);
164 
165         /**
166          * Callback for after the content views finish inflating.
167          *
168          * @param entry the entry with the content views set
169          */
onAsyncInflationFinished(NotificationEntry entry)170         void onAsyncInflationFinished(NotificationEntry entry);
171     }
172 }
173