@@ -51,6 +51,7 @@ public class CountryCodePicker extends RelativeLayout {
51
51
static int LIB_DEFAULT_COUNTRY_CODE = 91 ;
52
52
private static int TEXT_GRAVITY_LEFT = -1 , TEXT_GRAVITY_RIGHT = 1 , TEXT_GRAVITY_CENTER = 0 ;
53
53
private static String ANDROID_NAME_SPACE = "http://schemas.android.com/apk/res/android" ;
54
+ private CCPTalkBackTextProvider talkBackTextProvider = new InternalTalkBackTextProvider ();
54
55
String CCP_PREF_FILE = "CCP_PREF_FILE" ;
55
56
int defaultCountryCode ;
56
57
String defaultCountryNameCode ;
@@ -71,7 +72,6 @@ public class CountryCodePicker extends RelativeLayout {
71
72
TextGravity currentTextGravity ;
72
73
String originalHint = "" ;
73
74
int ccpPadding ;
74
-
75
75
// see attr.xml to see corresponding values for pref
76
76
AutoDetectionPref selectedAutoDetectionPref = AutoDetectionPref .SIM_NETWORK_LOCALE ;
77
77
PhoneNumberUtil phoneUtil ;
@@ -779,6 +779,9 @@ private CCPCountry getSelectedCountry() {
779
779
}
780
780
781
781
void setSelectedCountry (CCPCountry selectedCCPCountry ) {
782
+ if (talkBackTextProvider != null && talkBackTextProvider .getTalkBackTextForCountry (selectedCCPCountry ) != null ) {
783
+ textView_selectedCountry .setContentDescription (talkBackTextProvider .getTalkBackTextForCountry (selectedCCPCountry ));
784
+ }
782
785
783
786
//force disable area code country detection
784
787
countryDetectionBasedOnAreaAllowed = false ;
@@ -1061,7 +1064,12 @@ Language getCustomDefaultLanguage() {
1061
1064
private void setCustomDefaultLanguage (Language customDefaultLanguage ) {
1062
1065
this .customDefaultLanguage = customDefaultLanguage ;
1063
1066
updateLanguageToApply ();
1064
- setSelectedCountry (CCPCountry .getCountryForNameCodeFromLibraryMasterList (context , getLanguageToApply (), selectedCCPCountry .getNameCode ()));
1067
+ if (selectedCCPCountry != null ) {
1068
+ CCPCountry country = CCPCountry .getCountryForNameCodeFromLibraryMasterList (context , getLanguageToApply (), selectedCCPCountry .getNameCode ());
1069
+ if (country != null ) {
1070
+ setSelectedCountry (country );
1071
+ }
1072
+ }
1065
1073
}
1066
1074
1067
1075
private View getHolderView () {
@@ -1735,7 +1743,7 @@ public String getSelectedCountryNameCode() {
1735
1743
* For example for georgia it returns R.drawable.flag_georgia
1736
1744
*/
1737
1745
@ DrawableRes
1738
- public int getSelectedCountryFlagResourceId (){
1746
+ public int getSelectedCountryFlagResourceId () {
1739
1747
return getSelectedCountry ().flagResID ;
1740
1748
}
1741
1749
@@ -2247,7 +2255,7 @@ public boolean detectSIMCountry(boolean loadDefaultWhenFails) {
2247
2255
try {
2248
2256
TelephonyManager telephonyManager = (TelephonyManager ) context .getSystemService (Context .TELEPHONY_SERVICE );
2249
2257
String simCountryISO = telephonyManager .getSimCountryIso ();
2250
- if (simCountryISO == null || simCountryISO .isEmpty ()) {
2258
+ if (simCountryISO == null || simCountryISO .isEmpty () || ! isNameCodeInCustomMasterList ( simCountryISO ) ) {
2251
2259
if (loadDefaultWhenFails ) {
2252
2260
resetToDefaultCountry ();
2253
2261
}
@@ -2264,6 +2272,16 @@ public boolean detectSIMCountry(boolean loadDefaultWhenFails) {
2264
2272
}
2265
2273
}
2266
2274
2275
+ private boolean isNameCodeInCustomMasterList (String nameCode ) {
2276
+ List <CCPCountry > allowedList = CCPCountry .getCustomMasterCountryList (context , this );
2277
+ for (CCPCountry country : allowedList ) {
2278
+ if (country .nameCode .equalsIgnoreCase (nameCode )) {
2279
+ return true ;
2280
+ }
2281
+ }
2282
+ return false ;
2283
+ }
2284
+
2267
2285
/**
2268
2286
* This will detect country from NETWORK info and then load it into CCP.
2269
2287
*
@@ -2275,7 +2293,7 @@ public boolean detectNetworkCountry(boolean loadDefaultWhenFails) {
2275
2293
try {
2276
2294
TelephonyManager telephonyManager = (TelephonyManager ) context .getSystemService (Context .TELEPHONY_SERVICE );
2277
2295
String networkCountryISO = telephonyManager .getNetworkCountryIso ();
2278
- if (networkCountryISO == null || networkCountryISO .isEmpty ()) {
2296
+ if (networkCountryISO == null || networkCountryISO .isEmpty () || ! isNameCodeInCustomMasterList ( networkCountryISO ) ) {
2279
2297
if (loadDefaultWhenFails ) {
2280
2298
resetToDefaultCountry ();
2281
2299
}
@@ -2302,7 +2320,7 @@ public boolean detectNetworkCountry(boolean loadDefaultWhenFails) {
2302
2320
public boolean detectLocaleCountry (boolean loadDefaultWhenFails ) {
2303
2321
try {
2304
2322
String localeCountryISO = context .getResources ().getConfiguration ().locale .getCountry ();
2305
- if (localeCountryISO == null || localeCountryISO .isEmpty ()) {
2323
+ if (localeCountryISO == null || localeCountryISO .isEmpty () || ! isNameCodeInCustomMasterList ( localeCountryISO ) ) {
2306
2324
if (loadDefaultWhenFails ) {
2307
2325
resetToDefaultCountry ();
2308
2326
}
@@ -2355,6 +2373,11 @@ public boolean isDialogInitialScrollToSelectionEnabled() {
2355
2373
return ccpDialogInitialScrollToSelection ;
2356
2374
}
2357
2375
2376
+ public void setTalkBackTextProvider (CCPTalkBackTextProvider talkBackTextProvider ) {
2377
+ this .talkBackTextProvider = talkBackTextProvider ;
2378
+ setSelectedCountry (selectedCCPCountry );
2379
+ }
2380
+
2358
2381
/**
2359
2382
* This will decide initial scroll position of countries list in dialog.
2360
2383
*
@@ -2422,6 +2445,7 @@ public enum Language {
2422
2445
SPANISH ("es" ),
2423
2446
SWEDISH ("sv" ),
2424
2447
TAGALOG ("tl" ),
2448
+ THAI ("th" ),
2425
2449
TURKISH ("tr" ),
2426
2450
UKRAINIAN ("uk" ),
2427
2451
URDU ("ur" ),
@@ -2432,16 +2456,6 @@ public enum Language {
2432
2456
private String country ;
2433
2457
private String script ;
2434
2458
2435
- public static Language forCountryNameCode (String code ) {
2436
- Language lang = Language .ENGLISH ;
2437
- for (Language language : Language .values ()) {
2438
- if (language .code .equals (code )) {
2439
- lang = language ;
2440
- }
2441
- }
2442
- return lang ;
2443
- }
2444
-
2445
2459
Language (String code , String country , String script ) {
2446
2460
this .code = code ;
2447
2461
this .country = country ;
@@ -2452,6 +2466,16 @@ public static Language forCountryNameCode(String code) {
2452
2466
this .code = code ;
2453
2467
}
2454
2468
2469
+ public static Language forCountryNameCode (String code ) {
2470
+ Language lang = Language .ENGLISH ;
2471
+ for (Language language : Language .values ()) {
2472
+ if (language .code .equals (code )) {
2473
+ lang = language ;
2474
+ }
2475
+ }
2476
+ return lang ;
2477
+ }
2478
+
2455
2479
public String getCode () {
2456
2480
return code ;
2457
2481
}
0 commit comments