Giter VIP home page Giter VIP logo

loadingbuttonandroid's Introduction

Java CI with GradleMaven Central

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("com.github.leandroborgesferreira:loading-button-android:2.3.0")

How to use

Animate and revert animation

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

<com.github.leandroborgesferreira.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

Animation

This library only works with selector as the background, but not with shape as the root tag. Please put your shape inside a selector, like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:state_selected="false">
    <shape android:shape="rectangle">
        <corners android:radius="10dp" />
        <solid android:color="@android:color/transparent" />
        <stroke android:width="3dp"
            android:color="@color/black"/>
    </shape>
</item>
</selector>

I still need to debug this problem.

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 mehrab832 avatar netodevel avatar nicolasducom avatar przemekpan avatar rayliverified avatar shahimclt avatar sinadalvand avatar spichen avatar wokkaflokka avatar yazdipour avatar zinokader avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loadingbuttonandroid's Issues

Fetch Location Using LoadingButtonAndroid

hey, I want to use this loading button as a progress dialog.
Means I want when user clicks it then i should fetch lat long and user should not interact with the activity and when the lat long are successfully fetched then the loading of this button should stop. How i can do that ?
Mainly i want the functionality of progress dialog with this loading button.

If i use asyn task still the user can interact with the activity...

Animation disappears on rotation

If I rotate the screen while the button is in progress, the button completely disappears even though I call startAnimation straight after orientation change happened. When I try to debug startAnimation in that case, in the following code mParams.mInitialWidth = getWidth();
mParams.mInitialHeight = getHeight();
getWidth() and getHeight() both return 0.
Should I do something special in order to make the button remember its state on orientation change?

Keep background resource border on doneLoadingAnimation

Hi, I am trying to keep the border (stroke) of my custom background when doneLoadingAnimation is called. Instead, I can only select the same color of my custom background but the stroke is lost in the process.

My custom background (request_button_background.xml) is:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="12dp" />
    <solid android:color="@color/green" />
    <stroke
        android:width="1.5dp"
        android:color="@color/colorPrimaryDark" />
    <padding
        android:bottom="10dp"
        android:left="10dp"
        android:right="10dp"
        android:top="10dp" />
</shape>

My CircularProgressButton is defined as:

<br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
        android:id="@+id/btn_request"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:elevation="30dp"
        android:textAlignment="center"
        android:background="@drawable/request_button_background"
        android:layout_marginEnd="20dp"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|right"
        app:spinning_bar_width="4dp"
        app:spinning_bar_color="@color/white"
        app:spinning_bar_padding="2dp"
        android:paddingStart="20dp"
        android:paddingEnd="20dp"
        android:textSize="15sp"
        android:textColor="@color/black"
        android:textAllCaps="false"
        android:text="Request RSVP"/>

Finally I call the doneLoadingAnimation as follows

btn.doneLoadingAnimation(ContextCompat.getColor(EventInfoActivity.this, R.color.green),
                                        BitmapFactory.decodeResource(EventInfoActivity.this.getResources(),
                                        R.drawable.ic_check2));

Thanks for the support and the awesome library.

Bernat

Width and colors in XML are not working

This is my xml, and the spinning is still black and the button is still full width of the layout

 <br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
        android:id="@+id/pointsButton"
        android:layout_width="150dp" (or wrap_content)
        android:layout_height="wrap_content"
        android:background="@color/blue"
        android:text="Sumar"
        android:layout_marginTop="15dp"
        android:layout_below="@id/number_picker"
        android:textColor="@color/white"
        android:layout_centerHorizontal="true"
        app:spinning_bar_color="@color/white"
        app:spinning_bar_width="4dp"/> 

Change background color in use

Hi,
When I change background color of the CircularProgressButton in use, the button doesn't get round during animation.
Here is my xml:
<br.com.simplepass.loading_button_lib.customViews.CircularProgressButton android:id="@+id/valider_date_livraison" android:layout_width="match_parent" android:layout_height="40dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:background="@color/bleu" android:text="SUIVANT" android:textColor="@color/blanc" android:textSize="16dp" app:font="Gotham-Bold.otf" app:spinning_bar_width="3dp" app:spinning_bar_color="@color/blanc" app:spinning_bar_padding="6dp" app:initialCornerAngle="0dp"> </br.com.simplepass.loading_button_lib.customViews.CircularProgressButton>

