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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7b2a3998c90f6774e1883cdcaecae194bbe3049b |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialog.java |
@@ -0,0 +1,94 @@ |
+// Copyright (c) 2013 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.autofill; |
+ |
+import java.util.ArrayList; |
+import java.util.List; |
+ |
+import android.app.AlertDialog; |
+import android.content.Context; |
+import android.content.DialogInterface; |
+ |
+import android.content.DialogInterface.OnClickListener; |
+import android.view.View; |
+import android.widget.AdapterView; |
+import android.widget.ScrollView; |
+import android.widget.AdapterView.OnItemSelectedListener; |
+ |
+import org.chromium.chrome.R; |
+ |
+/** |
+ * This is the dialog that will act as the java side controller between the |
+ * 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 implements OnClickListener, |
Ted C
2013/03/06 01:41:56
I would put all the implements on the second line
Yusuf
2013/03/06 19:50:00
Done.
|
+ OnItemSelectedListener { |
Ted C
2013/03/06 01:41:56
+4 indent
Yusuf
2013/03/06 19:50:00
Done.
|
+ static final int LAYOUT_STEADY = 0; |
+ static final int LAYOUT_EDITING_SHIPPING = 1; |
+ static final int LAYOUT_EDITING_BILLING = 2; |
+ |
+ AutofillDialogContentView mContentView; |
Ted C
2013/03/06 01:41:56
private?
Yusuf
2013/03/06 19:50:00
Done.
|
+ private int mCurrentLayout = LAYOUT_STEADY; |
Ted C
2013/03/06 01:41:56
I would probably move this logic to the content vi
Yusuf
2013/03/06 19:50:00
Done.
|
+ private boolean mWillDismiss = false; |
+ |
+ protected AutofillDialog(Context context) { |
+ super(context); |
+ List<String> accountNames = new ArrayList<String>(); |
+ accountNames.add("placeholder@gmail.com"); |
Ted C
2013/03/06 01:41:56
where are these account names going to come from i
Yusuf
2013/03/06 19:50:00
Done.
|
+ accountNames.add("placeholder@google.com"); |
+ AutofillDialogTitleView title = new AutofillDialogTitleView(context, accountNames); |
+ title.setOnItemSelectedListener(this); |
+ setCustomTitle(title); |
+ ScrollView scroll = new ScrollView(context); |
+ mContentView = (AutofillDialogContentView)getLayoutInflater(). |
Ted C
2013/03/06 01:41:56
space after cast
Yusuf
2013/03/06 19:50:00
Done.
|
+ inflate(R.layout.autofill_dialog_content, null); |
+ scroll.addView(mContentView); |
+ setView(scroll); |
+ setButton(AlertDialog.BUTTON_NEGATIVE, |
Ted C
2013/03/06 01:41:56
I would add some blank lines in this constructor t
Yusuf
2013/03/06 19:50:00
Done.
|
+ getContext().getResources().getString(R.string.autofill_negative_button), this); |
+ setButton(AlertDialog.BUTTON_POSITIVE, |
+ getContext().getResources().getString(R.string.autofill_positive_button), this); |
+ mContentView.setOnItemSelectedListener(this); |
+ } |
+ |
+ @Override |
+ public void dismiss() { |
+ if (mWillDismiss) super.dismiss(); |
+ } |
+ |
+ @Override |
+ public void onClick(DialogInterface dialog, int which) { |
+ if (mCurrentLayout == LAYOUT_STEADY) { |
+ mWillDismiss = true; |
+ return; |
+ } |
+ |
+ mCurrentLayout = LAYOUT_STEADY; |
+ mContentView.changeLayoutTo(LAYOUT_STEADY); |
+ getButton(BUTTON_POSITIVE).setText(R.string.autofill_positive_button); |
+ mWillDismiss = false; |
+ } |
+ |
+ @Override |
+ public void onItemSelected(AdapterView<?> spinner, View view, int position, |
+ long id) { |
+ if (spinner.getId() == R.id.accounts_spinner || |
+ !mContentView.selectionShouldChangeLayout(spinner, position) || |
+ mCurrentLayout != LAYOUT_STEADY) return; |
Ted C
2013/03/06 01:41:56
braces needed as it doesn't fit all on one line
Yusuf
2013/03/06 19:50:00
Done.
|
+ |
+ mCurrentLayout = spinner.getId() == R.id.address_spinner ? LAYOUT_EDITING_SHIPPING : |
+ LAYOUT_EDITING_BILLING; |
Ted C
2013/03/06 01:41:56
+4 indent
Yusuf
2013/03/06 19:50:00
Done.
|
+ mContentView.changeLayoutTo(mCurrentLayout); |
+ spinner.setSelection(0); |
+ getButton(BUTTON_POSITIVE).setText(R.string.autofill_positive_button_editing); |
+ } |
+ |
+ @Override |
+ public void onNothingSelected(AdapterView<?> arg0) { |
Ted C
2013/03/06 01:41:56
arg0 isn't the best name :-)
Yusuf
2013/03/06 19:50:00
Done.
|
+ } |
+ |
+ |
+} |