Java Code Examples for android.view.animation.Interpolator

The following examples show how to use android.view.animation.Interpolator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: YCScrollPager   Source File: DirectionalViewPager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 设置viewPager滑动动画持续时间
 * API>19
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public void setAnimationDuration(final int during){
    try {
        // viewPager平移动画事件
        Field mField = ViewPager.class.getDeclaredField("mScroller");
        mField.setAccessible(true);
        // 动画效果与ViewPager的一致
        Interpolator interpolator = new Interpolator() {
            @Override
            public float getInterpolation(float t) {
                t -= 1.0f;
                return t * t * t * t * t + 1.0f;
            }
        };
        FixedSpeedScroller scroller = new FixedSpeedScroller(getContext(),
                interpolator, mRecentTouchTime);
        scroller.setDuration(during);
        mField.set(this, scroller);
    } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source Project: scene   Source File: AnimationOrAnimator.java    License: Apache License 2.0 6 votes vote down vote up
private void reverse(Animation animation) {
    Interpolator interpolator = animation.getInterpolator();
    if (interpolator != null) {
        if (interpolator instanceof ReverseInterpolator) {
            animation.setInterpolator(((ReverseInterpolator) interpolator).delegate);
        } else {
            animation.setInterpolator(new ReverseInterpolator(interpolator));
        }
    } else {
        animation.setInterpolator(new ReverseInterpolator());
    }

    if (animation instanceof AnimationSet) {
        List<Animation> animationList = ((AnimationSet) animation).getAnimations();
        for (int i = 0; i < animationList.size(); i++) {
            reverse(animationList.get(i));
        }
    }
}
 
Example 3
/**
 * Creates and returns a layout listener, which allows to start a peek animation to add a tab,
 * once its view has been inflated.
 *
 * @param item
 *         The item, which corresponds to the tab, which should be added, as an instance of the
 *         class {@link AbstractItem}. The item may not be null
 * @param peekAnimation
 *         The peek animation, which should be started, as an instance of the class {@link
 *         PeekAnimation}. The peek animation may not be null
 * @return The listener, which has been created, as an instance of the type {@link
 * OnGlobalLayoutListener}. The listener may not be null
 */
private OnGlobalLayoutListener createPeekLayoutListener(@NonNull final AbstractItem item,
                                                        @NonNull final PeekAnimation peekAnimation) {
    return new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            long totalDuration =
                    peekAnimation.getDuration() != -1 ? peekAnimation.getDuration() :
                            peekAnimationDuration;
            long duration = totalDuration / 3;
            Interpolator interpolator =
                    peekAnimation.getInterpolator() != null ? peekAnimation.getInterpolator() :
                            new AccelerateDecelerateInterpolator();
            float peekPosition =
                    getArithmetics().getTabContainerSize(Axis.DRAGGING_AXIS, false) * 0.66f;
            animatePeek(item, duration, interpolator, peekPosition, peekAnimation);
        }

    };
}
 
Example 4
Source Project: android-proguards   Source File: AnimUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Interpolator getFastOutSlowInInterpolator(Context context) {
    if (fastOutSlowIn == null) {
        fastOutSlowIn = AnimationUtils.loadInterpolator(context,
                android.R.interpolator.fast_out_slow_in);
    }
    return fastOutSlowIn;
}
 
Example 5
@Test
public void partialInterpolator_isModified_when_setPartialInterpolator_isCalled() {
    //given
    StaggeredAnimationGroup spiedGroup = prepareSpiedGroup();
    Interpolator testInterpolator = new LinearOutSlowInInterpolator();

    //when
    spiedGroup.setPartialInterpolator(testInterpolator);

    //then
    assertThat(spiedGroup.partialInterpolator).isEqualTo(testInterpolator);
}
 
