Search in sources :

Example 1 with PropertyResetListener

use of com.android.launcher3.anim.PropertyResetListener in project android_packages_apps_Launcher3 by crdroidandroid.

the class FolderAnimationManager method getAnimator.

/**
 * Prepares the Folder for animating between open / closed states.
 */
public AnimatorSet getAnimator() {
    final BaseDragLayer.LayoutParams lp = (BaseDragLayer.LayoutParams) mFolder.getLayoutParams();
    mFolderIcon.getPreviewItemManager().recomputePreviewDrawingParams();
    ClippedFolderIconLayoutRule rule = mFolderIcon.getLayoutRule();
    final List<BubbleTextView> itemsInPreview = getPreviewIconsOnPage(0);
    // Match position of the FolderIcon
    final Rect folderIconPos = new Rect();
    float scaleRelativeToDragLayer = mFolder.mActivityContext.getDragLayer().getDescendantRectRelativeToSelf(mFolderIcon, folderIconPos);
    int scaledRadius = mPreviewBackground.getScaledRadius();
    float initialSize = (scaledRadius * 2) * scaleRelativeToDragLayer;
    // Match size/scale of icons in the preview
    float previewScale = rule.scaleForItem(itemsInPreview.size());
    float previewSize = rule.getIconSize() * previewScale;
    float initialScale = previewSize / itemsInPreview.get(0).getIconSize() * scaleRelativeToDragLayer;
    final float finalScale = 1f;
    float scale = mIsOpening ? initialScale : finalScale;
    mFolder.setPivotX(0);
    mFolder.setPivotY(0);
    // Scale the contents of the folder.
    mFolder.mContent.setScaleX(scale);
    mFolder.mContent.setScaleY(scale);
    mFolder.mContent.setPivotX(0);
    mFolder.mContent.setPivotY(0);
    mFolder.mFooter.setScaleX(scale);
    mFolder.mFooter.setScaleY(scale);
    mFolder.mFooter.setPivotX(0);
    mFolder.mFooter.setPivotY(0);
    // We want to create a small X offset for the preview items, so that they follow their
    // expected path to their final locations. ie. an icon should not move right, if it's final
    // location is to its left. This value is arbitrarily defined.
    int previewItemOffsetX = (int) (previewSize / 2);
    if (Utilities.isRtl(mContext.getResources())) {
        previewItemOffsetX = (int) (lp.width * initialScale - initialSize - previewItemOffsetX);
    }
    final int paddingOffsetX = (int) (mContent.getPaddingLeft() * initialScale);
    final int paddingOffsetY = (int) (mContent.getPaddingTop() * initialScale);
    int initialX = folderIconPos.left + mFolder.getPaddingLeft() + mPreviewBackground.getOffsetX() - paddingOffsetX - previewItemOffsetX;
    int initialY = folderIconPos.top + mFolder.getPaddingTop() + mPreviewBackground.getOffsetY() - paddingOffsetY;
    final float xDistance = initialX - lp.x;
    final float yDistance = initialY - lp.y;
    // Set up the Folder background.
    final int finalColor;
    int folderFillColor = Themes.getAttrColor(mContext, R.attr.folderFillColor);
    if (mIsOpening) {
        finalColor = folderFillColor;
    } else {
        finalColor = mFolderBackground.getColor().getDefaultColor();
    }
    final int initialColor = setColorAlphaBound(folderFillColor, mPreviewBackground.getBackgroundAlpha());
    mFolderBackground.mutate();
    mFolderBackground.setColor(mIsOpening ? initialColor : finalColor);
    // Set up the reveal animation that clips the Folder.
    int totalOffsetX = paddingOffsetX + previewItemOffsetX;
    Rect startRect = new Rect(totalOffsetX, paddingOffsetY, Math.round((totalOffsetX + initialSize)), Math.round((paddingOffsetY + initialSize)));
    Rect endRect = new Rect(0, 0, lp.width, lp.height);
    float finalRadius = mFolderBackground.getCornerRadius();
    // Create the animators.
    AnimatorSet a = new AnimatorSet();
    // Initialize the Folder items' text.
    PropertyResetListener colorResetListener = new PropertyResetListener<>(TEXT_ALPHA_PROPERTY, 1f);
    for (BubbleTextView icon : mFolder.getItemsOnPage(mFolder.mContent.getCurrentPage())) {
        if (mIsOpening) {
            icon.setTextVisibility(false);
        }
        ObjectAnimator anim = icon.createTextAlphaAnimator(mIsOpening);
        anim.addListener(colorResetListener);
        play(a, anim);
    }
    mBgColorAnimator = getAnimator(mFolderBackground, "color", initialColor, finalColor);
    play(a, mBgColorAnimator);
    play(a, getAnimator(mFolder, View.TRANSLATION_X, xDistance, 0f));
    play(a, getAnimator(mFolder, View.TRANSLATION_Y, yDistance, 0f));
    play(a, getAnimator(mFolder.mContent, SCALE_PROPERTY, initialScale, finalScale));
    play(a, getAnimator(mFolder.mFooter, SCALE_PROPERTY, initialScale, finalScale));
    final int footerAlphaDuration;
    final int footerStartDelay;
    if (isLargeFolder()) {
        if (mIsOpening) {
            footerAlphaDuration = LARGE_FOLDER_FOOTER_DURATION;
            footerStartDelay = mDuration - footerAlphaDuration;
        } else {
            footerAlphaDuration = 0;
            footerStartDelay = 0;
        }
    } else {
        footerStartDelay = 0;
        footerAlphaDuration = mDuration;
    }
    play(a, getAnimator(mFolder.mFooter, ALPHA, 0, 1f), footerStartDelay, footerAlphaDuration);
    // Create reveal animator for the folder background
    play(a, getShape().createRevealAnimator(mFolder, startRect, endRect, finalRadius, !mIsOpening));
    // Create reveal animator for the folder content (capture the top 4 icons 2x2)
    int width = mDeviceProfile.folderCellLayoutBorderSpacingPx + mDeviceProfile.folderCellWidthPx * 2;
    int height = mDeviceProfile.folderCellLayoutBorderSpacingPx + mDeviceProfile.folderCellHeightPx * 2;
    int page = mIsOpening ? mContent.getCurrentPage() : mContent.getDestinationPage();
    int left = mContent.getPaddingLeft() + page * lp.width;
    Rect contentStart = new Rect(left, 0, left + width, height);
    Rect contentEnd = new Rect(left, 0, left + lp.width, lp.height);
    play(a, getShape().createRevealAnimator(mFolder.getContent(), contentStart, contentEnd, finalRadius, !mIsOpening));
    // Fade in the folder name, as the text can overlap the icons when grid size is small.
    mFolder.mFolderName.setAlpha(mIsOpening ? 0f : 1f);
    play(a, getAnimator(mFolder.mFolderName, View.ALPHA, 0, 1), mIsOpening ? FOLDER_NAME_ALPHA_DURATION : 0, mIsOpening ? mDuration - FOLDER_NAME_ALPHA_DURATION : FOLDER_NAME_ALPHA_DURATION);
    // Translate the footer so that it tracks the bottom of the content.
    float normalHeight = mFolder.getContentAreaHeight();
    float scaledHeight = normalHeight * initialScale;
    float diff = normalHeight - scaledHeight;
    play(a, getAnimator(mFolder.mFooter, View.TRANSLATION_Y, -diff, 0f));
    // 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, mIsOpening ? midDuration : 0, midDuration);
    // Store clip variables
    CellLayout cellLayout = mContent.getCurrentCellLayout();
    boolean folderClipChildren = mFolder.getClipChildren();
    boolean folderClipToPadding = mFolder.getClipToPadding();
    boolean contentClipChildren = mContent.getClipChildren();
    boolean contentClipToPadding = mContent.getClipToPadding();
    boolean cellLayoutClipChildren = cellLayout.getClipChildren();
    boolean cellLayoutClipPadding = cellLayout.getClipToPadding();
    mFolder.setClipChildren(false);
    mFolder.setClipToPadding(false);
    mContent.setClipChildren(false);
    mContent.setClipToPadding(false);
    cellLayout.setClipChildren(false);
    cellLayout.setClipToPadding(false);
    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.mContent.setScaleX(1f);
            mFolder.mContent.setScaleY(1f);
            mFolder.mFooter.setScaleX(1f);
            mFolder.mFooter.setScaleY(1f);
            mFolder.mFooter.setTranslationX(0f);
            mFolder.mFolderName.setAlpha(1f);
            mFolder.setClipChildren(folderClipChildren);
            mFolder.setClipToPadding(folderClipToPadding);
            mContent.setClipChildren(contentClipChildren);
            mContent.setClipToPadding(contentClipToPadding);
            cellLayout.setClipChildren(cellLayoutClipChildren);
            cellLayout.setClipToPadding(cellLayoutClipPadding);
        }
    });
    // animators may use a different interpolator.
    for (Animator animator : a.getChildAnimations()) {
        animator.setInterpolator(mFolderInterpolator);
    }
    int radiusDiff = scaledRadius - mPreviewBackground.getRadius();
    addPreviewItemAnimators(a, initialScale / scaleRelativeToDragLayer, // difference to keep the preview items centered.
    previewItemOffsetX + radiusDiff, radiusDiff);
    return a;
}
Also used : Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) PropertyResetListener(com.android.launcher3.anim.PropertyResetListener) AnimatorSet(android.animation.AnimatorSet) BaseDragLayer(com.android.launcher3.views.BaseDragLayer) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) CellLayout(com.android.launcher3.CellLayout) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) BubbleTextView(com.android.launcher3.BubbleTextView)

