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

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

Issue 14886012: Implement layout transition animations for the Autofill dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: findbugs errors Created 7 years, 7 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/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 29b3235e8cf5fcdebba8c915cba39ca31a817f70..a7c93054daa8af08a8ffb2be3d217370200e1584 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,26 +5,27 @@
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.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;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
-import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
@@ -39,11 +40,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 +212,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,17 +228,18 @@ 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);
}
private AutofillDialogField[] getFieldsForSection(int section) {
@@ -265,7 +264,7 @@ public class AutofillDialog extends AlertDialog
@Override
public void show() {
- mContentView.createAdapters();
+ mView.createAdapters();
super.show();
}
@@ -277,6 +276,25 @@ public class AutofillDialog extends AlertDialog
mDelegate.dialogDismissed();
}
+ private void setButton(int which, String text, android.view.View.OnClickListener listener) {
+ Button button = getButton(which);
+
+ if (button == null) return;
+ assert(button != null);
+
+ button.setVisibility(View.VISIBLE);
+ button.setText(text);
+ button.setOnClickListener(listener);
+ }
+
+ private Button getButton(int which) {
+ if (which == AlertDialog.BUTTON_POSITIVE) {
+ return (Button) mView.findViewById(R.id.positive_button);
+ } else {
+ return (Button) mView.findViewById(R.id.negative_button);
+ }
+ }
+
/**
* Get the list associated with this field as a string array.
* @param field The field for which the list should be returned.
@@ -287,9 +305,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
@@ -304,7 +329,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) {
@@ -313,7 +338,7 @@ public class AutofillDialog extends AlertDialog
} else {
mDelegate.editingCancel(section);
}
- changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY);
+ changeLayoutTo(AutofillDialogView.LAYOUT_STEADY);
}
@Override
@@ -334,11 +359,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
@@ -373,7 +398,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(
@@ -383,7 +408,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(
@@ -409,10 +434,10 @@ 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);
- if (mFocusedField != null && !mContentView.isInEditingMode()) {
+ UiUtils.hideKeyboard(mView);
+ if (mFocusedField != null && !mView.isInEditingMode()) {
mFocusedField.removeTextChangedListener(mCurrentTextWatcher);
mFocusedField = null;
}
@@ -425,7 +450,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());
}
/**
@@ -436,10 +461,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);
}
}
@@ -507,11 +532,11 @@ public class AutofillDialog extends AlertDialog
* @param fieldTypeToAlwaysClobber Field type to be clobbered anyway, or UNKNOWN_TYPE.
*/
public void updateSection(int section, boolean visible, AutofillDialogField[] dialogInputs,
- String suggestionText, Bitmap suggestionIcon,
- String suggestionTextExtra, Bitmap suggestionIconExtra,
- boolean suggestionSectionEditable,
- AutofillDialogMenuItem[] menuItems, int selectedMenuItem,
- boolean clobberInputs, int fieldTypeToAlwaysClobber) {
+ String suggestionText, Bitmap suggestionIcon, String suggestionTextExtra,
+ Bitmap suggestionIconExtra, boolean suggestionSectionEditable,
+ AutofillDialogMenuItem[] menuItems,
+ int selectedMenuItem, boolean clobberInputs,
+ int fieldTypeToAlwaysClobber) {
View currentField;
String inputValue;
@@ -530,7 +555,7 @@ public class AutofillDialog extends AlertDialog
&& dialogInputs[i].mFieldType
== AutofillDialogConstants.CREDIT_CARD_VERIFICATION_CODE) {
currentEdit.setCompoundDrawables(null, null,
- mContentView.createFieldIconDrawable(suggestionIconExtra), null);
+ mView.createFieldIconDrawable(suggestionIconExtra), null);
}
currentEdit.setHint(dialogInputs[i].mPlaceholder);
@@ -553,12 +578,11 @@ public class AutofillDialog extends AlertDialog
}
}
setFieldsForSection(section, dialogInputs);
- mContentView.setVisibilityForSection(section, visible);
+ mView.setVisibilityForSection(section, visible);
updateSectionMenuItems(section,
- suggestionText, suggestionIcon,
- suggestionTextExtra, suggestionIconExtra, suggestionSectionEditable,
- menuItems, selectedMenuItem);
+ suggestionText, suggestionIcon, suggestionTextExtra, suggestionIconExtra,
+ suggestionSectionEditable, menuItems, selectedMenuItem);
}
/**
@@ -573,16 +597,13 @@ public class AutofillDialog extends AlertDialog
* @param selectedMenuItem The menu item that is currently selected or -1 otherwise.
*/
public void updateSectionMenuItems(
- int section,
- String suggestionText, Bitmap suggestionIcon,
- String suggestionTextExtra, Bitmap suggestionIconExtra,
- boolean suggestionSectionEditable,
- AutofillDialogMenuItem[] menuItems, int selectedMenuItem) {
- mContentView.updateMenuItemsForSection(
- section,
- suggestionText, suggestionIcon,
- suggestionTextExtra, suggestionIconExtra, suggestionSectionEditable,
- Arrays.asList(menuItems), selectedMenuItem);
+ int section, String suggestionText, Bitmap suggestionIcon, String suggestionTextExtra,
+ Bitmap suggestionIconExtra, boolean suggestionSectionEditable,
+ AutofillDialogMenuItem[] menuItems, int selectedMenuItem) {
+ mView.updateMenuItemsForSection(
+ section, suggestionText, suggestionIcon, suggestionTextExtra,
+ suggestionIconExtra, suggestionSectionEditable,
+ Arrays.asList(menuItems), selectedMenuItem);
}
/**
@@ -651,7 +672,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);
}
/**
@@ -749,7 +770,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;
@@ -757,7 +778,7 @@ public class AutofillDialog extends AlertDialog
// New EditText just got focused.
if (hasFocus) mFocusedField = currentfield;
- int section = mContentView.getCurrentSection();
+ int section = mView.getCurrentSection();
AutofillDialogField[] fields = getFieldsForSection(section);
int fieldType = AutofillDialogConstants.UNKNOWN_TYPE;
int nativePointer = 0;

Powered by Google App Engine
This is Rietveld 408576698