diff options
-rw-r--r-- | core/java/android/text/DynamicLayout.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/core/java/android/text/DynamicLayout.java b/core/java/android/text/DynamicLayout.java index 2c78679..4f42659 100644 --- a/core/java/android/text/DynamicLayout.java +++ b/core/java/android/text/DynamicLayout.java @@ -268,10 +268,11 @@ extends Layout // generate new layout for affected text StaticLayout reflowed; - + WeakReference<StaticLayout> layoutRef; synchronized (sLock) { - reflowed = sStaticLayout; - sStaticLayout = null; + layoutRef = sStaticLayoutRef; + reflowed = sStaticLayoutRef != null ? sStaticLayoutRef.get() : null; + sStaticLayoutRef = null; } if (reflowed == null) { @@ -358,8 +359,12 @@ extends Layout } synchronized (sLock) { - sStaticLayout = reflowed; reflowed.finish(); + if (layoutRef == null || layoutRef.get() != reflowed) { + sStaticLayoutRef = new WeakReference<StaticLayout>(reflowed); + } else { + sStaticLayoutRef = layoutRef; + } } } @@ -488,7 +493,8 @@ extends Layout private int mTopPadding, mBottomPadding; - private static StaticLayout sStaticLayout = new StaticLayout(true); + private static WeakReference<StaticLayout> sStaticLayoutRef = new WeakReference<StaticLayout>( + new StaticLayout(true)); private static final Object[] sLock = new Object[0]; private static final int START = 0; |