Skip to content

Commit

Permalink
[Feature] Add warning inside setIndeterminate().
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Feb 4, 2017
1 parent 8b86414 commit f29a526
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* A backported {@code Drawable} for determinate horizontal {@code ProgressBar}.
*/
public class HorizontalProgressDrawable extends LayerDrawable implements IntrinsicPaddingDrawable,
ShowBackgroundDrawable, TintableDrawable {
MaterialProgressDrawable, ShowBackgroundDrawable, TintableDrawable {

private static final String TAG = HorizontalProgressDrawable.class.getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* A backported {@code Drawable} for indeterminate horizontal {@code ProgressBar}.
*/
public class IndeterminateHorizontalProgressDrawable extends BaseIndeterminateProgressDrawable
implements ShowBackgroundDrawable {
implements MaterialProgressDrawable, ShowBackgroundDrawable {

private static final int PROGRESS_INTRINSIC_HEIGHT_DP = 4;
private static final int PADDED_INTRINSIC_HEIGHT_DP = 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
/**
* A backported {@code Drawable} for indeterminate circular {@code ProgressBar}.
*/
public class IndeterminateProgressDrawable extends BaseIndeterminateProgressDrawable {
public class IndeterminateProgressDrawable extends BaseIndeterminateProgressDrawable
implements MaterialProgressDrawable {

private static final int PROGRESS_INTRINSIC_SIZE_DP = 42;
private static final int PADDED_INTRINSIC_SIZE_DP = 48;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public class MaterialProgressBar extends ProgressBar {
public static final int PROGRESS_STYLE_CIRCULAR = 0;
public static final int PROGRESS_STYLE_HORIZONTAL = 1;

// This field remains false inside super class constructor.
@SuppressWarnings("FieldCanBeLocal")
private boolean mSuperInitialized = true;
private int mProgressStyle;

private TintInfo mProgressTintInfo = new TintInfo();

public MaterialProgressBar(Context context) {
Expand Down Expand Up @@ -146,6 +148,15 @@ private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
setShowProgressBackground(showProgressBackground);
}

@Override
public synchronized void setIndeterminate(boolean indeterminate) {
super.setIndeterminate(indeterminate);

if (mSuperInitialized && !(getCurrentDrawable() instanceof MaterialProgressDrawable)) {
Log.w(TAG, "Current drawable is not a MaterialProgressDrawable, you may want to set app:mpb_setBothDrawables");
}
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright (c) 2017 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
* All Rights Reserved.
*/

package me.zhanghai.android.materialprogressbar;

interface MaterialProgressDrawable {}

0 comments on commit f29a526

Please sign in to comment.