Skip to content

Conversation

@luongvo
Copy link

@luongvo luongvo commented Apr 21, 2020

What happened 🤔

  • attrs.getAttributeIntValue(XML_NAMESPACE_ANDROID, "maxLength", 4) doesn't support to get max length int value from an integer id.

Insight 👀

  • The default way to support getting int value from int id value is using TypeArray.getInt(com.android.internal.R.styleable.TextView_maxLength, -1), but custom PinEntryEditText class can't access to com.android.internal.R.styleable.TextView_maxLength.

  • There is another approach to get the current value of max length from android:maxLength property. android:maxLength was initialized via TextView into InputFilter.LengthFilter, so we could get this value out from current filter list. Note that, InputFilter.LengthFilter.getMax() is only supported from API 21, so we need to use reflection to get mMax value out in lower APIs. mMax field was introduced from the first version of InputFilter https://android.googlesource.com/platform/frameworks/base/+/54b6cfa9a9e5b861a9930af873580d6dc20f773c/core/java/android/text/InputFilter.java

  • After rechecked, it seems getting value out from mMax by reflection on API 19 is not a pretty way, back to getting value from resid or raw int value https://stackoverflow.com/a/60593495.

PoW (a.k.a Proof Of Work)💪

  • API 21

  • API 19

@MarcinB85
Copy link

Can we merge this PR?

@luongvo
Copy link
Author

luongvo commented Dec 22, 2020

@MarcinB85 while waiting for the author merge this PR, you can use this version https://jitpack.io/#nimblehq/PinEntryEditText/feature~support-integer-id-value-on-max-length-SNAPSHOT

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

Successfully merging this pull request may close these issues.

2 participants