List of usage examples for android.animation ValueAnimator addUpdateListener
public void addUpdateListener(AnimatorUpdateListener listener)
From source file:com.tengio.FloatingSearchView.java
private void refreshLeftIcon(boolean showAnim) { int leftActionWidthAndMarginLeft = Util.dpToPx(LEFT_MENU_WIDTH_AND_MARGIN_START); int queryTranslationX = 0; mLeftAction.setVisibility(VISIBLE);// w w w. j a v a 2 s.c om switch (mLeftActionMode) { case LEFT_ACTION_MODE_SHOW_HAMBURGER: if (showAnim && mMenuBtnDrawable.getProgress() == 1.0f) { ValueAnimator anim = ValueAnimator.ofFloat(1.0f, 0.0f); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); mMenuBtnDrawable.setProgress(value); } }); anim.setDuration(MENU_ICON_ANIM_DURATION); anim.start(); break; } mLeftAction.setImageDrawable(mMenuBtnDrawable); mMenuBtnDrawable.setProgress(0.0f); break; case LEFT_ACTION_MODE_SHOW_SEARCH: mLeftAction.setImageDrawable(mIconSearch); break; case LEFT_ACTION_MODE_SHOW_HOME: if (showAnim && mMenuBtnDrawable.getProgress() == 0.0f) { ValueAnimator anim = ValueAnimator.ofFloat(0.0f, 1.0f); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); mMenuBtnDrawable.setProgress(value); } }); anim.setDuration(MENU_ICON_ANIM_DURATION); anim.start(); break; } mLeftAction.setImageDrawable(mMenuBtnDrawable); mMenuBtnDrawable.setProgress(1.0f); break; case LEFT_ACTION_MODE_NO_LEFT_ACTION: mLeftAction.setVisibility(View.INVISIBLE); queryTranslationX = -leftActionWidthAndMarginLeft; break; } mSearchInputParent.setTranslationX(queryTranslationX); }
From source file:cw.kop.autobackground.sources.SourceListFragment.java
private void startEditFragment(final View view, final int position) { sourceList.setOnItemClickListener(null); sourceList.setEnabled(false);//w w w .j a v a 2s. c o m 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:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java
void animateViewIn() { if (Build.VERSION.SDK_INT >= 12) { final int viewHeight = mView.getHeight(); if (USE_OFFSET_API) { ViewCompat.offsetTopAndBottom(mView, viewHeight); } else {/*w w w .j a v a 2 s . c o m*/ mView.setTranslationY(viewHeight); } final ValueAnimator animator = new ValueAnimator(); animator.setIntValues(viewHeight, 0); animator.setInterpolator(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 = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_in); anim.setInterpolator(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:io.plaidapp.about.ui.widget.InkPageIndicator.java
private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) { // create the actual move animator ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo); // also set up a pending retreat anim this starts when the move is 75% complete retreatAnimation = new PendingRetreatAnimator(was, now, steps, now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f)) : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f))); retreatAnimation.addListener(new AnimatorListenerAdapter() { @Override/*from w w w . jav a2s . co m*/ public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(valueAnimator -> { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); postInvalidateOnAnimation(); }); moveSelected.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { // set a flag so that we continue to draw the unselected dot in the target position // until the selected dot has finished moving into place selectedDotInPosition = false; } @Override public void onAnimationEnd(Animator animation) { // set a flag when anim finishes so that we don't draw both selected & unselected // page dots selectedDotInPosition = true; } }); // slightly delay the start to give the joins a chance to run // unless dot isn't in position yet then don't delay! moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4L : 0L); moveSelected.setDuration(animDuration * 3L / 4L); moveSelected.setInterpolator(interpolator); return moveSelected; }
From source file:com.commit451.inkpageindicator.InkPageIndicator.java
private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) { // create the actual move animator ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo); // also set up a pending retreat anim this starts when the move is 75% complete retreatAnimation = new PendingRetreatAnimator(was, now, steps, now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f)) : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f))); retreatAnimation.addListener(new AnimatorListenerAdapter() { @Override/*ww w .ja va2s .c om*/ public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this); } }); moveSelected.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { // set a flag so that we continue to draw the unselected dot in the target position // until the selected dot has finished moving into place selectedDotInPosition = false; } @Override public void onAnimationEnd(Animator animation) { // set a flag when anim finishes so that we don't draw both selected & unselected // page dots selectedDotInPosition = true; } }); // slightly delay the start to give the joins a chance to run // unless dot isn't in position yet then don't delay! moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4l : 0l); moveSelected.setDuration(animDuration * 3l / 4l); moveSelected.setInterpolator(interpolator); return moveSelected; }
From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java
private void animateViewOut(final int event) { if (Build.VERSION.SDK_INT >= 12) { //TODO CHANGE 0 mView.setTranslationY(0);/*from w ww.j a v a 2 s .c o m*/ final ValueAnimator animator = new ValueAnimator(); //TODO CHANGE ? animator.setIntValues(0, -mView.getHeight()); animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); animator.setDuration(ANIMATION_DURATION); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animator) { mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION); } @Override public void onAnimationEnd(Animator animator) { onViewHidden(event); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { private int mPreviousAnimatedIntValue = 0; @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_out); anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); anim.setDuration(ANIMATION_DURATION); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationEnd(Animation animation) { onViewHidden(event); } @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); mView.startAnimation(anim); } }
From source file:com.amaze.filemanager.ui.views.Indicator.java
private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) { // create the actual move animator ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo); // also set up a pending retreat anim this starts when the move is 75% complete retreatAnimation = new PendingRetreatAnimator(was, now, steps, now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f)) : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f))); retreatAnimation.addListener(new AnimatorListenerAdapter() { @Override/*from ww w. j ava 2 s. co m*/ public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); postInvalidateOnAnimation(); } }); moveSelected.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { // set a flag so that we continue to draw the unselected dot in the target position // until the selected dot has finished moving into place selectedDotInPosition = false; } @Override public void onAnimationEnd(Animator animation) { // set a flag when anim finishes so that we don't draw both selected & unselected // page dots selectedDotInPosition = true; } }); // slightly delay the start to give the joins a chance to run // unless dot isn't in position yet then don't delay! moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4l : 0l); moveSelected.setDuration(animDuration * 3l / 4l); moveSelected.setInterpolator(interpolator); return moveSelected; }
From source file:com.amaze.carbonfilemanager.ui.views.Indicator.java
private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) { // create the actual move animator ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo); // also set up a pending retreat anim this starts when the move is 75% complete retreatAnimation = new PendingRetreatAnimator(was, now, steps, now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f)) : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f))); retreatAnimation.addListener(new AnimatorListenerAdapter() { @Override//from w w w . ja va 2 s . c om public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); postInvalidateOnAnimation(); } }); moveSelected.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { // set a flag so that we continue to draw the unselected dot in the target position // until the selected dot has finished moving into place selectedDotInPosition = false; } @Override public void onAnimationEnd(Animator animation) { // set a flag when anim finishes so that we don't draw both selected & unselected // page dots selectedDotInPosition = true; } }); // slightly delay the start to give the joins a chance to run // unless dot isn't in position yet then don't delay! moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4L : 0L); moveSelected.setDuration(animDuration * 3L / 4L); moveSelected.setInterpolator(interpolator); return moveSelected; }
From source file:com.filemanager.free.ui.views.Indicator.java
private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) { // create the actual move animator ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo); // also set up a pending retreat anim this starts when the move is 75% complete retreatAnimation = new PendingRetreatAnimator(was, now, steps, now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f)) : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f))); retreatAnimation.addListener(new AnimatorListenerAdapter() { @Override// w ww . j a va 2 s . c o m public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { postInvalidateOnAnimation(); } else { postInvalidate(); } } }); moveSelected.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { // set a flag so that we continue to draw the unselected dot in the target position // until the selected dot has finished moving into place selectedDotInPosition = false; } @Override public void onAnimationEnd(Animator animation) { // set a flag when anim finishes so that we don't draw both selected & unselected // page dots selectedDotInPosition = true; } }); // slightly delay the start to give the joins a chance to run // unless dot isn't in position yet then don't delay! moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4l : 0l); moveSelected.setDuration(animDuration * 3l / 4l); moveSelected.setInterpolator(interpolator); return moveSelected; }
From source file:com.tengio.FloatingSearchView.java
private void fadeInBackground() { ValueAnimator anim = ValueAnimator.ofInt(BACKGROUND_DRAWABLE_ALPHA_SEARCH_NOT_FOCUSED, BACKGROUND_DRAWABLE_ALPHA_SEARCH_FOCUSED); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from www .j a v a 2 s . co m*/ public void onAnimationUpdate(ValueAnimator animation) { int value = (Integer) animation.getAnimatedValue(); } }); anim.setDuration(BACKGROUND_FADE_ANIM_DURATION); anim.start(); }