Permalink
Please sign in to comment.
Showing
with
130 additions
and 15 deletions.
- BIN art/easing1.png
- BIN art/easing2.png
- BIN art/easing3.png
- +4 −0 ei/src/main/java/com/daasuu/ei/EasingInterpolator.java
- +2 −2 ei/src/main/java/com/daasuu/ei/EasingProvider.java
- +107 −0 sample/src/main/java/com/daasuu/easinginterpolator/EasingGraphView.java
- +5 −8 sample/src/main/java/com/daasuu/easinginterpolator/MainActivity.java
- +12 −5 sample/src/main/res/layout/activity_main.xml
BIN
art/easing1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN
art/easing2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN
art/easing3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4
ei/src/main/java/com/daasuu/ei/EasingInterpolator.java
4
ei/src/main/java/com/daasuu/ei/EasingProvider.java
107
sample/src/main/java/com/daasuu/easinginterpolator/EasingGraphView.java
| @@ -0,0 +1,107 @@ | ||
| +package com.daasuu.easinginterpolator; | ||
| + | ||
| +import android.content.Context; | ||
| +import android.graphics.Canvas; | ||
| +import android.graphics.Color; | ||
| +import android.graphics.Paint; | ||
| +import android.graphics.PointF; | ||
| +import android.util.AttributeSet; | ||
| +import android.util.DisplayMetrics; | ||
| +import android.util.Log; | ||
| +import android.view.animation.OvershootInterpolator; | ||
| +import android.widget.FrameLayout; | ||
| + | ||
| +import com.daasuu.ei.Ease; | ||
| +import com.daasuu.ei.EasingInterpolator; | ||
| + | ||
| +/** | ||
| + * Created by sudamasayuki on 16/03/19. | ||
| + */ | ||
| +public class EasingGraphView extends FrameLayout { | ||
| + | ||
| + private Paint mPaint = new Paint(); | ||
| + private Paint mFramePaint = new Paint(); | ||
| + private Paint mTextPaint = new Paint(); | ||
| + | ||
| + private EasingInterpolator easingInterpolator; | ||
| + private float mAdjustTextMesureY = -1; | ||
| + | ||
| + private float dpSize; | ||
| + | ||
| + private final int loopSize = 100; | ||
| + | ||
| + public EasingGraphView(Context context) { | ||
| + this(context, null, 0); | ||
| + } | ||
| + | ||
| + public EasingGraphView(Context context, Ease ease) { | ||
| + this(context, null, 0); | ||
| + easingInterpolator = new EasingInterpolator(ease); | ||
| + } | ||
| + | ||
| + public EasingGraphView(Context context, AttributeSet attrs) { | ||
| + this(context, attrs, 0); | ||
| + } | ||
| + | ||
| + public EasingGraphView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
| + super(context, attrs, defStyleAttr); | ||
| + | ||
| + mPaint.setColor(Color.BLUE); | ||
| + mPaint.setAntiAlias(true); | ||
| + | ||
| + mFramePaint.setColor(Color.BLUE); | ||
| + mFramePaint.setAntiAlias(true); | ||
| + mFramePaint.setStyle(Paint.Style.STROKE); | ||
| + | ||
| + dpSize = convertDpToPixel(1, context); | ||
| + | ||
| + mTextPaint.setTextSize(convertDpToPixel(12, context)); | ||
| + mAdjustTextMesureY = mTextPaint.getTextSize(); | ||
| + } | ||
| + | ||
| + | ||
| + @Override | ||
| + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
| + super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
| + setMeasuredDimension(110 * (int) dpSize, 180 * (int) dpSize); | ||
| + } | ||
| + | ||
| + private static float convertDpToPixel(float dp, Context context) { | ||
| + DisplayMetrics metrics = context.getResources().getDisplayMetrics(); | ||
| + return dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); | ||
| + } | ||
| + | ||
| + @Override | ||
| + protected void dispatchDraw(Canvas canvas) { | ||
| + super.dispatchDraw(canvas); | ||
| + | ||
| + if (easingInterpolator == null) { | ||
| + easingInterpolator = new EasingInterpolator(Ease.ELASTIC_IN_OUT); | ||
| + } | ||
| + | ||
| + int x = (int) mTextPaint.measureText(easingInterpolator.getEase().name()); | ||
| + canvas.drawText(easingInterpolator.getEase().name(), (loopSize * dpSize - x) / 2, mAdjustTextMesureY, mTextPaint); | ||
| + | ||
| + | ||
| + PointF points[] = new PointF[loopSize]; | ||
| + for (int i = 0; i < loopSize; i++) { | ||
| + points[i] = new PointF(); | ||
| + points[i].x = i * dpSize; | ||
| + points[i].y = (loopSize - easingInterpolator.getInterpolation((float) i / loopSize) * loopSize) * dpSize; | ||
| + } | ||
| + | ||
| + canvas.save(); | ||
| + { | ||
| + canvas.translate(0, 40 * dpSize); | ||
| + for (int i = 0, n = loopSize - 1; i < n; i++) { | ||
| + canvas.drawLine(points[i].x, points[i].y, | ||
| + points[i + 1].x, points[i + 1].y, mPaint); | ||
| + } | ||
| + canvas.drawRect(0, 0, loopSize * dpSize, loopSize * dpSize, mFramePaint); | ||
| + } | ||
| + canvas.restore(); | ||
| + | ||
| + } | ||
| + | ||
| + | ||
| +} |
13
sample/src/main/java/com/daasuu/easinginterpolator/MainActivity.java
17
sample/src/main/res/layout/activity_main.xml
0 comments on commit
43c01c7