aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Perez <diegoperez@google.com>2017-07-07 14:17:33 +0100
committerDiego Perez <diegoperez@google.com>2017-07-07 14:17:33 +0100
commit878037d8f533ca51121d0dc035181e5ecb2762cf (patch)
tree16499d4468c3d1959c273336ed21103d7955d709
parent2d6dbfc19ec55a2e5158f49557f380ec83e624c6 (diff)
downloadlayoutlib-878037d8f533ca51121d0dc035181e5ecb2762cf.tar.gz
Clean-up any choreographer callbacks after render
After calling render, any animation callbacks need to be removed so they are not executed in the next frame. Test: Existing tests pass Bug: 63380076 Change-Id: If3974d84b47a48ee7c769f31c6c179ccc6e8f7c2
-rw-r--r--bridge/src/android/animation/PropertyValuesHolder_Delegate.java4
-rw-r--r--bridge/src/android/view/Choreographer_Delegate.java11
-rw-r--r--bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java2
3 files changed, 13 insertions, 4 deletions
diff --git a/bridge/src/android/animation/PropertyValuesHolder_Delegate.java b/bridge/src/android/animation/PropertyValuesHolder_Delegate.java
index 28a489ad6e..1d7026c4b2 100644
--- a/bridge/src/android/animation/PropertyValuesHolder_Delegate.java
+++ b/bridge/src/android/animation/PropertyValuesHolder_Delegate.java
@@ -106,9 +106,7 @@ class PropertyValuesHolder_Delegate {
try {
method.setAccessible(true);
method.invoke(target, args);
- } catch (IllegalAccessException e) {
- Bridge.getLog().error(null, "Unable to update property during animation", e, null);
- } catch (InvocationTargetException e) {
+ } catch (IllegalAccessException | InvocationTargetException e) {
Bridge.getLog().error(null, "Unable to update property during animation", e, null);
}
}
diff --git a/bridge/src/android/view/Choreographer_Delegate.java b/bridge/src/android/view/Choreographer_Delegate.java
index 494ffa1518..453d59edd4 100644
--- a/bridge/src/android/view/Choreographer_Delegate.java
+++ b/bridge/src/android/view/Choreographer_Delegate.java
@@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicReference;
*
*/
public class Choreographer_Delegate {
- static final AtomicReference<Choreographer> mInstance = new AtomicReference<Choreographer>();
+ private static final AtomicReference<Choreographer> mInstance = new AtomicReference<Choreographer>();
@LayoutlibDelegate
public static Choreographer getInstance() {
@@ -69,6 +69,15 @@ public class Choreographer_Delegate {
thisChoreographer.doCallbacks(Choreographer.CALLBACK_COMMIT, frameTimeNanos);
}
+ public static void clearFrames() {
+ Choreographer thisChoreographer = Choreographer.getInstance();
+
+ thisChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT, null, null);
+ thisChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, null, null);
+ thisChoreographer.removeCallbacks(Choreographer.CALLBACK_TRAVERSAL, null, null);
+ thisChoreographer.removeCallbacks(Choreographer.CALLBACK_COMMIT, null, null);
+ }
+
public static void dispose() {
try {
Field threadInstanceField = Choreographer.class.getDeclaredField("sThreadInstance");
diff --git a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 5adba23b2a..56665044a9 100644
--- a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -552,6 +552,8 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
visitAllChildren(mViewRoot, 0, 0, params.getExtendedViewInfoMode(),
false);
+ Choreographer_Delegate.clearFrames();
+
// success!
return renderResult;
} catch (Throwable e) {