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/ProgressBar.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/ProgressBar.java')
| -rw-r--r-- | core/java/android/widget/ProgressBar.java | 56 |
1 files changed, 10 insertions, 46 deletions
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index ea50e2e438ec..f2d2c65b4430 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -38,10 +38,7 @@ import android.graphics.drawable.shapes.Shape; import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; -import android.util.Pool; -import android.util.Poolable; -import android.util.PoolableManager; -import android.util.Pools; +import android.util.Pools.SynchronizedPool; import android.view.Gravity; import android.view.RemotableViewMethod; import android.view.View; @@ -604,33 +601,20 @@ public class ProgressBar extends View { } } - private static class RefreshData implements Poolable<RefreshData> { + private static class RefreshData { + private static final int POOL_MAX = 24; + private static final SynchronizedPool<RefreshData> sPool = + new SynchronizedPool<RefreshData>(POOL_MAX); + public int id; public int progress; public boolean fromUser; - - private RefreshData mNext; - private boolean mIsPooled; - - private static final int POOL_MAX = 24; - private static final Pool<RefreshData> sPool = Pools.synchronizedPool( - Pools.finitePool(new PoolableManager<RefreshData>() { - @Override - public RefreshData newInstance() { - return new RefreshData(); - } - - @Override - public void onAcquired(RefreshData element) { - } - - @Override - public void onReleased(RefreshData element) { - } - }, POOL_MAX)); public static RefreshData obtain(int id, int progress, boolean fromUser) { RefreshData rd = sPool.acquire(); + if (rd == null) { + rd = new RefreshData(); + } rd.id = id; rd.progress = progress; rd.fromUser = fromUser; @@ -640,28 +624,8 @@ public class ProgressBar extends View { public void recycle() { sPool.release(this); } - - @Override - public void setNextPoolable(RefreshData element) { - mNext = element; - } - - @Override - public RefreshData getNextPoolable() { - return mNext; - } - - @Override - public boolean isPooled() { - return mIsPooled; - } - - @Override - public void setPooled(boolean isPooled) { - mIsPooled = isPooled; - } } - + private synchronized void doRefreshProgress(int id, int progress, boolean fromUser, boolean callBackToApp) { float scale = mMax > 0 ? (float) progress / (float) mMax : 0; |
