From 3f9c971e761222dc9fb4e5866f81c5f7a3348992 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Fri, 31 Oct 2014 11:48:25 -0700 Subject: [PATCH] Adding a couple memory optimizations to Launcher -> Always dispose of widget page views when leaving the activity. These pages hold onto many bitmaps. -> Clear database cache when leaving the activity. Bug: 17967108 Change-Id: I10ebaaed14e7cd86f09a9afcabd73043705f21b8 --- .../launcher3/AppsCustomizePagedView.java | 2 ++ .../launcher3/AppsCustomizeTabHost.java | 8 -------- src/com/android/launcher3/Launcher.java | 19 +++++++++++++++++-- .../PagedViewWithDraggableItems.java | 4 ++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java index 7f3b7fb353..0648858230 100644 --- a/src/com/android/launcher3/AppsCustomizePagedView.java +++ b/src/com/android/launcher3/AppsCustomizePagedView.java @@ -1476,7 +1476,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } + @Override public void reset() { + super.reset(); // If we have reset, then we should not continue to restore the previous state mSaveInstanceStateItemIndex = -1; diff --git a/src/com/android/launcher3/AppsCustomizeTabHost.java b/src/com/android/launcher3/AppsCustomizeTabHost.java index 9a516fd411..df65cbaa1d 100644 --- a/src/com/android/launcher3/AppsCustomizeTabHost.java +++ b/src/com/android/launcher3/AppsCustomizeTabHost.java @@ -141,14 +141,6 @@ public class AppsCustomizeTabHost extends FrameLayout implements LauncherTransit mPagedView.loadAssociatedPages(mPagedView.getCurrentPage()); } } - - public void onTrimMemory() { - mContent.setVisibility(GONE); - // Clear the widget pages of all their subviews - this will trigger the widget previews - // to delete their bitmaps - mPagedView.clearAllWidgetPages(); - } - @Override public ViewGroup getContent() { return mPagedView; diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index bb7265e446..7fd8193bd1 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -50,6 +50,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; import android.content.res.Resources; import android.database.ContentObserver; +import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -3568,6 +3569,9 @@ public class Launcher extends Activity if (mSearchDropTargetBar != null) { mSearchDropTargetBar.hideSearchBar(false); } + + // This can hold unnecessary references to views. + mStateAnimation = null; } }); @@ -3853,6 +3857,9 @@ public class Launcher extends Activity content.setCurrentPage(content.getNextPage()); mAppsCustomizeContent.updateCurrentPageScroll(); + + // This can hold unnecessary references to views. + mStateAnimation = null; } }); @@ -3896,8 +3903,16 @@ public class Launcher extends Activity @Override public void onTrimMemory(int level) { super.onTrimMemory(level); - if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) { - mAppsCustomizeTabHost.onTrimMemory(); + if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) { + // The widget preview db can result in holding onto over + // 3MB of memory for caching which isn't necessary. + SQLiteDatabase.releaseMemory(); + + // We reset the apps customize tray in order to + // to free all the memory associated with widget previews + if (mAppsCustomizeTabHost != null) { + mAppsCustomizeTabHost.reset(); + } } } diff --git a/src/com/android/launcher3/PagedViewWithDraggableItems.java b/src/com/android/launcher3/PagedViewWithDraggableItems.java index 2a29c33f35..7f4a3a0320 100644 --- a/src/com/android/launcher3/PagedViewWithDraggableItems.java +++ b/src/com/android/launcher3/PagedViewWithDraggableItems.java @@ -91,6 +91,10 @@ public abstract class PagedViewWithDraggableItems extends PagedView return super.onTouchEvent(ev); } + public void reset() { + mLastTouchedItem = null; + } + @Override public boolean onTouch(View v, MotionEvent event) { mLastTouchedItem = v;