1 package com.xtremelabs.robolectric.shadows;
2 
3 import com.xtremelabs.robolectric.internal.Implementation;
4 import com.xtremelabs.robolectric.internal.Implements;
5 
6 import android.widget.ProgressBar;
7 
8 @Implements(ProgressBar.class)
9 public 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
applyAttributes()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
setMax(int max)27     public void setMax(int max) {
28         this.max = max;
29         if (progress > max) {
30             progress = max;
31         }
32     }
33 
34     @Implementation
getMax()35     public int getMax() {
36         return max;
37     }
38 
39     @Implementation
setProgress(int progress)40     public void setProgress(int progress) {
41         if (!isIndeterminate()) this.progress = Math.min(max, progress);
42     }
43 
44     @Implementation
getProgress()45     public int getProgress() {
46         return isIndeterminate ? 0 : progress;
47     }
48 
49     @Implementation
setSecondaryProgress(int secondaryProgress)50     public void setSecondaryProgress(int secondaryProgress) {
51         if (!isIndeterminate()) this.secondaryProgress = Math.min(max, secondaryProgress);
52     }
53 
54     @Implementation
getSecondaryProgress()55     public int getSecondaryProgress() {
56         return isIndeterminate ? 0 : secondaryProgress;
57     }
58 
59     @Implementation
setIndeterminate(boolean indeterminate)60     public void setIndeterminate(boolean indeterminate) {
61         this.isIndeterminate = indeterminate;
62     }
63 
64     @Implementation
isIndeterminate()65     public boolean isIndeterminate() {
66         return isIndeterminate;
67     }
68 
69     @Implementation
incrementProgressBy(int diff)70     public void incrementProgressBy(int diff) {
71         if (!isIndeterminate()) setProgress(progress + diff);
72     }
73 
74     @Implementation
incrementSecondaryProgressBy(int diff)75     public void incrementSecondaryProgressBy(int diff) {
76         if (!isIndeterminate()) setSecondaryProgress(secondaryProgress + diff);
77     }
78 }
79