Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish zh_CN/zh_TW by Locale country and script #236

Merged
merged 4 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ccp/src/main/java/com/hbb20/CountryCodeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
54 changes: 48 additions & 6 deletions ccp/src/main/java/com/hbb20/CountryCodePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -842,7 +852,7 @@ private PhoneNumberUtil.PhoneNumberType getSelectedHintNumberType() {
}
}

Language getLanguageToApply() {
public Language getLanguageToApply() {
if (languageToApply == null) {
updateLanguageToApply();
}
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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"),
Expand All @@ -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;
Expand All @@ -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 {
Expand Down