aboutsummaryrefslogtreecommitdiff
path: root/v1/src/main/java/com/xtremelabs/robolectric/shadows/ShadowProgressBar.java
blob: b1783017b7a1e93b5e21e817466f0091e8100d62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.xtremelabs.robolectric.shadows;

import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;

import android.widget.ProgressBar;

@Implements(ProgressBar.class)
public class ShadowProgressBar extends ShadowView {

    private int progress;
    private int secondaryProgress;
    private int max = 100;
    private boolean isIndeterminate;

    @Override
    public void applyAttributes() {
        super.applyAttributes();

        final int max = attributeSet.getAttributeIntValue("android", "max", this.max);

        if (max >= 0)
            setMax(max);
    }

    @Implementation
    public void setMax(int max) {
        this.max = max;
        if (progress > max) {
            progress = max;
        }
    }

    @Implementation
    public int getMax() {
        return max;
    }

    @Implementation
    public void setProgress(int progress) {
        if (!isIndeterminate()) this.progress = Math.min(max, progress);
    }

    @Implementation
    public int getProgress() {
        return isIndeterminate ? 0 : progress;
    }

    @Implementation
    public void setSecondaryProgress(int secondaryProgress) {
        if (!isIndeterminate()) this.secondaryProgress = Math.min(max, secondaryProgress);
    }

    @Implementation
    public int getSecondaryProgress() {
        return isIndeterminate ? 0 : secondaryProgress;
    }

    @Implementation
    public void setIndeterminate(boolean indeterminate) {
        this.isIndeterminate = indeterminate;
    }

    @Implementation
    public boolean isIndeterminate() {
        return isIndeterminate;
    }

    @Implementation
    public void incrementProgressBy(int diff) {
        if (!isIndeterminate()) setProgress(progress + diff);
    }

    @Implementation
    public void incrementSecondaryProgressBy(int diff) {
        if (!isIndeterminate()) setSecondaryProgress(secondaryProgress + diff);
    }
}