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

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

Issue 12412003: Initial UI structure for autofill dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes to comments Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.autofill;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import android.app.AlertDialog;
11 import android.content.Context;
12 import android.content.DialogInterface;
13
14 import android.content.DialogInterface.OnClickListener;
15 import android.view.View;
16 import android.widget.AdapterView;
17 import android.widget.ScrollView;
18 import android.widget.AdapterView.OnItemSelectedListener;
19
20 import org.chromium.chrome.R;
21
22 /**
23 * This is the dialog that will act as the java side controller between the
24 * AutofillDialogGlue object and the UI elements on the page. It contains the
25 * title and the content views and relays messages from the backend to them.
26 */
27 public class AutofillDialog extends AlertDialog
28 implements OnClickListener, OnItemSelectedListener {
29 private AutofillDialogContentView mContentView;
30 private AutofillDialogTitleView mTitleView;
31 private boolean mWillDismiss = false;
32
33 protected AutofillDialog(Context context) {
34 super(context);
35
36 addTitleWithPlaceholders();
37
38 ScrollView scroll = new ScrollView(context);
39 mContentView = (AutofillDialogContentView) getLayoutInflater().
40 inflate(R.layout.autofill_dialog_content, null);
41 scroll.addView(mContentView);
42 setView(scroll);
43
44 setButton(AlertDialog.BUTTON_NEGATIVE,
45 getContext().getResources().getString(R.string.autofill_negative _button), this);
46 setButton(AlertDialog.BUTTON_POSITIVE,
47 getContext().getResources().getString(R.string.autofill_positive _button), this);
48
49 mContentView.setOnItemSelectedListener(this);
50 }
51
52 @Override
53 public void dismiss() {
54 if (mWillDismiss) super.dismiss();
55 }
56
57 @Override
58 public void onClick(DialogInterface dialog, int which) {
59 if (mContentView.getCurrentLayout() == AutofillDialogContentView.LAYOUT_ STEADY) {
60 mWillDismiss = true;
61 return;
62 }
63
64 mContentView.changeLayoutTo(AutofillDialogContentView.LAYOUT_STEADY);
65 getButton(BUTTON_POSITIVE).setText(R.string.autofill_positive_button);
66 mWillDismiss = false;
67 }
68
69 @Override
70 public void onItemSelected(AdapterView<?> spinner, View view, int position,
71 long id) {
72 if (spinner.getId() == R.id.accounts_spinner) {
73 mContentView.changeLayoutTo(AutofillDialogContentView.LAYOUT_FETCHIN G);
74 return;
75 }
76
77 if (!mContentView.selectionShouldChangeLayout(spinner, position) ||
78 mContentView.getCurrentLayout() != AutofillDialogContentView.LAY OUT_STEADY) {
79 return;
80 }
81
82 int newLayout = spinner.getId() == R.id.address_spinner ?
83 AutofillDialogContentView.LAYOUT_EDITING_SHIPPING :
84 AutofillDialogContentView.LAYOUT_EDITING_BILLING;
85 mContentView.changeLayoutTo(newLayout);
86 spinner.setSelection(0);
87 getButton(BUTTON_POSITIVE).setText(R.string.autofill_positive_button_edi ting);
88 }
89
90 @Override
91 public void onNothingSelected(AdapterView<?> spinner) {
92 }
93
94 //TODO(yusufo): Remove this. updateAccountChooserAndAddTitle will get initia ted from glue.
95 private void addTitleWithPlaceholders() {
96 List<String> accounts = new ArrayList<String>();
97 accounts.add("placeholder@gmail.com");
98 accounts.add("placeholder@google.com");
99 updateAccountChooserAndAddTitle(accounts);
100 }
101
102 /**
103 * Update account chooser dropdown with given accounts and create the title view if needed.
104 * @param accounts The accounts to be used for the dropdown.
105 */
106 public void updateAccountChooserAndAddTitle(List<String> accounts) {
107 if (mTitleView == null) {
108 mTitleView = new AutofillDialogTitleView(getContext(), accounts);
109 mTitleView.setOnItemSelectedListener(this);
110 setCustomTitle(mTitleView);
111 return;
112 }
113 // TODO(yusufo): Add code to update accounts after title is created.
114 }
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698