Example usage for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

Introduction

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

Prototype

AnimatorListenerAdapter

Source Link

Usage

From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java

/**
 * Animates a view.// w w w  .  jav  a 2 s  .  c  o  m
 *
 * @param v              view to animate
 * @param initAlpha      initial alpha
 * @param initTransX     initial translation in the X
 * @param delay          delay in ms
 * @param duration       duration in ms
 * @param interpolator   interpolator to be used, can be null
 * @param isIcon         if {@code true}, this is the main icon being moved
 */
public void prepareAndAnimateView(final View v, float initAlpha, float initTransX, int delay, int duration,
        Interpolator interpolator, final boolean isIcon) {
    if (v != null && v.getWindowToken() != null) {
        v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
        v.buildLayer();
        v.setAlpha(initAlpha);
        v.setTranslationX(initTransX);
        v.animate().alpha(1f).translationX(0).setDuration(duration).setStartDelay(delay);
        if (interpolator != null) {
            v.animate().setInterpolator(interpolator);
        }
        v.animate().setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                v.setLayerType(View.LAYER_TYPE_NONE, null);
                if (isIcon) {
                    if (mShadowLayer != null) {
                        mShadowLayer.setShadowsAlpha(1f);
                    }
                    onIntroAnimationFinished();
                }
            }
        });
        v.animate().start();
    }
}

From source file:com.brandon.mailbox.RecyclerSwipeListener.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalLayoutParamsHeight = lp.height;
    final int originalHeight = dismissView.getHeight();
    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override//  w  w  w.  ja  v  a2  s . com
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);
                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                if (mFinalDelta < 0) {
                    mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions);
                } else {
                    mSwipeListener.onDismissedBySwipeRight(mRecyclerView, dismissPositions);
                }
                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;
                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(mAlpha);
                    pendingDismiss.view.setTranslationX(0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalLayoutParamsHeight;
                    pendingDismiss.view.setLayoutParams(lp);
                }
                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);
                mPendingDismisses.clear();
                mAnimatingPosition = ListView.INVALID_POSITION;
            }
        }
    });
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });
    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:com.igniva.filemanager.utils.Futils.java

public void revealShow(final View view, boolean reveal) {

    if (reveal) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override//from   w  w w  . j a  va2  s . c o m
            public void onAnimationStart(Animator animation) {
                view.setVisibility(View.VISIBLE);
            }
        });
        animator.start();
    } else {

        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }
        });
        animator.start();

    }

}

From source file:com.google.samples.apps.topeka.activity.QuizActivity.java

@NonNull
private QuizFragment.SolvedStateListener getSolvedStateListener() {
    return new QuizFragment.SolvedStateListener() {
        @Override/* w  w w.j  a v  a2 s .  c o m*/
        public void onCategorySolved() {
            setResultSolved();
            setToolbarElevation(true);
            displayDoneFab();
        }

        private void displayDoneFab() {
            /* We're re-using the already existing fab and give it some
             * new values. This has to run delayed due to the queued animation
             * to hide the fab initially.
             */
            if (null != mCircularReveal && mCircularReveal.isRunning()) {
                mCircularReveal.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        showQuizFabWithDoneIcon();
                        mCircularReveal.removeListener(this);
                    }
                });
            } else {
                showQuizFabWithDoneIcon();
            }
        }

        private void showQuizFabWithDoneIcon() {
            mQuizFab.setImageResource(R.drawable.ic_tick);
            mQuizFab.setId(R.id.quiz_done);
            mQuizFab.setVisibility(View.VISIBLE);
            mQuizFab.setScaleX(0f);
            mQuizFab.setScaleY(0f);
            ViewCompat.animate(mQuizFab).scaleX(1).scaleY(1).setInterpolator(mInterpolator).setListener(null)
                    .start();
        }
    };
}

From source file:br.com.halph.agendafeliz.util.SwipeableRecyclerViewTouchListener.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalLayoutParamsHeight = lp.height;
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override/*from w  w  w . j av  a2s . c  om*/
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }

                if (mFinalDelta < 0) {
                    mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions);
                } else {
                    mSwipeListener.onDismissedBySwipeRight(mRecyclerView, dismissPositions);
                }

                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(mAlpha);
                    pendingDismiss.view.setTranslationX(0);

                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalLayoutParamsHeight;

                    pendingDismiss.view.setLayoutParams(lp);
                }

                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);

                mPendingDismisses.clear();
                mAnimatingPosition = ListView.INVALID_POSITION;
            }
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:com.sefford.beauthentic.activities.LoginActivity.java

/**
 * Shows the progress UI and hides the login form.
 *//*w  ww .java2s .c o  m*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
void showProgress(final boolean show) {
    if (vLoginForm == null) {
        return;
    }
    // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
    // for very easy animations. If available, use these APIs to fade-in
    // the progress spinner.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);

        vLoginForm.setVisibility(show ? View.GONE : View.VISIBLE);
        vLoginForm.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (vLoginForm != null) {
                            vLoginForm.setVisibility(show ? View.GONE : View.VISIBLE);
                        }
                    }
                });

        pbProgress.setVisibility(show ? View.VISIBLE : View.GONE);
        pbProgress.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (vLoginForm != null) {
                            pbProgress.setVisibility(show ? View.VISIBLE : View.GONE);
                        }
                    }
                });
    } else {
        if (vLoginForm != null) {
            // The ViewPropertyAnimator APIs are not available, so simply show
            // and hide the relevant UI components.
            pbProgress.setVisibility(show ? View.VISIBLE : View.GONE);
            vLoginForm.setVisibility(show ? View.GONE : View.VISIBLE);
        }
    }
}

From source file:com.ayuget.redface.ui.fragment.PostsFragment.java

private void moveReplyButton(final float toTranslationY) {
    if (replyButton.getTranslationY() == toTranslationY) {
        return;// ww  w .  ja va2s.  c  om
    }
    if (!animationInProgress) {
        replyButtonAnimator = ValueAnimator.ofFloat(replyButton.getTranslationY(), toTranslationY)
                .setDuration(200);

        replyButtonAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float translationY = (float) animation.getAnimatedValue();
                replyButton.setTranslationY(translationY);
            }
        });
        replyButtonAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                animationInProgress = true;
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                animationInProgress = false;
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                animationInProgress = false;
            }
        });

        replyButtonAnimator.start();
    }
}

From source file:com.smp.musicspeed.MainActivity.java

private void animateLinkOff() {
    linkOff();/*from  w  ww  . j  ava 2s  .c  o  m*/
    tempoCard.setVisibility(View.INVISIBLE);

    TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            1.0f);
    anim.setDuration(TRANS_ANIMATION_TIME);
    anim.setInterpolator(new AnticipateOvershootInterpolator());
    anim.setAnimationListener(new AnimationListenerAdaptor() {
        @Override
        public void onAnimationEnd(Animation animation) {
            tempoText.setAlpha(0f);
            linkOff();

            tempoText.animate().alpha(1f).setDuration(TEXT_ANIMATION_TIME)
                    .setListener(new AnimatorListenerAdapter() {
                    });
        }
    });
    rateCard.startAnimation(anim);
    rateText.animate().alpha(0f).setDuration(TRANS_ANIMATION_TIME).setListener(new AnimatorListenerAdapter() {
    });
}

From source file:com.android.leanlauncher.CellLayout.java

public CellLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mDragEnforcer = new DropTarget.DragEnforcer(context);

    // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
    // the user where a dragged item will land when dropped.
    setWillNotDraw(false);// ww  w. java 2s .  c o  m
    setClipToPadding(false);
    mLauncher = (Launcher) context;

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);

    mCellWidth = mCellHeight = -1;
    mFixedCellWidth = mFixedCellHeight = -1;
    mWidthGap = mOriginalWidthGap = 0;
    mHeightGap = mOriginalHeightGap = 0;
    mMaxGap = Integer.MAX_VALUE;
    mCountX = (int) grid.numColumns;
    mCountY = (int) grid.numRows;
    mOccupied = new boolean[mCountX][mCountY];
    mTmpOccupied = new boolean[mCountX][mCountY];
    mPreviousReorderDirection[0] = INVALID_DIRECTION;
    mPreviousReorderDirection[1] = INVALID_DIRECTION;

    a.recycle();

    setAlwaysDrawnWithCacheEnabled(false);

    final Resources res = getResources();

    mNormalBackground = res.getDrawable(R.drawable.screenpanel);
    mActiveGlowBackground = res.getDrawable(R.drawable.screenpanel_hover);

    mOverScrollLeft = res.getDrawable(R.drawable.overscroll_glow_left);
    mOverScrollRight = res.getDrawable(R.drawable.overscroll_glow_right);
    mForegroundPadding = res.getDimensionPixelSize(R.dimen.workspace_overscroll_drawable_padding);

    mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx);

    mNormalBackground.setFilterBitmap(true);
    mActiveGlowBackground.setFilterBitmap(true);

    // Initialize the data structures used for the drag visualization.
    TimeInterpolator easeOutInterpolator = new DecelerateInterpolator(2.5f);
    mDragCell[0] = mDragCell[1] = -1;
    for (int i = 0; i < mDragOutlines.length; i++) {
        mDragOutlines[i] = new Rect(-1, -1, -1, -1);
    }

    // When dragging things around the home screens, we show a green outline of
    // where the item will land. The outlines gradually fade out, leaving a trail
    // behind the drag path.
    // Set up all the animations that are used to implement this fading.
    final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
    final float fromAlphaValue = 0;
    final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha);

    Arrays.fill(mDragOutlineAlphas, fromAlphaValue);

    for (int i = 0; i < mDragOutlineAnims.length; i++) {
        final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue,
                toAlphaValue);
        anim.getAnimator().setInterpolator(easeOutInterpolator);
        final int thisIndex = i;
        anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                final Bitmap outline = (Bitmap) anim.getTag();

                // If an animation is started and then stopped very quickly, we can still
                // get spurious updates we've cleared the tag. Guard against this.
                if (outline == null) {
                    @SuppressWarnings("all") // suppress dead code warning
                    final boolean debug = false;
                    if (debug) {
                        Object val = animation.getAnimatedValue();
                        Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped());
                    }
                    // Try to prevent it from continuing to run
                    animation.cancel();
                } else {
                    mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
                    CellLayout.this.invalidate(mDragOutlines[thisIndex]);
                }
            }
        });
        // The animation holds a reference to the drag outline bitmap as long is it's
        // running. This way the bitmap can be GCed when the animations are complete.
        anim.getAnimator().addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
                    anim.setTag(null);
                }
            }
        });
        mDragOutlineAnims[i] = anim;
    }

    mBackgroundRect = new Rect();
    mForegroundRect = new Rect();

    mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context);
    mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY);

    mTouchFeedbackView = new FastBitmapView(context);
    // Make the feedback view large enough to hold the blur bitmap.
    addView(mTouchFeedbackView, (int) (grid.cellWidthPx * 1.2), (int) (grid.cellHeightPx * 1.2));
    addView(mShortcutsAndWidgets);
}

From source file:com.shalzz.attendance.fragment.AttendanceListFragment.java

@Override
public void onItemExpanded(final View view) {
    final int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    final ExpandableListAdapter.GenericViewHolder viewHolder = (ExpandableListAdapter.GenericViewHolder) view
            .getTag();//  www .  ja v a2  s. c  o  m
    final RelativeLayout childView = viewHolder.childView;
    childView.measure(spec, spec);
    final int startingHeight = view.getHeight();
    final ViewTreeObserver observer = mRecyclerView.getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // We don'mTracker want to continue getting called for every draw.
            if (observer.isAlive()) {
                observer.removeOnPreDrawListener(this);
            }
            // Calculate some values to help with the animation.
            final int endingHeight = view.getHeight();
            final int distance = Math.abs(endingHeight - startingHeight);
            final int baseHeight = Math.min(endingHeight, startingHeight);
            final boolean isExpanded = endingHeight > startingHeight;

            // Set the views back to the start state of the animation
            view.getLayoutParams().height = startingHeight;
            if (!isExpanded) {
                viewHolder.childView.setVisibility(View.VISIBLE);
            }

            // Set up the fade effect for the action buttons.
            if (isExpanded) {
                // Start the fade in after the expansion has partly completed, otherwise it
                // will be mostly over before the expansion completes.
                viewHolder.childView.setAlpha(0f);
                viewHolder.childView.animate().alpha(1f).setStartDelay(mFadeInStartDelay)
                        .setDuration(mFadeInDuration).start();
            } else {
                viewHolder.childView.setAlpha(1f);
                viewHolder.childView.animate().alpha(0f).setDuration(mFadeOutDuration).start();
            }
            view.requestLayout();

            // Set up the animator to animate the expansion and shadow depth.
            ValueAnimator animator = isExpanded ? ValueAnimator.ofFloat(0f, 1f) : ValueAnimator.ofFloat(1f, 0f);

            // scroll to make the view fully visible.
            mRecyclerView.smoothScrollToPosition(viewHolder.position);

            animator.addUpdateListener(animator1 -> {
                Float value = (Float) animator1.getAnimatedValue();

                // For each value from 0 to 1, animate the various parts of the layout.
                view.getLayoutParams().height = (int) (value * distance + baseHeight);
                float z = mExpandedItemTranslationZ * value;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    view.setTranslationZ(z);
                }
                view.requestLayout();
            });

            // Set everything to their final values when the animation's done.
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;

                    if (!isExpanded) {
                        viewHolder.childView.setVisibility(View.GONE);
                    } else {
                        // This seems like it should be unnecessary, but without this, after
                        // navigating out of the activity and then back, the action view alpha
                        // is defaulting to the value (0) at the start of the expand animation.
                        viewHolder.childView.setAlpha(1);
                    }
                }
            });

            animator.setDuration(mExpandCollapseDuration);
            animator.start();

            // Return false so this draw does not occur to prevent the final frame from
            // being drawn for the single frame before the animations start.
            return false;
        }
    });
}