| | |
| | | package com.sahooz.library.countrypicker; |
| | | |
| | | import android.Manifest; |
| | | import android.content.Context; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.core.app.ActivityCompat; |
| | | |
| | | import android.content.pm.PackageManager; |
| | | import android.location.Address; |
| | | import android.location.Geocoder; |
| | | import android.location.Location; |
| | | import android.location.LocationManager; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | |
| | |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | Collections.sort(countries, (o1, o2) -> o1.getPinyin().compareTo(o2.getPinyin())); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取当前的国家区号(基于用户设置的语言和地区获取国家码) |
| | | * |
| | | * @return Country |
| | | */ |
| | | public static Country getCountryInfo() { |
| | | String countryCode = Locale.getDefault().getCountry(); |
| | | for (Country country : countries) { |
| | | if (country.locale.equals(countryCode)) { |
| | | return country; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取当前的国家区号(根据定位荻取国家编码) |
| | | * |
| | | * @return Country |
| | | */ |
| | | public static Country getLocationCountryInfo(String countryCode) { |
| | | if (TextUtils.isEmpty(countryCode)) { |
| | | return null; |
| | | } |
| | | for (Country country : countries) { |
| | | if (country.locale.equals(countryCode)) { |
| | | return country; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static void destroy() { |