diff --git a/app/src/main/java/com/github/jlmd/animatedcircleloadingview/sample/MainActivity.java b/app/src/main/java/com/github/jlmd/animatedcircleloadingview/sample/MainActivity.java index 7f70728..2c77c0e 100644 --- a/app/src/main/java/com/github/jlmd/animatedcircleloadingview/sample/MainActivity.java +++ b/app/src/main/java/com/github/jlmd/animatedcircleloadingview/sample/MainActivity.java @@ -3,6 +3,8 @@ import android.app.Activity; import android.os.Bundle; import android.util.Log; +import android.view.View; + import com.github.jlmd.animatedcircleloadingview.AnimatedCircleLoadingView; public class MainActivity extends Activity { @@ -14,6 +16,14 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); animatedCircleLoadingView = (AnimatedCircleLoadingView) findViewById(R.id.circle_loading_view); + animatedCircleLoadingView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + resetLoading(); + startLoading(); + startPercentMockThread(); + } + }); startLoading(); startPercentMockThread(); } diff --git a/library/src/main/java/com/github/jlmd/animatedcircleloadingview/AnimatedCircleLoadingView.java b/library/src/main/java/com/github/jlmd/animatedcircleloadingview/AnimatedCircleLoadingView.java index 0b1ff97..f17d8bd 100644 --- a/library/src/main/java/com/github/jlmd/animatedcircleloadingview/AnimatedCircleLoadingView.java +++ b/library/src/main/java/com/github/jlmd/animatedcircleloadingview/AnimatedCircleLoadingView.java @@ -4,6 +4,7 @@ import android.content.res.TypedArray; import android.graphics.Color; import android.util.AttributeSet; +import android.view.View; import android.widget.FrameLayout; import com.github.jlmd.animatedcircleloadingview.animator.ViewAnimator; import com.github.jlmd.animatedcircleloadingview.component.InitialCenterCircleView; @@ -80,7 +81,7 @@ private void startAnimation() { startAnimationIndeterminate = false; } if (startAnimationDeterminate) { - addView(percentIndicatorView); + percentIndicatorView.showView(); viewAnimator.startAnimator(); startAnimationDeterminate = false; } @@ -126,6 +127,7 @@ private void addComponentsViews() { addView(mainCircleView); addView(finishedOkView); addView(finishedFailureView); + addView(percentIndicatorView); } private void initAnimatorHelper() { @@ -172,6 +174,5 @@ public void stopFailure() { public void resetLoading() { viewAnimator.resetAnimator(); - setPercent(0); } } diff --git a/library/src/main/java/com/github/jlmd/animatedcircleloadingview/animator/ViewAnimator.java b/library/src/main/java/com/github/jlmd/animatedcircleloadingview/animator/ViewAnimator.java index 49df012..53b0371 100644 --- a/library/src/main/java/com/github/jlmd/animatedcircleloadingview/animator/ViewAnimator.java +++ b/library/src/main/java/com/github/jlmd/animatedcircleloadingview/animator/ViewAnimator.java @@ -1,5 +1,7 @@ package com.github.jlmd.animatedcircleloadingview.animator; +import android.view.View; + import com.github.jlmd.animatedcircleloadingview.component.ComponentViewAnimation; import com.github.jlmd.animatedcircleloadingview.component.InitialCenterCircleView; import com.github.jlmd.animatedcircleloadingview.component.MainCircleView; @@ -69,6 +71,7 @@ public void resetAnimator() { mainCircleView.hideView(); finishedOkView.hideView(); finishedFailureView.hideView(); + percentIndicatorView.reset(); resetAnimator = true; startAnimator(); } diff --git a/library/src/main/java/com/github/jlmd/animatedcircleloadingview/component/PercentIndicatorView.java b/library/src/main/java/com/github/jlmd/animatedcircleloadingview/component/PercentIndicatorView.java index a3070ca..efc6d46 100644 --- a/library/src/main/java/com/github/jlmd/animatedcircleloadingview/component/PercentIndicatorView.java +++ b/library/src/main/java/com/github/jlmd/animatedcircleloadingview/component/PercentIndicatorView.java @@ -3,6 +3,7 @@ import android.content.Context; import android.graphics.Color; import android.view.Gravity; +import android.view.View; import android.view.animation.AlphaAnimation; import android.widget.TextView; @@ -20,6 +21,7 @@ public PercentIndicatorView(Context context, int parentWidth) { } private void init() { + hideView(); int textSize = (35 * parentWidth) / 700; setTextSize(textSize); setTextColor(Color.WHITE); @@ -32,9 +34,24 @@ public void setPercent(int percent) { } public void startAlphaAnimation() { - AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); + AlphaAnimation alphaAnimation = new AlphaAnimation(0.8f, 0); alphaAnimation.setDuration(700); alphaAnimation.setFillAfter(true); startAnimation(alphaAnimation); } + + public void reset() { + hideView(); + setText(""); + clearAnimation(); + setAlpha(0.8f); + } + + public void hideView() { + setVisibility(View.INVISIBLE); + } + + public void showView() { + setVisibility(View.VISIBLE); + } }