diff options
Diffstat (limited to 'src/com/android/launcher3/folder')
8 files changed, 176 insertions, 145 deletions
diff --git a/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java b/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java index 33bf2750c..ff357c0bc 100644 --- a/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java +++ b/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java @@ -29,8 +29,8 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule } @Override - public FolderIcon.PreviewItemDrawingParams computePreviewItemDrawingParams(int index, - int curNumItems, FolderIcon.PreviewItemDrawingParams params) { + public PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems, + PreviewItemDrawingParams params) { float totalScale = scaleForItem(index, curNumItems); float transX; @@ -47,7 +47,7 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule } if (params == null) { - params = new FolderIcon.PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha); + params = new PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha); } else { params.update(transX, transY, totalScale); params.overlayAlpha = overlayAlpha; diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index aad8123a9..3c7c69810 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -791,6 +791,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC if (mFolderIcon != null) { mFolderIcon.setVisibility(View.VISIBLE); if (FeatureFlags.LAUNCHER3_NEW_FOLDER_ANIMATION) { + mFolderIcon.mFolderName.setTextVisibility(true); mFolderIcon.setBackgroundVisible(true); mFolderIcon.mBackground.fadeInBackgroundShadow(); } diff --git a/src/com/android/launcher3/folder/FolderAnimationManager.java b/src/com/android/launcher3/folder/FolderAnimationManager.java index 7e6205aba..3648c60e1 100644 --- a/src/com/android/launcher3/folder/FolderAnimationManager.java +++ b/src/com/android/launcher3/folder/FolderAnimationManager.java @@ -71,8 +71,7 @@ public class FolderAnimationManager { private final TimeInterpolator mFolderInterpolator; private final TimeInterpolator mLargeFolderPreviewItemInterpolator; - private final FolderIcon.PreviewItemDrawingParams mTmpParams = - new FolderIcon.PreviewItemDrawingParams(0, 0, 0, 0); + private final PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0); private static final Property<View, Float> SCALE_PROPERTY = new Property<View, Float>(Float.class, "scale") { @@ -202,20 +201,20 @@ public class FolderAnimationManager { play(a, new RoundedRectRevealOutlineProvider(initialRadius, finalRadius, startRect, endRect).createRevealAnimator(mFolder, !mIsOpening)); + // Animate the elevation midway so that the shadow is not noticeable in the background. + int midDuration = mDuration / 2; + Animator z = getAnimator(mFolder, View.TRANSLATION_Z, -mFolder.getElevation(), 0); + play(a, z, midDuration, midDuration); + a.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mFolder.setTranslationX(0.0f); mFolder.setTranslationY(0.0f); + mFolder.setTranslationZ(0.0f); mFolder.setScaleX(1f); mFolder.setScaleY(1f); - - if (mIsOpening) { - getAnimator(mFolder, View.TRANSLATION_Z, -mFolder.getElevation(), 0) - .setDuration(150) - .start(); - } } }); @@ -324,7 +323,12 @@ public class FolderAnimationManager { } private void play(AnimatorSet as, Animator a) { - a.setDuration(mDuration); + play(as, a, a.getStartDelay(), mDuration); + } + + private void play(AnimatorSet as, Animator a, long startDelay, int duration) { + a.setStartDelay(startDelay); + a.setDuration(duration); as.play(a); } @@ -344,12 +348,6 @@ public class FolderAnimationManager { : ObjectAnimator.ofFloat(view, property, v2, v1); } - private Animator getAnimator(List<BubbleTextView> items, Property property, int v1, int v2) { - return mIsOpening - ? ObjectAnimator.ofArgb(items, property, v1, v2) - : ObjectAnimator.ofArgb(items, property, v2, v1); - } - private Animator getAnimator(GradientDrawable drawable, String property, int v1, int v2) { return mIsOpening ? ObjectAnimator.ofArgb(drawable, property, v1, v2) diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index 215a31c8f..1cc285ea5 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -19,8 +19,6 @@ package com.android.launcher3.folder; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; -import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.graphics.Canvas; import android.graphics.Point; @@ -227,8 +225,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { } public boolean acceptDrop(ItemInfo dragInfo) { - final ItemInfo item = dragInfo; - return !mFolder.isDestroyed() && willAcceptItem(item); + return !mFolder.isDestroyed() && willAcceptItem(dragInfo); } public void addItem(ShortcutInfo item) { @@ -423,39 +420,6 @@ public class FolderIcon extends FrameLayout implements FolderListener { return mBadgeInfo != null && mBadgeInfo.hasBadge(); } - static class PreviewItemDrawingParams { - PreviewItemDrawingParams(float transX, float transY, float scale, float overlayAlpha) { - this.transX = transX; - this.transY = transY; - this.scale = scale; - this.overlayAlpha = overlayAlpha; - } - - public void update(float transX, float transY, float scale) { - // We ensure the update will not interfere with an animation on the layout params - // If the final values differ, we cancel the animation. - if (anim != null) { - if (anim.finalTransX == transX || anim.finalTransY == transY - || anim.finalScale == scale) { - return; - } - anim.cancel(); - } - - this.transX = transX; - this.transY = transY; - this.scale = scale; - } - - float transX; - float transY; - float scale; - public float overlayAlpha; - boolean hidden; - FolderPreviewItemAnim anim; - Drawable drawable; - } - private float getLocalCenterForIndex(int index, int curNumItems, int[] center) { mTmpParams = computePreviewItemDrawingParams( Math.min(mPreviewLayoutRule.maxNumItems(), index), curNumItems, mTmpParams); @@ -465,12 +429,12 @@ public class FolderIcon extends FrameLayout implements FolderListener { float offsetX = mTmpParams.transX + (mTmpParams.scale * mIntrinsicIconSize) / 2; float offsetY = mTmpParams.transY + (mTmpParams.scale * mIntrinsicIconSize) / 2; - center[0] = (int) Math.round(offsetX); - center[1] = (int) Math.round(offsetY); + center[0] = Math.round(offsetX); + center[1] = Math.round(offsetY); return mTmpParams.scale; } - private PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems, + PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems, PreviewItemDrawingParams params) { // We use an index of -1 to represent an icon on the workspace for the destroy and // create animations @@ -582,89 +546,14 @@ public class FolderIcon extends FrameLayout implements FolderListener { } } - class FolderPreviewItemAnim { - ValueAnimator mValueAnimator; - float finalScale; - float finalTransX; - float finalTransY; - - /** - * - * @param params layout params to animate - * @param index0 original index of the item to be animated - * @param nItems0 original number of items in the preview - * @param index1 new index of the item to be animated - * @param nItems1 new number of items in the preview - * @param duration duration in ms of the animation - * @param onCompleteRunnable runnable to execute upon animation completion - */ - public FolderPreviewItemAnim(final PreviewItemDrawingParams params, int index0, int nItems0, - int index1, int nItems1, int duration, final Runnable onCompleteRunnable) { - - computePreviewItemDrawingParams(index1, nItems1, mTmpParams); - - finalScale = mTmpParams.scale; - finalTransX = mTmpParams.transX; - finalTransY = mTmpParams.transY; - - computePreviewItemDrawingParams(index0, nItems0, mTmpParams); - - final float scale0 = mTmpParams.scale; - final float transX0 = mTmpParams.transX; - final float transY0 = mTmpParams.transY; - - mValueAnimator = LauncherAnimUtils.ofFloat(0f, 1.0f); - mValueAnimator.addUpdateListener(new AnimatorUpdateListener(){ - public void onAnimationUpdate(ValueAnimator animation) { - float progress = animation.getAnimatedFraction(); - - params.transX = transX0 + progress * (finalTransX - transX0); - params.transY = transY0 + progress * (finalTransY - transY0); - params.scale = scale0 + progress * (finalScale - scale0); - invalidate(); - } - }); - - mValueAnimator.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animation) { - } - - @Override - public void onAnimationEnd(Animator animation) { - if (onCompleteRunnable != null) { - onCompleteRunnable.run(); - } - params.anim = null; - } - }); - mValueAnimator.setDuration(duration); - } - - public void start() { - mValueAnimator.start(); - } - - public void cancel() { - mValueAnimator.cancel(); - } - - public boolean hasEqualFinalState(FolderPreviewItemAnim anim) { - return finalTransY == anim.finalTransY && finalTransX == anim.finalTransX && - finalScale == anim.finalScale; - - } - } - private void animateFirstItem(final Drawable d, int duration, final boolean reverse, final Runnable onCompleteRunnable) { - FolderPreviewItemAnim anim; if (!reverse) { - anim = new FolderPreviewItemAnim(mDrawingParams.get(0), -1, -1, 0, 2, duration, + anim = new FolderPreviewItemAnim(this, mDrawingParams.get(0), -1, -1, 0, 2, duration, onCompleteRunnable); } else { - anim = new FolderPreviewItemAnim(mDrawingParams.get(0), 0, 2, -1, -1, duration, + anim = new FolderPreviewItemAnim(this, mDrawingParams.get(0), 0, 2, -1, -1, duration, onCompleteRunnable); } anim.start(); @@ -740,7 +629,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { mReferenceDrawable = p.drawable; } } else { - FolderPreviewItemAnim anim = new FolderPreviewItemAnim(p, i, prevNumItems, i, + FolderPreviewItemAnim anim = new FolderPreviewItemAnim(this, p, i, prevNumItems, i, nItemsInPreview, DROP_IN_ANIMATION_DURATION, null); if (p.anim != null) { @@ -901,7 +790,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { } } - public interface PreviewLayoutRule { + interface PreviewLayoutRule { PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems, PreviewItemDrawingParams params); void init(int availableSpace, float intrinsicIconSize, boolean rtl); diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java index d0ac9f4b1..f62568f78 100644 --- a/src/com/android/launcher3/folder/FolderPagedView.java +++ b/src/com/android/launcher3/folder/FolderPagedView.java @@ -701,10 +701,4 @@ public class FolderPagedView extends PagedView { public int itemsPerPage() { return mMaxItemsPerPage; } - - @Override - protected void getEdgeVerticalPosition(int[] pos) { - pos[0] = 0; - pos[1] = getViewportHeight(); - } } diff --git a/src/com/android/launcher3/folder/FolderPreviewItemAnim.java b/src/com/android/launcher3/folder/FolderPreviewItemAnim.java new file mode 100644 index 000000000..0da7c5cb1 --- /dev/null +++ b/src/com/android/launcher3/folder/FolderPreviewItemAnim.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.folder; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ValueAnimator; + +import com.android.launcher3.LauncherAnimUtils; + +/** + * Animates a Folder preview item. + */ +class FolderPreviewItemAnim { + private ValueAnimator mValueAnimator; + + float finalScale; + float finalTransX; + float finalTransY; + + private PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0); + + /** + * @param folderIcon The FolderIcon this preview will be drawn in. + * @param params layout params to animate + * @param index0 original index of the item to be animated + * @param items0 original number of items in the preview + * @param index1 new index of the item to be animated + * @param items1 new number of items in the preview + * @param duration duration in ms of the animation + * @param onCompleteRunnable runnable to execute upon animation completion + */ + FolderPreviewItemAnim(final FolderIcon folderIcon, final PreviewItemDrawingParams params, + int index0, int items0, int index1, int items1, int duration, + final Runnable onCompleteRunnable) { + folderIcon.computePreviewItemDrawingParams(index1, items1, mTmpParams); + + finalScale = mTmpParams.scale; + finalTransX = mTmpParams.transX; + finalTransY = mTmpParams.transY; + + folderIcon.computePreviewItemDrawingParams(index0, items0, mTmpParams); + + final float scale0 = mTmpParams.scale; + final float transX0 = mTmpParams.transX; + final float transY0 = mTmpParams.transY; + + mValueAnimator = LauncherAnimUtils.ofFloat(0f, 1.0f); + mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener(){ + public void onAnimationUpdate(ValueAnimator animation) { + float progress = animation.getAnimatedFraction(); + + params.transX = transX0 + progress * (finalTransX - transX0); + params.transY = transY0 + progress * (finalTransY - transY0); + params.scale = scale0 + progress * (finalScale - scale0); + folderIcon.invalidate(); + } + }); + mValueAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + if (onCompleteRunnable != null) { + onCompleteRunnable.run(); + } + params.anim = null; + } + }); + mValueAnimator.setDuration(duration); + } + + public void start() { + mValueAnimator.start(); + } + + public void cancel() { + mValueAnimator.cancel(); + } + + public boolean hasEqualFinalState(FolderPreviewItemAnim anim) { + return finalTransY == anim.finalTransY && finalTransX == anim.finalTransX && + finalScale == anim.finalScale; + + } +} diff --git a/src/com/android/launcher3/folder/PreviewItemDrawingParams.java b/src/com/android/launcher3/folder/PreviewItemDrawingParams.java new file mode 100644 index 000000000..607b7caec --- /dev/null +++ b/src/com/android/launcher3/folder/PreviewItemDrawingParams.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.folder; + +import android.graphics.drawable.Drawable; + +/** + * Manages the parameters used to draw a Folder preview item. + */ +class PreviewItemDrawingParams { + float transX; + float transY; + float scale; + float overlayAlpha; + FolderPreviewItemAnim anim; + public boolean hidden; + Drawable drawable; + + PreviewItemDrawingParams(float transX, float transY, float scale, float overlayAlpha) { + this.transX = transX; + this.transY = transY; + this.scale = scale; + this.overlayAlpha = overlayAlpha; + } + + public void update(float transX, float transY, float scale) { + // We ensure the update will not interfere with an animation on the layout params + // If the final values differ, we cancel the animation. + if (anim != null) { + if (anim.finalTransX == transX || anim.finalTransY == transY + || anim.finalScale == scale) { + return; + } + anim.cancel(); + } + + this.transX = transX; + this.transY = transY; + this.scale = scale; + } +} diff --git a/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java b/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java index 1ece27831..138dc1c55 100644 --- a/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java +++ b/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java @@ -16,8 +16,6 @@ package com.android.launcher3.folder; -import com.android.launcher3.folder.FolderIcon.PreviewItemDrawingParams; - public class StackFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule { static final int MAX_NUM_ITEMS_IN_PREVIEW = 3; |