소스 검색

0.0.46.beta7
- CustomDialog#ALIGN 新增 TOP_CENTER、TOP_LEFT、TOP_RIGHT、BOTTOM_CENTER、BOTTOM_LEFT、BOTTOM_RIGHT、LEFT_CENTER、LEFT_TOP、LEFT_BOTTOM、RIGHT_CENTER、RIGHT_TOP、RIGHT_BOTTOM 可以更精细的控制对话框的位置,额外的,TOP、LEFT、RIGHT、BOTTOM将默认改为等同于TOP_CENTER、LEFT_CENTER、RIGHT_CENTER、BOTTOM_CENTER,另外,TOP_LEFT和LEFT_TOP的区别在于入场出场动画方向不一样;
- 修复 WaitDialog/TipDialog 的 ProgressView 在默认情况下动画衔接的bug;

kongzue 2 년 전
부모
커밋
e39046295b

+ 68 - 13
DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java

@@ -66,9 +66,21 @@ public class CustomDialog extends BaseDialog {
     public enum ALIGN {
         CENTER,
         TOP,
+        TOP_CENTER,
+        TOP_LEFT,
+        TOP_RIGHT,
         BOTTOM,
+        BOTTOM_CENTER,
+        BOTTOM_LEFT,
+        BOTTOM_RIGHT,
         LEFT,
-        RIGHT
+        LEFT_CENTER,
+        LEFT_TOP,
+        LEFT_BOTTOM,
+        RIGHT,
+        RIGHT_CENTER,
+        RIGHT_TOP,
+        RIGHT_BOTTOM
     }
     
     protected CustomDialog() {
@@ -183,18 +195,30 @@ public class CustomDialog extends BaseDialog {
                             baseView == null) {
                         switch (align) {
                             case TOP:
+                            case TOP_CENTER:
+                            case TOP_LEFT:
+                            case TOP_RIGHT:
                                 enterAnimResId = R.anim.anim_dialogx_top_enter;
                                 exitAnimResId = R.anim.anim_dialogx_top_exit;
                                 break;
                             case BOTTOM:
+                            case BOTTOM_CENTER:
+                            case BOTTOM_LEFT:
+                            case BOTTOM_RIGHT:
                                 enterAnimResId = R.anim.anim_dialogx_bottom_enter;
                                 exitAnimResId = R.anim.anim_dialogx_bottom_exit;
                                 break;
                             case LEFT:
+                            case LEFT_CENTER:
+                            case LEFT_TOP:
+                            case LEFT_BOTTOM:
                                 enterAnimResId = R.anim.anim_dialogx_left_enter;
                                 exitAnimResId = R.anim.anim_dialogx_left_exit;
                                 break;
                             case RIGHT:
+                            case RIGHT_CENTER:
+                            case RIGHT_TOP:
+                            case RIGHT_BOTTOM:
                                 enterAnimResId = R.anim.anim_dialogx_right_enter;
                                 exitAnimResId = R.anim.anim_dialogx_right_exit;
                                 break;
@@ -245,6 +269,7 @@ public class CustomDialog extends BaseDialog {
         }
         
         boolean initSetCustomViewLayoutListener = false;
+        ALIGN alignCache;
         
         @Override
         public void refreshView() {
@@ -305,17 +330,44 @@ public class CustomDialog extends BaseDialog {
             } else {
                 RelativeLayout.LayoutParams rlp;
                 rlp = ((RelativeLayout.LayoutParams) boxCustom.getLayoutParams());
-                if (rlp == null) {
+                if (rlp == null || (alignCache != null && alignCache != align)) {
                     rlp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                 }
                 switch (align) {
+                    case TOP_LEFT:
+                    case LEFT_TOP:
+                        rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
+                        rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
+                        rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
+                        break;
                     case TOP:
+                    case TOP_CENTER:
                         rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                         rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
+                        rlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
+                        break;
+                    case TOP_RIGHT:
+                    case RIGHT_TOP:
+                        rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
+                        rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
+                        rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
+                        break;
+                    case BOTTOM_LEFT:
+                    case LEFT_BOTTOM:
+                        rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
+                        rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                         break;
                     case BOTTOM:
+                    case BOTTOM_CENTER:
+                        rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
+                        rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
+                        rlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
+                        break;
+                    case BOTTOM_RIGHT:
+                    case RIGHT_BOTTOM:
                         rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                         rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
+                        rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                         break;
                     case CENTER:
                         rlp.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
@@ -323,16 +375,19 @@ public class CustomDialog extends BaseDialog {
                         rlp.addRule(RelativeLayout.CENTER_IN_PARENT);
                         break;
                     case LEFT:
+                    case LEFT_CENTER:
                         rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
                         rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
-                        rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
+                        rlp.addRule(RelativeLayout.CENTER_VERTICAL);
                         break;
                     case RIGHT:
+                    case RIGHT_CENTER:
                         rlp.removeRule(RelativeLayout.CENTER_IN_PARENT);
-                        rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                         rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
+                        rlp.addRule(RelativeLayout.CENTER_VERTICAL);
                         break;
                 }
+                alignCache = align;
                 boxCustom.setLayoutParams(rlp);
             }
             
@@ -686,44 +741,44 @@ public class CustomDialog extends BaseDialog {
     }
     
     public CustomDialog setBaseViewMargin(int marginLeft, int marginTop,
-                                                  int marginRight, int marginBottom) {
+                                          int marginRight, int marginBottom) {
         this.marginRelativeBaseView = new int[]{marginLeft, marginTop, marginRight, marginBottom};
         return this;
     }
     
-    public CustomDialog setBaseViewMarginLeft(int marginLeft){
+    public CustomDialog setBaseViewMarginLeft(int marginLeft) {
         this.marginRelativeBaseView[0] = marginLeft;
         return this;
     }
     
-    public CustomDialog setBaseViewMarginTop(int marginTop){
+    public CustomDialog setBaseViewMarginTop(int marginTop) {
         this.marginRelativeBaseView[1] = marginTop;
         return this;
     }
     
-    public CustomDialog setBaseViewMarginRight(int marginRight){
+    public CustomDialog setBaseViewMarginRight(int marginRight) {
         this.marginRelativeBaseView[2] = marginRight;
         return this;
     }
     
-    public CustomDialog setBaseViewMarginBottom(int marginBottom){
+    public CustomDialog setBaseViewMarginBottom(int marginBottom) {
         this.marginRelativeBaseView[3] = marginBottom;
         return this;
     }
     
-    public int getBaseViewMarginLeft(int marginLeft){
+    public int getBaseViewMarginLeft(int marginLeft) {
         return this.marginRelativeBaseView[0];
     }
     
-    public int getBaseViewMarginTop(int marginLeft){
+    public int getBaseViewMarginTop(int marginLeft) {
         return this.marginRelativeBaseView[1];
     }
     
-    public int getBaseViewMarginRight(int marginLeft){
+    public int getBaseViewMarginRight(int marginLeft) {
         return this.marginRelativeBaseView[2];
     }
     
-    public int getBaseViewMarginBottom(int marginLeft){
+    public int getBaseViewMarginBottom(int marginLeft) {
         return this.marginRelativeBaseView[3];
     }
     

+ 39 - 12
DialogX/src/main/java/com/kongzue/dialogx/util/views/ProgressView.java

@@ -13,6 +13,7 @@ import android.graphics.RectF;
 import android.os.Handler;
 import android.os.Looper;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.HapticFeedbackConstants;
 import android.view.View;
 import android.view.animation.AccelerateDecelerateInterpolator;
@@ -188,6 +189,10 @@ public class ProgressView extends View implements ProgressViewInterface {
                         canvas.drawArc(oval, nowLoadingProgressValue, nowLoadingProgressEndAngle, false, mPaint);
                         if (nowLoadingProgressEndAngle - 360 >= nowLoadingProgressValue) {
                             successStep = 1;
+                            if (waitArticulationAnimationRunnable != null) {
+                                waitArticulationAnimationRunnable.run();
+                                waitArticulationAnimationRunnable = null;
+                            }
                         }
                         break;
                     case 1:
@@ -197,16 +202,27 @@ public class ProgressView extends View implements ProgressViewInterface {
                 }
                 break;
             case STATUS_PROGRESSING:
-                canvas.drawArc(oval, -90, currentRotateDegrees, false, mPaint);
-                if (currentRotateDegrees == 365 && waitProgressingRunnable != null) {
-                    waitProgressingRunnable.run();
-                    waitProgressingRunnable = null;
+                switch (successStep) {
+                    case 0:
+                        canvas.drawArc(oval, -90, currentRotateDegrees, false, mPaint);
+                        if (currentRotateDegrees == 365) {
+                            successStep = 1;
+                            if (waitArticulationAnimationRunnable != null) {
+                                waitArticulationAnimationRunnable.run();
+                                waitArticulationAnimationRunnable = null;
+                            }
+                        }
+                        break;
+                    case 1:
+                        canvas.drawArc(oval, 0, 360, false, mPaint);
+                        drawDoneMark(status, canvas);
+                        break;
                 }
-                break;
         }
     }
     
     private void drawDoneMark(int status, Canvas canvas) {
+        Log.e(">>>", "drawDoneMark.status: "+status );
         if (rotateAnimator.getInterpolator() != interpolator) {
             rotateAnimator.setInterpolator(interpolator);
         }
@@ -322,16 +338,14 @@ public class ProgressView extends View implements ProgressViewInterface {
         }
     }
     
-    private TimeInterpolator interpolator;
-    private Runnable waitProgressingRunnable;
+    private Interpolator interpolator;
     
     public void success() {
         if (status == STATUS_PROGRESSING) {
             progress(1f);
-            waitProgressingRunnable = new Runnable() {
+            waitArticulationAnimationRunnable = new Runnable() {
                 @Override
                 public void run() {
-                    successStep = 1;
                     initTipAnimator(STATUS_SUCCESS, new AccelerateDecelerateInterpolator());
                 }
             };
@@ -343,10 +357,10 @@ public class ProgressView extends View implements ProgressViewInterface {
     public void warning() {
         if (status == STATUS_PROGRESSING) {
             progress(1f);
-            waitProgressingRunnable = new Runnable() {
+            waitArticulationAnimationRunnable = new Runnable() {
                 @Override
                 public void run() {
-                    initTipAnimator(STATUS_WARNING, new DecelerateInterpolator(2));
+                    initTipAnimator(STATUS_WARNING, new AccelerateInterpolator(2f));
                 }
             };
             return;
@@ -357,7 +371,7 @@ public class ProgressView extends View implements ProgressViewInterface {
     public void error() {
         if (status == STATUS_PROGRESSING) {
             progress(1f);
-            waitProgressingRunnable = new Runnable() {
+            waitArticulationAnimationRunnable = new Runnable() {
                 @Override
                 public void run() {
                     initTipAnimator(STATUS_ERROR, new DecelerateInterpolator(2));
@@ -368,20 +382,33 @@ public class ProgressView extends View implements ProgressViewInterface {
         initTipAnimator(STATUS_ERROR, new DecelerateInterpolator(2));
     }
     
+    Runnable waitArticulationAnimationRunnable;     //等待衔接完成后再执行
+    
     private void initTipAnimator(int s, Interpolator i) {
         interpolator = i;
         status = s;
+        if (successStep == 0) {
+            waitArticulationAnimationRunnable = new Runnable() {
+                @Override
+                public void run() {
+                    initTipAnimator(status, interpolator);
+                }
+            };
+            return;
+        }
         
         if (tickAnimator != null) {
             tickAnimator.cancel();
             tickAnimator = null;
         }
+        tickAnimatorValue = 0;
         tickAnimator = ValueAnimator.ofFloat(0f, 1f);
         tickAnimator.setDuration(TIP_ANIMATOR_DURATION);
         tickAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
             @Override
             public void onAnimationUpdate(ValueAnimator animation) {
                 tickAnimatorValue = (float) animation.getAnimatedValue();
+                Log.e(">>>", "onAnimationUpdate: " + tickAnimatorValue);
                 invalidate();
             }
         });

+ 1 - 1
gradle.properties

@@ -19,5 +19,5 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.46.beta6
+BUILD_VERSION=0.0.46.beta7
 BUILD_VERSION_INT=45