| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.widget; |
| 18 |
|
| 19 |
import android.util.Log; |
| 20 |
import android.util.Pools; |
| 21 |
import android.view.View; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class MessagingPool<T extends View> implements Pools.Pool<T> { |
| 29 |
private static final boolean ENABLED = false; |
| 30 |
private static final String TAG = "MessagingPool"; |
| 31 |
private final int mMaxPoolSize; |
| 32 |
private Pools.SynchronizedPool<T> mCurrentPool; |
| 33 |
|
| 34 |
public MessagingPool(int maxPoolSize) { |
| 35 |
mMaxPoolSize = maxPoolSize; |
| 36 |
if (ENABLED) { |
| 37 |
mCurrentPool = new Pools.SynchronizedPool<>(mMaxPoolSize); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public T acquire() { |
| 43 |
if (!ENABLED) { |
| 44 |
return null; |
| 45 |
} |
| 46 |
T instance = mCurrentPool.acquire(); |
| 47 |
if (instance.getParent() != null) { |
| 48 |
Log.wtf(TAG, "acquired " + instance + " with parent " + instance.getParent()); |
| 49 |
return null; |
| 50 |
} |
| 51 |
return instance; |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public boolean release(T instance) { |
| 56 |
if (instance.getParent() != null) { |
| 57 |
Log.wtf(TAG, "releasing " + instance + " with parent " + instance.getParent()); |
| 58 |
return false; |
| 59 |
} |
| 60 |
if (!ENABLED) { |
| 61 |
return false; |
| 62 |
} |
| 63 |
return mCurrentPool.release(instance); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
public void clear() { |
| 68 |
if (ENABLED) { |
| 69 |
mCurrentPool = new Pools.SynchronizedPool<>(mMaxPoolSize); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
} |