List of usage examples for android.animation ValueAnimator getAnimatedValue
public Object getAnimatedValue()
ValueAnimator
when there is just one property being animated. From source file:com.advaitaworld.widgets.SlidingTabLayout.java
private void updateTitleColors(int prevSelectedPosition, int newSelectedPosition) { if (mSelectedTabColor == 0 && mDefaultTabColor == 0) { return;//from w w w .j a v a2s . c o m } View tabViewPrev = mTabStrip.getChildAt(prevSelectedPosition); View tabViewNew = mTabStrip.getChildAt(newSelectedPosition); final TextView tabTitlePrev = getTabTitleView(tabViewPrev); final TextView tabTitleNew = getTabTitleView(tabViewNew); ArgbEvaluator evaluator = new ArgbEvaluator(); ValueAnimator anim1 = new ValueAnimator(); anim1.setIntValues(mDefaultTabColor, mSelectedTabColor); anim1.setEvaluator(evaluator); anim1.setDuration(300); anim1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { tabTitleNew.setTextColor((Integer) valueAnimator.getAnimatedValue()); } }); ValueAnimator anim2 = new ValueAnimator(); anim2.setIntValues(mSelectedTabColor, mDefaultTabColor); anim2.setEvaluator(evaluator); anim2.setDuration(300); anim2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { tabTitlePrev.setTextColor((Integer) valueAnimator.getAnimatedValue()); } }); anim1.start(); anim2.start(); }
From source file:com.velli.passwordmanager.ActivityMain.java
public boolean lockDrawer(final boolean lock, boolean animate) { final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); boolean locked = isDrawerLocked(); if (drawer != null && lock != locked) { if (lock) { drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } else {// w ww .ja va 2s. c om drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); if (!animate) { initDrawer(); } } if (animate) { final ValueAnimator anim = ValueAnimator.ofFloat(lock ? 0 : 1, lock ? 1 : 0); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float slideOffset = (Float) valueAnimator.getAnimatedValue(); mToolbarDrawerToggle.onDrawerSlide(drawer, slideOffset); } }); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { anim.removeAllUpdateListeners(); if (!lock) { initDrawer(); } animation.removeAllListeners(); } }); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(500); anim.start(); } else { mToolbarDrawerToggle.onDrawerSlide(drawer, lock ? 1 : 0); } return true; } return false; }
From source file:liam.franco.selene.fragments.SuperNotesFragment.java
@Subscribe public void newNotesCount(NotesCount notesCount) { boolean hasNotes = notesCount.getSize() > 0; int paddingBottom = -1; if (parentLayout != null) { if (hasNotes) { if (parentLayout.getPaddingBottom() > 0) { paddingBottom = 0;/*w w w . ja va2 s . com*/ } } else { if (parentLayout.getPaddingBottom() <= 0) { paddingBottom = (int) UIUtils.convertDpToPixel(208, App.CONTEXT); } } if (paddingBottom > -1) { ValueAnimator animator = ValueAnimator.ofInt(parentLayout.getPaddingBottom(), paddingBottom); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { if (parentLayout != null) { parentLayout.setPadding(parentLayout.getPaddingLeft(), parentLayout.getPaddingTop(), parentLayout.getPaddingRight(), (Integer) valueAnimator.getAnimatedValue()); } } }); animator.setDuration(500); animator.start(); } } }
From source file:se.kth.csc.stayawhile.swipe.QueueTouchListener.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/* ww w . ja va 2 s .co 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; } mQueueSwipeListener.onDismiss(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 (PendingActionData 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 PendingActionData(dismissPosition, dismissView)); animator.start(); }
From source file:co.com.parsoniisolutions.custombottomsheetbehavior.lib.MergedAppBarLayoutBehavior.java
private void setTitleVisible(boolean visible) { if ((visible && mTitleTextView.getAlpha() == 1) || (!visible && mTitleTextView.getAlpha() == 0)) return;//from w w w. j a v a2 s .c o m if (mTitleAlphaValueAnimator == null || !mTitleAlphaValueAnimator.isRunning()) { mToolbar.setTitle(mToolbarTitle); int startAlpha = visible ? 0 : 1; int endAlpha = mCurrentTitleAlpha = visible ? 1 : 0; mTitleAlphaValueAnimator = ValueAnimator.ofFloat(startAlpha, endAlpha); mTitleAlphaValueAnimator .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime)); mTitleAlphaValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mTitleTextView.setAlpha((Float) animation.getAnimatedValue()); } }); mTitleAlphaValueAnimator.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 a 2s .co 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; } 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.bitants.wally.fragments.ImageZoomFragment.java
private void animateOut() { ValueAnimator animWidth = ValueAnimator.ofInt(zoomableImageView.getMeasuredWidth(), rect.right); animWidth.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from w w w . j av a 2 s .com*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams(); layoutParams.width = val; zoomableImageView.setLayoutParams(layoutParams); } }); animWidth.setDuration(500); animWidth.start(); ValueAnimator animHeight = ValueAnimator.ofInt(zoomableImageView.getMeasuredHeight(), rect.bottom); animHeight.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams(); layoutParams.height = val; zoomableImageView.setLayoutParams(layoutParams); } }); animHeight.setDuration(500); animHeight.start(); if (statusBarHeightCorrection > 0) { zoomableImageView.animate().y(-statusBarHeightCorrection).setDuration(300).start(); } zoomableImageView.animate().alpha(0.0f).setDuration(500).start(); }
From source file:es.ugr.swad.swadroid.gui.SwipeListViewTouchListener.java
private void performSwipeAction(final View swipeView, final int swipePosition, boolean toTheRight, boolean dismiss) { // 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 = swipeView.getLayoutParams(); final int originalHeight = swipeView.getHeight(); final boolean swipeRight = toTheRight; ValueAnimator animator;/*from ww w . j a va2s . c o m*/ if (dismiss) animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); else animator = ValueAnimator.ofInt(originalHeight, originalHeight - 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { --mDismissAnimationRefCount; if (mDismissAnimationRefCount == 0) { // No active animations, process all pending dismisses. // Sort by descending position Collections.sort(mPendingSwipes); int[] swipePositions = new int[mPendingSwipes.size()]; for (int i = mPendingSwipes.size() - 1; i >= 0; i--) { swipePositions[i] = mPendingSwipes.get(i).position; } if (swipeRight) mCallback.onSwipeRight(mListView, swipePositions); else mCallback.onSwipeLeft(mListView, swipePositions); ViewGroup.LayoutParams lp; for (PendingSwipeData pendingDismiss : mPendingSwipes) { // Reset view presentation pendingDismiss.view.setAlpha(1f); pendingDismiss.view.setTranslationX(0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalHeight; pendingDismiss.view.setLayoutParams(lp); } mPendingSwipes.clear(); } } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); swipeView.setLayoutParams(lp); } }); mPendingSwipes.add(new PendingSwipeData(swipePosition, swipeView)); animator.start(); }
From source file:com.bottomsheetbehavior.MergedAppBarLayoutBehavior.java
private void setTitleVisible(boolean visible) { if (mTitleTextView != null && mToolbar != null) { if ((visible && mTitleTextView.getAlpha() == 1) || (!visible && mTitleTextView.getAlpha() == 0)) return; if (mTitleAlphaValueAnimator == null || !mTitleAlphaValueAnimator.isRunning()) { int startAlpha = visible ? 0 : 1; int endAlpha = mCurrentTitleAlpha = visible ? 1 : 0; mTitleAlphaValueAnimator = ValueAnimator.ofFloat(startAlpha, endAlpha); mTitleAlphaValueAnimator/* w ww .j a v a 2 s .c o m*/ .setDuration(mContext.getResources().getInteger(android.R.integer.config_shortAnimTime)); mTitleAlphaValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mTitleTextView.setAlpha((Float) animation.getAnimatedValue()); } }); mTitleAlphaValueAnimator.start(); } } }
From source file:net.margaritov.preference.colorpicker.ColorPickerDialog.java
private ValueAnimator createAlphaAnimator(int start, int end) { ValueAnimator animator = ValueAnimator.ofInt(start, end); animator.setDuration(500);//from w w w. java2s . co m animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int value = (Integer) valueAnimator.getAnimatedValue(); float currentAlpha = value / 100f; mActionBarMain.setAlpha(1f - currentAlpha); mActionBarEditHex.setAlpha(currentAlpha); mDivider.setAlpha(currentAlpha); } }); if (mHideEditHexBar) { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { mActionBarMain.setVisibility(View.VISIBLE); ViewCompat.jumpDrawablesToCurrentState(mActionBarMain); } }); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mActionBarEditHex.setVisibility(View.GONE); mDivider.setVisibility(View.GONE); } }); } else { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { mActionBarEditHex.setVisibility(View.VISIBLE); ViewCompat.jumpDrawablesToCurrentState(mActionBarEditHex); mDivider.setVisibility(View.VISIBLE); } }); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mActionBarMain.setVisibility(View.GONE); } }); } return animator; }