• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

opensrp / opensrp-client-native-form / #57

12 Sep 2023 07:43AM UTC coverage: 66.18% (+0.2%) from 66.013%
#57

push

github-actions

web-flow
Merge pull request #667 from opensrp/fix_tech_debt_660

Add tests for setUpOptiBpActivityResultListener

8432 of 12741 relevant lines covered (66.18%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
android-json-form-wizard/src/main/java/com/vijay/jsonwizard/views/CustomTextView.java
1
package com.vijay.jsonwizard.views;
2

3
import android.content.Context;
4
import android.content.res.ColorStateList;
5
import androidx.annotation.ColorInt;
6
import androidx.appcompat.widget.AppCompatTextView;
7
import android.text.SpannableString;
8
import android.text.style.ForegroundColorSpan;
9
import android.util.AttributeSet;
10

11
import com.vijay.jsonwizard.R;
12

13
/**
14
 * Basically this custom TextView also provides the following capabilities:
15
 * <p>
16
 * <ul>
17
 * <li>Grey when disabled - Rather the hint color set in the theme</li>
18
 * <li>Returns to previous color when re-enabled</li>
19
 * <li>Hinted text is color {@link com.vijay.jsonwizard.R.color#text_hint_color} - Hinted text
20
 * is text between <> tags (tags inclusive). Furthermore, the tags are not removed</></li>
21
 * </ul>
22
 * <p>
23
 * Created by Ephraim Kigamba - ekigamba@ona.io on 11/04/2018.
24
 */
25
public class CustomTextView extends AppCompatTextView {
26

27
    private boolean hintOnText = false;
1✔
28

29

30
    public CustomTextView(Context context) {
31
        super(context);
1✔
32
    }
1✔
33

34
    public CustomTextView(Context context, AttributeSet attrs) {
35
        super(context, attrs);
1✔
36
    }
1✔
37

38
    public CustomTextView(Context context, AttributeSet attrs, int defStyleAttr) {
39
        super(context, attrs, defStyleAttr);
×
40
    }
×
41

42
    public boolean isHintOnText() {
43
        return hintOnText;
×
44
    }
45

46
    public void setHintOnText(boolean hintOnText) {
47
        this.hintOnText = hintOnText;
×
48
        setText(getText().toString());
×
49
    }
×
50

51
    @Override
52
    public void setTextColor(@ColorInt int color) {
53
        ColorStateList colorStateList = getTextColors();
1✔
54

55
        int[][] states = new int[][]{
1✔
56
                new int[]{android.R.attr.state_enabled}, // enabled
57
                new int[]{-android.R.attr.state_enabled}, // disabled
58
                new int[]{-android.R.attr.state_checked}, // unchecked
59
                new int[]{android.R.attr.state_pressed}  // pressed
60
        };
61

62
        int[] colors = new int[]{
1✔
63
                color,
64
                colorStateList.getColorForState(new int[]{-android.R.attr.state_enabled}, color),
1✔
65
                colorStateList.getColorForState(new int[]{-android.R.attr.state_checked}, color),
1✔
66
                colorStateList.getColorForState(new int[]{android.R.attr.state_pressed}, color)
1✔
67
        };
68

69
        ColorStateList newColorStateList = new ColorStateList(states, colors);
1✔
70
        setTextColor(newColorStateList);
1✔
71
    }
1✔
72

73
    public void setText(String text) {
74
        if (hintOnText && isEnabled()) {
1✔
75
            int currentStartScanIndex = 0;
1✔
76

77
            SpannableString styledString = new SpannableString(text);
1✔
78
            while (currentStartScanIndex > -1) {
1✔
79
                currentStartScanIndex = text.indexOf("<", currentStartScanIndex);
1✔
80
                if (currentStartScanIndex > -1) {
1✔
81
                    int endTagIndex = text.indexOf(">", currentStartScanIndex + 1);
1✔
82

83
                    if (endTagIndex > currentStartScanIndex) {
1✔
84
                        styledString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.toaster_note_red_icon)), currentStartScanIndex,
1✔
85
                                endTagIndex + 1, 0);
86
                    }
87
                    currentStartScanIndex = endTagIndex;
1✔
88
                }
1✔
89
            }
90

91
            setText(styledString);
1✔
92
        } else {
1✔
93
            setText((CharSequence) text);
1✔
94
        }
95
    }
1✔
96

97
    @Override
98
    public void setEnabled(boolean enabled) {
99
        super.setEnabled(enabled);
1✔
100
        String text = getText().toString();
1✔
101
        setText(text);
1✔
102
    }
1✔
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc