From 4fe5a37dda8eb1869f9328d94236eb2c23f8109c Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Thu, 14 May 2015 19:55:10 -0700 Subject: Optimizing shadow generation by reusing bitmap. > Not creating unnecessary bitmaps > Final bitmap is generated as ALPHA_8 instead of ARGB_8888 > The shadow drawing is done directly in the view Change-Id: I504fa2ea3abdc1a3c3fb9ad57d6e28880d2584a1 --- src/com/android/launcher3/CellLayout.java | 62 ++++++++++++++----------------- 1 file changed, 27 insertions(+), 35 deletions(-) (limited to 'src/com/android/launcher3/CellLayout.java') diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 72eabf177..a348008d8 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -132,7 +132,7 @@ public class CellLayout extends ViewGroup { private int mDragOutlineCurrent = 0; private final Paint mDragOutlinePaint = new Paint(); - private final FastBitmapView mTouchFeedbackView; + private final ClickShadowView mTouchFeedbackView; @Thunk HashMap mReorderAnimators = new HashMap(); @@ -301,9 +301,8 @@ public class CellLayout extends ViewGroup { mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY); - mTouchFeedbackView = new FastBitmapView(context); - // Make the feedback view large enough to hold the blur bitmap. - addView(mTouchFeedbackView, (int) (grid.cellWidthPx * 1.5), (int) (grid.cellHeightPx * 1.5)); + mTouchFeedbackView = new ClickShadowView(context); + addView(mTouchFeedbackView); addView(mShortcutsAndWidgets); } @@ -410,22 +409,14 @@ public class CellLayout extends ViewGroup { invalidate(); } - void setPressedIcon(BubbleTextView icon, Bitmap background, int padding) { + void setPressedIcon(BubbleTextView icon, Bitmap background) { if (icon == null || background == null) { mTouchFeedbackView.setBitmap(null); mTouchFeedbackView.animate().cancel(); } else { - int offset = getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - - (mCountX * mCellWidth); - mTouchFeedbackView.setTranslationX(icon.getLeft() + (int) Math.ceil(offset / 2f) - - padding); - mTouchFeedbackView.setTranslationY(icon.getTop() - padding); if (mTouchFeedbackView.setBitmap(background)) { - mTouchFeedbackView.setAlpha(0); - mTouchFeedbackView.animate().alpha(1) - .setDuration(FastBitmapDrawable.CLICK_FEEDBACK_DURATION) - .setInterpolator(FastBitmapDrawable.CLICK_FEEDBACK_INTERPOLATOR) - .start(); + mTouchFeedbackView.alignWithIconView(icon, mShortcutsAndWidgets); + mTouchFeedbackView.animateShadow(); } } } @@ -895,19 +886,20 @@ public class CellLayout extends ViewGroup { mWidthGap = mOriginalWidthGap; mHeightGap = mOriginalHeightGap; } - int count = getChildCount(); - int maxWidth = 0; - int maxHeight = 0; - for (int i = 0; i < count; i++) { - View child = getChildAt(i); - int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth, - MeasureSpec.EXACTLY); - int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight, - MeasureSpec.EXACTLY); - child.measure(childWidthMeasureSpec, childheightMeasureSpec); - maxWidth = Math.max(maxWidth, child.getMeasuredWidth()); - maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); - } + + // Make the feedback view large enough to hold the blur bitmap. + mTouchFeedbackView.measure( + MeasureSpec.makeMeasureSpec(mCellWidth + mTouchFeedbackView.getExtraSize(), + MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(mCellHeight + mTouchFeedbackView.getExtraSize(), + MeasureSpec.EXACTLY)); + + mShortcutsAndWidgets.measure( + MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY)); + + int maxWidth = mShortcutsAndWidgets.getMeasuredWidth(); + int maxHeight = mShortcutsAndWidgets.getMeasuredHeight(); if (mFixedWidth > 0 && mFixedHeight > 0) { setMeasuredDimension(maxWidth, maxHeight); } else { @@ -921,13 +913,13 @@ public class CellLayout extends ViewGroup { (mCountX * mCellWidth); int left = getPaddingLeft() + (int) Math.ceil(offset / 2f); int top = getPaddingTop(); - int count = getChildCount(); - for (int i = 0; i < count; i++) { - View child = getChildAt(i); - child.layout(left, top, - left + r - l, - top + b - t); - } + + mTouchFeedbackView.layout(left, top, + left + mTouchFeedbackView.getMeasuredWidth(), + top + mTouchFeedbackView.getMeasuredHeight()); + mShortcutsAndWidgets.layout(left, top, + left + r - l, + top + b - t); } @Override -- cgit v1.2.3