|
|
@@ -5,6 +5,7 @@ import android.animation.ObjectAnimator;
|
|
|
import android.animation.PropertyValuesHolder;
|
|
|
import android.animation.ValueAnimator;
|
|
|
import android.content.Context;
|
|
|
+import android.support.annotation.IntRange;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.constraint.ConstraintLayout;
|
|
|
import android.util.AttributeSet;
|
|
|
@@ -27,7 +28,6 @@ import kr.co.zumo.app.R;
|
|
|
public class LoadingCircleView extends ConstraintLayout {
|
|
|
|
|
|
private ObjectAnimator alphaAnimator;
|
|
|
- private long currentPlayTime;
|
|
|
private View circle;
|
|
|
|
|
|
public LoadingCircleView(Context context) {
|
|
|
@@ -43,41 +43,79 @@ public class LoadingCircleView extends ConstraintLayout {
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void init(Context context) {
|
|
|
+ /**
|
|
|
+ * fraction = 0, 1, 2. 점 3개짜리 웨이터에 이용한다.
|
|
|
+ *
|
|
|
+ * @param context context
|
|
|
+ * @param fraction 0 ~ 2, default 0
|
|
|
+ */
|
|
|
+ public void init(Context context, @IntRange(from = 0, to = 2) int fraction) {
|
|
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
inflater.inflate(R.layout.loading_circle_view, this);
|
|
|
circle = findViewById(R.id.loading_circle);
|
|
|
|
|
|
- Keyframe kf0 = Keyframe.ofFloat(0f, 1.0f);
|
|
|
- Keyframe kf1 = Keyframe.ofFloat(.5f, 0f);
|
|
|
- Keyframe kf2 = Keyframe.ofFloat(1f, 1.0f);
|
|
|
+ PropertyValuesHolder propertyValuesHolder;
|
|
|
+
|
|
|
+ if (fraction == 1) {
|
|
|
+ Keyframe kf0 = Keyframe.ofFloat(0f, .5f);
|
|
|
+ Keyframe kf1 = Keyframe.ofFloat(.2f, 1f);
|
|
|
+ Keyframe kf2 = Keyframe.ofFloat(.6f, 0f);
|
|
|
+ Keyframe kf3 = Keyframe.ofFloat(.8f, 0f);
|
|
|
+ Keyframe kf4 = Keyframe.ofFloat(1f, .5f);
|
|
|
+ propertyValuesHolder = PropertyValuesHolder.ofKeyframe(ALPHA, kf0, kf1, kf2, kf3, kf4);
|
|
|
+ }
|
|
|
+ else if (fraction == 2) {
|
|
|
+ Keyframe kf0 = Keyframe.ofFloat(0f, 0f);
|
|
|
+ Keyframe kf1 = Keyframe.ofFloat(.4f, 1f);
|
|
|
+ Keyframe kf2 = Keyframe.ofFloat(.8f, 0f);
|
|
|
+ Keyframe kf3 = Keyframe.ofFloat(1f, 0f);
|
|
|
+ propertyValuesHolder = PropertyValuesHolder.ofKeyframe(ALPHA, kf0, kf1, kf2, kf3);
|
|
|
+ }
|
|
|
+ else { // 0
|
|
|
+ Keyframe kf0 = Keyframe.ofFloat(0f, 1f);
|
|
|
+ Keyframe kf1 = Keyframe.ofFloat(.4f, 0f);
|
|
|
+ Keyframe kf2 = Keyframe.ofFloat(.6f, 0f);
|
|
|
+ Keyframe kf3 = Keyframe.ofFloat(1f, 1f);
|
|
|
+ propertyValuesHolder = PropertyValuesHolder.ofKeyframe(ALPHA, kf0, kf1, kf2, kf3);
|
|
|
+ }
|
|
|
|
|
|
- PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofKeyframe(ALPHA, kf0, kf1, kf2);
|
|
|
alphaAnimator = ObjectAnimator.ofPropertyValuesHolder(circle, propertyValuesHolder);
|
|
|
alphaAnimator.setInterpolator(new LinearInterpolator());
|
|
|
alphaAnimator.setRepeatCount(ValueAnimator.INFINITE);
|
|
|
alphaAnimator.setDuration(1000);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void setCurrentPlayTime(long currentPlayTime) {
|
|
|
- this.currentPlayTime = currentPlayTime;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 에니메이션 start
|
|
|
+ */
|
|
|
public void animationStart() {
|
|
|
if (null != alphaAnimator) {
|
|
|
circle.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
- alphaAnimator.setCurrentPlayTime(currentPlayTime);
|
|
|
alphaAnimator.start();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 에니메이션 cancel
|
|
|
+ */
|
|
|
public void animationCancel() {
|
|
|
if (null != alphaAnimator) {
|
|
|
circle.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
alphaAnimator.cancel();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * dispose
|
|
|
+ */
|
|
|
+ public void dispose() {
|
|
|
+ if (null != alphaAnimator) {
|
|
|
+ alphaAnimator.cancel();
|
|
|
+ alphaAnimator = null;
|
|
|
+ }
|
|
|
+ if (null != circle) {
|
|
|
+ circle.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
+ circle = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|