Last active
April 1, 2023 02:45
-
-
Save 0x10FF/5176884e21511676f2020cc0ebe88d20 to your computer and use it in GitHub Desktop.
lower casing text input watcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sample.util.text; | |
import android.text.Editable; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class LowerCasingTextWatcher implements android.text.TextWatcher { | |
/** | |
* Optimize me | |
*/ | |
public static final Pattern UPPER_CASE_REGEX = Pattern.compile("[A-Z]"); | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, int count) { | |
} | |
@Override | |
public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
} | |
@Override | |
public void afterTextChanged(Editable s) { | |
Matcher matcher = UPPER_CASE_REGEX.matcher(s); | |
while (matcher.find()) { | |
CharSequence upperCaseRegion = s.subSequence(matcher.start(), matcher.end()); | |
s.replace(matcher.start(), matcher.end(), upperCaseRegion.toString().toLowerCase()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment