OLD | NEW |
---|---|
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.support.v7.content.res.AppCompatResources; | 8 import android.support.v7.content.res.AppCompatResources; |
9 import android.view.LayoutInflater; | 9 import android.view.LayoutInflater; |
10 import android.view.View; | 10 import android.view.View; |
11 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
12 import android.view.ViewGroup.LayoutParams; | 12 import android.widget.BaseAdapter; |
13 import android.widget.ImageView; | 13 import android.widget.ImageView; |
14 import android.widget.LinearLayout; | |
15 import android.widget.TextView; | 14 import android.widget.TextView; |
16 | 15 |
17 import org.chromium.base.ApiCompatibilityUtils; | |
18 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
17 import org.chromium.chrome.browser.widget.ExpandableGridView; | |
18 | |
19 import java.util.List; | |
19 | 20 |
20 /** | 21 /** |
21 * Helper class for creating a horizontal list of icons with a title. | 22 * Helper class for creating a horizontal list of icons with a title. |
22 */ | 23 */ |
23 class EditorIconsField { | 24 class EditorIconsField { |
24 private final View mLayout; | 25 private final View mLayout; |
25 | 26 |
26 /** | 27 /** |
27 * Builds a horizontal list of icons. | 28 * Builds a horizontal list of icons. |
28 * | 29 * |
29 * @param context The application context to use when creating widgets. | 30 * @param context The application context to use when creating widgets. |
30 * @param root The object that provides a set of LayoutParams values f or the view. | 31 * @param root The object that provides a set of LayoutParams values f or the view. |
31 * @param fieldModel The data model of the icon list. | 32 * @param fieldModel The data model of the icon list. |
32 */ | 33 */ |
33 public EditorIconsField(Context context, ViewGroup root, EditorFieldModel fi eldModel) { | 34 public EditorIconsField(Context context, ViewGroup root, EditorFieldModel fi eldModel) { |
34 assert fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT _ICONS; | 35 assert fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT _ICONS; |
35 | 36 |
36 mLayout = LayoutInflater.from(context).inflate( | 37 mLayout = LayoutInflater.from(context).inflate( |
37 R.layout.payment_request_editor_icons, root, false); | 38 R.layout.payment_request_editor_icons, root, false); |
38 | 39 |
39 ((TextView) mLayout.findViewById(R.id.label)).setText(fieldModel.getLabe l()); | 40 ((TextView) mLayout.findViewById(R.id.label)).setText(fieldModel.getLabe l()); |
40 | 41 |
41 LinearLayout container = (LinearLayout) mLayout.findViewById(R.id.icons_ container); | 42 ExpandableGridView iconsContainer = |
42 int size = | 43 (ExpandableGridView) mLayout.findViewById(R.id.icons_container); |
43 context.getResources().getDimensionPixelSize(R.dimen.payments_se ction_logo_width); | 44 iconsContainer.setAdapter(new IconListAdapter(context, fieldModel.getIco nResourceIds(), |
44 int margin = context.getResources().getDimensionPixelSize( | 45 fieldModel.getIconDescriptionsForAccessibility())); |
45 R.dimen.payments_section_small_spacing); | |
46 LinearLayout.LayoutParams layoutParams = | |
47 new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutP arams.WRAP_CONTENT); | |
48 ApiCompatibilityUtils.setMarginEnd(layoutParams, margin); | |
49 for (int i = 0; i < fieldModel.getIconResourceIds().size(); i++) { | |
50 ImageView icon = new ImageView(context); | |
51 icon.setImageDrawable(AppCompatResources.getDrawable( | |
52 context, fieldModel.getIconResourceIds().get(i))); | |
53 icon.setContentDescription(context.getString( | |
54 fieldModel.getIconDescriptionsForAccessibility().get(i))); | |
55 icon.setAdjustViewBounds(true); | |
56 icon.setMaxWidth(size); | |
57 icon.setMaxHeight(size); | |
58 container.addView(icon, layoutParams); | |
59 } | |
60 } | 46 } |
61 | 47 |
62 /** @return The View containing everything. */ | 48 /** @return The View containing everything. */ |
63 public View getLayout() { | 49 public View getLayout() { |
64 return mLayout; | 50 return mLayout; |
65 } | 51 } |
52 | |
53 /** | |
54 * this Adapter provides access to the icon views. | |
gogerald1
2017/05/31 15:12:01
"An instance of a {@link BaseAdapter} that provide
Hwanseung Lee
2017/05/31 15:37:58
Done.
| |
55 */ | |
56 private static class IconListAdapter extends BaseAdapter { | |
57 private Context mContext; | |
58 private List<Integer> mIconResourceIds; | |
59 private List<Integer> mIconDescriptionIds; | |
60 private int mIconSize; | |
61 | |
62 public IconListAdapter( | |
63 Context context, List<Integer> iconResourceIds, List<Integer> ic onDescriptionIds) { | |
64 mContext = context; | |
65 mIconResourceIds = iconResourceIds; | |
66 mIconDescriptionIds = iconDescriptionIds; | |
67 mIconSize = mContext.getResources().getDimensionPixelSize( | |
68 R.dimen.payments_section_logo_width); | |
69 assert mIconResourceIds.size() == mIconDescriptionIds.size(); | |
70 } | |
71 | |
72 @Override | |
73 public int getCount() { | |
74 return mIconResourceIds.size(); | |
75 } | |
76 | |
77 @Override | |
78 public Object getItem(int position) { | |
79 return mIconResourceIds.get(position); | |
80 } | |
81 | |
82 @Override | |
83 public long getItemId(int position) { | |
84 return position; | |
85 } | |
86 | |
87 @Override | |
88 public View getView(int position, View convertView, ViewGroup parent) { | |
89 ImageView iconView = (ImageView) convertView; | |
90 if (iconView == null) iconView = new ImageView(mContext); | |
91 iconView.setImageDrawable( | |
92 AppCompatResources.getDrawable(mContext, mIconResourceIds.ge t(position))); | |
93 iconView.setContentDescription(mContext.getString(mIconDescriptionId s.get(position))); | |
94 iconView.setAdjustViewBounds(true); | |
95 iconView.setMaxWidth(mIconSize); | |
96 iconView.setMaxHeight(mIconSize); | |
97 return iconView; | |
98 } | |
99 } | |
66 } | 100 } |
OLD | NEW |