Example usage for android.animation AnimatorSet setInterpolator

List of usage examples for android.animation AnimatorSet setInterpolator

Introduction

In this page you can find the example usage for android.animation AnimatorSet setInterpolator.

Prototype

@Override
public void setInterpolator(TimeInterpolator interpolator) 

Source Link

Document

Sets the TimeInterpolator for all current #getChildAnimations() child animations of this AnimatorSet.

Usage

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

private void hideActionBar() {
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(backButton, "alpha", 0.0f),
            ObjectAnimator.ofFloat(shareContainer, "alpha", 0.0f));
    animatorSet.setDuration(250);//from www.  ja  va 2 s .  c o m
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.start();
}

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

@Override
protected AnimatorSet onCustomTransitionAnimation(final boolean isOpen, final Runnable callback) {
    if (playProfileAnimation && allowProfileAnimation) {
        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(180);//from www. j a va 2 s .c om
        if (Build.VERSION.SDK_INT > 15) {
            listView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
        ActionBarMenu menu = actionBar.createMenu();
        if (menu.getItem(10) == null) {
            if (animatingItem == null) {
                animatingItem = menu.addItem(10, R.drawable.ic_ab_other);
            }
        }
        if (isOpen) {
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) onlineTextView[1]
                    .getLayoutParams();
            layoutParams.rightMargin = (int) (-21 * AndroidUtilities.density + AndroidUtilities.dp(8));
            onlineTextView[1].setLayoutParams(layoutParams);

            int width = (int) Math.ceil(AndroidUtilities.displaySize.x - AndroidUtilities.dp(118 + 8)
                    + 21 * AndroidUtilities.density);
            float width2 = nameTextView[1].getPaint().measureText(nameTextView[1].getText().toString()) * 1.12f
                    + getSideDrawablesSize(nameTextView[1]);
            layoutParams = (FrameLayout.LayoutParams) nameTextView[1].getLayoutParams();
            if (width < width2) {
                layoutParams.width = (int) Math.ceil(width / 1.12f);
            } else {
                layoutParams.width = LayoutHelper.WRAP_CONTENT;
            }
            nameTextView[1].setLayoutParams(layoutParams);

            initialAnimationExtraHeight = AndroidUtilities.dp(88);
            fragmentView.setBackgroundColor(0);
            setAnimationProgress(0);
            ArrayList<Animator> animators = new ArrayList<>();
            animators.add(ObjectAnimator.ofFloat(this, "animationProgress", 0.0f, 1.0f));
            if (writeButton != null) {
                writeButton.setScaleX(0.2f);
                writeButton.setScaleY(0.2f);
                writeButton.setAlpha(0.0f);
                animators.add(ObjectAnimator.ofFloat(writeButton, "scaleX", 1.0f));
                animators.add(ObjectAnimator.ofFloat(writeButton, "scaleY", 1.0f));
                animators.add(ObjectAnimator.ofFloat(writeButton, "alpha", 1.0f));
            }
            for (int a = 0; a < 2; a++) {
                onlineTextView[a].setAlpha(a == 0 ? 1.0f : 0.0f);
                nameTextView[a].setAlpha(a == 0 ? 1.0f : 0.0f);
                animators.add(ObjectAnimator.ofFloat(onlineTextView[a], "alpha", a == 0 ? 0.0f : 1.0f));
                animators.add(ObjectAnimator.ofFloat(nameTextView[a], "alpha", a == 0 ? 0.0f : 1.0f));
            }
            if (animatingItem != null) {
                animatingItem.setAlpha(1.0f);
                animators.add(ObjectAnimator.ofFloat(animatingItem, "alpha", 0.0f));
            }
            animatorSet.playTogether(animators);
        } else {
            initialAnimationExtraHeight = extraHeight;
            ArrayList<Animator> animators = new ArrayList<>();
            animators.add(ObjectAnimator.ofFloat(this, "animationProgress", 1.0f, 0.0f));
            if (writeButton != null) {
                animators.add(ObjectAnimator.ofFloat(writeButton, "scaleX", 0.2f));
                animators.add(ObjectAnimator.ofFloat(writeButton, "scaleY", 0.2f));
                animators.add(ObjectAnimator.ofFloat(writeButton, "alpha", 0.0f));
            }
            for (int a = 0; a < 2; a++) {
                animators.add(ObjectAnimator.ofFloat(onlineTextView[a], "alpha", a == 0 ? 1.0f : 0.0f));
                animators.add(ObjectAnimator.ofFloat(nameTextView[a], "alpha", a == 0 ? 1.0f : 0.0f));
            }
            if (animatingItem != null) {
                animatingItem.setAlpha(0.0f);
                animators.add(ObjectAnimator.ofFloat(animatingItem, "alpha", 1.0f));
            }
            animatorSet.playTogether(animators);
        }
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (Build.VERSION.SDK_INT > 15) {
                    listView.setLayerType(View.LAYER_TYPE_NONE, null);
                }
                if (animatingItem != null) {
                    ActionBarMenu menu = actionBar.createMenu();
                    menu.clearItems();
                    animatingItem = null;
                }
                callback.run();
            }
        });
        animatorSet.setInterpolator(new DecelerateInterpolator());

        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                animatorSet.start();
            }
        }, 50);
        return animatorSet;
    }
    return null;
}

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

