1package com.xtremelabs.robolectric.shadows; 2 3import com.xtremelabs.robolectric.internal.Implementation; 4import com.xtremelabs.robolectric.internal.Implements; 5 6import android.widget.ProgressBar; 7 8@Implements(ProgressBar.class) 9public class ShadowProgressBar extends ShadowView { 10 11 private int progress; 12 private int secondaryProgress; 13 private int max = 100; 14 private boolean isIndeterminate; 15 16 @Override 17 public void applyAttributes() { 18 super.applyAttributes(); 19 20 final int max = attributeSet.getAttributeIntValue("android", "max", this.max); 21 22 if (max >= 0) 23 setMax(max); 24 } 25 26 @Implementation 27 public void setMax(int max) { 28 this.max = max; 29 if (progress > max) { 30 progress = max; 31 } 32 } 33 34 @Implementation 35 public int getMax() { 36 return max; 37 } 38 39 @Implementation 40 public void setProgress(int progress) { 41 if (!isIndeterminate()) this.progress = Math.min(max, progress); 42 } 43 44 @Implementation 45 public int getProgress() { 46 return isIndeterminate ? 0 : progress; 47 } 48 49 @Implementation 50 public void setSecondaryProgress(int secondaryProgress) { 51 if (!isIndeterminate()) this.secondaryProgress = Math.min(max, secondaryProgress); 52 } 53 54 @Implementation 55 public int getSecondaryProgress() { 56 return isIndeterminate ? 0 : secondaryProgress; 57 } 58 59 @Implementation 60 public void setIndeterminate(boolean indeterminate) { 61 this.isIndeterminate = indeterminate; 62 } 63 64 @Implementation 65 public boolean isIndeterminate() { 66 return isIndeterminate; 67 } 68 69 @Implementation 70 public void incrementProgressBy(int diff) { 71 if (!isIndeterminate()) setProgress(progress + diff); 72 } 73 74 @Implementation 75 public void incrementSecondaryProgressBy(int diff) { 76 if (!isIndeterminate()) setSecondaryProgress(secondaryProgress + diff); 77 } 78} 79