diff options
| -rw-r--r-- | core/java/android/view/View.java | 63 | ||||
| -rw-r--r-- | core/java/android/view/ViewGroup.java | 31 |
2 files changed, 57 insertions, 37 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index eb6cff7aef17..b1025c97a852 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -1623,7 +1623,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility * have changed since the matrix was last calculated. This variable * is only valid after a call to getMatrix(). */ - boolean mMatrixIsIdentity = true; + private boolean mMatrixIsIdentity = true; /** * The degrees rotation around the pivot point. @@ -4855,6 +4855,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility * @return The current transform matrix for the view */ public Matrix getMatrix() { + hasIdentityMatrix(); + return mMatrix; + } + + /** + * Recomputes the transform matrix if necessary. + * + * @return True if the transform matrix is the identity matrix, false otherwise. + */ + boolean hasIdentityMatrix() { if (mMatrixDirty) { // transform-related properties have changed since the last time someone // asked for the matrix; recalculate it with the current values @@ -4865,7 +4875,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility mMatrixIsIdentity = mMatrix.isIdentity(); mInverseMatrixDirty = true; } - return mMatrix; + return mMatrixIsIdentity; } /** @@ -5088,7 +5098,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility */ public final void setTop(int top) { if (top != mTop) { - if (mMatrixIsIdentity) { + if (hasIdentityMatrix()) { final ViewParent p = mParent; if (p != null && mAttachInfo != null) { final int[] location = mAttachInfo.mInvalidateChildLocation; @@ -5103,7 +5113,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility // Double-invalidation is necessary to capture view's old and new areas invalidate(); } + mTop = top; + if (!mMatrixIsIdentity) { mPrivateFlags |= DRAWN; // force another invalidation with the new orientation invalidate(); @@ -5128,7 +5140,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility */ public final void setBottom(int bottom) { if (bottom != mBottom) { - if (mMatrixIsIdentity) { + if (hasIdentityMatrix()) { final ViewParent p = mParent; if (p != null && mAttachInfo != null) { final int[] location = mAttachInfo.mInvalidateChildLocation; @@ -5143,7 +5155,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility // Double-invalidation is necessary to capture view's old and new areas invalidate(); } + mBottom = bottom; + if (!mMatrixIsIdentity) { mPrivateFlags |= DRAWN; // force another invalidation with the new orientation invalidate(); @@ -5168,7 +5182,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility */ public final void setLeft(int left) { if (left != mLeft) { - if (mMatrixIsIdentity) { + if (hasIdentityMatrix()) { final ViewParent p = mParent; if (p != null && mAttachInfo != null) { final int[] location = mAttachInfo.mInvalidateChildLocation; @@ -5183,7 +5197,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility // Double-invalidation is necessary to capture view's old and new areas invalidate(); } + mLeft = left; + if (!mMatrixIsIdentity) { mPrivateFlags |= DRAWN; // force another invalidation with the new orientation invalidate(); @@ -5208,7 +5224,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility */ public final void setRight(int right) { if (right != mRight) { - if (mMatrixIsIdentity) { + if (hasIdentityMatrix()) { final ViewParent p = mParent; if (p != null && mAttachInfo != null) { final int[] location = mAttachInfo.mInvalidateChildLocation; @@ -5223,7 +5239,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility // Double-invalidation is necessary to capture view's old and new areas invalidate(); } + mRight = right; + if (!mMatrixIsIdentity) { mPrivateFlags |= DRAWN; // force another invalidation with the new orientation invalidate(); @@ -5279,16 +5297,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility * @param outRect The hit rectangle of the view. */ public void getHitRect(Rect outRect) { - if (mMatrixIsIdentity || mAttachInfo == null) { + if (hasIdentityMatrix() || mAttachInfo == null) { outRect.set(mLeft, mTop, mRight, mBottom); } else { Matrix m = getMatrix(); final RectF tmpRect = mAttachInfo.mTmpTransformRect; - tmpRect.set(-mPivotX, -mPivotY, - getWidth() - mPivotX, getHeight() - mPivotY); + tmpRect.set(-mPivotX, -mPivotY, getWidth() - mPivotX, getHeight() - mPivotY); m.mapRect(tmpRect); - outRect.set((int)tmpRect.left + mLeft, (int)tmpRect.top + mTop, - (int)tmpRect.right + mLeft, (int)tmpRect.bottom + mTop); + outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, + (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); } } @@ -5304,7 +5321,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility boolean dispatchTouchEvent(MotionEvent ev, float parentX, float parentY) { float localX = parentX - mLeft; float localY = parentY - mTop; - if (!mMatrixIsIdentity && mAttachInfo != null) { + if (!hasIdentityMatrix() && mAttachInfo != null) { // non-identity matrix: transform the point into the view's coordinates final float[] localXY = mAttachInfo.mTmpTransformLocation; localXY[0] = localX; @@ -5313,8 +5330,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility localX = localXY[0]; localY = localXY[1]; } - if (localX >= 0 && localY >= 0 && - localX < (mRight - mLeft) && localY < (mBottom - mTop)) { + if (localX >= 0 && localY >= 0 && localX < (mRight - mLeft) && localY < (mBottom - mTop)) { // It would be safer to clone the event here but we don't for performance. // There are many subtle interactions in touch event dispatch; change at your own risk. mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; @@ -5331,7 +5347,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility * is still within the view. */ private boolean pointInView(float localX, float localY, float slop) { - if (!mMatrixIsIdentity && mAttachInfo != null) { + if (!hasIdentityMatrix() && mAttachInfo != null) { // non-identity matrix: transform the point into the view's coordinates final float[] localXY = mAttachInfo.mTmpTransformLocation; localXY[0] = localX; @@ -5340,11 +5356,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility localX = localXY[0]; localY = localXY[1]; } - if (localX > -slop && localY > -slop && - localX < ((mRight - mLeft) + slop) && localY < ((mBottom - mTop) + slop)) { - return true; - } - return false; + return localX > -slop && localY > -slop && localX < ((mRight - mLeft) + slop) && + localY < ((mBottom - mTop) + slop); } /** @@ -5408,7 +5421,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility */ public void offsetTopAndBottom(int offset) { if (offset != 0) { - if (mMatrixIsIdentity) { + if (hasIdentityMatrix()) { final ViewParent p = mParent; if (p != null && mAttachInfo != null) { final int[] location = mAttachInfo.mInvalidateChildLocation; @@ -5423,8 +5436,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility } else { invalidate(); } + mTop += offset; mBottom += offset; + if (!mMatrixIsIdentity) { mPrivateFlags |= DRAWN; // force another invalidation with the new orientation invalidate(); @@ -5439,7 +5454,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility */ public void offsetLeftAndRight(int offset) { if (offset != 0) { - if (mMatrixIsIdentity) { + if (hasIdentityMatrix()) { final ViewParent p = mParent; if (p != null && mAttachInfo != null) { final int[] location = mAttachInfo.mInvalidateChildLocation; @@ -5454,8 +5469,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility } else { invalidate(); } + mLeft += offset; mRight += offset; + if (!mMatrixIsIdentity) { mPrivateFlags |= DRAWN; // force another invalidation with the new orientation invalidate(); @@ -9297,7 +9314,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility LayoutInflater factory = LayoutInflater.from(context); return factory.inflate(resource, root); } - + /** * A MeasureSpec encapsulates the layout requirements passed from parent to child. * Each MeasureSpec represents a requirement for either the width or the height. diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index ef98958f6f9b..15b833522f92 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -106,7 +106,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager // Target of Motion events private View mMotionTarget; - private final Rect mTempRect = new Rect(); // Layout animation private LayoutAnimationController mLayoutAnimationController; @@ -925,7 +924,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager // dispatch the event. float xc; float yc; - if (mMatrixIsIdentity || mAttachInfo == null) { + if (hasIdentityMatrix() || mAttachInfo == null) { xc = scrolledXFloat - (float) target.mLeft; yc = scrolledYFloat - (float) target.mTop; } else { @@ -1513,7 +1512,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } if (a != null) { - final boolean initialized = a.isInitialized(); if (!initialized) { a.initialize(cr - cl, cb - ct, getWidth(), getHeight()); @@ -1609,13 +1607,15 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager float alpha = child.getAlpha(); - if (transformToApply != null || alpha < 1.0f || !child.mMatrixIsIdentity) { + if (transformToApply != null || alpha < 1.0f || !child.hasIdentityMatrix()) { int transX = 0; int transY = 0; + if (hasNoCache) { transX = -sx; transY = -sy; } + if (transformToApply != null) { if (concatMatrix) { // Undo the scroll translation, apply the transformation matrix, @@ -1625,28 +1625,31 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager canvas.translate(transX, transY); mGroupFlags |= FLAG_CLEAR_TRANSFORMATION; } + float transformAlpha = transformToApply.getAlpha(); if (transformAlpha < 1.0f) { alpha *= transformToApply.getAlpha(); mGroupFlags |= FLAG_CLEAR_TRANSFORMATION; } } - if (!child.mMatrixIsIdentity) { + + if (!child.hasIdentityMatrix()) { canvas.translate(-transX, -transY); canvas.concat(child.getMatrix()); canvas.translate(transX, transY); } + if (alpha < 1.0f) { mGroupFlags |= FLAG_CLEAR_TRANSFORMATION; - } - - if (alpha < 1.0f && hasNoCache) { - final int multipliedAlpha = (int) (255 * alpha); - if (!child.onSetAlpha(multipliedAlpha)) { - canvas.saveLayerAlpha(sx, sy, sx + cr - cl, sy + cb - ct, multipliedAlpha, - Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); - } else { - child.mPrivateFlags |= ALPHA_SET; + + if (hasNoCache) { + final int multipliedAlpha = (int) (255 * alpha); + if (!child.onSetAlpha(multipliedAlpha)) { + canvas.saveLayerAlpha(sx, sy, sx + cr - cl, sy + cb - ct, multipliedAlpha, + Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); + } else { + child.mPrivateFlags |= ALPHA_SET; + } } } } else if ((child.mPrivateFlags & ALPHA_SET) == ALPHA_SET) { |