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

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

Issue 2436883002: Make PaymentOption store a Drawable instead of id (Closed)
Patch Set: Try to fix test compilation Created 4 years, 2 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.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
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
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
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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 private static final int OPTION_ROW_TYPE_WARNING = 3; 683 private static final int OPTION_ROW_TYPE_WARNING = 3;
683 684
684 private final int mRowType; 685 private final int mRowType;
685 private final PaymentOption mOption; 686 private final PaymentOption mOption;
686 private final View mButton; 687 private final View mButton;
687 private final TextView mLabel; 688 private final TextView mLabel;
688 private final View mIcon; 689 private final View mIcon;
689 690
690 public OptionRow(GridLayout parent, int rowIndex, int rowType, Payme ntOption item, 691 public OptionRow(GridLayout parent, int rowIndex, int rowType, Payme ntOption item,
691 boolean isSelected) { 692 boolean isSelected) {
692 boolean iconExists = item != null && item.getDrawableIconId() != 0; 693 boolean iconExists = item != null && item.getDrawableIcon() != n ull;
693 boolean isEnabled = item != null && item.isValid(); 694 boolean isEnabled = item != null && item.isValid();
694 mRowType = rowType; 695 mRowType = rowType;
695 mOption = item; 696 mOption = item;
696 mButton = createButton(parent, rowIndex, isSelected, isEnabled); 697 mButton = createButton(parent, rowIndex, isSelected, isEnabled);
697 mLabel = createLabel(parent, rowIndex, iconExists, isEnabled); 698 mLabel = createLabel(parent, rowIndex, iconExists, isEnabled);
698 mIcon = iconExists ? createIcon(parent, rowIndex) : null; 699 mIcon = iconExists ? createIcon(parent, rowIndex) : null;
699 } 700 }
700 701
701 /** Sets the selected state of this item, alerting the delegate if s elected. */ 702 /** Sets the selected state of this item, alerting the delegate if s elected. */
702 public void setChecked(boolean isChecked) { 703 public void setChecked(boolean isChecked) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 836
836 labelView.setOnClickListener(OptionSection.this); 837 labelView.setOnClickListener(OptionSection.this);
837 return labelView; 838 return labelView;
838 } 839 }
839 840
840 private View createIcon(GridLayout parent, int rowIndex) { 841 private View createIcon(GridLayout parent, int rowIndex) {
841 // The icon has a pre-defined width. 842 // The icon has a pre-defined width.
842 ImageView icon = new ImageView(parent.getContext()); 843 ImageView icon = new ImageView(parent.getContext());
843 icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO ); 844 icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO );
844 icon.setBackgroundResource(R.drawable.payments_ui_logo_bg); 845 icon.setBackgroundResource(R.drawable.payments_ui_logo_bg);
845 icon.setImageResource(mOption.getDrawableIconId()); 846 icon.setImageDrawable(mOption.getDrawableIcon());
846 icon.setMaxWidth(mIconMaxWidth); 847 icon.setMaxWidth(mIconMaxWidth);
847 848
848 // The icon floats to the right of everything. 849 // The icon floats to the right of everything.
849 GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams ( 850 GridLayout.LayoutParams iconParams = new GridLayout.LayoutParams (
850 GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLay out.spec(2, 1)); 851 GridLayout.spec(rowIndex, 1, GridLayout.CENTER), GridLay out.spec(2, 1));
851 iconParams.topMargin = mVerticalMargin; 852 iconParams.topMargin = mVerticalMargin;
852 ApiCompatibilityUtils.setMarginStart(iconParams, mLargeSpacing); 853 ApiCompatibilityUtils.setMarginStart(iconParams, mLargeSpacing);
853 parent.addView(icon, iconParams); 854 parent.addView(icon, iconParams);
854 855
855 icon.setOnClickListener(OptionSection.this); 856 icon.setOnClickListener(OptionSection.this);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 } else if (mSectionInformation.getSelectedItem() == null) { 1018 } else if (mSectionInformation.getSelectedItem() == null) {
1018 // The user hasn't selected any available PaymentOptions. Ask t he user to pick one. 1019 // The user hasn't selected any available PaymentOptions. Ask t he user to pick one.
1019 return EDIT_BUTTON_SELECT; 1020 return EDIT_BUTTON_SELECT;
1020 } else { 1021 } else {
1021 return EDIT_BUTTON_GONE; 1022 return EDIT_BUTTON_GONE;
1022 } 1023 }
1023 } 1024 }
1024 1025
1025 private void updateSelectedItem(PaymentOption selectedItem) { 1026 private void updateSelectedItem(PaymentOption selectedItem) {
1026 if (selectedItem == null) { 1027 if (selectedItem == null) {
1027 setLogoResource(0); 1028 setLogoDrawable(null);
1028 setIsSummaryAllowed(false); 1029 setIsSummaryAllowed(false);
1029 setSummaryText(null, null); 1030 setSummaryText(null, null);
1030 } else { 1031 } else {
1031 setLogoResource(selectedItem.getDrawableIconId()); 1032 setLogoDrawable(selectedItem.getDrawableIcon());
1032 setSummaryText(convertOptionToString(selectedItem, false), null) ; 1033 setSummaryText(convertOptionToString(selectedItem, false), null) ;
1033 } 1034 }
1034 1035
1035 updateControlLayout(); 1036 updateControlLayout();
1036 } 1037 }
1037 1038
1038 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) { 1039 private void updateOptionList(SectionInformation information, PaymentOpt ion selectedItem) {
1039 mOptionLayout.removeAllViews(); 1040 mOptionLayout.removeAllViews();
1040 mOptionRows.clear(); 1041 mOptionRows.clear();
1041 mLabelsForTest.clear(); 1042 mLabelsForTest.clear();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 } 1154 }
1154 1155
1155 /** Expand the separator to be the full width of the dialog. */ 1156 /** Expand the separator to be the full width of the dialog. */
1156 public void expand() { 1157 public void expand() {
1157 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa youtParams(); 1158 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLa youtParams();
1158 ApiCompatibilityUtils.setMarginStart(params, 0); 1159 ApiCompatibilityUtils.setMarginStart(params, 0);
1159 ApiCompatibilityUtils.setMarginEnd(params, 0); 1160 ApiCompatibilityUtils.setMarginEnd(params, 0);
1160 } 1161 }
1161 } 1162 }
1162 } 1163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698