OSDN Git Service

Reduce recents memory usage
authorMichael Jurka <mikejurka@google.com>
Fri, 1 Jun 2012 11:06:45 +0000 (04:06 -0700)
committerMichael Jurka <mikejurka@google.com>
Fri, 1 Jun 2012 11:52:03 +0000 (04:52 -0700)
Change-Id: I7e50bc1987dd75b1fbbe4e91d13490ae1faa6cb8

packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
packages/SystemUI/src/com/android/systemui/recent/RecentsScrollViewPerformanceHelper.java
packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java

index 1302c1f..e1abb23 100644 (file)
@@ -73,10 +73,16 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
         return mLinearLayout.getWidth() - getWidth();
     }
 
+    private void addToRecycledViews(View v) {
+        if (mRecycledViews.size() < mNumItemsInOneScreenful) {
+            mRecycledViews.add(v);
+        }
+    }
+
     private void update() {
         for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
             View v = mLinearLayout.getChildAt(i);
-            mRecycledViews.add(v);
+            addToRecycledViews(v);
             mAdapter.recycleView(v);
         }
         LayoutTransition transitioner = getLayoutTransition();
@@ -187,7 +193,7 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
     }
 
     public void onChildDismissed(View v) {
-        mRecycledViews.add(v);
+        addToRecycledViews(v);
         mLinearLayout.removeView(v);
         if (v.getParent() != null) {
             throw new RuntimeException("Recycled child has parent");
@@ -362,13 +368,13 @@ public class RecentsHorizontalScrollView extends HorizontalScrollView
         child.measure(childWidthMeasureSpec, childheightMeasureSpec);
         mNumItemsInOneScreenful =
                 (int) FloatMath.ceil(dm.widthPixels / (float) child.getMeasuredWidth());
-        mRecycledViews.add(child);
+        addToRecycledViews(child);
         if (child.getParent() != null) {
             throw new RuntimeException("First recycled child has parent");
         }
 
         for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) {
-            mRecycledViews.add(mAdapter.createView(mLinearLayout));
+            addToRecycledViews(mAdapter.createView(mLinearLayout));
             if (mRecycledViews.get(mRecycledViews.size() - 1).getParent() != null) {
                 throw new RuntimeException("Recycled child has parent");
             }
index 6bd1826..9bc54cb 100644 (file)
@@ -78,9 +78,10 @@ public class RecentsScrollViewPerformanceHelper {
 
     public void addViewCallback(View newLinearLayoutChild) {
         if (mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) {
-            final View view = newLinearLayoutChild;
-            view.setDrawingCacheEnabled(true);
-            view.buildDrawingCache();
+            final RecentsPanelView.ViewHolder holder =
+                    (RecentsPanelView.ViewHolder) newLinearLayoutChild.getTag();
+            holder.labelView.setDrawingCacheEnabled(true);
+            holder.labelView.buildDrawingCache();
         }
     }
 
index f682203..33d2a75 100644 (file)
@@ -74,10 +74,16 @@ public class RecentsVerticalScrollView extends ScrollView
         return mLinearLayout.getHeight() - getHeight();
     }
 
+    private void addToRecycledViews(View v) {
+        if (mRecycledViews.size() < mNumItemsInOneScreenful) {
+            mRecycledViews.add(v);
+        }
+    }
+
     private void update() {
         for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
             View v = mLinearLayout.getChildAt(i);
-            mRecycledViews.add(v);
+            addToRecycledViews(v);
             mAdapter.recycleView(v);
         }
         LayoutTransition transitioner = getLayoutTransition();
@@ -203,7 +209,7 @@ public class RecentsVerticalScrollView extends ScrollView
     }
 
     public void onChildDismissed(View v) {
-        mRecycledViews.add(v);
+        addToRecycledViews(v);
         mLinearLayout.removeView(v);
         if (v.getParent() != null) {
             throw new RuntimeException("Recycled child has parent");
@@ -380,13 +386,13 @@ public class RecentsVerticalScrollView extends ScrollView
         child.measure(childWidthMeasureSpec, childheightMeasureSpec);
         mNumItemsInOneScreenful =
                 (int) FloatMath.ceil(dm.heightPixels / (float) child.getMeasuredHeight());
-        mRecycledViews.add(child);
+        addToRecycledViews(child);
         if (child.getParent() != null) {
             throw new RuntimeException("First recycled child has parent");
         }
 
         for (int i = 0; i < mNumItemsInOneScreenful - 1; i++) {
-            mRecycledViews.add(mAdapter.createView(mLinearLayout));
+            addToRecycledViews(mAdapter.createView(mLinearLayout));
             if (mRecycledViews.get(mRecycledViews.size() - 1).getParent() != null) {
                 throw new RuntimeException("Recycled child has parent");
             }