Add support to get max length integer value via integer id #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 customPinEntryEditTextclass can't access tocom.android.internal.R.styleable.TextView_maxLength.There is another approach to get the current value of max length from
android:maxLengthproperty.android:maxLengthwas initialized viaTextViewintoInputFilter.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 getmMaxvalue out in lower APIs.mMaxfield was introduced from the first version ofInputFilterhttps://android.googlesource.com/platform/frameworks/base/+/54b6cfa9a9e5b861a9930af873580d6dc20f773c/core/java/android/text/InputFilter.javaAfter rechecked, it seems getting value out from
mMaxby 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)💪