Example usage for android.animation ObjectAnimator ofInt

List of usage examples for android.animation ObjectAnimator ofInt

Introduction

In this page you can find the example usage for android.animation ObjectAnimator ofInt.

Prototype

public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> property, int... values) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates between int values.

Usage

From source file:org.michaelbel.bottomsheet.BottomSheet.java

private void startOpenAnimation() {
    containerView.setVisibility(View.VISIBLE);

    if (Build.VERSION.SDK_INT >= 20) {
        container.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }// w ww  .  j  a  va 2 s . c  o  m

    containerView.setTranslationY(containerView.getMeasuredHeight());
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationY", 0),
            ObjectAnimator.ofInt(backDrawable, "alpha", 51));
    animatorSet.setDuration(200);
    animatorSet.setStartDelay(20);
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
                container.setLayerType(View.LAYER_TYPE_NONE, null);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
            }
        }
    });
    animatorSet.start();
    currentSheetAnimation = animatorSet;
}

From source file:ir.besteveryeverapp.ui.ActionBar.BottomSheet.java

@Override
public void dismiss() {
    if (dismissed) {
        return;//  w  w  w.  j a va2s.  c  om
    }
    dismissed = true;
    cancelSheetAnimation();
    if (!allowCustomAnimation || !onCustomCloseAnimation()) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(
                ObjectAnimator.ofFloat(containerView, "translationY",
                        containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
                ObjectAnimator.ofInt(backDrawable, "alpha", 0));
        if (useFastDismiss) {
            int height = containerView.getMeasuredHeight();
            animatorSet.setDuration(
                    Math.max(60, (int) (180 * (height - containerView.getTranslationY()) / (float) height)));
            useFastDismiss = false;
        } else {
            animatorSet.setDuration(180);
        }
        animatorSet.setInterpolator(new AccelerateInterpolator());
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                dismissInternal();
                            } catch (Exception e) {
                                FileLog.e("tmessages", e);
                            }
                        }
                    });
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                }
            }
        });
        animatorSet.start();
        currentSheetAnimation = animatorSet;
    }
}

From source file:com.b44t.ui.ActionBar.BottomSheet.java

@Override
public void dismiss() {
    if (dismissed) {
        return;/*from w  w w .  j a v a2 s  . co m*/
    }
    dismissed = true;
    cancelSheetAnimation();
    if (!allowCustomAnimation || !onCustomCloseAnimation()) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(
                ObjectAnimator.ofFloat(containerView, "translationY",
                        containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
                ObjectAnimator.ofInt(backDrawable, "alpha", 0));
        if (useFastDismiss) {
            int height = containerView.getMeasuredHeight();
            animatorSet.setDuration(
                    Math.max(60, (int) (180 * (height - containerView.getTranslationY()) / (float) height)));
            useFastDismiss = false;
        } else {
            animatorSet.setDuration(180);
        }
        animatorSet.setInterpolator(new AccelerateInterpolator());
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                dismissInternal();
                            } catch (Exception e) {
                                FileLog.e("messenger", e);
                            }
                        }
                    });
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                }
            }
        });
        animatorSet.start();
        currentSheetAnimation = animatorSet;
    }
}

From source file:com.adityarathi.muo.ui.activities.NowPlayingActivity.java

/**
 * Smoothly scrolls the seekbar to the indicated position.
 *//*from ww  w . j a  v a2s .c  o m*/
private void smoothScrollSeekbar(int progress) {
    ObjectAnimator animation = ObjectAnimator.ofInt(mSeekbar, "progress", progress);
    animation.setDuration(200);
    animation.setInterpolator(new DecelerateInterpolator());
    animation.start();

}

From source file:org.michaelbel.bottomsheet.BottomSheet.java

private void dismissWithButtonClick(final int viewId) {
    if (dismissed) {
        return;/*  w ww. j av  a  2 s  .  c  o  m*/
    }

    dismissed = true;
    cancelSheetAnimation();
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(containerView, "translationY",
                    containerView.getMeasuredHeight() + Utils.dp(getContext(), 10)),
            ObjectAnimator.ofInt(backDrawable, "alpha", 0));
    animatorSet.setDuration(180);
    animatorSet.setInterpolator(new AccelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
                if (onClickListener != null) {
                    onClickListener.onClick(BottomSheet.this, viewId);
                }

                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            BottomSheet.super.dismiss();
                        } catch (Exception e) {
                            Log.e(TAG, e.getMessage());
                        }
                    }
                });
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
            }
        }
    });

    animatorSet.start();
    currentSheetAnimation = animatorSet;

    if (bottomSheetCallBack != null) {
        bottomSheetCallBack.onClose();
    }
}

