summaryrefslogtreecommitdiff
path: root/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationRowContentBinder.java
blob: a9f83c8b9e6bd980522ea73f41d279f1cdf41af9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.row;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;

import com.android.systemui.statusbar.notification.collection.NotificationEntry;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Binder that takes a notifications {@link ExpandableNotificationRow} and binds the appropriate
 * content to it based off the bind parameters passed to it.
 */
public interface NotificationRowContentBinder {

    /**
     * Inflate notification content views and bind to the row.
     *
     * @param entry notification
     * @param row notification row to bind views to
     * @param contentToBind content views that should be inflated and bound
     * @param bindParams parameters for binding content views
     * @param forceInflate true to force reinflation even if views are cached
     * @param callback callback after inflation is finished
     */
    void bindContent(
            @NonNull NotificationEntry entry,
            @NonNull ExpandableNotificationRow row,
            @InflationFlag int contentToBind,
            BindParams bindParams,
            boolean forceInflate,
            @Nullable InflationCallback callback);

    /**
     * Cancel any on-going bind operation.
     *
     * @param entry notification
     * @param row notification row to cancel bind on
     */
    void cancelBind(
            @NonNull NotificationEntry entry,
            @NonNull ExpandableNotificationRow row);

    /**
     * Unbind content views from the row.
     *
     * @param entry notification
     * @param row notification row to unbind content views from
     * @param contentToUnbind content views that should be unbound
     */
    void unbindContent(
            @NonNull NotificationEntry entry,
            @NonNull ExpandableNotificationRow row,
            @InflationFlag int contentToUnbind);

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = true,
            prefix = {"FLAG_CONTENT_VIEW_"},
            value = {
                    FLAG_CONTENT_VIEW_CONTRACTED,
                    FLAG_CONTENT_VIEW_EXPANDED,
                    FLAG_CONTENT_VIEW_HEADS_UP,
                    FLAG_CONTENT_VIEW_PUBLIC,
                    FLAG_CONTENT_VIEW_ALL})
    @interface InflationFlag {}
    /**
     * The default, contracted view.  Seen when the shade is pulled down and in the lock screen
     * if there is no worry about content sensitivity.
     */
    int FLAG_CONTENT_VIEW_CONTRACTED = 1;
    /**
     * The expanded view.  Seen when the user expands a notification.
     */
    int FLAG_CONTENT_VIEW_EXPANDED = 1 << 1;
    /**
     * The heads up view.  Seen when a high priority notification peeks in from the top.
     */
    int FLAG_CONTENT_VIEW_HEADS_UP = 1 << 2;
    /**
     * The public view.  This is a version of the contracted view that hides sensitive
     * information and is used on the lock screen if we determine that the notification's
     * content should be hidden.
     */
    int FLAG_CONTENT_VIEW_PUBLIC = 1 << 3;

    int FLAG_CONTENT_VIEW_ALL = (1 << 4) - 1;

    /**
     * Parameters for content view binding
     */
    class BindParams {

        /**
         * Bind a low priority version of the content views.
         */
        public boolean isLowPriority;

        /**
         * Use increased height when binding contracted view.
         */
        public boolean usesIncreasedHeight;

        /**
         * Use increased height when binding heads up views.
         */
        public boolean usesIncreasedHeadsUpHeight;
    }

    /**
     * Callback for inflation finishing
     */
    interface InflationCallback {

        /**
         * Callback for when there is an inflation exception
         *
         * @param entry notification which failed to inflate content
         * @param e exception
         */
        void handleInflationException(NotificationEntry entry, Exception e);

        /**
         * Callback for after the content views finish inflating.
         *
         * @param entry the entry with the content views set
         */
        void onAsyncInflationFinished(NotificationEntry entry);
    }
}