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