Example 6
Source Project: MDPreference   Source File: LineMorphingDrawable.java    License: Apache License 2.0 5 votes vote down vote up
private LineMorphingDrawable(State[] states, int curState, int paddingLeft, int paddingTop, int paddingRight, int paddingBottom, int animDuration, Interpolator interpolator, int strokeSize, int strokeColor, Paint.Cap strokeCap, Paint.Join strokeJoin, boolean clockwise, boolean isRtl){
	mStates = states;
	mPaddingLeft = paddingLeft;
	mPaddingTop = paddingTop;
	mPaddingRight = paddingRight;
	mPaddingBottom = paddingBottom;
	
	mAnimDuration = animDuration;
	mInterpolator = interpolator;
	mStrokeSize = strokeSize;
	mStrokeColor = strokeColor;
	mStrokeCap = strokeCap;
	mStrokeJoin = strokeJoin;
	mClockwise = clockwise;
       mIsRtl = isRtl;
	
	mPaint = new Paint();
	mPaint.setAntiAlias(true);
	mPaint.setStyle(Paint.Style.STROKE);
	mPaint.setStrokeCap(mStrokeCap);
	mPaint.setStrokeJoin(mStrokeJoin);
	mPaint.setColor(mStrokeColor);
	mPaint.setStrokeWidth(mStrokeSize);
	
	mDrawBound = new RectF();
	
	mPath = new Path();			
		
	switchLineState(curState, false);
}
 
Example 7
Source Project: LiuAGeAndroid   Source File: CanvasTransformerBuilder.java    License: MIT License 5 votes vote down vote up
public CanvasTransformer translate(final int openedX, final int closedX, 
		final int openedY, final int closedY, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.translate((openedX - closedX) * f + closedX,
					(openedY - closedY) * f + closedY);
		}			
	};
	return mTrans;
}
 
Example 8
Source Project: PinchToZoom   Source File: ImageMatrixTouchHandler.java    License: MIT License 5 votes vote down vote up
/**
 * <p>Performs a zoom animation from <code>scaleFrom</code> to <code>scaleTo</code> using the given <code>ScaleAnimatorHandler</code>.</p>
 * @param scaleFrom
 * @param scaleTo
 * @param duration
 * @param scaleAnimatorHandler
 * @param interpolator
    */
private void animateZoom(float scaleFrom, float scaleTo, long duration, ScaleAnimatorHandler scaleAnimatorHandler, Interpolator interpolator) {
	if(isAnimating()) {
		throw new IllegalStateException("An animation is currently running; Check isAnimating() first!");
	}
	valueAnimator = ValueAnimator.ofFloat(scaleFrom, scaleTo);
	valueAnimator.setDuration(duration);
	valueAnimator.addUpdateListener(scaleAnimatorHandler);
	if(interpolator != null) valueAnimator.setInterpolator(interpolator);
	valueAnimator.start();
}
 
Example 9
Source Project: lottie-android   Source File: KeyframeParser.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private static WeakReference<Interpolator> getInterpolator(int hash) {
  // This must be synchronized because get and put isn't thread safe because
  // SparseArrayCompat has to create new sized arrays sometimes.
  synchronized (KeyframeParser.class) {
    return pathInterpolatorCache().get(hash);
  }
}
 
Example 10
public static Interpolator parse(Integer type, Float cycles) {
    if (type != null) {
        switch (type) {
            case 0:
                return new AccelerateDecelerateInterpolator();
            case 1:
                return new AccelerateInterpolator();
            case 2:
                return new AnticipateInterpolator();
            case 3:
                return new AnticipateOvershootInterpolator();
            case 4:
                return new BounceInterpolator();
            case 5:
                return new CycleInterpolator((cycles != null && cycles > 0) ? cycles : 1f);
            case 6:
                return new DecelerateInterpolator();
            case 7:
                return new LinearInterpolator();
            case 8:
                return new OvershootInterpolator();
            default:
                return new LinearInterpolator();
        }
    } else {
        return new LinearInterpolator();
    }
}
 
