Loading core/java/android/widget/AbsListView.java +7 −3 Original line number Diff line number Diff line Loading @@ -4367,10 +4367,14 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te public void setRemoteViewsAdapter(Intent intent) { // Ensure that we don't already have a RemoteViewsAdapter that is bound to an existing // service handling the specified intent. Intent.FilterComparison fc = new Intent.FilterComparison(intent); if (mRemoteAdapter != null && fc.equals(mRemoteAdapter.getRemoteViewsServiceIntent())) { if (mRemoteAdapter != null) { Intent.FilterComparison fcNew = new Intent.FilterComparison(intent); Intent.FilterComparison fcOld = new Intent.FilterComparison( mRemoteAdapter.getRemoteViewsServiceIntent()); if (fcNew.equals(fcOld)) { return; } } // Otherwise, create a new RemoteViewsAdapter for binding mRemoteAdapter = new RemoteViewsAdapter(getContext(), intent, this); Loading core/java/android/widget/AdapterViewAnimator.java +11 −8 Original line number Diff line number Diff line Loading @@ -389,7 +389,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> int newWindowStartUnbounded = childIndex - mActiveOffset; int newWindowEndUnbounded = newWindowStartUnbounded + mNumActiveViews - 1; int newWindowStart = Math.max(0, newWindowStartUnbounded); int newWindowEnd = Math.min(mAdapter.getCount(), newWindowEndUnbounded); int newWindowEnd = Math.min(mAdapter.getCount() - 1, newWindowEndUnbounded); // This section clears out any items that are in our mActiveViews list // but are outside the effective bounds of our window (this is becomes an issue Loading Loading @@ -592,18 +592,18 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> */ private SavedState(Parcel in) { super(in); whichChild = in.readInt(); this.whichChild = in.readInt(); } @Override public void writeToParcel(Parcel out, int flags) { super.writeToParcel(out, flags); out.writeInt(whichChild); out.writeInt(this.whichChild); } @Override public String toString() { return "AdapterViewAnimator.SavedState{ whichChild = " + whichChild + " }"; return "AdapterViewAnimator.SavedState{ whichChild = " + this.whichChild + " }"; } public static final Parcelable.Creator<SavedState> CREATOR Loading Loading @@ -781,11 +781,14 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> public void setRemoteViewsAdapter(Intent intent) { // Ensure that we don't already have a RemoteViewsAdapter that is bound to an existing // service handling the specified intent. Intent.FilterComparison fc = new Intent.FilterComparison(intent); if (mRemoteViewsAdapter != null && fc.equals(mRemoteViewsAdapter.getRemoteViewsServiceIntent())) { if (mRemoteViewsAdapter != null) { Intent.FilterComparison fcNew = new Intent.FilterComparison(intent); Intent.FilterComparison fcOld = new Intent.FilterComparison( mRemoteViewsAdapter.getRemoteViewsServiceIntent()); if (fcNew.equals(fcOld)) { return; } } // Otherwise, create a new RemoteViewsAdapter for binding mRemoteViewsAdapter = new RemoteViewsAdapter(getContext(), intent, this); Loading core/java/android/widget/RemoteViews.java +108 −2 Original line number Diff line number Diff line Loading @@ -74,6 +74,11 @@ public class RemoteViews implements Parcelable, Filter { */ private ArrayList<Action> mActions; /** * A class to keep track of memory usage by this RemoteViews */ private MemoryUsageCounter mMemoryUsageCounter; /** * This flag indicates whether this RemoteViews object is being created from a Loading Loading @@ -118,6 +123,15 @@ public class RemoteViews implements Parcelable, Filter { public int describeContents() { return 0; } /** * Overridden by each class to report on it's own memory usage */ public void updateMemoryUsageEstimate(MemoryUsageCounter counter) { // We currently only calculate Bitmap memory usage, so by default, don't do anything // here return; } } private class SetEmptyView extends Action { Loading Loading @@ -817,6 +831,35 @@ public class RemoteViews implements Parcelable, Filter { throw new ActionException(ex); } } @Override public void updateMemoryUsageEstimate(MemoryUsageCounter counter) { // We currently only calculate Bitmap memory usage switch (this.type) { case BITMAP: if (this.value != null) { final Bitmap b = (Bitmap) this.value; final Bitmap.Config c = b.getConfig(); int bpp = 4; switch (c) { case ALPHA_8: bpp = 1; break; case RGB_565: case ARGB_4444: bpp = 2; break; case ARGB_8888: bpp = 4; break; } counter.bitmapIncrement(b.getWidth() * b.getHeight() * bpp); } break; default: break; } } } /** Loading Loading @@ -854,12 +897,39 @@ public class RemoteViews implements Parcelable, Filter { } } @Override public void updateMemoryUsageEstimate(MemoryUsageCounter counter) { if (nestedViews != null) { counter.bitmapIncrement(nestedViews.estimateBitmapMemoryUsage()); } } int viewId; RemoteViews nestedViews; public final static int TAG = 4; } /** * Simple class used to keep track of memory usage in a RemoteViews. * */ private class MemoryUsageCounter { public void clear() { mBitmapHeapMemoryUsage = 0; } public void bitmapIncrement(int numBytes) { mBitmapHeapMemoryUsage += numBytes; } public int getBitmapHeapMemoryUsage() { return mBitmapHeapMemoryUsage; } int mBitmapHeapMemoryUsage; } /** * Create a new RemoteViews object that will display the views contained * in the specified layout file. Loading @@ -870,6 +940,10 @@ public class RemoteViews implements Parcelable, Filter { public RemoteViews(String packageName, int layoutId) { mPackage = packageName; mLayoutId = layoutId; // setup the memory usage statistics mMemoryUsageCounter = new MemoryUsageCounter(); recalculateMemoryUsage(); } /** Loading Loading @@ -920,6 +994,10 @@ public class RemoteViews implements Parcelable, Filter { } } } // setup the memory usage statistics mMemoryUsageCounter = new MemoryUsageCounter(); recalculateMemoryUsage(); } @Override Loading @@ -928,6 +1006,9 @@ public class RemoteViews implements Parcelable, Filter { if (mActions != null) { that.mActions = (ArrayList<Action>)mActions.clone(); } // update the memory usage stats of the cloned RemoteViews that.recalculateMemoryUsage(); return that; } Loading @@ -939,7 +1020,7 @@ public class RemoteViews implements Parcelable, Filter { return mLayoutId; } /** /* * This flag indicates whether this RemoteViews object is being created from a * RemoteViewsService for use as a child of a widget collection. This flag is used * to determine whether or not certain features are available, in particular, Loading @@ -950,6 +1031,28 @@ public class RemoteViews implements Parcelable, Filter { mIsWidgetCollectionChild = isWidgetCollectionChild; } /** * Updates the memory usage statistics. */ private void recalculateMemoryUsage() { mMemoryUsageCounter.clear(); // Accumulate the memory usage for each action if (mActions != null) { final int count = mActions.size(); for (int i= 0; i < count; ++i) { mActions.get(i).updateMemoryUsageEstimate(mMemoryUsageCounter); } } } /** * Returns an estimate of the bitmap heap memory usage for this RemoteViews. */ int estimateBitmapMemoryUsage() { return mMemoryUsageCounter.getBitmapHeapMemoryUsage(); } /** * Add an action to be executed on the remote side when apply is called. * Loading @@ -960,6 +1063,9 @@ public class RemoteViews implements Parcelable, Filter { mActions = new ArrayList<Action>(); } mActions.add(a); // update the memory usage stats a.updateMemoryUsageEstimate(mMemoryUsageCounter); } /** Loading core/java/android/widget/RemoteViewsAdapter.java +648 −521 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/widget/AbsListView.java +7 −3 Original line number Diff line number Diff line Loading @@ -4367,10 +4367,14 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te public void setRemoteViewsAdapter(Intent intent) { // Ensure that we don't already have a RemoteViewsAdapter that is bound to an existing // service handling the specified intent. Intent.FilterComparison fc = new Intent.FilterComparison(intent); if (mRemoteAdapter != null && fc.equals(mRemoteAdapter.getRemoteViewsServiceIntent())) { if (mRemoteAdapter != null) { Intent.FilterComparison fcNew = new Intent.FilterComparison(intent); Intent.FilterComparison fcOld = new Intent.FilterComparison( mRemoteAdapter.getRemoteViewsServiceIntent()); if (fcNew.equals(fcOld)) { return; } } // Otherwise, create a new RemoteViewsAdapter for binding mRemoteAdapter = new RemoteViewsAdapter(getContext(), intent, this); Loading
core/java/android/widget/AdapterViewAnimator.java +11 −8 Original line number Diff line number Diff line Loading @@ -389,7 +389,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> int newWindowStartUnbounded = childIndex - mActiveOffset; int newWindowEndUnbounded = newWindowStartUnbounded + mNumActiveViews - 1; int newWindowStart = Math.max(0, newWindowStartUnbounded); int newWindowEnd = Math.min(mAdapter.getCount(), newWindowEndUnbounded); int newWindowEnd = Math.min(mAdapter.getCount() - 1, newWindowEndUnbounded); // This section clears out any items that are in our mActiveViews list // but are outside the effective bounds of our window (this is becomes an issue Loading Loading @@ -592,18 +592,18 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> */ private SavedState(Parcel in) { super(in); whichChild = in.readInt(); this.whichChild = in.readInt(); } @Override public void writeToParcel(Parcel out, int flags) { super.writeToParcel(out, flags); out.writeInt(whichChild); out.writeInt(this.whichChild); } @Override public String toString() { return "AdapterViewAnimator.SavedState{ whichChild = " + whichChild + " }"; return "AdapterViewAnimator.SavedState{ whichChild = " + this.whichChild + " }"; } public static final Parcelable.Creator<SavedState> CREATOR Loading Loading @@ -781,11 +781,14 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> public void setRemoteViewsAdapter(Intent intent) { // Ensure that we don't already have a RemoteViewsAdapter that is bound to an existing // service handling the specified intent. Intent.FilterComparison fc = new Intent.FilterComparison(intent); if (mRemoteViewsAdapter != null && fc.equals(mRemoteViewsAdapter.getRemoteViewsServiceIntent())) { if (mRemoteViewsAdapter != null) { Intent.FilterComparison fcNew = new Intent.FilterComparison(intent); Intent.FilterComparison fcOld = new Intent.FilterComparison( mRemoteViewsAdapter.getRemoteViewsServiceIntent()); if (fcNew.equals(fcOld)) { return; } } // Otherwise, create a new RemoteViewsAdapter for binding mRemoteViewsAdapter = new RemoteViewsAdapter(getContext(), intent, this); Loading
core/java/android/widget/RemoteViews.java +108 −2 Original line number Diff line number Diff line Loading @@ -74,6 +74,11 @@ public class RemoteViews implements Parcelable, Filter { */ private ArrayList<Action> mActions; /** * A class to keep track of memory usage by this RemoteViews */ private MemoryUsageCounter mMemoryUsageCounter; /** * This flag indicates whether this RemoteViews object is being created from a Loading Loading @@ -118,6 +123,15 @@ public class RemoteViews implements Parcelable, Filter { public int describeContents() { return 0; } /** * Overridden by each class to report on it's own memory usage */ public void updateMemoryUsageEstimate(MemoryUsageCounter counter) { // We currently only calculate Bitmap memory usage, so by default, don't do anything // here return; } } private class SetEmptyView extends Action { Loading Loading @@ -817,6 +831,35 @@ public class RemoteViews implements Parcelable, Filter { throw new ActionException(ex); } } @Override public void updateMemoryUsageEstimate(MemoryUsageCounter counter) { // We currently only calculate Bitmap memory usage switch (this.type) { case BITMAP: if (this.value != null) { final Bitmap b = (Bitmap) this.value; final Bitmap.Config c = b.getConfig(); int bpp = 4; switch (c) { case ALPHA_8: bpp = 1; break; case RGB_565: case ARGB_4444: bpp = 2; break; case ARGB_8888: bpp = 4; break; } counter.bitmapIncrement(b.getWidth() * b.getHeight() * bpp); } break; default: break; } } } /** Loading Loading @@ -854,12 +897,39 @@ public class RemoteViews implements Parcelable, Filter { } } @Override public void updateMemoryUsageEstimate(MemoryUsageCounter counter) { if (nestedViews != null) { counter.bitmapIncrement(nestedViews.estimateBitmapMemoryUsage()); } } int viewId; RemoteViews nestedViews; public final static int TAG = 4; } /** * Simple class used to keep track of memory usage in a RemoteViews. * */ private class MemoryUsageCounter { public void clear() { mBitmapHeapMemoryUsage = 0; } public void bitmapIncrement(int numBytes) { mBitmapHeapMemoryUsage += numBytes; } public int getBitmapHeapMemoryUsage() { return mBitmapHeapMemoryUsage; } int mBitmapHeapMemoryUsage; } /** * Create a new RemoteViews object that will display the views contained * in the specified layout file. Loading @@ -870,6 +940,10 @@ public class RemoteViews implements Parcelable, Filter { public RemoteViews(String packageName, int layoutId) { mPackage = packageName; mLayoutId = layoutId; // setup the memory usage statistics mMemoryUsageCounter = new MemoryUsageCounter(); recalculateMemoryUsage(); } /** Loading Loading @@ -920,6 +994,10 @@ public class RemoteViews implements Parcelable, Filter { } } } // setup the memory usage statistics mMemoryUsageCounter = new MemoryUsageCounter(); recalculateMemoryUsage(); } @Override Loading @@ -928,6 +1006,9 @@ public class RemoteViews implements Parcelable, Filter { if (mActions != null) { that.mActions = (ArrayList<Action>)mActions.clone(); } // update the memory usage stats of the cloned RemoteViews that.recalculateMemoryUsage(); return that; } Loading @@ -939,7 +1020,7 @@ public class RemoteViews implements Parcelable, Filter { return mLayoutId; } /** /* * This flag indicates whether this RemoteViews object is being created from a * RemoteViewsService for use as a child of a widget collection. This flag is used * to determine whether or not certain features are available, in particular, Loading @@ -950,6 +1031,28 @@ public class RemoteViews implements Parcelable, Filter { mIsWidgetCollectionChild = isWidgetCollectionChild; } /** * Updates the memory usage statistics. */ private void recalculateMemoryUsage() { mMemoryUsageCounter.clear(); // Accumulate the memory usage for each action if (mActions != null) { final int count = mActions.size(); for (int i= 0; i < count; ++i) { mActions.get(i).updateMemoryUsageEstimate(mMemoryUsageCounter); } } } /** * Returns an estimate of the bitmap heap memory usage for this RemoteViews. */ int estimateBitmapMemoryUsage() { return mMemoryUsageCounter.getBitmapHeapMemoryUsage(); } /** * Add an action to be executed on the remote side when apply is called. * Loading @@ -960,6 +1063,9 @@ public class RemoteViews implements Parcelable, Filter { mActions = new ArrayList<Action>(); } mActions.add(a); // update the memory usage stats a.updateMemoryUsageEstimate(mMemoryUsageCounter); } /** Loading
core/java/android/widget/RemoteViewsAdapter.java +648 −521 File changed.Preview size limit exceeded, changes collapsed. Show changes