public void close(boolean byBackPress, boolean force) {
    if (parentActivity == null || !isVisible || checkAnimation()) {
        return;//  ww w  . j  a  v a  2  s . c  o m
    }
    if (fullscreenVideoContainer.getVisibility() == View.VISIBLE) {
        if (customView != null) {
            fullscreenVideoContainer.setVisibility(View.INVISIBLE);
            customViewCallback.onCustomViewHidden();
            fullscreenVideoContainer.removeView(customView);
            customView = null;
        } else if (fullscreenedVideo != null) {
            fullscreenedVideo.exitFullscreen();
        }
        if (!force) {
            return;
        }
    }
    if (isPhotoVisible) {
        closePhoto(!force);
        if (!force) {
            return;
        }
    }
    if (openUrlReqId != 0) {
        ConnectionsManager.getInstance().cancelRequest(openUrlReqId, true);
        openUrlReqId = 0;
        showProgressView(false);
    }
    if (previewsReqId != 0) {
        ConnectionsManager.getInstance().cancelRequest(previewsReqId, true);
        previewsReqId = 0;
        showProgressView(false);
    }
    saveCurrentPagePosition();
    if (byBackPress && !force) {
        if (removeLastPageFromStack()) {
            return;
        }
    }

    try {
        if (visibleDialog != null) {
            visibleDialog.dismiss();
            visibleDialog = null;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(windowView, "alpha", 0),
            ObjectAnimator.ofFloat(containerView, "alpha", 0.0f),
            ObjectAnimator.ofFloat(windowView, "translationX", 0, AndroidUtilities.dp(56)));
    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;
            onClosed();
        }
    };
    animatorSet.setDuration(150);
    animatorSet.setInterpolator(interpolator);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @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();
}

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

