Giter Site home page Giter Site logo

snakebang007 / loadingbuttonandroid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leandroborgesferreira/loadingbuttonandroid

0.0 1.0 0.0 19.11 MB

A button to substitute the ProgressDialog

License: MIT License

Shell 1.72% Kotlin 98.03% Java 0.25%

loadingbuttonandroid's Introduction

Download Build Status

Hey, if you think this (or other of my projects) help you some how, please consider giving me some sponsorship: https://github.com/sponsors/leandroBorgesFerreira (Open source software can be quite a work haha)

Progress Button Android

enter image description here

Android Button that morphs into a loading progress bar.

  • Fully customizable in the XML
  • Really simple to use.
  • Makes your app looks cooler =D

You can check how this library was implemented here (Old version): https://medium.com/p/9efee6e39711/

Contents

Installation

implementation 'br.com.simplepass:loading-button-android:2.2.0'

How to use

Animate and revert animation

Add the button in your layout file and customize it the way you like it.

<br.com.simplepass.loadingbutton.customViews.CircularProgressButton
	android:id="@+id/btn_id"
	android:layout_width="match_parent"
	android:layout_height="wrap_content"
	android:background="@drawable/circular_border_shape" />
	app:spinning_bar_width="4dp" <!-- Optional -->
	app:spinning_bar_color="#FFF" <!-- Optional -->
	app:spinning_bar_padding="6dp" <!-- Optional -->

Then, instanciate the button

CircularProgressButton btn = (CircularProgressButton) findViewById(R.id.btn_id)
btn.startAnimation();

//[do some async task. When it finishes]
//You can choose the color and the image after the loading is finished
btn.doneLoadingAnimation(fillColor, bitmap);

//[or just revert de animation]
btn.revertAnimation();

You can also add a callback to trigger an action after the startAnimation has finished resizing the button :

btn.startAnimation {
	<start async task>
}

Switch to determinant progress

You can switch between indeterminant and determinant progress:

circularProgressButton.setProgress(10)
...
circularProgressButton.setProgress(50)
...
circularProgressButton.setProgress(100)

- Show 'done' animation

When the loading animation is running, call:

//Choose the color and the image that will be show
circularProgressButton.doneLoadingAnimation(fillColor, bitmap);

- Revert the loading animation with different text or image

progressButton.revertAnimation {
	progressButton.text = "Some new text"
}

or

progressImageButton.revertAnimation {
	progressImageButton.setImageResource(R.drawable.image)
}

- Button State

This button is a state machine and it changes its state during the animation process. The states are:

Before Draw

This state is the initial one, the button is in this state before the View is draw on the screen. This is the state when the button is accesed in the onCreate() of an Activity.

Idle

After the button is drawn in the screen, it gets in the Idle state. It is basically waiting for an animation. Call startAnimation() to start animations with this button.

WAITING_PROGRESS

If the startAnimation() is called before the Idle state, the button goes to this state. The button waits for the button to be drawn in the screen before start the morph animation.

MORPHING

The button stays in this state during the morphing animation.

PROGRESS

After the morph animation, the button start the progress animation. From this state the done and revert animations can happen.

MORPHING_REVERT

The button stays in this state during the morphing animation reversal.

WAITING_DONE

If the doneLoadingAnimation(fillColor: Int, bitmap: Bitmap) is called when the button is still morphing, it enter in this state. The button waits for the morph animation to complete and then start the done animation.

DONE

The button enters this state when the doneLoadingAnimation finishes.

WAITING_TO_STOP

The button enters this state when the stopAnimation() is called before the morph state is completed. The button waits for the morph animation to complete and the stops further animations.

STOPPED

The button enters this state after stopAnimation() when the button is not morphing.

Configure XML

  • app:spinning_bar_width : Changes the width of the spinning bar inside the button
  • app:spinning_bar_color: Changes the color of the spinning bar inside the button
  • app:spinning_bar_padding: Changes the padding of the spinning bar in relation of the button bounds.
  • app:initialCornerAngle: The initial corner angle of the animation. Insert 0 if you have a square button.
  • app:finalCornerAngle: The final corner angle of the animation.

Problems and troubleshooting

Manifest merge

This library only supports androidx since prior the version 2.0.0. So don't try to use it with the old Support Library. Use androidx instead.

Avoid Memory Leaks

Prior to version 2.1.0, to avoid memory leaks is your code, you must dispose the buttons in the onDestroy method. Example:

override fun onDestroy() {
        super.onDestroy()
	progressButton.dispose()
}

In version 2.1.0, ProgressButton was updated to be a LifecycleObserver and will automatically call dispose() when an onDestroy() event is observed by the lifecycle owner.

Contributing

###Setup Git Pre-commit hook script (Optional)

The purpose of setting up this optional pre-commit hook is so that the lintKotlin Gradle task runs each time you as a developer create a commit. Although the Travis build will run lintKotlin in the cloud, running this locally will allow you to catch Kotlin Lint violations early in the development cycle without having to wait for Travis's build report.

To enable the script, execute the following commands starting from the project's root directory:

cd .git/hooks
ln -s ../../scripts/pre-commit.sh pre-commit     

Bugs and Feedback

For bugs, feature requests, and discussion please use GitHub Issues.

Credits

This library was inspired in this repo: https://github.com/dmytrodanylyk/android-morphing-button

And that's it! Enjoy!

loadingbuttonandroid's People

Contributors

bors[bot] avatar cdongieux avatar flo5324 avatar jachenry avatar jbmlaird avatar jguerinet avatar leandroborgesferreira avatar netodevel avatar nicolasducom avatar przemekpan avatar rayliverified avatar shahimclt avatar sinadalvand avatar spichen avatar wokkaflokka avatar yazdipour avatar zinokader avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.