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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/EditorIconsField.java

Issue 2902503002: [Payment] should show all accepted card icon in payment editor. (Closed)
Patch Set: adjust icon size Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.payments.ui; 5 package org.chromium.chrome.browser.payments.ui;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
9 import android.view.View; 9 import android.view.View;
10 import android.view.ViewGroup; 10 import android.view.ViewGroup;
11 import android.view.ViewGroup.LayoutParams; 11 import android.widget.BaseAdapter;
12 import android.widget.ImageView; 12 import android.widget.ImageView;
13 import android.widget.LinearLayout;
14 import android.widget.TextView; 13 import android.widget.TextView;
15 14
16 import org.chromium.base.ApiCompatibilityUtils;
17 import org.chromium.chrome.R; 15 import org.chromium.chrome.R;
16 import org.chromium.chrome.browser.widget.DynamicHeightGridView;
17
18 import java.util.List;
18 19
19 /** 20 /**
20 * Helper class for creating a horizontal list of icons with a title. 21 * Helper class for creating a horizontal list of icons with a title.
21 */ 22 */
22 class EditorIconsField { 23 class EditorIconsField {
23 private final View mLayout; 24 private final View mLayout;
24 25
25 /** 26 /**
26 * Builds a horizontal list of icons. 27 * Builds a horizontal list of icons.
27 * 28 *
28 * @param context The application context to use when creating widgets. 29 * @param context The application context to use when creating widgets.
29 * @param root The object that provides a set of LayoutParams values f or the view. 30 * @param root The object that provides a set of LayoutParams values f or the view.
30 * @param fieldModel The data model of the icon list. 31 * @param fieldModel The data model of the icon list.
31 */ 32 */
32 public EditorIconsField(Context context, ViewGroup root, EditorFieldModel fi eldModel) { 33 public EditorIconsField(Context context, ViewGroup root, EditorFieldModel fi eldModel) {
33 assert fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT _ICONS; 34 assert fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT _ICONS;
34 35
35 mLayout = LayoutInflater.from(context).inflate( 36 mLayout = LayoutInflater.from(context).inflate(
36 R.layout.payment_request_editor_icons, root, false); 37 R.layout.payment_request_editor_icons, root, false);
37 38
38 ((TextView) mLayout.findViewById(R.id.label)).setText(fieldModel.getLabe l()); 39 ((TextView) mLayout.findViewById(R.id.label)).setText(fieldModel.getLabe l());
39 40
40 LinearLayout container = (LinearLayout) mLayout.findViewById(R.id.icons_ container); 41 DynamicHeightGridView container =
gogerald1 2017/05/24 14:25:23 nit: iconsContainer
Hwanseung Lee 2017/05/26 15:42:39 Done.
41 int size = 42 (DynamicHeightGridView) mLayout.findViewById(R.id.icons_containe r);
42 context.getResources().getDimensionPixelSize(R.dimen.payments_se ction_logo_width); 43 container.setAdapter(new IconAdapter(context, fieldModel.getIconResource Ids(),
43 int margin = context.getResources().getDimensionPixelSize( 44 fieldModel.getIconDescriptionsForAccessibility()));
44 R.dimen.payments_section_small_spacing);
45 LinearLayout.LayoutParams layoutParams =
46 new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutP arams.WRAP_CONTENT);
47 ApiCompatibilityUtils.setMarginEnd(layoutParams, margin);
48 for (int i = 0; i < fieldModel.getIconResourceIds().size(); i++) {
49 ImageView icon = new ImageView(context);
50 icon.setImageResource(fieldModel.getIconResourceIds().get(i));
51 icon.setBackgroundResource(R.drawable.payments_ui_logo_bg);
52 icon.setContentDescription(context.getString(
53 fieldModel.getIconDescriptionsForAccessibility().get(i)));
54 icon.setAdjustViewBounds(true);
55 icon.setMaxWidth(size);
56 icon.setMaxHeight(size);
57 container.addView(icon, layoutParams);
58 }
59 } 45 }
60 46
61 /** @return The View containing everything. */ 47 /** @return The View containing everything. */
62 public View getLayout() { 48 public View getLayout() {
63 return mLayout; 49 return mLayout;
64 } 50 }
51
52 private static class IconAdapter extends BaseAdapter {
gogerald1 2017/05/24 14:25:23 gridview setAdapter accepts ListAdapter https://d
Hwanseung Lee 2017/05/26 15:42:39 right, but BaseAdapter implement ListAdapter. http
53 private Context mContext;
54 private List<Integer> mIconResources;
gogerald1 2017/05/24 14:25:23 nit: mIconResourceIds
Hwanseung Lee 2017/05/26 15:42:39 Done.
55 private List<Integer> mIconDescription;
gogerald1 2017/05/24 14:25:23 nit: mIconDescriptionIds
Hwanseung Lee 2017/05/26 15:42:39 Done.
56 private int mIconSize;
57
58 public IconAdapter(
gogerald1 2017/05/24 14:25:23 IconListAdapter?
Hwanseung Lee 2017/05/26 15:42:39 Done.
59 Context context, List<Integer> iconResources, List<Integer> icon Description) {
60 mContext = context;
61 mIconResources = iconResources;
62 mIconDescription = iconDescription;
63 mIconSize = mContext.getResources().getDimensionPixelSize(
64 R.dimen.payments_section_logo_width);
gogerald1 2017/05/24 14:25:23 nit: assert mIconResourceIds.size() == mIconDescri
Hwanseung Lee 2017/05/26 15:42:39 Done.
65 }
66 public int getCount() {
gogerald1 2017/05/24 14:25:23 one space line above and @Override
Hwanseung Lee 2017/05/26 15:42:40 Done.
67 return mIconResources.size();
68 }
69 public Object getItem(int position) {
gogerald1 2017/05/24 14:25:23 ditto
Hwanseung Lee 2017/05/26 15:42:39 Done.
70 return mIconResources.get(position);
71 }
72 public long getItemId(int position) {
gogerald1 2017/05/24 14:25:23 ditto
Hwanseung Lee 2017/05/26 15:42:39 Done.
73 return position;
74 }
75 public View getView(int position, View convertView, ViewGroup parent) {
gogerald1 2017/05/24 14:25:23 ditto
Hwanseung Lee 2017/05/26 15:42:39 Done.
76 ImageView imageView;
gogerald1 2017/05/24 14:25:23 you can simplify this code like below. ImageView
Hwanseung Lee 2017/05/26 15:42:39 Done.
77 if (convertView == null) {
78 imageView = new ImageView(mContext);
79 } else {
80 imageView = (ImageView) convertView;
81 }
82 imageView.setImageResource(mIconResources.get(position));
gogerald1 2017/05/24 14:25:23 setImageDrawable instead of setImageResource, http
Hwanseung Lee 2017/05/26 15:42:39 Done.
83 imageView.setBackgroundResource(R.drawable.payments_ui_logo_bg);
gogerald1 2017/05/24 14:25:23 no need setBackgroundResource anymore,
Hwanseung Lee 2017/05/26 15:42:39 Done.
84 imageView.setContentDescription(mContext.getString(mIconDescription. get(position)));
85 imageView.setAdjustViewBounds(true);
86 imageView.setMaxWidth(mIconSize);
87 imageView.setMaxHeight(mIconSize);
88 return imageView;
89 }
90 }
65 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698