Skip to content

Commit ab4c4f4

Browse files
author
Romain Guy
committed
Remove unnecessary framework allocations
These allocations were frequently triggered by the home screen. This change removes dozens of allocations during page scrolls on home. Change-Id: I7289efa28ecf5bd62459042b10062aa9cf0432dd
1 parent d0c66f6 commit ab4c4f4

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

core/java/android/view/View.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9187,7 +9187,7 @@ public final boolean getGlobalVisibleRect(Rect r) {
91879187
}
91889188

91899189
public final boolean getLocalVisibleRect(Rect r) {
9190-
Point offset = new Point();
9190+
final Point offset = mAttachInfo != null ? mAttachInfo.mPoint : new Point();
91919191
if (getGlobalVisibleRect(r, offset)) {
91929192
r.offset(-offset.x, -offset.y); // make r local
91939193
return true;
@@ -17006,6 +17006,11 @@ public void setPooled(boolean isPooled) {
1700617006
*/
1700717007
final boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false);
1700817008

17009+
/**
17010+
* Point used to compute visible regions.
17011+
*/
17012+
final Point mPoint = new Point();
17013+
1700917014
/**
1701017015
* Creates a new set of attachment information with the specified
1701117016
* events handler and thread.

core/java/android/widget/ProgressBar.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ public class ProgressBar extends View {
211211
private boolean mOnlyIndeterminate;
212212
private Transformation mTransformation;
213213
private AlphaAnimation mAnimation;
214+
private boolean mHasAnimation;
214215
private Drawable mIndeterminateDrawable;
215216
private Drawable mProgressDrawable;
216217
private Drawable mCurrentDrawable;
@@ -670,18 +671,14 @@ private synchronized void refreshProgress(int id, int progress, boolean fromUser
670671
if (mUiThreadId == Thread.currentThread().getId()) {
671672
doRefreshProgress(id, progress, fromUser, true);
672673
} else {
673-
RefreshProgressRunnable r;
674-
if (mRefreshProgressRunnable != null) {
675-
// Use cached RefreshProgressRunnable if available
676-
r = mRefreshProgressRunnable;
677-
} else {
678-
// Make a new one
679-
r = new RefreshProgressRunnable();
674+
if (mRefreshProgressRunnable == null) {
675+
mRefreshProgressRunnable = new RefreshProgressRunnable();
680676
}
677+
681678
final RefreshData rd = RefreshData.obtain(id, progress, fromUser);
682679
mRefreshData.add(rd);
683680
if (mAttached && !mRefreshIsPosted) {
684-
post(r);
681+
post(mRefreshProgressRunnable);
685682
mRefreshIsPosted = true;
686683
}
687684
}
@@ -860,14 +857,26 @@ void startAnimation() {
860857

861858
if (mIndeterminateDrawable instanceof Animatable) {
862859
mShouldStartAnimationDrawable = true;
863-
mAnimation = null;
860+
mHasAnimation = false;
864861
} else {
862+
mHasAnimation = true;
863+
865864
if (mInterpolator == null) {
866865
mInterpolator = new LinearInterpolator();
867866
}
868867

869-
mTransformation = new Transformation();
870-
mAnimation = new AlphaAnimation(0.0f, 1.0f);
868+
if (mTransformation == null) {
869+
mTransformation = new Transformation();
870+
} else {
871+
mTransformation.clear();
872+
}
873+
874+
if (mAnimation == null) {
875+
mAnimation = new AlphaAnimation(0.0f, 1.0f);
876+
} else {
877+
mAnimation.reset();
878+
}
879+
871880
mAnimation.setRepeatMode(mBehavior);
872881
mAnimation.setRepeatCount(Animation.INFINITE);
873882
mAnimation.setDuration(mDuration);
@@ -881,8 +890,7 @@ void startAnimation() {
881890
* <p>Stop the indeterminate progress animation.</p>
882891
*/
883892
void stopAnimation() {
884-
mAnimation = null;
885-
mTransformation = null;
893+
mHasAnimation = false;
886894
if (mIndeterminateDrawable instanceof Animatable) {
887895
((Animatable) mIndeterminateDrawable).stop();
888896
mShouldStartAnimationDrawable = false;
@@ -1030,7 +1038,7 @@ protected synchronized void onDraw(Canvas canvas) {
10301038
canvas.save();
10311039
canvas.translate(mPaddingLeft, mPaddingTop);
10321040
long time = getDrawingTime();
1033-
if (mAnimation != null) {
1041+
if (mHasAnimation) {
10341042
mAnimation.getTransformation(time, mTransformation);
10351043
float scale = mTransformation.getAlpha();
10361044
try {

0 commit comments

Comments
 (0)