-
-
Notifications
You must be signed in to change notification settings - Fork 509
Guide to add new country in list
Oh, CCP missing some country? sorry about that. But it can be added easily and can be helpful to other developers from all over the world.
Assume that we want to add japan
- Get image file of flag (Generally 80 x 52 px flags are used. If ratio differs from 80x52 then use flag by keeping width = 80).
- Name that file as flag_<country_name>.png . In case of the Japan, it will be "flag_japan.png".
- CCP supports various languages. For that, we need to translate country name into all other languages. (List of languages can be found in this file under
<!--list of languages-->
. - Get international phone code for the country. Here it's +81 for Japan. (If you are not sure, Google search with
japan phone code
will be helpful). - Get name code from the official page. It's "JP" for the Japan.
-
Add flag file to
ccp/src/main/res/drawable-nodpi/
folder. Here placingflag_japan.png
in the folder will makeccp/src/main/res/drawable-nodpi/flag_japan.png
. -
Now go to
/ccp/src/main/java/com/hbb20/Country.java
. Locate the methodstatic int getFlagResID(Country country)
. -
Find the place for the country based on alphabetical index of name code of the country. For example,
jp
(Japan) will fit betweenjo
(Jordan) andke
(Kenya). Remember this placement. -
Add a new country case to this list. It will now look like...
....... ....... case "jo": //jordan return R.drawable.flag_jordan; case "jp": //japan return R.drawable.flag_japan; case "ke": //kenya return R.drawable.flag_kenya; ....... .......
-
Locate
getLibraryMasterCountriesEnglish()
method inCountry.java
and add country's entry with English translation at the same position as step 3. (This list is used for layout preview in editor)....... ....... countries.add(new Country("jo", "962", "Jordan")); countries.add(new Country("jp", "81", "Japan")); countries.add(new Country("ke", "254", "Kenya")); ....... .......
-
Go to "ccp/src/main/res/raw/a_new_lang_template.xml" and locate the new country placement as step 3. And make an entry there.
.......
.......
<country
name="TODO: replace with translated country name"
english_name="Jordan"
name_code="jo"
phone_code="962"/>
<country
name="TODO: replace with translated country name"
english_name="Japan"
name_code="jp"
phone_code="81"/>
<country
name="TODO: replace with translated country name"
english_name="Kenya"
name_code="ke"
phone_code="254"/>
.......
.......
- Go to all other xml files of different languages in "ccp/src/main/res/raw/" and add an entry of the new country with respective translation. Placement of new country's entry should be the same as step 3.
All set 👍. Now run the app just verify if you can see the new country in the list (even for different languages). Send a Pull Request.
- How to Integrate into your project
- Full Number Support
- Use as a Country Selector
- Auto detect country
- Auto detect language
- Remember last selection
- Country Preference
- Custom Mater List
- Exclude Countries
- Example phonenumber as hint
- Multi Language Support
- Default Country
- Country Selection Listener
- Dialog events listener
- CCP Theme Customization
- CCP Dialog Theme Customization
- Custom TypeFace
- Read Selected Country
- XML Properties
- Update Guide to v2
- Guide to Add New Language Support
- Guide to add New Country
- Change contry names for local project
- Handle CCP ClickListener Manually
- Custom Dialog Title/Hint/Empty Result ACK
- Flag Emoji Support (BETA)
- Change Log