Merge "Remove unnecessary framework allocations" into jb-dev

This commit is contained in:
Romain Guy
2012-05-06 13:27:29 -07:00
committed by Android (Google) Code Review
2 changed files with 28 additions and 15 deletions

View File

@ -9187,7 +9187,7 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
} }
public final boolean getLocalVisibleRect(Rect r) { public final boolean getLocalVisibleRect(Rect r) {
Point offset = new Point(); final Point offset = mAttachInfo != null ? mAttachInfo.mPoint : new Point();
if (getGlobalVisibleRect(r, offset)) { if (getGlobalVisibleRect(r, offset)) {
r.offset(-offset.x, -offset.y); // make r local r.offset(-offset.x, -offset.y); // make r local
return true; return true;
@ -17023,6 +17023,11 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
*/ */
final boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false); final boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false);
/**
* Point used to compute visible regions.
*/
final Point mPoint = new Point();
/** /**
* Creates a new set of attachment information with the specified * Creates a new set of attachment information with the specified
* events handler and thread. * events handler and thread.

View File

@ -211,6 +211,7 @@ public class ProgressBar extends View {
private boolean mOnlyIndeterminate; private boolean mOnlyIndeterminate;
private Transformation mTransformation; private Transformation mTransformation;
private AlphaAnimation mAnimation; private AlphaAnimation mAnimation;
private boolean mHasAnimation;
private Drawable mIndeterminateDrawable; private Drawable mIndeterminateDrawable;
private Drawable mProgressDrawable; private Drawable mProgressDrawable;
private Drawable mCurrentDrawable; private Drawable mCurrentDrawable;
@ -670,18 +671,14 @@ public class ProgressBar extends View {
if (mUiThreadId == Thread.currentThread().getId()) { if (mUiThreadId == Thread.currentThread().getId()) {
doRefreshProgress(id, progress, fromUser, true); doRefreshProgress(id, progress, fromUser, true);
} else { } else {
RefreshProgressRunnable r; if (mRefreshProgressRunnable == null) {
if (mRefreshProgressRunnable != null) { mRefreshProgressRunnable = new RefreshProgressRunnable();
// Use cached RefreshProgressRunnable if available
r = mRefreshProgressRunnable;
} else {
// Make a new one
r = new RefreshProgressRunnable();
} }
final RefreshData rd = RefreshData.obtain(id, progress, fromUser); final RefreshData rd = RefreshData.obtain(id, progress, fromUser);
mRefreshData.add(rd); mRefreshData.add(rd);
if (mAttached && !mRefreshIsPosted) { if (mAttached && !mRefreshIsPosted) {
post(r); post(mRefreshProgressRunnable);
mRefreshIsPosted = true; mRefreshIsPosted = true;
} }
} }
@ -860,14 +857,26 @@ public class ProgressBar extends View {
if (mIndeterminateDrawable instanceof Animatable) { if (mIndeterminateDrawable instanceof Animatable) {
mShouldStartAnimationDrawable = true; mShouldStartAnimationDrawable = true;
mAnimation = null; mHasAnimation = false;
} else { } else {
mHasAnimation = true;
if (mInterpolator == null) { if (mInterpolator == null) {
mInterpolator = new LinearInterpolator(); mInterpolator = new LinearInterpolator();
} }
mTransformation = new Transformation(); if (mTransformation == null) {
mAnimation = new AlphaAnimation(0.0f, 1.0f); mTransformation = new Transformation();
} else {
mTransformation.clear();
}
if (mAnimation == null) {
mAnimation = new AlphaAnimation(0.0f, 1.0f);
} else {
mAnimation.reset();
}
mAnimation.setRepeatMode(mBehavior); mAnimation.setRepeatMode(mBehavior);
mAnimation.setRepeatCount(Animation.INFINITE); mAnimation.setRepeatCount(Animation.INFINITE);
mAnimation.setDuration(mDuration); mAnimation.setDuration(mDuration);
@ -881,8 +890,7 @@ public class ProgressBar extends View {
* <p>Stop the indeterminate progress animation.</p> * <p>Stop the indeterminate progress animation.</p>
*/ */
void stopAnimation() { void stopAnimation() {
mAnimation = null; mHasAnimation = false;
mTransformation = null;
if (mIndeterminateDrawable instanceof Animatable) { if (mIndeterminateDrawable instanceof Animatable) {
((Animatable) mIndeterminateDrawable).stop(); ((Animatable) mIndeterminateDrawable).stop();
mShouldStartAnimationDrawable = false; mShouldStartAnimationDrawable = false;
@ -1030,7 +1038,7 @@ public class ProgressBar extends View {
canvas.save(); canvas.save();
canvas.translate(mPaddingLeft, mPaddingTop); canvas.translate(mPaddingLeft, mPaddingTop);
long time = getDrawingTime(); long time = getDrawingTime();
if (mAnimation != null) { if (mHasAnimation) {
mAnimation.getTransformation(time, mTransformation); mAnimation.getTransformation(time, mTransformation);
float scale = mTransformation.getAlpha(); float scale = mTransformation.getAlpha();
try { try {