diff options
| author | Svetoslav Ganov <svetoslavganov@google.com> | 2012-11-28 09:11:41 -0800 |
|---|---|---|
| committer | Svetoslav Ganov <svetoslavganov@google.com> | 2012-11-28 09:11:51 -0800 |
| commit | f4782ec9c57a40224ac0974fce6b6fe280c829ce (patch) | |
| tree | 718df5c4da3b6c7691bd5b39d0687dcee82da8de /core | |
| parent | abae2a1b891772d36d8f781adfcc8969e551691f (diff) | |
| download | frameworks_base-f4782ec9c57a40224ac0974fce6b6fe280c829ce.zip frameworks_base-f4782ec9c57a40224ac0974fce6b6fe280c829ce.tar.gz frameworks_base-f4782ec9c57a40224ac0974fce6b6fe280c829ce.tar.bz2 | |
Switching the accessibility poolable classes to the new pool management APIs.
The pool management APIs were simplified and using them requires much less
code than implementing your own pooling. Using common pooling logic is
also less error prone. This change swithces AccessibilityEvent and
AccessibilityNodeInfo to the new APIs.
Change-Id: I2dcfe2e1b0b0be5f89bd92359766ae3d6f8a143b
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/view/accessibility/AccessibilityEvent.java | 33 | ||||
| -rw-r--r-- | core/java/android/view/accessibility/AccessibilityNodeInfo.java | 35 |
2 files changed, 13 insertions, 55 deletions
diff --git a/core/java/android/view/accessibility/AccessibilityEvent.java b/core/java/android/view/accessibility/AccessibilityEvent.java index 03288ba..9603fe5 100644 --- a/core/java/android/view/accessibility/AccessibilityEvent.java +++ b/core/java/android/view/accessibility/AccessibilityEvent.java @@ -19,6 +19,7 @@ package android.view.accessibility; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; +import android.util.Pools.SynchronizedPool; import java.util.ArrayList; import java.util.List; @@ -686,11 +687,8 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par public static final int TYPES_ALL_MASK = 0xFFFFFFFF; private static final int MAX_POOL_SIZE = 10; - private static final Object sPoolLock = new Object(); - private static AccessibilityEvent sPool; - private static int sPoolSize; - private AccessibilityEvent mNext; - private boolean mIsInPool; + private static final SynchronizedPool<AccessibilityEvent> sPool = + new SynchronizedPool<AccessibilityEvent>(MAX_POOL_SIZE); private int mEventType; private CharSequence mPackageName; @@ -916,17 +914,8 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par * @return An instance. */ public static AccessibilityEvent obtain() { - synchronized (sPoolLock) { - if (sPool != null) { - AccessibilityEvent event = sPool; - sPool = sPool.mNext; - sPoolSize--; - event.mNext = null; - event.mIsInPool = false; - return event; - } - return new AccessibilityEvent(); - } + AccessibilityEvent event = sPool.acquire(); + return (event != null) ? event : new AccessibilityEvent(); } /** @@ -939,18 +928,8 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par */ @Override public void recycle() { - if (mIsInPool) { - throw new IllegalStateException("Event already recycled!"); - } clear(); - synchronized (sPoolLock) { - if (sPoolSize <= MAX_POOL_SIZE) { - mNext = sPool; - sPool = this; - mIsInPool = true; - sPoolSize++; - } - } + sPool.release(this); } /** diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.java b/core/java/android/view/accessibility/AccessibilityNodeInfo.java index 1dc2487..0751566 100644 --- a/core/java/android/view/accessibility/AccessibilityNodeInfo.java +++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.java @@ -20,6 +20,7 @@ import android.graphics.Rect; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; +import android.util.Pools.SynchronizedPool; import android.util.SparseLongArray; import android.view.View; @@ -354,11 +355,9 @@ public class AccessibilityNodeInfo implements Parcelable { // Housekeeping. private static final int MAX_POOL_SIZE = 50; - private static final Object sPoolLock = new Object(); - private static AccessibilityNodeInfo sPool; - private static int sPoolSize; - private AccessibilityNodeInfo mNext; - private boolean mIsInPool; + private static final SynchronizedPool<AccessibilityNodeInfo> sPool = + new SynchronizedPool<AccessibilityNodeInfo>(MAX_POOL_SIZE); + private boolean mSealed; // Data. @@ -1517,17 +1516,8 @@ public class AccessibilityNodeInfo implements Parcelable { * @return An instance. */ public static AccessibilityNodeInfo obtain() { - synchronized (sPoolLock) { - if (sPool != null) { - AccessibilityNodeInfo info = sPool; - sPool = sPool.mNext; - sPoolSize--; - info.mNext = null; - info.mIsInPool = false; - return info; - } - return new AccessibilityNodeInfo(); - } + AccessibilityNodeInfo info = sPool.acquire(); + return (info != null) ? info : new AccessibilityNodeInfo(); } /** @@ -1552,18 +1542,8 @@ public class AccessibilityNodeInfo implements Parcelable { * @throws IllegalStateException If the info is already recycled. */ public void recycle() { - if (mIsInPool) { - throw new IllegalStateException("Info already recycled!"); - } clear(); - synchronized (sPoolLock) { - if (sPoolSize <= MAX_POOL_SIZE) { - mNext = sPool; - sPool = this; - mIsInPool = true; - sPoolSize++; - } - } + sPool.release(this); } /** @@ -1620,7 +1600,6 @@ public class AccessibilityNodeInfo implements Parcelable { * * @param other The other instance. */ - @SuppressWarnings("unchecked") private void init(AccessibilityNodeInfo other) { mSealed = other.mSealed; mSourceNodeId = other.mSourceNodeId; |
