Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestSection.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestSection.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestSection.java |
| index 495c6919d0eb4c5c6fc1126fc297945ced5ec3e1..db39da7a4b250c1276d771f0b81406231aa19d64 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestSection.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/ui/PaymentRequestSection.java |
| @@ -20,7 +20,9 @@ import android.widget.GridLayout; |
| import android.widget.ImageButton; |
| import android.widget.ImageView; |
| import android.widget.LinearLayout; |
| +import android.widget.ProgressBar; |
| import android.widget.RadioButton; |
| +import android.widget.RelativeLayout; |
| import android.widget.TextView; |
| import org.chromium.base.ApiCompatibilityUtils; |
| @@ -85,6 +87,9 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| /** Returns any additional text that needs to be displayed. */ |
| @Nullable String getAdditionalText(OptionSection section); |
| + |
| + /** Returns true if the additional text should be stylized as a warning instead of info. */ |
| + boolean isAdditionalTextWarning(OptionSection section); |
| } |
| /** Normal mode: White background, displays the item assuming the user accepts it as is. */ |
| @@ -96,6 +101,9 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| /** Focused mode: Gray background, more padding, no edit chevron. */ |
| static final int DISPLAY_MODE_FOCUSED = 2; |
| + /** Checking mode: Gray background, spinner overlay hides everything except the title. */ |
| + static final int DISPLAY_MODE_CHECKING = 3; |
| + |
| protected final SectionDelegate mDelegate; |
| protected final int mLargeSpacing; |
| @@ -163,8 +171,9 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| */ |
| public void setDisplayMode(int displayMode) { |
| mDisplayMode = displayMode; |
| - setBackgroundColor( |
| - displayMode == DISPLAY_MODE_FOCUSED ? mFocusedBackgroundColor : Color.WHITE); |
| + boolean expanded = |
|
gone
2016/06/13 20:34:03
isExpanded
please use gerrit instead
2016/06/13 21:59:08
Done.
|
| + displayMode == DISPLAY_MODE_FOCUSED || displayMode == DISPLAY_MODE_CHECKING; |
| + setBackgroundColor(expanded ? mFocusedBackgroundColor : Color.WHITE); |
| updateLogoVisibility(); |
| mChevronView.setVisibility(displayMode == DISPLAY_MODE_EXPANDABLE ? VISIBLE : GONE); |
| @@ -173,8 +182,7 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| for (int i = 0; i < mMainSection.getChildCount(); i++) { |
| if (mMainSection.getChildAt(i).getVisibility() == VISIBLE) numVisibleMainViews += 1; |
| } |
| - boolean isTitleMarginNecessary = |
| - numVisibleMainViews > 1 && displayMode == DISPLAY_MODE_FOCUSED; |
| + boolean isTitleMarginNecessary = numVisibleMainViews > 1 && expanded; |
| ((ViewGroup.MarginLayoutParams) mTitleView.getLayoutParams()).bottomMargin = |
| isTitleMarginNecessary ? mVerticalSpacing : 0; |
| } |
| @@ -216,9 +224,9 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| protected abstract void createMainSectionContent(LinearLayout mainSectionLayout); |
| /** |
| - * Sets whether or not the summary text can be displayed. |
| + * Sets whether the summary text can be displayed. |
| * |
| - * @param isAllowed Whether or not do display the summary text. |
| + * @param isAllowed Whether to display the summary text. |
| */ |
| protected void setIsSummaryAllowed(boolean isAllowed) { |
| mIsSummaryAllowed = isAllowed; |
| @@ -523,9 +531,10 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| public OptionRow( |
| GridLayout parent, int rowIndex, PaymentOption item, boolean isSelected) { |
| boolean iconExists = item != null && item.getDrawableIconId() != 0; |
| + boolean isEnabled = item != null && item.isValid(); |
| mOption = item; |
| - mButton = createButton(parent, rowIndex, isSelected); |
| - mLabel = createLabel(parent, rowIndex, iconExists); |
| + mButton = createButton(parent, rowIndex, isSelected, isEnabled); |
| + mLabel = createLabel(parent, rowIndex, iconExists, isEnabled); |
| mIcon = iconExists ? createIcon(parent, rowIndex) : null; |
| } |
| @@ -545,7 +554,8 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| mLabel.setText(stringId); |
| } |
| - private View createButton(GridLayout parent, int rowIndex, boolean isSelected) { |
| + private View createButton(GridLayout parent, int rowIndex, boolean isSelected, |
|
gone
2016/06/13 20:34:03
Everything after and including "GridLayout parent"
please use gerrit instead
2016/06/13 21:59:08
Done.
|
| + boolean isEnabled) { |
| Context context = parent.getContext(); |
| View view; |
| @@ -561,7 +571,8 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| } else { |
| // Show a radio button indicating whether the PaymentOption is selected. |
| RadioButton button = new RadioButton(context); |
| - button.setChecked(isSelected); |
| + button.setChecked(isSelected && isEnabled); |
| + button.setEnabled(isEnabled); |
| view = button; |
| } |
| @@ -577,7 +588,8 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| return view; |
| } |
| - private TextView createLabel(GridLayout parent, int rowIndex, boolean iconExists) { |
| + private TextView createLabel(GridLayout parent, int rowIndex, boolean iconExists, |
| + boolean isEnabled) { |
| Context context = parent.getContext(); |
| Resources resources = context.getResources(); |
| @@ -596,9 +608,11 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| labelView.setTypeface(Typeface.create(typeface, textStyle)); |
| } else { |
| // Show the string representing the PaymentOption. |
| - ApiCompatibilityUtils.setTextAppearance( |
| - labelView, R.style.PaymentsUiSectionDefaultText); |
| + ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled |
| + ? R.style.PaymentsUiSectionDefaultText |
| + : R.style.PaymentsUiSectionDisabledText); |
| labelView.setText(convertOptionToString(mOption)); |
| + labelView.setEnabled(isEnabled); |
| } |
| // The label spans two columns if no icon exists. Setting the view width to 0 |
| @@ -648,9 +662,15 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| /** TextView for displaying additional text. */ |
| private TextView mDescriptionView; |
| + /** Layout containing both options and the spinner. */ |
| + private RelativeLayout mOptionsContainer; |
| + |
| /** Layout containing all the {@link OptionRow}s. */ |
| private GridLayout mOptionLayout; |
| + /** A spinner and message to show when the user selection is being checked. */ |
| + private LinearLayout mCheckingProgress; |
| + |
| /** |
| * Constructs an OptionSection. |
| * |
| @@ -700,14 +720,30 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| @Override |
| protected void createMainSectionContent(LinearLayout mainSectionLayout) { |
| Context context = mainSectionLayout.getContext(); |
| - |
| mDescriptionView = new TextView(getContext()); |
| - ApiCompatibilityUtils.setTextAppearance( |
| - mDescriptionView, R.style.PaymentsUiSectionDescriptiveText); |
| + mOptionsContainer = new RelativeLayout(getContext()); |
|
gone
2016/06/13 20:34:03
No point in using an expensive RelativeLayout if t
please use gerrit instead
2016/06/13 21:59:08
Talked to UX. They want us to collapse the view, s
|
| mOptionLayout = new GridLayout(context); |
| mOptionLayout.setColumnCount(3); |
| - mainSectionLayout.addView(mOptionLayout, new LinearLayout.LayoutParams( |
| + mOptionsContainer.addView(mOptionLayout); |
| + RelativeLayout.LayoutParams lp = |
| + ((RelativeLayout.LayoutParams) mOptionLayout.getLayoutParams()); |
| + lp.addRule(RelativeLayout.ALIGN_PARENT_START); |
| + lp.addRule(RelativeLayout.ALIGN_PARENT_END); |
| + |
| + TextView message = new TextView(getContext()); |
| + message.setText(getContext().getString(R.string.payments_shipping_address_checking)); |
| + |
| + mCheckingProgress = new LinearLayout(getContext()); |
| + mCheckingProgress.setOrientation(LinearLayout.VERTICAL); |
| + mCheckingProgress.addView(new ProgressBar(getContext())); |
| + mCheckingProgress.addView(message); |
| + mOptionsContainer.addView(mCheckingProgress); |
| + lp = ((RelativeLayout.LayoutParams) mCheckingProgress.getLayoutParams()); |
| + lp.addRule(RelativeLayout.CENTER_IN_PARENT); |
| + mCheckingProgress.setVisibility(GONE); |
| + |
| + mainSectionLayout.addView(mOptionsContainer, new LinearLayout.LayoutParams( |
| LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); |
| } |
| @@ -725,10 +761,17 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| if (displayMode == DISPLAY_MODE_FOCUSED) { |
| setIsSummaryAllowed(false); |
| mOptionLayout.setVisibility(VISIBLE); |
| + mCheckingProgress.setVisibility(GONE); |
| + setDescriptionVisibility(!TextUtils.isEmpty(mDescriptionView.getText())); |
| + } else if (displayMode == DISPLAY_MODE_CHECKING) { |
| + setIsSummaryAllowed(false); |
| + mOptionLayout.setVisibility(INVISIBLE); |
| + mCheckingProgress.setVisibility(VISIBLE); |
| setDescriptionVisibility(!TextUtils.isEmpty(mDescriptionView.getText())); |
| } else { |
| setIsSummaryAllowed(true); |
| mOptionLayout.setVisibility(GONE); |
| + mCheckingProgress.setVisibility(GONE); |
| setDescriptionVisibility(false); |
| } |
| } |
| @@ -753,9 +796,9 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| */ |
| private void setDescriptionVisibility(boolean visible) { |
| if (visible && mDescriptionView.getParent() == null) { |
| - // Put it right above the GridLayout with all the PaymentOptions. |
| - ViewGroup mainSectionLayout = (ViewGroup) mOptionLayout.getParent(); |
| - int optionLayoutIndex = mainSectionLayout.indexOfChild(mOptionLayout); |
| + // Put it right above the mOptionsContainer with all the PaymentOptions. |
| + ViewGroup mainSectionLayout = (ViewGroup) mOptionsContainer.getParent(); |
| + int optionLayoutIndex = mainSectionLayout.indexOfChild(mOptionsContainer); |
| LinearLayout.LayoutParams descriptionParams = new LinearLayout.LayoutParams( |
| LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); |
| @@ -771,6 +814,10 @@ public abstract class PaymentRequestSection extends LinearLayout { |
| private void updateOptionList(SectionInformation information, PaymentOption selectedItem) { |
| mDescriptionView.setText(mDelegate.getAdditionalText(this)); |
| setDescriptionVisibility(!TextUtils.isEmpty(mDescriptionView.getText())); |
| + ApiCompatibilityUtils.setTextAppearance( |
| + mDescriptionView, mDelegate.isAdditionalTextWarning(this) |
| + ? R.style.PaymentsUiSectionWarningText |
| + : R.style.PaymentsUiSectionDescriptiveText); |
| mOptionLayout.removeAllViews(); |
| mOptionRows.clear(); |