summaryrefslogtreecommitdiff
path: root/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/RowContentBindParams.java
blob: a52f638e7c26e9445d6325fb7d5cc7e4e8834378 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright (C) 2020 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 static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_CONTRACTED;
import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_EXPANDED;
import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_HEADS_UP;

import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;

/**
 * Parameters for {@link RowContentBindStage}.
 */
public final class RowContentBindParams {
    private boolean mUseLowPriority;
    private boolean mUseIncreasedHeight;
    private boolean mUseIncreasedHeadsUpHeight;
    private boolean mViewsNeedReinflation;
    private @InflationFlag int mContentViews = DEFAULT_INFLATION_FLAGS;

    /**
     * Content views that are out of date and need to be rebound.
     *
     * TODO: This should go away once {@link NotificationContentInflater} is broken down into
     * smaller stages as then the stage itself would be invalidated.
     */
    private @InflationFlag int mDirtyContentViews = mContentViews;

    /**
     * Set whether content should use a low priority version of its content views.
     */
    public void setUseLowPriority(boolean useLowPriority) {
        if (mUseLowPriority != useLowPriority) {
            mDirtyContentViews |= (FLAG_CONTENT_VIEW_CONTRACTED | FLAG_CONTENT_VIEW_EXPANDED);
        }
        mUseLowPriority = useLowPriority;
    }

    public boolean useLowPriority() {
        return mUseLowPriority;
    }

    /**
     * Set whether content should use an increased height version of its contracted view.
     */
    public void setUseIncreasedCollapsedHeight(boolean useIncreasedHeight) {
        if (mUseIncreasedHeight != useIncreasedHeight) {
            mDirtyContentViews |= FLAG_CONTENT_VIEW_CONTRACTED;
        }
        mUseIncreasedHeight = useIncreasedHeight;
    }

    public boolean useIncreasedHeight() {
        return mUseIncreasedHeight;
    }

    /**
     * Set whether content should use an increased height version of its heads up view.
     */
    public void setUseIncreasedHeadsUpHeight(boolean useIncreasedHeadsUpHeight) {
        if (mUseIncreasedHeadsUpHeight != useIncreasedHeadsUpHeight) {
            mDirtyContentViews |= FLAG_CONTENT_VIEW_HEADS_UP;
        }
        mUseIncreasedHeadsUpHeight = useIncreasedHeadsUpHeight;
    }

    public boolean useIncreasedHeadsUpHeight() {
        return mUseIncreasedHeadsUpHeight;
    }

    /**
     * Require the specified content views to be bound after the rebind request.
     *
     * @see InflationFlag
     */
    public void requireContentViews(@InflationFlag int contentViews) {
        @InflationFlag int newContentViews = contentViews &= ~mContentViews;
        mContentViews |= contentViews;
        mDirtyContentViews |= newContentViews;
    }

    /**
     * Mark the content view to be freed. The view may not be immediately freeable since it may
     * be visible and animating out but this lets the binder know to free the view when safe.
     * Note that the callback passed into {@link RowContentBindStage#requestRebind}
     * may return before the view is actually freed since the view is considered up-to-date.
     *
     * @see InflationFlag
     */
    public void markContentViewsFreeable(@InflationFlag int contentViews) {
        @InflationFlag int existingContentViews = contentViews &= mContentViews;
        mContentViews &= ~contentViews;
        mDirtyContentViews |= existingContentViews;
    }

    public @InflationFlag int getContentViews() {
        return mContentViews;
    }

    /**
     * Request that all content views be rebound. This may happen if, for example, the underlying
     * layout has changed.
     */
    public void rebindAllContentViews() {
        mDirtyContentViews = mContentViews;
    }

    /**
     * Clears all dirty content views so that they no longer need to be rebound.
     */
    void clearDirtyContentViews() {
        mDirtyContentViews = 0;
    }

    public @InflationFlag int getDirtyContentViews() {
        return mDirtyContentViews;
    }

    /**
     * Set whether all content views need to be reinflated even if cached.
     *
     * TODO: This should probably be a more global config on {@link NotifBindPipeline} since this
     * generally corresponds to a Context/Configuration change that all stages should know about.
     */
    public void setNeedsReinflation(boolean needsReinflation) {
        mViewsNeedReinflation = needsReinflation;
        @InflationFlag int currentContentViews = mContentViews;
        mDirtyContentViews |= currentContentViews;
    }

    public boolean needsReinflation() {
        return mViewsNeedReinflation;
    }

    @Override
    public String toString() {
        return String.format("RowContentBindParams[mContentViews=%x mDirtyContentViews=%x "
                + "mUseLowPriority=%b mUseIncreasedHeight=%b "
                + "mUseIncreasedHeadsUpHeight=%b mViewsNeedReinflation=%b]",
                mContentViews, mDirtyContentViews, mUseLowPriority, mUseIncreasedHeight,
                mUseIncreasedHeadsUpHeight, mViewsNeedReinflation);
    }

    /**
     * Content views that should be inflated by default for all notifications.
     */
    @InflationFlag private static final int DEFAULT_INFLATION_FLAGS =
            FLAG_CONTENT_VIEW_CONTRACTED | FLAG_CONTENT_VIEW_EXPANDED;
}