List of usage examples for android.animation ValueAnimator getAnimatedValue
public Object getAnimatedValue()
ValueAnimator
when there is just one property being animated. From source file:nuclei.ui.view.ButtonBarView.java
private void setSelected(final Item item, boolean selected) { if (mItems.length < 5) return;//from w ww. ja v a 2 s . c o m if (selected) { item.imageView.setColorFilter(mSelectedTint, PorterDuff.Mode.SRC_ATOP); if (item.textView != null) { item.textView.setTextColor(mSelectedTint); item.textView.setVisibility(View.VISIBLE); item.textView.setTextSize(0); ValueAnimator animator = mLabelAnimators.get(item); if (animator != null) animator.cancel(); animator = new ValueAnimator(); mLabelAnimators.put(item, animator); animator.setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int animatedValue = (Integer) valueAnimator.getAnimatedValue(); item.textView.setTextSize(animatedValue); } }); animator.setIntValues(0, 14); animator.start(); } } else { item.imageView.setColorFilter(mUnselectedTint, PorterDuff.Mode.SRC_ATOP); if (item.textView != null) { item.textView.setTextColor(mUnselectedTint); ValueAnimator animator = mLabelAnimators.get(item); if (animator != null) animator.cancel(); animator = new ValueAnimator(); mLabelAnimators.put(item, animator); animator.setDuration(200); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int animatedValue = (Integer) valueAnimator.getAnimatedValue(); item.textView.setTextSize(animatedValue); if (animatedValue == 0) item.textView.setVisibility(View.GONE); } }); animator.setIntValues(14, 0); animator.start(); } } }
From source file:org.digitalcampus.oppia.activity.CourseIndexActivity.java
private void initializeCourseIndex(boolean animate) { final ListView listView = (ListView) findViewById(R.id.section_list); if (listView == null) return;/*from w w w. jav a 2 s. co m*/ ViewCompat.setNestedScrollingEnabled(listView, true); sla = new SectionListAdapter(CourseIndexActivity.this, course, sections, new SectionListAdapter.CourseClickListener() { @Override public void onActivityClicked(String activityDigest) { startCourseActivityByDigest(activityDigest); } }); if (animate) { AlphaAnimation fadeOutAnimation = new AlphaAnimation(1f, 0f); fadeOutAnimation.setDuration(700); fadeOutAnimation.setFillAfter(true); listView.setAlpha(0f); ValueAnimator animator = ValueAnimator.ofFloat(1f, 0f); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator valueAnimator) { listView.setTranslationX((Float) valueAnimator.getAnimatedValue() * 80); listView.setAlpha(1f - (Float) valueAnimator.getAnimatedValue()); } }); animator.setDuration(700); animator.start(); loadingCourseView.startAnimation(fadeOutAnimation); } else { loadingCourseView.setVisibility(View.GONE); listView.setVisibility(View.VISIBLE); } listView.setAdapter(sla); }
From source file:com.folioreader.view.ConfigView.java
private void toggleBlackTheme() { int day = getResources().getColor(R.color.white); int night = getResources().getColor(R.color.night); int darkNight = getResources().getColor(R.color.dark_night); final int diffNightDark = night - darkNight; ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), mIsNightMode ? night : day, mIsNightMode ? day : night); colorAnimation.setDuration(FADE_DAY_NIGHT_MODE); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w .j av a 2 s. c o m public void onAnimationUpdate(ValueAnimator animator) { int value = (int) animator.getAnimatedValue(); mContainer.setBackgroundColor(value); if (mConfigViewCallback != null) { mConfigViewCallback.onBackgroundUpdate(value - diffNightDark); } } }); colorAnimation.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { mIsNightMode = !mIsNightMode; Config.getConfig().setNightMode(mIsNightMode); mConfigViewCallback.onConfigChange(); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); colorAnimation.setDuration(FADE_DAY_NIGHT_MODE); colorAnimation.start(); }
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 w w w . j a va 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:com.bitants.wally.fragments.ImageZoomFragment.java
private void animateIn(final Dialog dialog) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomableImageView.getLayoutParams(); params.width = rect.right;/*w w w .j a v a2 s . co m*/ params.height = rect.bottom; zoomableImageView.setLayoutParams(params); zoomableImageView.setX(rect.left); zoomableImageView.setY(rect.top - statusBarHeightCorrection); zoomableImageView.setAlpha(0.0f); zoomableImageView.setImageBitmap(bitmap); WindowManager win = getActivity().getWindowManager(); Display d = win.getDefaultDisplay(); int displayWidth = d.getWidth(); // Width of the actual device int displayHeight = d.getHeight() + statusBarHeightCorrection; ValueAnimator animWidth = ValueAnimator.ofInt(rect.right, displayWidth); animWidth.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override 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.setInterpolator(new LinearOutSlowInInterpolator()); animWidth.start(); ValueAnimator animHeight = ValueAnimator.ofInt(rect.bottom, displayHeight); 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.setInterpolator(new LinearOutSlowInInterpolator()); animHeight.start(); if (statusBarHeightCorrection > 0) { zoomableImageView.animate().y(0.0f).setDuration(300).start(); } ValueAnimator animDim = ValueAnimator.ofFloat(0.0f, 0.5f); animDim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); layoutParams.copyFrom(dialog.getWindow().getAttributes()); layoutParams.dimAmount = (Float) valueAnimator.getAnimatedValue(); dialog.getWindow().setAttributes(layoutParams); } }); animDim.setDuration(300); animDim.setStartDelay(300); animDim.start(); zoomableImageView.animate().alpha(1.0f).setDuration(300).start(); }
From source file:com.hippo.nimingban.widget.PostLayout.java
private void init(Context context) { mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback()); mShadowTop = context.getResources().getDrawable(R.drawable.shadow_top); mShadowHeight = LayoutUtils.dp2pix(context, 8); mThreshold = LayoutUtils.dp2pix(context, 48); mHideTypeSendAnimation = new ValueAnimator(); mHideTypeSendAnimation.setDuration(300); mHideTypeSendAnimation.setInterpolator(AnimationUtils2.FAST_SLOW_INTERPOLATOR); mHideTypeSendAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w. jav a2 s . c o m public void onAnimationUpdate(ValueAnimator animation) { View view = getChildAt(1); if (view != null) { int value = (Integer) animation.getAnimatedValue(); view.offsetTopAndBottom(value - view.getTop()); ((LayoutParams) view.getLayoutParams()).offsetY = value; invalidate(); } } }); mShowTypeSendAnimation = new ValueAnimator(); mShowTypeSendAnimation.setDuration(300); mShowTypeSendAnimation.setInterpolator(AnimationUtils2.FAST_SLOW_INTERPOLATOR); mShowTypeSendAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { View view = getChildAt(1); if (view != null) { int value = (Integer) animation.getAnimatedValue(); view.offsetTopAndBottom(value - view.getTop()); ((LayoutParams) view.getLayoutParams()).offsetY = value; invalidate(); } } }); }
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/*w w w . j a v a 2s. 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; } 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:org.secuso.privacyfriendlypasswordgenerator.helpers.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 ww 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; } 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:ca.zadrox.dota2esportticker.ui.TeamDetailActivity.java
private void createCompatReveal() { mHeaderTeamLogo.setVisibility(View.VISIBLE); mHeaderTeamLogo.setImageBitmap(mTeam.logo); mHeaderTeamLogo.setTranslationY(-UIUtils.calculateActionBarSize(this) - mHeaderTeamLogo.getHeight()); mHeaderTeamLogo.animate().translationY(0).setDuration(100) .setInterpolator(new AccelerateDecelerateInterpolator()) .setListener(new Animator.AnimatorListener() { @Override/*from w w w .j a va2 s . c o m*/ public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { mHeaderTeamName.animate().alpha(1).setDuration(150) .setInterpolator(new AccelerateDecelerateInterpolator()).start(); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.theme_primary), mTeam.palette.getDarkVibrantColor(getResources().getColor(R.color.theme_primary))); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { mHeaderBox.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.setDuration(150); colorAnimation.start(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }).start(); }
From source file:com.miris.ui.view.WaveView.java
public void startWaveAnimation(float h) { h = Math.min(h, MAX_WAVE_HEIGHT) * mWidth; mWaveReverseAnimator = ValueAnimator.ofFloat(h, 0.f); mWaveReverseAnimator.setDuration(WAVE_ANIMATOR_DURATION); mWaveReverseAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w ww . j ava 2 s . c o m public void onAnimationUpdate(ValueAnimator valueAnimator) { float h = (Float) valueAnimator.getAnimatedValue(); mWavePath.moveTo(0, 0); mWavePath.quadTo(0.25f * mWidth, 0, 0.333f * mWidth, h * 0.5f); mWavePath.quadTo(mWidth * 0.5f, h * 1.4f, 0.666f * mWidth, h * 0.5f); mWavePath.quadTo(0.75f * mWidth, 0, mWidth, 0); postInvalidate(); } }); mWaveReverseAnimator.setInterpolator(new BounceInterpolator()); mWaveReverseAnimator.start(); }