@@ -59,12 +59,11 @@ interface STATE {
5959 private ValueAnimator mShrinkAnimator ;
6060 private int mShrinkDuration ;
6161 private CircularProgressDrawable mLoadingDrawable ;
62+ private OnLoadingListener mOnLoadingListener ;
6263 private EndDrawable mEndDrawable ;
6364 private int mLoadingSize ;
6465 private int mLoadingPosition ;
6566
66- private OnLoadingListener mOnLoadingListener ;
67-
6867
6968 private boolean isShrinkAnimReverse ;
7069 private boolean isCancel ;
@@ -88,7 +87,6 @@ public LoadingButton(Context context, AttributeSet attrs, int defStyleAttr) {
8887
8988 private void init (Context context , AttributeSet attrs ) {
9089
91-
9290 //getConfig
9391 TypedArray array = context .obtainStyledAttributes (attrs , R .styleable .LoadingButton );
9492 enableShrink = array .getBoolean (R .styleable .LoadingButton_enableShrink , false );
@@ -121,9 +119,11 @@ private void init(Context context, AttributeSet attrs) {
121119
122120 //initShrinkAnimator
123121 setUpShrinkAnimator ();
124- if (mLoadingPosition % 2 == 0 || enableShrink )
122+ //TODO
123+ setEnableTextInCenter (true );
124+ /* if (mLoadingPosition % 2 == 0 || enableShrink)
125125 setEnableTextInCenter(true);
126-
126+ */
127127 if (getRootView ().isInEditMode ()) {
128128 mLoadingDrawable .setStartEndTrim (0 , 0.8f );
129129 }
@@ -331,16 +331,22 @@ public void start() {
331331
332332 public void complete () {
333333 if (mEndDrawable != null ) {
334- mEndDrawable .show (true );
334+ if (curStatus == STATE .LOADING )
335+ mEndDrawable .show (true , true );
336+ else
337+ mEndDrawable .show (true , false );
335338 } else {
336- beginShrinkAnim (true , false );
339+ if (curStatus == STATE .LOADING )
340+ beginShrinkAnim (true , false );
341+ else
342+ beginShrinkAnim (true , true );
337343 }
338344 }
339345
340346 public void fail () {
341347 isFail = true ;
342348 if (mEndDrawable != null ) {
343- mEndDrawable .show (false );
349+ mEndDrawable .show (false , true );
344350 } else {
345351 beginShrinkAnim (true , false );
346352 }
@@ -530,7 +536,9 @@ public class EndDrawable {
530536 private ObjectAnimator mAppearAnimator ;
531537 private long duration ;
532538 private float animValue ;
539+ int [] offsetTemp = new int []{0 , 0 };
533540 private boolean isShowing ;
541+ private boolean shrink ;
534542 private Runnable mRunnable ;
535543
536544 private EndDrawable (@ Nullable Drawable completeDrawable , @ Nullable Drawable failDrawable ) {
@@ -554,7 +562,7 @@ private void init() {
554562 @ Override
555563 public void run () {
556564 setAnimValue (0 );
557- if (enableShrink ) {
565+ if (shrink ) {
558566 beginShrinkAnim (true , false );
559567 } else {
560568 endCallbackListener ();
@@ -586,7 +594,7 @@ public void onAnimationEnd(Animator animation) {
586594 }
587595
588596
589- private void show (boolean isSuccess ) {
597+ private void show (boolean isSuccess , boolean shrink ) {
590598 //end running Shrinking
591599 if (mShrinkAnimator .isRunning ()) {
592600 mShrinkAnimator .end ();
@@ -604,6 +612,7 @@ private void show(boolean isSuccess) {
604612 }
605613 mAppearAnimator .start ();
606614 isShowing = true ;
615+ this .shrink = shrink ;
607616 }
608617
609618 private void cancel (boolean withAnim ) {
@@ -627,7 +636,7 @@ private void hide() {
627636 }
628637
629638 private int [] calcOffset (Canvas canvas , Rect bounds , @ POSITION int pos ) {
630- int [] offset = new int []{ 0 , 0 } ;
639+ final int [] offset = offsetTemp ;
631640 offset [0 ] = canvas .getWidth () / 2 ;
632641 offset [1 ] = canvas .getHeight () / 2 ;
633642 switch (pos ) {
@@ -640,11 +649,28 @@ private int[] calcOffset(Canvas canvas, Rect bounds, @POSITION int pos) {
640649 break ;
641650 }
642651 case POSITION .TOP : {
652+ //TODO Test
653+
643654 offset [0 ] -= bounds .width () / 2 ;
644- offset [1 ] -= (int ) getTextHeight () / 2 + bounds .height () + getCompoundDrawablePadding ();
645- if (enableShrink && isShrinkAnimReverse ) {
646- offset [1 ] += bounds .height () / 2 ;
655+
656+ if (enableShrink ) {
657+ offset [1 ] -= bounds .height () / 2 ;
658+ } else {
659+ offset [1 ] -= (getTextHeight () + bounds .height () + getCompoundDrawablePadding ()) / 2 ;
660+ if (isEnableTextInCenter ()) {
661+ offset [1 ] -= getCompoundDrawablePadding () / 2 ;
662+ }
647663 }
664+
665+ /* offset[1] -= (int) getTextHeight() / 2 + bounds.height() + getCompoundDrawablePadding();
666+ if (enableShrink) {
667+ if (isShrinkAnimReverse)
668+ offset[1] += bounds.height() / 2;
669+ }
670+
671+ if (!enableShrink && !isEnableTextInCenter()) {
672+ offset[1] += (bounds.height() + getCompoundDrawablePadding()) >> 1;
673+ }*/
648674 break ;
649675 }
650676 case POSITION .END : {
0 commit comments