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 mContentViews &= ~contentViews; 106 mDirtyContentViews &= ~contentViews; 107 } 108 getContentViews()109 public @InflationFlag int getContentViews() { 110 return mContentViews; 111 } 112 113 /** 114 * Request that all content views be rebound. This may happen if, for example, the underlying 115 * layout has changed. 116 */ rebindAllContentViews()117 public void rebindAllContentViews() { 118 mDirtyContentViews = mContentViews; 119 } 120 121 /** 122 * Clears all dirty content views so that they no longer need to be rebound. 123 */ clearDirtyContentViews()124 void clearDirtyContentViews() { 125 mDirtyContentViews = 0; 126 } 127 getDirtyContentViews()128 public @InflationFlag int getDirtyContentViews() { 129 return mDirtyContentViews; 130 } 131 132 /** 133 * Set whether all content views need to be reinflated even if cached. 134 * 135 * TODO: This should probably be a more global config on {@link NotifBindPipeline} since this 136 * generally corresponds to a Context/Configuration change that all stages should know about. 137 */ setNeedsReinflation(boolean needsReinflation)138 public void setNeedsReinflation(boolean needsReinflation) { 139 mViewsNeedReinflation = needsReinflation; 140 @InflationFlag int currentContentViews = mContentViews; 141 mDirtyContentViews |= currentContentViews; 142 } 143 needsReinflation()144 public boolean needsReinflation() { 145 return mViewsNeedReinflation; 146 } 147 148 @Override toString()149 public String toString() { 150 return String.format("RowContentBindParams[mContentViews=%x mDirtyContentViews=%x " 151 + "mUseLowPriority=%b mUseIncreasedHeight=%b " 152 + "mUseIncreasedHeadsUpHeight=%b mViewsNeedReinflation=%b]", 153 mContentViews, mDirtyContentViews, mUseLowPriority, mUseIncreasedHeight, 154 mUseIncreasedHeadsUpHeight, mViewsNeedReinflation); 155 } 156 157 /** 158 * Content views that should be inflated by default for all notifications. 159 */ 160 @InflationFlag private static final int DEFAULT_INFLATION_FLAGS = 161 FLAG_CONTENT_VIEW_CONTRACTED | FLAG_CONTENT_VIEW_EXPANDED; 162 } 163