aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/utils/ui/TextViewUtil.java
blob: a775dad68bfdf9f98525a5b24d9ecdd4f24dd990 (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 de.thedevstack.conversationsplus.utils.ui;

import android.support.annotation.StringRes;
import android.view.View;
import android.widget.TextView;

/**
 * Created by steckbrief on 29.03.2016.
 */
public final class TextViewUtil {

    public static void setText(View parentView, int textViewId, CharSequence text) {
        TextView tv = (TextView) parentView.findViewById(textViewId);
        if (null != tv) {
            tv.setText(text);
        }
    }

    public static void setText(View parentView, int textViewId, int textResId) {
        TextView tv = (TextView) parentView.findViewById(textViewId);
        if (null != tv) {
            tv.setText(textResId);
        }
    }

    public static void enable(TextView tv) {
        setColorEnabledAndTextResId(tv, null, true, null);
    }

    public static void enable(TextView tv, String text) {
        setColorEnabledAndText(tv, null, true, text);
    }

    public static void enable(TextView tv, Integer color) {
        setColorEnabledAndTextResId(tv, color, true, null);
    }

    public static void enable(TextView tv, Integer color, @StringRes Integer resid) {
        setColorEnabledAndTextResId(tv, color, true, resid);
    }

    public static void disable(TextView tv) {
        setColorEnabledAndTextResId(tv, null, false, null);
    }

    public static void disable(TextView tv, String text) {
        setColorEnabledAndText(tv, null, false, text);
    }

    public static void disable(TextView tv, Integer color) {
        setColorEnabledAndTextResId(tv, color, false, null);
    }

    public static void disable(TextView tv, Integer color, @StringRes Integer resid) {
        setColorEnabledAndTextResId(tv, color, false, resid);
    }

    public static void setColor(TextView tv, Integer color) {
        setColorEnabledAndTextResId(tv, color, null, null);
    }

    public static void setColorEnabledAndTextResId(TextView tv, Integer color, Boolean enabled, @StringRes Integer resid) {
        if (null != color) {
            tv.setTextColor(color);
        }

        if (enabled != null) {
            tv.setEnabled(enabled);
        }
        if (resid != null) {
            tv.setText(resid);
        }
    }

    public static void setColorEnabledAndText(TextView tv, Integer color, Boolean enabled, String text) {
        if (null != color) {
            tv.setTextColor(color);
        }

        if (enabled != null) {
            tv.setEnabled(enabled);
        }
        if (text != null) {
            tv.setText(text);
        }
    }

    private TextViewUtil() {
        // avoid instantiation - helper class
    }
}