Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillProfileBridge.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillProfileBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillProfileBridge.java |
index 755cb67d7c8019305fee26e2d9690b81bacc9d9e..4a638ec26832cc7d0d355390094bc9388c0fdfab 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillProfileBridge.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillProfileBridge.java |
@@ -25,38 +25,44 @@ public class AutofillProfileBridge { |
/** |
* Address field types. |
- * This list must be kept in-sync with the corresponding enum in auotfill_profile_bridge.cc. |
+ * This list must be kept in-sync with the corresponding enum in |
+ * third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h |
*/ |
- static class AddressField { |
- static final int COUNTRY = 0; |
- static final int ADMIN_AREA = 1; |
- static final int LOCALITY = 2; |
- static final int DEPENDENT_LOCALITY = 3; |
- static final int SORTING_CODE = 4; |
- static final int POSTAL_CODE = 5; |
- static final int STREET_ADDRESS = 6; |
- static final int ORGANIZATION = 7; |
- static final int RECIPIENT = 8; |
- |
- static final int NUM_FIELDS = 9; |
+ public static class AddressField { |
+ public static final int COUNTRY = 0; |
+ public static final int ADMIN_AREA = 1; |
+ public static final int LOCALITY = 2; |
+ public static final int DEPENDENT_LOCALITY = 3; |
+ public static final int SORTING_CODE = 4; |
+ public static final int POSTAL_CODE = 5; |
+ public static final int STREET_ADDRESS = 6; |
+ public static final int ORGANIZATION = 7; |
+ public static final int RECIPIENT = 8; |
+ |
+ public static final int NUM_FIELDS = 9; |
} |
/** |
- * A convenience class for storing a CLDR country code and its corresponding |
- * localized display name. |
+ * A convenience class for displaying keyed values in a dropdown. |
*/ |
- static class Country { |
- String mName; |
- String mCode; |
+ public static class DropdownKeyValue extends Pair<String, String> { |
+ DropdownKeyValue(String key, String value) { |
+ super(key, value); |
+ } |
+ |
+ /** @return The key identifier. */ |
+ public String getKey() { |
+ return super.first; |
+ } |
- Country(String name, String code) { |
- mName = name; |
- mCode = code; |
+ /** @return The human-readable localized display value. */ |
+ public String getValue() { |
+ return super.second; |
} |
@Override |
public String toString() { |
- return mName; |
+ return super.second; |
} |
} |
@@ -69,28 +75,25 @@ public class AutofillProfileBridge { |
return nativeGetDefaultCountryCode(); |
} |
- /** |
- * @return The list of supported countries sorted by their localized display |
- * names. |
- */ |
- static List<Country> getSupportedCountries() { |
- List<String> countryCodes = new ArrayList<String>(); |
- List<String> countryNames = new ArrayList<String>(); |
- List<Country> countries = new ArrayList<Country>(); |
+ /** @return The list of supported countries sorted by their localized display names. */ |
+ public static List<DropdownKeyValue> getSupportedCountries() { |
+ List<String> countryCodes = new ArrayList<>(); |
+ List<String> countryNames = new ArrayList<>(); |
+ List<DropdownKeyValue> countries = new ArrayList<>(); |
nativeGetSupportedCountries(countryCodes, countryNames); |
for (int i = 0; i < countryCodes.size(); i++) { |
- countries.add(new Country(countryNames.get(i), countryCodes.get(i))); |
+ countries.add(new DropdownKeyValue(countryCodes.get(i), countryNames.get(i))); |
} |
final Collator collator = Collator.getInstance(Locale.getDefault()); |
collator.setStrength(Collator.PRIMARY); |
- Collections.sort(countries, new Comparator<Country>() { |
+ Collections.sort(countries, new Comparator<DropdownKeyValue>() { |
@Override |
- public int compare(Country lhs, Country rhs) { |
- int result = collator.compare(lhs.mName, rhs.mName); |
- if (result == 0) result = lhs.mCode.compareTo(rhs.mCode); |
+ public int compare(DropdownKeyValue lhs, DropdownKeyValue rhs) { |
+ int result = collator.compare(lhs.getValue(), rhs.getValue()); |
+ if (result == 0) result = lhs.getKey().compareTo(rhs.getKey()); |
return result; |
} |
}); |
@@ -98,6 +101,45 @@ public class AutofillProfileBridge { |
return countries; |
} |
+ /** @return The list of required fields. COUNTRY is always included. RECIPIENT often omitted. */ |
+ public static List<Integer> getRequiredAddressFields(String countryCode) { |
+ List<Integer> requiredFields = new ArrayList<>(); |
+ nativeGetRequiredFields(countryCode, requiredFields); |
+ return requiredFields; |
+ } |
+ |
+ /** |
+ * Description of an address editor input field. |
+ */ |
+ public static class AddressUiComponent { |
+ /** The type of the field, e.g., AddressField.LOCALITY. */ |
+ public final int id; |
+ |
+ /** The localized display label for the field, e.g., "City." */ |
+ public final String label; |
+ |
+ /** Whether the field is required. */ |
+ public final boolean isRequired; |
+ |
+ /** Whether the field takes up the full line.*/ |
+ public final boolean isFullLine; |
+ |
+ /** |
+ * Builds a description of an address editor input field. |
+ * |
+ * @param id The type of the field, .e.g., AddressField.LOCALITY. |
+ * @param label The localized display label for the field, .e.g., "City." |
+ * @param isRequired Whether the field is required. |
+ * @param isFullLine Whether the field takes up the full line. |
+ */ |
+ public AddressUiComponent(int id, String label, boolean isRequired, boolean isFullLine) { |
+ this.id = id; |
+ this.label = label; |
+ this.isRequired = isRequired; |
+ this.isFullLine = isFullLine; |
+ } |
+ } |
+ |
/** |
* Returns the UI components for the CLDR countryCode and languageCode provided. If no language |
* code is provided, the application's default locale is used instead. Also stores the |
@@ -108,24 +150,23 @@ public class AutofillProfileBridge { |
* @param languageCode The language code associated with the saved autofill profile that ui |
* components are being retrieved for; can be null if ui components are |
* being retrieved for a new profile. |
- * @return A list containing pairs where the first element in the pair is an Integer |
- * representing the component id (one of the constants in AddressField), and the second |
- * element in the pair is the localized component name (intended for use as labels in |
- * the UI). The ordering in the list of pairs specifies the order these components |
- * should appear in the UI. |
+ * @return A list of address UI components. The ordering in the list specifies the order these |
+ * components should appear in the UI. |
*/ |
- List<Pair<Integer, String>> getAddressUiComponents(String countryCode, |
- String languageCode) { |
- List<Integer> componentIds = new ArrayList<Integer>(); |
- List<String> componentNames = new ArrayList<String>(); |
- List<Pair<Integer, String>> uiComponents = new ArrayList<Pair<Integer, String>>(); |
+ public List<AddressUiComponent> getAddressUiComponents( |
+ String countryCode, String languageCode) { |
+ List<Integer> componentIds = new ArrayList<>(); |
+ List<String> componentNames = new ArrayList<>(); |
+ List<Integer> componentRequired = new ArrayList<>(); |
+ List<Integer> componentLengths = new ArrayList<>(); |
+ List<AddressUiComponent> uiComponents = new ArrayList<>(); |
- mCurrentBestLanguageCode = |
- nativeGetAddressUiComponents(countryCode, languageCode, componentIds, |
- componentNames); |
+ mCurrentBestLanguageCode = nativeGetAddressUiComponents(countryCode, languageCode, |
+ componentIds, componentNames, componentRequired, componentLengths); |
for (int i = 0; i < componentIds.size(); i++) { |
- uiComponents.add(new Pair<Integer, String>(componentIds.get(i), componentNames.get(i))); |
+ uiComponents.add(new AddressUiComponent(componentIds.get(i), componentNames.get(i), |
+ componentRequired.get(i) == 1, componentLengths.get(i) == 1)); |
} |
return uiComponents; |
@@ -135,7 +176,7 @@ public class AutofillProfileBridge { |
* @return The language code associated with the most recently retrieved address ui components. |
* Will return null if getAddressUiComponents() has not been called yet. |
*/ |
- String getCurrentBestLanguageCode() { |
+ public String getCurrentBestLanguageCode() { |
return mCurrentBestLanguageCode; |
} |
@@ -156,6 +197,9 @@ public class AutofillProfileBridge { |
private static native String nativeGetDefaultCountryCode(); |
private static native void nativeGetSupportedCountries(List<String> countryCodes, |
List<String> countryNames); |
+ private static native void nativeGetRequiredFields( |
+ String countryCode, List<Integer> requiredFields); |
private static native String nativeGetAddressUiComponents(String countryCode, |
- String languageCode, List<Integer> componentIds, List<String> componentNames); |
+ String languageCode, List<Integer> componentIds, List<String> componentNames, |
+ List<Integer> componentRequired, List<Integer> componentLengths); |
} |