diff --git a/ccp/src/main/java/com/hbb20/CountryCodeDialog.java b/ccp/src/main/java/com/hbb20/CountryCodeDialog.java index 6b53756a..7f375bbf 100644 --- a/ccp/src/main/java/com/hbb20/CountryCodeDialog.java +++ b/ccp/src/main/java/com/hbb20/CountryCodeDialog.java @@ -30,6 +30,11 @@ */ class CountryCodeDialog { public static void openCountryCodeDialog(final CountryCodePicker codePicker) { + openCountryCodeDialog(codePicker, null); + } + + public static void + openCountryCodeDialog(final CountryCodePicker codePicker, final String countryNameCode) { final Context context = codePicker.getContext(); final Dialog dialog = new Dialog(context); codePicker.refreshCustomMasterList(); @@ -178,6 +183,15 @@ public void onCancel(DialogInterface dialogInterface) { } }); + if (countryNameCode != null) { + for (int i = 0; i < masterCountries.size(); i++) { + if (masterCountries.get(i).nameCode.equals(countryNameCode)) { + recyclerView_countryDialog.scrollToPosition(i); + break; + } + } + } + dialog.show(); if (codePicker.getDialogEventsListener() != null) { codePicker.getDialogEventsListener().onCcpDialogOpen(dialog); diff --git a/ccp/src/main/java/com/hbb20/CountryCodePicker.java b/ccp/src/main/java/com/hbb20/CountryCodePicker.java index 0aba14a3..b328e1f0 100644 --- a/ccp/src/main/java/com/hbb20/CountryCodePicker.java +++ b/ccp/src/main/java/com/hbb20/CountryCodePicker.java @@ -657,7 +657,17 @@ private Language getCCPLanguageFromLocale() { Log.d(TAG, "getCCPLanguageFromLocale: current locale language" + currentLocale.getLanguage()); for (Language language : Language.values()) { if (language.getCode().equalsIgnoreCase(currentLocale.getLanguage())) { - return language; + + if (language.getCountry() == null + || language.getCountry().equalsIgnoreCase(currentLocale.getCountry())) + return language; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (language.getScript() == null + || language.getScript().equalsIgnoreCase(currentLocale.getScript())) + return language; + + } } } return null; @@ -842,7 +852,7 @@ private PhoneNumberUtil.PhoneNumberType getSelectedHintNumberType() { } } - Language getLanguageToApply() { + public Language getLanguageToApply() { if (languageToApply == null) { updateLanguageToApply(); } @@ -1922,7 +1932,15 @@ public void setPhoneNumberValidityChangeListener(FailureListener failureListener * Developer can use this to trigger manually. */ public void launchCountrySelectionDialog() { - CountryCodeDialog.openCountryCodeDialog(codePicker); + launchCountrySelectionDialog(null); + } + + /** + * Manually trigger selection dialog and set + * scroll position to specified country. + */ + public void launchCountrySelectionDialog(final String countryNameCode) { + CountryCodeDialog.openCountryCodeDialog(codePicker, countryNameCode); } /** @@ -2128,8 +2146,8 @@ public enum Language { AFRIKAANS("af"), ARABIC("ar"), BENGALI("bn"), - CHINESE_SIMPLIFIED("zh"), - CHINESE_TRADITIONAL("zh"), + CHINESE_SIMPLIFIED("zh", "CN", "Hans"), + CHINESE_TRADITIONAL("zh", "TW", "Hant"), CZECH("cs"), DUTCH("nl"), ENGLISH("en"), @@ -2154,7 +2172,15 @@ public enum Language { UKRAINIAN("uk"), UZBEK("uz"); - String code; + private String code; + private String country; + private String script; + + Language(String code, String country, String script) { + this.code = code; + this.country = country; + this.script = script; + } Language(String code) { this.code = code; @@ -2167,6 +2193,22 @@ public String getCode() { public void setCode(String code) { this.code = code; } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getScript() { + return script; + } + + public void setScript(String script) { + this.script = script; + } } public enum PhoneNumberType {