From source file:fr.paug.droidcon.ui.BaseActivity.java

protected void onActionBarAutoShowOrHide(boolean shown) {
    if (mStatusBarColorAnimator != null) {
        mStatusBarColorAnimator.cancel();
    }/*from  ww  w. j a v  a 2  s.c om*/
    mStatusBarColorAnimator = ObjectAnimator
            .ofInt(mLPreviewUtils, "statusBarColor", shown ? mThemedStatusBarColor : Color.BLACK)
            .setDuration(250);
    mStatusBarColorAnimator.setEvaluator(ARGB_EVALUATOR);
    mStatusBarColorAnimator.start();

    updateSwipeRefreshProgressBarTop();

    for (View view : mHideableHeaderViews) {
        if (shown) {
            view.animate().translationY(0).alpha(1).setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        } else {
            view.animate().translationY(-view.getBottom()).alpha(0).setDuration(HEADER_HIDE_ANIM_DURATION)
                    .setInterpolator(new DecelerateInterpolator());
        }
    }
}

From source file:org.chromium.chrome.browser.toolbar.ToolbarPhone.java

private void populateUrlClearFocusingAnimatorSet(List<Animator> animators) {
    Animator animator = ObjectAnimator.ofFloat(this, mUrlFocusChangePercentProperty, 0f);
    animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);/*from   w  w w.  j  a v a  2 s. com*/

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, TRANSLATION_X, 0);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    animator = ObjectAnimator.ofFloat(mMenuButtonWrapper, ALPHA, 1);
    animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
    animator.setStartDelay(URL_CLEAR_FOCUS_MENU_DELAY_MS);
    animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
    animators.add(animator);

    if (mToggleTabStackButton != null) {
        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, TRANSLATION_X, 0);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);

        animator = ObjectAnimator.ofFloat(mToggleTabStackButton, ALPHA, 1);
        animator.setDuration(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setStartDelay(URL_CLEAR_FOCUS_TABSTACK_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);
    }

    for (int i = 0; i < mLocationBar.getChildCount(); i++) {
        View childView = mLocationBar.getChildAt(i);
        if (childView == mLocationBar.getFirstViewVisibleWhenFocused())
            break;
        animator = ObjectAnimator.ofFloat(childView, ALPHA, 1);
        animator.setStartDelay(URL_FOCUS_TOOLBAR_BUTTONS_DURATION_MS);
        animator.setDuration(URL_CLEAR_FOCUS_MENU_DELAY_MS);
        animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
        animators.add(animator);
    }

    if (isLocationBarShownInNTP() && mNtpSearchBoxScrollPercent == 0f)
        return;

    // The call to getLayout() can return null briefly during text changes, but as it
    // is only needed for RTL calculations, we proceed if the location bar is showing
    // LTR content.
    boolean isLocationBarRtl = ApiCompatibilityUtils.isLayoutRtl(mLocationBar);
    if (!isLocationBarRtl || mUrlBar.getLayout() != null) {
        int urlBarStartScrollX = 0;
        if (isLocationBarRtl) {
            urlBarStartScrollX = (int) mUrlBar.getLayout().getPrimaryHorizontal(0);
            urlBarStartScrollX -= mUrlBar.getWidth();
        }

        // If the scroll position matches the current scroll position, do not trigger
        // this animation as it will cause visible jumps when going from cleared text
        // back to page URLs (despite it continually calling setScrollX with the same
        // number).
        if (mUrlBar.getScrollX() != urlBarStartScrollX) {
            animator = ObjectAnimator.ofInt(mUrlBar, buildUrlScrollProperty(mLocationBar, isLocationBarRtl),
                    urlBarStartScrollX);
            animator.setDuration(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
            animator.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE);
            animators.add(animator);
        }
    }
}

From source file:org.telegram.ui.Components.ChatAttachAlert.java

