private void processRestoredCountry() { if (!TextUtils.isEmpty(restoredCountry)) { Country country = countries.getCountryByIso(restoredCountry); restoredCountry = null; if (country != null) { setCountry(country); } } }
private void setupDefaultCountry() { String[] possibleRegions = Phones.getPossibleRegions(getContext()); for (String region : possibleRegions) { Country country = countries.getCountryByIso(region); if (country != null) { this.defaultCountry = country; break; } } }
private void onCountriesLoaded() { if (defaultCountry == null) { setupDefaultCountry(); } processRestoredCountry(); if (this.country != null) { return; } Country country = countries.getCountryByIso(countryFromAttrs); if (country != null) { setCountry(country); } if (this.country == null) { setCountry(defaultCountry); } }
public void init(AttributeSet attrs) { if (attrs != null) { TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.pi_PhoneInputStyle); int formatInt = typedArray.getInt(R.styleable.pi_PhoneInputStyle_phoneNumberFormat, -1); switch (formatInt) { case 0: phoneNumberFormat = PhoneNumberUtil.PhoneNumberFormat.E164; break; case 1: phoneNumberFormat = PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL; break; case 2: phoneNumberFormat = PhoneNumberUtil.PhoneNumberFormat.NATIONAL; break; case 3: phoneNumberFormat = PhoneNumberUtil.PhoneNumberFormat.RFC3966; break; } countryFromAttrs = typedArray.getString(R.styleable.pi_PhoneInputStyle_countryIso); typedArray.recycle(); } Countries.get( getContext(), new Countries.Callback() { @Override public void onLoaded(Countries loadedCountries) { countries = loadedCountries; phoneNumberUtil = PhoneNumberUtil.getInstance(); onCountriesLoaded(); } }); }
public void setCountryIso(String countryIso) { setCountry(countries.getCountryByIso(countryIso)); }