瀏覽代碼

Merge branch 'develop' of https://github.com/swict/LifeplusAndroid into develop

Hasemi 6 年之前
父節點
當前提交
0785d081e9

+ 28 - 9
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/loading/ButtonLoadingView.java

@@ -31,6 +31,11 @@ public class ButtonLoadingView extends ConstraintLayout {
     super(context, attrs);
   }
 
+  /**
+   * draw
+   *
+   * @param context
+   */
   public void draw(Context context) {
     if (null != context) {
       LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -39,27 +44,41 @@ public class ButtonLoadingView extends ConstraintLayout {
       circleView2 = findViewById(R.id.circle2);
       circleView3 = findViewById(R.id.circle3);
 
-      circleView1.init(context);
-      circleView2.init(context);
-      circleView3.init(context);
-
-      circleView1.setCurrentPlayTime(100);
-      circleView2.setCurrentPlayTime(200);
-      circleView3.setCurrentPlayTime(300);
+      circleView1.init(context, 0);
+      circleView2.init(context, 1);
+      circleView3.init(context, 2);
     }
-
   }
 
+  /**
+   * 에니메이션 start
+   */
   public void animationStart() {
-
     circleView1.animationStart();
     circleView2.animationStart();
     circleView3.animationStart();
   }
 
+  /**
+   * 에니메이션 cancel
+   */
   public void animationCancel() {
     circleView1.animationCancel();
     circleView2.animationCancel();
     circleView3.animationCancel();
   }
+
+  /**
+   * dispose
+   */
+  public void dispose() {
+    if (null != circleView1) {
+      circleView1.dispose();
+      circleView2.dispose();
+      circleView3.dispose();
+      circleView1 = null;
+      circleView2 = null;
+      circleView3 = null;
+    }
+  }
 }

+ 52 - 14
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/loading/LoadingCircleView.java

@@ -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;
+    }
+  }
 }