Example 2 with PropertyResetListener

use of com.android.launcher3.anim.PropertyResetListener in project android_packages_apps_Trebuchet by LineageOS.

the class NotificationFooterLayout method animateFirstNotificationTo.

public void animateFirstNotificationTo(Rect toBounds, final IconAnimationEndListener callback) {
    AnimatorSet animation = new AnimatorSet();
    final View firstNotification = mIconRow.getChildAt(mIconRow.getChildCount() - 1);
    Rect fromBounds = sTempRect;
    firstNotification.getGlobalVisibleRect(fromBounds);
    float scale = (float) toBounds.height() / fromBounds.height();
    Animator moveAndScaleIcon = new PropertyListBuilder().scale(scale).translationY(toBounds.top - fromBounds.top + (fromBounds.height() * scale - fromBounds.height()) / 2).build(firstNotification);
    moveAndScaleIcon.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            callback.onIconAnimationEnd((NotificationInfo) firstNotification.getTag());
            removeViewFromIconRow(firstNotification);
        }
    });
    animation.play(moveAndScaleIcon);
    // Shift all notifications (not the overflow) over to fill the gap.
    int gapWidth = mIconLayoutParams.width + mIconLayoutParams.getMarginStart();
    if (mRtl) {
        gapWidth = -gapWidth;
    }
    if (!mOverflowNotifications.isEmpty()) {
        NotificationInfo notification = mOverflowNotifications.remove(0);
        mNotifications.add(notification);
        View iconFromOverflow = addNotificationIconForInfo(notification);
        animation.play(ObjectAnimator.ofFloat(iconFromOverflow, ALPHA, 0, 1));
    }
    // All children besides the one leaving.
    int numIcons = mIconRow.getChildCount() - 1;
    // We have to reset the translation X to 0 when the new main notification
    // is removed from the footer.
    PropertyResetListener<View, Float> propertyResetListener = new PropertyResetListener<>(TRANSLATION_X, 0f);
    for (int i = 0; i < numIcons; i++) {
        final View child = mIconRow.getChildAt(i);
        Animator shiftChild = ObjectAnimator.ofFloat(child, TRANSLATION_X, gapWidth);
        shiftChild.addListener(propertyResetListener);
        animation.play(shiftChild);
    }
    animation.start();
}
Also used : Rect(android.graphics.Rect) PropertyResetListener(com.android.launcher3.anim.PropertyResetListener) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyListBuilder(com.android.launcher3.anim.PropertyListBuilder)

