From b65d6cc721ef284241f0bd061f85e35127a9c774 Mon Sep 17 00:00:00 2001 From: mortred Date: Tue, 21 Jun 2016 16:40:07 +0530 Subject: [PATCH 1/3] Added functionality to animate increase in mCurrentProgress --- .../example/MainActivity.java | 14 +----- gradle/wrapper/gradle-wrapper.properties | 2 +- .../numberprogressbar/NumberProgressBar.java | 50 ++++++++++++++++++- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java b/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java index f523a78..10ab7dd 100644 --- a/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java +++ b/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java @@ -22,21 +22,9 @@ public class MainActivity extends ActionBarActivity implements OnProgressBarList protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - bnp = (NumberProgressBar)findViewById(R.id.numberbar1); bnp.setOnProgressBarListener(this); - timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { - runOnUiThread(new Runnable() { - @Override - public void run() { - bnp.incrementProgressBy(1); - } - }); - } - }, 1000, 100); + bnp.setProgress(100,true,this); } @Override diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7113e2c..a6c8ca5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Tue Feb 24 10:50:01 CST 2015 +#Tue Jun 21 15:07:22 IST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/library/src/main/java/com/daimajia/numberprogressbar/NumberProgressBar.java b/library/src/main/java/com/daimajia/numberprogressbar/NumberProgressBar.java index 4379298..4e8c2ab 100644 --- a/library/src/main/java/com/daimajia/numberprogressbar/NumberProgressBar.java +++ b/library/src/main/java/com/daimajia/numberprogressbar/NumberProgressBar.java @@ -1,5 +1,7 @@ package com.daimajia.numberprogressbar; +import android.app.Activity; +import android.app.Application; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -11,6 +13,9 @@ import android.util.AttributeSet; import android.view.View; +import java.util.Timer; +import java.util.TimerTask; + import static com.daimajia.numberprogressbar.NumberProgressBar.ProgressTextVisibility.Invisible; import static com.daimajia.numberprogressbar.NumberProgressBar.ProgressTextVisibility.Visible; @@ -434,9 +439,50 @@ public void incrementProgressBy(int by) { } public void setProgress(int progress) { + setProgress(progress,false,null,0); + } + + /** + * Sets the NumberProgressBar to the required value, with optional animation + * @param progress the progress to be set + * @param animate whether change should be incremental (not sudden) + * @param activity the calling activity, may be left null in case of no animation + */ + public void setProgress(final int progress, boolean animate, final Activity activity){ + setProgress(progress,animate,activity,100); + } + + /** + * Sets the NumberProgressBar to the required value, with optional animation, with the increments at defined periods + * @param progress the progress to be set + * @param animate whether change should be incremental (not sudden) + * @param activity the calling activity, may be left null in case of no animation + * @param period amount of time in milliseconds between subsequent increments. + */ + public void setProgress(final int progress, boolean animate, final Activity activity, int period){ if (progress <= getMax() && progress >= 0) { - this.mCurrentProgress = progress; - invalidate(); + if(!animate || progressmCurrentProgress) + incrementProgressBy(1); + else { + timer.cancel(); + timer.purge(); + } + } + }); + } + }, 0, period); + } } } From c9f33e43bf7d35ed1aa29f591946a764c676a215 Mon Sep 17 00:00:00 2001 From: mortred Date: Tue, 21 Jun 2016 16:47:26 +0530 Subject: [PATCH 2/3] Bug fix --- .../daimajia/numberprogressbar/example/MainActivity.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java b/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java index 10ab7dd..bcd69ca 100644 --- a/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java +++ b/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java @@ -49,7 +49,11 @@ public boolean onOptionsItemSelected(MenuItem item) { @Override protected void onDestroy() { super.onDestroy(); - timer.cancel(); + try { + timer.cancel(); + } catch (Exception e) { + e.printStackTrace(); + } } @Override From 5da1355315248c19bcfa9d80fed4a42b98674bd3 Mon Sep 17 00:00:00 2001 From: acethepace Date: Fri, 24 Jun 2016 00:30:16 +0530 Subject: [PATCH 3/3] code cleanup --- .../numberprogressbar/example/MainActivity.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java b/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java index bcd69ca..8ee62e0 100644 --- a/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java +++ b/demo/src/main/java/com/daimajia/numberprogressbar/example/MainActivity.java @@ -1,7 +1,7 @@ package com.daimajia.numberprogressbar.example; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; @@ -9,12 +9,8 @@ import com.daimajia.numberprogressbar.NumberProgressBar; import com.daimajia.numberprogressbar.OnProgressBarListener; -import java.util.Timer; -import java.util.TimerTask; - -public class MainActivity extends ActionBarActivity implements OnProgressBarListener { - private Timer timer; +public class MainActivity extends AppCompatActivity implements OnProgressBarListener { private NumberProgressBar bnp; @@ -49,11 +45,6 @@ public boolean onOptionsItemSelected(MenuItem item) { @Override protected void onDestroy() { super.onDestroy(); - try { - timer.cancel(); - } catch (Exception e) { - e.printStackTrace(); - } } @Override