Skip to content
Browse files

add sample and bug fix

1 parent 1a37180 commit 43c01c7ec79bcf67764acb87b5b0dbc88076cb3d @MasayukiSuda committed
View
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.
View
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.
View
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.
View
4 ei/src/main/java/com/daasuu/ei/EasingInterpolator.java
@@ -19,4 +19,8 @@ public EasingInterpolator(@NonNull Ease ease) {
public float getInterpolation(float input) {
return EasingProvider.get(this.ease, input);
}
+
+ public Ease getEase() {
+ return ease;
+ }
}
View
4 ei/src/main/java/com/daasuu/ei/EasingProvider.java
@@ -15,7 +15,7 @@
public static float get(@NonNull Ease ease, float elapsedTimeRate) {
switch (ease) {
case LINEAR:
- return 1f;
+ return elapsedTimeRate;
case QUAD_IN:
return getPowIn(elapsedTimeRate, 2);
case QUAD_OUT:
@@ -80,7 +80,7 @@ public static float get(@NonNull Ease ease, float elapsedTimeRate) {
return getElasticInOut(elapsedTimeRate, 1, 0.45);
default:
- return 1f;
+ return elapsedTimeRate;
}
View
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();
+
+ }
+
+
+}
View
13 sample/src/main/java/com/daasuu/easinginterpolator/MainActivity.java
@@ -3,6 +3,7 @@
import android.animation.ObjectAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
+import android.widget.LinearLayout;
import android.widget.TextView;
import com.daasuu.ei.Ease;
@@ -15,14 +16,10 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- TextView textView = (TextView) findViewById(R.id.txt_hello);
-
- ObjectAnimator animator = ObjectAnimator.ofFloat(
- textView, "translationX", 0, 600);
-
- animator.setDuration(2000)
- .setInterpolator(new EasingInterpolator(Ease.ELASTIC_IN_OUT));
- animator.start();
+ LinearLayout flowLayout = (LinearLayout) findViewById(R.id.layout_flow);
+ for (Ease ease : Ease.values()) {
+ flowLayout.addView(new EasingGraphView(this, ease));
+ }
}
}
View
17 sample/src/main/res/layout/activity_main.xml
@@ -9,9 +9,16 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.daasuu.easinginterpolator.MainActivity">
- <TextView
- android:id="@+id/txt_hello"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Hello World!" />
+ <ScrollView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:id="@+id/layout_flow"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" />
+
+ </ScrollView>
+
</RelativeLayout>

0 comments on commit 43c01c7

Please sign in to comment.
Something went wrong with that request. Please try again.