Пример #1
0
 private void processRestoredCountry() {
   if (!TextUtils.isEmpty(restoredCountry)) {
     Country country = countries.getCountryByIso(restoredCountry);
     restoredCountry = null;
     if (country != null) {
       setCountry(country);
     }
   }
 }
Пример #2
0
 private void setupDefaultCountry() {
   String[] possibleRegions = Phones.getPossibleRegions(getContext());
   for (String region : possibleRegions) {
     Country country = countries.getCountryByIso(region);
     if (country != null) {
       this.defaultCountry = country;
       break;
     }
   }
 }
Пример #3
0
  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);
    }
  }
Пример #4
0
  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();
          }
        });
  }
Пример #5
0
 public void setCountryIso(String countryIso) {
   setCountry(countries.getCountryByIso(countryIso));
 }