List of usage examples for android.animation ValueAnimator start
@Override public void start()
From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissListViewTouchListener.java
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 originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override/*from w w w . j a v a 2 s .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; } mCallback.onDismiss(mListView, dismissPositions); ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation setAlpha(pendingDismiss.view, 1f); setTranslationX(pendingDismiss.view, 0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalHeight; pendingDismiss.view.setLayoutParams(lp); } mPendingDismisses.clear(); } } }); 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.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java
void animateViewIn() { if (Build.VERSION.SDK_INT >= 12) { //TODO CHANGE ? final int viewHeight = -mView.getHeight(); if (USE_OFFSET_API) { ViewCompat.offsetTopAndBottom(mView, viewHeight); } else {/*from ww w. java 2s. c o m*/ mView.setTranslationY(viewHeight); } final ValueAnimator animator = new ValueAnimator(); animator.setIntValues(viewHeight, 0); animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); animator.setDuration(ANIMATION_DURATION); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animator) { mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION, ANIMATION_FADE_DURATION); } @Override public void onAnimationEnd(Animator animator) { onViewShown(); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { private int mPreviousAnimatedIntValue = viewHeight; @Override public void onAnimationUpdate(ValueAnimator animator) { int currentAnimatedIntValue = (int) animator.getAnimatedValue(); if (USE_OFFSET_API) { ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue); } else { mView.setTranslationY(currentAnimatedIntValue); } mPreviousAnimatedIntValue = currentAnimatedIntValue; } }); animator.start(); } else { final Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_in); anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); anim.setDuration(ANIMATION_DURATION); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationEnd(Animation animation) { onViewShown(); } @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); mView.startAnimation(anim); } }
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();/*ww w. j a 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; } }); }
From source file:com.jinzht.pro.swipelistview.SwipeListViewTouchListener.java
/** * Perform dismiss action/* ww w .j av a 2 s. c o m*/ * * @param dismissView View * @param dismissPosition Position of list */ protected void performDismiss(final View dismissView, final int dismissPosition, boolean doPendingDismiss) { enableDisableViewGroup((ViewGroup) dismissView, false); final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(animationTime); if (doPendingDismiss) { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { --dismissAnimationRefCount; if (dismissAnimationRefCount == 0) { removePendingDismisses(originalHeight); } } }); } animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { enableDisableViewGroup((ViewGroup) dismissView, true); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); pendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
From source file:io.authme.sdk.widget.LockPatternView.java
private void startLineEndAnimation(final CellState state, final float startX, final float startY, final float targetX, final float targetY) { /*/* w w w. ja va 2 s . c o m*/ * Currently this animation looks unclear, we don't really need it... */ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) return; ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float t = (Float) animation.getAnimatedValue(); state.lineEndX = (1 - t) * startX + t * targetX; state.lineEndY = (1 - t) * startY + t * targetY; invalidate(); } }); valueAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { state.lineAnimator = null; } }); valueAnimator.setInterpolator(mFastOutSlowInInterpolator); valueAnimator.setDuration(100); valueAnimator.start(); state.lineAnimator = valueAnimator; }
From source file:com.android.nobug.view.pattern.PatternView.java
private void startLineEndAnimation(final CellState state, final float startX, final float startY, final float targetX, final float targetY) { ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//www . j ava 2 s . c om public void onAnimationUpdate(ValueAnimator animation) { float t = (float) animation.getAnimatedValue(); state.lineEndX = (1 - t) * startX + t * targetX; state.lineEndY = (1 - t) * startY + t * targetY; invalidate(); } }); valueAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { state.lineAnimator = null; } }); valueAnimator.setInterpolator(mFastOutSlowInInterpolator); valueAnimator.setDuration(100); valueAnimator.start(); state.lineAnimator = valueAnimator; }
From source file:edu.uark.spARK.SwipeDismissListViewTouchListener.java
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 originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override/*from ww w . ja v a 2 s .c o m*/ 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; } mCallbacks.onDismiss(mListView, dismissPositions); ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : mPendingDismisses) { // Reset view presentation pendingDismiss.view.setAlpha(1f); pendingDismiss.view.setTranslationX(0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalHeight; pendingDismiss.view.setLayoutParams(lp); } mPendingDismisses.clear(); } } }); 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:cw.kop.autobackground.sources.SourceListFragment.java
private void startEditFragment(final View view, final int position) { sourceList.setOnItemClickListener(null); sourceList.setEnabled(false);//from w ww . j av a2 s . com listAdapter.saveData(); Source dataItem = listAdapter.getItem(position); final SourceInfoFragment sourceInfoFragment = new SourceInfoFragment(); sourceInfoFragment.setImageDrawable(((ImageView) view.findViewById(R.id.source_image)).getDrawable()); Bundle arguments = new Bundle(); arguments.putInt("position", position); arguments.putString("type", dataItem.getType()); arguments.putString("title", dataItem.getTitle()); arguments.putString("data", dataItem.getData()); arguments.putInt("num", dataItem.getNum()); arguments.putBoolean("use", dataItem.isUse()); arguments.putBoolean("preview", dataItem.isPreview()); String imageFileName = dataItem.getImageFile().getAbsolutePath(); if (imageFileName != null && imageFileName.length() > 0) { arguments.putString("image", imageFileName); } else { arguments.putString("image", ""); } arguments.putBoolean("use_time", dataItem.isUseTime()); arguments.putString("time", dataItem.getTime()); sourceInfoFragment.setArguments(arguments); final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container); final CardView sourceCard = (CardView) view.findViewById(R.id.source_card); final View imageOverlay = view.findViewById(R.id.source_image_overlay); final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title); final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button); final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button); final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button); final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container); final float cardStartShadow = sourceCard.getPaddingLeft(); final float viewStartHeight = sourceContainer.getHeight(); final float viewStartY = view.getY(); final int viewStartPadding = view.getPaddingLeft(); final float textStartX = sourceTitle.getX(); final float textStartY = sourceTitle.getY(); final float textTranslationY = sourceTitle.getHeight(); /*+ TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());*/ Animation animation = new Animation() { private boolean needsFragment = true; @Override protected void applyTransformation(float interpolatedTime, Transformation t) { if (needsFragment && interpolatedTime >= 1) { needsFragment = false; getFragmentManager().beginTransaction() .add(R.id.content_frame, sourceInfoFragment, "source_info_fragment") .addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_NONE).commit(); } int newPadding = Math.round(viewStartPadding * (1 - interpolatedTime)); int newShadowPadding = (int) (cardStartShadow * (1.0f - interpolatedTime)); sourceCard.setShadowPadding(newShadowPadding, 0, newShadowPadding, 0); ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).topMargin = newShadowPadding; ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).bottomMargin = newShadowPadding; ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).leftMargin = newShadowPadding; ((LinearLayout.LayoutParams) sourceCard.getLayoutParams()).rightMargin = newShadowPadding; view.setPadding(newPadding, 0, newPadding, 0); view.setY(viewStartY - interpolatedTime * viewStartY); ViewGroup.LayoutParams params = sourceContainer.getLayoutParams(); params.height = (int) (viewStartHeight + (screenHeight - viewStartHeight) * interpolatedTime); sourceContainer.setLayoutParams(params); sourceTitle.setY(textStartY + interpolatedTime * textTranslationY); sourceTitle.setX(textStartX + viewStartPadding - newPadding); deleteButton.setAlpha(1.0f - interpolatedTime); viewButton.setAlpha(1.0f - interpolatedTime); editButton.setAlpha(1.0f - interpolatedTime); sourceExpandContainer.setAlpha(1.0f - interpolatedTime); } @Override public boolean willChangeBounds() { return true; } }; animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (needsListReset) { Parcelable state = sourceList.onSaveInstanceState(); sourceList.setAdapter(null); sourceList.setAdapter(listAdapter); sourceList.onRestoreInstanceState(state); sourceList.setOnItemClickListener(SourceListFragment.this); sourceList.setEnabled(true); needsListReset = false; } } @Override public void onAnimationRepeat(Animation animation) { } }); ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), AppSettings.getDialogColor(appContext), getResources().getColor(AppSettings.getBackgroundColorResource())); cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue()); } }); ValueAnimator titleColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), sourceTitle.getCurrentTextColor(), getResources().getColor(R.color.BLUE_OPAQUE)); titleColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { sourceTitle.setTextColor((Integer) animation.getAnimatedValue()); } }); ValueAnimator titleShadowAlphaAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), AppSettings.getColorFilterInt(appContext), getResources().getColor(android.R.color.transparent)); titleShadowAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { sourceTitle.setShadowLayer(4, 0, 0, (Integer) animation.getAnimatedValue()); } }); ValueAnimator imageOverlayAlphaAnimation = ValueAnimator.ofFloat(imageOverlay.getAlpha(), 0f); imageOverlayAlphaAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { imageOverlay.setAlpha((Float) animation.getAnimatedValue()); } }); int transitionTime = INFO_ANIMATION_TIME; DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f); animation.setDuration(transitionTime); cardColorAnimation.setDuration(transitionTime); titleColorAnimation.setDuration(transitionTime); titleShadowAlphaAnimation.setDuration(transitionTime); animation.setInterpolator(decelerateInterpolator); cardColorAnimation.setInterpolator(decelerateInterpolator); titleColorAnimation.setInterpolator(decelerateInterpolator); titleShadowAlphaAnimation.setInterpolator(decelerateInterpolator); if (imageOverlay.getAlpha() > 0) { imageOverlayAlphaAnimation.start(); } handler.postDelayed(new Runnable() { @Override public void run() { if (needsListReset) { Parcelable state = sourceList.onSaveInstanceState(); sourceList.setAdapter(null); sourceList.setAdapter(listAdapter); sourceList.onRestoreInstanceState(state); sourceList.setOnItemClickListener(SourceListFragment.this); sourceList.setEnabled(true); needsListReset = false; } } }, (long) (transitionTime * 1.1f)); needsListReset = true; view.startAnimation(animation); cardColorAnimation.start(); titleColorAnimation.start(); titleShadowAlphaAnimation.start(); }
From source file:io.authme.sdk.widget.LockPatternView.java
private void startSizeAnimation(float start, float end, long duration, Interpolator interpolator, final CellState state, final Runnable endRunnable) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { FloatAnimator animator = new FloatAnimator(start, end, duration); animator.addEventListener(new FloatAnimator.SimpleEventListener() { @Override// w ww. j a va 2 s.com public void onAnimationUpdate(FloatAnimator animator) { state.size = (Float) animator.getAnimatedValue(); invalidate(); }// onAnimationUpdate() @Override public void onAnimationEnd(FloatAnimator animator) { if (endRunnable != null) endRunnable.run(); }// onAnimationEnd() }); animator.start(); } // API < 11 else { ValueAnimator valueAnimator = ValueAnimator.ofFloat(start, end); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { state.size = (Float) animation.getAnimatedValue(); invalidate(); } }); if (endRunnable != null) { valueAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (endRunnable != null) endRunnable.run(); } }); } valueAnimator.setInterpolator(interpolator); valueAnimator.setDuration(duration); valueAnimator.start(); } // API 11+ }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
private void openMenuDrawable(final DrawerArrowDrawable drawerArrowDrawable, boolean withAnim) { if (withAnim) { ValueAnimator anim = ValueAnimator.ofFloat(0.0f, 1.0f); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w . jav a 2 s. c o m public void onAnimationUpdate(ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); drawerArrowDrawable.setProgress(value); } }); anim.setDuration(MENU_ICON_ANIM_DURATION); anim.start(); } else { drawerArrowDrawable.setProgress(1.0f); } }