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