项目作者: abdularis

项目描述 :
Provides download button progress view for android
高级语言: Java
项目地址: git://github.com/abdularis/AndroidButtonProgress.git
创建时间: 2018-01-05T11:02:48Z
项目社区:https://github.com/abdularis/AndroidButtonProgress

开源协议:

下载


AndroidButtonProgress

Android Arsenal
API

This is a combination of button and progress bar. There are 4 states in this view first Idle, Indeterminate, Determinate and Finish. it makes you easy to manage download button state in your app ui.

In a download case you can use this as.

  • 1st show download button to the user
  • 2nd show indeterminate progress bar, it tells the user that the download is connecting.
  • 3rd show determinate progress bar, which tells the user that the download is progressing
  • 4th show finish button/icon

Demo

demo

Usage

Use jitpack

  1. allprojects {
  2. repositories {
  3. maven { url 'https://jitpack.io' }
  4. }
  5. }

Gradle

  1. dependencies {
  2. implementation 'com.github.abdularis:androidbuttonprogress:1.1.0'
  3. }

Please always use same width and height for this button progress view

  1. <com.github.abdularis.buttonprogress.DownloadButtonProgress
  2. android:layout_width="45dp"
  3. android:layout_height="45dp"></com.github.abdularis.buttonprogress.DownloadButtonProgress>

sc1

You can also

  1. <com.github.abdularis.buttonprogress.DownloadButtonProgress
  2. android:layout_width="72dp"
  3. android:layout_height="72dp"
  4. app:progressIndeterminateSweepAngle="1"
  5. app:state="INDETERMINATE"></com.github.abdularis.buttonprogress.DownloadButtonProgress>

demo1

Use custom drawable for every state

  1. <com.github.abdularis.buttonprogress.DownloadButtonProgress
  2. android:id="@+id/button_progress_2"
  3. android:layout_width="64dp"
  4. android:layout_height="64dp"
  5. android:layout_marginTop="20dp"
  6. app:idleIconDrawable="@drawable/ic_download"
  7. app:idleBackgroundDrawable="@drawable/bg_button_progress"
  8. app:cancelIconDrawable="@drawable/ic_cancel"
  9. app:indeterminateBackgroundDrawable="@drawable/bg_button_progress"
  10. app:progressIndeterminateColor="#828282"
  11. app:determinateBackgroundDrawable="@drawable/bg_button_progress"
  12. app:progressDeterminateColor="#ef2241"
  13. app:finishIconDrawable="@drawable/ic_finish"
  14. app:finishBackgroundDrawable="@drawable/bg_button_progress"></com.github.abdularis.buttonprogress.DownloadButtonProgress>

sc1

Note: you can use DownloadButtonProgress as upload button too just replace the idle download icon with upload icon! :)

Click listener

  1. DownloadButtonProgress btn = findViewById(R.id.button_progress_id);
  2. btn.addOnClickListener(new DownloadButtonProgress.OnClickListener() {
  3. @Override
  4. public void onIdleButtonClick(View view) {
  5. // called when download button/icon is clicked
  6. }
  7. @Override
  8. public void onCancelButtonClick(View view) {
  9. // called when cancel button/icon is clicked
  10. }
  11. @Override
  12. public void onFinishButtonClick(View view) {
  13. // called when finish button/icon is clicked
  14. }
  15. });

Attributes

attrs for DownloadButtonProgress

  1. <declare-styleable name="DownloadButtonProgress">
  2. <attr name="state" format="enum">
  3. <enum name="IDLE" value="1"></enum>
  4. <enum name="INDETERMINATE" value="2"></enum>
  5. <enum name="DETERMINATE" value="3"></enum>
  6. <enum name="FINISHED" value="4"></enum>
  7. </attr>
  8. <attr name="cancelable" format="boolean"></attr>
  9. <attr name="progressIndeterminateSweepAngle" format="integer"></attr>
  10. <attr name="idleBackgroundColor" format="color"></attr>
  11. <attr name="finishBackgroundColor" format="color"></attr>
  12. <attr name="indeterminateBackgroundColor" format="color"></attr>
  13. <attr name="determinateBackgroundColor" format="color"></attr>
  14. <attr name="idleBackgroundDrawable" format="reference"></attr>
  15. <attr name="finishBackgroundDrawable" format="reference"></attr>
  16. <attr name="indeterminateBackgroundDrawable" format="reference"></attr>
  17. <attr name="determinateBackgroundDrawable" format="reference"></attr>
  18. <attr name="progress" format="integer"></attr>
  19. <attr name="maxProgress" format="integer"></attr>
  20. <attr name="progressWidth" format="dimension"></attr>
  21. <attr name="progressMargin" format="dimension"></attr>
  22. <attr name="progressDeterminateColor" format="color"></attr>
  23. <attr name="progressIndeterminateColor" format="color"></attr>
  24. <attr name="idleIconDrawable" format="reference"></attr>
  25. <attr name="idleIconWidth" format="dimension"></attr>
  26. <attr name="idleIconHeight" format="dimension"></attr>
  27. <attr name="cancelIconDrawable" format="reference"></attr>
  28. <attr name="cancelIconWidth" format="dimension"></attr>
  29. <attr name="cancelIconHeight" format="dimension"></attr>
  30. <attr name="finishIconDrawable" format="reference"></attr>
  31. <attr name="finishIconWidth" format="dimension"></attr>
  32. <attr name="finishIconHeight" format="dimension"></attr>
  33. </declare-styleable>

License

No