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.android.settings.widget.DotsPageIndicator.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))); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from w ww . j a v a2s. c o m*/ 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:co.ceryle.segmentedbutton.SegmentedButtonGroup.java
private void expand(final View v, Interpolator interpolator, int duration, int targetWidth) { int prevWidth = v.getWidth(); ValueAnimator valueAnimator = ValueAnimator.ofInt(prevWidth, targetWidth); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override// w w w .j av a 2s . co m public void onAnimationUpdate(ValueAnimator animation) { v.getLayoutParams().width = (int) animation.getAnimatedValue(); v.requestLayout(); } }); valueAnimator.setInterpolator(interpolator); valueAnimator.setDuration(duration); valueAnimator.start(); }
From source file:com.quanliren.quan_one.pull.swipe.SwipeRefreshLayout.java
private void startScaleDownReturnToStartAnimation(int from, AnimatorListenerAdapter listener) { mFrom = from;/*from ww w .j a v a 2s. co m*/ if (isAlphaUsedForScale()) { mStartingScale = mProgress.getAlpha(); } else { mStartingScale = ViewCompat.getScaleX(mCircleView); } mScaleDownToStartAnimation = new ObjectAnimator().ofFloat(0f, 1f).setDuration(SCALE_DOWN_DURATION); mScaleDownToStartAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float targetScale = (mStartingScale + (-mStartingScale * Float.valueOf(animation.getAnimatedValue().toString()))); setAnimationProgress(targetScale); moveToStart(Float.valueOf(animation.getAnimatedValue().toString())); } }); if (listener != null) mScaleDownToStartAnimation.addListener(listener); mScaleDownToStartAnimation.start(); }
From source file:com.jaydenxiao.androidfire.ui.zone.widget.ExpandableTextView.java
/** * /*from w ww . j av a 2s . com*/ * @param view */ @Override public void onClick(View view) { if (mTvExpandCollapse.getVisibility() != View.VISIBLE) { return; } mCollapsed = !mCollapsed; ///? if (showExpandCollapseDrawable) { mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null, mCollapsed ? mExpandDrawable : mCollapseDrawable, null); } mTvExpandCollapse.setText( mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink)); //??? if (mCollapsedStatus != null) { mCollapsedStatus.put(mPosition, mCollapsed); } // / mAnimating = true; ValueAnimator valueAnimator; if (mCollapsed) { // mTvContent.setMaxLines(mMaxCollapsedLines); valueAnimator = new ValueAnimator().ofInt(getHeight(), mCollapsedHeight); } else { valueAnimator = new ValueAnimator().ofInt(getHeight(), getHeight() + mTextHeightWithMaxLines - mTvContent.getHeight()); } valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int animatedValue = (int) valueAnimator.getAnimatedValue(); mTvContent.setMaxHeight(animatedValue - mMarginBetweenTxtAndBottom); getLayoutParams().height = animatedValue; requestLayout(); } }); valueAnimator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { // ?????? /// clear the animation flag mAnimating = false; // notify the listener if (mListener != null) { mListener.onExpandStateChanged(mTvContent, !mCollapsed); } } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); valueAnimator.setDuration(mAnimationDuration); valueAnimator.start(); }
From source file:com.mukesh.OtpView.java
private void setupAnimator() { defaultAddAnimator = ValueAnimator.ofFloat(0.5f, 1f); defaultAddAnimator.setDuration(150); defaultAddAnimator.setInterpolator(new DecelerateInterpolator()); defaultAddAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from ww w . j ava 2s .co m*/ public void onAnimationUpdate(ValueAnimator animation) { float scale = (float) animation.getAnimatedValue(); int alpha = (int) (255 * scale); animatorTextPaint.setTextSize(getTextSize() * scale); animatorTextPaint.setAlpha(alpha); postInvalidate(); } }); }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
@Override public boolean onDoubleTap(MotionEvent arg0) { mZoomIn = !mZoomIn;//from w w w. j a va2 s . c om float scale = 1.0f; final float x = arg0.getX(); final float y = arg0.getY(); if (mZoomIn) { scale = MasterImage.getImage().getMaxScaleFactor(); } if (scale != MasterImage.getImage().getScaleFactor()) { if (mAnimatorScale != null) { mAnimatorScale.cancel(); } mAnimatorScale = ValueAnimator.ofFloat(MasterImage.getImage().getScaleFactor(), scale); float translateX = (getWidth() / 2 - x); float translateY = (getHeight() / 2 - y); Point translation = MasterImage.getImage().getTranslation(); int startTranslateX = translation.x; int startTranslateY = translation.y; if (scale != 1.0f) { translation.x = (int) (mOriginalTranslation.x + translateX); translation.y = (int) (mOriginalTranslation.y + translateY); } else { translation.x = 0; translation.y = 0; } constrainTranslation(translation, scale); startAnimTranslation(startTranslateX, translation.x, startTranslateY, translation.y, mAnimationZoomDelay); mAnimatorScale.setDuration(mAnimationZoomDelay); mAnimatorScale.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { MasterImage.getImage().setScaleFactor((Float) animation.getAnimatedValue()); invalidate(); } }); mAnimatorScale.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { applyTranslationConstraints(); MasterImage.getImage().needsUpdatePartialPreview(); invalidate(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); mAnimatorScale.start(); } return true; }
From source file:com.huyn.demogroup.zoomageview.view.PhotoViewAttacher.java
private void reverseFromDrag() { final float translationY = mImageView.getTranslationY(); final float translationX = mImageView.getTranslationX(); final float startScale = mImageView.getScaleX(); ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f); animator.setDuration(200);/*w w w. j av a 2s . co m*/ animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); float y = translationY * (1 - value); float x = translationX * (1 - value); float scale = startScale + (1 - startScale) * value; mImageView.setTranslationY(y); mImageView.setTranslationX(x); mImageView.setScaleY(scale); mImageView.setScaleX(scale); } }); animator.start(); if (translationY >= mDragToFinishDistance / 2 && mDragToFinishListener != null && mEnableDragToFinish) { //doReverse(); mDragToFinish = true; //mDragToFinishListener.onDismiss(); System.out.println("+++++++++change mDragToFinish:" + mDragToFinish); View parent = (View) mImageView.getParent(); if (parent instanceof PhotoLayout) ((PhotoLayout) parent).reverse(); } }
From source file:com.quanliren.quan_one.pull.swipe.SwipeRefreshLayout.java
private ValueAnimator startAlphaAnimation(final int startingAlpha, final int endingAlpha) { // Pre API 11, alpha is used in place of scale. Don't also use it to // show the trigger point. if (mScale && isAlphaUsedForScale()) { return null; }// w w w . j a v a 2 s .co m ValueAnimator alpha = new ObjectAnimator().ofFloat(0f, 1f); alpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mProgress.setAlpha((int) (startingAlpha + ((endingAlpha - startingAlpha) * Float.valueOf(animation.getAnimatedValue().toString())))); } }); alpha.setDuration(ALPHA_ANIMATION_DURATION); alpha.start(); return alpha; }
From source file:net.qiujuer.genius.ui.widget.GeniusAbsSeekBar.java
private void animateSetProgress(float curProgress) { if (mPositionAnimator != null) { mPositionAnimator.cancel();//from w w w . j av a2s. co m mPositionAnimator.setFloatValues(curProgress, mAnimationTarget); } else { mPositionAnimator = ValueAnimator.ofFloat(curProgress, mAnimationTarget); mPositionAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mAnimationPosition = (Float) animation.getAnimatedValue(); float currentScale = (mAnimationPosition - mMin) / (float) (mMax - mMin); updateProgressFromAnimation(currentScale); } }); mPositionAnimator.setDuration(PROGRESS_ANIMATION_DURATION); } mPositionAnimator.start(); }
From source file:nl.eduvpn.app.fragment.HomeFragment.java
/** * Checks if the loading has finished.//from w ww . jav a2s . co m * If yes, it hides the loading animation. * If there were any errors, it will display a warning bar as well. * * @param adapter The adapter which the items are being loaded into. */ private synchronized void _checkLoadingFinished(final ProfileAdapter adapter) { _pendingInstanceCount--; if (_pendingInstanceCount <= 0 && _problematicInstances.size() == 0) { if (_loadingBar == null) { Log.d(TAG, "Layout has been destroyed already."); return; } float startHeight = _loadingBar.getHeight(); ValueAnimator animator = ValueAnimator.ofFloat(startHeight, 0); animator.setDuration(600); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float fraction = animation.getAnimatedFraction(); float alpha = 1f - fraction; float height = (Float) animation.getAnimatedValue(); if (_loadingBar != null) { _loadingBar.setAlpha(alpha); _loadingBar.getLayoutParams().height = (int) height; _loadingBar.requestLayout(); } } }); animator.start(); } else if (_pendingInstanceCount <= 0) { if (_displayText == null) { Log.d(TAG, "Layout has been destroyed already."); return; } // There are some warnings _displayText.setText(R.string.could_not_fetch_all_profiles); _warningIcon.setVisibility(View.VISIBLE); _progressBar.setVisibility(View.GONE); _loadingBar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Display a dialog with all the warnings _currentDialog = ErrorDialog.show(getContext(), getString(R.string.warnings_list), getString(R.string.instance_access_warning_message), new ErrorDialog.InstanceWarningHandler() { @Override public List<Instance> getInstances() { return _problematicInstances; } @Override public void retryInstance(Instance instance) { _warningIcon.setVisibility(View.GONE); _progressBar.setVisibility(View.VISIBLE); _displayText.setText(R.string.loading_available_profiles); SavedAuthState savedAuthState = _historyService.getSavedToken(instance); if (savedAuthState == null) { // Should never happen _currentDialog = ErrorDialog.show(getContext(), R.string.error_dialog_title, R.string.data_removed); } else { // Retry _problematicInstances.remove(instance); _fillList(adapter, Collections.singletonList(savedAuthState)); } } @Override public void loginInstance(final Instance instance) { // Find the auth state for the instance and then retry AuthState authState = _historyService.getCachedAuthState(instance); _apiService.getJSON( instance.getSanitizedBaseURI() + Constants.API_DISCOVERY_POSTFIX, authState, new APIService.Callback<JSONObject>() { @Override public void onSuccess(JSONObject result) { try { DiscoveredAPI discoveredAPI = _serializerService .deserializeDiscoveredAPI(result); // Cache the result _historyService.cacheDiscoveredAPI( instance.getSanitizedBaseURI(), discoveredAPI); _problematicInstances.remove(instance); Activity activity = getActivity(); if (activity != null && !activity.isFinishing()) { _connectionService.initiateConnection(getActivity(), instance, discoveredAPI); } } catch (SerializerService.UnknownFormatException ex) { Log.e(TAG, "Error parsing discovered API!", ex); _currentDialog = ErrorDialog.show(getContext(), R.string.error_dialog_title, R.string.provider_incorrect_format); } } @Override public void onError(String errorMessage) { Log.e(TAG, "Error while fetching discovered API: " + errorMessage); DiscoveredAPI discoveredAPI = _historyService .getCachedDiscoveredAPI(instance.getSanitizedBaseURI()); Activity activity = getActivity(); if (discoveredAPI != null && activity != null && !activity.isFinishing()) { _connectionService.initiateConnection(activity, instance, discoveredAPI); } else { _currentDialog = ErrorDialog.show(getContext(), R.string.error_dialog_title, R.string.provider_not_found_retry); } } }); } @Override public void removeInstance(Instance instance) { _historyService.removeAllDataForInstance(instance); _problematicInstances.remove(instance); getActivity().runOnUiThread(() -> _checkLoadingFinished(adapter)); } }); } }); } }