Example 11
Source Project: MusicPlayer   Source File: Animation.java    License: GNU General Public License v3.0 5 votes vote down vote up
@NonNull
public static Interpolator getInterpolator(int id) {
    switch (id) {
        case 0:
            return new LinearInterpolator();
        case 1:
            return new AccelerateInterpolator();
        case 2:
            return new DecelerateInterpolator();
        case 3:
            return new AccelerateDecelerateInterpolator();
        case 4:
            return new OvershootInterpolator();
        case 5:
            return new AnticipateInterpolator();
        case 6:
            return new AnticipateOvershootInterpolator();
        case 7:
            return new BounceInterpolator();
        case 8:
            return new FastOutLinearInInterpolator();
        case 9:
            return new LinearInterpolator();
        case 10:
            return new LinearOutSlowInInterpolator();
        default:
            return new FastOutSlowInInterpolator();
    }
}
 
Example 12
Source Project: morphos   Source File: Morpho.java    License: Apache License 2.0 5 votes vote down vote up
public Morpho build(AnimationType animationType, int duration, Interpolator interpolator) {
    if (animationType != null) {
        this.completeAnimationAnimationType = animationType;
    }
    this.completeAnimationDuration = duration;
    if (interpolator != null) {
        this.completeAnimationInterpolator = interpolator;
    }
    return this;
}
 
Example 13
Source Project: android_9.0.0_r45   Source File: AppTransition.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Prepares the specified animation with a standard duration, interpolator, etc.
 */
Animation prepareThumbnailAnimationWithDuration(Animation a, int appWidth, int appHeight,
        long duration, Interpolator interpolator) {
    if (duration > 0) {
        a.setDuration(duration);
    }
    a.setFillAfter(true);
    if (interpolator != null) {
        a.setInterpolator(interpolator);
    }
    a.initialize(appWidth, appHeight, appWidth, appHeight);
    return a;
}
 
Example 14
Source Project: android-proguards   Source File: CollapsingTextHelper.java    License: Apache License 2.0 5 votes vote down vote up
private static float lerp(float startValue, float endValue, float fraction,
                          Interpolator interpolator) {
    if (interpolator != null) {
        fraction = interpolator.getInterpolation(fraction);
    }
    return AnimUtils.lerp(startValue, endValue, fraction);
}
 
Example 15
Source Project: TraceByAmap   Source File: MarkerAnimationActivity.java    License: MIT License 5 votes vote down vote up
/**
 * 屏幕中心marker 跳动
 */
public void startJumpAnimation() {

	if (screenMarker != null ) {
		//根据屏幕距离计算需要移动的目标点
		final LatLng latLng = screenMarker.getPosition();
		Point point =  aMap.getProjection().toScreenLocation(latLng);
		point.y -= dip2px(this,125);
		LatLng target = aMap.getProjection()
				.fromScreenLocation(point);
		//使用TranslateAnimation,填写一个需要移动的目标点
		Animation animation = new TranslateAnimation(target);
		animation.setInterpolator(new Interpolator() {
			@Override
			public float getInterpolation(float input) {
				// 模拟重加速度的interpolator
				if(input <= 0.5) {
					return (float) (0.5f - 2 * (0.5 - input) * (0.5 - input));
				} else {
					return (float) (0.5f - Math.sqrt((input - 0.5f)*(1.5f - input)));
				}
			}
		});
		//整个移动所需要的时间
		animation.setDuration(600);
		//设置动画
		screenMarker.setAnimation(animation);
		//开始动画
		screenMarker.startAnimation();

	} else {
		Log.e("amap","screenMarker is null");
	}
}
 
Example 16
Source Project: WeatherStream   Source File: CanvasTransformerBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public CanvasTransformer zoom(final int openedX, final int closedX, 
		final int openedY, final int closedY,
		final int px, final int py, final Interpolator interp) {
	initTransformer();
	mTrans = new CanvasTransformer() {
		public void transformCanvas(Canvas canvas, float percentOpen) {
			mTrans.transformCanvas(canvas, percentOpen);
			float f = interp.getInterpolation(percentOpen);
			canvas.scale((openedX - closedX) * f + closedX,
					(openedY - closedY) * f + closedY, px, py);
		}			
	};
	return mTrans;
}
 
Example 17
Source Project: Trebuchet   Source File: LauncherScroller.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a Scroller with the specified interpolator. If the interpolator is
 * null, the default (viscous) interpolator will be used. Specify whether or
 * not to support progressive "flywheel" behavior in flinging.
 */