Example 3 with PropertyResetListener

use of com.android.launcher3.anim.PropertyResetListener in project Neo-Launcher by NeoApplications.

the class NotificationFooterLayout method animateFirstNotificationTo.

public void animateFirstNotificationTo(Rect toBounds, final IconAnimationEndListener callback) {
    AnimatorSet animation = new AnimatorSet();
    final View firstNotification = mIconRow.getChildAt(mIconRow.getChildCount() - 1);
    Rect fromBounds = sTempRect;
    firstNotification.getGlobalVisibleRect(fromBounds);
    float scale = (float) toBounds.height() / fromBounds.height();
    Animator moveAndScaleIcon = new PropertyListBuilder().scale(scale).translationY(toBounds.top - fromBounds.top + (fromBounds.height() * scale - fromBounds.height()) / 2).build(firstNotification);
    moveAndScaleIcon.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            callback.onIconAnimationEnd((NotificationInfo) firstNotification.getTag());
            removeViewFromIconRow(firstNotification);
        }
    });
    animation.play(moveAndScaleIcon);
    // Shift all notifications (not the overflow) over to fill the gap.
    int gapWidth = mIconLayoutParams.width + mIconLayoutParams.getMarginStart();
    if (mRtl) {
        gapWidth = -gapWidth;
    }
    if (!mOverflowNotifications.isEmpty()) {
        NotificationInfo notification = mOverflowNotifications.remove(0);
        mNotifications.add(notification);
        View iconFromOverflow = addNotificationIconForInfo(notification);
        animation.play(ObjectAnimator.ofFloat(iconFromOverflow, ALPHA, 0, 1));
    }
    // All children besides the one leaving.
    int numIcons = mIconRow.getChildCount() - 1;
    // We have to reset the translation X to 0 when the new main notification
    // is removed from the footer.
    PropertyResetListener<View, Float> propertyResetListener = new PropertyResetListener<>(TRANSLATION_X, 0f);
    for (int i = 0; i < numIcons; i++) {
        final View child = mIconRow.getChildAt(i);
        Animator shiftChild = ObjectAnimator.ofFloat(child, TRANSLATION_X, gapWidth);
        shiftChild.addListener(propertyResetListener);
        animation.play(shiftChild);
    }
    animation.start();
}
Also used : Rect(android.graphics.Rect) PropertyResetListener(com.android.launcher3.anim.PropertyResetListener) AnimatorSet(android.animation.AnimatorSet) View(android.view.View) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyListBuilder(com.android.launcher3.anim.PropertyListBuilder)