@SuppressLint("NewApi")
private void startRevealAnimation(final boolean open) {
    containerView.setTranslationY(0);// ww  w  .  j  ava 2 s.c  o  m

    final AnimatorSet animatorSet = new AnimatorSet();

    View view = delegate.getRevealView();
    if (view.getVisibility() == View.VISIBLE
            && ((ViewGroup) view.getParent()).getVisibility() == View.VISIBLE) {
        final int coords[] = new int[2];
        view.getLocationInWindow(coords);
        float top;
        if (Build.VERSION.SDK_INT <= 19) {
            top = AndroidUtilities.displaySize.y - containerView.getMeasuredHeight()
                    - AndroidUtilities.statusBarHeight;
        } else {
            top = containerView.getY();
        }
        revealX = coords[0] + view.getMeasuredWidth() / 2;
        revealY = (int) (coords[1] + view.getMeasuredHeight() / 2 - top);
        if (Build.VERSION.SDK_INT <= 19) {
            revealY -= AndroidUtilities.statusBarHeight;
        }
    } else {
        revealX = AndroidUtilities.displaySize.x / 2 + backgroundPaddingLeft;
        revealY = (int) (AndroidUtilities.displaySize.y - containerView.getY());
    }

    int corners[][] = new int[][] { { 0, 0 }, { 0, AndroidUtilities.dp(304) },
            { containerView.getMeasuredWidth(), 0 },
            { containerView.getMeasuredWidth(), AndroidUtilities.dp(304) } };
    int finalRevealRadius = 0;
    int y = revealY - scrollOffsetY + backgroundPaddingTop;
    for (int a = 0; a < 4; a++) {
        finalRevealRadius = Math.max(finalRevealRadius,
                (int) Math.ceil(Math.sqrt((revealX - corners[a][0]) * (revealX - corners[a][0])
                        + (y - corners[a][1]) * (y - corners[a][1]))));
    }
    int finalRevealX = revealX <= containerView.getMeasuredWidth() ? revealX : containerView.getMeasuredWidth();

    ArrayList<Animator> animators = new ArrayList<>(3);
    animators.add(ObjectAnimator.ofFloat(this, "revealRadius", open ? 0 : finalRevealRadius,
            open ? finalRevealRadius : 0));
    animators.add(ObjectAnimator.ofInt(backDrawable, "alpha", open ? 51 : 0));
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            animators.add(ViewAnimationUtils.createCircularReveal(containerView, finalRevealX, revealY,
                    open ? 0 : finalRevealRadius, open ? finalRevealRadius : 0));
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        animatorSet.setDuration(320);
    } else {
        if (!open) {
            animatorSet.setDuration(200);
            containerView.setPivotX(
                    revealX <= containerView.getMeasuredWidth() ? revealX : containerView.getMeasuredWidth());
            containerView.setPivotY(revealY);
            animators.add(ObjectAnimator.ofFloat(containerView, "scaleX", 0.0f));
            animators.add(ObjectAnimator.ofFloat(containerView, "scaleY", 0.0f));
            animators.add(ObjectAnimator.ofFloat(containerView, "alpha", 0.0f));
        } else {
            animatorSet.setDuration(250);
            containerView.setScaleX(1);
            containerView.setScaleY(1);
            containerView.setAlpha(1);
            if (Build.VERSION.SDK_INT <= 19) {
                animatorSet.setStartDelay(20);
            }
        }
    }
    animatorSet.playTogether(animators);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        public void onAnimationEnd(Animator animation) {
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
                onRevealAnimationEnd(open);
                containerView.invalidate();
                containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                if (!open) {
                    try {
                        dismissInternal();
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (currentSheetAnimation != null && animatorSet.equals(animation)) {
                currentSheetAnimation = null;
            }
        }
    });

    if (open) {
        innerAnimators.clear();
        NotificationCenter.getInstance()
                .setAllowedNotificationsDutingAnimation(new int[] { NotificationCenter.dialogsNeedReload });
        NotificationCenter.getInstance().setAnimationInProgress(true);
        revealAnimationInProgress = true;

        int count = Build.VERSION.SDK_INT <= 19 ? 11 : 8;
        for (int a = 0; a < count; a++) {
            if (Build.VERSION.SDK_INT <= 19) {
                if (a < 8) {
                    views[a].setScaleX(0.1f);
                    views[a].setScaleY(0.1f);
                }
                views[a].setAlpha(0.0f);
            } else {
                views[a].setScaleX(0.7f);
                views[a].setScaleY(0.7f);
            }

            InnerAnimator innerAnimator = new InnerAnimator();

            int buttonX = views[a].getLeft() + views[a].getMeasuredWidth() / 2;
            int buttonY = views[a].getTop() + attachView.getTop() + views[a].getMeasuredHeight() / 2;
            float dist = (float) Math.sqrt(
                    (revealX - buttonX) * (revealX - buttonX) + (revealY - buttonY) * (revealY - buttonY));
            float vecX = (revealX - buttonX) / dist;
            float vecY = (revealY - buttonY) / dist;
            views[a].setPivotX(views[a].getMeasuredWidth() / 2 + vecX * AndroidUtilities.dp(20));
            views[a].setPivotY(views[a].getMeasuredHeight() / 2 + vecY * AndroidUtilities.dp(20));
            innerAnimator.startRadius = dist - AndroidUtilities.dp(27 * 3);

            views[a].setTag(R.string.AppName, 1);
            animators = new ArrayList<>();
            final AnimatorSet animatorSetInner;
            if (a < 8) {
                animators.add(ObjectAnimator.ofFloat(views[a], "scaleX", 0.7f, 1.05f));
                animators.add(ObjectAnimator.ofFloat(views[a], "scaleY", 0.7f, 1.05f));

                animatorSetInner = new AnimatorSet();
                animatorSetInner.playTogether(ObjectAnimator.ofFloat(views[a], "scaleX", 1.0f),
                        ObjectAnimator.ofFloat(views[a], "scaleY", 1.0f));
                animatorSetInner.setDuration(100);
                animatorSetInner.setInterpolator(decelerateInterpolator);
            } else {
                animatorSetInner = null;
            }
            if (Build.VERSION.SDK_INT <= 19) {
                animators.add(ObjectAnimator.ofFloat(views[a], "alpha", 1.0f));
            }
            innerAnimator.animatorSet = new AnimatorSet();
            innerAnimator.animatorSet.playTogether(animators);
            innerAnimator.animatorSet.setDuration(150);
            innerAnimator.animatorSet.setInterpolator(decelerateInterpolator);
            innerAnimator.animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (animatorSetInner != null) {
                        animatorSetInner.start();
                    }
                }
            });
            innerAnimators.add(innerAnimator);
        }
    }
    currentSheetAnimation = animatorSet;
    animatorSet.start();
}

