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      * @return true if an on-going bind operation was cancelled
58      */
cancelBind( @onNull NotificationEntry entry, @NonNull ExpandableNotificationRow row)59     boolean cancelBind(
60             @NonNull NotificationEntry entry,
61             @NonNull ExpandableNotificationRow row);
62 
63     /**
64      * Unbind content views from the row.
65      *
66      * @param entry notification
67      * @param row notification row to unbind content views from
68      * @param contentToUnbind content views that should be unbound
69      */
unbindContent( @onNull NotificationEntry entry, @NonNull ExpandableNotificationRow row, @InflationFlag int contentToUnbind)70     void unbindContent(
71             @NonNull NotificationEntry entry,
72             @NonNull ExpandableNotificationRow row,
73             @InflationFlag int contentToUnbind);
74 
75     @Retention(RetentionPolicy.SOURCE)
76     @IntDef(flag = true,
77             prefix = {"FLAG_CONTENT_VIEW_"},
78             value = {
79                     FLAG_CONTENT_VIEW_CONTRACTED,
80                     FLAG_CONTENT_VIEW_EXPANDED,
81                     FLAG_CONTENT_VIEW_HEADS_UP,
82                     FLAG_CONTENT_VIEW_PUBLIC,
83                     FLAG_CONTENT_VIEW_ALL})
84     @interface InflationFlag {}
85     /**
86      * The default, contracted view.  Seen when the shade is pulled down and in the lock screen
87      * if there is no worry about content sensitivity.
88      */
89     int FLAG_CONTENT_VIEW_CONTRACTED = 1;
90     /**
91      * The expanded view.  Seen when the user expands a notification.
92      */
93     int FLAG_CONTENT_VIEW_EXPANDED = 1 << 1;
94     /**
95      * The heads up view.  Seen when a high priority notification peeks in from the top.
96      */
97     int FLAG_CONTENT_VIEW_HEADS_UP = 1 << 2;
98     /**
99      * The public view.  This is a version of the contracted view that hides sensitive
100      * information and is used on the lock screen if we determine that the notification's
101      * content should be hidden.
102      */
103     int FLAG_CONTENT_VIEW_PUBLIC = 1 << 3;
104 
105     int FLAG_CONTENT_VIEW_ALL = (1 << 4) - 1;
106 
107     /**
108      * Parameters for content view binding
109      */
110     class BindParams {
111 
112         /**
113          * Bind a low priority version of the content views.
114          */
115         public boolean isLowPriority;
116 
117         /**
118          * Use increased height when binding contracted view.
119          */
120         public boolean usesIncreasedHeight;
121 
122         /**
123          * Use increased height when binding heads up views.
124          */
125         public boolean usesIncreasedHeadsUpHeight;
126     }
127 
128     /**
129      * Callback for inflation finishing
130      */
131     interface InflationCallback {
132 
133         /**
134          * Callback for when there is an inflation exception
135          *
136          * @param entry notification which failed to inflate content
137          * @param e exception
138          */
handleInflationException(NotificationEntry entry, Exception e)139         void handleInflationException(NotificationEntry entry, Exception e);
140 
141         /**
142          * Callback for after the content views finish inflating.
143          *
144          * @param entry the entry with the content views set
145          */
onAsyncInflationFinished(NotificationEntry entry)146         void onAsyncInflationFinished(NotificationEntry entry);
147     }
148 }
149