Example usage for android.view View postOnAnimationDelayed

List of usage examples for android.view View postOnAnimationDelayed

Introduction

In this page you can find the example usage for android.view View postOnAnimationDelayed.

Prototype

public void postOnAnimationDelayed(Runnable action, long delayMillis) 

Source Link

Document

Causes the Runnable to execute on the next animation time step, after the specified amount of time elapses.

Usage

From source file:com.android.tv.settings.dialog.DialogFragment.java

private void runDelayedAnim(final Runnable runnable) {
    final View dialogView = getView();
    final View contentView = (View) dialogView.getTag(R.id.content_fragment);

    contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override//from  w  w  w  .j  a  va2  s. c  om
        public void onGlobalLayout() {
            contentView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            // if we buildLayer() at this time, the texture is
            // actually not created delay a little so we can make
            // sure all hardware layer is created before animation,
            // in that way we can avoid the jittering of start
            // animation
            contentView.postOnAnimationDelayed(runnable, ANIMATE_DELAY);
        }
    });

}

From source file:com.yekertech.tvbarsetting.dialog.SettingsLayoutFragment.java

private void performEntryTransition() {
    final View dialogView = getView();
    final View contentView = (View) dialogView.getTag(R.id.content_fragment);
    final View actionContainerView = dialogView.findViewById(R.id.action_fragment);

    mIntroAnimationInProgress = true;/*from   w w  w . j av a 2 s  . c o  m*/

    // Fade out the old activity.
    getActivity().overridePendingTransition(0, R.anim.lb_dialog_fade_out);

    int bgColor = contentView.getContext().getColor(R.color.lb_dialog_activity_background);
    final ColorDrawable bgDrawable = new ColorDrawable();
    bgDrawable.setColor(bgColor);
    bgDrawable.setAlpha(0);
    dialogView.setBackground(bgDrawable);
    dialogView.setVisibility(View.INVISIBLE);

    // We need to defer the remainder of the animation preparation until the first layout has
    // occurred, as we don't yet know the final location of the icon.
    contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            contentView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            // if we buildLayer() at this time, the texture is
            // actually not created delay a little so we can make
            // sure all hardware layer is created before animation,
            // in that way we can avoid the jittering of start
            // animation
            contentView.postOnAnimationDelayed(mEntryAnimationRunnable, mAnimateDelay);
        }

        final Runnable mEntryAnimationRunnable = new Runnable() {
            @Override
            public void run() {
                if (!isAdded()) {
                    // We have been detached before this could run, so just bail.
                    return;
                }

                dialogView.setVisibility(View.VISIBLE);

                // Fade in the activity background protection
                ObjectAnimator oa = ObjectAnimator.ofInt(bgDrawable, "alpha", 255);
                oa.setDuration(mAnimateInDuration);
                oa.setStartDelay(mSecondaryAnimateDelay);
                oa.setInterpolator(new DecelerateInterpolator(1.0f));
                oa.start();

                boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL;
                int startDist = isRtl ? mSlideInDistance : -mSlideInDistance;
                int endDist = isRtl ? -actionContainerView.getMeasuredWidth()
                        : actionContainerView.getMeasuredWidth();

                // Fade in and slide in the ContentFragment TextViews from the start.
                prepareAndAnimateView((View) contentView.getTag(R.id.title), startDist, false);
                prepareAndAnimateView((View) contentView.getTag(R.id.breadcrumb), startDist, false);
                prepareAndAnimateView((View) contentView.getTag(R.id.description), startDist, false);

                // Fade in and slide in the ActionFragment from the end.
                prepareAndAnimateView(actionContainerView, endDist, false);
                prepareAndAnimateView((View) contentView.getTag(R.id.icon), startDist, true);
            }
        };
    });
}

From source file:com.android.tv.settings.dialog.SettingsLayoutFragment.java

private void performEntryTransition() {
    final View dialogView = getView();
    final View contentView = (View) dialogView.getTag(R.id.content_fragment);
    final View actionContainerView = dialogView.findViewById(R.id.action_fragment);

    mIntroAnimationInProgress = true;//from  w  ww  .j  a v a  2  s . c  om

    // Fade out the old activity.
    getActivity().overridePendingTransition(0, R.anim.lb_dialog_fade_out);

    int bgColor = contentView.getContext().getResources().getColor(R.color.lb_dialog_activity_background);
    final ColorDrawable bgDrawable = new ColorDrawable();
    bgDrawable.setColor(bgColor);
    bgDrawable.setAlpha(0);
    dialogView.setBackground(bgDrawable);
    dialogView.setVisibility(View.INVISIBLE);

    // We need to defer the remainder of the animation preparation until the first layout has
    // occurred, as we don't yet know the final location of the icon.
    contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            contentView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            // if we buildLayer() at this time, the texture is
            // actually not created delay a little so we can make
            // sure all hardware layer is created before animation,
            // in that way we can avoid the jittering of start
            // animation
            contentView.postOnAnimationDelayed(mEntryAnimationRunnable, mAnimateDelay);
        }

        Runnable mEntryAnimationRunnable = new Runnable() {
            @Override
            public void run() {
                if (!isAdded()) {
                    // We have been detached before this could run, so just bail.
                    return;
                }

                dialogView.setVisibility(View.VISIBLE);

                // Fade in the activity background protection
                ObjectAnimator oa = ObjectAnimator.ofInt(bgDrawable, "alpha", 255);
                oa.setDuration(mAnimateInDuration);
                oa.setStartDelay(mSecondaryAnimateDelay);
                oa.setInterpolator(new DecelerateInterpolator(1.0f));
                oa.start();

                boolean isRtl = ViewCompat.getLayoutDirection(contentView) == View.LAYOUT_DIRECTION_RTL;
                int startDist = isRtl ? mSlideInDistance : -mSlideInDistance;
                int endDist = isRtl ? -actionContainerView.getMeasuredWidth()
                        : actionContainerView.getMeasuredWidth();

                // Fade in and slide in the ContentFragment TextViews from the start.
                prepareAndAnimateView((View) contentView.getTag(R.id.title), startDist, false);
                prepareAndAnimateView((View) contentView.getTag(R.id.breadcrumb), startDist, false);
                prepareAndAnimateView((View) contentView.getTag(R.id.description), startDist, false);

                // Fade in and slide in the ActionFragment from the end.
                prepareAndAnimateView(actionContainerView, endDist, false);
                prepareAndAnimateView((View) contentView.getTag(R.id.icon), startDist, true);
            }
        };
    });
}