From source file:kr.wdream.ui.PhotoViewer.java

public void closePhoto(boolean animated, boolean fromEditMode) {
    if (!fromEditMode && currentEditMode != 0) {
        if (currentEditMode == 3 && photoPaintView != null) {
            photoPaintView.maybeShowDismissalAlert(this, parentActivity, new Runnable() {
                @Override/*from w  w  w. ja  v a 2 s.  c  o  m*/
                public void run() {
                    switchToEditMode(0);
                }
            });
            return;
        }

        if (currentEditMode == 1) {
            photoCropView.cancelAnimationRunnable();
        }
        switchToEditMode(0);
        return;
    }
    try {
        if (visibleDialog != null) {
            visibleDialog.dismiss();
            visibleDialog = null;
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    if (currentEditMode != 0) {
        if (currentEditMode == 2) {
            photoFilterView.shutdown();
            containerView.removeView(photoFilterView);
            photoFilterView = null;
        } else if (currentEditMode == 1) {
            editorDoneLayout.setVisibility(View.GONE);
            photoCropView.setVisibility(View.GONE);
        }
        currentEditMode = 0;
    }

    if (parentActivity == null || !isVisible || checkAnimation() || placeProvider == null) {
        return;
    }
    if (captionEditText.hideActionMode() && !fromEditMode) {
        return;
    }

    releasePlayer();
    captionEditText.onDestroy();
    parentChatActivity = null;
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileLoadProgressChanged);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaCountDidLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaDidLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.dialogPhotosLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
    ConnectionsManager.getInstance().cancelRequestsForGuid(classGuid);

    isActionBarVisible = false;

    if (velocityTracker != null) {
        velocityTracker.recycle();
        velocityTracker = null;
    }
    ConnectionsManager.getInstance().cancelRequestsForGuid(classGuid);

    final PlaceProviderObject object = placeProvider.getPlaceForPhoto(currentMessageObject, currentFileLocation,
            currentIndex);

    if (animated) {
        animationInProgress = 1;
        animatingImageView.setVisibility(View.VISIBLE);
        containerView.invalidate();

        AnimatorSet animatorSet = new AnimatorSet();

        final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
        Rect drawRegion = null;
        int orientation = centerImage.getOrientation();
        int animatedOrientation = 0;
        if (object != null && object.imageReceiver != null) {
            animatedOrientation = object.imageReceiver.getAnimatedOrientation();
        }
        if (animatedOrientation != 0) {
            orientation = animatedOrientation;
        }
        animatingImageView.setOrientation(orientation);
        if (object != null) {
            animatingImageView.setNeedRadius(object.radius != 0);
            drawRegion = object.imageReceiver.getDrawRegion();
            layoutParams.width = drawRegion.right - drawRegion.left;
            layoutParams.height = drawRegion.bottom - drawRegion.top;
            animatingImageView.setImageBitmap(object.thumb);
        } else {
            animatingImageView.setNeedRadius(false);
            layoutParams.width = centerImage.getImageWidth();
            layoutParams.height = centerImage.getImageHeight();
            animatingImageView.setImageBitmap(centerImage.getBitmap());
        }
        animatingImageView.setLayoutParams(layoutParams);

        float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
        float scaleY = (float) (AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / layoutParams.height;
        float scale2 = scaleX > scaleY ? scaleY : scaleX;
        float width = layoutParams.width * scale * scale2;
        float height = layoutParams.height * scale * scale2;
        float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
        float yPos = ((AndroidUtilities.displaySize.y
                + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) - height) / 2.0f;
        animatingImageView.setTranslationX(xPos + translationX);
        animatingImageView.setTranslationY(yPos + translationY);
        animatingImageView.setScaleX(scale * scale2);
        animatingImageView.setScaleY(scale * scale2);

        if (object != null) {
            object.imageReceiver.setVisible(false, true);
            int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
            int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());

            int coords2[] = new int[2];
            object.parentView.getLocationInWindow(coords2);
            int clipTop = coords2[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight)
                    - (object.viewY + drawRegion.top) + object.clipTopAddition;
            if (clipTop < 0) {
                clipTop = 0;
            }
            int clipBottom = (object.viewY + drawRegion.top + (drawRegion.bottom - drawRegion.top))
                    - (coords2[1] + object.parentView.getHeight()
                            - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight))
                    + object.clipBottomAddition;
            if (clipBottom < 0) {
                clipBottom = 0;
            }

            clipTop = Math.max(clipTop, clipVertical);
            clipBottom = Math.max(clipBottom, clipVertical);

            animationValues[0][0] = animatingImageView.getScaleX();
            animationValues[0][1] = animatingImageView.getScaleY();
            animationValues[0][2] = animatingImageView.getTranslationX();
            animationValues[0][3] = animatingImageView.getTranslationY();
            animationValues[0][4] = 0;
            animationValues[0][5] = 0;
            animationValues[0][6] = 0;
            animationValues[0][7] = 0;

            animationValues[1][0] = object.scale;
            animationValues[1][1] = object.scale;
            animationValues[1][2] = object.viewX + drawRegion.left * object.scale;
            animationValues[1][3] = object.viewY + drawRegion.top * object.scale;
            animationValues[1][4] = clipHorizontal * object.scale;
            animationValues[1][5] = clipTop * object.scale;
            animationValues[1][6] = clipBottom * object.scale;
            animationValues[1][7] = object.radius;

            animatorSet.playTogether(
                    ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
                    ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
                    ObjectAnimator.ofFloat(containerView, "alpha", 0.0f));
        } else {
            int h = (AndroidUtilities.displaySize.y
                    + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0));
            animatorSet.playTogether(ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
                    ObjectAnimator.ofFloat(animatingImageView, "alpha", 0.0f),
                    ObjectAnimator.ofFloat(animatingImageView, "translationY", translationY >= 0 ? h : -h),
                    ObjectAnimator.ofFloat(containerView, "alpha", 0.0f));
        }

        animationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= 18) {
                    containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                animationInProgress = 0;
                onPhotoClosed(object);
            }
        };

        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        if (animationEndRunnable != null) {
                            animationEndRunnable.run();
                            animationEndRunnable = null;
                        }
                    }
                });
            }
        });
        transitionAnimationStartTime = System.currentTimeMillis();
        if (Build.VERSION.SDK_INT >= 18) {
            containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        animatorSet.start();
    } else {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "scaleX", 0.9f),
                ObjectAnimator.ofFloat(containerView, "scaleY", 0.9f),
                ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
                ObjectAnimator.ofFloat(containerView, "alpha", 0.0f));
        animationInProgress = 2;
        animationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (containerView == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 18) {
                    containerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                animationInProgress = 0;
                onPhotoClosed(object);
                containerView.setScaleX(1.0f);
                containerView.setScaleY(1.0f);
            }
        };
        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (animationEndRunnable != null) {
                    animationEndRunnable.run();
                    animationEndRunnable = null;
                }
            }
        });
        transitionAnimationStartTime = System.currentTimeMillis();
        if (Build.VERSION.SDK_INT >= 18) {
            containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        animatorSet.start();
    }
    if (currentAnimation != null) {
        currentAnimation.setSecondParentView(null);
        currentAnimation = null;
        centerImage.setImageBitmap((Drawable) null);
    }
    if (placeProvider instanceof EmptyPhotoViewerProvider) {
        placeProvider.cancelButtonPressed();
    }
}