public LauncherScroller(Context context, Interpolator interpolator, boolean flywheel) {
    mFinished = true;
    mInterpolator = interpolator;
    mPpi = context.getResources().getDisplayMetrics().density * 160.0f;
    mDeceleration = computeDeceleration(ViewConfiguration.getScrollFriction());
    mFlywheel = flywheel;

    mPhysicalCoeff = computeDeceleration(0.84f); // look and feel tuning
}
 
Example 18
Source Project: MDPreference   Source File: RippleDrawable.java    License: Apache License 2.0 5 votes vote down vote up
private RippleDrawable(Drawable backgroundDrawable, int backgroundAnimDuration, int backgroundColor, int rippleType, int delayClickType,  int maxRippleRadius, int rippleAnimDuration, int rippleColor, Interpolator inInterpolator, Interpolator outInterpolator, int type, int topLeftCornerRadius, int topRightCornerRadius, int bottomRightCornerRadius, int bottomLeftCornerRadius, int left, int top, int right, int bottom){
	setBackgroundDrawable(backgroundDrawable);
	mBackgroundAnimDuration = backgroundAnimDuration;
	mBackgroundColor = backgroundColor;
	
	mRippleType = rippleType;
       setDelayClickType(delayClickType);
	mMaxRippleRadius = maxRippleRadius;
	mRippleAnimDuration = rippleAnimDuration;
	mRippleColor = rippleColor;

       if(mRippleType == TYPE_TOUCH && mMaxRippleRadius <= 0)
           mRippleType = TYPE_TOUCH_MATCH_VIEW;
	
	mInInterpolator = inInterpolator;
	mOutInterpolator = outInterpolator;
	
	setMask(type, topLeftCornerRadius, topRightCornerRadius, bottomRightCornerRadius, bottomLeftCornerRadius, left, top, right, bottom);
	
	mFillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mFillPaint.setStyle(Paint.Style.FILL);		
	
	mShaderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mShaderPaint.setStyle(Paint.Style.FILL);
	
	mBackground = new Path();
	mBackgroundBounds = new RectF();
	
	mRipplePoint = new PointF();
	
	mMatrix = new Matrix();
	
	mInShader = new RadialGradient(0, 0, GRADIENT_RADIUS, new int[]{mRippleColor, mRippleColor, 0}, GRADIENT_STOPS, Shader.TileMode.CLAMP);		
	if(mRippleType == TYPE_WAVE)
		mOutShader = new RadialGradient(0, 0, GRADIENT_RADIUS, new int[]{0, ColorUtil.getColor(mRippleColor, 0f), mRippleColor}, GRADIENT_STOPS, Shader.TileMode.CLAMP);		
}
 
Example 19
Source Project: ticdesign   Source File: CircularProgressDrawable.java    License: Apache License 2.0 5 votes vote down vote up
private CircularProgressDrawable(int padding, float initialAngle, float progressPercent, float secondaryProgressPercent, float maxSweepAngle, float minSweepAngle, int strokeSize, int[] strokeColors, int strokeSecondaryColor, boolean reverse, int rotateDuration, int transformDuration, int keepDuration, Interpolator transformInterpolator, int progressMode, int inAnimDuration, float inStepPercent, int[] inStepColors, int outAnimDuration, int alpha) {
        mPadding = padding;
        mInitialAngle = initialAngle;
        mAlpha = alpha;
        mProgressPercent = Math.min(1f, Math.max(0f, progressPercent));
//        setProgress(progressPercent);
        setSecondaryProgress(secondaryProgressPercent);
        mMaxSweepAngle = maxSweepAngle;
        mMinSweepAngle = minSweepAngle;
        mStrokeSize = strokeSize;
        mStrokeColors = strokeColors;
        mStrokeSecondaryColor = strokeSecondaryColor;
        mReverse = reverse;
        mRotateDuration = rotateDuration;
        mTransformDuration = transformDuration;
        mKeepDuration = keepDuration;
        mTransformInterpolator = transformInterpolator;
        mProgressMode = progressMode;
        mInAnimationDuration = inAnimDuration;
        mInStepPercent = inStepPercent;
        mInColors = inStepColors;
        mOutAnimationDuration = outAnimDuration;

        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setStrokeCap(Paint.Cap.BUTT);
        mPaint.setStrokeJoin(Paint.Join.ROUND);

        mRect = new RectF();

        mState = createConstantState(null, null);
    }
 
