List of usage examples for android.animation ValueAnimator getAnimatedFraction
public float getAnimatedFraction()
From source file:com.taobao.weex.ui.animation.DimensionUpdateListener.java
@Override public void onAnimationUpdate(ValueAnimator animation) { if (view.getLayoutParams() != null) { ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); TimeInterpolator interpolator = animation.getInterpolator(); float fraction = animation.getAnimatedFraction(); int preWidth = layoutParams.width; int preHeight = layoutParams.height; if (width != null) { layoutParams.width = intEvaluator.evaluate(interpolator.getInterpolation(fraction), width.first, width.second);//from w ww. ja va 2s . com } if (height != null) { layoutParams.height = intEvaluator.evaluate(interpolator.getInterpolation(fraction), height.first, height.second); } if (preHeight != layoutParams.height || preWidth != layoutParams.width) { view.requestLayout(); } } }
From source file:org.lib.ExpandableLinearLayout.java
private void animateHeight(final View view, final int targetHeight) { if (animatorSet == null) { animatorSet = new AnimatorSet(); animatorSet.setInterpolator(interpolator); animatorSet.setDuration(duration); }//from w w w . jav a 2 s . c o m final LayoutParams lp = (LayoutParams) view.getLayoutParams(); lp.weight = 0; int height = view.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(height, targetHeight); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { view.getLayoutParams().height = (Integer) valueAnimator.getAnimatedValue(); view.requestLayout(); if (listener != null) { float fraction = targetHeight == 0 ? 1 - valueAnimator.getAnimatedFraction() : valueAnimator.getAnimatedFraction(); listener.onExpansionUpdate(fraction); } } }); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { view.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animator) { if (targetHeight == 0) { view.setVisibility(GONE); } else { lp.height = lp.originalHeight; lp.weight = lp.originalWeight; } } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); animatorSet.playTogether(animator); }
From source file:nl.eduvpn.app.fragment.HomeFragment.java
/** * Checks if the loading has finished.// w w w. jav a2 s . c o 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)); } }); } }); } }
From source file:com.android.settings.widget.DotsPageIndicator.java
private ValueAnimator createJoiningAnimator(final int leftJoiningDot, final long startDelay) { // animate the joining fraction for the given dot ValueAnimator joining = ValueAnimator.ofFloat(0f, 1.0f); joining.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w . j av a 2 s . com public void onAnimationUpdate(ValueAnimator valueAnimator) { setJoiningFraction(leftJoiningDot, valueAnimator.getAnimatedFraction()); } }); joining.setDuration(animHalfDuration); joining.setStartDelay(startDelay); joining.setInterpolator(interpolator); return joining; }
From source file:com.dgmltn.ranger.internal.AbsRangeBar.java
/** * Set the thumb to be in the pressed state and calls invalidate() to redraw * the canvas to reflect the updated state. * * @param thumb the thumb to press//from w w w. j a va2s. com */ private void pressPin(final PinView thumb) { if (mArePinsTemporary) { ValueAnimator animator = ValueAnimator.ofFloat(0, mExpandedPinRadius); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mPinRadius = (Float) animation.getAnimatedValue(); thumb.setSize(mPinRadius, mPinPadding * animation.getAnimatedFraction()); invalidate(); } }); animator.start(); thumb.press(); } else { thumb.setSize(mExpandedPinRadius, mPinPadding); } }
From source file:com.dgmltn.ranger.internal.AbsRangeBar.java
/** * Set the thumb to be in the normal/un-pressed state and calls invalidate() * to redraw the canvas to reflect the updated state. * * @param pinView the thumb to release// w w w.jav a 2s.com */ private void releasePin(final PinView pinView) { PointF point = new PointF(); getNearestIndexPosition(pinView.getPosition(), point); pinView.setPosition(point); int tickIndex = getNearestIndex(pinView); pinView.setLabel(getPinLabel(tickIndex)); if (mArePinsTemporary) { ValueAnimator animator = ValueAnimator.ofFloat(mExpandedPinRadius, 0); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mPinRadius = (Float) (animation.getAnimatedValue()); pinView.setSize(mPinRadius, mPinPadding - (mPinPadding * animation.getAnimatedFraction())); invalidate(); } }); animator.start(); pinView.release(); } else { invalidate(); } }
From source file:com.baitouwei.swiperefresh.ASwipeRefreshLayout.java
/** * animate header view specific location * * @param isToStart true:move to the start location,false:move to the end location * @param listener {@link OnAnimateContentOffsetListener} *///from ww w. ja va 2s .co m private void animateHeaderOffsetToPos(final boolean isToStart, final OnAnimateContentOffsetListener listener) { if (animatorOfHeader != null && animatorOfHeader.isRunning()) { animatorOfHeader.cancel(); } if (headerView.getVisibility() != VISIBLE) { headerView.setVisibility(VISIBLE); } if (isToStart) { animatorOfHeader = ObjectAnimator.ofInt(headerView.getCurrentOffset(), headerView.getStartOffset()) .setDuration(durationOfSwipeDown); } else { animatorOfHeader = ObjectAnimator.ofInt(headerView.getCurrentOffset(), headerView.getEndOffset()) .setDuration(durationOfSwipeDown); } final float currentPercent = headerView.getPercent(); animatorOfHeader.setInterpolator(headerInterpolator); animatorOfHeader.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { offsetHeader((int) animation.getAnimatedValue() - headerView.getCurrentOffset()); computeOffsetPercent(currentPercent, isToStart, animation.getAnimatedFraction()); } }); animatorOfHeader.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { if (listener != null) { listener.onOffsetEnd(); } if (isToStart) { headerView.setVisibility(INVISIBLE); footerView.setVisibility(INVISIBLE); } else { if (!headerView.isRunning()) { headerView.start(); } } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animatorOfHeader.start(); }
From source file:com.baitouwei.swiperefresh.ASwipeRefreshLayout.java
/** * animate footer view specific location * * @param isToStart true:move to the start location,false:move to the end location * @param listener {@link OnAnimateContentOffsetListener} *///from w w w.ja v a 2 s. c o m private void animateFooterOffsetToPos(final boolean isToStart, final OnAnimateContentOffsetListener listener) { if (animatorOfFooter != null && animatorOfFooter.isRunning()) { animatorOfFooter.cancel(); } if (footerView.getVisibility() != VISIBLE) { footerView.setVisibility(VISIBLE); } if (isToStart) { animatorOfFooter = ObjectAnimator.ofInt(footerView.getCurrentOffset(), footerView.getStartOffset()) .setDuration(durationOfSwipeUp); } else { animatorOfFooter = ObjectAnimator.ofInt(footerView.getCurrentOffset(), footerView.getEndOffset()) .setDuration(durationOfSwipeUp); } animatorOfFooter.setInterpolator(footerInterpolator); final float currentPercent = footerView.getPercent(); animatorOfFooter.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { offsetFooter((int) animation.getAnimatedValue() - footerView.getCurrentOffset()); computeOffsetPercent(currentPercent, isToStart, animation.getAnimatedFraction()); } }); animatorOfFooter.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { if (listener != null) { listener.onOffsetEnd(); } if (isToStart) { headerView.setVisibility(INVISIBLE); footerView.setVisibility(INVISIBLE); } else { if (!footerView.isRunning()) { footerView.start(); } } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animatorOfFooter.start(); }
From source file:org.chromium.chrome.browser.toolbar.ToolbarPhone.java
@Override protected void onPrimaryColorChanged(boolean shouldAnimate) { super.onPrimaryColorChanged(shouldAnimate); if (mBrandColorTransitionActive) mBrandColorTransitionAnimation.cancel(); final int initialColor = mToolbarBackground.getColor(); final int finalColor = getToolbarDataProvider().getPrimaryColor(); if (initialColor == finalColor) return;//from ww w . jav a 2s. c o m if (!isVisualStateValidForBrandColorTransition(mVisualState)) return; if (!shouldAnimate) { updateToolbarBackground(finalColor); return; } boolean shouldUseOpaque = ColorUtils.shouldUseOpaqueTextboxBackground(finalColor); final int initialAlpha = mLocationBarBackgroundAlpha; final int finalAlpha = shouldUseOpaque ? 255 : LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA; final boolean shouldAnimateAlpha = initialAlpha != finalAlpha; mBrandColorTransitionAnimation = ValueAnimator.ofFloat(0, 1).setDuration(THEME_COLOR_TRANSITION_DURATION); mBrandColorTransitionAnimation.setInterpolator(BakedBezierInterpolator.TRANSFORM_CURVE); mBrandColorTransitionAnimation.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float fraction = animation.getAnimatedFraction(); if (shouldAnimateAlpha) { mLocationBarBackgroundAlpha = (int) (MathUtils.interpolate(initialAlpha, finalAlpha, fraction)); } updateToolbarBackground(ColorUtils.getColorWithOverlay(initialColor, finalColor, fraction)); } }); mBrandColorTransitionAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mBrandColorTransitionActive = false; updateVisualsForToolbarState(); } }); mBrandColorTransitionAnimation.start(); mBrandColorTransitionActive = true; }
From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java
@TargetApi(11) private void startIdleAnimations() { if (mAnimationCurrent != null) { mAnimationCurrent.removeAllUpdateListeners(); mAnimationCurrent.cancel();//from ww w . j av a2s . c o m mAnimationCurrent = null; } mAnimationCurrent = ValueAnimator.ofFloat(0, mFocalRadius10Percent, 0); mAnimationCurrent.setInterpolator(mAnimationInterpolator); mAnimationCurrent.setDuration(1000); mAnimationCurrent.setStartDelay(225); mAnimationCurrent.setRepeatCount(ValueAnimator.INFINITE); mAnimationCurrent.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { boolean direction = true; @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onAnimationUpdate(ValueAnimator animation) { final float newFocalFraction = (Float) animation.getAnimatedValue(); boolean newDirection = direction; if (newFocalFraction < mFocalRippleProgress && direction) { newDirection = false; } else if (newFocalFraction > mFocalRippleProgress && !direction) { newDirection = true; } if (newDirection != direction && !newDirection) { mAnimationFocalRipple.start(); } direction = newDirection; mFocalRippleProgress = newFocalFraction; mView.mFocalRadius = mBaseFocalRadius + mFocalRippleProgress; mView.invalidate(); } }); mAnimationCurrent.start(); if (mAnimationFocalRipple != null) { mAnimationFocalRipple.removeAllUpdateListeners(); mAnimationFocalRipple.cancel(); mAnimationFocalRipple = null; } final float baseRadius = mBaseFocalRadius + mFocalRadius10Percent; mAnimationFocalRipple = ValueAnimator.ofFloat(baseRadius, baseRadius + (mFocalRadius10Percent * 6)); mAnimationFocalRipple.setInterpolator(mAnimationInterpolator); mAnimationFocalRipple.setDuration(500); mAnimationFocalRipple.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onAnimationUpdate(ValueAnimator animation) { mView.mFocalRippleSize = (float) animation.getAnimatedValue(); final float fraction; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { fraction = animation.getAnimatedFraction(); } else { fraction = (mFocalRadius10Percent * 6) / (mView.mFocalRippleSize - mBaseFocalRadius - mFocalRadius10Percent); } mView.mFocalRippleAlpha = (int) (mBaseFocalRippleAlpha * (1f - fraction)); } }); }