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.hippo.widget.lockpattern.LockPatternView.java
private void startSizeAnimation(float start, float end, long duration, Interpolator interpolator, final CellState state, final Runnable endRunnable) { ValueAnimator valueAnimator = ValueAnimator.ofFloat(start, end); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/* w ww . ja v a2s. c o m*/ public void onAnimationUpdate(ValueAnimator animation) { state.size = (float) animation.getAnimatedValue(); invalidate(); } }); if (endRunnable != null) { valueAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { endRunnable.run(); } }); } valueAnimator.setInterpolator(interpolator); valueAnimator.setDuration(duration); valueAnimator.start(); }
From source file:android.support.v17.leanback.app.PlaybackSupportFragment.java
private void loadBgAnimator() { AnimatorUpdateListener listener = new AnimatorUpdateListener() { @Override//from www .j a v a 2s . c om public void onAnimationUpdate(ValueAnimator arg0) { setBgAlpha((Integer) arg0.getAnimatedValue()); } }; Context context = getContext(); mBgFadeInAnimator = loadAnimator(context, R.animator.lb_playback_bg_fade_in); mBgFadeInAnimator.addUpdateListener(listener); mBgFadeInAnimator.addListener(mFadeListener); mBgFadeOutAnimator = loadAnimator(context, R.animator.lb_playback_bg_fade_out); mBgFadeOutAnimator.addUpdateListener(listener); mBgFadeOutAnimator.addListener(mFadeListener); }
From source file:com.jinzht.pro.swipelistview.SwipeListViewTouchListener.java
/** * Perform dismiss action/*w w w . ja va2s . c o m*/ * * @param dismissView View * @param dismissPosition Position of list */ protected void performDismiss(final View dismissView, final int dismissPosition, boolean doPendingDismiss) { enableDisableViewGroup((ViewGroup) dismissView, false); final ViewGroup.LayoutParams lp = dismissView.getLayoutParams(); final int originalHeight = dismissView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(animationTime); if (doPendingDismiss) { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { --dismissAnimationRefCount; if (dismissAnimationRefCount == 0) { removePendingDismisses(originalHeight); } } }); } animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { enableDisableViewGroup((ViewGroup) dismissView, true); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); dismissView.setLayoutParams(lp); } }); pendingDismisses.add(new PendingDismissData(dismissPosition, dismissView)); animator.start(); }
From source file:devlight.io.library.ArcProgressStackView.java
public ArcProgressStackView(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); // Init CPSV//w w w . j a va2s. c om // Always draw setWillNotDraw(false); setLayerType(LAYER_TYPE_SOFTWARE, null); ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null); // Detect if features available mIsFeaturesAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; // Retrieve attributes from xml final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArcProgressStackView); try { setIsAnimated(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_animated, true)); setIsShadowed(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_shadowed, true)); setIsRounded(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_rounded, false)); setIsDragged(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_dragged, false)); setIsLeveled(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_leveled, false)); setTypeface(typedArray.getString(R.styleable.ArcProgressStackView_apsv_typeface)); setTextColor(typedArray.getColor(R.styleable.ArcProgressStackView_apsv_text_color, Color.WHITE)); setShadowRadius(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_shadow_radius, DEFAULT_SHADOW_RADIUS)); setShadowDistance(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_shadow_distance, DEFAULT_SHADOW_DISTANCE)); setShadowAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_shadow_angle, (int) DEFAULT_SHADOW_ANGLE)); setShadowColor( typedArray.getColor(R.styleable.ArcProgressStackView_apsv_shadow_color, DEFAULT_SHADOW_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_animation_duration, DEFAULT_ANIMATION_DURATION)); setStartAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_start_angle, (int) DEFAULT_START_ANGLE)); setSweepAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_sweep_angle, (int) DEFAULT_SWEEP_ANGLE)); setProgressModelOffset(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_model_offset, DEFAULT_MODEL_OFFSET)); setModelBgEnabled(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_model_bg_enabled, false)); // Set orientation final int orientationOrdinal = typedArray .getInt(R.styleable.ArcProgressStackView_apsv_indicator_orientation, 0); setIndicatorOrientation( orientationOrdinal == 0 ? IndicatorOrientation.VERTICAL : IndicatorOrientation.HORIZONTAL); // Retrieve interpolator Interpolator interpolator = null; try { final int interpolatorId = typedArray .getResourceId(R.styleable.ArcProgressStackView_apsv_interpolator, 0); interpolator = interpolatorId == 0 ? null : AnimationUtils.loadInterpolator(context, interpolatorId); } catch (Resources.NotFoundException exception) { interpolator = null; exception.printStackTrace(); } finally { setInterpolator(interpolator); } // Set animation info if is available if (mIsFeaturesAvailable) { mProgressAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mProgressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { mAnimatedFraction = (float) animation.getAnimatedValue(); if (mAnimatorUpdateListener != null) mAnimatorUpdateListener.onAnimationUpdate(animation); postInvalidate(); } }); } // Check whether draw width dimension or fraction if (typedArray.hasValue(R.styleable.ArcProgressStackView_apsv_draw_width)) { final TypedValue drawWidth = new TypedValue(); typedArray.getValue(R.styleable.ArcProgressStackView_apsv_draw_width, drawWidth); if (drawWidth.type == TypedValue.TYPE_DIMENSION) setDrawWidthDimension(drawWidth.getDimension(context.getResources().getDisplayMetrics())); else setDrawWidthFraction(drawWidth.getFraction(MAX_FRACTION, MAX_FRACTION)); } else setDrawWidthFraction(DEFAULT_DRAW_WIDTH_FRACTION); // Set preview models if (isInEditMode()) { String[] preview = null; try { final int previewId = typedArray .getResourceId(R.styleable.ArcProgressStackView_apsv_preview_colors, 0); preview = previewId == 0 ? null : typedArray.getResources().getStringArray(previewId); } catch (Exception exception) { preview = null; exception.printStackTrace(); } finally { if (preview == null) preview = typedArray.getResources().getStringArray(R.array.default_preview); final Random random = new Random(); for (String previewColor : preview) mModels.add( new Model("", random.nextInt((int) MAX_PROGRESS), Color.parseColor(previewColor))); measure(mSize, mSize); } // Set preview model bg color mPreviewModelBgColor = typedArray.getColor(R.styleable.ArcProgressStackView_apsv_preview_bg, Color.LTGRAY); } } finally { typedArray.recycle(); } }
From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.java
@Override public void onAnimationUpdate(@NonNull ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); int oldLeft = mTargetView.getLeft(); int newLeft = MathUtils.lerp(mStartLeft, mEndLeft, value); if (mTargetView == mLeftDrawer) slideLeftDrawer(newLeft - oldLeft); else//from w w w .j a v a 2 s . co m slideRightDrawer(newLeft - oldLeft); }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
private void animateRevealHide(final View targetview, View startView) { if (isActionInsertOrEdit()) { int cx = startView.getLeft() + (startView.getWidth() / 2); //middle of button int cy = startView.getTop() + (startView.getHeight() / 2); //middle of button int radius = (int) Math.sqrt(Math.pow(cx, 2) + Math.pow(cy, 2)); //hypotenuse to top left Animator anim = ViewAnimationUtils.createCircularReveal(targetview, cx, cy, radius, 0); anim.addListener(new AnimatorListenerAdapter() { @Override//from w w w.ja v a2 s. c o m public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); targetview.setVisibility(View.INVISIBLE); } }); //anim.setInterpolator(new AccelerateInterpolator()); anim.setDuration(ANIM_DURATION); anim.start(); Integer colorTo = getResources().getColor(R.color.primaryColor); Integer colorFrom = getResources().getColor(android.R.color.white); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { targetview.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.setInterpolator(new AccelerateInterpolator(2)); colorAnimation.setDuration(ANIM_DURATION); colorAnimation.start(); } else if (isActionActionView()) { mAnimBackGroudView.animate().scaleX(1).scaleY(1).alpha(1).translationY(0).setDuration(ANIM_DURATION) .setInterpolator(new AccelerateInterpolator()).start(); mNoteEditor.animate().alpha(0).setDuration(100).start(); } }
From source file:android.support.v17.leanback.app.PlaybackSupportFragment.java
private void loadOtherRowAnimator() { final AnimatorUpdateListener updateListener = new AnimatorUpdateListener() { @Override//www . j a v a2 s . co m public void onAnimationUpdate(ValueAnimator arg0) { if (getVerticalGridView() == null) { return; } final float fraction = (Float) arg0.getAnimatedValue(); final int count = getVerticalGridView().getChildCount(); for (int i = 0; i < count; i++) { View view = getVerticalGridView().getChildAt(i); if (getVerticalGridView().getChildAdapterPosition(view) > 0) { view.setAlpha(fraction); view.setTranslationY((float) mAnimationTranslateY * (1f - fraction)); } } } }; Context context = getContext(); mOtherRowFadeInAnimator = loadAnimator(context, R.animator.lb_playback_controls_fade_in); mOtherRowFadeInAnimator.addUpdateListener(updateListener); mOtherRowFadeInAnimator.setInterpolator(mLogDecelerateInterpolator); mOtherRowFadeOutAnimator = loadAnimator(context, R.animator.lb_playback_controls_fade_out); mOtherRowFadeOutAnimator.addUpdateListener(updateListener); mOtherRowFadeOutAnimator.setInterpolator(new AccelerateInterpolator()); }
From source file:com.hippo.drawerlayout.DrawerLayout.java
@Override public void onAnimationUpdate(@NonNull ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); int oldLeft = mTargetView.getLeft(); int newLeft = lerp(mStartLeft, mEndLeft, value); if (mTargetView == mLeftDrawer) { slideLeftDrawer(newLeft - oldLeft); } else {//from w ww.j a v a 2 s . c o m slideRightDrawer(newLeft - oldLeft); } }
From source file:Steps.StepsFragment.java
public void animateTextView(int initialValue, int finalValue, final TextView textview) { ValueAnimator valueAnimator = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { valueAnimator = ValueAnimator.ofInt((int) initialValue, (int) finalValue); valueAnimator.setDuration(1500); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override/* w ww. ja v a 2 s . co m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { textview.setText(valueAnimator.getAnimatedValue().toString()); } }); valueAnimator.start(); } }
From source file:org.protocoderrunner.apprunner.api.PUI.java
@ProtocoderScript @APIMethod(description = "Resize a view to a given width and height. If a parameter is -1 then that dimension is not changed", example = "") @APIParam(params = { "View", "width", "height" }) public void resize(final View v, int h, int w) { boolean animated = false; if (!animated) { if (h != -1) { v.getLayoutParams().height = h; }//w w w . j a v a 2 s . co m if (w != -1) { v.getLayoutParams().width = w; } v.setLayoutParams(v.getLayoutParams()); } else { int initHeight = v.getLayoutParams().height; // v.setLayoutParams(v.getLayoutParams()); ValueAnimator anim = ValueAnimator.ofInt(initHeight, h); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); v.getLayoutParams().height = val; v.setLayoutParams(v.getLayoutParams()); } }); anim.setDuration(200); anim.start(); } }