Example 4 with PropertyResetListener

use of com.android.launcher3.anim.PropertyResetListener in project android_packages_apps_404Launcher by P-404.

the class FolderAnimationManager method getAnimator.

/**
 * Prepares the Folder for animating between open / closed states.
 */
public AnimatorSet getAnimator() {
    final BaseDragLayer.LayoutParams lp = (BaseDragLayer.LayoutParams) mFolder.getLayoutParams();
    mFolderIcon.getPreviewItemManager().recomputePreviewDrawingParams();
    ClippedFolderIconLayoutRule rule = mFolderIcon.getLayoutRule();
    final List<BubbleTextView> itemsInPreview = getPreviewIconsOnPage(0);
    // Match position of the FolderIcon
    final Rect folderIconPos = new Rect();
    float scaleRelativeToDragLayer = mFolder.mActivityContext.getDragLayer().getDescendantRectRelativeToSelf(mFolderIcon, folderIconPos);
    int scaledRadius = mPreviewBackground.getScaledRadius();
    float initialSize = (scaledRadius * 2) * scaleRelativeToDragLayer;
    // Match size/scale of icons in the preview
    float previewScale = rule.scaleForItem(itemsInPreview.size());
    float previewSize = rule.getIconSize() * previewScale;
    float initialScale = previewSize / itemsInPreview.get(0).getIconSize() * scaleRelativeToDragLayer;
    final float finalScale = 1f;
    float scale = mIsOpening ? initialScale : finalScale;
    mFolder.setPivotX(0);
    mFolder.setPivotY(0);
    // Scale the contents of the folder.
    mFolder.mContent.setScaleX(scale);
    mFolder.mContent.setScaleY(scale);
    mFolder.mContent.setPivotX(0);
    mFolder.mContent.setPivotY(0);
    mFolder.mFooter.setScaleX(scale);
    mFolder.mFooter.setScaleY(scale);
    mFolder.mFooter.setPivotX(0);
    mFolder.mFooter.setPivotY(0);
    // We want to create a small X offset for the preview items, so that they follow their
    // expected path to their final locations. ie. an icon should not move right, if it's final
    // location is to its left. This value is arbitrarily defined.
    int previewItemOffsetX = (int) (previewSize / 2);
    if (Utilities.isRtl(mContext.getResources())) {
        previewItemOffsetX = (int) (lp.width * initialScale - initialSize - previewItemOffsetX);
    }
    final int paddingOffsetX = (int) (mContent.getPaddingLeft() * initialScale);
    final int paddingOffsetY = (int) (mContent.getPaddingTop() * initialScale);
    int initialX = folderIconPos.left + mFolder.getPaddingLeft() + mPreviewBackground.getOffsetX() - paddingOffsetX - previewItemOffsetX;
    int initialY = folderIconPos.top + mFolder.getPaddingTop() + mPreviewBackground.getOffsetY() - paddingOffsetY;
    final float xDistance = initialX - lp.x;
    final float yDistance = initialY - lp.y;
    // Set up the Folder background.
    final int initialColor = Themes.getAttrColor(mContext, R.attr.folderPreviewColor);
    final int finalColor = Themes.getAttrColor(mContext, R.attr.folderBackgroundColor);
    mFolderBackground.mutate();
    mFolderBackground.setColor(mIsOpening ? initialColor : finalColor);
    // Set up the reveal animation that clips the Folder.
    int totalOffsetX = paddingOffsetX + previewItemOffsetX;
    Rect startRect = new Rect(totalOffsetX, paddingOffsetY, Math.round((totalOffsetX + initialSize)), Math.round((paddingOffsetY + initialSize)));
    Rect endRect = new Rect(0, 0, lp.width, lp.height);
    float finalRadius = mFolderBackground.getCornerRadius();
    // Create the animators.
    AnimatorSet a = new AnimatorSet();
    // Initialize the Folder items' text.
    PropertyResetListener colorResetListener = new PropertyResetListener<>(TEXT_ALPHA_PROPERTY, 1f);
    for (BubbleTextView icon : mFolder.getItemsOnPage(mFolder.mContent.getCurrentPage())) {
        if (mIsOpening) {
            icon.setTextVisibility(false);
        }
        ObjectAnimator anim = icon.createTextAlphaAnimator(mIsOpening);
        anim.addListener(colorResetListener);
        play(a, anim);
    }
    mBgColorAnimator = getAnimator(mFolderBackground, "color", initialColor, finalColor);
    play(a, mBgColorAnimator);
    play(a, getAnimator(mFolder, View.TRANSLATION_X, xDistance, 0f));
    play(a, getAnimator(mFolder, View.TRANSLATION_Y, yDistance, 0f));
    play(a, getAnimator(mFolder.mContent, SCALE_PROPERTY, initialScale, finalScale));
    play(a, getAnimator(mFolder.mFooter, SCALE_PROPERTY, initialScale, finalScale));
    final int footerAlphaDuration;
    final int footerStartDelay;
    if (isLargeFolder()) {
        if (mIsOpening) {
            footerAlphaDuration = LARGE_FOLDER_FOOTER_DURATION;
            footerStartDelay = mDuration - footerAlphaDuration;
        } else {
            footerAlphaDuration = 0;
            footerStartDelay = 0;
        }
    } else {
        footerStartDelay = 0;
        footerAlphaDuration = mDuration;
    }
    play(a, getAnimator(mFolder.mFooter, ALPHA, 0, 1f), footerStartDelay, footerAlphaDuration);
    // Create reveal animator for the folder background
    play(a, getShape().createRevealAnimator(mFolder, startRect, endRect, finalRadius, !mIsOpening));
    // Create reveal animator for the folder content (capture the top 4 icons 2x2)
    int width = mDeviceProfile.folderCellLayoutBorderSpacePx.x + mDeviceProfile.folderCellWidthPx * 2;
    int height = mDeviceProfile.folderCellLayoutBorderSpacePx.y + mDeviceProfile.folderCellHeightPx * 2;
    int page = mIsOpening ? mContent.getCurrentPage() : mContent.getDestinationPage();
    int left = mContent.getPaddingLeft() + page * lp.width;
    Rect contentStart = new Rect(left, 0, left + width, height);
    Rect contentEnd = new Rect(left, 0, left + lp.width, lp.height);
    play(a, getShape().createRevealAnimator(mFolder.getContent(), contentStart, contentEnd, finalRadius, !mIsOpening));
    // Fade in the folder name, as the text can overlap the icons when grid size is small.
    mFolder.mFolderName.setAlpha(mIsOpening ? 0f : 1f);
    play(a, getAnimator(mFolder.mFolderName, View.ALPHA, 0, 1), mIsOpening ? FOLDER_NAME_ALPHA_DURATION : 0, mIsOpening ? mDuration - FOLDER_NAME_ALPHA_DURATION : FOLDER_NAME_ALPHA_DURATION);
    // Translate the footer so that it tracks the bottom of the content.
    float normalHeight = mFolder.getContentAreaHeight();
    float scaledHeight = normalHeight * initialScale;
    float diff = normalHeight - scaledHeight;
    play(a, getAnimator(mFolder.mFooter, View.TRANSLATION_Y, -diff, 0f));
    // 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, mIsOpening ? midDuration : 0, midDuration);
    // Store clip variables
    CellLayout cellLayout = mContent.getCurrentCellLayout();
    boolean folderClipChildren = mFolder.getClipChildren();
    boolean folderClipToPadding = mFolder.getClipToPadding();
    boolean contentClipChildren = mContent.getClipChildren();
    boolean contentClipToPadding = mContent.getClipToPadding();
    boolean cellLayoutClipChildren = cellLayout.getClipChildren();
    boolean cellLayoutClipPadding = cellLayout.getClipToPadding();
    mFolder.setClipChildren(false);
    mFolder.setClipToPadding(false);
    mContent.setClipChildren(false);
    mContent.setClipToPadding(false);
    cellLayout.setClipChildren(false);
    cellLayout.setClipToPadding(false);
    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.mContent.setScaleX(1f);
            mFolder.mContent.setScaleY(1f);
            mFolder.mFooter.setScaleX(1f);
            mFolder.mFooter.setScaleY(1f);
            mFolder.mFooter.setTranslationX(0f);
            mFolder.mFolderName.setAlpha(1f);
            mFolder.setClipChildren(folderClipChildren);
            mFolder.setClipToPadding(folderClipToPadding);
            mContent.setClipChildren(contentClipChildren);
            mContent.setClipToPadding(contentClipToPadding);
            cellLayout.setClipChildren(cellLayoutClipChildren);
            cellLayout.setClipToPadding(cellLayoutClipPadding);
        }
    });
    // animators may use a different interpolator.
    for (Animator animator : a.getChildAnimations()) {
        animator.setInterpolator(mFolderInterpolator);
    }
    int radiusDiff = scaledRadius - mPreviewBackground.getRadius();
    addPreviewItemAnimators(a, initialScale / scaleRelativeToDragLayer, // difference to keep the preview items centered.
    previewItemOffsetX + radiusDiff, radiusDiff);
    return a;
}
Also used : Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) PropertyResetListener(com.android.launcher3.anim.PropertyResetListener) AnimatorSet(android.animation.AnimatorSet) BaseDragLayer(com.android.launcher3.views.BaseDragLayer) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) CellLayout(com.android.launcher3.CellLayout) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) BubbleTextView(com.android.launcher3.BubbleTextView)

