Merge "Switching the accessibility poolable classes to the new pool management APIs."
This commit is contained in:
committed by
Android (Google) Code Review
commit
ec45cc096d
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user