Skip to content

Guide to add new country in list

Harsh Bhakta edited this page Dec 5, 2017 · 3 revisions

How to add new country

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

Preparing assets

  1. 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).
  2. Name that file as flag_<country_name>.png . In case of the Japan, it will be "flag_japan.png".
  3. 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-->.
  4. 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).
  5. Get name code from the official page. It's "JP" for the Japan.

Integrate with CCP

  1. Add flag file to ccp/src/main/res/drawable-nodpi/ folder. Here placing flag_japan.png in the folder will make ccp/src/main/res/drawable-nodpi/flag_japan.png.

  2. Now go to /ccp/src/main/java/com/hbb20/Country.java. Locate the method static int getFlagResID(Country country).

  3. Find the place for the country based on alphabetical index of name code of the country. For example, jp (Japan) will fit between jo (Jordan) and ke (Kenya). Remember this placement.

  4. 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;
         .......
         .......
    
  5. Locate getLibraryMasterCountriesEnglish() method in Country.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"));
     .......
     .......
    
  6. 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"/>
        .......
        .......
  1. 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.

Clone this wiki locally