Skip to content

Commit 0dc7cb3

Browse files
author
Rygel Louv
committed
Fixed button click not working, changed inside button to textview, reduced progress size
1 parent 1b98575 commit 0dc7cb3

File tree

7 files changed

+48
-31
lines changed

7 files changed

+48
-31
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

androidloadingbuttonlib/src/main/java/com/github/rygelouv/androidloadingbuttonlib/LoadingButton.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.widget.LinearLayout;
1212
import android.widget.ProgressBar;
1313
import android.widget.RelativeLayout;
14+
import android.widget.TextView;
1415

1516
/**
1617
* Created by rygelouv on 9/21/17.
@@ -29,7 +30,7 @@ public class LoadingButton extends LinearLayout
2930
private Drawable background;
3031
private int textSize;
3132
private int progressColor;
32-
private Button mTextButton;
33+
private TextView mTextButton;
3334
private ProgressBar mProgressBar;
3435

3536
public LoadingButton(Context context)
@@ -75,7 +76,7 @@ private void init(Context context)
7576
this.mProgressBar = mRootView.findViewById(R.id.progress);
7677

7778
if (!TextUtils.isEmpty(text))
78-
mTextButton.setText(text);
79+
mTextButton.setText(text.toUpperCase());
7980

8081
if (textColor != 0)
8182
mTextButton.setTextColor(textColor);
@@ -92,37 +93,20 @@ private void init(Context context)
9293
if (progressColor != 0)
9394
this.mProgressBar.getIndeterminateDrawable().setColorFilter(progressColor,
9495
android.graphics.PorterDuff.Mode.MULTIPLY);
95-
96-
this.mRootView.setOnClickListener(new OnClickListener()
97-
{
98-
@Override
99-
public void onClick(View view)
100-
{
101-
startLoading("Loading...");
102-
}
103-
});
104-
this.mTextButton.setOnClickListener(new OnClickListener()
105-
{
106-
@Override
107-
public void onClick(View view)
108-
{
109-
startLoading("Loading...");
110-
}
111-
});
11296
}
11397

11498
public void startLoading(String loadingText)
11599
{
116100
this.setEnabled(false);
117101
this.mProgressBar.setVisibility(VISIBLE);
118-
this.mTextButton.setText(loadingText);
102+
this.mTextButton.setText(loadingText.toUpperCase());
119103
}
120104

121105
public void stopLoading(String loadingDoneText)
122106
{
123107
this.setEnabled(true);
124108
this.mProgressBar.setVisibility(GONE);
125-
this.mTextButton.setText(loadingDoneText);
109+
this.mTextButton.setText(loadingDoneText.toUpperCase());
126110
}
127111

128112
public int getTextColor()

androidloadingbuttonlib/src/main/res/layout/loading_button_layout.xml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,29 @@
33
android:layout_width="match_parent"
44
android:layout_height="wrap_content"
55
xmlns:tools="http://schemas.android.com/tools"
6-
android:gravity="center_horizontal"
6+
android:gravity="center"
7+
8+
android:minHeight="@dimen/dimen_48"
79
>
810

911
<ProgressBar
1012
android:id="@+id/progress"
11-
android:layout_width="30dp"
12-
android:layout_height="30dp"
13+
android:layout_width="25dp"
14+
android:layout_height="25dp"
1315
android:layout_gravity="center_vertical"
14-
android:layout_marginLeft="4dp"
16+
android:layout_marginRight="4dp"
17+
android:layout_marginEnd="4dp"
1518
android:visibility="gone"
1619
/>
1720

18-
<Button
21+
<TextView
1922
android:id="@+id/button"
2023
android:layout_width="wrap_content"
2124
android:layout_height="wrap_content"
2225
tools:text="validate"
2326
android:background="@android:color/transparent"
24-
android:layout_marginRight="4dp"
27+
android:layout_marginLeft="4dp"
28+
android:layout_marginStart="4dp"
2529
/>
2630

2731
</LinearLayout>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<dimen name="dimen_48">48dp</dimen>
4+
</resources>

app/src/main/java/com/github/rygelouv/androidloadingbutton/TestLibActivity.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,39 @@
33
import android.support.v7.app.AppCompatActivity;
44
import android.os.Bundle;
55
import android.view.View;
6+
import android.widget.Button;
67

78
import com.github.rygelouv.androidloadingbuttonlib.LoadingButton;
89

910
public class TestLibActivity extends AppCompatActivity
1011
{
1112

13+
LoadingButton buton;
14+
Button stop;
15+
1216
@Override
1317
protected void onCreate(Bundle savedInstanceState)
1418
{
1519
super.onCreate(savedInstanceState);
1620
setContentView(R.layout.activity_test_lib);
21+
buton = findViewById(R.id.button_test);
22+
stop = findViewById(R.id.stop);
23+
24+
stop.setOnClickListener(new View.OnClickListener()
25+
{
26+
@Override
27+
public void onClick(View view)
28+
{
29+
buton.stopLoading("Done!");
30+
}
31+
});
1732

18-
findViewById(R.id.stop).setOnClickListener(new View.OnClickListener()
33+
buton.setOnClickListener(new View.OnClickListener()
1934
{
2035
@Override
2136
public void onClick(View view)
2237
{
23-
((LoadingButton)findViewById(R.id.button_test))
24-
.stopLoading("Done!");
38+
buton.startLoading("Loading...");
2539
}
2640
});
2741
}

app/src/main/res/drawable/button_accent_full.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
3+
<item android:state_enabled="false" >
4+
<shape android:shape="rectangle" >
5+
<corners android:radius="4dip" />
6+
<stroke android:width="1dip"
7+
android:color="@color/gray" />
8+
<gradient android:angle="-90"
9+
android:startColor="@color/gray"
10+
android:endColor="@color/gray" />
11+
</shape>
12+
</item>
313
<item android:state_pressed="true" >
414
<shape android:shape="rectangle" >
515
<corners android:radius="4dip" />

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
<color name="colorPrimaryDark">#303F9F</color>
55
<color name="colorAccent">#FF4081</color>
66
<color name="gray_dark">#4e5e69</color>
7+
<color name="gray">#909AAB</color>
78
</resources>

0 commit comments

Comments
 (0)