summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/base/views/ProgressSpinner.java
blob: 380ddf238cc75d79033d9d8fb31685ad89ca3bd6 (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
package se.leap.bitmaskclient.base.views;

import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;

import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.content.ContextCompat;

import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.databinding.VProgressSpinnerBinding;

public class ProgressSpinner extends RelativeLayout {

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

    AppCompatImageView spinnerView;
    AppCompatTextView textView;

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

    public ProgressSpinner(Context context, AttributeSet attrs) {
        super(context, attrs);
        initLayout(context);
    }

    public ProgressSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initLayout(context);
    }


    public ProgressSpinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initLayout(context);
    }

    private void initLayout(Context context) {
        VProgressSpinnerBinding binding = VProgressSpinnerBinding.inflate(LayoutInflater.from(context), this, true);
        spinnerView = binding.spinnerView;
        textView = binding.tvProgress;
    }

    public void update(int progress) {
        String text = "";
        if (progress > 0) {
            if ((progress / 10) == 0) {
                text = text + " ";
            }
            if ((progress / 100) == 0) {
                text = text + " ";
            }
            text = text + progress + "%";
        }
        textView.setText(text);
    }
}