summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/base/views/LocationIndicator.java
blob: 8245893d132f3a51c17977be82b4c67884092b72 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
package se.leap.bitmaskclient.base.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.eip.GatewaysManager;

import static androidx.core.content.ContextCompat.getColor;

public class LocationIndicator extends LinearLayout {

    private View level1;
    private View level1_2;
    private View level2;
    private View level2_2;
    private View level3;
    private View level3_2;

    public LocationIndicator(Context context) {
        super(context);
        initLayout(context);
    }

    public LocationIndicator(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initLayout(context);

    }

    public LocationIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initLayout(context);
    }


    void initLayout(Context context) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rootview = inflater.inflate(R.layout.v_location_status_indicator, this, true);
        level1 = rootview.findViewById(R.id.level1);
        level1_2 = rootview.findViewById(R.id.level1_2);
        level2 = rootview.findViewById(R.id.level2);
        level2_2 = rootview.findViewById(R.id.level2_2);
        level3 = rootview.findViewById(R.id.level3);
        level3_2 = rootview.findViewById(R.id.level3_2);
    }

    public void setLoad(GatewaysManager.Load load) {
        switch (load) {
            case GOOD:
                level1.setBackgroundColor(getColor(getContext(), R.color.green200));
                level1_2.setBackgroundColor(getColor(getContext(), R.color.green200));
                level2.setBackgroundColor(getColor(getContext(), R.color.green200));
                level2_2.setBackgroundColor(getColor(getContext(), R.color.green200));
                level3.setBackgroundColor(getColor(getContext(), R.color.green200));
                level3_2.setBackgroundColor(getColor(getContext(), R.color.green200));
                break;
            case AVERAGE:
                level1.setBackgroundColor(getColor(getContext(), R.color.yellow200));
                level1_2.setBackgroundColor(getColor(getContext(), R.color.yellow200));
                level2.setBackgroundColor(getColor(getContext(), R.color.yellow200));
                level2_2.setBackgroundColor(getColor(getContext(), R.color.yellow200));
                level3.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                level3_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                break;
            case CRITICAL:
                level1.setBackgroundColor(getColor(getContext(), R.color.red200));
                level1_2.setBackgroundColor(getColor(getContext(), R.color.red200));
                level2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                level2_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                level3.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                level3_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                break;
            default:
                level1.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                level1_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                level2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                level2_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                level3.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));
                level3_2.setBackgroundColor(getColor(getContext(), R.color.black800_high_transparent));;
                break;
        }
    }
}