From source file:org.telegram.ui.ArticleViewer.java

public void closePhoto(boolean animated) {
    if (parentActivity == null || !isPhotoVisible || checkPhotoAnimation()) {
        return;/*www.j av  a  2 s .co m*/
    }

    releasePlayer();
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileLoadProgressChanged);
    NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);

    isActionBarVisible = false;

    if (velocityTracker != null) {
        velocityTracker.recycle();
        velocityTracker = null;
    }

    final PlaceProviderObject object = getPlaceForPhoto(currentMedia);

    if (animated) {
        photoAnimationInProgress = 1;
        animatingImageView.setVisibility(View.VISIBLE);
        photoContainerView.invalidate();

        AnimatorSet animatorSet = new AnimatorSet();

        final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
        Rect drawRegion = null;
        int orientation = centerImage.getOrientation();
        int animatedOrientation = 0;
        if (object != null && object.imageReceiver != null) {
            animatedOrientation = object.imageReceiver.getAnimatedOrientation();
        }
        if (animatedOrientation != 0) {
            orientation = animatedOrientation;
        }
        animatingImageView.setOrientation(orientation);
        if (object != null) {
            animatingImageView.setNeedRadius(object.radius != 0);
            drawRegion = object.imageReceiver.getDrawRegion();
            layoutParams.width = drawRegion.right - drawRegion.left;
            layoutParams.height = drawRegion.bottom - drawRegion.top;
            animatingImageView.setImageBitmap(object.thumb);
        } else {
            animatingImageView.setNeedRadius(false);
            layoutParams.width = centerImage.getImageWidth();
            layoutParams.height = centerImage.getImageHeight();
            animatingImageView.setImageBitmap(centerImage.getBitmap());
        }
        animatingImageView.setLayoutParams(layoutParams);

        float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
        float scaleY = (float) (AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight)
                / layoutParams.height;
        float scale2 = scaleX > scaleY ? scaleY : scaleX;
        float width = layoutParams.width * scale * scale2;
        float height = layoutParams.height * scale * scale2;
        float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
        if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
            xPos += ((WindowInsets) lastInsets).getSystemWindowInsetLeft();
        }
        float yPos = (AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight - height) / 2.0f;
        animatingImageView.setTranslationX(xPos + translationX);
        animatingImageView.setTranslationY(yPos + translationY);
        animatingImageView.setScaleX(scale * scale2);
        animatingImageView.setScaleY(scale * scale2);

        if (object != null) {
            object.imageReceiver.setVisible(false, true);
            int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
            int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());

            int coords2[] = new int[2];
            object.parentView.getLocationInWindow(coords2);
            int clipTop = coords2[1] - (object.viewY + drawRegion.top) + object.clipTopAddition;
            if (clipTop < 0) {
                clipTop = 0;
            }
            int clipBottom = (object.viewY + drawRegion.top + (drawRegion.bottom - drawRegion.top))
                    - (coords2[1] + object.parentView.getHeight()) + object.clipBottomAddition;
            if (clipBottom < 0) {
                clipBottom = 0;
            }

            clipTop = Math.max(clipTop, clipVertical);
            clipBottom = Math.max(clipBottom, clipVertical);

            animationValues[0][0] = animatingImageView.getScaleX();
            animationValues[0][1] = animatingImageView.getScaleY();
            animationValues[0][2] = animatingImageView.getTranslationX();
            animationValues[0][3] = animatingImageView.getTranslationY();
            animationValues[0][4] = 0;
            animationValues[0][5] = 0;
            animationValues[0][6] = 0;
            animationValues[0][7] = 0;

            animationValues[1][0] = object.scale;
            animationValues[1][1] = object.scale;
            animationValues[1][2] = object.viewX + drawRegion.left * object.scale;
            animationValues[1][3] = object.viewY + drawRegion.top * object.scale;
            animationValues[1][4] = clipHorizontal * object.scale;
            animationValues[1][5] = clipTop * object.scale;
            animationValues[1][6] = clipBottom * object.scale;
            animationValues[1][7] = object.radius;

            animatorSet.playTogether(
                    ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
                    ObjectAnimator.ofInt(photoBackgroundDrawable, "alpha", 0),
                    ObjectAnimator.ofFloat(actionBar, "alpha", 0),
                    ObjectAnimator.ofFloat(bottomLayout, "alpha", 0),
                    ObjectAnimator.ofFloat(captionTextView, "alpha", 0));
        } else {
            int h = AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight;
            animatorSet.playTogether(ObjectAnimator.ofInt(photoBackgroundDrawable, "alpha", 0),
                    ObjectAnimator.ofFloat(animatingImageView, "alpha", 0.0f),
                    ObjectAnimator.ofFloat(animatingImageView, "translationY", translationY >= 0 ? h : -h),
                    ObjectAnimator.ofFloat(actionBar, "alpha", 0),
                    ObjectAnimator.ofFloat(bottomLayout, "alpha", 0),
                    ObjectAnimator.ofFloat(captionTextView, "alpha", 0));
        }

        photoAnimationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= 18) {
                    photoContainerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                photoContainerView.setVisibility(View.INVISIBLE);
                photoContainerBackground.setVisibility(View.INVISIBLE);
                photoAnimationInProgress = 0;
                onPhotoClosed(object);
            }
        };

        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        if (photoAnimationEndRunnable != null) {
                            photoAnimationEndRunnable.run();
                            photoAnimationEndRunnable = null;
                        }
                    }
                });
            }
        });
        photoTransitionAnimationStartTime = System.currentTimeMillis();
        if (Build.VERSION.SDK_INT >= 18) {
            photoContainerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        animatorSet.start();
    } else {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(ObjectAnimator.ofFloat(photoContainerView, "scaleX", 0.9f),
                ObjectAnimator.ofFloat(photoContainerView, "scaleY", 0.9f),
                ObjectAnimator.ofInt(photoBackgroundDrawable, "alpha", 0),
                ObjectAnimator.ofFloat(actionBar, "alpha", 0), ObjectAnimator.ofFloat(bottomLayout, "alpha", 0),
                ObjectAnimator.ofFloat(captionTextView, "alpha", 0));
        photoAnimationInProgress = 2;
        photoAnimationEndRunnable = new Runnable() {
            @Override
            public void run() {
                if (photoContainerView == null) {
                    return;
                }
                if (Build.VERSION.SDK_INT >= 18) {
                    photoContainerView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                photoContainerView.setVisibility(View.INVISIBLE);
                photoContainerBackground.setVisibility(View.INVISIBLE);
                photoAnimationInProgress = 0;
                onPhotoClosed(object);
                photoContainerView.setScaleX(1.0f);
                photoContainerView.setScaleY(1.0f);
            }
        };
        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (photoAnimationEndRunnable != null) {
                    photoAnimationEndRunnable.run();
                    photoAnimationEndRunnable = null;
                }
            }
        });
        photoTransitionAnimationStartTime = System.currentTimeMillis();
        if (Build.VERSION.SDK_INT >= 18) {
            photoContainerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        animatorSet.start();
    }
    if (currentAnimation != null) {
        currentAnimation.setSecondParentView(null);
        currentAnimation = null;
        centerImage.setImageBitmap((Drawable) null);
    }
}