Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions library/src/main/java/com/dd/processbutton/ProcessButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Parcel;
import android.os.Parcelable;
Expand All @@ -14,9 +15,10 @@ public abstract class ProcessButton extends FlatButton {
private int mMaxProgress;
private int mMinProgress;

private GradientDrawable mProgressDrawable;
private GradientDrawable mProgressLineDrawable;
private GradientDrawable mCompleteDrawable;
private GradientDrawable mErrorDrawable;
private GradientDrawable mProgressDrawable;

private CharSequence mLoadingText;
private CharSequence mCompleteText;
Expand All @@ -41,8 +43,8 @@ private void init(Context context, AttributeSet attrs) {
mMinProgress = 0;
mMaxProgress = 100;

mProgressDrawable = (GradientDrawable) getDrawable(R.drawable.rect_progress).mutate();
mProgressDrawable.setCornerRadius(getCornerRadius());
mProgressLineDrawable = (GradientDrawable) getDrawable(R.drawable.rect_progress_line).mutate();
mProgressLineDrawable.setCornerRadius(getCornerRadius());

mCompleteDrawable = (GradientDrawable) getDrawable(R.drawable.rect_complete).mutate();
mCompleteDrawable.setCornerRadius(getCornerRadius());
Expand All @@ -67,9 +69,9 @@ private void initAttributes(Context context, AttributeSet attributeSet) {
mCompleteText = attr.getString(R.styleable.ProcessButton_pb_textComplete);
mErrorText = attr.getString(R.styleable.ProcessButton_pb_textError);

int purple = getColor(R.color.purple_progress);
int colorProgress = attr.getColor(R.styleable.ProcessButton_pb_colorProgress, purple);
mProgressDrawable.setColor(colorProgress);
int purple = getColor(R.color.purple_progress_line);
int colorProgressLine = attr.getColor(R.styleable.ProcessButton_pb_colorProgressLine, purple);
mProgressLineDrawable.setColor(colorProgressLine);

int green = getColor(R.color.green_complete);
int colorComplete = attr.getColor(R.styleable.ProcessButton_pb_colorComplete, green);
Expand All @@ -79,6 +81,12 @@ private void initAttributes(Context context, AttributeSet attributeSet) {
int colorError = attr.getColor(R.styleable.ProcessButton_pb_colorError, red);
mErrorDrawable.setColor(colorError);

if (attr.hasValue(R.styleable.ProcessButton_pb_colorProgress)) {
mProgressDrawable = (GradientDrawable) getDrawable(R.drawable.rect_progress).mutate();
mProgressDrawable.setCornerRadius(getCornerRadius());
mProgressDrawable.setColor(attr.getColor(R.styleable.ProcessButton_pb_colorProgress, getColor(R.color.blue_normal)));
}

} finally {
attr.recycle();
}
Expand Down Expand Up @@ -111,7 +119,7 @@ protected void onProgress() {
if(getLoadingText() != null) {
setText(getLoadingText());
}
setBackgroundCompat(getNormalDrawable());
setBackgroundCompat(getProgressDrawable());
}

protected void onCompleteState() {
Expand Down Expand Up @@ -152,14 +160,18 @@ public int getMinProgress() {
return mMinProgress;
}

public GradientDrawable getProgressDrawable() {
return mProgressDrawable;
public GradientDrawable getProgressLineDrawable() {
return mProgressLineDrawable;
}

public GradientDrawable getCompleteDrawable() {
return mCompleteDrawable;
}

public Drawable getProgressDrawable() {
return mProgressDrawable == null ? getNormalDrawable() : mProgressDrawable;
}

public CharSequence getLoadingText() {
return mLoadingText;
}
Expand All @@ -168,14 +180,18 @@ public CharSequence getCompleteText() {
return mCompleteText;
}

public void setProgressDrawable(GradientDrawable progressDrawable) {
mProgressDrawable = progressDrawable;
public void setProgressLineDrawable(GradientDrawable progressLineDrawable) {
mProgressLineDrawable = progressLineDrawable;
}

public void setCompleteDrawable(GradientDrawable completeDrawable) {
mCompleteDrawable = completeDrawable;
}

public void setProgressDrawable(GradientDrawable progressDrawable) {
mProgressDrawable = progressDrawable;
}

public void setNormalText(CharSequence normalText) {
super.setNormalText(normalText);
if (mProgress == mMinProgress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public void setColorScheme(int color1, int color2, int color3, int color4) {

@Override
public void drawProgress(Canvas canvas) {
if(getBackground() != getNormalDrawable()) {
setBackgroundDrawable(getNormalDrawable());
if(getBackground() != getProgressDrawable()) {
setBackgroundDrawable(getProgressDrawable());
}

switch (mMode) {
Expand All @@ -122,8 +122,8 @@ private void drawLineProgress(Canvas canvas) {

double indicatorHeightPercent = 0.05; // 5%
int bottom = (int) (getMeasuredHeight() - getMeasuredHeight() * indicatorHeightPercent);
getProgressDrawable().setBounds(0, bottom, (int) indicatorWidth, getMeasuredHeight());
getProgressDrawable().draw(canvas);
getProgressLineDrawable().setBounds(0, bottom, (int) indicatorWidth, getMeasuredHeight());
getProgressLineDrawable().draw(canvas);
}

private void drawEndlessProgress(Canvas canvas) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void drawProgress(Canvas canvas) {
float scale = (float) getProgress() / (float) getMaxProgress();
float indicatorHeight = (float) getMeasuredHeight() * scale;

getProgressDrawable().setBounds(0, 0, getMeasuredWidth(), (int) indicatorHeight);
getProgressDrawable().draw(canvas);
getProgressLineDrawable().setBounds(0, 0, getMeasuredWidth(), (int) indicatorHeight);
getProgressLineDrawable().draw(canvas);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void drawProgress(Canvas canvas) {
float scale = (float) getProgress() / (float) getMaxProgress();
float indicatorWidth = (float) getMeasuredWidth() * scale;

getProgressDrawable().setBounds(0, 0, (int) indicatorWidth, getMeasuredHeight());
getProgressDrawable().draw(canvas);
getProgressLineDrawable().setBounds(0, 0, (int) indicatorWidth, getMeasuredHeight());
getProgressLineDrawable().draw(canvas);
}

}
2 changes: 1 addition & 1 deletion library/src/main/res/drawable/rect_progress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="@dimen/corner_radius" />
<solid android:color="@color/purple_progress" />
<solid android:color="@color/orange_progress" />
</shape>
7 changes: 7 additions & 0 deletions library/src/main/res/drawable/rect_progress_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="@dimen/corner_radius" />
<solid android:color="@color/purple_progress_line" />
</shape>
3 changes: 2 additions & 1 deletion library/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<color name="blue_pressed">#ff0099cc</color>
<color name="blue_normal">#ff33b5e5</color>
<color name="green_complete">#ff99cc00</color>
<color name="purple_progress">#ffaa66cc</color>
<color name="purple_progress_line">#ffaa66cc</color>
<color name="red_error">#ffff4444</color>
<color name="orange_progress">#ffb74d</color>

<color name="holo_blue_bright">#ff00ddff</color>
<color name="holo_green_light">#ff99cc00</color>
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<attr name="pb_textProgress" format="string" />
<attr name="pb_textComplete" format="string" />
<attr name="pb_textError" format="string" />
<attr name="pb_colorProgressLine" format="color" />
<attr name="pb_colorProgress" format="color" />
<attr name="pb_colorComplete" format="color" />
<attr name="pb_colorError" format="color" />
Expand Down
3 changes: 2 additions & 1 deletion sample/src/main/res/layout/ac_sign_in.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
custom:pb_colorComplete="@color/green_complete"
custom:pb_colorNormal="@color/blue_normal"
custom:pb_colorPressed="@color/blue_pressed"
custom:pb_colorProgress="@color/purple_progress"
custom:pb_colorProgressLine="@color/purple_progress_line"
custom:pb_colorProgress="@color/orange_progress"
custom:pb_textComplete="@string/Success"
custom:pb_textProgress="@string/Loading" />

Expand Down