Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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; |
| 18 | |
| 19 | import android.content.Context; |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 20 | import android.content.res.Resources; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 21 | import android.graphics.Canvas; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 22 | import android.graphics.Outline; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 23 | import android.graphics.Path; |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame] | 24 | import android.graphics.Rect; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 25 | import android.graphics.RectF; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 26 | import android.util.AttributeSet; |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame] | 27 | import android.view.View; |
| 28 | import android.view.ViewOutlineProvider; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 29 | |
| 30 | import com.android.settingslib.Utils; |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 31 | import com.android.systemui.R; |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 32 | import com.android.systemui.statusbar.notification.AnimatableProperty; |
| 33 | import com.android.systemui.statusbar.notification.PropertyAnimator; |
| 34 | import com.android.systemui.statusbar.stack.AnimationProperties; |
| 35 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Like {@link ExpandableView}, but setting an outline for the height and clipping. |
| 39 | */ |
| 40 | public abstract class ExpandableOutlineView extends ExpandableView { |
| 41 | |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 42 | private static final AnimatableProperty TOP_ROUNDNESS = AnimatableProperty.from( |
| 43 | "topRoundness", |
| 44 | ExpandableOutlineView::setTopRoundnessInternal, |
| 45 | ExpandableOutlineView::getCurrentTopRoundness, |
| 46 | R.id.top_roundess_animator_tag, |
| 47 | R.id.top_roundess_animator_end_tag, |
| 48 | R.id.top_roundess_animator_start_tag); |
| 49 | private static final AnimatableProperty BOTTOM_ROUNDNESS = AnimatableProperty.from( |
| 50 | "bottomRoundness", |
| 51 | ExpandableOutlineView::setBottomRoundnessInternal, |
| 52 | ExpandableOutlineView::getCurrentBottomRoundness, |
| 53 | R.id.bottom_roundess_animator_tag, |
| 54 | R.id.bottom_roundess_animator_end_tag, |
| 55 | R.id.bottom_roundess_animator_start_tag); |
| 56 | private static final AnimationProperties ROUNDNESS_PROPERTIES = |
| 57 | new AnimationProperties().setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 58 | private static final Path EMPTY_PATH = new Path(); |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 59 | |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame] | 60 | private final Rect mOutlineRect = new Rect(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 61 | private final Path mClipPath = new Path(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 62 | private boolean mCustomOutline; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 63 | private float mOutlineAlpha = -1f; |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 64 | protected float mOutlineRadius; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 65 | private boolean mAlwaysRoundBothCorners; |
| 66 | private Path mTmpPath = new Path(); |
| 67 | private Path mTmpPath2 = new Path(); |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 68 | private float mCurrentBottomRoundness; |
| 69 | private float mCurrentTopRoundness; |
| 70 | private float mBottomRoundness; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 71 | private float mTopRoundness; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 72 | private int mBackgroundTop; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 73 | |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 74 | /** |
| 75 | * {@code true} if the children views of the {@link ExpandableOutlineView} are translated when |
| 76 | * it is moved. Otherwise, the translation is set on the {@code ExpandableOutlineView} itself. |
| 77 | */ |
| 78 | protected boolean mShouldTranslateContents; |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 79 | private boolean mTopAmountRounded; |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 80 | private float mDistanceToTopRoundness = -1; |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 81 | private float mExtraWidthForClipping; |
| 82 | private int mMinimumHeightForClipping = 0; |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 83 | |
| 84 | private final ViewOutlineProvider mProvider = new ViewOutlineProvider() { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 85 | @Override |
| 86 | public void getOutline(View view, Outline outline) { |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 87 | if (!mCustomOutline && mCurrentTopRoundness == 0.0f |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 88 | && mCurrentBottomRoundness == 0.0f && !mAlwaysRoundBothCorners |
| 89 | && !mTopAmountRounded) { |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 90 | int translation = mShouldTranslateContents ? (int) getTranslation() : 0; |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 91 | int left = Math.max(translation, 0); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 92 | int top = mClipTopAmount + mBackgroundTop; |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 93 | int right = getWidth() + Math.min(translation, 0); |
Selim Cinek | 1a891a9 | 2017-12-04 17:41:27 +0100 | [diff] [blame] | 94 | int bottom = Math.max(getActualHeight() - mClipBottomAmount, top); |
| 95 | outline.setRect(left, top, right, bottom); |
| 96 | } else { |
| 97 | Path clipPath = getClipPath(); |
| 98 | if (clipPath != null && clipPath.isConvex()) { |
| 99 | // The path might not be convex in border cases where the view is small and |
| 100 | // clipped |
| 101 | outline.setConvexPath(clipPath); |
| 102 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 103 | } |
| 104 | outline.setAlpha(mOutlineAlpha); |
| 105 | } |
| 106 | }; |
| 107 | |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 108 | private Path getClipPath() { |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 109 | return getClipPath(false, /* ignoreTranslation */ |
| 110 | false /* clipRoundedToBottom */); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 113 | protected Path getClipPath(boolean ignoreTranslation, boolean clipRoundedToBottom) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 114 | int left; |
| 115 | int top; |
| 116 | int right; |
| 117 | int bottom; |
| 118 | int height; |
| 119 | Path intersectPath = null; |
| 120 | if (!mCustomOutline) { |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 121 | int translation = mShouldTranslateContents && !ignoreTranslation |
| 122 | ? (int) getTranslation() : 0; |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 123 | left = Math.max(translation, 0); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 124 | top = mClipTopAmount + mBackgroundTop; |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 125 | right = getWidth() + Math.min(translation, 0); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 126 | bottom = Math.max(getActualHeight(), top); |
| 127 | int intersectBottom = Math.max(getActualHeight() - mClipBottomAmount, top); |
| 128 | if (bottom != intersectBottom) { |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 129 | if (clipRoundedToBottom) { |
| 130 | bottom = intersectBottom; |
| 131 | } else { |
| 132 | getRoundedRectPath(left, top, right, |
| 133 | intersectBottom, 0.0f, |
| 134 | 0.0f, mTmpPath2); |
| 135 | intersectPath = mTmpPath2; |
| 136 | } |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 137 | } |
| 138 | } else { |
| 139 | left = mOutlineRect.left; |
| 140 | top = mOutlineRect.top; |
| 141 | right = mOutlineRect.right; |
| 142 | bottom = mOutlineRect.bottom; |
| 143 | } |
| 144 | height = bottom - top; |
| 145 | if (height == 0) { |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 146 | return EMPTY_PATH; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 147 | } |
| 148 | float topRoundness = mAlwaysRoundBothCorners |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 149 | ? mOutlineRadius : getCurrentBackgroundRadiusTop(); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 150 | float bottomRoundness = mAlwaysRoundBothCorners |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 151 | ? mOutlineRadius : getCurrentBackgroundRadiusBottom(); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 152 | if (topRoundness + bottomRoundness > height) { |
| 153 | float overShoot = topRoundness + bottomRoundness - height; |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 154 | topRoundness -= overShoot * mCurrentTopRoundness |
| 155 | / (mCurrentTopRoundness + mCurrentBottomRoundness); |
| 156 | bottomRoundness -= overShoot * mCurrentBottomRoundness |
| 157 | / (mCurrentTopRoundness + mCurrentBottomRoundness); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 158 | } |
| 159 | getRoundedRectPath(left, top, right, bottom, topRoundness, |
| 160 | bottomRoundness, mTmpPath); |
| 161 | Path roundedRectPath = mTmpPath; |
| 162 | if (intersectPath != null) { |
| 163 | roundedRectPath.op(intersectPath, Path.Op.INTERSECT); |
| 164 | } |
| 165 | return roundedRectPath; |
| 166 | } |
| 167 | |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 168 | public static void getRoundedRectPath(int left, int top, int right, int bottom, |
| 169 | float topRoundness, float bottomRoundness, Path outPath) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 170 | outPath.reset(); |
| 171 | int width = right - left; |
| 172 | float topRoundnessX = topRoundness; |
| 173 | float bottomRoundnessX = bottomRoundness; |
| 174 | topRoundnessX = Math.min(width / 2, topRoundnessX); |
| 175 | bottomRoundnessX = Math.min(width / 2, bottomRoundnessX); |
| 176 | if (topRoundness > 0.0f) { |
| 177 | outPath.moveTo(left, top + topRoundness); |
| 178 | outPath.quadTo(left, top, left + topRoundnessX, top); |
| 179 | outPath.lineTo(right - topRoundnessX, top); |
| 180 | outPath.quadTo(right, top, right, top + topRoundness); |
| 181 | } else { |
| 182 | outPath.moveTo(left, top); |
| 183 | outPath.lineTo(right, top); |
| 184 | } |
| 185 | if (bottomRoundness > 0.0f) { |
| 186 | outPath.lineTo(right, bottom - bottomRoundness); |
| 187 | outPath.quadTo(right, bottom, right - bottomRoundnessX, bottom); |
| 188 | outPath.lineTo(left + bottomRoundnessX, bottom); |
| 189 | outPath.quadTo(left, bottom, left, bottom - bottomRoundness); |
| 190 | } else { |
| 191 | outPath.lineTo(right, bottom); |
| 192 | outPath.lineTo(left, bottom); |
| 193 | } |
| 194 | outPath.close(); |
| 195 | } |
| 196 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 197 | public ExpandableOutlineView(Context context, AttributeSet attrs) { |
| 198 | super(context, attrs); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 199 | setOutlineProvider(mProvider); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 200 | initDimens(); |
| 201 | } |
| 202 | |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 203 | @Override |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 204 | protected boolean drawChild(Canvas canvas, View child, long drawingTime) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 205 | canvas.save(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 206 | Path intersectPath = null; |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 207 | if (mTopAmountRounded && topAmountNeedsClipping()) { |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 208 | int left = (int) (- mExtraWidthForClipping / 2.0f); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 209 | int top = (int) (mClipTopAmount - mDistanceToTopRoundness); |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 210 | int right = getWidth() + (int) (mExtraWidthForClipping + left); |
| 211 | int bottom = (int) Math.max(mMinimumHeightForClipping, |
| 212 | Math.max(getActualHeight() - mClipBottomAmount, top + mOutlineRadius)); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 213 | ExpandableOutlineView.getRoundedRectPath(left, top, right, bottom, mOutlineRadius, |
| 214 | 0.0f, |
| 215 | mClipPath); |
| 216 | intersectPath = mClipPath; |
| 217 | } |
| 218 | boolean clipped = false; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 219 | if (childNeedsClipping(child)) { |
| 220 | Path clipPath = getCustomClipPath(child); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 221 | if (clipPath == null) { |
| 222 | clipPath = getClipPath(); |
| 223 | } |
| 224 | if (clipPath != null) { |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 225 | if (intersectPath != null) { |
| 226 | clipPath.op(intersectPath, Path.Op.INTERSECT); |
| 227 | } |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 228 | canvas.clipPath(clipPath); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 229 | clipped = true; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 230 | } |
| 231 | } |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 232 | if (!clipped && intersectPath != null) { |
| 233 | canvas.clipPath(intersectPath); |
| 234 | } |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 235 | boolean result = super.drawChild(canvas, child, drawingTime); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 236 | canvas.restore(); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 237 | return result; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 240 | public void setExtraWidthForClipping(float extraWidthForClipping) { |
| 241 | mExtraWidthForClipping = extraWidthForClipping; |
| 242 | } |
| 243 | |
| 244 | public void setMinimumHeightForClipping(int minimumHeightForClipping) { |
| 245 | mMinimumHeightForClipping = minimumHeightForClipping; |
| 246 | } |
| 247 | |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 248 | @Override |
| 249 | public void setDistanceToTopRoundness(float distanceToTopRoundness) { |
| 250 | super.setDistanceToTopRoundness(distanceToTopRoundness); |
| 251 | if (distanceToTopRoundness != mDistanceToTopRoundness) { |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 252 | mTopAmountRounded = distanceToTopRoundness >= 0; |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 253 | mDistanceToTopRoundness = distanceToTopRoundness; |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 254 | applyRoundness(); |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 258 | protected boolean childNeedsClipping(View child) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 259 | return false; |
| 260 | } |
| 261 | |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 262 | public boolean topAmountNeedsClipping() { |
| 263 | return true; |
| 264 | } |
| 265 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 266 | protected boolean isClippingNeeded() { |
| 267 | return mAlwaysRoundBothCorners || mCustomOutline || getTranslation() != 0 ; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 270 | private void initDimens() { |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 271 | Resources res = getResources(); |
| 272 | mShouldTranslateContents = |
| 273 | res.getBoolean(R.bool.config_translateNotificationContentsOnSwipe); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 274 | mOutlineRadius = res.getDimension(R.dimen.notification_shadow_radius); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 275 | mAlwaysRoundBothCorners = res.getBoolean(R.bool.config_clipNotificationsToOutline); |
| 276 | if (!mAlwaysRoundBothCorners) { |
| 277 | mOutlineRadius = res.getDimensionPixelSize( |
| 278 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
| 279 | } |
| 280 | setClipToOutline(mAlwaysRoundBothCorners); |
| 281 | } |
| 282 | |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 283 | /** |
| 284 | * Set the topRoundness of this view. |
| 285 | * @return Whether the roundness was changed. |
| 286 | */ |
| 287 | public boolean setTopRoundness(float topRoundness, boolean animate) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 288 | if (mTopRoundness != topRoundness) { |
| 289 | mTopRoundness = topRoundness; |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 290 | PropertyAnimator.setProperty(this, TOP_ROUNDNESS, topRoundness, |
| 291 | ROUNDNESS_PROPERTIES, animate); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 292 | return true; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 293 | } |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 294 | return false; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | protected void applyRoundness() { |
| 298 | invalidateOutline(); |
| 299 | invalidate(); |
| 300 | } |
| 301 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 302 | public float getCurrentBackgroundRadiusTop() { |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 303 | // If this view is top amount notification view, it should always has round corners on top. |
| 304 | // It will be applied with applyRoundness() |
| 305 | if (mTopAmountRounded) { |
| 306 | return mOutlineRadius; |
| 307 | } |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 308 | return mCurrentTopRoundness * mOutlineRadius; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 311 | public float getCurrentTopRoundness() { |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 312 | return mCurrentTopRoundness; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 315 | public float getCurrentBottomRoundness() { |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 316 | return mCurrentBottomRoundness; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 319 | protected float getCurrentBackgroundRadiusBottom() { |
| 320 | return mCurrentBottomRoundness * mOutlineRadius; |
| 321 | } |
| 322 | |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 323 | /** |
| 324 | * Set the bottom roundness of this view. |
| 325 | * @return Whether the roundness was changed. |
| 326 | */ |
| 327 | public boolean setBottomRoundness(float bottomRoundness, boolean animate) { |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 328 | if (mBottomRoundness != bottomRoundness) { |
| 329 | mBottomRoundness = bottomRoundness; |
| 330 | PropertyAnimator.setProperty(this, BOTTOM_ROUNDNESS, bottomRoundness, |
| 331 | ROUNDNESS_PROPERTIES, animate); |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 332 | return true; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 333 | } |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 334 | return false; |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 337 | protected void setBackgroundTop(int backgroundTop) { |
| 338 | if (mBackgroundTop != backgroundTop) { |
| 339 | mBackgroundTop = backgroundTop; |
| 340 | invalidateOutline(); |
| 341 | } |
| 342 | } |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 343 | |
| 344 | private void setTopRoundnessInternal(float topRoundness) { |
| 345 | mCurrentTopRoundness = topRoundness; |
| 346 | applyRoundness(); |
| 347 | } |
| 348 | |
| 349 | private void setBottomRoundnessInternal(float bottomRoundness) { |
| 350 | mCurrentBottomRoundness = bottomRoundness; |
| 351 | applyRoundness(); |
| 352 | } |
| 353 | |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 354 | public void onDensityOrFontScaleChanged() { |
| 355 | initDimens(); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 356 | applyRoundness(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 360 | public void setActualHeight(int actualHeight, boolean notifyListeners) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 361 | int previousHeight = getActualHeight(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 362 | super.setActualHeight(actualHeight, notifyListeners); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 363 | if (previousHeight != actualHeight) { |
| 364 | applyRoundness(); |
| 365 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | @Override |
| 369 | public void setClipTopAmount(int clipTopAmount) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 370 | int previousAmount = getClipTopAmount(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 371 | super.setClipTopAmount(clipTopAmount); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 372 | if (previousAmount != clipTopAmount) { |
| 373 | applyRoundness(); |
| 374 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 377 | @Override |
| 378 | public void setClipBottomAmount(int clipBottomAmount) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 379 | int previousAmount = getClipBottomAmount(); |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 380 | super.setClipBottomAmount(clipBottomAmount); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 381 | if (previousAmount != clipBottomAmount) { |
| 382 | applyRoundness(); |
| 383 | } |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 386 | protected void setOutlineAlpha(float alpha) { |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 387 | if (alpha != mOutlineAlpha) { |
| 388 | mOutlineAlpha = alpha; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 389 | applyRoundness(); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 390 | } |
Jorim Jaggi | 83eb6bb | 2015-08-17 17:38:58 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 393 | @Override |
| 394 | public float getOutlineAlpha() { |
| 395 | return mOutlineAlpha; |
| 396 | } |
| 397 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 398 | protected void setOutlineRect(RectF rect) { |
| 399 | if (rect != null) { |
| 400 | setOutlineRect(rect.left, rect.top, rect.right, rect.bottom); |
| 401 | } else { |
| 402 | mCustomOutline = false; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 403 | applyRoundness(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 407 | @Override |
| 408 | public int getOutlineTranslation() { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 409 | return mCustomOutline ? mOutlineRect.left : (int) getTranslation(); |
| 410 | } |
| 411 | |
| 412 | public void updateOutline() { |
| 413 | if (mCustomOutline) { |
| 414 | return; |
| 415 | } |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 416 | boolean hasOutline = needsOutline(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 417 | setOutlineProvider(hasOutline ? mProvider : null); |
| 418 | } |
| 419 | |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 420 | /** |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 421 | * @return Whether the view currently needs an outline. This is usually {@code false} in case |
| 422 | * it doesn't have a background. |
Selim Cinek | ad7fac0 | 2016-10-18 17:09:15 -0700 | [diff] [blame] | 423 | */ |
| 424 | protected boolean needsOutline() { |
| 425 | if (isChildInGroup()) { |
| 426 | return isGroupExpanded() && !isGroupExpansionChanging(); |
| 427 | } else if (isSummaryWithChildren()) { |
| 428 | return !isGroupExpanded() || isGroupExpansionChanging(); |
| 429 | } |
| 430 | return true; |
| 431 | } |
| 432 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 433 | public boolean isOutlineShowing() { |
| 434 | ViewOutlineProvider op = getOutlineProvider(); |
| 435 | return op != null; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 438 | protected void setOutlineRect(float left, float top, float right, float bottom) { |
| 439 | mCustomOutline = true; |
| 440 | |
Chris Craik | 7b7ca3c | 2014-07-11 13:32:19 -0700 | [diff] [blame] | 441 | mOutlineRect.set((int) left, (int) top, (int) right, (int) bottom); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 442 | |
| 443 | // Outlines need to be at least 1 dp |
Selim Cinek | 3969ffa | 2014-09-01 23:08:39 +0200 | [diff] [blame] | 444 | mOutlineRect.bottom = (int) Math.max(top, mOutlineRect.bottom); |
| 445 | mOutlineRect.right = (int) Math.max(left, mOutlineRect.right); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 446 | applyRoundness(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 447 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 448 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 449 | public Path getCustomClipPath(View child) { |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 450 | return null; |
| 451 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 452 | } |