很酷的Android下载进度条:DownloadProgressBar

jopen 9年前

一个带有很酷动画的Android进度条,设计源于https://dribbble.com/shots/2012292-Download-Animation


Download Progress Bar Animation

Download Progress Bar Animation


Attributes

Attribute Type Usage
app:circleRadius dimension The dimension of the circle radius
app:strokeWidth dimension The dimension of the circle stroke width
app:lineWidth dimension Color used for the progress completed
app:progressDuration integer Duration of progress. Default value is set to 1000 ms
app:resultDuration integer Duration of result, either success and error. Default set to 4000 ms
app:overshootValue dimension Value of overshoot interpolator (used for popping up the circle)
app:drawingColor color Color used for drawing inside drawables (white on gif)
app:progressColor color Color used for drawing the progress (white on gif)
app:circleBackgroundColor color Color used for drawing background circle (light blue on gif)
app:progressBackgroundColor color Color used for drawing progress background (light blue on gif)

下载

repositories {      maven {          url "https://jitpack.io"      }  }    dependencies {      compile 'com.github.panwrona:DownloadProgressBar:1.0'  }

用法

首先需要区别的是两种结果:成功和失败。要播放成功动画,调用下面的一行代码:

DownloadProgressBar downloadProgressBar = (DownloadProgressBar)findViewById(R.id.download_progress_view);  downloadProgressBar.playToSuccess();

如果想播放错误动画,调用:

DownloadProgressBar downloadProgressBar = (DownloadProgressBar)findViewById(R.id.download_progress_view);  downloadProgressBar.playToError();

同时我还添加了常用事件的listener:whole animation start, whole animation end, progress update, animation success, animation error。要实现他们,如下:

downloadProgressBar.setOnProgressUpdateListener(new DownloadProgressBar.OnProgressUpdateListener() {              @Override              public void onProgressUpdate(float currentPlayTime) {                  // Here we are setting % value on our text view.                  successTextView.setText(Math.round(currentPlayTime / 3.6) + " %");              }                @Override              public void onAnimationStarted() {                  // Here we are disabling our view because of possible interactions while animating.                  downloadProgressBar.setEnabled(false);              }                @Override              public void onAnimationEnded() {                  successTextView.setText("Click to download");                  downloadProgressBar.setEnabled(true);              }                @Override              public void onAnimationSuccess() {                  successTextView.setText("Downloaded!");              }                @Override              public void onAnimationError() {                }          });

项目主页:http://www.open-open.com/lib/view/home/1435633863200