summaryrefslogtreecommitdiffstats
path: root/chrome/android
diff options
context:
space:
mode:
authoryusufo@chromium.org <yusufo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-04 09:43:47 +0000
committeryusufo@chromium.org <yusufo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-04 09:43:47 +0000
commitaffdd4bf02851f3611c3226a50e8583f93f7b26e (patch)
tree3561280f4e847eb7d2c9b5b0ee76bfdd8feb1c44 /chrome/android
parentae5d47a13edfc10300db0afdbbe3c2038921096a (diff)
downloadchromium_src-affdd4bf02851f3611c3226a50e8583f93f7b26e.zip
chromium_src-affdd4bf02851f3611c3226a50e8583f93f7b26e.tar.gz
chromium_src-affdd4bf02851f3611c3226a50e8583f93f7b26e.tar.bz2
Add dropdowns to autofill dialog
Adding the dropdown for country, month and year with the glue that gives the related string array for a given field. Made changes so the dialog calls are aware that some views in the edit layout are spinners and not edittexts. This gives a non-null UI element for each field now. BUG=181538 NOTRY=true Review URL: https://chromiumcodereview.appspot.com/13446004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192268 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/android')
-rw-r--r--chrome/android/java/res/layout/autofill_editing_layout_credit_card.xml29
-rw-r--r--chrome/android/java/res/layout/autofill_editing_layout_shipping.xml12
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialog.java81
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogContentView.java31
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogGlue.java6
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogUtils.java24
6 files changed, 136 insertions, 47 deletions
diff --git a/chrome/android/java/res/layout/autofill_editing_layout_credit_card.xml b/chrome/android/java/res/layout/autofill_editing_layout_credit_card.xml
index 7e18c83..d78b929 100644
--- a/chrome/android/java/res/layout/autofill_editing_layout_credit_card.xml
+++ b/chrome/android/java/res/layout/autofill_editing_layout_credit_card.xml
@@ -21,16 +21,16 @@
android:textSize="@dimen/autofill_edit_text_size"
android:layout_gravity="fill_horizontal"
android:layout_columnSpan="4"/>
- <EditText
+ <Spinner
android:layout_height="@dimen/autofill_edit_height"
- android:id="@+id/expiration_month"
- android:layout_margin="@dimen/autofill_edit_margin"
- android:textSize="@dimen/autofill_edit_text_size"/>
- <EditText
+ android:layout_margin="5dp"
+ android:id="@+id/expiration_month_spinner"
+ android:layout_gravity="fill_horizontal"/>
+ <Spinner
android:layout_height="@dimen/autofill_edit_height"
- android:id="@+id/expiration_year"
- android:layout_margin="@dimen/autofill_edit_margin"
- android:textSize="@dimen/autofill_edit_text_size"/>
+ android:layout_margin="5dp"
+ android:id="@+id/expiration_year_spinner"
+ android:layout_gravity="fill_horizontal"/>
<Space
android:layout_columnSpan="1"
android:layout_gravity="fill"/>
@@ -77,11 +77,24 @@
android:layout_columnSpan="4"/>
<EditText
android:layout_height="@dimen/autofill_edit_height"
+ android:id="@+id/billing_state"
+ android:layout_margin="@dimen/autofill_edit_margin"
+ android:textSize="@dimen/autofill_edit_text_size"
+ android:layout_gravity="fill_horizontal"
+ android:layout_columnSpan="4"/>
+ <EditText
+ android:layout_height="@dimen/autofill_edit_height"
android:id="@+id/billing_zip_code"
android:layout_margin="@dimen/autofill_edit_margin"
android:textSize="@dimen/autofill_edit_text_size"
android:layout_gravity="fill_horizontal"
android:layout_columnSpan="4"/>
+ <Spinner
+ android:layout_height="@dimen/autofill_edit_height"
+ android:layout_margin="5dp"
+ android:id="@+id/billing_country_spinner"
+ android:layout_gravity="fill_horizontal"
+ android:layout_columnSpan="4"/>
<EditText
android:layout_height="@dimen/autofill_edit_height"
android:id="@+id/billing_phone_number"
diff --git a/chrome/android/java/res/layout/autofill_editing_layout_shipping.xml b/chrome/android/java/res/layout/autofill_editing_layout_shipping.xml
index b98de8e..f72b2d3 100644
--- a/chrome/android/java/res/layout/autofill_editing_layout_shipping.xml
+++ b/chrome/android/java/res/layout/autofill_editing_layout_shipping.xml
@@ -39,11 +39,23 @@
android:layout_columnSpan="4"/>
<EditText
android:layout_height="@dimen/autofill_edit_height"
+ android:id="@+id/shipping_state"
+ android:layout_margin="@dimen/autofill_edit_margin"
+ android:textSize="@dimen/autofill_edit_text_size"
+ android:layout_gravity="fill_horizontal"
+ android:layout_columnSpan="4"/>
+ <EditText
+ android:layout_height="@dimen/autofill_edit_height"
android:id="@+id/shipping_zip_code"
android:layout_margin="@dimen/autofill_edit_margin"
android:textSize="@dimen/autofill_edit_text_size"
android:layout_gravity="fill_horizontal"
android:layout_columnSpan="4"/>
+ <Spinner
+ android:layout_margin="5dp"
+ android:id="@+id/shipping_country_spinner"
+ android:layout_gravity="fill_horizontal"
+ android:layout_columnSpan="4"/>
<EditText
android:layout_height="@dimen/autofill_edit_height"
android:id="@+id/shipping_phone_number"
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialog.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialog.java
index 8f27e03..80327f9 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialog.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialog.java
@@ -20,6 +20,7 @@ import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ScrollView;
+import android.widget.Spinner;
import android.widget.TextView;
import org.chromium.chrome.R;
@@ -101,6 +102,13 @@ public class AutofillDialog extends AlertDialog
public void dialogCancel();
/**
+ * Get the list associated with this field as a string array.
+ * @param field The field for which the list should be returned.
+ * @return A string array that contains the list
+ **/
+ public String[] getListForField(int field);
+
+ /**
* Returns the label string to be used for the given section.
* @param section Section for which the label should be returned.
* @return The string that should appear on the label for the given section.
@@ -135,6 +143,7 @@ public class AutofillDialog extends AlertDialog
ScrollView scroll = new ScrollView(context);
mContentView = (AutofillDialogContentView) getLayoutInflater().
inflate(R.layout.autofill_dialog_content, null);
+ mContentView.setAutofillDialog(this);
String[] labels = new String[AutofillDialogConstants.NUM_SECTIONS];
for (int i = 0; i < AutofillDialogConstants.NUM_SECTIONS; i++) {
labels[i] = mDelegate.getLabelForSection(i);
@@ -182,10 +191,19 @@ public class AutofillDialog extends AlertDialog
@Override
public void show() {
- mContentView.createAdaptersForEachSection();
+ mContentView.createAdapters();
super.show();
}
+ /**
+ * Get the list associated with this field as a string array.
+ * @param field The field for which the list should be returned.
+ * @return A string array that contains the list
+ **/
+ public String[] getListForField(int field) {
+ return mDelegate.getListForField(field);
+ }
+
@Override
public void onClick(DialogInterface dialog, int which) {
if (!mContentView.isInEditingMode()) {
@@ -317,22 +335,36 @@ public class AutofillDialog extends AlertDialog
*/
public void updateSection(int section, boolean visible, AutofillDialogField[] dialogInputs,
AutofillDialogMenuItem[] menuItems, int selectedMenuItem) {
- EditText currentField;
+ View currentField;
String inputValue;
for (int i = 0; i < dialogInputs.length; i++) {
- currentField = (EditText) findViewById(AutofillDialogUtils.getEditTextIDForField(
+ currentField = findViewById(AutofillDialogUtils.getViewIDForField(
section, dialogInputs[i].mFieldType));
- if (AutofillDialogUtils.containsCreditCardInfo(section)
- && dialogInputs[i].mFieldType
- == AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE) {
- currentField.setCompoundDrawables(
- null, null, mContentView.getCVCDrawable(), null);
+ if (currentField instanceof EditText) {
+ EditText currentEdit = (EditText) currentField;
+ if (AutofillDialogUtils.containsCreditCardInfo(section)
+ && dialogInputs[i].mFieldType
+ == AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE) {
+ currentEdit.setCompoundDrawables(
+ null, null, mContentView.getCVCDrawable(), null);
+ }
+ currentEdit.setHint(dialogInputs[i].mPlaceholder);
+ inputValue = dialogInputs[i].getValue();
+ if (TextUtils.isEmpty(inputValue)) {
+ currentEdit.setText("");
+ } else {
+ currentEdit.setText(inputValue);
+ }
+ } else if (currentField instanceof Spinner) {
+ Spinner currentSpinner = (Spinner) currentField;
+ for (int k = 0; k < currentSpinner.getCount(); k++) {
+ if (currentSpinner.getItemAtPosition(k).equals(dialogInputs[i]
+ .getValue())) {
+ currentSpinner.setSelection(k);
+ }
+ currentSpinner.setPrompt(dialogInputs[i].mPlaceholder);
+ }
}
- if (currentField == null) continue;
- currentField.setHint(dialogInputs[i].mPlaceholder);
- inputValue = dialogInputs[i].getValue();
- if (TextUtils.isEmpty(inputValue)) currentField.setText("");
- else currentField.setText(inputValue);
}
mAutofillSectionFieldData[section] = dialogInputs;
mContentView.setVisibilityForSection(section, visible);
@@ -364,13 +396,15 @@ public class AutofillDialog extends AlertDialog
AutofillDialogField[] fieldData = mAutofillSectionFieldData[section];
if (fieldData == null) return;
- EditText currentField;
+ View currentField;
for (int i = 0; i < fieldData.length; i++) {
- currentField = (EditText) findViewById(AutofillDialogUtils.getEditTextIDForField(
+ currentField = findViewById(AutofillDialogUtils.getViewIDForField(
section, fieldData[i].mFieldType));
- if (currentField == null) continue;
-
- currentField.setText("");
+ if (currentField instanceof EditText) {
+ ((EditText) currentField).setText("");
+ } else if (currentField instanceof Spinner) {
+ ((Spinner) currentField).setSelected(false);
+ }
}
}
@@ -383,12 +417,15 @@ public class AutofillDialog extends AlertDialog
AutofillDialogField[] fieldData = mAutofillSectionFieldData[section];
if (fieldData == null) return null;
- EditText currentField;
- String currentValue;
+ View currentField;
+ String currentValue = "";
for (int i = 0; i < fieldData.length; i++) {
- currentField = (EditText) findViewById(AutofillDialogUtils.getEditTextIDForField(
+ currentField = findViewById(AutofillDialogUtils.getViewIDForField(
section, fieldData[i].mFieldType));
- currentValue = currentField.getText().toString();
+ if (currentField instanceof EditText)
+ currentValue = ((EditText) currentField).getText().toString();
+ else if (currentField instanceof Spinner)
+ currentValue = ((Spinner) currentField).getSelectedItem().toString();
if (TextUtils.isEmpty(currentValue)) continue;
fieldData[i].setValue(currentValue);
}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogContentView.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogContentView.java
index 8e46de1..9842394 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogContentView.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogContentView.java
@@ -4,9 +4,6 @@
package org.chromium.chrome.browser.autofill;
-import java.util.ArrayList;
-import java.util.List;
-
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -35,6 +32,10 @@ import static org.chromium.chrome.browser.autofill.AutofillDialogConstants.SECTI
import org.chromium.chrome.R;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
/**
* This is the parent layout that contains the layouts for different states of
* autofill dialog. In principle it shouldn't contain any logic related with the
@@ -57,6 +58,7 @@ public class AutofillDialogContentView extends LinearLayout {
mSteadyLayout.setVisibility(GONE);
}
};
+ private AutofillDialog mDialog;
private Spinner[] mSpinners = new Spinner[NUM_SECTIONS];
private AutofillDialogMenuAdapter[] mAdapters = new AutofillDialogMenuAdapter[NUM_SECTIONS];
private ViewGroup mSteadyLayout;
@@ -89,10 +91,18 @@ public class AutofillDialogContentView extends LinearLayout {
}
/**
+ * Sets the controller dialog for this content view.
+ * @param dialog The autofill Dialog that should be set as the controller.
+ */
+ public void setAutofillDialog(AutofillDialog dialog) {
+ mDialog = dialog;
+ }
+
+ /**
* Prompts the content view to create the adapters for each section. This is
* separated to be able to control the timing in a flexible manner.
*/
- public void createAdaptersForEachSection() {
+ public void createAdapters() {
for (int i = 0; i < AutofillDialogConstants.NUM_SECTIONS; i++) {
AutofillDialogMenuAdapter adapter;
if (AutofillDialogUtils.containsCreditCardInfo(i)) {
@@ -106,6 +116,19 @@ public class AutofillDialogContentView extends LinearLayout {
mAdapters[i] = adapter;
if (mSpinners[i] != null) mSpinners[i].setAdapter(adapter);
}
+
+ initializeSpinner(SECTION_SHIPPING, AutofillDialogConstants.ADDRESS_HOME_COUNTRY);
+ initializeSpinner(SECTION_BILLING, AutofillDialogConstants.ADDRESS_HOME_COUNTRY);
+ initializeSpinner(SECTION_CC, AutofillDialogConstants.CREDIT_CARD_EXP_MONTH);
+ initializeSpinner(SECTION_CC, AutofillDialogConstants.CREDIT_CARD_EXP_4_DIGIT_YEAR);
+ }
+
+ private void initializeSpinner(int section, int field) {
+ ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
+ android.R.layout.simple_spinner_dropdown_item);
+ adapter.addAll(Arrays.asList(mDialog.getListForField(field)));
+ ((Spinner) findViewById(AutofillDialogUtils
+ .getViewIDForField(section, field))).setAdapter(adapter);
}
/**
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogGlue.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogGlue.java
index 5d4b90a..8a93352 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogGlue.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogGlue.java
@@ -201,6 +201,11 @@ public class AutofillDialogGlue implements AutofillDialogDelegate,
return nativeGetLabelForSection(mNativeDialogPopup, section);
}
+ @Override
+ public String[] getListForField(int field) {
+ return nativeGetListForField(mNativeDialogPopup, field);
+ }
+
// Helper methods for AutofillDialogField and AutofillDialogItem ------------------------------
@CalledByNative
@@ -272,6 +277,7 @@ public class AutofillDialogGlue implements AutofillDialogDelegate,
private native void nativeDialogCancel(int nativeAutofillDialogViewAndroid);
private native String nativeGetLabelForSection(int nativeAutofillDialogViewAndroid,
int section);
+ private native String[] nativeGetListForField(int nativeAutofillDialogViewAndroid, int field);
private native Bitmap nativeGetIconForField(int nativeAutofillDialogViewAndroid,
int fieldType, String input);
private native String nativeGetPlaceholderForField(int nativeAutofillDialogViewAndroid,
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogUtils.java
index 1d7ef56..1ede216 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogUtils.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogUtils.java
@@ -124,9 +124,7 @@ public class AutofillDialogUtils {
* @param field The field to return the Android ID for.
* @return The Android ID corresponding to the field.
*/
- public static int getEditTextIDForField(int section, int field) {
- // TODO(yusufo) : Fill out all the fields returning 0 currently when their UI
- // elements are added to code.
+ public static int getViewIDForField(int section, int field) {
switch (section) {
case AutofillDialogConstants.SECTION_EMAIL :
return 0;
@@ -135,9 +133,9 @@ public class AutofillDialogUtils {
case AutofillDialogConstants.CREDIT_CARD_NUMBER :
return R.id.card_number;
case AutofillDialogConstants.CREDIT_CARD_EXP_MONTH :
- return R.id.expiration_month;
+ return R.id.expiration_month_spinner;
case AutofillDialogConstants.CREDIT_CARD_EXP_4_DIGIT_YEAR :
- return R.id.expiration_year;
+ return R.id.expiration_year_spinner;
case AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE :
return R.id.cvc_code;
case AutofillDialogConstants.CREDIT_CARD_NAME :
@@ -155,11 +153,11 @@ public class AutofillDialogUtils {
case AutofillDialogConstants.ADDRESS_HOME_CITY :
return R.id.billing_city;
case AutofillDialogConstants.ADDRESS_HOME_STATE :
- return INVALID_ID;
+ return R.id.billing_state;
case AutofillDialogConstants.ADDRESS_HOME_ZIP :
return R.id.billing_zip_code;
case AutofillDialogConstants.ADDRESS_HOME_COUNTRY :
- return INVALID_ID;
+ return R.id.billing_country_spinner;
case AutofillDialogConstants.PHONE_HOME_WHOLE_NUMBER :
return R.id.billing_phone_number;
default:
@@ -171,9 +169,9 @@ public class AutofillDialogUtils {
case AutofillDialogConstants.CREDIT_CARD_NUMBER :
return R.id.card_number;
case AutofillDialogConstants.CREDIT_CARD_EXP_MONTH :
- return R.id.expiration_month;
+ return R.id.expiration_month_spinner;
case AutofillDialogConstants.CREDIT_CARD_EXP_4_DIGIT_YEAR :
- return R.id.expiration_year;
+ return R.id.expiration_year_spinner;
case AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE :
return R.id.cvc_code;
case AutofillDialogConstants.CREDIT_CARD_NAME :
@@ -185,11 +183,11 @@ public class AutofillDialogUtils {
case AutofillDialogConstants.ADDRESS_HOME_CITY :
return R.id.billing_city;
case AutofillDialogConstants.ADDRESS_HOME_STATE :
- return INVALID_ID;
+ return R.id.billing_state;
case AutofillDialogConstants.ADDRESS_HOME_ZIP :
return R.id.billing_zip_code;
case AutofillDialogConstants.ADDRESS_HOME_COUNTRY :
- return INVALID_ID;
+ return R.id.billing_country_spinner;
case AutofillDialogConstants.PHONE_HOME_WHOLE_NUMBER :
return R.id.billing_phone_number;
default:
@@ -207,11 +205,11 @@ public class AutofillDialogUtils {
case AutofillDialogConstants.ADDRESS_HOME_CITY :
return R.id.shipping_city;
case AutofillDialogConstants.ADDRESS_HOME_STATE :
- return INVALID_ID;
+ return R.id.shipping_state;
case AutofillDialogConstants.ADDRESS_HOME_ZIP :
return R.id.shipping_zip_code;
case AutofillDialogConstants.ADDRESS_HOME_COUNTRY :
- return INVALID_ID;
+ return R.id.shipping_country_spinner;
case AutofillDialogConstants.PHONE_HOME_WHOLE_NUMBER :
return R.id.shipping_phone_number;
default: