Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3263)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillProfileBridge.java

Issue 872023002: Use floating labels for preference forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-fix findbugs Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..3f168550f0ad5f113d9b8e23a5df6e209e6261f7
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/autofill/AutofillProfileBridge.java
@@ -0,0 +1,161 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.preferences.autofill;
+
+import android.util.Pair;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+import java.text.Collator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Static methods to fetch information needed to create the address fields for the autofill profile
+ * form.
+ */
+@JNINamespace("autofill")
+public class AutofillProfileBridge {
+ static final Collator sCollator = Collator.getInstance(Locale.getDefault());
newt (away) 2015/01/29 20:00:37 There are lots of good reasons to avoid statics wh
Theresa 2015/01/29 22:31:12 Done.
+
+
+ /**
+ * @return The CLDR region code for the default locale.
+ */
+ public static String getDefaultCountryCode() {
+ 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>();
+
+ nativeGetSupportedCountries(countryCodes, countryNames);
+
+ for (int i = 0; i < countryCodes.size(); i++) {
+ countries.add(new Country(countryNames.get(i), countryCodes.get(i)));
+ }
+
+ sCollator.setStrength(Collator.PRIMARY);
+ Collections.sort(countries);
+
+ return countries;
+ }
+
+ /**
+ * Returns the UI components for the CLDR countryCode provided.
+ *
+ * @param countryCode The CLDR code used to retrieve address components.
+ * @return A list containing pairs of strings, where the first element in the pair is the
newt (away) 2015/01/29 20:00:37 it's not pairs of strings anymore
Theresa 2015/01/29 22:31:12 Done.
+ * component id (one of the static int's in AddressField), and the second element
newt (away) 2015/01/29 20:00:37 s/static ints/constants
Theresa 2015/01/29 22:31:12 Done.
+ * 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.
+ */
+ static List<Pair<Integer, String>> getAddressUiComponents(String countryCode) {
+ List<Integer> componentIds = new ArrayList<Integer>();
+ List<String> componentNames = new ArrayList<String>();
+ List<Pair<Integer, String>> uiComponents = new ArrayList<Pair<Integer, String>>();
+
+ nativeGetAddressUiComponents(countryCode, componentIds, componentNames);
+
+ for (int i = 0; i < componentIds.size(); i++) {
+ uiComponents.add(new Pair<Integer, String>(componentIds.get(i), componentNames.get(i)));
+ }
+
+ return uiComponents;
+ }
+
+ @CalledByNative
+ private static void stringArrayToList(String[] array, List<String> list) {
+ for (String s : array) {
+ list.add(s);
+ }
+ }
+
+ @CalledByNative
+ private static void intArrayToList(int[] array, List<Integer> list) {
+ for (int s : array) {
+ list.add(s);
+ }
+ }
+
+ private static native String nativeGetDefaultCountryCode();
+ private static native void nativeGetSupportedCountries(List<String> countryCodes,
+ List<String> countryNames);
+ private static native void nativeGetAddressUiComponents(String countryCode,
+ List<Integer> componentIds, List<String> componentNames);
+}
+
+/**
+ * Address field types, ordered by size, from largest to smallest.
newt (away) 2015/01/29 20:00:37 What do you mean "ordered by size"? Size of what?
Theresa 2015/01/29 22:31:12 I think it means country > region (e.g. state) > l
+ * This list must be kept in-sync with the corresponding enum in auotfill_profile_bridge.cc.
+ */
+class AddressField {
newt (away) 2015/01/29 20:00:37 Put these classes inside of AutofillProfileBridge.
Theresa 2015/01/29 22:31:12 Done.
+ public static final int COUNTRY = 0;
newt (away) 2015/01/29 20:00:37 I'd remove "public" since the class itself isn't p
Theresa 2015/01/29 22:31:12 Done.
+ 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 it's corresponding
+ * localized display name.
+ */
+class Country implements Comparable<Country> {
+ String mName;
+ String mCode;
+
+ public Country(String name, String code) {
+ mName = name;
+ mCode = code;
+ }
+
+ @Override
+ public int compareTo(Country other) {
+ if (mName.equals(other.mName)) {
+ return mCode.compareTo(other.mCode);
+ }
+ return AutofillProfileBridge.sCollator.compare(mName, other.mName);
+ }
+
+ @Override
+ public boolean equals(Object other) {
newt (away) 2015/01/29 20:00:37 Let's not go overboard with implementing methods t
Theresa 2015/01/29 22:31:12 Done.
+ if (!(other instanceof Country)) {
+ return false;
+ }
+ return compareTo((Country) other) == 0;
+ }
+
+ @Override
+ public int hashCode() {
+ // Note: auto-generated by Eclipse.
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((mCode == null) ? 0 : mCode.hashCode());
+ result = prime * result + ((mName == null) ? 0 : mName.hashCode());
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return mName;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698