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.content.res.Resources; | 8 import android.content.res.Resources; |
9 import android.graphics.Color; | 9 import android.graphics.Color; |
10 import android.graphics.Typeface; | 10 import android.graphics.Typeface; |
11 import android.graphics.drawable.Drawable; | |
12 import android.text.SpannableStringBuilder; | 11 import android.text.SpannableStringBuilder; |
13 import android.text.TextUtils; | 12 import android.text.TextUtils; |
14 import android.text.TextUtils.TruncateAt; | 13 import android.text.TextUtils.TruncateAt; |
15 import android.text.style.StyleSpan; | 14 import android.text.style.StyleSpan; |
16 import android.view.Gravity; | 15 import android.view.Gravity; |
17 import android.view.LayoutInflater; | 16 import android.view.LayoutInflater; |
18 import android.view.MotionEvent; | 17 import android.view.MotionEvent; |
19 import android.view.View; | 18 import android.view.View; |
20 import android.view.ViewGroup; | 19 import android.view.ViewGroup; |
21 import android.widget.Button; | 20 import android.widget.Button; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 private final int mFocusedBackgroundColor; | 128 private final int mFocusedBackgroundColor; |
130 private final LinearLayout mMainSection; | 129 private final LinearLayout mMainSection; |
131 private final ImageView mLogoView; | 130 private final ImageView mLogoView; |
132 private final ImageView mChevronView; | 131 private final ImageView mChevronView; |
133 | 132 |
134 private TextView mTitleView; | 133 private TextView mTitleView; |
135 private LinearLayout mSummaryLayout; | 134 private LinearLayout mSummaryLayout; |
136 private TextView mSummaryLeftTextView; | 135 private TextView mSummaryLeftTextView; |
137 private TextView mSummaryRightTextView; | 136 private TextView mSummaryRightTextView; |
138 | 137 |
139 private Drawable mLogo; | 138 private int mLogoResourceId; |
140 private boolean mIsSummaryAllowed = true; | 139 private boolean mIsSummaryAllowed = true; |
141 | 140 |
142 /** | 141 /** |
143 * Constructs a PaymentRequestSection. | 142 * Constructs a PaymentRequestSection. |
144 * | 143 * |
145 * @param context Context to pull resources from. | 144 * @param context Context to pull resources from. |
146 * @param sectionName Title of the section to display. | 145 * @param sectionName Title of the section to display. |
147 * @param delegate Delegate to alert when something changes in the dialog
. | 146 * @param delegate Delegate to alert when something changes in the dialog
. |
148 */ | 147 */ |
149 private PaymentRequestSection(Context context, String sectionName, SectionDe
legate delegate) { | 148 private PaymentRequestSection(Context context, String sectionName, SectionDe
legate delegate) { |
(...skipping 17 matching lines...) Expand all Loading... |
167 mLogoView = isLogoNecessary() ? createAndAddLogoView(this, 0, mLargeSpac
ing) : null; | 166 mLogoView = isLogoNecessary() ? createAndAddLogoView(this, 0, mLargeSpac
ing) : null; |
168 mEditButtonView = createAndAddEditButton(this); | 167 mEditButtonView = createAndAddEditButton(this); |
169 mChevronView = createAndAddChevron(this); | 168 mChevronView = createAndAddChevron(this); |
170 mIsLayoutInitialized = true; | 169 mIsLayoutInitialized = true; |
171 setDisplayMode(DISPLAY_MODE_NORMAL); | 170 setDisplayMode(DISPLAY_MODE_NORMAL); |
172 } | 171 } |
173 | 172 |
174 /** | 173 /** |
175 * Sets what logo should be displayed. | 174 * Sets what logo should be displayed. |
176 * | 175 * |
177 * @param resource The logo to display. | 176 * @param resourceId ID of the logo to display. |
178 */ | 177 */ |
179 protected void setLogoDrawable(Drawable logo) { | 178 protected void setLogoResource(int resourceId) { |
180 assert isLogoNecessary(); | 179 assert isLogoNecessary(); |
181 mLogo = logo; | 180 mLogoResourceId = resourceId; |
182 mLogoView.setImageDrawable(mLogo); | 181 mLogoView.setImageResource(resourceId); |
183 } | 182 } |
184 | 183 |
185 @Override | 184 @Override |
186 public boolean onInterceptTouchEvent(MotionEvent event) { | 185 public boolean onInterceptTouchEvent(MotionEvent event) { |
187 // Allow touches to propagate to children only if the layout can be inte
racted with. | 186 // Allow touches to propagate to children only if the layout can be inte
racted with. |
188 return !mDelegate.isAcceptingUserInput(); | 187 return !mDelegate.isAcceptingUserInput(); |
189 } | 188 } |
190 | 189 |
191 @Override | 190 @Override |
192 public final void onClick(View v) { | 191 public final void onClick(View v) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 */ | 404 */ |
406 protected void updateControlLayout() { | 405 protected void updateControlLayout() { |
407 if (!mIsLayoutInitialized) return; | 406 if (!mIsLayoutInitialized) return; |
408 | 407 |
409 boolean isExpanded = | 408 boolean isExpanded = |
410 mDisplayMode == DISPLAY_MODE_FOCUSED || mDisplayMode == DISPLAY_
MODE_CHECKING; | 409 mDisplayMode == DISPLAY_MODE_FOCUSED || mDisplayMode == DISPLAY_
MODE_CHECKING; |
411 setBackgroundColor(isExpanded ? mFocusedBackgroundColor : Color.WHITE); | 410 setBackgroundColor(isExpanded ? mFocusedBackgroundColor : Color.WHITE); |
412 | 411 |
413 // Update whether the logo is displayed. | 412 // Update whether the logo is displayed. |
414 if (mLogoView != null) { | 413 if (mLogoView != null) { |
415 boolean show = mLogo != null && mDisplayMode != DISPLAY_MODE_FOCUSED
; | 414 boolean show = mLogoResourceId != 0 && mDisplayMode != DISPLAY_MODE_
FOCUSED; |
416 mLogoView.setVisibility(show ? VISIBLE : GONE); | 415 mLogoView.setVisibility(show ? VISIBLE : GONE); |
417 } | 416 } |
418 | 417 |
419 // The button takes precedence over the summary text and the chevron. | 418 // The button takes precedence over the summary text and the chevron. |
420 int editButtonState = getEditButtonState(); | 419 int editButtonState = getEditButtonState(); |
421 if (editButtonState == EDIT_BUTTON_GONE) { | 420 if (editButtonState == EDIT_BUTTON_GONE) { |
422 mEditButtonView.setVisibility(GONE); | 421 mEditButtonView.setVisibility(GONE); |
423 mChevronView.setVisibility( | 422 mChevronView.setVisibility( |
424 mDisplayMode == DISPLAY_MODE_EXPANDABLE ? VISIBLE : GONE); | 423 mDisplayMode == DISPLAY_MODE_EXPANDABLE ? VISIBLE : GONE); |
425 | 424 |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 private static final int OPTION_ROW_TYPE_WARNING = 3; | 711 private static final int OPTION_ROW_TYPE_WARNING = 3; |
713 | 712 |
714 private final int mRowType; | 713 private final int mRowType; |
715 private final PaymentOption mOption; | 714 private final PaymentOption mOption; |
716 private final View mButton; | 715 private final View mButton; |
717 private final TextView mLabel; | 716 private final TextView mLabel; |
718 private final View mIcon; | 717 private final View mIcon; |
719 | 718 |
720 public OptionRow(GridLayout parent, int rowIndex, int rowType, Payme
ntOption item, | 719 public OptionRow(GridLayout parent, int rowIndex, int rowType, Payme
ntOption item, |
721 boolean isSelected) { | 720 boolean isSelected) { |
722 boolean iconExists = item != null && item.getDrawableIcon() != n
ull; | 721 boolean iconExists = item != null && item.getDrawableIconId() !=
0; |
723 boolean isEnabled = item != null && item.isValid(); | 722 boolean isEnabled = item != null && item.isValid(); |
724 mRowType = rowType; | 723 mRowType = rowType; |
725 mOption = item; | 724 mOption = item; |
726 mButton = createButton(parent, rowIndex, isSelected, isEnabled); | 725 mButton = createButton(parent, rowIndex, isSelected, isEnabled); |
727 mLabel = createLabel(parent, rowIndex, iconExists, isEnabled); | 726 mLabel = createLabel(parent, rowIndex, iconExists, isEnabled); |
728 mIcon = iconExists ? createIcon(parent, rowIndex) : null; | 727 mIcon = iconExists ? createIcon(parent, rowIndex) : null; |
729 } | 728 } |
730 | 729 |
731 /** Sets the selected state of this item, alerting the delegate if s
elected. */ | 730 /** Sets the selected state of this item, alerting the delegate if s
elected. */ |
732 public void setChecked(boolean isChecked) { | 731 public void setChecked(boolean isChecked) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 | 864 |
866 labelView.setOnClickListener(OptionSection.this); | 865 labelView.setOnClickListener(OptionSection.this); |
867 return labelView; | 866 return labelView; |
868 } | 867 } |
869 | 868 |
870 private View createIcon(GridLayout parent, int rowIndex) { | 869 private View createIcon(GridLayout parent, int rowIndex) { |
871 // The icon has a pre-defined width. | 870 // The icon has a pre-defined width. |
872 ImageView icon = new ImageView(parent.getContext()); | 871 ImageView icon = new ImageView(parent.getContext()); |
873 icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO
); | 872 icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO
); |
874 icon.setBackgroundResource(R.drawable.payments_ui_logo_bg); | 873 icon.setBackgroundResource(R.drawable.payments_ui_logo_bg); |
875 icon.setImageDrawable(mOption.getDrawableIcon()); | 874 icon.setImageResource(mOption.getDrawableIconId()); |
876 icon.setMaxWidth(mIconMaxWidth); | 875 icon.setMaxWidth(mIconMaxWidth); |
877 | 876 |
878 // The icon floats to the right of everything. | 877 // The icon floats to the right of everything. |
879 GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams
( | 878 GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams
( |
880 GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLay
out.spec(2, 1)); | 879 GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLay
out.spec(2, 1)); |
881 iconParams.topMargin = mVerticalMargin; | 880 iconParams.topMargin = mVerticalMargin; |
882 ApiCompatibilityUtils.setMarginStart(iconParams, mLargeSpacing); | 881 ApiCompatibilityUtils.setMarginStart(iconParams, mLargeSpacing); |
883 parent.addView(icon, iconParams); | 882 parent.addView(icon, iconParams); |
884 | 883 |
885 icon.setOnClickListener(OptionSection.this); | 884 icon.setOnClickListener(OptionSection.this); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 } else if (mSectionInformation.getSelectedItem() == null) { | 1046 } else if (mSectionInformation.getSelectedItem() == null) { |
1048 // The user hasn't selected any available PaymentOptions. Ask t
he user to pick one. | 1047 // The user hasn't selected any available PaymentOptions. Ask t
he user to pick one. |
1049 return EDIT_BUTTON_SELECT; | 1048 return EDIT_BUTTON_SELECT; |
1050 } else { | 1049 } else { |
1051 return EDIT_BUTTON_GONE; | 1050 return EDIT_BUTTON_GONE; |
1052 } | 1051 } |
1053 } | 1052 } |
1054 | 1053 |
1055 private void updateSelectedItem(PaymentOption selectedItem) { | 1054 private void updateSelectedItem(PaymentOption selectedItem) { |
1056 if (selectedItem == null) { | 1055 if (selectedItem == null) { |
1057 setLogoDrawable(null); | 1056 setLogoResource(0); |
1058 setIsSummaryAllowed(false); | 1057 setIsSummaryAllowed(false); |
1059 setSummaryText(null, null); | 1058 setSummaryText(null, null); |
1060 } else { | 1059 } else { |
1061 setLogoDrawable(selectedItem.getDrawableIcon()); | 1060 setLogoResource(selectedItem.getDrawableIconId()); |
1062 setSummaryText(convertOptionToString(selectedItem, false), null)
; | 1061 setSummaryText(convertOptionToString(selectedItem, false), null)
; |
1063 } | 1062 } |
1064 | 1063 |
1065 updateControlLayout(); | 1064 updateControlLayout(); |
1066 } | 1065 } |
1067 | 1066 |
1068 private void updateOptionList(SectionInformation information, PaymentOpt
ion selectedItem) { | 1067 private void updateOptionList(SectionInformation information, PaymentOpt
ion selectedItem) { |
1069 mOptionLayout.removeAllViews(); | 1068 mOptionLayout.removeAllViews(); |
1070 mOptionRows.clear(); | 1069 mOptionRows.clear(); |
1071 mLabelsForTest.clear(); | 1070 mLabelsForTest.clear(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 } | 1182 } |
1184 | 1183 |
1185 /** Expand the separator to be the full width of the dialog. */ | 1184 /** Expand the separator to be the full width of the dialog. */ |
1186 public void expand() { | 1185 public void expand() { |
1187 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa
youtParams(); | 1186 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa
youtParams(); |
1188 ApiCompatibilityUtils.setMarginStart(params, 0); | 1187 ApiCompatibilityUtils.setMarginStart(params, 0); |
1189 ApiCompatibilityUtils.setMarginEnd(params, 0); | 1188 ApiCompatibilityUtils.setMarginEnd(params, 0); |
1190 } | 1189 } |
1191 } | 1190 } |
1192 } | 1191 } |
OLD | NEW |