Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialog.java |
| 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 1ad4593af3f1356b8eac585041bf1b03c92bb938..e5d451fba4240685cf479e4045ff8a4b190ed2fd 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 |
| @@ -5,20 +5,23 @@ |
| package org.chromium.chrome.browser.autofill; |
| import android.app.AlertDialog; |
| +import android.app.Dialog; |
| import android.content.Context; |
| -import android.content.DialogInterface; |
| -import android.content.DialogInterface.OnClickListener; |
| +import android.content.res.Resources; |
| import android.graphics.Bitmap; |
| import android.text.Editable; |
| import android.text.TextUtils; |
| import android.text.TextWatcher; |
| import android.util.TypedValue; |
| import android.view.View; |
| +import android.view.View.OnClickListener; |
| import android.view.View.OnFocusChangeListener; |
| import android.view.ViewGroup; |
| +import android.view.Window; |
| import android.view.WindowManager; |
| import android.widget.AdapterView; |
| import android.widget.AdapterView.OnItemSelectedListener; |
| +import android.widget.LinearLayout.LayoutParams; |
| import android.widget.Button; |
| import android.widget.CheckBox; |
| import android.widget.CompoundButton; |
| @@ -39,11 +42,11 @@ import java.util.Arrays; |
| * AutofillDialogGlue object and the UI elements on the page. It contains the |
| * title and the content views and relays messages from the backend to them. |
| */ |
| -public class AutofillDialog extends AlertDialog |
| +public class AutofillDialog extends Dialog |
| implements OnClickListener, OnItemSelectedListener, |
| - AutofillDialogContentView.OnItemEditButtonClickedListener, |
| + AutofillDialogView.OnItemEditButtonClickedListener, |
| OnFocusChangeListener, ViewAndroidDelegate { |
| - private final AutofillDialogContentView mContentView; |
| + private final AutofillDialogView mView; |
| private final AutofillDialogTitleView mTitleView; |
| private final AutofillDialogDelegate mDelegate; |
| @@ -211,17 +214,14 @@ public class AutofillDialog extends AlertDialog |
| protected AutofillDialog(Context context, AutofillDialogDelegate delegate) { |
| super(context); |
| + requestWindowFeature(Window.FEATURE_NO_TITLE); |
| getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); |
| mDelegate = delegate; |
| + mView = (AutofillDialogView) getLayoutInflater(). |
| + inflate(R.layout.autofill_dialog_content, null); |
| - mTitleView = new AutofillDialogTitleView(getContext()); |
| + mTitleView = (AutofillDialogTitleView) mView.findViewById(R.id.title); |
| mTitleView.setOnItemSelectedListener(this); |
| - setCustomTitle(mTitleView); |
| - |
| - ScrollView scroll = new ScrollView(context); |
| - mContentView = (AutofillDialogContentView) getLayoutInflater(). |
| - inflate(R.layout.autofill_dialog_content, null); |
| - mContentView.setAutofillDialog(this); |
| getSaveLocallyCheckBox().setText(mDelegate.getSaveLocallyText()); |
| getSaveLocallyCheckBox().setChecked(true); |
| @@ -230,24 +230,25 @@ public class AutofillDialog extends AlertDialog |
| for (int i = 0; i < AutofillDialogConstants.NUM_SECTIONS; i++) { |
| labels[i] = mDelegate.getLabelForSection(i); |
| } |
| - mContentView.initializeLabelsForEachSection(labels); |
| - scroll.addView(mContentView); |
| - setView(scroll); |
| + getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); |
| + setContentView(mView); |
| + mView.initialize(this); |
| + mView.initializeLabelsForEachSection(labels); |
| setButton(AlertDialog.BUTTON_NEGATIVE, |
| mDelegate.getDialogButtonText(AutofillDialogConstants.DIALOG_BUTTON_CANCEL), this); |
| setButton(AlertDialog.BUTTON_POSITIVE, |
| mDelegate.getDialogButtonText(AutofillDialogConstants.DIALOG_BUTTON_OK), this); |
| - mContentView.setOnItemSelectedListener(this); |
| - mContentView.setOnItemEditButtonClickedListener(this); |
| + mView.setOnItemSelectedListener(this); |
| + mView.setOnItemEditButtonClickedListener(this); |
| String hint = mDelegate.getPlaceholderForField( |
| AutofillDialogConstants.SECTION_CC, |
| AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE); |
| Bitmap icon = mDelegate.getIconForField( |
| AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE, ""); |
| - mContentView.setCVCInfo(hint, icon); |
| + mView.setCVCInfo(hint, icon); |
| } |
| private AutofillDialogField[] getFieldsForSection(int section) { |
| @@ -272,7 +273,7 @@ public class AutofillDialog extends AlertDialog |
| @Override |
| public void show() { |
| - mContentView.createAdapters(); |
| + mView.createAdapters(); |
| super.show(); |
| } |
| @@ -284,6 +285,24 @@ public class AutofillDialog extends AlertDialog |
| mDelegate.dialogDismissed(); |
| } |
| + private void setButton(int which, String text, android.view.View.OnClickListener listener) { |
|
Ted C
2013/05/07 21:49:07
I don't think you need the android.view.View befor
Yusuf
2013/05/08 21:39:00
Done.
|
| + Button button = getButton(which); |
| + assert(button != null); |
|
Ted C
2013/05/07 21:49:07
Should handle the case where it's null gracefully
Yusuf
2013/05/08 21:39:00
Done.
|
| + button.setVisibility(View.VISIBLE); |
| + button.setText(text); |
| + button.setOnClickListener(listener); |
| + } |
| + |
| + private Button getButton(int which) { |
| + Button button; |
| + if (which == AlertDialog.BUTTON_POSITIVE) { |
| + button = (Button) mView.findViewById(R.id.positive_button); |
|
Ted C
2013/05/07 21:49:07
I would either return directly in these conditions
Yusuf
2013/05/08 21:39:00
Done.
|
| + } else { |
| + button = (Button) mView.findViewById(R.id.negative_button); |
| + } |
| + return button; |
| + } |
| + |
| /** |
| * Get the list associated with this field as a string array. |
| * @param field The field for which the list should be returned. |
| @@ -294,9 +313,16 @@ public class AutofillDialog extends AlertDialog |
| } |
| @Override |
| - public void onClick(DialogInterface dialog, int which) { |
| + public void onClick(View button) { |
| + int which; |
| + if (button.getId() == R.id.positive_button) { |
| + which = AlertDialog.BUTTON_POSITIVE; |
| + } else { |
| + which = AlertDialog.BUTTON_NEGATIVE; |
| + } |
| + |
| // Note that the dialog will NOT be dismissed automatically. |
| - if (!mContentView.isInEditingMode()) { |
| + if (!mView.isInEditingMode()) { |
| if (which == AlertDialog.BUTTON_POSITIVE) { |
| // The controller will dismiss the dialog if the validation succeeds. |
| // Otherwise, the dialog should be in the operational state to show |
| @@ -311,7 +337,7 @@ public class AutofillDialog extends AlertDialog |
| return; |
| } |
| - int section = mContentView.getCurrentSection(); |
| + int section = mView.getCurrentSection(); |
| assert(section != AutofillDialogUtils.INVALID_SECTION); |
| if (which == AlertDialog.BUTTON_POSITIVE) { |
| @@ -320,7 +346,7 @@ public class AutofillDialog extends AlertDialog |
| } else { |
| mDelegate.editingCancel(section); |
| } |
| - changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY); |
| + changeLayoutTo(AutofillDialogView.LAYOUT_STEADY); |
| } |
| @Override |
| @@ -341,11 +367,11 @@ public class AutofillDialog extends AlertDialog |
| @Override |
| public void onItemEditButtonClicked(int section, int position) { |
| - mContentView.updateMenuSelectionForSection(section, position); |
| + mView.updateMenuSelectionForSection(section, position); |
| mDelegate.itemSelected(section, position); |
| mDelegate.editingStart(section); |
| - changeLayoutTo(AutofillDialogContentView.getLayoutModeForSection(section)); |
| + changeLayoutTo(AutofillDialogView.getLayoutModeForSection(section)); |
| } |
| @Override |
| @@ -380,7 +406,7 @@ public class AutofillDialog extends AlertDialog |
| final Button positive = getButton(BUTTON_POSITIVE); |
| switch (mode) { |
| - case AutofillDialogContentView.LAYOUT_FETCHING: |
| + case AutofillDialogView.LAYOUT_FETCHING: |
| negative.setText(mDelegate.getDialogButtonText( |
| AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); |
| negative.setEnabled(mDelegate.isDialogButtonEnabled( |
| @@ -390,7 +416,7 @@ public class AutofillDialog extends AlertDialog |
| positive.setEnabled(false); |
| mTitleView.setAccountChooserEnabled(false); |
| break; |
| - case AutofillDialogContentView.LAYOUT_STEADY: |
| + case AutofillDialogView.LAYOUT_STEADY: |
| negative.setText(mDelegate.getDialogButtonText( |
| AutofillDialogConstants.DIALOG_BUTTON_CANCEL)); |
| negative.setEnabled(mDelegate.isDialogButtonEnabled( |
| @@ -416,9 +442,9 @@ public class AutofillDialog extends AlertDialog |
| * @param mode The layout mode to transition to. |
| */ |
| private void changeLayoutTo(int mode) { |
| - mContentView.changeLayoutTo(mode); |
| + mView.changeLayoutTo(mode); |
| updateButtons(mode); |
| - UiUtils.hideKeyboard(mContentView); |
| + UiUtils.hideKeyboard(mView); |
| } |
| /** |
| @@ -428,7 +454,7 @@ public class AutofillDialog extends AlertDialog |
| */ |
| public void updateAccountChooser(String[] accounts, int selectedAccountIndex) { |
| mTitleView.updateAccountsAndSelect(Arrays.asList(accounts), selectedAccountIndex); |
| - mContentView.updateLegalDocumentsText(mDelegate.getLegalDocumentsText()); |
| + mView.updateLegalDocumentsText(mDelegate.getLegalDocumentsText()); |
| } |
| /** |
| @@ -439,10 +465,10 @@ public class AutofillDialog extends AlertDialog |
| */ |
| public void modelChanged(boolean fetchingIsActive) { |
| if (fetchingIsActive) { |
| - changeLayoutTo(AutofillDialogContentView.LAYOUT_FETCHING); |
| + changeLayoutTo(AutofillDialogView.LAYOUT_FETCHING); |
| mTitleView.hideLogoAndAccountChooserVisibility(); |
| } else { |
| - changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY); |
| + changeLayoutTo(AutofillDialogView.LAYOUT_STEADY); |
| } |
| } |
| @@ -525,7 +551,7 @@ public class AutofillDialog extends AlertDialog |
| && dialogInputs[i].mFieldType |
| == AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE) { |
| currentEdit.setCompoundDrawables( |
| - null, null, mContentView.getCVCDrawable(), null); |
| + null, null, mView.getCVCDrawable(), null); |
| } |
| currentEdit.setHint(dialogInputs[i].mPlaceholder); |
| @@ -548,7 +574,7 @@ public class AutofillDialog extends AlertDialog |
| } |
| } |
| setFieldsForSection(section, dialogInputs); |
| - mContentView.setVisibilityForSection(section, visible); |
| + mView.setVisibilityForSection(section, visible); |
| updateSectionMenuItems(section, menuItems, selectedMenuItem); |
| } |
| @@ -561,7 +587,7 @@ public class AutofillDialog extends AlertDialog |
| */ |
| public void updateSectionMenuItems( |
| int section, AutofillDialogMenuItem[] menuItems, int selectedMenuItem) { |
| - mContentView.updateMenuItemsForSection( |
| + mView.updateMenuItemsForSection( |
| section, Arrays.asList(menuItems), selectedMenuItem); |
| } |
| @@ -631,7 +657,7 @@ public class AutofillDialog extends AlertDialog |
| } |
| private CheckBox getSaveLocallyCheckBox() { |
| - return (CheckBox) mContentView.findViewById(R.id.save_locally_checkbox); |
| + return (CheckBox) mView.findViewById(R.id.save_locally_checkbox); |
| } |
| /** |
| @@ -726,7 +752,7 @@ public class AutofillDialog extends AlertDialog |
| */ |
| @Override |
| public void onFocusChange(View v, boolean hasFocus) { |
| - if (!mContentView.isInEditingMode()) return; |
| + if (!mView.isInEditingMode()) return; |
| if (!(v instanceof EditText)) return; |
| EditText currentfield = (EditText) v; |
| @@ -734,7 +760,7 @@ public class AutofillDialog extends AlertDialog |
| mFocusedField = currentfield; |
| // Validation is performed when user changes from one EditText view to another. |
| - int section = mContentView.getCurrentSection(); |
| + int section = mView.getCurrentSection(); |
| AutofillDialogField[] fields = getFieldsForSection(section); |
| if (fields == null) return; |
| @@ -765,7 +791,7 @@ public class AutofillDialog extends AlertDialog |
| @Override |
| public View acquireAnchorView() { |
| - return mFocusedField; |
| + return mFocusedField; |
|
Ted C
2013/05/07 21:49:07
looks like you added a space here that messes up t
Yusuf
2013/05/08 21:39:00
Done.
|
| } |
| @Override |