private boolean open(final MessageObject messageObject, boolean first) {
    if (parentActivity == null || isVisible && !collapsed || messageObject == null) {
        return false;
    }/* w  w w.j  a v a2 s  .c  o  m*/

    if (first) {
        TLRPC.TL_messages_getWebPage req = new TLRPC.TL_messages_getWebPage();
        req.url = messageObject.messageOwner.media.webpage.url;
        if (messageObject.messageOwner.media.webpage.cached_page instanceof TLRPC.TL_pagePart) {
            req.hash = 0;
        } else {
            req.hash = messageObject.messageOwner.media.webpage.hash;
        }
        ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
            @Override
            public void run(TLObject response, TLRPC.TL_error error) {
                if (response instanceof TLRPC.TL_webPage) {
                    final TLRPC.TL_webPage webPage = (TLRPC.TL_webPage) response;
                    if (webPage.cached_page == null) {
                        return;
                    }
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            if (!pagesStack.isEmpty()
                                    && pagesStack.get(0) == messageObject.messageOwner.media.webpage
                                    && webPage.cached_page != null) {
                                messageObject.messageOwner.media.webpage = webPage;
                                pagesStack.set(0, webPage);
                                if (pagesStack.size() == 1) {
                                    currentPage = webPage;
                                    ApplicationLoader.applicationContext
                                            .getSharedPreferences("articles", Activity.MODE_PRIVATE).edit()
                                            .remove("article" + currentPage.id).commit();
                                    updateInterfaceForCurrentPage(false);
                                }
                            }
                        }
                    });
                    HashMap<Long, TLRPC.WebPage> webpages = new HashMap<>();
                    webpages.put(webPage.id, webPage);
                    MessagesStorage.getInstance().putWebPages(webpages);
                }
            }
        });
    }

    pagesStack.clear();
    collapsed = false;
    backDrawable.setRotation(0, false);
    containerView.setTranslationX(0);
    containerView.setTranslationY(0);
    listView.setTranslationY(0);
    listView.setAlpha(1.0f);
    windowView.setInnerTranslationX(0);

    actionBar.setVisibility(View.GONE);
    bottomLayout.setVisibility(View.GONE);
    captionTextViewNew.setVisibility(View.GONE);
    captionTextViewOld.setVisibility(View.GONE);
    shareContainer.setAlpha(0.0f);
    backButton.setAlpha(0.0f);
    layoutManager.scrollToPositionWithOffset(0, 0);
    checkScroll(-AndroidUtilities.dp(56));

    TLRPC.WebPage webPage = messageObject.messageOwner.media.webpage;
    String webPageUrl = webPage.url.toLowerCase();
    int index;
    String anchor = null;
    for (int a = 0; a < messageObject.messageOwner.entities.size(); a++) {
        TLRPC.MessageEntity entity = messageObject.messageOwner.entities.get(a);
        if (entity instanceof TLRPC.TL_messageEntityUrl) {
            try {
                String url = messageObject.messageOwner.message
                        .substring(entity.offset, entity.offset + entity.length).toLowerCase();
                if (url.contains(webPageUrl) || webPageUrl.contains(url)) {
                    if ((index = url.lastIndexOf('#')) != -1) {
                        anchor = url.substring(index + 1);
                    }
                    break;
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    }
    addPageToStack(webPage, anchor);

    lastInsets = null;
    if (!isVisible) {
        WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
        if (attachedToWindow) {
            try {
                wm.removeView(windowView);
            } catch (Exception e) {
                //ignore
            }
        }
        try {
            if (Build.VERSION.SDK_INT >= 21) {
                windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
                        | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
            }
            windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
            windowView.setFocusable(false);
            containerView.setFocusable(false);
            wm.addView(windowView, windowLayoutParams);
        } catch (Exception e) {
            FileLog.e(e);
            return false;
        }
    } else {
        windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
        wm.updateViewLayout(windowView, windowLayoutParams);
    }
    isVisible = true;
    animationInProgress = 1;
    windowView.setAlpha(0);
    containerView.setAlpha(0);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(windowView, "alpha", 0, 1.0f),
            ObjectAnimator.ofFloat(containerView, "alpha", 0.0f, 1.0f),
            ObjectAnimator.ofFloat(windowView, "translationX", AndroidUtilities.dp(56), 0));

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

    animatorSet.setDuration(150);
    animatorSet.setInterpolator(interpolator);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    NotificationCenter.getInstance().setAnimationInProgress(false);
                    if (animationEndRunnable != null) {
                        animationEndRunnable.run();
                        animationEndRunnable = null;
                    }
                }
            });
        }
    });
    transitionAnimationStartTime = System.currentTimeMillis();
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            NotificationCenter.getInstance()
                    .setAllowedNotificationsDutingAnimation(new int[] { NotificationCenter.dialogsNeedReload,
                            NotificationCenter.closeChats, NotificationCenter.mediaCountDidLoaded,
                            NotificationCenter.mediaDidLoaded, NotificationCenter.dialogPhotosLoaded });
            NotificationCenter.getInstance().setAnimationInProgress(true);
            animatorSet.start();
        }
    });
    if (Build.VERSION.SDK_INT >= 18) {
        containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    showActionBar(200);
    return true;
}

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

