Bug 1168497 - Only run LayerMarginsAnimationTask when there is work to do. r?snorp

Before, we'd run this animate the dynamic toolbar over a specified duration
even if the dynamic toolbar was not actually animating anywhere. Thus, this
patch reduces excess work when the dynamic toolbar is not scrolled out of
place (e.g. onPanZoomStopped, onLocationChange, onTabChanged). This reduced
work includes allocating the RenderTask only when we need it.

--HG--
extra : commitid : 3tswkPeE27
extra : rebase_source : e0ffbbfdb8f60e80ef96372d71693aa2ee0490bc
This commit is contained in:
Michael Comella 2015-06-09 16:15:28 -07:00
Родитель 9852029db4
Коммит 211b2b667a
1 изменённых файлов: 15 добавлений и 0 удалений

Просмотреть файл

@ -110,11 +110,26 @@ public class LayerMarginsAnimator {
}
ImmutableViewportMetrics metrics = mTarget.getViewportMetrics();
if (!canAnimateMargins(metrics, left, top, right, bottom)) {
return;
}
mAnimationTask = new LayerMarginsAnimationTask(false, metrics, left, top, right, bottom);
mTarget.getView().postRenderTask(mAnimationTask);
}
/**
* Returns true if we can animate the margins from their current position, false otherwise.
* We can animate if the given values are not identical (i.e. there is somewhere to animate to).
*/
private static boolean canAnimateMargins(final ImmutableViewportMetrics metrics,
final float left, final float top, final float right, final float bottom) {
return !(FloatUtils.fuzzyEquals(left, metrics.marginLeft) &&
FloatUtils.fuzzyEquals(top, metrics.marginTop) &&
FloatUtils.fuzzyEquals(right, metrics.marginRight) &&
FloatUtils.fuzzyEquals(bottom, metrics.marginBottom));
}
/**
* Exposes the margin area by growing the margin components of the current
* metrics to the values set in setMaxMargins.