leandroBorgesFerreira / LoadingButtonAndroid

A button to substitute the ProgressDialog
MIT License
1.94k stars 214 forks source link

Selector and fontFamily ignored #34

Open venjirai opened 6 years ago

venjirai commented 6 years ago

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"/>`
venjirai commented 6 years ago

Another Problem: When using this selector, when the animation is done and after I finish the activity and dispose of the button. When opening the same activity again, the button seems to start with a very high corner angle, like 50dp. Even though the selector only has 2 dp corners. I also set app:initialCornerAngle="2dp" and tried to revertAnimation and disposed the button immediately after use but this doesn't change anything.

leandroBorgesFerreira commented 6 years ago

Hello @venjirai. This button doesn't accept selectors. Although you can use then, it picks the first state and ignore the other ones. The idea to show selection is the animation. I will implement a feature to make possible change the colours of the button using setters.

About the second problem. It seams weird. I will take a look

venjirai commented 6 years ago

Hello, What about fontFamily being ignored? This is a big deal for my app which is using a company defined font anywhere else. Regards

leandroBorgesFerreira commented 6 years ago

Sure, I will take a look at this too.

leandroBorgesFerreira commented 6 years ago

@venjirai When are you disposing the object? In the onPause?

Can you provide the code for reproducing the dispose bug?

leandroBorgesFerreira commented 6 years ago

The font family bug is fixed in the version 1.9.0. Happy coding and thanks for spotting a bug!

venjirai commented 6 years ago

Hello, thank you for the fast font family fix! For the corner bug:

View in the first activity:

        <br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
            android:id="@+id/login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="16dp"
            android:background="@drawable/rounded_corners_yellow"
            android:fontFamily="@font/brandon_bold"
            android:text="@string/login"
            android:textColor="@color/black"
            app:initialCornerAngle="2dp"
            app:spinning_bar_color="@color/black"
            app:spinning_bar_padding="6dp"
            app:spinning_bar_width="4dp"/>

Background:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/yellow"/>
    <corners
        android:bottomLeftRadius="2dp"
        android:bottomRightRadius="2dp"
        android:topLeftRadius="2dp"
        android:topRightRadius="2dp"/>
</shape>
btnLogin.doneLoadingAnimation(ContextCompat.getColor(FirstActivity.this, R.color.yellow), BitmapFactory.decodeResource(getResources(), R.drawable.ic_done_white_48dp));

        btnLogin.postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
                startActivity(intent);
                finish();
            }
        }, 800);

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        btnLogin.dispose();
    }

First start or after clearing the RAM:

image

After destroying the activity and coming back to it again later: image

Regards

leandroBorgesFerreira commented 6 years ago

@venjirai I still can't reproduce this error. I just pushed a commit that should reproduce this error. In the MainActivity, there is the same code that you just presented, but I can't see the problem yet.

venjirai commented 6 years ago

I can't see it in your code but did you finish the first activity after starting the second one? Then go back to the first activity by starting an intent like for the second one. When I call .revertAnimation then the button is in the correct state when coming back but the button changing while the new activity starts looks really weird. It is also weird, that even though the onDestroy of the first activity is called, the button somehow still has some state.

leandroBorgesFerreira commented 6 years ago

I was killing the app to test this behavior. I will try with intents

venjirai commented 6 years ago

Hello, any update on this issue? Regards

leandroBorgesFerreira commented 6 years ago

Hi @venjirai. I could reproduce your problem and it really seams that the button is keeps some kind of state. Your problem only happens using a Shape. As a workaround you could use a selector:

<?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="2dp" />
        <solid android:color="@color/color_button_default" />
    </shape>
</item>
</selector>

I will take a look and find out what is happening when using shape.

leandroBorgesFerreira commented 5 years ago

This is fixed in version 2.1.1