diff options
Diffstat (limited to 'src/com/android/launcher3/folder/FolderIcon.java')
-rw-r--r-- | src/com/android/launcher3/folder/FolderIcon.java | 104 |
1 files changed, 87 insertions, 17 deletions
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index 25123fb1d..6e3db0b2d 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -126,6 +126,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { private float mSlop; + FolderIconPreviewVerifier mPreviewVerifier; private PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0); private ArrayList<PreviewItemDrawingParams> mDrawingParams = new ArrayList<PreviewItemDrawingParams>(); private Drawable mReferenceDrawable = null; @@ -181,7 +182,8 @@ public class FolderIcon extends FrameLayout implements FolderListener { } DeviceProfile grid = launcher.getDeviceProfile(); - FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false); + FolderIcon icon = (FolderIcon) LayoutInflater.from(group.getContext()) + .inflate(resId, group, false); icon.setClipToPadding(false); icon.mFolderName = (BubbleTextView) icon.findViewById(R.id.folder_icon_name); @@ -221,6 +223,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { private void setFolder(Folder folder) { mFolder = folder; + mPreviewVerifier = new FolderIconPreviewVerifier(mLauncher.getDeviceProfile().inv); updateItemDrawingParams(false); } @@ -407,6 +410,10 @@ public class FolderIcon extends FrameLayout implements FolderListener { mBadgeInfo = badgeInfo; } + public PreviewLayoutRule getLayoutRule() { + return mPreviewLayoutRule; + } + /** * Sets mBadgeScale to 1 or 0, animating if wasBadged or isBadged is false * (the badge is being added or removed). @@ -540,6 +547,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { private float mScale = 1f; private float mColorMultiplier = 1f; private float mStrokeWidth; + private int mStrokeAlpha = MAX_BG_OPACITY; private View mInvalidateDelegate; public int previewSize; @@ -565,6 +573,21 @@ public class FolderIcon extends FrameLayout implements FolderListener { private static final int SHADOW_OPACITY = 40; ValueAnimator mScaleAnimator; + ObjectAnimator mStrokeAlphaAnimator; + + private static final Property<PreviewBackground, Integer> STROKE_ALPHA = + new Property<PreviewBackground, Integer>(Integer.class, "strokeAlpha") { + @Override + public Integer get(PreviewBackground previewBackground) { + return previewBackground.mStrokeAlpha; + } + + @Override + public void set(PreviewBackground previewBackground, Integer alpha) { + previewBackground.mStrokeAlpha = alpha; + previewBackground.invalidate(); + } + }; public void setup(DisplayMetrics dm, DeviceProfile grid, View invalidateDelegate, int availableSpace, int topPadding) { @@ -674,8 +697,24 @@ public class FolderIcon extends FrameLayout implements FolderListener { canvas.restoreToCount(saveCount); } + public void animateBackgroundStroke() { + if (mStrokeAlphaAnimator != null) { + mStrokeAlphaAnimator.cancel(); + } + mStrokeAlphaAnimator = ObjectAnimator + .ofArgb(this, STROKE_ALPHA, MAX_BG_OPACITY / 2, MAX_BG_OPACITY) + .setDuration(100); + mStrokeAlphaAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mStrokeAlphaAnimator = null; + } + }); + mStrokeAlphaAnimator.start(); + } + public void drawBackgroundStroke(Canvas canvas) { - mPaint.setColor(Color.argb(255, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY)); + mPaint.setColor(Color.argb(mStrokeAlpha, BG_INTENSITY, BG_INTENSITY, BG_INTENSITY)); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(mStrokeWidth); drawCircle(canvas, 1 /* deltaRadius */); @@ -822,6 +861,14 @@ public class FolderIcon extends FrameLayout implements FolderListener { }; animateScale(1f, 1f, onStart, onEnd); } + + public int getBackgroundAlpha() { + return (int) Math.min(MAX_BG_OPACITY, BG_OPACITY * mColorMultiplier); + } + + public float getStrokeWidth() { + return mStrokeWidth; + } } public void setFolderBackground(PreviewBackground bg) { @@ -991,8 +1038,26 @@ public class FolderIcon extends FrameLayout implements FolderListener { return mFolderName.getVisibility() == VISIBLE; } + public List<BubbleTextView> getItemsToDisplay() { + mPreviewVerifier.setFolderInfo(mFolder.getInfo()); + + List<BubbleTextView> itemsToDisplay = new ArrayList<>(); + List<View> allItems = mFolder.getItemsInReadingOrder(); + int numItems = allItems.size(); + for (int rank = 0; rank < numItems; ++rank) { + if (mPreviewVerifier.isItemInPreview(rank)) { + itemsToDisplay.add((BubbleTextView) allItems.get(rank)); + } + + if (itemsToDisplay.size() == FolderIcon.NUM_ITEMS_IN_PREVIEW) { + break; + } + } + return itemsToDisplay; + } + private void updateItemDrawingParams(boolean animate) { - List<View> items = mPreviewLayoutRule.getItemsToDisplay(mFolder); + List<BubbleTextView> items = getItemsToDisplay(); int nItemsInPreview = items.size(); int prevNumItems = mDrawingParams.size(); @@ -1007,7 +1072,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { for (int i = 0; i < mDrawingParams.size(); i++) { PreviewItemDrawingParams p = mDrawingParams.get(i); - p.drawable = ((TextView) items.get(i)).getCompoundDrawables()[1]; + p.drawable = items.get(i).getCompoundDrawables()[1]; if (!animate || FeatureFlags.LAUNCHER3_LEGACY_FOLDER_ICON) { computePreviewItemDrawingParams(i, nItemsInPreview, p); @@ -1109,28 +1174,21 @@ public class FolderIcon extends FrameLayout implements FolderListener { } public void shrinkAndFadeIn(boolean animate) { - final CellLayout cl = (CellLayout) getParent().getParent(); - ((CellLayout.LayoutParams) getLayoutParams()).canReorder = true; - // We remove and re-draw the FolderIcon in-case it has changed final PreviewImageView previewImage = PreviewImageView.get(getContext()); previewImage.removeFromParent(); copyToPreview(previewImage); - if (cl != null) { - cl.clearFolderLeaveBehind(); - } + clearLeaveBehindIfExists(); ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(previewImage, 1, 1, 1); oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration)); oa.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { - if (cl != null) { - // Remove the ImageView copy of the FolderIcon and make the original visible. - previewImage.removeFromParent(); - setVisibility(View.VISIBLE); - } + // Remove the ImageView copy of the FolderIcon and make the original visible. + previewImage.removeFromParent(); + setVisibility(View.VISIBLE); } }); oa.start(); @@ -1139,7 +1197,15 @@ public class FolderIcon extends FrameLayout implements FolderListener { } } - public void growAndFadeOut() { + public void clearLeaveBehindIfExists() { + ((CellLayout.LayoutParams) getLayoutParams()).canReorder = true; + if (mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + CellLayout cl = (CellLayout) getParent().getParent(); + cl.clearFolderLeaveBehind(); + } + } + + public void drawLeaveBehindIfExists() { CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams(); // While the folder is open, the position of the icon cannot change. lp.canReorder = false; @@ -1147,6 +1213,10 @@ public class FolderIcon extends FrameLayout implements FolderListener { CellLayout cl = (CellLayout) getParent().getParent(); cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); } + } + + public void growAndFadeOut() { + drawLeaveBehindIfExists(); // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original PreviewImageView previewImage = PreviewImageView.get(getContext()); @@ -1176,8 +1246,8 @@ public class FolderIcon extends FrameLayout implements FolderListener { PreviewItemDrawingParams params); void init(int availableSpace, int intrinsicIconSize, boolean rtl); float scaleForItem(int index, int totalNumItems); + float getIconSize(); int maxNumItems(); boolean clipToBackground(); - List<View> getItemsToDisplay(Folder folder); } } |