And here is the change of background color in the code:
valider_date_livraison.setBackgroundColor(Color.GREEN);

see the result on animation start:
screenshot_20171215-014547

Thanks for your help,
Théo

How to make the button return to it's previous state?

I have successfully implemented this library in my dem app but now what I want is the button to go back to it's state before pressing it. Similar to what is displayed on the main page of this library. This is my code so far:

circularProgressButton = (CircularProgressButton) findViewById(R.id.sign_in_button);

        circularProgressButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AsyncTask<String, String, String> signInActivity = new AsyncTask<String, String, String>() {
                    @Override
                    protected String doInBackground(String... params) {
                        try{
                            Thread.sleep(3000);
                        } catch (InterruptedException e){
                            e.printStackTrace();
                        }
                        return "done";
                    }

                    @Override
                    protected void onPostExecute(String s) {
                        if(s.equals("done")){
                                circularProgressButton.doneLoadingAnimation(Color.parseColor("#FF4081"), BitmapFactory.decodeResource(getResources(), R.drawable.ic_done_white_48dp));
                                Toast.makeText(MainActivity.this, "Welcome!", Toast.LENGTH_SHORT).show();
                        }
                    }
                };
                circularProgressButton.startAnimation();
                signInActivity.execute();
            }
        });

I am trying to implement this for my login functionality. I want the button to go back to it's initial state but I can't understand how is it possible here?
Any help here would be appreciated!

Animation doesn't work with theme attribute

I tried to use the "theme" attribute on a CircularProgressButton but it does not animate the button to a full circle. It remains a rectangle and the progressbar starts to spin. As soon as I remove the "theme" attribute, it starts to work again like a charm

Button doesn't resize to the center.

the button resize all the way from right to left. the progress end up being on the left part of the screen looking awful

<android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/ivHeader"
        android:layout_marginTop="-26dp"
        android:background="@mipmap/bg_logincard"
        android:elevation="15dp"
        android:orientation="vertical">
                     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="32dp"
            android:layout_marginStart="32dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout">

            <br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
                android:id="@+id/btnLogin"
                style="@style/BoldFont"
                android:layout_gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/selector_btn_rounded"
                android:paddingBottom="16dp"
                android:paddingTop="16dp"
                android:text="@string/session_btnlbl_login"
                android:textAllCaps="false"
                android:textColor="@color/text_btn_light"
                android:textSize="17sp"
                app:spinning_bar_color="#FFF"
                app:spinning_bar_padding="6dp"
                app:spinning_bar_width="4dp"
                app:finalCornerAngle="90dp"
                app:initialCornerAngle="90dp"
                android:gravity="center"
                >

            </br.com.simplepass.loading_button_lib.customViews.CircularProgressButton>

        </LinearLayout>
</android.support.constraint.ConstraintLayout>

Merger Manifest Failed

Unable to use library in project due to manifest merger failure. Perhaps increasing the Build Tools version to 25.0.2 will fix the problem?

Not working in ContraintLayout with left and right contraints

`<br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
android:id="@+id/submit_settings"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_margin="dimen/activity_layout_margin"
android:background="drawable/button_submit"
android:onClick="onClick"
android:text="string/api_settings_submit"
android:textColor="color/colorWhite"

        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/secret_layout"

        android:scaleType="fitCenter"
        android:src="drawable/ic_checkmark"
        app:spinning_bar_padding="0dp"
        app:spinning_bar_color="@color/colorBlack"
        app:spinning_bar_width="3dp"
        app:initialCornerAngle="0dp"
        app:finalCornerAngle="0dp" />

</android.support.constraint.ConstraintLayout>`

saveButton.doneLoadingAnimation( ContextCompat.getColor(getApplicationContext(), R.color.colorBlack), BitmapFactory.decodeResource(getResources(), R.drawable.ic_checkmark));

When the contraints are set on left and right, after calling the doneLoadingAnimation. the image/bitmap is stretched out.

