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