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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..450950ea101b13f3c6f572c39983dd2a13551ca9 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillDialog.java |
| @@ -0,0 +1,106 @@ |
| +// 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, OnItemSelectedListener { |
| + private AutofillDialogContentView mContentView; |
| + private boolean mWillDismiss = false; |
| + |
| + protected AutofillDialog(Context context) { |
| + super(context); |
| + |
| + addTitleWithPlaceholders(); |
| + |
| + ScrollView scroll = new ScrollView(context); |
| + mContentView = (AutofillDialogContentView) getLayoutInflater(). |
| + inflate(R.layout.autofill_dialog_content, null); |
| + scroll.addView(mContentView); |
| + setView(scroll); |
| + |
| + setButton(AlertDialog.BUTTON_NEGATIVE, |
| + 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 (mContentView.getCurrentLayout() == AutofillDialogContentView.LAYOUT_STEADY) { |
| + mWillDismiss = true; |
| + return; |
| + } |
| + |
| + mContentView.changeLayoutTo(AutofillDialogContentView.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.changeLayoutTo(AutofillDialogContentView.LAYOUT_FETCHING); |
| + return; |
| + } |
| + |
| + if (!mContentView.selectionShouldChangeLayout(spinner, position) || |
| + mContentView.getCurrentLayout() != AutofillDialogContentView.LAYOUT_STEADY) { |
| + return; |
| + } |
| + |
| + int newLayout = spinner.getId() == R.id.address_spinner ? |
| + AutofillDialogContentView.LAYOUT_EDITING_SHIPPING : |
| + AutofillDialogContentView.LAYOUT_EDITING_BILLING; |
| + mContentView.changeLayoutTo(newLayout); |
| + spinner.setSelection(0); |
| + getButton(BUTTON_POSITIVE).setText(R.string.autofill_positive_button_editing); |
| + } |
| + |
| + @Override |
| + public void onNothingSelected(AdapterView<?> spinner) { |
| + } |
| + |
| + //TODO(yusufo): Remove this. updateAccountChooserAndAddTitle will get initiated from glue. |
| + private void addTitleWithPlaceholders() { |
| + List<String> accounts = new ArrayList<String>(); |
| + accounts.add("placeholder@gmail.com"); |
| + accounts.add("placeholder@google.com"); |
| + updateAccountChooserAndAddTitle(accounts); |
| + } |
| + |
| + private void updateAccountChooserAndAddTitle(List<String> accounts) { |
|
Ted C
2013/03/06 21:57:11
if this will eventually be what is called, should
Yusuf
2013/03/07 18:16:58
Done.
|
| + AutofillDialogTitleView title = new AutofillDialogTitleView(getContext(), accounts); |
| + title.setOnItemSelectedListener(this); |
| + setCustomTitle(title); |
| + } |
| +} |