Crash when calling doneLoagingAnimation before start animation ends

When calling doneLoagingAnimation after startAnimation(), but before the start animation has ended, the application crashes on a nullpointer:

Attempt to invoke virtual method 
'void br.com.simplepass.loading_button_lib.animatedDrawables.CircularAnimatedDrawable.stop()' on a null object reference at
br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.doneLoagingAnimation(CircularProgressButton.java:228)

As said, it happens in the following situation:

  • The button starts animating using startAnimation()
  • The loading animation is stopped using doneLoagingAnimation(params) before the initial start animation has ended (button getting narrower)

In my case I'm running an async task that finishes really quick. Because the button depends on its own start animation, this might be an issue that can arise anytime; especially when using wide buttons on tablet and devices get faster in the future.

Another tiny note: is doneLoagingAnimation a typo? (Loaging vs Loading)

Animation is not smooth

When starting the animation it morphs in a circle but progress border stops in between. Any way around?

revertAnimation only change background but not image and spinningbar color

I using CircularProgressImageButton. Then when I call revertAnimation with callback, only is changed the background, isn't changing ImageDrawable and SpinningBarColor.

btnPersonFollow.revertAnimation(new OnAnimationEndListener() {
            @Override
            public void onAnimationEnd() {
                boolean followingOrPending = Arrays.asList(FollowStatus.FollowStatusAccepted, FollowStatus.FollowStatusPending, FollowStatus.FollowStatusRejected).contains(getPerson().followingStatus);
                if (followingOrPending) {
                    btnPersonFollow.setBackgroundResource(R.drawable.bg_button_following);
                    btnPersonFollow.setImageResource(R.drawable.person_check);
                    btnPersonFollow.setSpinningBarColor(ResourcesCompat.getColor(viewHolder.itemView.getResources(),R.color.suda_blue_medium,null));

                } else {
                    btnPersonFollow.setBackgroundResource(R.drawable.bg_button_following_outline);
                    btnPersonFollow.setImageResource(R.drawable.person_add);
                    btnPersonFollow.setSpinningBarColor(ResourcesCompat.getColor(viewHolder.itemView.getResources(),R.color.suda_cyan,null));
                }
            }
        });

Unable to merge dex

I tried many ways to get around this with no success and I tried Invalidate cache & tried to change compile sdk from 26 to 27, the same problem
This is the error I get:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

and this is my dependencies

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:0.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    //retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

    //circular image view
    implementation 'com.mikhaellopez:circularimageview:3.0.2'

    //Matisse selector
    implementation 'com.zhihu.android:matisse:0.4.3'
    implementation 'net.alhazmy13.MediaPicker:libary:2.4.0'

    //swipe left recycle view
    implementation 'com.tubb.smrv:swipemenu-recyclerview:5.4.0'

    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    //animation library
    implementation 'com.wang.avi:library:2.1.3'
    //Ok http
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    //Glide
    implementation 'com.github.bumptech.glide:glide:4.0.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
    //loading button
    implementation 'br.com.simplepass:loading-button-android:1.14.0'

    implementation 'com.android.support:multidex:1.0.3'
}

CircularProgressButton doesn't work with gradient_button.xml

The CircularProgressButton won't work correctly with my gradient_button.xml background. In fact it doesn't change the color when I click on it. So it simply doesn't execute the android:state_pressed="true" part... Using this gradient_button.xml for a default button, it works perfectly.

layout_main.xml

<br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
        android:id="@+id/buttonCircle"
        android:text="Register Device"
        app:spinning_bar_color="#fff"
        app:spinning_bar_padding="6dp"
        app:spinning_bar_width="4dp"
        app:initialCornerAngle="24dp"
        style="@style/button"
        />

style.xml

    <style name="button">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">20sp</item>
        <item name="android:layout_marginTop">30dp</item>
        <item name="android:background">@drawable/gradient_button</item>
        <item name="android:paddingStart">35dp</item>
        <item name="android:paddingEnd">11dp</item>
        <item name="android:drawableEnd">@drawable/ic_navigate_next_24dp</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

