From e572fe46f75adfb1adbf3c2a6812d1e3dbdee5e1 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Wed, 12 Jun 2013 22:46:02 -0400 Subject: [PATCH] Make HolographicOutlineHelper a singleton. It's a pretty heavy object, including three Paints at 74 bytes apiece, and we allocate one for every workspace and every icon. We really only need one. Change-Id: Ic9e12d478c3be27b13133718875c91540f7ccf4c --- src/com/android/launcher3/BubbleTextView.java | 2 +- .../android/launcher3/HolographicOutlineHelper.java | 10 +++++++++- src/com/android/launcher3/Workspace.java | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 7cac8a68c3..7c7d93e4d5 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -45,7 +45,7 @@ public class BubbleTextView extends TextView { private int mPrevAlpha = -1; - private final HolographicOutlineHelper mOutlineHelper = new HolographicOutlineHelper(); + private final HolographicOutlineHelper mOutlineHelper = HolographicOutlineHelper.obtain(); private final Canvas mTempCanvas = new Canvas(); private final Rect mTempRect = new Rect(); private boolean mDidInvalidateForPressedState; diff --git a/src/com/android/launcher3/HolographicOutlineHelper.java b/src/com/android/launcher3/HolographicOutlineHelper.java index 0344cd537f..47c40b657b 100644 --- a/src/com/android/launcher3/HolographicOutlineHelper.java +++ b/src/com/android/launcher3/HolographicOutlineHelper.java @@ -43,6 +43,8 @@ public class HolographicOutlineHelper { private static final int MEDIUM = 1; private static final int EXTRA_THICK = 2; + static HolographicOutlineHelper INSTANCE; + static { final float scale = LauncherAppState.getScreenDensity(); @@ -56,9 +58,11 @@ public class HolographicOutlineHelper { sExtraThickInnerBlurMaskFilter = new BlurMaskFilter(scale * 6.0f, BlurMaskFilter.Blur.NORMAL); sThickInnerBlurMaskFilter = new BlurMaskFilter(scale * 4.0f, BlurMaskFilter.Blur.NORMAL); sMediumInnerBlurMaskFilter = new BlurMaskFilter(scale * 2.0f, BlurMaskFilter.Blur.NORMAL); + + INSTANCE = new HolographicOutlineHelper(); } - HolographicOutlineHelper() { + private HolographicOutlineHelper() { mHolographicPaint.setFilterBitmap(true); mHolographicPaint.setAntiAlias(true); mBlurPaint.setFilterBitmap(true); @@ -68,6 +72,10 @@ public class HolographicOutlineHelper { mErasePaint.setAntiAlias(true); } + public static HolographicOutlineHelper obtain() { + return INSTANCE; + } + /** * Returns the interpolated holographic highlight alpha for the effect we want when scrolling * pages. diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index fd324420a0..abf3b9832a 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -167,7 +167,7 @@ public class Workspace extends SmoothPagedView /** Is the user is dragging an item near the edge of a page? */ private boolean mInScrollArea = false; - private final HolographicOutlineHelper mOutlineHelper = new HolographicOutlineHelper(); + private final HolographicOutlineHelper mOutlineHelper = HolographicOutlineHelper.obtain(); private Bitmap mDragOutline = null; private final Rect mTempRect = new Rect(); private final int[] mTempXY = new int[2];