Example 20
Source Project: SimpleProject   Source File: ViewAnimationUtil.java    License: MIT License 5 votes vote down vote up
public static void alpha(View view, float fromAlpha, float toAlpha, int duration, Interpolator interpolator) {
	AlphaAnimation animation = new AlphaAnimation(fromAlpha, toAlpha);
	animation.setDuration(duration);
	animation.setFillAfter(true);
	animation.setInterpolator(interpolator);
	view.startAnimation(animation);
}
 
Example 21
Source Project: react-native-GPay   Source File: AbstractLayoutAnimation.java    License: MIT License 5 votes vote down vote up
private static Interpolator getInterpolator(InterpolatorType type, ReadableMap params) {
   Interpolator interpolator;
   if (type.equals(InterpolatorType.SPRING)) {
     interpolator = new SimpleSpringInterpolator(SimpleSpringInterpolator.getSpringDamping(params));
   } else {
     interpolator = INTERPOLATOR.get(type);
   }
  if (interpolator == null) {
    throw new IllegalArgumentException("Missing interpolator for type : " + type);
  }
  return interpolator;
}
 
Example 22
Source Project: UIWidget   Source File: CollapsingTextHelper.java    License: Apache License 2.0 4 votes vote down vote up
public void setTextSizeInterpolator(Interpolator interpolator) {
    mTextSizeInterpolator = interpolator;
    recalculate();
}
 
Example 23
Source Project: MemoryCleaner   Source File: BaseRecyclerViewAdapter.java    License: Apache License 2.0 4 votes vote down vote up
public void setInterpolator(Interpolator interpolator) {
    mInterpolator = interpolator;
}
 
Example 24
Source Project: MTransition   Source File: Transition.java    License: Apache License 2.0 4 votes vote down vote up
public void translateXInterpolator(Interpolator interpolator) {
    mTransX.setInterpolator(interpolator);
}
 
Example 25
public ViewPagerScroller(Context context, Interpolator interpolator,
		boolean flywheel) {
	super(context, interpolator, flywheel);
}
 
Example 26
Source Project: morphos   Source File: Morpho.java    License: Apache License 2.0 4 votes vote down vote up
public Morpho dimensions(float width, float height, int duration, Interpolator interpolator) {
    if (width >= 0 && height >= 0) {
        animationParts.add(new DimensionsAnimation(width, height, duration, interpolator));
    }
    return this;
}
 
Example 27
Source Project: letv   Source File: PathInterpolatorCompat.java    License: Apache License 2.0 4 votes vote down vote up
public static Interpolator create(float controlX1, float controlY1, float controlX2, float controlY2) {
    if (VERSION.SDK_INT >= 21) {
        return PathInterpolatorCompatApi21.create(controlX1, controlY1, controlX2, controlY2);
    }
    return PathInterpolatorCompatBase.create(controlX1, controlY1, controlX2, controlY2);
}
 
Example 28
Source Project: Flubber   Source File: EaseOutExpo.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Interpolator createInterpolatorFor(AnimationBody animationBody) {
    return PathInterpolatorCompat.create(0.19f, 1f, 0.22f, 1f);
}
 
Example 29
Source Project: Hify   Source File: SwipeConfiguration.java    License: MIT License 4 votes vote down vote up
SwipeBehaviour(float range, Interpolator interpolator) {
    this.range = range;
    this.interpolator = interpolator;
}
 
Example 30
Source Project: android-proguards   Source File: CollapsingTextHelper.java    License: Apache License 2.0 4 votes vote down vote up
public void setPositionInterpolator(Interpolator interpolator) {
    mPositionInterpolator = interpolator;
    recalculate();
}