gradient_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid
                android:color="@color/lightgreen" />

            <corners
                android:radius="24dp" />

            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid
                android:color="@color/green" />

            <corners
                android:radius="24dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>

Latest version

I am not able to find latest version to add in gradle file. Can anyone please help me out?

java.lang.NullPointerException on emulator running 19 api

The library works on android 5.1 and above(both emulators and real phones) and there is no problem. However, when I ran my app on the emulator(19 level API), the app got crashed.
I don't know whether there is the same problem on the real phone running 19 API.

Stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.app.test, PID: 4578 java.lang.NullPointerException at android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:505) at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:487) at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:517) at android.animation.ValueAnimator.start(ValueAnimator.java:936) at android.animation.ValueAnimator.start(ValueAnimator.java:946) at android.animation.ObjectAnimator.start(ObjectAnimator.java:465) at android.animation.AnimatorSet.start(AnimatorSet.java:563) at br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.d(CircularProgressButton.java:513) at com.app.test.MainActivity.m(MainActivity.java:123) at com.app.test.MainActivity.onClick(MainActivity.java:54) at android.view.View.performClick(View.java:4438) at android.view.View$PerformClick.run(View.java:18422) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)

The app crashes at line circularProgressButton.startAnimation();

Is the library compatible with emulators? And does it work with prelollipop devices?

error when startanimation()

Beautiful animation. I have a problem when init call mBtLogin.startAnimation(), animation not load full in onCreate. I fix it as put startAnimation in a Handler().postdelay. How to direct call startAnimation() when start app.
Thanks.

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       CircularProgressButton mBtLogin = (CircularProgressButton) findViewById(R.id.progress_btn_change_activity);
        mBtLogin.startAnimation();
        /*new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mBtLogin.startAnimation();
            }
        }, 100);*/
}

Selector and fontFamily ignored

Hello, nice library, I do have some issues though:

I have a custom font but android:fontFamily on the button is completely ignored.
I also have a custom selector for the button background with rounded corners that doesn't seem to work. The button stays gray like it is constant in the enabled=false state.
When I remove the first item in my selector then the button has the right color, but doesn't take the other color when pressed.
Hope those issues can be resolved.

