diff options
author | aruslan@chromium.org <aruslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 07:09:15 +0000 |
---|---|---|
committer | aruslan@chromium.org <aruslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-24 07:09:15 +0000 |
commit | f20daaf753e6afe24de0d8c19c3280dcdf8f472c (patch) | |
tree | 94ff60cbcda08d7fbb331e7c8278f08ed56382a5 /chrome/android | |
parent | 2452193684cba70b1fad78e58d77183a57e4e1d3 (diff) | |
download | chromium_src-f20daaf753e6afe24de0d8c19c3280dcdf8f472c.zip chromium_src-f20daaf753e6afe24de0d8c19c3280dcdf8f472c.tar.gz chromium_src-f20daaf753e6afe24de0d8c19c3280dcdf8f472c.tar.bz2 |
[rAc Android Dialog] Respect controller-provided strings/enables.
Use controller-provided strings and enables for
- Dialog "confirm" button;
- Dialog "cancel" button;
- "Save locally" checkbox;
- Progress bar.
Refresh the state on Show().
Avoid crashing if the state is not yet set.
BUG=226853, 223134
Review URL: https://chromiumcodereview.appspot.com/14018031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196060 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/android')
6 files changed, 161 insertions, 49 deletions
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 f9c42ec..4219934 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 @@ -19,6 +19,7 @@ import android.view.ViewGroup; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ScrollView; @@ -132,14 +133,12 @@ public class AutofillDialog extends AlertDialog 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. */ public String getLabelForSection(int section); /** - * Returns the bitmap icon associated with the given field. * @param fieldType The field type to return the icon for. * @param input The current user input on the field. * @return The bitmap resource that should be shown on the field. @@ -147,16 +146,36 @@ public class AutofillDialog extends AlertDialog public Bitmap getIconForField(int fieldType, String input); /** - * Returns the placeholder string associated with the given field. * @param section The section associated with the field. * @param fieldType The field type to return the icon for. * @return The placeholder string that should be shown on the field. */ public String getPlaceholderForField(int section, int fieldType); + + /** + * @param dialogButtonId AutofillDialogConstants.DIALOG_BUTTON_ ID of the button. + * @return The text for the given button. + */ + public String getDialogButtonText(int dialogButtonId); + + /** + * @param dialogButtonId AutofillDialogConstants.DIALOG_BUTTON_ ID of the button. + * @return Whether the given button should be enabled. + */ + public boolean isDialogButtonEnabled(int dialogButtonId); + + /** + * @return The "Save locally" checkbox label. + */ + public String getSaveLocallyText(); + + /** + * @return The progress bar label. + */ + public String getProgressBarText(); } - protected AutofillDialog(Context context, AutofillDialogDelegate delegate, - String saveLocallyText) { + protected AutofillDialog(Context context, AutofillDialogDelegate delegate) { super(context); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); mDelegate = delegate; @@ -170,7 +189,7 @@ public class AutofillDialog extends AlertDialog inflate(R.layout.autofill_dialog_content, null); mContentView.setAutofillDialog(this); - getSaveLocallyCheckBox().setText(saveLocallyText); + getSaveLocallyCheckBox().setText(mDelegate.getSaveLocallyText()); String[] labels = new String[AutofillDialogConstants.NUM_SECTIONS]; for (int i = 0; i < AutofillDialogConstants.NUM_SECTIONS; i++) { @@ -182,9 +201,9 @@ public class AutofillDialog extends AlertDialog Resources resources = context.getResources(); setButton(AlertDialog.BUTTON_NEGATIVE, - resources.getString(R.string.autofill_negative_button), this); + mDelegate.getDialogButtonText(AutofillDialogConstants.DIALOG_BUTTON_CANCEL), this); setButton(AlertDialog.BUTTON_POSITIVE, - getContext().getResources().getString(R.string.autofill_positive_button), this); + mDelegate.getDialogButtonText(AutofillDialogConstants.DIALOG_BUTTON_OK), this); mContentView.setOnItemSelectedListener(this); @@ -236,7 +255,7 @@ public class AutofillDialog extends AlertDialog private AutofillDialogField[] getFieldsForSection(int section) { if (section < 0 || section >= mAutofillSectionFieldData.length) { - assert(false); + assert false; return new AutofillDialogField[0]; } return mAutofillSectionFieldData[section]; @@ -285,8 +304,7 @@ public class AutofillDialog extends AlertDialog } else { mDelegate.editingCancel(section); } - mContentView.changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY); - getButton(BUTTON_POSITIVE).setText(R.string.autofill_positive_button); + changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY); mWillDismiss = false; } @@ -310,8 +328,7 @@ public class AutofillDialog extends AlertDialog if (currentItem.mIndex == ADD_MENU_ITEM_INDEX) { clearAutofillSectionFieldValues(section); } - mContentView.changeLayoutTo(AutofillDialogContentView.getLayoutModeForSection(section)); - getButton(BUTTON_POSITIVE).setText(R.string.autofill_positive_button_editing); + changeLayoutTo(AutofillDialogContentView.getLayoutModeForSection(section)); } @Override @@ -331,7 +348,56 @@ public class AutofillDialog extends AlertDialog } /** - * Update account chooser dropdown with given accounts. + * Updates the buttons state for the given mode. + * @param mode The layout mode. + */ + private void updateButtons(int mode) { + final Button negative = getButton(BUTTON_NEGATIVE); + final Button positive = getButton(BUTTON_POSITIVE); + + switch (mode) { + case AutofillDialogContentView.LAYOUT_FETCHING: + negative.setText(mDelegate.getDialogButtonText( + AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); + negative.setEnabled(mDelegate.isDialogButtonEnabled( + AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); + positive.setText(mDelegate.getDialogButtonText( + AutofillDialogConstants.DIALOG_BUTTON_OK)); + positive.setEnabled(false); + mTitleView.setAccountChooserEnabled(false); + break; + case AutofillDialogContentView.LAYOUT_STEADY: + negative.setText(mDelegate.getDialogButtonText( + AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); + negative.setEnabled(mDelegate.isDialogButtonEnabled( + AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); + positive.setText(mDelegate.getDialogButtonText( + AutofillDialogConstants.DIALOG_BUTTON_OK)); + positive.setEnabled(mDelegate.isDialogButtonEnabled( + AutofillDialogConstants.DIALOG_BUTTON_OK)); + mTitleView.setAccountChooserEnabled(true); + break; + default: + negative.setText(R.string.autofill_negative_button_editing); + negative.setEnabled(true); + positive.setText(R.string.autofill_positive_button_editing); + positive.setEnabled(true); + mTitleView.setAccountChooserEnabled(false); + break; + } + } + + /** + * Transitions the layout shown to a given layout. + * @param mode The layout mode to transition to. + */ + private void changeLayoutTo(int mode) { + mContentView.changeLayoutTo(mode); + updateButtons(mode); + } + + /** + * Updates the account chooser dropdown with given accounts. * @param accounts The accounts to be used for the dropdown. * @param selectedAccountIndex The index of a currently selected account. */ @@ -349,9 +415,9 @@ public class AutofillDialog extends AlertDialog */ public void modelChanged(boolean fetchingIsActive) { if (fetchingIsActive) { - mContentView.changeLayoutTo(AutofillDialogContentView.LAYOUT_FETCHING); + changeLayoutTo(AutofillDialogContentView.LAYOUT_FETCHING); } else { - mContentView.changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY); + changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY); } } @@ -465,12 +531,14 @@ public class AutofillDialog extends AlertDialog */ public void updateSectionErrors(int section, AutofillDialogFieldError[] errors) { AutofillDialogField[] fields = getFieldsForSection(section); - // Clear old errors. - for (AutofillDialogField field : fields) { - View currentField = findViewById( - AutofillDialogUtils.getViewIDForField(section, field.mFieldType)); - if (currentField instanceof EditText) - ((EditText) currentField).setError(null); + if (fields != null) { + // Clear old errors. + for (AutofillDialogField field : fields) { + View currentField = findViewById( + AutofillDialogUtils.getViewIDForField(section, field.mFieldType)); + if (currentField instanceof EditText) + ((EditText) currentField).setError(null); + } } // Add new errors. @@ -488,11 +556,15 @@ public class AutofillDialog extends AlertDialog */ public void clearAutofillSectionFieldData(int section) { AutofillDialogField[] fields = getFieldsForSection(section); + if (fields == null) return; + for (AutofillDialogField field : fields) field.setValue(""); } private void clearAutofillSectionFieldValues(int section) { AutofillDialogField[] fields = getFieldsForSection(section); + if (fields == null) return; + for (AutofillDialogField field : fields) { View currentField = findViewById( AutofillDialogUtils.getViewIDForField(section, field.mFieldType)); @@ -525,6 +597,8 @@ public class AutofillDialog extends AlertDialog */ public AutofillDialogField[] getSection(int section) { AutofillDialogField[] fields = getFieldsForSection(section); + if (fields == null) return null; + for (AutofillDialogField field : fields) { View currentField = findViewById( AutofillDialogUtils.getViewIDForField(section, field.mFieldType)); @@ -532,8 +606,10 @@ public class AutofillDialog extends AlertDialog String currentValue = ""; if (currentField instanceof EditText) currentValue = ((EditText) currentField).getText().toString(); - else if (currentField instanceof Spinner) - currentValue = ((Spinner) currentField).getSelectedItem().toString(); + else if (currentField instanceof Spinner) { + Object selectedItem = ((Spinner) currentField).getSelectedItem(); + currentValue = selectedItem != null ? selectedItem.toString() : ""; + } field.setValue(currentValue); } return fields; @@ -576,6 +652,7 @@ public class AutofillDialog extends AlertDialog // Validation is performed when user changes from one EditText view to another. int section = mContentView.getCurrentSection(); AutofillDialogField[] fields = getFieldsForSection(section); + if (fields == null) return; int fieldType = AutofillDialogConstants.UNKNOWN_TYPE; for (AutofillDialogField field : fields) { diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogConstants.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogConstants.java index b3e2127..37b037d 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogConstants.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogConstants.java @@ -8,6 +8,12 @@ package org.chromium.chrome.browser.autofill; * Constants required for AutofillDialog. */ public class AutofillDialogConstants { + // Dialog button identifiers used to specify which buttons to show the user. + // This list should be kept in sync with enum DialogButton in ui_base_types.h. + public static final int DIALOG_BUTTON_NONE = 0; + public static final int DIALOG_BUTTON_OK = 1; + public static final int DIALOG_BUTTON_CANCEL = 2; + // Section ID constants. This list should be kept in sync with enum DialogSection in // autofill_dialog_types.h @@ -21,7 +27,7 @@ public class AutofillDialogConstants { public static final int NUM_SECTIONS = 5; - // Filed Type ID constants. This list should be kept in sync with enum AutofillFieldType + // Field Type ID constants. This list should be kept in sync with enum AutofillFieldType // in field_types.h // Server indication that it has no data for the requested field. @@ -91,6 +97,5 @@ public class AutofillDialogConstants { public static final int FIELD_WITH_DEFAULT_VALUE = 61; // No new types can be added. - public static final int MAX_VALID_FIELD_TYPE = 62; } 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 83cd1f9..c9d437f 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 @@ -193,9 +193,9 @@ public class AutofillDialogContentView extends LinearLayout { * @return Whether the current layout is one of the editing layouts. */ public boolean isInEditingMode() { - return mCurrentLayout != INVALID_LAYOUT && - mCurrentLayout != LAYOUT_STEADY && - mCurrentLayout != LAYOUT_FETCHING; + return mCurrentLayout != INVALID_LAYOUT + && mCurrentLayout != LAYOUT_STEADY + && mCurrentLayout != LAYOUT_FETCHING; } /** 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 52108a1..9bac69c 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 @@ -22,21 +22,18 @@ public class AutofillDialogGlue implements AutofillDialogDelegate, private final AutofillDialog mAutofillDialog; private final AutofillDialogAccountHelper mAccountHelper; - public AutofillDialogGlue(int nativeAutofillDialogViewAndroid, WindowAndroid windowAndroid, - String saveLocallyText) { + public AutofillDialogGlue(int nativeAutofillDialogViewAndroid, WindowAndroid windowAndroid) { mNativeDialogPopup = nativeAutofillDialogViewAndroid; mAccountHelper = new AutofillDialogAccountHelper(this, windowAndroid.getContext()); - mAutofillDialog = new AutofillDialog(windowAndroid.getContext(), this, saveLocallyText); + mAutofillDialog = new AutofillDialog(windowAndroid.getContext(), this); mAutofillDialog.show(); } @CalledByNative private static AutofillDialogGlue create(int nativeAutofillDialogViewAndroid, - WindowAndroid windowAndroid, - String saveLocallyText) { - return new AutofillDialogGlue(nativeAutofillDialogViewAndroid, windowAndroid, - saveLocallyText); + WindowAndroid windowAndroid) { + return new AutofillDialogGlue(nativeAutofillDialogViewAndroid, windowAndroid); } /** @@ -216,6 +213,26 @@ public class AutofillDialogGlue implements AutofillDialogDelegate, return nativeGetListForField(mNativeDialogPopup, field); } + @Override + public String getDialogButtonText(int dialogButtonId) { + return nativeGetDialogButtonText(mNativeDialogPopup, dialogButtonId); + } + + @Override + public boolean isDialogButtonEnabled(int dialogButtonId) { + return nativeIsDialogButtonEnabled(mNativeDialogPopup, dialogButtonId); + } + + @Override + public String getSaveLocallyText() { + return nativeGetSaveLocallyText(mNativeDialogPopup); + } + + @Override + public String getProgressBarText() { + return nativeGetProgressBarText(mNativeDialogPopup); + } + // Helper methods for AutofillDialogField and AutofillDialogItem ------------------------------ @CalledByNative @@ -306,4 +323,10 @@ public class AutofillDialogGlue implements AutofillDialogDelegate, int fieldType, String input); private native String nativeGetPlaceholderForField(int nativeAutofillDialogViewAndroid, int section, int fieldType); + private native String nativeGetDialogButtonText(int nativeAutofillDialogViewAndroid, + int dialogButtonId); + private native boolean nativeIsDialogButtonEnabled(int nativeAutofillDialogViewAndroid, + int dialogButtonId); + private native String nativeGetSaveLocallyText(int nativeAutofillDialogViewAndroid); + private native String nativeGetProgressBarText(int nativeAutofillDialogViewAndroid); } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogTitleView.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogTitleView.java index 8cd45ee..a4f79b0 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogTitleView.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialogTitleView.java @@ -28,21 +28,22 @@ public class AutofillDialogTitleView extends FrameLayout { private ArrayAdapter<String> mAdapter; /** - * Create a title using the given context with only the default dropdown items. + * Creates a title using the given context with only the default dropdown items. * @param context The context to create the title within. */ public AutofillDialogTitleView(Context context) { super(context); LayoutInflater.from(context).inflate(R.layout.autofill_dialog_title, this, true); - Spinner accountsSpinner = (Spinner)findViewById(R.id.accounts_spinner); + Spinner accountsSpinner = (Spinner) findViewById(R.id.accounts_spinner); mAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item); mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); accountsSpinner.setAdapter(mAdapter); + accountsSpinner.setEnabled(false); } /** - * Update account chooser dropdown with given accounts and create the title view if needed. + * Updates account chooser dropdown with given accounts and creates the title view if needed. * @param accountNames The dropdown items to be listed. * @param selectedAccountIndex The index of a currently selected account or * -1 if nothing is selected. @@ -52,18 +53,27 @@ public class AutofillDialogTitleView extends FrameLayout { mAdapter.clear(); mAccountNames = accountNames; mAdapter.addAll(mAccountNames); - Spinner accountsSpinner = (Spinner)findViewById(R.id.accounts_spinner); + Spinner accountsSpinner = (Spinner) findViewById(R.id.accounts_spinner); if (selectedAccountIndex >= 0) { accountsSpinner.setSelection(selectedAccountIndex); } } /** - * Set the listener for all the dropdown members in the layout. + * Enables/disables the account chooser. + * @param enabled True if the account chooser is enabled. + */ + public void setAccountChooserEnabled(boolean enabled) { + Spinner accountsSpinner = (Spinner) findViewById(R.id.accounts_spinner); + accountsSpinner.setEnabled(enabled); + } + + /** + * Sets the listener for all the dropdown members in the layout. * @param listener The listener object to attach to the dropdowns. */ public void setOnItemSelectedListener(OnItemSelectedListener listener) { - Spinner accounts_spinner = (Spinner)findViewById(R.id.accounts_spinner); + Spinner accounts_spinner = (Spinner) findViewById(R.id.accounts_spinner); accounts_spinner.setOnItemSelectedListener(listener); } -}
\ No newline at end of file +} diff --git a/chrome/android/java/strings/android_chrome_strings.grd b/chrome/android/java/strings/android_chrome_strings.grd index 1d2fa4a..6ab6597 100644 --- a/chrome/android/java/strings/android_chrome_strings.grd +++ b/chrome/android/java/strings/android_chrome_strings.grd @@ -75,15 +75,12 @@ <message desc="Message for adding a new billing item to the autofill dialog. [CHAR-LIMIT=64]" name="IDS_AUTOFILL_NEW_CC_BILLING"> Add new billing details </message> - <message desc="Message for positive button on the autofill dialog. [CHAR-LIMIT=32]" name="IDS_AUTOFILL_POSITIVE_BUTTON"> - Submit - </message> - <message desc="Message for negative button on the autofill dialog. [CHAR-LIMIT=32]" name="IDS_AUTOFILL_NEGATIVE_BUTTON"> - Cancel - </message> <message desc="Message for positive button while editing details on the autofill dialog. [CHAR-LIMIT=32]" name="IDS_AUTOFILL_POSITIVE_BUTTON_EDITING"> Done </message> + <message desc="Message for negative button while editing details on the autofill dialog. [CHAR-LIMIT=32]" name="IDS_AUTOFILL_NEGATIVE_BUTTON_EDITING"> + Cancel + </message> <message desc="Message for editing an single item on the autofill dialog. [CHAR-LIMIT=32]" name="IDS_AUTOFILL_EDIT_BUTTON"> Edit </message> |