public void uncollapse() {
    if (parentActivity == null || !isVisible || checkAnimation()) {
        return;//from ww w  .  j  a v  a  2  s.c o  m
    }

    /*windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
    WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
    wm.updateViewLayout(windowView, windowLayoutParams);*/

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationX", 0),
            ObjectAnimator.ofFloat(containerView, "translationY", 0),
            ObjectAnimator.ofFloat(windowView, "alpha", 1.0f), ObjectAnimator.ofFloat(listView, "alpha", 1.0f),
            ObjectAnimator.ofFloat(listView, "translationY", 0),
            ObjectAnimator.ofFloat(headerView, "translationY", 0),

            ObjectAnimator.ofFloat(backButton, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(backButton, "scaleY", 1.0f),
            ObjectAnimator.ofFloat(backButton, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(shareContainer, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleY", 1.0f));
    collapsed = false;
    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;
            //onClosed();
        }
    };
    animatorSet.setDuration(250);
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @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);
    }
    backDrawable.setRotation(0, true);
    animatorSet.start();
}

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

public void setPage(int page, boolean animated, Bundle params) {
    if (page == 3) {
        doneItem.setVisibility(View.GONE);
    }//from  w ww  .  ja  v  a  2s  . co  m
    final SlideView outView = views[currentViewNum];
    final SlideView newView = views[page];
    currentViewNum = page;

    newView.setParams(params, false);
    newView.onShow();

    if (animated) {
        newView.setTranslationX(AndroidUtilities.displaySize.x);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
        animatorSet.setDuration(300);
        animatorSet.playTogether(
                ObjectAnimator.ofFloat(outView, "translationX", -AndroidUtilities.displaySize.x),
                ObjectAnimator.ofFloat(newView, "translationX", 0));
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                newView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                outView.setVisibility(View.GONE);
                outView.setX(0);
            }
        });
        animatorSet.start();
    } else {
        newView.setTranslationX(0);
        newView.setVisibility(View.VISIBLE);
        if (outView != newView) {
            outView.setVisibility(View.GONE);
        }
    }
}

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

public void collapse() {
    if (parentActivity == null || !isVisible || checkAnimation()) {
        return;//  w ww .  j  a  v a2s.  com
    }
    if (fullscreenVideoContainer.getVisibility() == View.VISIBLE) {
        if (customView != null) {
            fullscreenVideoContainer.setVisibility(View.INVISIBLE);
            customViewCallback.onCustomViewHidden();
            fullscreenVideoContainer.removeView(customView);
            customView = null;
        } else if (fullscreenedVideo != null) {
            fullscreenedVideo.exitFullscreen();
        }
    }
    if (isPhotoVisible) {
        closePhoto(false);
    }
    try {
        if (visibleDialog != null) {
            visibleDialog.dismiss();
            visibleDialog = null;
        }
    } catch (Exception e) {
        FileLog.e(e);
    }

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(containerView, "translationX",
                    containerView.getMeasuredWidth() - AndroidUtilities.dp(56)),
            ObjectAnimator.ofFloat(containerView, "translationY",
                    ActionBar.getCurrentActionBarHeight()
                            + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)),
            ObjectAnimator.ofFloat(windowView, "alpha", 0.0f), ObjectAnimator.ofFloat(listView, "alpha", 0.0f),
            ObjectAnimator.ofFloat(listView, "translationY", -AndroidUtilities.dp(56)),
            ObjectAnimator.ofFloat(headerView, "translationY", 0),

            ObjectAnimator.ofFloat(backButton, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(backButton, "scaleY", 1.0f),
            ObjectAnimator.ofFloat(backButton, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleX", 1.0f),
            ObjectAnimator.ofFloat(shareContainer, "translationY", 0),
            ObjectAnimator.ofFloat(shareContainer, "scaleY", 1.0f));
    collapsed = true;
    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;

            //windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
            WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
            wm.updateViewLayout(windowView, windowLayoutParams);

            //onClosed();
            //containerView.setScaleX(1.0f);
            //containerView.setScaleY(1.0f);
        }
    };
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.setDuration(250);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @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);
    }
    backDrawable.setRotation(1, true);
    animatorSet.start();
}