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 static org.chromium.chrome.browser.payments.ui.PaymentRequestSection.EDIT
_BUTTON_GONE; | 7 import static org.chromium.chrome.browser.payments.ui.PaymentRequestSection.EDIT
_BUTTON_GONE; |
8 | 8 |
9 import android.animation.Animator; | 9 import android.animation.Animator; |
10 import android.animation.AnimatorListenerAdapter; | 10 import android.animation.AnimatorListenerAdapter; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 import java.util.ArrayList; | 56 import java.util.ArrayList; |
57 import java.util.List; | 57 import java.util.List; |
58 | 58 |
59 /** | 59 /** |
60 * The PaymentRequest UI. | 60 * The PaymentRequest UI. |
61 */ | 61 */ |
62 public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
.OnClickListener, | 62 public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
.OnClickListener, |
63 PaymentRequestSection.SectionDelegate { | 63 PaymentRequestSection.SectionDelegate { |
64 public static final int TYPE_SHIPPING_ADDRESSES = 1; | 64 public static final int TYPE_SHIPPING_ADDRESSES = 1; |
65 public static final int TYPE_SHIPPING_OPTIONS = 2; | 65 public static final int TYPE_SHIPPING_OPTIONS = 2; |
66 public static final int TYPE_CONTACT_DETAILS = 3; | 66 public static final int TYPE_PAYER_INFO_DETAILS = 3; |
67 public static final int TYPE_PAYMENT_METHODS = 4; | 67 public static final int TYPE_PAYMENT_METHODS = 4; |
68 | 68 |
69 public static final int SELECTION_RESULT_ASYNCHRONOUS_VALIDATION = 1; | 69 public static final int SELECTION_RESULT_ASYNCHRONOUS_VALIDATION = 1; |
70 public static final int SELECTION_RESULT_EDITOR_LAUNCH = 2; | 70 public static final int SELECTION_RESULT_EDITOR_LAUNCH = 2; |
71 public static final int SELECTION_RESULT_NONE = 3; | 71 public static final int SELECTION_RESULT_NONE = 3; |
72 | 72 |
73 @Retention(RetentionPolicy.SOURCE) | 73 @Retention(RetentionPolicy.SOURCE) |
74 @IntDef({ | 74 @IntDef({ |
75 TYPE_SHIPPING_ADDRESSES, | 75 TYPE_SHIPPING_ADDRESSES, |
76 TYPE_SHIPPING_OPTIONS, | 76 TYPE_SHIPPING_OPTIONS, |
77 TYPE_CONTACT_DETAILS, | 77 TYPE_PAYER_INFO_DETAILS, |
78 TYPE_PAYMENT_METHODS | 78 TYPE_PAYMENT_METHODS |
79 }) | 79 }) |
80 public @interface DataType {} | 80 public @interface DataType {} |
81 | 81 |
82 @Retention(RetentionPolicy.SOURCE) | 82 @Retention(RetentionPolicy.SOURCE) |
83 @IntDef({ | 83 @IntDef({ |
84 SELECTION_RESULT_ASYNCHRONOUS_VALIDATION, | 84 SELECTION_RESULT_ASYNCHRONOUS_VALIDATION, |
85 SELECTION_RESULT_EDITOR_LAUNCH, | 85 SELECTION_RESULT_EDITOR_LAUNCH, |
86 SELECTION_RESULT_NONE, | 86 SELECTION_RESULT_NONE, |
87 }) | 87 }) |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 private static final int DIALOG_EXIT_ANIMATION_MS = 195; | 254 private static final int DIALOG_EXIT_ANIMATION_MS = 195; |
255 | 255 |
256 private static PaymentRequestObserverForTest sObserverForTest; | 256 private static PaymentRequestObserverForTest sObserverForTest; |
257 | 257 |
258 /** Notifies tests that the [PAY] button can be clicked. */ | 258 /** Notifies tests that the [PAY] button can be clicked. */ |
259 private final NotifierForTest mReadyToPayNotifierForTest; | 259 private final NotifierForTest mReadyToPayNotifierForTest; |
260 | 260 |
261 private final Context mContext; | 261 private final Context mContext; |
262 private final Client mClient; | 262 private final Client mClient; |
263 private final boolean mRequestShipping; | 263 private final boolean mRequestShipping; |
264 private final boolean mRequestContactDetails; | 264 private final boolean mRequestPayerInfoDetails; |
265 | 265 |
266 private final Dialog mDialog; | 266 private final Dialog mDialog; |
267 private final EditorView mEditorView; | 267 private final EditorView mEditorView; |
268 private final EditorView mCardEditorView; | 268 private final EditorView mCardEditorView; |
269 private final ViewGroup mFullContainer; | 269 private final ViewGroup mFullContainer; |
270 private final ViewGroup mRequestView; | 270 private final ViewGroup mRequestView; |
271 private final PaymentRequestUiErrorView mErrorView; | 271 private final PaymentRequestUiErrorView mErrorView; |
272 private final Callback<PaymentInformation> mUpdateSectionsCallback; | 272 private final Callback<PaymentInformation> mUpdateSectionsCallback; |
273 | 273 |
274 private ScrollView mPaymentContainer; | 274 private ScrollView mPaymentContainer; |
275 private LinearLayout mPaymentContainerLayout; | 275 private LinearLayout mPaymentContainerLayout; |
276 private DualControlLayout mButtonBar; | 276 private DualControlLayout mButtonBar; |
277 private Button mEditButton; | 277 private Button mEditButton; |
278 private Button mPayButton; | 278 private Button mPayButton; |
279 private View mCloseButton; | 279 private View mCloseButton; |
280 private View mSpinnyLayout; | 280 private View mSpinnyLayout; |
281 | 281 |
282 private LineItemBreakdownSection mOrderSummarySection; | 282 private LineItemBreakdownSection mOrderSummarySection; |
283 private ExtraTextSection mShippingSummarySection; | 283 private ExtraTextSection mShippingSummarySection; |
284 private OptionSection mShippingAddressSection; | 284 private OptionSection mShippingAddressSection; |
285 private OptionSection mShippingOptionSection; | 285 private OptionSection mShippingOptionSection; |
286 private OptionSection mContactDetailsSection; | 286 private OptionSection mPayerInfoDetailsSection; |
287 private OptionSection mPaymentMethodSection; | 287 private OptionSection mPaymentMethodSection; |
288 private List<SectionSeparator> mSectionSeparators; | 288 private List<SectionSeparator> mSectionSeparators; |
289 | 289 |
290 private PaymentRequestSection mSelectedSection; | 290 private PaymentRequestSection mSelectedSection; |
291 private boolean mIsShowingEditDialog; | 291 private boolean mIsShowingEditDialog; |
292 private boolean mIsProcessingPayClicked; | 292 private boolean mIsProcessingPayClicked; |
293 private boolean mIsClientClosing; | 293 private boolean mIsClientClosing; |
294 private boolean mIsClientCheckingSelection; | 294 private boolean mIsClientCheckingSelection; |
295 private boolean mIsShowingSpinner; | 295 private boolean mIsShowingSpinner; |
296 private boolean mIsEditingPaymentItem; | 296 private boolean mIsEditingPaymentItem; |
297 private boolean mIsClosing; | 297 private boolean mIsClosing; |
298 | 298 |
299 private SectionInformation mPaymentMethodSectionInformation; | 299 private SectionInformation mPaymentMethodSectionInformation; |
300 private SectionInformation mShippingAddressSectionInformation; | 300 private SectionInformation mShippingAddressSectionInformation; |
301 private SectionInformation mShippingOptionsSectionInformation; | 301 private SectionInformation mShippingOptionsSectionInformation; |
302 private SectionInformation mContactDetailsSectionInformation; | 302 private SectionInformation mPayerInfoDetailsSectionInformation; |
303 | 303 |
304 private Animator mSheetAnimator; | 304 private Animator mSheetAnimator; |
305 private FocusAnimator mSectionAnimator; | 305 private FocusAnimator mSectionAnimator; |
306 private int mAnimatorTranslation; | 306 private int mAnimatorTranslation; |
307 private boolean mIsInitialLayoutComplete; | 307 private boolean mIsInitialLayoutComplete; |
308 | 308 |
309 /** | 309 /** |
310 * Builds the UI for PaymentRequest. | 310 * Builds the UI for PaymentRequest. |
311 * | 311 * |
312 * @param activity The activity on top of which the UI should be disp
layed. | 312 * @param activity The activity on top of which the UI should be disp
layed. |
313 * @param client The consumer of the PaymentRequest UI. | 313 * @param client The consumer of the PaymentRequest UI. |
314 * @param requestShipping Whether the UI should show the shipping address an
d option selection. | 314 * @param requestShipping Whether the UI should show the shipping address an
d option selection. |
315 * @param requestContact Whether the UI should show the email address and p
hone number | 315 * @param requestPayerInfo Whether the UI should show the email address and
phone number |
316 * selection. | 316 * selection. |
317 * @param canAddCards Whether the UI should show the [+ADD CARD] button.
This can be false, | 317 * @param canAddCards Whether the UI should show the [+ADD CARD] button.
This can be false, |
318 * for example, when the merchant does not accept cre
dit cards, so | 318 * for example, when the merchant does not accept cre
dit cards, so |
319 * there's no point in adding cards within PaymentReq
uest UI. | 319 * there's no point in adding cards within PaymentReq
uest UI. |
320 * @param title The title to show at the top of the UI. This can b
e, for example, the | 320 * @param title The title to show at the top of the UI. This can b
e, for example, the |
321 * <title> of the merchant website. If the stri
ng is too long for | 321 * <title> of the merchant website. If the stri
ng is too long for |
322 * UI, it elides at the end. | 322 * UI, it elides at the end. |
323 * @param origin The origin (part of URL) to show under the title.
For example, | 323 * @param origin The origin (part of URL) to show under the title.
For example, |
324 * "https://shop.momandpop.com". If the origin is too
long for the UI, it | 324 * "https://shop.momandpop.com". If the origin is too
long for the UI, it |
325 * should elide according to: | 325 * should elide according to: |
326 * https://www.chromium.org/Home/chromium-security/enamel#TOC-Eliding-Origin
-Names-And-Hostnames | 326 * https://www.chromium.org/Home/chromium-security/enamel#TOC-Eliding-Origin
-Names-And-Hostnames |
327 */ | 327 */ |
328 public PaymentRequestUI(Activity activity, Client client, boolean requestShi
pping, | 328 public PaymentRequestUI(Activity activity, Client client, boolean requestShi
pping, |
329 boolean requestContact, boolean canAddCards, String title, String or
igin) { | 329 boolean requestPayerInfo, boolean canAddCards, String title, String
origin) { |
330 mContext = activity; | 330 mContext = activity; |
331 mClient = client; | 331 mClient = client; |
332 mRequestShipping = requestShipping; | 332 mRequestShipping = requestShipping; |
333 mRequestContactDetails = requestContact; | 333 mRequestPayerInfoDetails = requestPayerInfo; |
334 mAnimatorTranslation = activity.getResources().getDimensionPixelSize( | 334 mAnimatorTranslation = activity.getResources().getDimensionPixelSize( |
335 R.dimen.payments_ui_translation); | 335 R.dimen.payments_ui_translation); |
336 | 336 |
337 mErrorView = (PaymentRequestUiErrorView) LayoutInflater.from(mContext).i
nflate( | 337 mErrorView = (PaymentRequestUiErrorView) LayoutInflater.from(mContext).i
nflate( |
338 R.layout.payment_request_error, null); | 338 R.layout.payment_request_error, null); |
339 mErrorView.initialize(title, origin); | 339 mErrorView.initialize(title, origin); |
340 | 340 |
341 mReadyToPayNotifierForTest = new NotifierForTest(new Runnable() { | 341 mReadyToPayNotifierForTest = new NotifierForTest(new Runnable() { |
342 @Override | 342 @Override |
343 public void run() { | 343 public void run() { |
344 if (sObserverForTest != null && isAcceptingUserInput() && mPayBu
tton.isEnabled()) { | 344 if (sObserverForTest != null && isAcceptingUserInput() && mPayBu
tton.isEnabled()) { |
345 sObserverForTest.onPaymentRequestReadyToPay(PaymentRequestUI
.this); | 345 sObserverForTest.onPaymentRequestReadyToPay(PaymentRequestUI
.this); |
346 } | 346 } |
347 } | 347 } |
348 }); | 348 }); |
349 | 349 |
350 // This callback will be fired if mIsClientCheckingSelection is true. | 350 // This callback will be fired if mIsClientCheckingSelection is true. |
351 mUpdateSectionsCallback = new Callback<PaymentInformation>() { | 351 mUpdateSectionsCallback = new Callback<PaymentInformation>() { |
352 @Override | 352 @Override |
353 public void onResult(PaymentInformation result) { | 353 public void onResult(PaymentInformation result) { |
354 mIsClientCheckingSelection = false; | 354 mIsClientCheckingSelection = false; |
355 updateOrderSummarySection(result.getShoppingCart()); | 355 updateOrderSummarySection(result.getShoppingCart()); |
356 if (mRequestShipping) { | 356 if (mRequestShipping) { |
357 updateSection(TYPE_SHIPPING_ADDRESSES, result.getShippingAdd
resses()); | 357 updateSection(TYPE_SHIPPING_ADDRESSES, result.getShippingAdd
resses()); |
358 updateSection(TYPE_SHIPPING_OPTIONS, result.getShippingOptio
ns()); | 358 updateSection(TYPE_SHIPPING_OPTIONS, result.getShippingOptio
ns()); |
359 } | 359 } |
360 if (mRequestContactDetails) { | 360 if (mRequestPayerInfoDetails) { |
361 updateSection(TYPE_CONTACT_DETAILS, result.getContactDetails
()); | 361 updateSection(TYPE_PAYER_INFO_DETAILS, result.getPayerInfoDe
tails()); |
362 } | 362 } |
363 updateSection(TYPE_PAYMENT_METHODS, result.getPaymentMethods()); | 363 updateSection(TYPE_PAYMENT_METHODS, result.getPaymentMethods()); |
364 if (mShippingAddressSectionInformation.getSelectedItem() == null
) { | 364 if (mShippingAddressSectionInformation.getSelectedItem() == null
) { |
365 expand(mShippingAddressSection); | 365 expand(mShippingAddressSection); |
366 } else { | 366 } else { |
367 expand(null); | 367 expand(null); |
368 } | 368 } |
369 updatePayButtonEnabled(); | 369 updatePayButtonEnabled(); |
370 notifySelectionChecked(); | 370 notifySelectionChecked(); |
371 } | 371 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 mShippingSummarySection.setSummaryText( | 435 mShippingSummarySection.setSummaryText( |
436 selectedShippingAddress, selectedShippingName); | 436 selectedShippingAddress, selectedShippingName); |
437 mShippingSummarySection.setSummaryProperties( | 437 mShippingSummarySection.setSummaryProperties( |
438 TruncateAt.MIDDLE, true, null, true); | 438 TruncateAt.MIDDLE, true, null, true); |
439 | 439 |
440 // Indicate the shipping option below the address. | 440 // Indicate the shipping option below the address. |
441 mShippingSummarySection.setExtraText(selectedShippingOpt
ionLabel); | 441 mShippingSummarySection.setExtraText(selectedShippingOpt
ionLabel); |
442 } | 442 } |
443 } | 443 } |
444 | 444 |
445 if (mRequestContactDetails) { | 445 if (mRequestPayerInfoDetails) { |
446 updateSection(TYPE_CONTACT_DETAILS, result.getContactDetails
()); | 446 updateSection(TYPE_PAYER_INFO_DETAILS, result.getPayerInfoDe
tails()); |
447 } | 447 } |
448 | 448 |
449 updateSection(TYPE_PAYMENT_METHODS, result.getPaymentMethods()); | 449 updateSection(TYPE_PAYMENT_METHODS, result.getPaymentMethods()); |
450 updatePayButtonEnabled(); | 450 updatePayButtonEnabled(); |
451 | 451 |
452 // Hide the loading indicators and show the real sections. | 452 // Hide the loading indicators and show the real sections. |
453 mPaymentContainer.setVisibility(View.VISIBLE); | 453 mPaymentContainer.setVisibility(View.VISIBLE); |
454 mButtonBar.setVisibility(View.VISIBLE); | 454 mButtonBar.setVisibility(View.VISIBLE); |
455 mRequestView.removeView(mSpinnyLayout); | 455 mRequestView.removeView(mSpinnyLayout); |
456 mRequestView.addOnLayoutChangeListener(new SheetEnlargingAnimato
r(false)); | 456 mRequestView.addOnLayoutChangeListener(new SheetEnlargingAnimato
r(false)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 mPaymentContainerLayout = | 500 mPaymentContainerLayout = |
501 (LinearLayout) mRequestView.findViewById(R.id.payment_container_
layout); | 501 (LinearLayout) mRequestView.findViewById(R.id.payment_container_
layout); |
502 mOrderSummarySection = new LineItemBreakdownSection( | 502 mOrderSummarySection = new LineItemBreakdownSection( |
503 activity, activity.getString(R.string.payments_order_summary_lab
el), this); | 503 activity, activity.getString(R.string.payments_order_summary_lab
el), this); |
504 mShippingSummarySection = new ExtraTextSection( | 504 mShippingSummarySection = new ExtraTextSection( |
505 activity, activity.getString(R.string.payments_shipping_summary_
label), this); | 505 activity, activity.getString(R.string.payments_shipping_summary_
label), this); |
506 mShippingAddressSection = new OptionSection( | 506 mShippingAddressSection = new OptionSection( |
507 activity, activity.getString(R.string.payments_shipping_address_
label), this); | 507 activity, activity.getString(R.string.payments_shipping_address_
label), this); |
508 mShippingOptionSection = new OptionSection( | 508 mShippingOptionSection = new OptionSection( |
509 activity, activity.getString(R.string.payments_shipping_option_l
abel), this); | 509 activity, activity.getString(R.string.payments_shipping_option_l
abel), this); |
510 mContactDetailsSection = new OptionSection( | 510 mPayerInfoDetailsSection = new OptionSection( |
511 activity, activity.getString(R.string.payments_contact_details_l
abel), this); | 511 activity, activity.getString(R.string.payments_payer_info_detail
s_label), this); |
512 mPaymentMethodSection = new OptionSection( | 512 mPaymentMethodSection = new OptionSection( |
513 activity, activity.getString(R.string.payments_method_of_payment
_label), this); | 513 activity, activity.getString(R.string.payments_method_of_payment
_label), this); |
514 | 514 |
515 // Some sections conditionally allow adding new options. | 515 // Some sections conditionally allow adding new options. |
516 mShippingOptionSection.setCanAddItems(false); | 516 mShippingOptionSection.setCanAddItems(false); |
517 mPaymentMethodSection.setCanAddItems(canAddCards); | 517 mPaymentMethodSection.setCanAddItems(canAddCards); |
518 | 518 |
519 // Add the necessary sections to the layout. | 519 // Add the necessary sections to the layout. |
520 mPaymentContainerLayout.addView(mOrderSummarySection, new LinearLayout.L
ayoutParams( | 520 mPaymentContainerLayout.addView(mOrderSummarySection, new LinearLayout.L
ayoutParams( |
521 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); | 521 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); |
522 mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout)); | 522 mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout)); |
523 if (mRequestShipping) { | 523 if (mRequestShipping) { |
524 // The shipping breakout sections are only added if they are needed. | 524 // The shipping breakout sections are only added if they are needed. |
525 mPaymentContainerLayout.addView(mShippingSummarySection, new LinearL
ayout.LayoutParams( | 525 mPaymentContainerLayout.addView(mShippingSummarySection, new LinearL
ayout.LayoutParams( |
526 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); | 526 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); |
527 mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout)
); | 527 mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout)
); |
528 } | 528 } |
529 mPaymentContainerLayout.addView(mPaymentMethodSection, new LinearLayout.
LayoutParams( | 529 mPaymentContainerLayout.addView(mPaymentMethodSection, new LinearLayout.
LayoutParams( |
530 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); | 530 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); |
531 if (mRequestContactDetails) { | 531 if (mRequestPayerInfoDetails) { |
532 // Contact details are optional, depending on the merchant website. | 532 // Payer info details are optional, depending on the merchant websit
e. |
533 mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout)
); | 533 mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout)
); |
534 mPaymentContainerLayout.addView(mContactDetailsSection, new LinearLa
yout.LayoutParams( | 534 mPaymentContainerLayout.addView(mPayerInfoDetailsSection, new Linear
Layout.LayoutParams( |
535 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); | 535 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); |
536 } | 536 } |
537 mRequestView.addOnLayoutChangeListener(new FadeInAnimator()); | 537 mRequestView.addOnLayoutChangeListener(new FadeInAnimator()); |
538 mRequestView.addOnLayoutChangeListener(new PeekingAnimator()); | 538 mRequestView.addOnLayoutChangeListener(new PeekingAnimator()); |
539 | 539 |
540 // Enabled in updatePayButtonEnabled() when the user has selected all pa
yment options. | 540 // Enabled in updatePayButtonEnabled() when the user has selected all pa
yment options. |
541 mPayButton.setEnabled(false); | 541 mPayButton.setEnabled(false); |
542 } | 542 } |
543 | 543 |
544 /** | 544 /** |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 * | 616 * |
617 * @param section The shipping options. | 617 * @param section The shipping options. |
618 */ | 618 */ |
619 public void updateSection(@DataType int whichSection, SectionInformation sec
tion) { | 619 public void updateSection(@DataType int whichSection, SectionInformation sec
tion) { |
620 if (whichSection == TYPE_SHIPPING_ADDRESSES) { | 620 if (whichSection == TYPE_SHIPPING_ADDRESSES) { |
621 mShippingAddressSectionInformation = section; | 621 mShippingAddressSectionInformation = section; |
622 mShippingAddressSection.update(section); | 622 mShippingAddressSection.update(section); |
623 } else if (whichSection == TYPE_SHIPPING_OPTIONS) { | 623 } else if (whichSection == TYPE_SHIPPING_OPTIONS) { |
624 mShippingOptionsSectionInformation = section; | 624 mShippingOptionsSectionInformation = section; |
625 mShippingOptionSection.update(section); | 625 mShippingOptionSection.update(section); |
626 } else if (whichSection == TYPE_CONTACT_DETAILS) { | 626 } else if (whichSection == TYPE_PAYER_INFO_DETAILS) { |
627 mContactDetailsSectionInformation = section; | 627 mPayerInfoDetailsSectionInformation = section; |
628 mContactDetailsSection.update(section); | 628 mPayerInfoDetailsSection.update(section); |
629 } else if (whichSection == TYPE_PAYMENT_METHODS) { | 629 } else if (whichSection == TYPE_PAYMENT_METHODS) { |
630 mPaymentMethodSectionInformation = section; | 630 mPaymentMethodSectionInformation = section; |
631 mPaymentMethodSection.update(section); | 631 mPaymentMethodSection.update(section); |
632 } | 632 } |
633 mIsEditingPaymentItem = false; | 633 mIsEditingPaymentItem = false; |
634 updateSectionButtons(); | 634 updateSectionButtons(); |
635 updatePayButtonEnabled(); | 635 updatePayButtonEnabled(); |
636 } | 636 } |
637 | 637 |
638 @Override | 638 @Override |
639 public void onPaymentOptionChanged(final PaymentRequestSection section, Paym
entOption option) { | 639 public void onPaymentOptionChanged(final PaymentRequestSection section, Paym
entOption option) { |
640 @SelectionResult int result = SELECTION_RESULT_NONE; | 640 @SelectionResult int result = SELECTION_RESULT_NONE; |
641 if (section == mShippingAddressSection | 641 if (section == mShippingAddressSection |
642 && mShippingAddressSectionInformation.getSelectedItem() != optio
n) { | 642 && mShippingAddressSectionInformation.getSelectedItem() != optio
n) { |
643 mShippingAddressSectionInformation.setSelectedItem(option); | 643 mShippingAddressSectionInformation.setSelectedItem(option); |
644 result = mClient.onSectionOptionSelected( | 644 result = mClient.onSectionOptionSelected( |
645 TYPE_SHIPPING_ADDRESSES, option, mUpdateSectionsCallback); | 645 TYPE_SHIPPING_ADDRESSES, option, mUpdateSectionsCallback); |
646 } else if (section == mShippingOptionSection | 646 } else if (section == mShippingOptionSection |
647 && mShippingOptionsSectionInformation.getSelectedItem() != optio
n) { | 647 && mShippingOptionsSectionInformation.getSelectedItem() != optio
n) { |
648 mShippingOptionsSectionInformation.setSelectedItem(option); | 648 mShippingOptionsSectionInformation.setSelectedItem(option); |
649 result = mClient.onSectionOptionSelected( | 649 result = mClient.onSectionOptionSelected( |
650 TYPE_SHIPPING_OPTIONS, option, mUpdateSectionsCallback); | 650 TYPE_SHIPPING_OPTIONS, option, mUpdateSectionsCallback); |
651 } else if (section == mContactDetailsSection) { | 651 } else if (section == mPayerInfoDetailsSection) { |
652 mContactDetailsSectionInformation.setSelectedItem(option); | 652 mPayerInfoDetailsSectionInformation.setSelectedItem(option); |
653 result = mClient.onSectionOptionSelected(TYPE_CONTACT_DETAILS, optio
n, null); | 653 result = mClient.onSectionOptionSelected(TYPE_PAYER_INFO_DETAILS, op
tion, null); |
654 } else if (section == mPaymentMethodSection) { | 654 } else if (section == mPaymentMethodSection) { |
655 mPaymentMethodSectionInformation.setSelectedItem(option); | 655 mPaymentMethodSectionInformation.setSelectedItem(option); |
656 result = mClient.onSectionOptionSelected(TYPE_PAYMENT_METHODS, optio
n, null); | 656 result = mClient.onSectionOptionSelected(TYPE_PAYMENT_METHODS, optio
n, null); |
657 } | 657 } |
658 | 658 |
659 updateStateFromResult(section, result); | 659 updateStateFromResult(section, result); |
660 } | 660 } |
661 | 661 |
662 @Override | 662 @Override |
663 public void onAddPaymentOption(PaymentRequestSection section) { | 663 public void onAddPaymentOption(PaymentRequestSection section) { |
664 assert section != mShippingOptionSection; | 664 assert section != mShippingOptionSection; |
665 | 665 |
666 // There's no way to add new shipping options, so users adding an option
via the shipping | 666 // There's no way to add new shipping options, so users adding an option
via the shipping |
667 // summary's button have to be adding an address. Expand the sheet when
this happens so | 667 // summary's button have to be adding an address. Expand the sheet when
this happens so |
668 // that the shipping address section properly appears afterward. | 668 // that the shipping address section properly appears afterward. |
669 if (section == mShippingSummarySection) { | 669 if (section == mShippingSummarySection) { |
670 expand(null); | 670 expand(null); |
671 section = mShippingAddressSection; | 671 section = mShippingAddressSection; |
672 } | 672 } |
673 | 673 |
674 @SelectionResult int result = SELECTION_RESULT_NONE; | 674 @SelectionResult int result = SELECTION_RESULT_NONE; |
675 if (section == mShippingAddressSection) { | 675 if (section == mShippingAddressSection) { |
676 result = mClient.onSectionAddOption(TYPE_SHIPPING_ADDRESSES, mUpdate
SectionsCallback); | 676 result = mClient.onSectionAddOption(TYPE_SHIPPING_ADDRESSES, mUpdate
SectionsCallback); |
677 } else if (section == mContactDetailsSection) { | 677 } else if (section == mPayerInfoDetailsSection) { |
678 result = mClient.onSectionAddOption(TYPE_CONTACT_DETAILS, null); | 678 result = mClient.onSectionAddOption(TYPE_PAYER_INFO_DETAILS, null); |
679 } else if (section == mPaymentMethodSection) { | 679 } else if (section == mPaymentMethodSection) { |
680 result = mClient.onSectionAddOption(TYPE_PAYMENT_METHODS, null); | 680 result = mClient.onSectionAddOption(TYPE_PAYMENT_METHODS, null); |
681 } | 681 } |
682 | 682 |
683 updateStateFromResult(section, result); | 683 updateStateFromResult(section, result); |
684 } | 684 } |
685 | 685 |
686 void updateStateFromResult(PaymentRequestSection section, @SelectionResult i
nt result) { | 686 void updateStateFromResult(PaymentRequestSection section, @SelectionResult i
nt result) { |
687 mIsClientCheckingSelection = result == SELECTION_RESULT_ASYNCHRONOUS_VAL
IDATION; | 687 mIsClientCheckingSelection = result == SELECTION_RESULT_ASYNCHRONOUS_VAL
IDATION; |
688 mIsEditingPaymentItem = result == SELECTION_RESULT_EDITOR_LAUNCH; | 688 mIsEditingPaymentItem = result == SELECTION_RESULT_EDITOR_LAUNCH; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 PaymentRequestSection section = (PaymentRequestSection) v; | 733 PaymentRequestSection section = (PaymentRequestSection) v; |
734 if (section.getEditButtonState() != EDIT_BUTTON_GONE) return; | 734 if (section.getEditButtonState() != EDIT_BUTTON_GONE) return; |
735 } | 735 } |
736 | 736 |
737 if (v == mOrderSummarySection) { | 737 if (v == mOrderSummarySection) { |
738 expand(mOrderSummarySection); | 738 expand(mOrderSummarySection); |
739 } else if (v == mShippingSummarySection || v == mShippingAddressSection)
{ | 739 } else if (v == mShippingSummarySection || v == mShippingAddressSection)
{ |
740 expand(mShippingAddressSection); | 740 expand(mShippingAddressSection); |
741 } else if (v == mShippingOptionSection) { | 741 } else if (v == mShippingOptionSection) { |
742 expand(mShippingOptionSection); | 742 expand(mShippingOptionSection); |
743 } else if (v == mContactDetailsSection) { | 743 } else if (v == mPayerInfoDetailsSection) { |
744 expand(mContactDetailsSection); | 744 expand(mPayerInfoDetailsSection); |
745 } else if (v == mPaymentMethodSection) { | 745 } else if (v == mPaymentMethodSection) { |
746 expand(mPaymentMethodSection); | 746 expand(mPaymentMethodSection); |
747 } else if (v == mPayButton) { | 747 } else if (v == mPayButton) { |
748 processPayButton(); | 748 processPayButton(); |
749 } else if (v == mEditButton) { | 749 } else if (v == mEditButton) { |
750 if (mIsShowingEditDialog) { | 750 if (mIsShowingEditDialog) { |
751 dismissDialog(true); | 751 dismissDialog(true); |
752 } else { | 752 } else { |
753 expand(mOrderSummarySection); | 753 expand(mOrderSummarySection); |
754 } | 754 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 } else { | 833 } else { |
834 mRequestView.removeView(mSpinnyLayout); | 834 mRequestView.removeView(mSpinnyLayout); |
835 mRequestView.addView(mPaymentContainer); | 835 mRequestView.addView(mPaymentContainer); |
836 mRequestView.addView(mButtonBar); | 836 mRequestView.addView(mButtonBar); |
837 | 837 |
838 if (mIsShowingEditDialog) expand(mSelectedSection); | 838 if (mIsShowingEditDialog) expand(mSelectedSection); |
839 } | 839 } |
840 } | 840 } |
841 | 841 |
842 private void updatePayButtonEnabled() { | 842 private void updatePayButtonEnabled() { |
843 boolean contactInfoOk = !mRequestContactDetails | 843 boolean payerInfoOk = !mRequestPayerInfoDetails |
844 || (mContactDetailsSectionInformation != null | 844 || (mPayerInfoDetailsSectionInformation != null |
845 && mContactDetailsSectionInformation.getSelectedItem(
) != null); | 845 && mPayerInfoDetailsSectionInformation.getSelectedIte
m() != null); |
846 boolean shippingInfoOk = !mRequestShipping | 846 boolean shippingInfoOk = !mRequestShipping |
847 || (mShippingAddressSectionInformation != null | 847 || (mShippingAddressSectionInformation != null |
848 && mShippingAddressSectionInformation.getSelectedItem
() != null | 848 && mShippingAddressSectionInformation.getSelectedItem
() != null |
849 && mShippingOptionsSectionInformation != null | 849 && mShippingOptionsSectionInformation != null |
850 && mShippingOptionsSectionInformation.getSelectedItem
() != null); | 850 && mShippingOptionsSectionInformation.getSelectedItem
() != null); |
851 mPayButton.setEnabled(contactInfoOk && shippingInfoOk | 851 mPayButton.setEnabled(payerInfoOk && shippingInfoOk |
852 && mPaymentMethodSectionInformation != null | 852 && mPaymentMethodSectionInformation != null |
853 && mPaymentMethodSectionInformation.getSelectedItem() != null | 853 && mPaymentMethodSectionInformation.getSelectedItem() != null |
854 && !mIsClientCheckingSelection | 854 && !mIsClientCheckingSelection |
855 && !mIsEditingPaymentItem | 855 && !mIsEditingPaymentItem |
856 && !mIsClosing); | 856 && !mIsClosing); |
857 mReadyToPayNotifierForTest.run(); | 857 mReadyToPayNotifierForTest.run(); |
858 } | 858 } |
859 | 859 |
860 /** @return Whether or not the dialog can be closed via the X close button.
*/ | 860 /** @return Whether or not the dialog can be closed via the X close button.
*/ |
861 private boolean isAcceptingCloseButton() { | 861 private boolean isAcceptingCloseButton() { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 updateOrderSummarySection(result); | 922 updateOrderSummarySection(result); |
923 updateSectionVisibility(); | 923 updateSectionVisibility(); |
924 } | 924 } |
925 }); | 925 }); |
926 } else if (mSelectedSection == mShippingAddressSection) { | 926 } else if (mSelectedSection == mShippingAddressSection) { |
927 mClient.getSectionInformation( | 927 mClient.getSectionInformation( |
928 TYPE_SHIPPING_ADDRESSES, createUpdateSectionCallback(TYPE_SH
IPPING_ADDRESSES)); | 928 TYPE_SHIPPING_ADDRESSES, createUpdateSectionCallback(TYPE_SH
IPPING_ADDRESSES)); |
929 } else if (mSelectedSection == mShippingOptionSection) { | 929 } else if (mSelectedSection == mShippingOptionSection) { |
930 mClient.getSectionInformation( | 930 mClient.getSectionInformation( |
931 TYPE_SHIPPING_OPTIONS, createUpdateSectionCallback(TYPE_SHIP
PING_OPTIONS)); | 931 TYPE_SHIPPING_OPTIONS, createUpdateSectionCallback(TYPE_SHIP
PING_OPTIONS)); |
932 } else if (mSelectedSection == mContactDetailsSection) { | 932 } else if (mSelectedSection == mPayerInfoDetailsSection) { |
933 mClient.getSectionInformation( | 933 mClient.getSectionInformation( |
934 TYPE_CONTACT_DETAILS, createUpdateSectionCallback(TYPE_CONTA
CT_DETAILS)); | 934 TYPE_PAYER_INFO_DETAILS, createUpdateSectionCallback(TYPE_PA
YER_INFO_DETAILS)); |
935 } else if (mSelectedSection == mPaymentMethodSection) { | 935 } else if (mSelectedSection == mPaymentMethodSection) { |
936 mClient.getSectionInformation( | 936 mClient.getSectionInformation( |
937 TYPE_PAYMENT_METHODS, createUpdateSectionCallback(TYPE_PAYME
NT_METHODS)); | 937 TYPE_PAYMENT_METHODS, createUpdateSectionCallback(TYPE_PAYME
NT_METHODS)); |
938 } else { | 938 } else { |
939 updateSectionVisibility(); | 939 updateSectionVisibility(); |
940 } | 940 } |
941 } | 941 } |
942 | 942 |
943 private Callback<SectionInformation> createUpdateSectionCallback(@DataType f
inal int type) { | 943 private Callback<SectionInformation> createUpdateSectionCallback(@DataType f
inal int type) { |
944 return new Callback<SectionInformation>() { | 944 return new Callback<SectionInformation>() { |
945 @Override | 945 @Override |
946 public void onResult(SectionInformation result) { | 946 public void onResult(SectionInformation result) { |
947 updateSection(type, result); | 947 updateSection(type, result); |
948 updateSectionVisibility(); | 948 updateSectionVisibility(); |
949 } | 949 } |
950 }; | 950 }; |
951 } | 951 } |
952 | 952 |
953 /** Update the display status of each expandable section in the full dialog.
*/ | 953 /** Update the display status of each expandable section in the full dialog.
*/ |
954 private void updateSectionVisibility() { | 954 private void updateSectionVisibility() { |
955 startSectionResizeAnimation(); | 955 startSectionResizeAnimation(); |
956 mOrderSummarySection.focusSection(mSelectedSection == mOrderSummarySecti
on); | 956 mOrderSummarySection.focusSection(mSelectedSection == mOrderSummarySecti
on); |
957 mShippingAddressSection.focusSection(mSelectedSection == mShippingAddres
sSection); | 957 mShippingAddressSection.focusSection(mSelectedSection == mShippingAddres
sSection); |
958 mShippingOptionSection.focusSection(mSelectedSection == mShippingOptionS
ection); | 958 mShippingOptionSection.focusSection(mSelectedSection == mShippingOptionS
ection); |
959 mContactDetailsSection.focusSection(mSelectedSection == mContactDetailsS
ection); | 959 mPayerInfoDetailsSection.focusSection(mSelectedSection == mPayerInfoDeta
ilsSection); |
960 mPaymentMethodSection.focusSection(mSelectedSection == mPaymentMethodSec
tion); | 960 mPaymentMethodSection.focusSection(mSelectedSection == mPaymentMethodSec
tion); |
961 updateSectionButtons(); | 961 updateSectionButtons(); |
962 } | 962 } |
963 | 963 |
964 /** | 964 /** |
965 * Updates the enabled/disbled state of each section's edit button. | 965 * Updates the enabled/disbled state of each section's edit button. |
966 * | 966 * |
967 * Only the top-most button is enabled -- the others are disabled so the use
r is directed | 967 * Only the top-most button is enabled -- the others are disabled so the use
r is directed |
968 * through the form from top to bottom. | 968 * through the form from top to bottom. |
969 */ | 969 */ |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 public ViewGroup getShippingAddressSectionForTest() { | 1224 public ViewGroup getShippingAddressSectionForTest() { |
1225 return mShippingAddressSection; | 1225 return mShippingAddressSection; |
1226 } | 1226 } |
1227 | 1227 |
1228 @VisibleForTesting | 1228 @VisibleForTesting |
1229 public ViewGroup getPaymentMethodSectionForTest() { | 1229 public ViewGroup getPaymentMethodSectionForTest() { |
1230 return mPaymentMethodSection; | 1230 return mPaymentMethodSection; |
1231 } | 1231 } |
1232 | 1232 |
1233 @VisibleForTesting | 1233 @VisibleForTesting |
1234 public ViewGroup getContactDetailsSectionForTest() { | 1234 public ViewGroup getPayerInfoDetailsSectionForTest() { |
1235 return mContactDetailsSection; | 1235 return mPayerInfoDetailsSection; |
1236 } | 1236 } |
1237 | 1237 |
1238 private void notifyReadyForInput() { | 1238 private void notifyReadyForInput() { |
1239 if (sObserverForTest != null && isAcceptingUserInput()) { | 1239 if (sObserverForTest != null && isAcceptingUserInput()) { |
1240 sObserverForTest.onPaymentRequestReadyForInput(this); | 1240 sObserverForTest.onPaymentRequestReadyForInput(this); |
1241 } | 1241 } |
1242 } | 1242 } |
1243 | 1243 |
1244 private void notifySelectionChecked() { | 1244 private void notifySelectionChecked() { |
1245 if (sObserverForTest != null) { | 1245 if (sObserverForTest != null) { |
1246 sObserverForTest.onPaymentRequestSelectionChecked(this); | 1246 sObserverForTest.onPaymentRequestSelectionChecked(this); |
1247 } | 1247 } |
1248 } | 1248 } |
1249 } | 1249 } |
OLD | NEW |