1  /*
2   * Copyright (C) 2020 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 static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_CONTRACTED;
20  import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_EXPANDED;
21  import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_HEADS_UP;
22  
23  import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
24  
25  /**
26   * Parameters for {@link RowContentBindStage}.
27   */
28  public final class RowContentBindParams {
29      private boolean mUseLowPriority;
30      private boolean mUseIncreasedHeight;
31      private boolean mUseIncreasedHeadsUpHeight;
32      private boolean mViewsNeedReinflation;
33      private @InflationFlag int mContentViews = DEFAULT_INFLATION_FLAGS;
34  
35      /**
36       * Content views that are out of date and need to be rebound.
37       *
38       * TODO: This should go away once {@link NotificationContentInflater} is broken down into
39       * smaller stages as then the stage itself would be invalidated.
40       */
41      private @InflationFlag int mDirtyContentViews = mContentViews;
42  
43      /**
44       * Set whether content should use a low priority version of its content views.
45       */
setUseLowPriority(boolean useLowPriority)46      public void setUseLowPriority(boolean useLowPriority) {
47          if (mUseLowPriority != useLowPriority) {
48              mDirtyContentViews |= (FLAG_CONTENT_VIEW_CONTRACTED | FLAG_CONTENT_VIEW_EXPANDED);
49          }
50          mUseLowPriority = useLowPriority;
51      }
52  
useLowPriority()53      public boolean useLowPriority() {
54          return mUseLowPriority;
55      }
56  
57      /**
58       * Set whether content should use an increased height version of its contracted view.
59       */
setUseIncreasedCollapsedHeight(boolean useIncreasedHeight)60      public void setUseIncreasedCollapsedHeight(boolean useIncreasedHeight) {
61          if (mUseIncreasedHeight != useIncreasedHeight) {
62              mDirtyContentViews |= FLAG_CONTENT_VIEW_CONTRACTED;
63          }
64          mUseIncreasedHeight = useIncreasedHeight;
65      }
66  
useIncreasedHeight()67      public boolean useIncreasedHeight() {
68          return mUseIncreasedHeight;
69      }
70  
71      /**
72       * Set whether content should use an increased height version of its heads up view.
73       */
setUseIncreasedHeadsUpHeight(boolean useIncreasedHeadsUpHeight)74      public void setUseIncreasedHeadsUpHeight(boolean useIncreasedHeadsUpHeight) {
75          if (mUseIncreasedHeadsUpHeight != useIncreasedHeadsUpHeight) {
76              mDirtyContentViews |= FLAG_CONTENT_VIEW_HEADS_UP;
77          }
78          mUseIncreasedHeadsUpHeight = useIncreasedHeadsUpHeight;
79      }
80  
useIncreasedHeadsUpHeight()81      public boolean useIncreasedHeadsUpHeight() {
82          return mUseIncreasedHeadsUpHeight;
83      }
84  
85      /**
86       * Require the specified content views to be bound after the rebind request.
87       *
88       * @see InflationFlag
89       */
requireContentViews(@nflationFlag int contentViews)90      public void requireContentViews(@InflationFlag int contentViews) {
91          @InflationFlag int newContentViews = contentViews &= ~mContentViews;
92          mContentViews |= contentViews;
93          mDirtyContentViews |= newContentViews;
94      }
95  
96      /**
97       * Mark the content view to be freed. The view may not be immediately freeable since it may
98       * be visible and animating out but this lets the binder know to free the view when safe.
99       * Note that the callback passed into {@link RowContentBindStage#requestRebind}
100       * may return before the view is actually freed since the view is considered up-to-date.
101       *
102       * @see InflationFlag
103       */
markContentViewsFreeable(@nflationFlag int contentViews)104      public void markContentViewsFreeable(@InflationFlag int contentViews) {
105          @InflationFlag int existingContentViews = contentViews &= mContentViews;
106          mContentViews &= ~contentViews;
107          mDirtyContentViews |= existingContentViews;
108      }
109  
getContentViews()110      public @InflationFlag int getContentViews() {
111          return mContentViews;
112      }
113  
114      /**
115       * Request that all content views be rebound. This may happen if, for example, the underlying
116       * layout has changed.
117       */
rebindAllContentViews()118      public void rebindAllContentViews() {
119          mDirtyContentViews = mContentViews;
120      }
121  
122      /**
123       * Clears all dirty content views so that they no longer need to be rebound.
124       */
clearDirtyContentViews()125      void clearDirtyContentViews() {
126          mDirtyContentViews = 0;
127      }
128  
getDirtyContentViews()129      public @InflationFlag int getDirtyContentViews() {
130          return mDirtyContentViews;
131      }
132  
133      /**
134       * Set whether all content views need to be reinflated even if cached.
135       *
136       * TODO: This should probably be a more global config on {@link NotifBindPipeline} since this
137       * generally corresponds to a Context/Configuration change that all stages should know about.
138       */
setNeedsReinflation(boolean needsReinflation)139      public void setNeedsReinflation(boolean needsReinflation) {
140          mViewsNeedReinflation = needsReinflation;
141          @InflationFlag int currentContentViews = mContentViews;
142          mDirtyContentViews |= currentContentViews;
143      }
144  
needsReinflation()145      public boolean needsReinflation() {
146          return mViewsNeedReinflation;
147      }
148  
149      @Override
toString()150      public String toString() {
151          return String.format("RowContentBindParams[mContentViews=%x mDirtyContentViews=%x "
152                  + "mUseLowPriority=%b mUseIncreasedHeight=%b "
153                  + "mUseIncreasedHeadsUpHeight=%b mViewsNeedReinflation=%b]",
154                  mContentViews, mDirtyContentViews, mUseLowPriority, mUseIncreasedHeight,
155                  mUseIncreasedHeadsUpHeight, mViewsNeedReinflation);
156      }
157  
158      /**
159       * Content views that should be inflated by default for all notifications.
160       */
161      @InflationFlag private static final int DEFAULT_INFLATION_FLAGS =
162              FLAG_CONTENT_VIEW_CONTRACTED | FLAG_CONTENT_VIEW_EXPANDED;
163  }
164