Example 5 with PropertyResetListener

use of com.android.launcher3.anim.PropertyResetListener in project Neo-Launcher by NeoApplications.

the class FolderAnimationManager method getAnimator.

/**
 * Prepares the Folder for animating between open / closed states.
 */
public AnimatorSet getAnimator() {
    final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) mFolder.getLayoutParams();
    ClippedFolderIconLayoutRule rule = mFolderIcon.getLayoutRule();
    final List<BubbleTextView> itemsInPreview = getPreviewIconsOnPage(0);
    // Match position of the FolderIcon
    final Rect folderIconPos = new Rect();
    float scaleRelativeToDragLayer = mLauncher.getDragLayer().getDescendantRectRelativeToSelf(mFolderIcon, folderIconPos);
    int scaledRadius = mPreviewBackground.getScaledRadius();
    float initialSize = (scaledRadius * 2) * scaleRelativeToDragLayer;
    // Match size/scale of icons in the preview
    float previewScale = rule.scaleForItem(itemsInPreview.size());
    float previewSize = rule.getIconSize() * previewScale;
    Log.d("FolderAnimation", "Items " + itemsInPreview.get(0));
    float initialScale = previewSize / itemsInPreview.get(0).getIconSize() * scaleRelativeToDragLayer;
    final float finalScale = 1f;
    float scale = mIsOpening ? initialScale : finalScale;
    mFolder.setPivotX(0);
    mFolder.setPivotY(0);
    // Scale the contents of the folder.
    mFolder.mContent.setScaleX(scale);
    mFolder.mContent.setScaleY(scale);
    mFolder.mContent.setPivotX(0);
    mFolder.mContent.setPivotY(0);
    mFolder.mFooter.setScaleX(scale);
    mFolder.mFooter.setScaleY(scale);
    mFolder.mFooter.setPivotX(0);
    mFolder.mFooter.setPivotY(0);
    // We want to create a small X offset for the preview items, so that they follow their
    // expected path to their final locations. ie. an icon should not move right, if it's final
    // location is to its left. This value is arbitrarily defined.
    int previewItemOffsetX = (int) (previewSize / 2);
    if (Utilities.isRtl(mContext.getResources())) {
        previewItemOffsetX = (int) (lp.width * initialScale - initialSize - previewItemOffsetX);
    }
    final int paddingOffsetX = (int) (mContent.getPaddingLeft() * initialScale);
    final int paddingOffsetY = (int) (mContent.getPaddingTop() * initialScale);
    int initialX = folderIconPos.left + mFolder.getPaddingLeft() + mPreviewBackground.getOffsetX() - paddingOffsetX - previewItemOffsetX;
    int initialY = folderIconPos.top + mFolder.getPaddingTop() + mPreviewBackground.getOffsetY() - paddingOffsetY;
    final float xDistance = initialX - lp.x;
    final float yDistance = initialY - lp.y;
    // Set up the Folder background.
    final int finalColor = ColorUtils.setAlphaComponent(Themes.getAttrColor(mContext, R.attr.folderFillColor), 255);
    final int initialColor = setColorAlphaBound(finalColor, mPreviewBackground.getBackgroundAlpha());
    mFolderBackground.mutate();
    mFolderBackground.setColor(mIsOpening ? initialColor : finalColor);
    // Set up the reveal animation that clips the Folder.
    int totalOffsetX = paddingOffsetX + previewItemOffsetX;
    Rect startRect = new Rect(totalOffsetX, paddingOffsetY, Math.round((totalOffsetX + initialSize)), Math.round((paddingOffsetY + initialSize)));
    Rect endRect = new Rect(0, 0, lp.width, lp.height);
    float finalRadius = ResourceUtils.pxFromDp(2, mContext.getResources().getDisplayMetrics());
    // Create the animators.
    AnimatorSet a = new AnimatorSet();
    // Initialize the Folder items' text.
    PropertyResetListener colorResetListener = new PropertyResetListener<>(TEXT_ALPHA_PROPERTY, 1f);
    for (BubbleTextView icon : mFolder.getItemsOnPage(mFolder.mContent.getCurrentPage())) {
        if (mIsOpening) {
            icon.setTextVisibility(false);
        }
        ObjectAnimator anim = icon.createTextAlphaAnimator(mIsOpening);
        anim.addListener(colorResetListener);
        play(a, anim);
    }
    play(a, getAnimator(mFolder, View.TRANSLATION_X, xDistance, 0f));
    play(a, getAnimator(mFolder, View.TRANSLATION_Y, yDistance, 0f));
    play(a, getAnimator(mFolder.mContent, SCALE_PROPERTY, initialScale, finalScale));
    play(a, getAnimator(mFolder.mFooter, SCALE_PROPERTY, initialScale, finalScale));
    play(a, getAnimator(mFolderBackground, "color", initialColor, finalColor));
    play(a, mFolderIcon.mFolderName.createTextAlphaAnimator(!mIsOpening));
    play(a, getShape().createRevealAnimator(mFolder, startRect, endRect, finalRadius, !mIsOpening));
    // Fade in the folder name, as the text can overlap the icons when grid size is small.
    mFolder.mFolderName.setAlpha(mIsOpening ? 0f : 1f);
    play(a, getAnimator(mFolder.mFolderName, View.ALPHA, 0, 1), mIsOpening ? FOLDER_NAME_ALPHA_DURATION : 0, mIsOpening ? mDuration - FOLDER_NAME_ALPHA_DURATION : FOLDER_NAME_ALPHA_DURATION);
    // Translate the footer so that it tracks the bottom of the content.
    float normalHeight = mFolder.getContentAreaHeight();
    float scaledHeight = normalHeight * initialScale;
    float diff = normalHeight - scaledHeight;
    play(a, getAnimator(mFolder.mFooter, View.TRANSLATION_Y, -diff, 0f));
    // 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, mIsOpening ? midDuration : 0, midDuration);
    // Store clip variables
    CellLayout cellLayout = mContent.getCurrentCellLayout();
    boolean folderClipChildren = mFolder.getClipChildren();
    boolean folderClipToPadding = mFolder.getClipToPadding();
    boolean contentClipChildren = mContent.getClipChildren();
    boolean contentClipToPadding = mContent.getClipToPadding();
    boolean cellLayoutClipChildren = cellLayout.getClipChildren();
    boolean cellLayoutClipPadding = cellLayout.getClipToPadding();
    mFolder.setClipChildren(false);
    mFolder.setClipToPadding(false);
    mContent.setClipChildren(false);
    mContent.setClipToPadding(false);
    cellLayout.setClipChildren(false);
    cellLayout.setClipToPadding(false);
    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.mContent.setScaleX(1f);
            mFolder.mContent.setScaleY(1f);
            mFolder.mFooter.setScaleX(1f);
            mFolder.mFooter.setScaleY(1f);
            mFolder.mFooter.setTranslationX(0f);
            mFolder.mFolderName.setAlpha(1f);
            mFolder.setClipChildren(folderClipChildren);
            mFolder.setClipToPadding(folderClipToPadding);
            mContent.setClipChildren(contentClipChildren);
            mContent.setClipToPadding(contentClipToPadding);
            cellLayout.setClipChildren(cellLayoutClipChildren);
            cellLayout.setClipToPadding(cellLayoutClipPadding);
        }
    });
    // animators may use a different interpolator.
    for (Animator animator : a.getChildAnimations()) {
        animator.setInterpolator(mFolderInterpolator);
    }
    int radiusDiff = scaledRadius - mPreviewBackground.getRadius();
    addPreviewItemAnimators(a, initialScale / scaleRelativeToDragLayer, // difference to keep the preview items centered.
    previewItemOffsetX + radiusDiff, radiusDiff);
    return a;
}
Also used : Rect(android.graphics.Rect) ObjectAnimator(android.animation.ObjectAnimator) PropertyResetListener(com.android.launcher3.anim.PropertyResetListener) AnimatorSet(android.animation.AnimatorSet) DragLayer(com.android.launcher3.dragndrop.DragLayer) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) CellLayout(com.android.launcher3.CellLayout) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) BubbleTextView(com.android.launcher3.BubbleTextView)

Aggregations

Animator (android.animation.Animator)9 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)9 AnimatorSet (android.animation.AnimatorSet)9 ObjectAnimator (android.animation.ObjectAnimator)9 Rect (android.graphics.Rect)9 PropertyResetListener (com.android.launcher3.anim.PropertyResetListener)9 BubbleTextView (com.android.launcher3.BubbleTextView)7 CellLayout (com.android.launcher3.CellLayout)7 BaseDragLayer (com.android.launcher3.views.BaseDragLayer)5 View (android.view.View)2 PropertyListBuilder (com.android.launcher3.anim.PropertyListBuilder)2 DragLayer (com.android.launcher3.dragndrop.DragLayer)2