CountryCodePickerProject
CountryCodePickerProject copied to clipboard
Add support for Preference API
It would be very nice if CountryCodePicker could be a custom preference supported by the Preference API. More info here: Settings | Android Developers
Hello @yankarinRG, this sounds interesting. Can you brief a little what exactly you want to see in term of feature.
Basically it would be a DialogPreference with the custom CountryCodePicker view (country code/prefix + phone number). In the preference layout file (with PreferenceScreen as root) then you would add something like <in.hbb20.CountryCodePickerPreference>, then in onDisplayPreferenceDialog (of class PreferenceFragmentCompat) you check if the preference which wants to show a dialog (because the preference item on the preference screen is different than the dialog) is instanceof CountryCodePickerPreference, then create a new instance of CountryCodePickerPreferenceDialogFragment and show it. Some useful source code here: (I take EditTextPreference as an example)
- EditTextPreference (the item on the preference screen)
- EditTextPreferenceDialogFragmentCompat (the dialog which show when you click EditTextPreference)
- PreferenceFragmentCompat (to see how onDisplayPreferenceDialog works)
This way you can have a persistent preference of a phone number!
@hbb20 really it'll be consistent to have support for android preferences,because choosing a country /language... is something we do at registration and also when changing settings . thank you
@yankarinRG did you make it yourself? or any workaround please?
At the end I simply used an EditTextPreference and guessed/validated the phone number using libphonenumber. Of course, it would've been a lot more elegant if there was a CountryCodePickerPreference.