Created
November 2, 2015 14:49
-
-
Save justintuchek/0899753952fc7b44604b to your computer and use it in GitHub Desktop.
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
public class MMInputUtils { | |
private MMInputUtils() { | |
throw new AssertionError("no instances"); | |
} | |
@IntDef({CURSOR_POSITION_BEGINNING, CURSOR_POSITION_ENDING}) | |
@Retention(RetentionPolicy.SOURCE) | |
public @interface CursorPosition{} | |
public static final int CURSOR_POSITION_BEGINNING = 0; | |
public static final int CURSOR_POSITION_ENDING = 1; | |
public static void setCursorPosition(@Nullable EditText inputField, @CursorPosition int cursorPosition) { | |
if(inputField == null) { | |
return; | |
} | |
switch (cursorPosition) { | |
case CURSOR_POSITION_BEGINNING: { | |
inputField.setSelection(0); | |
break; | |
} | |
case CURSOR_POSITION_ENDING: { | |
inputField.setSelection(inputField.length()); | |
} | |
} | |
} | |
@IntDef({MASK_VISIBILITY_SHADOWED, MASK_VISIBILITY_UNSHADOWED}) | |
@Retention(RetentionPolicy.SOURCE) | |
public @interface InputMaskVisibility{} | |
public static final int MASK_VISIBILITY_SHADOWED = 0; | |
public static final int MASK_VISIBILITY_UNSHADOWED = 1; | |
public static void setMaskVisibility(@Nullable EditText inputField, @InputMaskVisibility int maskVisibility) { | |
if(inputField == null) { | |
return; | |
} | |
switch(maskVisibility) { | |
case MASK_VISIBILITY_SHADOWED: { | |
inputField.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); | |
break; | |
} | |
case MASK_VISIBILITY_UNSHADOWED: { | |
inputField.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment