List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter
AnimatorListenerAdapter
From source file:com.example.android.saddacampus.MainActivity.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void circleReveal(int viewID, int posFromRight, boolean containsOverflow, final boolean isShow) { final View myView = findViewById(viewID); int width = myView.getWidth(); if (posFromRight > 0) width -= (posFromRight/*from w w w.j a v a2 s . c o m*/ * getResources().getDimensionPixelSize(R.dimen.abc_action_button_min_width_material)) - (getResources().getDimensionPixelSize(R.dimen.abc_action_button_min_width_material) / 2); if (containsOverflow) width -= getResources().getDimensionPixelSize(R.dimen.abc_action_button_min_width_overflow_material); int cx = width; int cy = myView.getHeight() / 2; Animator anim; if (isShow) anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, (float) width); else anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, (float) width, 0); anim.setDuration((long) 220); // make the view invisible when the animation is done anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (!isShow) { super.onAnimationEnd(animation); myView.setVisibility(View.INVISIBLE); } } }); // make the view visible and start the animation if (isShow) myView.setVisibility(View.VISIBLE); // start the animation anim.start(); }
From source file:com.amitupadhyay.aboutexample.ui.widget.BottomSheet.java
private void animateSettle(int initialOffset, final int targetOffset, float initialVelocity) { if (settling) return;//from w w w . java2 s . c o m if (sheetOffsetHelper.getTopAndBottomOffset() == targetOffset) { if (targetOffset >= dismissOffset) { dispatchDismissCallback(); } return; } settling = true; final boolean dismissing = targetOffset == dismissOffset; final long duration = computeSettleDuration(initialVelocity, dismissing); final ObjectAnimator settleAnim = ObjectAnimator.ofInt(sheetOffsetHelper, ViewOffsetHelper.OFFSET_Y, initialOffset, targetOffset); settleAnim.setDuration(duration); settleAnim.setInterpolator(getSettleInterpolator(dismissing, initialVelocity)); settleAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { dispatchPositionChangedCallback(); if (dismissing) { dispatchDismissCallback(); } settling = false; } }); if (callbacks != null && !callbacks.isEmpty()) { settleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (animation.getAnimatedFraction() > 0f) { dispatchPositionChangedCallback(); } } }); } settleAnim.start(); }
From source file:com.druk.servicebrowser.ui.fragment.ServiceBrowserFragment.java
protected void showError(final Throwable e) { getActivity().runOnUiThread(new Runnable() { @Override/* w w w .jav a 2 s .c om*/ public void run() { mRecyclerView.animate().alpha(0.0f).setInterpolator(new AccelerateDecelerateInterpolator()) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mRecyclerView.setVisibility(View.GONE); } }).start(); mProgressView.animate().alpha(0.0f).setInterpolator(new AccelerateDecelerateInterpolator()) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mProgressView.setVisibility(View.GONE); } }).start(); mErrorView.setAlpha(0.0f); mErrorView.setVisibility(View.VISIBLE); mErrorView.animate().alpha(1.0f).setInterpolator(new AccelerateDecelerateInterpolator()).start(); mErrorView.findViewById(R.id.send_report).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e); } }); } }); }
From source file:com.linroid.pushapp.ui.send.SendActivity.java
private void switchFabIcon(final int drawableResId) { final long duration = getResources().getInteger(android.R.integer.config_shortAnimTime); fab.animate().scaleX(0f).scaleY(0f).setDuration(duration).setListener(new AnimatorListenerAdapter() { @Override/* w w w . ja va2 s . c o m*/ public void onAnimationEnd(Animator animation) { fab.setImageDrawable(getResources().getDrawable(drawableResId)); fab.animate().scaleX(1.f).scaleY(1.f).setDuration(duration) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { fab.setScaleX(1.f); fab.setScaleY(1.f); } }).start(); } }).start(); }
From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissTouchListener.java
private void performDismiss() { // Animate the dismissed view to zero-height and then fire the dismiss // callback./*from www.j a v a 2 s. c o m*/ // This triggers layout on each animation frame; in the future we may // want to do something // smarter and more performant. final ViewGroup.LayoutParams lp = mView.getLayoutParams(); final int originalHeight = mView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCallback.onDismiss(mView, mToken); // Reset view presentation setAlpha(mView, 1f); setTranslationX(mView, 0); lp.height = originalHeight; mView.setLayoutParams(lp); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); mView.setLayoutParams(lp); } }); animator.start(); }
From source file:com.achep.acdisplay.acdisplay.AcDisplayActivity.java
/** * Smoothly sets the background.// w ww. j a v a2s . c om */ private void dispatchSetBackground(Bitmap bitmap) { if (bitmap == null) { if (mCustomBackgroundShown) { mBackgroundView.animate().cancel(); mBackgroundView.animate().alpha(0f).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mBackgroundView.setImageBitmap(null); mBackgroundView.setVisibility(View.GONE); } }); } mCustomBackgroundShown = false; return; } // TODO: Crossfade background change animation would be really nice. float alphaStart = mBackgroundView.getVisibility() == View.GONE ? 0f : 0.4f; mCustomBackgroundShown = true; mBackgroundView.setAlpha(alphaStart); mBackgroundView.setImageBitmap(bitmap); mBackgroundView.setVisibility(View.VISIBLE); mBackgroundView.animate().cancel(); mBackgroundView.animate().alpha(1f).setListener(null); }
From source file:com.alexandrepiveteau.library.tutorial.TutorialActivity.java
private void animateViewScaleIn(final View view) { view.animate().scaleX(1).scaleY(1)// w w w .j a va 2 s . c om .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime)) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); view.setVisibility(View.VISIBLE); } }).start(); }
From source file:com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void animateRemoveImpl(final RecyclerView.ViewHolder holder) { final View view = holder.itemView; // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mRemoveAnimations.add(holder);/*w ww . j av a 2 s . c o m*/ // get the center for the clipping circle int cx = (view.getLeft() + view.getRight()) / 2; int cy = view.getHeight() / 2; // get the initial radius for the clipping circle int initialRadius = view.getWidth(); // create the animation (the final radius is zero) final Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0); anim.setDuration(getRemoveDuration()); // make the view invisible when the animation is done anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { dispatchAddStarting(holder); } @Override public void onAnimationEnd(Animator animation) { anim.removeListener(this); view.setVisibility(View.VISIBLE); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }); // start the animation anim.start(); // animation.setDuration(getRemoveDuration()) // .alpha(0).setListener(new CircularRevealItemAnimator.VpaListenerAdapter() { // @Override // public void onAnimationStart(View view) { // dispatchRemoveStarting(holder); // } // // @Override // public void onAnimationEnd(View view) { // animation.setListener(null); // ViewCompat.setAlpha(view, 1); // dispatchRemoveFinished(holder); // mRemoveAnimations.remove(holder); // dispatchFinishedWhenDone(); // } // }).start(); }
From source file:com.lovejjfg.blogdemo.ui.BottomSheet.java
private void animateSettle(int initialOffset, final int targetOffset, long duration) { if (settling) return;/*from ww w . j a v a 2 s .c o m*/ if (sheetOffsetHelper.getTopAndBottomOffset() == targetOffset) return; settling = true; final ObjectAnimator settleAnim = ObjectAnimator.ofInt(sheetOffsetHelper, ViewOffsetHelper.OFFSET_Y, initialOffset, targetOffset); settleAnim.setDuration(duration); settleAnim.setInterpolator(AnimUtils.getFastOutSlowInInterpolator(getContext())); settleAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { dispatchPositionChangedCallback(); if (targetOffset == dismissOffset) { dispatchDismissCallback(); } settling = false; } }); if (callbacks != null && !callbacks.isEmpty()) { settleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (animation.getAnimatedFraction() > 0f) { dispatchPositionChangedCallback(); } } }); } settleAnim.start(); }
From source file:ccv.checkhelzio.nuevaagendacucsh.transitions.FabTransition.java
@Override public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues, final TransitionValues endValues) { if (startValues == null || endValues == null) return null; final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS); final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS); final boolean fromFab = endBounds.width() > startBounds.width(); final View view = endValues.view; final Rect dialogBounds = fromFab ? endBounds : startBounds; final Rect fabBounds = fromFab ? startBounds : endBounds; final Interpolator fastOutSlowInInterpolator = AnimUtils .getFastOutSlowInInterpolator(sceneRoot.getContext()); final long duration = getDuration(); final long halfDuration = duration / 2; final long twoThirdsDuration = duration * 2 / 3; if (!fromFab) { // Force measure / layout the dialog back to it's original bounds view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY), makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY)); view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom); }// w w w . j a v a2 s .com final int translationX = startBounds.centerX() - endBounds.centerX(); final int translationY = startBounds.centerY() - endBounds.centerY(); if (fromFab) { view.setTranslationX(translationX); view.setTranslationY(translationY); } // Add a color overlay to fake appearance of the FAB final ColorDrawable fabColor = new ColorDrawable(color); fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height()); if (!fromFab) fabColor.setAlpha(0); view.getOverlay().add(fabColor); // Add an icon overlay again to fake the appearance of the FAB final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate(); final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2; final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2; fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(), iconTop + fabIcon.getIntrinsicHeight()); if (!fromFab) fabIcon.setAlpha(0); view.getOverlay().add(fabIcon); // Circular clip from/to the FAB size final Animator circularReveal; if (fromFab) { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, startBounds.width() / 2, (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2)); circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator(sceneRoot.getContext())); //circularReveal.setInterpolator(new AnimationUtils().loadInterpolator(sceneRoot.getContext(), android.R.interpolator.fast_out_slow_in)); } else { circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2, view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2), endBounds.width() / 2); circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator(sceneRoot.getContext())); // Persist the end clip i.e. stay at FAB size after the reveal has run circularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { final int left = (view.getWidth() - fabBounds.width()) / 2; final int top = (view.getHeight() - fabBounds.height()) / 2; outline.setOval(left, top, left + fabBounds.width(), top + fabBounds.height()); view.setClipToOutline(true); } }); } }); } circularReveal.setDuration(duration); // Translate to end position along an arc final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y, fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0) : getPathMotion().getPath(0, 0, -translationX, -translationY)); translate.setDuration(duration); translate.setInterpolator(fastOutSlowInInterpolator); // Fade contents of non-FAB view in/out List<Animator> fadeContents = null; if (view instanceof ViewGroup) { final ViewGroup vg = ((ViewGroup) view); fadeContents = new ArrayList<>(vg.getChildCount()); for (int i = vg.getChildCount() - 1; i >= 0; i--) { final View child = vg.getChildAt(i); final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f); if (fromFab) { child.setAlpha(0f); } fade.setDuration(twoThirdsDuration); fade.setInterpolator(fastOutSlowInInterpolator); fadeContents.add(fade); } } // Fade in/out the fab color & icon overlays final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255); final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255); if (!fromFab) { colorFade.setStartDelay(halfDuration); iconFade.setStartDelay(halfDuration); } colorFade.setDuration(halfDuration); iconFade.setDuration(halfDuration); colorFade.setInterpolator(fastOutSlowInInterpolator); iconFade.setInterpolator(fastOutSlowInInterpolator); // Work around issue with elevation shadows. At the end of the return transition the shared // element's shadow is drawn twice (by each activity) which is jarring. This workaround // still causes the shadow to snap, but it's better than seeing it double drawn. Animator elevation = null; if (!fromFab) { elevation = ObjectAnimator.ofFloat(view, View.TRANSLATION_Z, -view.getElevation()); elevation.setDuration(duration); elevation.setInterpolator(fastOutSlowInInterpolator); } // Run all animations together final AnimatorSet transition = new AnimatorSet(); transition.playTogether(circularReveal, translate, colorFade, iconFade); transition.playTogether(fadeContents); if (elevation != null) transition.play(elevation); if (fromFab) { transition.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // Clean up view.getOverlay().clear(); } }); } return new AnimUtils.NoPauseAnimator(transition); }