Fix 4081795: Blue glow gone wild. DO NOT MERGE
Change-Id: I9038ed322811987e69045602f438cdf2bbd946e9
This commit is contained in:
parent
ec4ff67723
commit
3499d8c89d
|
@ -126,23 +126,13 @@ public class BubbleTextView extends TextView implements VisibilityChangedBroadca
|
|||
return who == mBackground || super.verifyDrawable(who);
|
||||
}
|
||||
|
||||
private void invalidatePressedOrFocusedBackground() {
|
||||
int padding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS / 2;
|
||||
View parent = (View) getParent();
|
||||
if (parent != null) {
|
||||
parent.invalidate(getLeft() - padding, getTop() - padding,
|
||||
getRight() + padding, getBottom() + padding);
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawableStateChanged() {
|
||||
if (isPressed()) {
|
||||
// In this case, we have already created the pressed outline on ACTION_DOWN,
|
||||
// so we just need to do an invalidate to trigger draw
|
||||
if (!mDidInvalidateForPressedState) {
|
||||
invalidatePressedOrFocusedBackground();
|
||||
setCellLayoutPressedOrFocusedIcon();
|
||||
}
|
||||
} else {
|
||||
// Otherwise, either clear the pressed/focused background, or create a background
|
||||
|
@ -161,11 +151,11 @@ public class BubbleTextView extends TextView implements VisibilityChangedBroadca
|
|||
mTempCanvas, mFocusedGlowColor, mFocusedOutlineColor);
|
||||
}
|
||||
mStayPressed = false;
|
||||
invalidatePressedOrFocusedBackground();
|
||||
setCellLayoutPressedOrFocusedIcon();
|
||||
}
|
||||
final boolean backgroundEmptyNow = mPressedOrFocusedBackground == null;
|
||||
if (!backgroundEmptyBefore && backgroundEmptyNow) {
|
||||
invalidatePressedOrFocusedBackground();
|
||||
setCellLayoutPressedOrFocusedIcon();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +186,7 @@ public class BubbleTextView extends TextView implements VisibilityChangedBroadca
|
|||
destCanvas.save();
|
||||
destCanvas.translate(-getScrollX() + padding / 2, -getScrollY() + padding / 2);
|
||||
destCanvas.clipRect(clipRect, Op.REPLACE);
|
||||
drawImpl(destCanvas, true);
|
||||
draw(destCanvas);
|
||||
destCanvas.restore();
|
||||
}
|
||||
|
||||
|
@ -269,35 +259,25 @@ public class BubbleTextView extends TextView implements VisibilityChangedBroadca
|
|||
if (!stayPressed) {
|
||||
mPressedOrFocusedBackground = null;
|
||||
}
|
||||
invalidatePressedOrFocusedBackground();
|
||||
setCellLayoutPressedOrFocusedIcon();
|
||||
}
|
||||
|
||||
void setCellLayoutPressedOrFocusedIcon() {
|
||||
CellLayoutChildren parent = (CellLayoutChildren) getParent();
|
||||
CellLayout cellLayout = (CellLayout) parent.getParent();
|
||||
cellLayout.setPressedOrFocusedIcon((mPressedOrFocusedBackground != null) ? this : null);
|
||||
}
|
||||
|
||||
Bitmap getPressedOrFocusedBackground() {
|
||||
return mPressedOrFocusedBackground;
|
||||
}
|
||||
|
||||
int getPressedOrFocusedBackgroundPadding() {
|
||||
return HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
drawImpl(canvas, false);
|
||||
}
|
||||
|
||||
private void drawImpl(Canvas canvas, boolean preventRecursion) {
|
||||
// If the View is focused but the focused background hasn't been created yet, create it now
|
||||
if (!preventRecursion && isFocused() && mPressedOrFocusedBackground == null) {
|
||||
mPressedOrFocusedBackground = createGlowingOutline(
|
||||
mTempCanvas, mFocusedGlowColor, mFocusedOutlineColor);
|
||||
}
|
||||
|
||||
if (mPressedOrFocusedBackground != null && (isPressed() || isFocused() || mStayPressed)) {
|
||||
// The blue glow can extend outside of our clip region, so we first temporarily expand
|
||||
// the canvas's clip region
|
||||
canvas.save(Canvas.CLIP_SAVE_FLAG);
|
||||
int padding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS / 2;
|
||||
canvas.clipRect(-padding + mScrollX, -padding + mScrollY,
|
||||
getWidth() + padding + mScrollX, getHeight() + padding + mScrollY,
|
||||
Region.Op.REPLACE);
|
||||
// draw blue glow
|
||||
canvas.drawBitmap(mPressedOrFocusedBackground,
|
||||
mScrollX - padding, mScrollY - padding, mTempPaint);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
final Drawable background = mBackground;
|
||||
if (background != null) {
|
||||
final int scrollX = mScrollX;
|
||||
|
|
|
@ -113,6 +113,8 @@ public class CellLayout extends ViewGroup {
|
|||
private int mDragOutlineCurrent = 0;
|
||||
private final Paint mDragOutlinePaint = new Paint();
|
||||
|
||||
private BubbleTextView mPressedOrFocusedIcon;
|
||||
|
||||
private Drawable mCrosshairsDrawable = null;
|
||||
private InterruptibleInOutAnimator mCrosshairsAnimator = null;
|
||||
private float mCrosshairsVisibility = 0.0f;
|
||||
|
@ -267,6 +269,27 @@ public class CellLayout extends ViewGroup {
|
|||
addView(mChildren);
|
||||
}
|
||||
|
||||
private void invalidateBubbleTextView(BubbleTextView icon) {
|
||||
final int padding = icon.getPressedOrFocusedBackgroundPadding();
|
||||
invalidate(icon.getLeft() - padding,
|
||||
icon.getTop() - padding,
|
||||
icon.getRight() + padding,
|
||||
icon.getBottom() + padding);
|
||||
}
|
||||
|
||||
void setPressedOrFocusedIcon(BubbleTextView icon) {
|
||||
// We draw the pressed or focused BubbleTextView's background in CellLayout because it
|
||||
// requires an expanded clip rect (due to the glow's blur radius)
|
||||
BubbleTextView oldIcon = mPressedOrFocusedIcon;
|
||||
mPressedOrFocusedIcon = icon;
|
||||
if (oldIcon != null) {
|
||||
invalidateBubbleTextView(oldIcon);
|
||||
}
|
||||
if (mPressedOrFocusedIcon != null) {
|
||||
invalidateBubbleTextView(mPressedOrFocusedIcon);
|
||||
}
|
||||
}
|
||||
|
||||
public CellLayoutChildren getChildrenLayout() {
|
||||
if (getChildCount() > 0) {
|
||||
return (CellLayoutChildren) getChildAt(0);
|
||||
|
@ -457,6 +480,19 @@ public class CellLayout extends ViewGroup {
|
|||
canvas.drawBitmap(b, p.x, p.y, paint);
|
||||
}
|
||||
}
|
||||
|
||||
// We draw the pressed or focused BubbleTextView's background in CellLayout because it
|
||||
// requires an expanded clip rect (due to the glow's blur radius)
|
||||
if (mPressedOrFocusedIcon != null) {
|
||||
final int padding = mPressedOrFocusedIcon.getPressedOrFocusedBackgroundPadding();
|
||||
final Bitmap b = mPressedOrFocusedIcon.getPressedOrFocusedBackground();
|
||||
if (b != null) {
|
||||
canvas.drawBitmap(b,
|
||||
mPressedOrFocusedIcon.getLeft() - padding,
|
||||
mPressedOrFocusedIcon.getTop() - padding,
|
||||
null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue