diff options
| author | Svetoslav Ganov <svetoslavganov@google.com> | 2012-11-27 16:59:37 -0800 |
|---|---|---|
| committer | Svetoslav Ganov <svetoslavganov@google.com> | 2012-11-27 19:10:51 -0800 |
| commit | abae2a1b891772d36d8f781adfcc8969e551691f (patch) | |
| tree | 361a160a5cb0e2e1fdbe8e27a57354152deb3d1f /core/java/android/widget/RelativeLayout.java | |
| parent | dccf9337e6c549cf0bf413dace0fee68589f628f (diff) | |
Simplification of the poolable management utils.
Before to implement a pool of objects, the pooled class had to implement an
interface which was leaking the pool management APIs. This requires
hiding APIs - inconvenient at best. Further, each client had to
implement the chaining of pooled instances which means adding a couple
of member variables which are manipulated by the implemented interface
methods. As a consequence the client is aware of how pooling is
implemented which is error prone and breaks encapsulation. Now the
pool objects are responsible for managing pooling state via reusable
wrapper objects and the clients are oblivious of how pooling is done.
Creating a thin cached wrapper for each pooled object has minimal
performance impact while making the code more maintainable. Actually
implementing of the old version of the APIs was taking as much code
as implementing the pooling yourself.
Also clients had to implement a poolable manager whose responsibility
was to create new instances and provide callbacks when an instance
is added to or removed from the pool. Now, the clinet class should
create a static member for the pool and expose obtain/aquire and
release/recycle methods in which it should create a new instance if
the pool did not return one and clear the state of the host when
it is returned to the pool. Updated the JavaDoc with a best practice.
The pooling was composed of several interfaces and classes scattered
over a few files, now all this is in a single small file.
Update all usages of the pooling APIs in the framework.
Also one had to write a poolable
manager which
Change-Id: Ib8dc286040eb3d7cb7d9668ba76fead05cb97647
Diffstat (limited to 'core/java/android/widget/RelativeLayout.java')
| -rw-r--r-- | core/java/android/widget/RelativeLayout.java | 46 |
1 files changed, 7 insertions, 39 deletions
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java index 3d1b6b36d8c8..83b6a005810f 100644 --- a/core/java/android/widget/RelativeLayout.java +++ b/core/java/android/widget/RelativeLayout.java @@ -30,10 +30,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Rect; import android.util.AttributeSet; -import android.util.Pool; -import android.util.Poolable; -import android.util.PoolableManager; -import android.util.Pools; +import android.util.Pools.SimplePool; import android.util.SparseArray; import android.view.Gravity; import android.view.View; @@ -1631,7 +1628,7 @@ public class RelativeLayout extends ViewGroup { * * A node with no dependent is considered a root of the graph. */ - static class Node implements Poolable<Node> { + static class Node { /** * The view representing this node in the layout. */ @@ -1654,43 +1651,14 @@ public class RelativeLayout extends ViewGroup { // The pool is static, so all nodes instances are shared across // activities, that's why we give it a rather high limit private static final int POOL_LIMIT = 100; - private static final Pool<Node> sPool = Pools.synchronizedPool( - Pools.finitePool(new PoolableManager<Node>() { - public Node newInstance() { - return new Node(); - } - - public void onAcquired(Node element) { - } - - public void onReleased(Node element) { - } - }, POOL_LIMIT) - ); - - private Node mNext; - private boolean mIsPooled; - - public void setNextPoolable(Node element) { - mNext = element; - } - - public Node getNextPoolable() { - return mNext; - } - - public boolean isPooled() { - return mIsPooled; - } - - public void setPooled(boolean isPooled) { - mIsPooled = isPooled; - } + private static final SimplePool<Node> sPool = new SimplePool<Node>(POOL_LIMIT); static Node acquire(View view) { - final Node node = sPool.acquire(); + Node node = sPool.acquire(); + if (node == null) { + node = new Node(); + } node.view = view; - return node; } |