So long

    <br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="16dp"
        android:background="@drawable/rounded_corners_button"
        android:fontFamily="@font/brandon_bold"
        android:text="@string/login"
        android:textColor="@color/black"
        app:spinning_bar_color="@color/black"
        app:spinning_bar_padding="6dp"
        app:spinning_bar_width="4dp"/>`
<item android:state_enabled="false">
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="@color/midLightGray"/>
        <corners
            android:bottomLeftRadius="2dp"
            android:bottomRightRadius="2dp"
            android:topLeftRadius="2dp"
            android:topRightRadius="2dp"/>
    </shape>
</item>


<item android:state_pressed="true">
    <shape>
        <solid android:color="@color/primaryDark"/>
        <corners
            android:bottomLeftRadius="2dp"
            android:bottomRightRadius="2dp"
            android:topLeftRadius="2dp"
            android:topRightRadius="2dp"/>
    </shape>
</item>

<item android:state_focused="true">
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="@color/primary"/>
        <corners
            android:bottomLeftRadius="2dp"
            android:bottomRightRadius="2dp"
            android:topLeftRadius="2dp"
            android:topRightRadius="2dp"/>
    </shape>
</item>

<item android:state_focused="false">
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="@color/primary"/>
        <corners
            android:bottomLeftRadius="2dp"
            android:bottomRightRadius="2dp"
            android:topLeftRadius="2dp"
            android:topRightRadius="2dp"/>
    </shape>
</item>

<item android:state_pressed="false">
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="@color/primary"/>
        <corners
            android:bottomLeftRadius="2dp"
            android:bottomRightRadius="2dp"
            android:topLeftRadius="2dp"
            android:topRightRadius="2dp"/>
    </shape>
</item>

Alterar Texto do Botão

Como faz pra mudar o texto do botão após uma animação? Após um revertAnimation() eu não consigo alterar o texto do botão.

Error inflating class br.com.simplepass.loading_button_lib.customViews.CircularProgressButton

Hi,

I'm trying to use the CircularProgressButton, but I receive this error:

 Caused by: android.view.InflateException: Binary XML file line #147: Binary XML file line #147: Error inflating class br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
 Caused by: android.view.InflateException: Binary XML file line #147: Error inflating class br.com.simplepass.loading_button_lib.customViews.CircularProgressButton

This is my XML:

 <br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
        android:id="@+id/login"
        style="?android:attr/borderlessButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="15dp"
        android:background="@drawable/button_rectangle"
        android:text="Accedi"
        android:textAllCaps="false"
        android:textColor="@drawable/text_color_button"
        android:textSize="18sp" />

Could you help me? Thanks

Memory leaks?

Hi,

Using https://github.com/square/leakcanary, I've got sometimes report of memory leaks; but I don't succeed to reproduce it all times.

I can't share you a full details (privacy issues), only the trace of leak.

Thanks,

Regards


* my.awesome.android.app.AwesomeActivity has leaked:
* GC ROOT org.chromium.ui.base.ActivityWindowAndroid.mVSyncMonitor
* references org.chromium.ui.VSyncMonitor.mChoreographer
* references android.view.Choreographer.mCallbackQueues
* references array android.view.Choreographer$CallbackQueue[].[1]
* references android.view.Choreographer$CallbackQueue.mHead
* references android.view.Choreographer$CallbackRecord.action
* references android.animation.AnimationHandler$1.this$0 (anonymous implementation of android.view.Choreographer$FrameCallback)
* references android.animation.AnimationHandler.mAnimationCallbacks
* references java.util.ArrayList.elementData
* references array java.lang.Object[].[0]
* references android.animation.AnimatorSet.mNodeMap
* references android.util.ArrayMap.mArray
* references array java.lang.Object[].[2]
* references android.animation.ValueAnimator.mUpdateListeners
* references java.util.ArrayList.elementData
* references array java.lang.Object[].[0]
* references br.com.simplepass.loading_button_lib.animatedDrawables.CircularAnimatedDrawable$3.this$0 (anonymous implementation of android.animation.ValueAnimator$AnimatorUpdateListener)
* references br.com.simplepass.loading_button_lib.animatedDrawables.CircularAnimatedDrawable.mAnimatedView
* references br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.mContext
* leaks my.awesome.android.app.AwesomeActivity instance

* Retaining: 1.00 MB.
* Reference Key: SOMETHING_THAT_LOOKS_LIKE_UUID_V4
* Device: Google google Android SDK built for x86 sdk_gphone_x86
* Android Version: 8.0.0 API: 26 LeakCanary: 1.5.1 1be44b3
* Durations: watch=5012ms, gc=116ms, heap dump=602ms, analysis=9154ms

Not showing up inside fragment

I put the button xml inside a FrameLayout since I am using fragments. It shows up in the Android Studio Preview window but doesn't show up in emulator or actual device. However when I move this to activity layout file with a CoordinatorLayout parent, it shows up there.

Custom fonts not displayed

Hi!
I need help with custom fonts. On Preview (in Android Studio) works fine but when I build and launch on emulator it's not.
loading_button_preview

Use .png as background

Is it possible to use .png or VectorDrawable as button background?
When I try to do so, it looks like this:
bcb3bf31-7b48-4f89-86fb-f294a4db5de7

even though corner angle was specified:

        circular:finalCornerAngle="50dp"
        circular:initialCornerAngle="0dp" // also tried "50dp"

Can I make it round circular after calling .startAnimation(); and then return back to rectangular shape after .revertAnimation(); ?

BTW done state also looks strange:
94f1db19-7f84-4b89-9ae0-b6d2d78a5c97

Button do not morph when not using background attribute

Button does not morph when we don't set any background to the button.
Here is my xml

<br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
                    android:id="@+id/welcome_signin_button"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="@dimen/form_horizontal_margin"
                    android:theme="@style/AppTheme.Button"
                    style="@style/progressButtonStyle"
                    android:text="@string/welcome_signin_cta"
                    />

And here is the styles applyed

<style name="AppTheme.Button">
        <item name="android:textAllCaps">false</item>
        <item name="android:colorButtonNormal">?attr/colorAccent</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:textStyle">bold</item>
    </style>


    <style name="progressButtonStyle" parent="Widget.AppCompat.Button">
        <item name="finalCornerAngle">50dp</item>
        <item name="initialCornerAngle">2dp</item>
        <item name="spinning_bar_color">@color/white</item>
        <item name="spinning_bar_padding">4dp</item>
        <item name="spinning_bar_width">2dp</item>
    </style>

Memory leak on button press

Great library. Looks great.

I got a 49KB memory leak when having two of these buttons in an Activity. I clicked on both of them and they did the full item animation.

btnCollection.startAnimation();

...

btnCollection.revertAnimation(() ->
{
    if (inCollection)
        btnCollection.setText("Remove from Collection");
    else
        btnCollection.setText("Add to Collection");
    });

I thought it might be due to assigning the OnAnimationEndListener but when I tried with:

btnCollection.revertAnimation();
btnCollection.setText("Remove from Collection");

I also got the 49KB leak.

EDIT: The leak does not occur if I do not press the button

Any ideas?

LeakCanary log:

loadingbuttonmemoryleak.txt

blinking while progress

Hello!

While progress, the arc is blinking. It's like a new step when it becomes it's min size and then become full size and immediately min again and begin the growing.

Tested on android simulator API 25

Cannot see the button on device.

I can see the button in Android Studio XML(Preview) but when I run the code on my mobile I cannot see the button on my screen. Please help me with it. Thanks

Button is not going to the center

I've already tried almost everything... but the progress keeps starting at the start position of the button and not in the center as it should..

(você é br, então... quando clico no botão, ao invés do progress ir pro meio da tela, ele fica no começo!!!)

Button with shadow like cardview

I want to use the button with shadow same like material CardView. I this possible with this library? or any alternative solution?

loadingButton.revertAnimation() NullpointerException

Hi, i found a issue in your library when i use .revertAnimation() method.
If i use twice the method on a button, nullpointerException occurred. Why?

the message:
"Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.revertAnimation(CircularProgressButton.java:279)"

Manifest merge cause by min sdk version

Hello,
Why min sdk version is 17 ? i couldn't add to my project that have min sdk 16

Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 17 declared in library [br.com.simplepass:loading-button-android:1.8.1] C:\Users\hptn.gradle\caches\transforms-1\files-1.1\loading-button-android-1.11.1.aar\09162386e44c5299c9cec1c77f0f0787\AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 17,
or use tools:overrideLibrary="br.com.simplepass.loading_button_lib" to force usage (may lead to runtime failures)

any solution ?
thanks

startAnimation not working in release mode

In Debug mode its is working but when i build for release mode the circle animation is not showing.
any suggestions?

I tried to add in proguard-rules to keep CircularProgressButton but never worked.

Usage in viewholder for recyclerview

Might be related #17...

Original view: capture d ecran 2017-08-25 a 14 15 34
View reused/recycled: got original + done loading image+filled color capture d ecran 2017-08-25 a 14 15 40

If I use dispose when the view is unbind, setupAnimations() is never called again. It will not work...

The only way I think to fix the problem, right now, is to instantiate a new view from code instead from layout...

Not tested yet, I will soon

Edit:

Setting up the Button programmatically, without attributes (new CircularProgressButton(context)) thrown exception:

java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.GradientDrawable
    at br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.init(CircularProgressButton.java:115)
    at br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.<init>(CircularProgressButton.java:63)

NullPointerException when calling doneLoadingAnimation

Well, I get a NPE when calling doneLoadingAnimation. I don't get it why, actually I have some more buttons in different fragments and they are working perfectly. If I debug and compare both circularProgressButton variables, they don't have any difference. circularProgressButton is not Null.
Used version 1.8.4 and 1.12.0.

Edit: I have a callback/interface in the AsyncTask to the Fragment, which will then call this method. I guess this could be the issue?, but actually I am doing the same in the other fragments...

  E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.sample.lexycon, PID: 16270
                  java.lang.NullPointerException: Attempt to invoke virtual method 'void br.com.simplepass.loading_button_lib.animatedDrawables.CircularRevealAnimatedDrawable.draw(android.graphics.Canvas)' on a null object reference
                      at br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.drawDoneAnimation(CircularProgressButton.java:316)
                      at br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.onDraw(CircularProgressButton.java:232)
                      at android.view.View.draw(View.java:18319)
                      at android.view.View.updateDisplayListIfDirty(View.java:17297)
                      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3950)
                      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3930)
                      at android.view.View.updateDisplayListIfDirty(View.java:17260)
                      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3950)
                      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3930)
                      at android.view.View.updateDisplayListIfDirty(View.java:17260)
                      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3950)
                      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3930)
                      at android.view.View.updateDisplayListIfDirty(View.java:17260)
                      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3950)
                      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3930)
                      at android.view.View.updateDisplayListIfDirty(View.java:17260)
                      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3950)
                      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3930)
                      at android.view.View.updateDisplayListIfDirty(View.java:17260)
                      at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3950)
                      at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3930)
                      at android.view.View.updateDisplayListIfDirty(View.java:17260)
                      at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:666)
                      at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:672)
                      at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:780)
                      at android.view.ViewRootImpl.draw(ViewRootImpl.java:3112)
                      at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2908)
                      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2502)
                      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1509)
                      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7051)
                      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
                      at android.view.Choreographer.doCallbacks(Choreographer.java:702)
                      at android.view.Choreographer.doFrame(Choreographer.java:638)
                      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
                      at android.os.Handler.handleCallback(Handler.java:751)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6692)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

stopAnimation not working

When i call stopAnimation() (without calling revertAnimation()) the animation does not stop and the loading progress continues running.

Here's my code:

 followButton.startAnimation();
 final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // Do something after 5s = 5000ms
                        followButton.stopAnimation();
                        followButton.setText("\u2713");
                        followButton.setTextSize(18);
                    }
                }, 5000);

Button not coming in center when animating

Hi, I tried to use this library. The button is on the left but not coming to center when the animation starts. I've used the Second Activity layout and copied a button from MainActivity.kt to SecondActivity.kt

ezgif com-video-to-gif

ClassCastException for Drawable in CircularProgressButton

Running your code on an Android 6 Device with Kotlin and Anko, I get the following error:

Caused by: java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.GradientDrawable
    at br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.init(CircularProgressButton.java:116)
    at br.com.simplepass.loading_button_lib.customViews.CircularProgressButton.<init>(CircularProgressButton.java:64)
    at com.example.anko.loadingbutton.CircularprogresbuttonKt.circularProgressButton(circularprogresbutton.kt:9)
    at com.example.app.ui.LoginActivityUi.createView(loginactivity.kt:95)
    at com.example.app.ui.LoginActivityUi.createView(loginactivity.kt:55)
    at org.jetbrains.anko.AnkoContextKt.setContentView(AnkoContext.kt:138)
    at com.example.app.ui.LoginActivity.onCreate(loginactivity.kt:34)
    at android.app.Activity.performCreate(Activity.java:6372)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2432)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2539) 
    at android.app.ActivityThread.access$900(ActivityThread.java:168) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:150) 
    at android.app.ActivityThread.main(ActivityThread.java:5665) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689) 

I tried delivering StateListDrawable.getCurrent() as background resource, but still no luck:

backgroundDrawable = (context.drawable(R.drawable.button_shape_default) as StateListDrawable).current

This is my code for integration with anko:

fun ViewManager.circularProgressButton(theme : Int = 0, init : CircularProgressButton.() -> Unit = {})
	= ankoView({ CircularProgressButton(it) }, theme, init)
fun ViewManager.circularProgressButton(text : CharSequence, theme : Int = 0, init : CircularProgressButton.() -> Unit = {})
	= circularProgressButton(theme) { init(); setText(text) }
fun ViewManager.circularProgressButton(@StringRes textRes : Int, theme : Int = 0, init : CircularProgressButton.() -> Unit = {})
	= circularProgressButton(theme) { init(); setText(textRes) }

Looking at the source code, it seems that you are only looking for the type of the Drawable if the passed AttributeSet is not null. While this is the case when inflating from xml layout, programmatically creating the button will hit that bug.

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.