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

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

Issue 12412003: Initial UI structure for autofill dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Styling fixes 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.annotation.SuppressLint;
11 import android.content.Context;
12 import android.text.style.UpdateLayout;
13 import android.util.AttributeSet;
14 import android.view.View;
15 import android.view.ViewGroup;
16 import android.view.animation.Animation;
17 import android.view.animation.AnimationSet;
18 import android.view.animation.ScaleAnimation;
19 import android.view.animation.TranslateAnimation;
20 import android.widget.AdapterView;
21 import android.widget.ArrayAdapter;
22 import android.widget.FrameLayout;
23 import android.widget.ImageView;
24 import android.widget.Spinner;
25 import android.widget.TextView;
26 import android.widget.AdapterView.OnItemSelectedListener;
27
28 import org.chromium.chrome.R;
29
30 /**
31 * This is the parent layout that contains the layouts for different states of
32 * autofill dialog. In principle it shouldn't contain any logic related with the
33 * actual workflow, but rather respond to any UI update messages coming to it
34 * from the AutofillDialog.
35 */
36 public class AutofillDialogContentView extends FrameLayout {
37 private static int ANIMATION_DURATION_MS = 1000;
38 private static int PLACEHOLDER_ANIMATION_DISTANCE = 500;
Ted C 2013/03/06 01:41:56 what unit is this distance in? Px? Dp?
Yusuf 2013/03/06 19:50:00 Done.
39 private static final List<AddressItem> mConstantShippingItems =
40 new ArrayList<AddressItem>();
41 private static final List<CreditCardItem> mConstantBillingItems =
Ted C 2013/03/06 01:41:56 why are these static?
Yusuf 2013/03/06 19:50:00 Done.
42 new ArrayList<CreditCardItem>();
43
44 private ArrayList<View> mTopViewGroup;
45 private ArrayList<View> mMidViewGroup;
46 private ArrayList<View> mBottomViewGroup;
47 private Spinner mCreditCardSpinner;
48 private Spinner mAddressSpinner;
49 private View mSteadyLayout;
50 private View mEditShippingLayout;
51 private View mEditBillingLayout;
52
53 public AutofillDialogContentView(Context context, AttributeSet attrs) {
54 super(context, attrs);
55 if (mConstantShippingItems.size() == 0) {
Ted C 2013/03/06 01:41:56 Does list have isEmpty()?
Yusuf 2013/03/06 19:50:00 Done.
56 mConstantShippingItems.add(new AddressItem(
57 getResources().getString(R.string.autofill_new_shipping), "" ));
58 mConstantShippingItems.add(new AddressItem(
59 getResources().getString(R.string.autofill_edit_shipping), " "));
60 }
61 if (mConstantBillingItems.size() == 0) {
62 mConstantBillingItems.add(new CreditCardItem(0,
63 getResources().getString(R.string.autofill_new_billing), "") );
64 mConstantBillingItems.add(new CreditCardItem(0,
65 getResources().getString(R.string.autofill_edit_billing), "" ));
66 }
67 mTopViewGroup = new ArrayList<View>();
Ted C 2013/03/06 01:41:56 these can probably be final since they're not rese
Yusuf 2013/03/06 19:50:00 Done.
68 mMidViewGroup = new ArrayList<View>();
69 mBottomViewGroup = new ArrayList<View>();
70 }
71
72 @Override
73 protected void onFinishInflate () {
74 mSteadyLayout = findViewById(R.id.general_layout);
75 mEditBillingLayout = findViewById(R.id.editing_layout_billing);
76 mEditShippingLayout = findViewById(R.id.editing_layout_shipping);
77
78 mCreditCardSpinner = (Spinner)findViewById(R.id.cc_spinner);
Ted C 2013/03/06 01:41:56 space after case (double check all your casts)
Yusuf 2013/03/06 19:50:00 Done.
79 List<CreditCardItem> cards = new ArrayList<CreditCardItem>();
80 //TODO(yusufo): Remove all placeholders here and also in related layout xml files.
81 cards.add(new CreditCardItem(R.drawable.visa,
Ted C 2013/03/06 01:41:56 again, move the placeholders to a function that ca
Yusuf 2013/03/06 19:50:00 Done.
82 "XXXX-XXXX-XXXX-1000", "Additional info required"));
83 cards.add(new CreditCardItem(R.drawable.master_card, "XXXX-XXXX-XXXX-100 0", ""));
84 cards.addAll(mConstantBillingItems);
85 mCreditCardSpinner.setAdapter(new CreditCardAdapter(getContext(), cards) );
86 mAddressSpinner = (Spinner)findViewById(R.id.address_spinner);
87 List<AddressItem> addresses = new ArrayList<AddressItem>();
88 addresses.add(new AddressItem("Place Holder", "1600 Amphitheatre Pkwy")) ;
89 addresses.addAll(mConstantShippingItems);
90 mAddressSpinner.setAdapter(new AddressAdapter(getContext(), addresses));
91
92 setViewGroups();
93 changeLayoutTo(AutofillDialog.LAYOUT_STEADY);
94 }
95
96 @Override
97 protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
98 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
99 mCreditCardSpinner.setDropDownWidth(mCreditCardSpinner.getMeasuredWidth( ));
100 mCreditCardSpinner.setDropDownVerticalOffset(-1 * mCreditCardSpinner.get MeasuredHeight());
Ted C 2013/03/06 01:41:56 you can just do: -mCreditCardSpinner.getMeasuredH
Yusuf 2013/03/06 19:50:00 Done.
101 mAddressSpinner.setDropDownWidth(mAddressSpinner.getMeasuredWidth());
102 mAddressSpinner.setDropDownVerticalOffset(-1 * mAddressSpinner.getMeasur edHeight());
103 }
104
105 /**
106 * Set the listener for all the dropdown members in the layout.
107 * @param listener The listener object to attach to the dropdowns.
108 */
109 public void setOnItemSelectedListener(OnItemSelectedListener listener) {
110 mCreditCardSpinner.setOnItemSelectedListener(listener);
111 mAddressSpinner.setOnItemSelectedListener(listener);
112 }
113
114 /**
115 * @param spinner The dropdown that was selected by the user.
116 * @param position The position for the selected item in the dropdown.
117 * @return Whether the selection should cause a layout state change.
118 */
119 public boolean selectionShouldChangeLayout(AdapterView<?> spinner, int posit ion) {
120 int numConstantItems = spinner.getId() == R.id.cc_spinner ?
121 mConstantBillingItems.size() : mConstantShippingItems.size();
122 return position >= spinner.getCount() - numConstantItems;
123 }
124
125 /**
126 * Transitions the layout shown to a given layout.
127 * @param mode The layout mode to transition to.
128 */
129 public void changeLayoutTo(int mode) {
Ted C 2013/03/06 01:41:56 this function is too long, look into splitting it
130 mEditBillingLayout.setVisibility(GONE);
Ted C 2013/03/06 01:41:56 if you're already in the current mode, should you
Yusuf 2013/03/06 19:50:00 Done.
131 mEditShippingLayout.setVisibility(GONE);
132 mSteadyLayout.setVisibility(VISIBLE);
133 if (mode == AutofillDialog.LAYOUT_STEADY) return;
134
135 View centerView;
136 View centeredLayout;
137
138 TranslateAnimation toTopAnimation = new TranslateAnimation(
139 0, 0, 0, -PLACEHOLDER_ANIMATION_DISTANCE);
140 toTopAnimation.setDuration(ANIMATION_DURATION_MS);
141 TranslateAnimation toBottomAnimation = new TranslateAnimation(
142 0, 0, 0, PLACEHOLDER_ANIMATION_DISTANCE);
143 toBottomAnimation.setDuration(ANIMATION_DURATION_MS);
144 TranslateAnimation midViewGroupAnimation;
145 if (mode == AutofillDialog.LAYOUT_EDITING_BILLING) {
146 centerView = mCreditCardSpinner;
147 centeredLayout = mEditBillingLayout;
148 midViewGroupAnimation = toBottomAnimation;
149 } else {
150 centerView = mAddressSpinner;
151 centeredLayout = mEditShippingLayout;
152 midViewGroupAnimation = toTopAnimation;
153 }
154 float yOffset = centerView.getY() - centerView.getHeight() / 2;
155 TranslateAnimation toLocationAnimation = new TranslateAnimation(0, 0, 0, 0);
156 toLocationAnimation.setDuration(ANIMATION_DURATION_MS);
157 ScaleAnimation scaleAnimation;
158 scaleAnimation = new ScaleAnimation(1, 1, 0, 1,
159 Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.5f) ;
160 scaleAnimation.setDuration(ANIMATION_DURATION_MS);
161 ScaleAnimation scaleDownAnimation;
162 scaleDownAnimation = new ScaleAnimation(1, 1, 1, 0,
163 Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.5f) ;
164 scaleDownAnimation.setDuration(ANIMATION_DURATION_MS / 2);
165 scaleDownAnimation.setStartOffset(ANIMATION_DURATION_MS / 2);
166 scaleAnimation.setStartOffset(ANIMATION_DURATION_MS / 4);
167
168 AnimationSet appearAnimation = new AnimationSet(true);
169 appearAnimation.addAnimation(toLocationAnimation);
170 appearAnimation.addAnimation(scaleAnimation);
171
172 int i;
Ted C 2013/03/06 01:41:56 I would declare i in each of the loops to prevent
Yusuf 2013/03/06 19:50:00 Done.
173 for (i = 0; i < mTopViewGroup.size(); i++) {
174 mTopViewGroup.get(i).setAnimation(toTopAnimation);
175 mTopViewGroup.get(i).animate();
176 }
177 for (i = 0; i < mMidViewGroup.size(); i++) {
178 mMidViewGroup.get(i).setAnimation(midViewGroupAnimation);
179 mMidViewGroup.get(i).animate();
180 }
181 for (i = 0; i < mBottomViewGroup.size(); i++) {
182 mBottomViewGroup.get(i).setAnimation(toBottomAnimation);
183 mBottomViewGroup.get(i).animate();
184 }
185
186 centeredLayout.setVisibility(VISIBLE);
187 centeredLayout.setAnimation(appearAnimation);
188 centeredLayout.animate();
189 mSteadyLayout.setAnimation(scaleDownAnimation);
190 mSteadyLayout.animate();
191 postDelayed(new Runnable() {
Ted C 2013/03/06 01:41:56 should you be caching this runnable in case you ne
Yusuf 2013/03/06 19:50:00 Done.
192 @Override
193 public void run() {
194 mSteadyLayout.setVisibility(GONE);
195 }
196 }, ANIMATION_DURATION_MS);
197 }
198
199 private void setViewGroups() {
Ted C 2013/03/06 01:41:56 I would move this up near the constructor.
Yusuf 2013/03/06 19:50:00 Done.
200 mTopViewGroup.clear();
201 mTopViewGroup.add(findViewById(R.id.billing_title));
202 mTopViewGroup.add(findViewById(R.id.cc_spinner));
203
204 mMidViewGroup.clear();
205 mMidViewGroup.add(findViewById(R.id.shipping_title));
206 mMidViewGroup.add(findViewById(R.id.address_spinner));
207
208 mBottomViewGroup.clear();
209 mBottomViewGroup.add(findViewById(R.id.check_box));
210 mBottomViewGroup.add(findViewById(R.id.line_bottom));
211 mBottomViewGroup.add(findViewById(R.id.terms_info));
212 }
213
214 private static class AddressItem {
215 String mName;
Ted C 2013/03/06 01:41:56 private final
Yusuf 2013/03/06 19:50:00 Done.
216 String mAddress;
217 public AddressItem(String name, String address) {
Ted C 2013/03/06 01:41:56 blank line above this
Yusuf 2013/03/06 19:50:00 Done.
218 mName = name;
219 mAddress = address;
220 }
221 }
222
223 private static class AddressAdapter extends ArrayAdapter<AddressItem> {
224
225 public AddressAdapter(Context context, List<AddressItem> objects) {
226 super(context, R.layout.autofill_address_spinner_dropdown, objects);
227 }
228
229 @Override
230 public View getView(int position, View convertView, ViewGroup parent) {
231 return initView(position, convertView);
232 }
233
234 @Override
235 public View getDropDownView(int position, View convertView,
236 ViewGroup parent) {
Ted C 2013/03/06 01:41:56 java indenting instead of c++
Yusuf 2013/03/06 19:50:00 Done.
237 return initView(position, convertView);
238 }
239
240 private View initView(int position, View convertView) {
241 if(convertView == null)
Ted C 2013/03/06 01:41:56 space after if, braces needed, and java indenting
Yusuf 2013/03/06 19:50:00 Done.
242 convertView = View.inflate(getContext(),
243 R.layout.autofill_address_spinner_dro pdown,
244 null);
245 TextView nameView = (TextView)convertView.findViewById(R.id.name);
246 TextView addressView = (TextView)convertView.findViewById(R.id.addre ss);
247 if (nameView != null) nameView.setText(getItem(position).mName);
Ted C 2013/03/06 01:41:56 I would cache getItem(position) before this.
Yusuf 2013/03/06 19:50:00 Done.
248 if (addressView != null) addressView.setText(getItem(position).mAddr ess);
249 return convertView;
250 }
251 }
252
253 private static class CreditCardItem {
Ted C 2013/03/06 01:41:56 Do these inner classes map to native counterparts?
Yusuf 2013/03/06 19:50:00 Done.
254 int mCardIconID;
Ted C 2013/03/06 01:41:56 private final here too
Yusuf 2013/03/06 19:50:00 No. See the added TODO to createAndAddPlaceholders
255 String mLastDigits;
256 String mInfo;
257 public CreditCardItem(int icon, String lastDigits, String info) {
Ted C 2013/03/06 01:41:56 blank line above it.
Yusuf 2013/03/06 19:50:00 Done.
258 mCardIconID = icon;
259 mLastDigits = lastDigits;
260 mInfo = info;
261 }
262 }
263
264 private static class CreditCardAdapter extends ArrayAdapter<CreditCardItem> {
Ted C 2013/03/06 01:41:56 same comments as the above in regards to style.
Yusuf 2013/03/06 19:50:00 Done.
265
266 public CreditCardAdapter(Context context, List<CreditCardItem> objects) {
267 super(context, R.layout.autofill_cc_spinner_dropdown, objects);
268 }
269
270 @Override
271 public View getView(int position, View convertView, ViewGroup parent) {
272 return initView(position, convertView);
273 }
274
275 @Override
276 public View getDropDownView(int position, View convertView,
277 ViewGroup parent) {
278 return initView(position, convertView);
279 }
280
281 private View initView(int position, View convertView) {
282 if(convertView == null)
283 convertView = View.inflate(getContext(),
284 R.layout.autofill_cc_spinner_dropdown ,
285 null);
286 ImageView icon = (ImageView)convertView.findViewById(R.id.cc_icon);
287 TextView lastDigitsView = (TextView)convertView.findViewById(R.id.cc _number);
288 TextView infoView = (TextView)convertView.findViewById(R.id.cc_info) ;
289 if (icon != null) icon.setImageResource(getItem(position).mCardIconI D);
290 if (lastDigitsView != null) lastDigitsView.setText(getItem(position) .mLastDigits);
291 if (infoView != null) infoView.setText(getItem(position).mInfo);
292 return convertView;
293 }
294 }
295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698