Skip to content

Commit fa83c5a

Browse files
authored
Merge branch 'master' into master
2 parents 56fef1a + 1b0414a commit fa83c5a

File tree

224 files changed

+1397
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+1397
-45
lines changed

.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: hbb20

CHANGELOG.md

+32

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package in.hbb20.countrycodepickerproject;
2+
3+
import com.hbb20.CCPCountry;
4+
import com.hbb20.CCPTalkBackTextProvider;
5+
6+
class CCPCustomTalkBackProvider implements CCPTalkBackTextProvider {
7+
@Override
8+
public String getTalkBackTextForCountry(CCPCountry country) {
9+
if (country != null) {
10+
return "Country code is +" + country.getPhoneCode();
11+
} else {
12+
return null;
13+
}
14+
}
15+
}

app/src/main/java/in/hbb20/countrycodepickerproject/IntroductionFragment.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class IntroductionFragment: Fragment() {
2828

2929
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
3030
super.onViewCreated(view, savedInstanceState)
31-
3231
assignViews()
3332
setClickListener()
33+
setCustomTalkBackProvider()
3434
}
3535

3636
private fun assignViews() {
@@ -43,4 +43,8 @@ class IntroductionFragment: Fragment() {
4343
private fun setClickListener() {
4444
buttonGo.setOnClickListener { (activity as ExampleActivity).viewPager.currentItem = 1 }
4545
}
46+
47+
private fun setCustomTalkBackProvider() {
48+
countryCodePicker.setTalkBackTextProvider(CCPCustomTalkBackProvider())
49+
}
4650
}

build.gradle

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
buildscript {
44
repositories {
55
google()
6-
jcenter()
6+
mavenCentral()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:4.2.1'
10-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
11-
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
12-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
9+
classpath 'com.android.tools.build:gradle:4.2.1'
10+
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.14.2'
11+
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.10.2'
12+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
13+
1314
// NOTE: Do not place your application dependencies here; they belong
1415
// in the individual module build.gradle files
1516
}
@@ -18,10 +19,10 @@ buildscript {
1819
allprojects {
1920
repositories {
2021
google()
21-
jcenter()
2222
maven {
2323
url "https://maven.google.com"
2424
}
25+
mavenCentral()
2526
}
2627
}
2728

ccp/build.gradle

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ext {
2525

2626
}
2727

28+
apply plugin: 'com.vanniktech.maven.publish'
2829

2930
android {
3031
compileSdkVersion 30
@@ -52,12 +53,10 @@ dependencies {
5253
testImplementation 'junit:junit:4.13.2'
5354
implementation 'androidx.recyclerview:recyclerview:1.2.0'
5455
implementation 'androidx.appcompat:appcompat:1.3.0'
55-
implementation 'io.michaelrocks:libphonenumber-android:8.12.13'
56+
implementation 'io.michaelrocks:libphonenumber-android:8.12.19-2'
5657
implementation "androidx.cardview:cardview:1.0.0"
5758
}
5859

59-
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
60-
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
6160

6261
/**
6362
* While uploading,

ccp/gradle.properties

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
GROUP=com.hbb20
2+
POM_ARTIFACT_ID=ccp
3+
VERSION_NAME=2.5.2
4+
POM_NAME=CountryCodePicker
5+
POM_PACKAGING=aar
6+
POM_DESCRIPTION=Country Code Picker (CCP) is an android library which provides an easy way to search and select international country code for the phone number.
7+
POM_INCEPTION_YEAR=2021
8+
POM_URL=https://github.com/hbb20/CountryCodePickerProject
9+
POM_SCM_URL=https://github.com/hbb20/CountryCodePickerProject
10+
POM_SCM_CONNECTION=scm:git@github.com:hbb20/CountryCodePickerProject.git
11+
POM_SCM_DEV_CONNECTION=scm:git@github.com:hbb20/CountryCodePickerProject.git
12+
POM_LICENCE_NAME=The Apache Software License, Version 2.0
13+
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
14+
POM_LICENCE_DIST=repo
15+
POM_DEVELOPER_ID=hbb20
16+
POM_DEVELOPER_NAME=Harsh Bhakta
17+
POM_DEVELOPER_URL=https://github.com/hbb20
18+
# ./gradlew ccp:uploadArchives --no-daemon --no-parallel -i
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.hbb20;
2+
3+
public interface CCPTalkBackTextProvider {
4+
public String getTalkBackTextForCountry(CCPCountry country);
5+
}
6+
7+
class InternalTalkBackTextProvider implements CCPTalkBackTextProvider {
8+
9+
@Override
10+
public String getTalkBackTextForCountry(CCPCountry country) {
11+
if (country == null) {
12+
return null;
13+
} else {
14+
return country.name + " phone code is +" + country.phoneCode;
15+
}
16+
}
17+
}
18+
19+

ccp/src/main/java/com/hbb20/CountryCodePicker.java

+40-16
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class CountryCodePicker extends RelativeLayout {
5151
static int LIB_DEFAULT_COUNTRY_CODE = 91;
5252
private static int TEXT_GRAVITY_LEFT = -1, TEXT_GRAVITY_RIGHT = 1, TEXT_GRAVITY_CENTER = 0;
5353
private static String ANDROID_NAME_SPACE = "http://schemas.android.com/apk/res/android";
54+
private CCPTalkBackTextProvider talkBackTextProvider = new InternalTalkBackTextProvider();
5455
String CCP_PREF_FILE = "CCP_PREF_FILE";
5556
int defaultCountryCode;
5657
String defaultCountryNameCode;
@@ -71,7 +72,6 @@ public class CountryCodePicker extends RelativeLayout {
7172
TextGravity currentTextGravity;
7273
String originalHint = "";
7374
int ccpPadding;
74-
7575
// see attr.xml to see corresponding values for pref
7676
AutoDetectionPref selectedAutoDetectionPref = AutoDetectionPref.SIM_NETWORK_LOCALE;
7777
PhoneNumberUtil phoneUtil;
@@ -779,6 +779,9 @@ private CCPCountry getSelectedCountry() {
779779
}
780780

781781
void setSelectedCountry(CCPCountry selectedCCPCountry) {
782+
if (talkBackTextProvider != null && talkBackTextProvider.getTalkBackTextForCountry(selectedCCPCountry) != null) {
783+
textView_selectedCountry.setContentDescription(talkBackTextProvider.getTalkBackTextForCountry(selectedCCPCountry));
784+
}
782785

783786
//force disable area code country detection
784787
countryDetectionBasedOnAreaAllowed = false;
@@ -1061,7 +1064,12 @@ Language getCustomDefaultLanguage() {
10611064
private void setCustomDefaultLanguage(Language customDefaultLanguage) {
10621065
this.customDefaultLanguage = customDefaultLanguage;
10631066
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+
}
10651073
}
10661074

10671075
private View getHolderView() {
@@ -1735,7 +1743,7 @@ public String getSelectedCountryNameCode() {
17351743
* For example for georgia it returns R.drawable.flag_georgia
17361744
*/
17371745
@DrawableRes
1738-
public int getSelectedCountryFlagResourceId(){
1746+
public int getSelectedCountryFlagResourceId() {
17391747
return getSelectedCountry().flagResID;
17401748
}
17411749

@@ -2247,7 +2255,7 @@ public boolean detectSIMCountry(boolean loadDefaultWhenFails) {
22472255
try {
22482256
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
22492257
String simCountryISO = telephonyManager.getSimCountryIso();
2250-
if (simCountryISO == null || simCountryISO.isEmpty()) {
2258+
if (simCountryISO == null || simCountryISO.isEmpty() || !isNameCodeInCustomMasterList(simCountryISO)) {
22512259
if (loadDefaultWhenFails) {
22522260
resetToDefaultCountry();
22532261
}
@@ -2264,6 +2272,16 @@ public boolean detectSIMCountry(boolean loadDefaultWhenFails) {
22642272
}
22652273
}
22662274

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+
22672285
/**
22682286
* This will detect country from NETWORK info and then load it into CCP.
22692287
*
@@ -2275,7 +2293,7 @@ public boolean detectNetworkCountry(boolean loadDefaultWhenFails) {
22752293
try {
22762294
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
22772295
String networkCountryISO = telephonyManager.getNetworkCountryIso();
2278-
if (networkCountryISO == null || networkCountryISO.isEmpty()) {
2296+
if (networkCountryISO == null || networkCountryISO.isEmpty() || !isNameCodeInCustomMasterList(networkCountryISO)) {
22792297
if (loadDefaultWhenFails) {
22802298
resetToDefaultCountry();
22812299
}
@@ -2302,7 +2320,7 @@ public boolean detectNetworkCountry(boolean loadDefaultWhenFails) {
23022320
public boolean detectLocaleCountry(boolean loadDefaultWhenFails) {
23032321
try {
23042322
String localeCountryISO = context.getResources().getConfiguration().locale.getCountry();
2305-
if (localeCountryISO == null || localeCountryISO.isEmpty()) {
2323+
if (localeCountryISO == null || localeCountryISO.isEmpty() || !isNameCodeInCustomMasterList(localeCountryISO)) {
23062324
if (loadDefaultWhenFails) {
23072325
resetToDefaultCountry();
23082326
}
@@ -2355,6 +2373,11 @@ public boolean isDialogInitialScrollToSelectionEnabled() {
23552373
return ccpDialogInitialScrollToSelection;
23562374
}
23572375

2376+
public void setTalkBackTextProvider(CCPTalkBackTextProvider talkBackTextProvider) {
2377+
this.talkBackTextProvider = talkBackTextProvider;
2378+
setSelectedCountry(selectedCCPCountry);
2379+
}
2380+
23582381
/**
23592382
* This will decide initial scroll position of countries list in dialog.
23602383
*
@@ -2422,6 +2445,7 @@ public enum Language {
24222445
SPANISH("es"),
24232446
SWEDISH("sv"),
24242447
TAGALOG("tl"),
2448+
THAI("th"),
24252449
TURKISH("tr"),
24262450
UKRAINIAN("uk"),
24272451
URDU("ur"),
@@ -2432,16 +2456,6 @@ public enum Language {
24322456
private String country;
24332457
private String script;
24342458

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-
24452459
Language(String code, String country, String script) {
24462460
this.code = code;
24472461
this.country = country;
@@ -2452,6 +2466,16 @@ public static Language forCountryNameCode(String code) {
24522466
this.code = code;
24532467
}
24542468

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+
24552479
public String getCode() {
24562480
return code;
24572481
}
-841 Bytes
-987 Bytes
-726 Bytes
-725 Bytes
-787 Bytes
-567 Bytes
-1.03 KB
-2.46 KB
-230 Bytes
-25 Bytes
-319 Bytes
-1.24 KB
-346 Bytes
-297 Bytes
-350 Bytes
-517 Bytes
-621 Bytes
-598 Bytes
-837 Bytes
-18 Bytes
-820 Bytes
-1.29 KB
-266 Bytes
-1.02 KB
-20 Bytes
-1.38 KB
-773 Bytes
-230 Bytes
-1.15 KB
-912 Bytes
-231 Bytes
-480 Bytes
-1.01 KB
-381 Bytes
-260 Bytes
-445 Bytes
-32 Bytes
-995 Bytes
-1.68 KB
-386 Bytes
-465 Bytes
-600 Bytes
-452 Bytes
-445 Bytes
-82 Bytes
-370 Bytes
-494 Bytes
-311 Bytes
-229 Bytes
-216 Bytes
-632 Bytes
-1.41 KB
-17 Bytes
-572 Bytes
-831 Bytes
-292 Bytes
-821 Bytes
-49 Bytes
-537 Bytes
-1.1 KB
-328 Bytes
-291 Bytes
-236 Bytes
-526 Bytes
-1.26 KB
-326 Bytes
-258 Bytes
-176 Bytes
-1.16 KB
-37 Bytes
-37 Bytes
-202 Bytes
-876 Bytes
-158 Bytes
-545 Bytes
-1.25 KB
-609 Bytes
-437 Bytes
-415 Bytes
-685 Bytes
-942 Bytes
-357 Bytes
-338 Bytes
-352 Bytes
-1.3 KB
-960 Bytes
-1.97 KB
-1023 Bytes
-176 Bytes
-1016 Bytes
-378 Bytes
-775 Bytes
-434 Bytes
-354 Bytes
-331 Bytes
-513 Bytes
-2 Bytes
-1.5 KB
-1.46 KB
-9 Bytes
-506 Bytes
-808 Bytes
-370 Bytes
-274 Bytes
-753 Bytes
-364 Bytes
-562 Bytes
-504 Bytes
-387 Bytes
-793 Bytes
-454 Bytes
-635 Bytes
-396 Bytes
-1.68 KB
-315 Bytes
-1.2 KB
-11 Bytes
-896 Bytes
-249 Bytes
-212 Bytes
-689 Bytes
-138 Bytes
-463 Bytes
-205 Bytes
-805 Bytes
-402 Bytes
-588 Bytes
-503 Bytes
-200 Bytes
-484 Bytes
-300 Bytes
-641 Bytes
-559 Bytes
-655 Bytes
-424 Bytes
-808 Bytes
-22 Bytes
-72 Bytes
-381 Bytes
-2.71 KB
-342 Bytes
-1.62 KB
-280 Bytes
-10 Bytes
-1023 Bytes
-547 Bytes
-823 Bytes
-639 Bytes
-395 Bytes
-344 Bytes
-997 Bytes
-800 Bytes
-1.08 KB
-849 Bytes
-158 Bytes
-3 Bytes
-1.36 KB
-225 Bytes
-330 Bytes
-1.19 KB
-99 Bytes
-134 Bytes
-382 Bytes
-561 Bytes
-280 Bytes
-957 Bytes
-2.17 KB
-474 Bytes
-285 Bytes
-85 Bytes
-608 Bytes
-331 Bytes
-518 Bytes
-1.6 KB
-36 Bytes
-329 Bytes
-1.54 KB
-677 Bytes
-489 Bytes
-1.12 KB
-538 Bytes
-308 Bytes
-340 Bytes
-616 Bytes
-476 Bytes
-526 Bytes

0 commit comments

Comments
 (0)