Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First char has black color #57

Open
monegask1969 opened this issue Apr 30, 2020 · 1 comment
Open

First char has black color #57

monegask1969 opened this issue Apr 30, 2020 · 1 comment

Comments

@monegask1969
Copy link

Первый элемент строки окрашивается в черный цвет, если маска выглядит следующим образом:
<br.com.sapereaude.maskedEditText.MaskedEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="true"
android:id="@+id/phone"
android:inputType="phone"
android:typeface="monospace"
mask:allowed_chars="1234567890"
mask:mask="(###)###-##-##"
android:hint="XXXXXXXXXX"
/>
В таком случае, скобка горит черным

Подскажите, пожалуйста, это баг или необходимо как-то настроить элемент?

image

@ashishgingercube
Copy link

Copy the below code and replace them in the MaskedEditText.java-

@OverRide
public void afterTextChanged(Editable s) {
if(!editingAfter && editingBefore && editingOnChanged) {
editingAfter = true;
if (hasHint() && (keepHint || rawText.length() == 0)) {
boolean typing = true;
if(rawText.length() == 0) {
typing = false;
}
setText(makeMaskedTextWithHint(typing));
} else {
setText(makeMaskedText());
}

        selectionChanged = false;
        setSelection(selection);

        editingBefore = false;
        editingOnChanged = false;
        editingAfter = false;
        ignore = false;
    }
}


private void cleanUp() {
    initialized = false;
    if(mask == null || mask.isEmpty()){
        return;
    }
    generatePositionArrays();
    if (!shouldKeepText || rawText == null) {
        rawText = new RawText();
        selection = rawToMask[0];
    }
    editingBefore = true;
    editingOnChanged = true;
    editingAfter = true;
    if(hasHint() && rawText.length() == 0) {
        this.setText(makeMaskedTextWithHint(false));
    } else {
        this.setText(makeMaskedText());
    }
    editingBefore = false;
    editingOnChanged = false;
    editingAfter = false;

    maxRawLength = maskToRaw[previousValidPosition(mask.length() - 1)] + 1;
    lastValidMaskPosition = findLastValidMaskPosition();
    initialized = true;

    super.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (focusChangeListener != null) {
                focusChangeListener.onFocusChange(v, hasFocus);
            }

            if (hasFocus()) {
                selectionChanged = false;
                MaskedEditText.this.setSelection(lastValidPosition());
            }
        }
    });
}

private CharSequence makeMaskedTextWithHint(boolean typing) {
SpannableStringBuilder ssb = new SpannableStringBuilder();
int mtrv;
int maskFirstChunkEnd = rawToMask[0];
for(int i = 0; i < mask.length(); i++) {
mtrv = maskToRaw[i];
if (mtrv != -1) {
if (mtrv < rawText.length()) {
ssb.append(rawText.charAt(mtrv));
} else {
ssb.append(getHint().charAt(maskToRaw[i]));
}
}
else {
ssb.append(mask.charAt(i));
}

        if(i == 0 && !typing) {
            ssb.setSpan(new ForegroundColorSpan(getCurrentHintTextColor()), i, i + 1, 0);
        }
        if ((keepHint && rawText.length() < rawToMask.length && i >= rawToMask[rawText.length()])
                || (!keepHint && i >= maskFirstChunkEnd)) {
            ssb.setSpan(new ForegroundColorSpan(getCurrentHintTextColor()), i, i + 1, 0);
        }
    }
    return ssb;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants