diff options
author | Ed Falk <efalk@cyngn.com> | 2015-09-11 10:37:01 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2015-09-14 12:32:58 -0700 |
commit | dfd1a96ad223be7c5a7f6c95a2fad5a46f6f16de (patch) | |
tree | 41b9c7eac6d081150ca45110c0577ff858b85d68 | |
parent | b927b86d927bf209c26779243cb741e4b84ffbc2 (diff) | |
download | android_hardware_qcom_fm-dfd1a96ad223be7c5a7f6c95a2fad5a46f6f16de.tar.gz android_hardware_qcom_fm-dfd1a96ad223be7c5a7f6c95a2fad5a46f6f16de.tar.bz2 android_hardware_qcom_fm-dfd1a96ad223be7c5a7f6c95a2fad5a46f6f16de.zip |
FMRadio : cleaned up band selection code
Based on the code reviews on my previous commit, my earlier
code (which was admittedly slapped together in a hurry) was
too sloppy. this is a more elegant solution.
Change-Id: I08fc64ad628a3c8cb9e634310b89ac8abae2d7c8
Issue-id: CYNGNOS-738
-rw-r--r-- | fmapp2/src/com/caf/fmradio/FmSharedPreferences.java | 119 |
1 files changed, 60 insertions, 59 deletions
diff --git a/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java b/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java index a26c179..903d280 100644 --- a/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java +++ b/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java @@ -81,6 +81,7 @@ public class FmSharedPreferences public static final int REGIONAL_BAND_UNITED_STATES = 35; public static final int REGIONAL_BAND_USER_DEFINED = 36; public static final int REGIONAL_BAND_INDONESIA = 37; + // If you add to this list, add to getBand() below as well. public static final int RECORD_DUR_INDEX_0_VAL = 5; public static final int RECORD_DUR_INDEX_1_VAL = 15; @@ -1178,69 +1179,69 @@ public class FmSharedPreferences * in the list, takes the default from resources. */ private static int getBand(int deflt) { - String country = Locale.getDefault().getCountry(); - // The order of country codes in this list is very strict. The - // majority of region band codes are for a single country, but - // Europe (the second item) is an exception. - final String[] countries = { - "CA", // REGIONAL_BAND_NORTH_AMERICA; - "--", // REGIONAL_BAND_EUROPE; - "JP", // REGIONAL_BAND_JAPAN; - "JP", // REGIONAL_BAND_JAPAN_WIDE; - "AU", // REGIONAL_BAND_AUSTRALIA; - "AT", // REGIONAL_BAND_AUSTRIA; - "BE", // REGIONAL_BAND_BELGIUM; - "BR", // REGIONAL_BAND_BRAZIL; - "CN", // REGIONAL_BAND_CHINA; - "CZ", // REGIONAL_BAND_CZECH; - "DK", // REGIONAL_BAND_DENMARK; - "FI", // REGIONAL_BAND_FINLAND; - "FR", // REGIONAL_BAND_FRANCE; - "DE", // REGIONAL_BAND_GERMANY; - "GR", // REGIONAL_BAND_GREECE; - "HK", // REGIONAL_BAND_HONGKONG; - "IN", // REGIONAL_BAND_INDIA; - "IE", // REGIONAL_BAND_IRELAND; - "IT", // REGIONAL_BAND_ITALY; - "KR", // REGIONAL_BAND_KOREA; - "MX", // REGIONAL_BAND_MEXICO; - "NL", // REGIONAL_BAND_NETHERLANDS; - "NZ", // REGIONAL_BAND_NEWZEALAND; - "NO", // REGIONAL_BAND_NORWAY; - "PL", // REGIONAL_BAND_POLAND; - "PT", // REGIONAL_BAND_PORTUGAL; - "RU", // REGIONAL_BAND_RUSSIA; - "SG", // REGIONAL_BAND_SINGAPORE; - "SK", // REGIONAL_BAND_SLOVAKIA; - "ES", // REGIONAL_BAND_SPAIN; - "CH", // REGIONAL_BAND_SWITZERLAND; - "SE", // REGIONAL_BAND_SWEDEN; - "TW", // REGIONAL_BAND_TAIWAN; - "TR", // REGIONAL_BAND_TURKEY; - "GB", // REGIONAL_BAND_UNITEDKINGDOM; - "US", // REGIONAL_BAND_UNITED_STATES; - "--", // REGIONAL_BAND_USER_DEFINED; - "ID", // REGIONAL_BAND_INDONESIA; + return getBand(Locale.getDefault().getCountry(), deflt); + } + + private static int getBand(String country, int deflt) { + // The order of country codes in this list is very strict; it + // needs to exactly correspond to the REGIONAL_BAND definitions + // at the top of this file. That is why there are two "JP" + // entries, one of which is unreachable, and why there is a + // placeholder for REGIONAL_BAND_USER_DEFINED. + // Some of these entries are intelligent guesses, e.g. my + // research indicates that Geurnsey, Jersey, and the Isle of Man + // use the same standards as GB. + // Many, many countries are not listed. Those will receive the + // default setting specified in the resources file. + final String[][] countries = { + {"CA"}, // REGIONAL_BAND_NORTH_AMERICA + {"AL", "AD", "AM", "AZ", "BY", "BA", "BG", "HR", "CY", "EE", + "GE", "HU", "IS", "KZ", "LV", "LI", "LT", "LU", "MK", "MT", + "MD", "MC", "ME", "RO", "SM", "RS", "SK", "SI", "UA", "VA"}, // REGIONAL_BAND_EUROPE + {"JP"}, // REGIONAL_BAND_JAPAN + {"JP"}, // REGIONAL_BAND_JAPAN_WIDE (not reached) + {"AU"}, // REGIONAL_BAND_AUSTRALIA + {"AT"}, // REGIONAL_BAND_AUSTRIA + {"BE"}, // REGIONAL_BAND_BELGIUM + {"BR"}, // REGIONAL_BAND_BRAZIL + {"CN"}, // REGIONAL_BAND_CHINA + {"CZ"}, // REGIONAL_BAND_CZECH + {"DK"}, // REGIONAL_BAND_DENMARK + {"FI"}, // REGIONAL_BAND_FINLAND + {"FR"}, // REGIONAL_BAND_FRANCE + {"DE"}, // REGIONAL_BAND_GERMANY + {"GR"}, // REGIONAL_BAND_GREECE + {"HK"}, // REGIONAL_BAND_HONGKONG + {"IN"}, // REGIONAL_BAND_INDIA + {"IE"}, // REGIONAL_BAND_IRELAND + {"IT"}, // REGIONAL_BAND_ITALY + {"KR"}, // REGIONAL_BAND_KOREA + {"MX"}, // REGIONAL_BAND_MEXICO + {"NL"}, // REGIONAL_BAND_NETHERLANDS + {"NZ"}, // REGIONAL_BAND_NEWZEALAND + {"NO","IS"}, // REGIONAL_BAND_NORWAY + {"PL"}, // REGIONAL_BAND_POLAND + {"PT"}, // REGIONAL_BAND_PORTUGAL + {"RU"}, // REGIONAL_BAND_RUSSIA + {"SG"}, // REGIONAL_BAND_SINGAPORE + {"SK"}, // REGIONAL_BAND_SLOVAKIA + {"ES"}, // REGIONAL_BAND_SPAIN + {"CH"}, // REGIONAL_BAND_SWITZERLAND + {"SE"}, // REGIONAL_BAND_SWEDEN + {"TW"}, // REGIONAL_BAND_TAIWAN + {"TR"}, // REGIONAL_BAND_TURKEY + {"GB","GG","IM","JE"}, // REGIONAL_BAND_UNITEDKINGDOM + {"US"}, // REGIONAL_BAND_UNITED_STATES + {"--"}, // REGIONAL_BAND_USER_DEFINED (handled elsewhere) + {"ID"}, // REGIONAL_BAND_INDONESIA }; - final String[] europe = { - "AL", "AD", "AM", "AZ", "BY", "BA", "BG", "HR", "CY", "EE", - "GE", "HU", "IS", "KZ", "LV", "LI", "LT", "LU", "MK", "MT", - "MD", "MC", "ME", "RO", "SM", "RS", "SK", "SI", "UA", "VA"}; for (int band = 0; band < countries.length; ++band) { - if (countries[band].equals(country)) { - return band; - } - } - for (String cc : europe) { - if (cc.equals(country)) { - return REGIONAL_BAND_EUROPE; + for (String cc : countries[band]) { + if (cc.equals(country)) { + return band; + } } } - // Special cases: - if (country.equals("GG")) return REGIONAL_BAND_UNITEDKINGDOM; - if (country.equals("IM")) return REGIONAL_BAND_UNITEDKINGDOM; - if (country.equals("JE")) return REGIONAL_BAND_UNITEDKINGDOM; - if (country.equals("IS")) return REGIONAL_BAND_NORWAY; return deflt; } } |