| 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; |
| 11 import android.animation.AnimatorSet; | 11 import android.animation.AnimatorSet; |
| 12 import android.animation.ObjectAnimator; | 12 import android.animation.ObjectAnimator; |
| 13 import android.animation.ValueAnimator; | 13 import android.animation.ValueAnimator; |
| 14 import android.animation.ValueAnimator.AnimatorUpdateListener; | 14 import android.animation.ValueAnimator.AnimatorUpdateListener; |
| 15 import android.app.Activity; | 15 import android.app.Activity; |
| 16 import android.app.Dialog; | 16 import android.app.Dialog; |
| 17 import android.content.Context; | 17 import android.content.Context; |
| 18 import android.content.DialogInterface; | 18 import android.content.DialogInterface; |
| 19 import android.graphics.Bitmap; | 19 import android.graphics.Bitmap; |
| 20 import android.graphics.Color; | 20 import android.graphics.Color; |
| 21 import android.graphics.drawable.ColorDrawable; | 21 import android.graphics.drawable.ColorDrawable; |
| 22 import android.os.Handler; | 22 import android.os.Handler; |
| 23 import android.support.annotation.IntDef; | 23 import android.support.annotation.IntDef; |
| 24 import android.support.v4.view.animation.FastOutLinearInInterpolator; | 24 import android.support.v4.view.animation.FastOutLinearInInterpolator; |
| 25 import android.support.v4.view.animation.LinearOutSlowInInterpolator; | 25 import android.support.v4.view.animation.LinearOutSlowInInterpolator; |
| 26 import android.text.SpannableString; | 26 import android.text.SpannableString; |
| 27 import android.text.TextUtils; | 27 import android.text.TextUtils; |
| 28 import android.text.TextUtils.TruncateAt; | |
| 29 import android.text.method.LinkMovementMethod; | 28 import android.text.method.LinkMovementMethod; |
| 30 import android.view.Gravity; | 29 import android.view.Gravity; |
| 31 import android.view.LayoutInflater; | 30 import android.view.LayoutInflater; |
| 32 import android.view.View; | 31 import android.view.View; |
| 33 import android.view.View.OnLayoutChangeListener; | 32 import android.view.View.OnLayoutChangeListener; |
| 34 import android.view.ViewGroup; | 33 import android.view.ViewGroup; |
| 35 import android.view.ViewGroup.LayoutParams; | 34 import android.view.ViewGroup.LayoutParams; |
| 36 import android.view.Window; | 35 import android.view.Window; |
| 37 import android.widget.Button; | 36 import android.widget.Button; |
| 38 import android.widget.FrameLayout; | 37 import android.widget.FrameLayout; |
| 39 import android.widget.LinearLayout; | 38 import android.widget.LinearLayout; |
| 40 import android.widget.ScrollView; | 39 import android.widget.ScrollView; |
| 41 import android.widget.TextView; | 40 import android.widget.TextView; |
| 42 | 41 |
| 43 import org.chromium.base.ApiCompatibilityUtils; | 42 import org.chromium.base.ApiCompatibilityUtils; |
| 44 import org.chromium.base.Callback; | 43 import org.chromium.base.Callback; |
| 45 import org.chromium.base.VisibleForTesting; | 44 import org.chromium.base.VisibleForTesting; |
| 46 import org.chromium.chrome.R; | 45 import org.chromium.chrome.R; |
| 47 import org.chromium.chrome.browser.payments.ShippingStrings; | 46 import org.chromium.chrome.browser.payments.ShippingStrings; |
| 48 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.ExtraTextsS
ection; | |
| 49 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.LineItemBre
akdownSection; | 47 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.LineItemBre
akdownSection; |
| 50 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.OptionSecti
on; | 48 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.OptionSecti
on; |
| 51 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.SectionSepa
rator; | 49 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.SectionSepa
rator; |
| 50 import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.ShippingSum
marySection; |
| 52 import org.chromium.chrome.browser.widget.AlwaysDismissedDialog; | 51 import org.chromium.chrome.browser.widget.AlwaysDismissedDialog; |
| 53 import org.chromium.chrome.browser.widget.animation.AnimatorProperties; | 52 import org.chromium.chrome.browser.widget.animation.AnimatorProperties; |
| 54 import org.chromium.chrome.browser.widget.animation.FocusAnimator; | 53 import org.chromium.chrome.browser.widget.animation.FocusAnimator; |
| 55 import org.chromium.components.signin.ChromeSigninController; | 54 import org.chromium.components.signin.ChromeSigninController; |
| 56 import org.chromium.ui.text.NoUnderlineClickableSpan; | 55 import org.chromium.ui.text.NoUnderlineClickableSpan; |
| 57 import org.chromium.ui.text.SpanApplier; | 56 import org.chromium.ui.text.SpanApplier; |
| 58 import org.chromium.ui.text.SpanApplier.SpanInfo; | 57 import org.chromium.ui.text.SpanApplier.SpanInfo; |
| 59 import org.chromium.ui.widget.TextViewWithClickableSpans; | 58 import org.chromium.ui.widget.TextViewWithClickableSpans; |
| 60 | 59 |
| 61 import java.lang.annotation.Retention; | 60 import java.lang.annotation.Retention; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 314 |
| 316 private ScrollView mPaymentContainer; | 315 private ScrollView mPaymentContainer; |
| 317 private LinearLayout mPaymentContainerLayout; | 316 private LinearLayout mPaymentContainerLayout; |
| 318 private ViewGroup mBottomBar; | 317 private ViewGroup mBottomBar; |
| 319 private Button mEditButton; | 318 private Button mEditButton; |
| 320 private Button mPayButton; | 319 private Button mPayButton; |
| 321 private View mCloseButton; | 320 private View mCloseButton; |
| 322 private View mSpinnyLayout; | 321 private View mSpinnyLayout; |
| 323 | 322 |
| 324 private LineItemBreakdownSection mOrderSummarySection; | 323 private LineItemBreakdownSection mOrderSummarySection; |
| 325 private ExtraTextsSection mShippingSummarySection; | 324 private ShippingSummarySection mShippingSummarySection; |
| 326 private OptionSection mShippingAddressSection; | 325 private OptionSection mShippingAddressSection; |
| 327 private OptionSection mShippingOptionSection; | 326 private OptionSection mShippingOptionSection; |
| 328 private OptionSection mContactDetailsSection; | 327 private OptionSection mContactDetailsSection; |
| 329 private OptionSection mPaymentMethodSection; | 328 private OptionSection mPaymentMethodSection; |
| 330 private List<SectionSeparator> mSectionSeparators; | 329 private List<SectionSeparator> mSectionSeparators; |
| 331 | 330 |
| 332 private PaymentRequestSection mSelectedSection; | 331 private PaymentRequestSection mSelectedSection; |
| 333 private boolean mIsExpandedToFullHeight; | 332 private boolean mIsExpandedToFullHeight; |
| 334 private boolean mIsProcessingPayClicked; | 333 private boolean mIsProcessingPayClicked; |
| 335 private boolean mIsClientClosing; | 334 private boolean mIsClientClosing; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 mDialog.show(); | 455 mDialog.show(); |
| 457 mClient.getDefaultPaymentInformation(new Callback<PaymentInformation>()
{ | 456 mClient.getDefaultPaymentInformation(new Callback<PaymentInformation>()
{ |
| 458 @Override | 457 @Override |
| 459 public void onResult(PaymentInformation result) { | 458 public void onResult(PaymentInformation result) { |
| 460 updateOrderSummarySection(result.getShoppingCart()); | 459 updateOrderSummarySection(result.getShoppingCart()); |
| 461 | 460 |
| 462 if (mRequestShipping) { | 461 if (mRequestShipping) { |
| 463 updateSection(TYPE_SHIPPING_ADDRESSES, result.getShippingAdd
resses()); | 462 updateSection(TYPE_SHIPPING_ADDRESSES, result.getShippingAdd
resses()); |
| 464 updateSection(TYPE_SHIPPING_OPTIONS, result.getShippingOptio
ns()); | 463 updateSection(TYPE_SHIPPING_OPTIONS, result.getShippingOptio
ns()); |
| 465 | 464 |
| 466 String selectedShippingName = result.getSelectedShippingAddr
essLabel(); | 465 mShippingSummarySection.update(new ShippingSummaryInformatio
n( |
| 467 String selectedShippingAddress = result.getSelectedShippingA
ddressSublabel(); | 466 result.getShippingAddresses(), result.getShippingOpt
ions())); |
| 468 String selectedShippingPhone = result.getSelectedShippingAdd
ressTertiaryLabel(); | |
| 469 String selectedShippingOptionLabel = result.getSelectedShipp
ingOptionLabel(); | |
| 470 | 467 |
| 471 if (selectedShippingAddress == null || selectedShippingOptio
nLabel == null) { | 468 // Let the summary display a CHOOSE/ADD button for the first
subsection that |
| 472 // Let the summary display a SELECT/ADD button for the f
irst subsection | 469 // needs it. |
| 473 // that needs it. | 470 PaymentRequestSection section = |
| 474 mShippingSummarySection.setSummaryText(null, null); | 471 mShippingAddressSection.getEditButtonState() == EDIT
_BUTTON_GONE |
| 475 mShippingSummarySection.setSummaryProperties(null /* lef
tTruncate */, | 472 ? mShippingOptionSection |
| 476 false /* leftIsSingleLine */, null /* rightTrunc
ate */, | 473 : mShippingAddressSection; |
| 477 false /* rightIsSingleLine */); | 474 mShippingSummarySection.setEditButtonState(section.getEditBu
ttonState()); |
| 478 | |
| 479 PaymentRequestSection section = | |
| 480 mShippingAddressSection.getEditButtonState() ==
EDIT_BUTTON_GONE | |
| 481 ? mShippingOptionSection : mShippingAddr
essSection; | |
| 482 mShippingSummarySection.setEditButtonState(section.getEd
itButtonState()); | |
| 483 } else { | |
| 484 // Show the shipping name in the summary section. | |
| 485 mShippingSummarySection.setSummaryText(selectedShippingN
ame, null); | |
| 486 mShippingSummarySection.setSummaryProperties(TruncateAt.
END, | |
| 487 true /* leftIsSingleLine */, null /* rightTrunca
te */, | |
| 488 false /* rightIsSingleLine */); | |
| 489 | |
| 490 // Show the shipping address, phone and option below the
summary. | |
| 491 mShippingSummarySection.setExtraTexts(new String[] {sele
ctedShippingAddress, | |
| 492 selectedShippingPhone, selectedShippingOptionLab
el}); | |
| 493 mShippingSummarySection.setExtraTextsProperties( | |
| 494 new TruncateAt[] { | |
| 495 TruncateAt.MIDDLE, TruncateAt.END, Trunc
ateAt.END}, | |
| 496 new boolean[] {true, true, true}); | |
| 497 } | |
| 498 } | 475 } |
| 499 | 476 |
| 500 if (mRequestContactDetails) { | 477 if (mRequestContactDetails) { |
| 501 // Sets the summary of the contact displays in a single line
. | |
| 502 mContactDetailsSection.setSummaryProperties(TruncateAt.END, | |
| 503 true /* leftIsSingleLine */, null /* rightTruncate *
/, | |
| 504 false /* rightIsSingleLine */); | |
| 505 updateSection(TYPE_CONTACT_DETAILS, result.getContactDetails
()); | 478 updateSection(TYPE_CONTACT_DETAILS, result.getContactDetails
()); |
| 506 } | 479 } |
| 507 | 480 |
| 508 // Sets the summary of the payment method displays in a single l
ine. | |
| 509 mPaymentMethodSection.setSummaryProperties(TruncateAt.END, | |
| 510 true /* leftIsSingleLine */, null /* rightTruncate */, | |
| 511 false /* rightIsSingleLine */); | |
| 512 updateSection(TYPE_PAYMENT_METHODS, result.getPaymentMethods()); | 481 updateSection(TYPE_PAYMENT_METHODS, result.getPaymentMethods()); |
| 513 updatePayButtonEnabled(); | 482 updatePayButtonEnabled(); |
| 514 | 483 |
| 515 // Hide the loading indicators and show the real sections. | 484 // Hide the loading indicators and show the real sections. |
| 516 changeSpinnerVisibility(false); | 485 changeSpinnerVisibility(false); |
| 517 mRequestView.addOnLayoutChangeListener(new SheetEnlargingAnimato
r(false)); | 486 mRequestView.addOnLayoutChangeListener(new SheetEnlargingAnimato
r(false)); |
| 518 } | 487 } |
| 519 }); | 488 }); |
| 520 } | 489 } |
| 521 | 490 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 mEditButton.setOnClickListener(this); | 522 mEditButton.setOnClickListener(this); |
| 554 | 523 |
| 555 // Create all the possible sections. | 524 // Create all the possible sections. |
| 556 mSectionSeparators = new ArrayList<>(); | 525 mSectionSeparators = new ArrayList<>(); |
| 557 mPaymentContainer = (ScrollView) mRequestView.findViewById(R.id.option_c
ontainer); | 526 mPaymentContainer = (ScrollView) mRequestView.findViewById(R.id.option_c
ontainer); |
| 558 mPaymentContainerLayout = | 527 mPaymentContainerLayout = |
| 559 (LinearLayout) mRequestView.findViewById(R.id.payment_container_
layout); | 528 (LinearLayout) mRequestView.findViewById(R.id.payment_container_
layout); |
| 560 mOrderSummarySection = new LineItemBreakdownSection(context, | 529 mOrderSummarySection = new LineItemBreakdownSection(context, |
| 561 context.getString(R.string.payments_order_summary_label), this, | 530 context.getString(R.string.payments_order_summary_label), this, |
| 562 context.getString(R.string.payments_updated_label)); | 531 context.getString(R.string.payments_updated_label)); |
| 563 mShippingSummarySection = new ExtraTextsSection( | 532 mShippingSummarySection = new ShippingSummarySection( |
| 564 context, context.getString(mShippingStrings.getSummaryLabel()),
this); | 533 context, context.getString(mShippingStrings.getSummaryLabel()),
this); |
| 565 mShippingAddressSection = new OptionSection( | 534 mShippingAddressSection = new OptionSection( |
| 566 context, context.getString(mShippingStrings.getAddressLabel()),
this); | 535 context, context.getString(mShippingStrings.getAddressLabel()),
this); |
| 567 mShippingOptionSection = new OptionSection( | 536 mShippingOptionSection = new OptionSection( |
| 568 context, context.getString(mShippingStrings.getOptionLabel()), t
his); | 537 context, context.getString(mShippingStrings.getOptionLabel()), t
his); |
| 569 mContactDetailsSection = new OptionSection( | 538 mContactDetailsSection = new OptionSection( |
| 570 context, context.getString(R.string.payments_contact_details_lab
el), this); | 539 context, context.getString(R.string.payments_contact_details_lab
el), this); |
| 571 mPaymentMethodSection = new OptionSection( | 540 mPaymentMethodSection = new OptionSection( |
| 572 context, context.getString(R.string.payments_method_of_payment_l
abel), this); | 541 context, context.getString(R.string.payments_method_of_payment_l
abel), this); |
| 573 | 542 |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 // Switch the 'edit' button to a 'cancel' button. | 986 // Switch the 'edit' button to a 'cancel' button. |
| 1018 mEditButton.setText(mContext.getString(R.string.cancel)); | 987 mEditButton.setText(mContext.getString(R.string.cancel)); |
| 1019 | 988 |
| 1020 // Make the dialog take the whole screen. | 989 // Make the dialog take the whole screen. |
| 1021 mDialog.getWindow().setLayout( | 990 mDialog.getWindow().setLayout( |
| 1022 ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.
MATCH_PARENT); | 991 ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.
MATCH_PARENT); |
| 1023 | 992 |
| 1024 // Disable all but the first button. | 993 // Disable all but the first button. |
| 1025 updateSectionButtons(); | 994 updateSectionButtons(); |
| 1026 | 995 |
| 1027 // Sets the summary of the payment method and contact displays in mu
ltiple lines. | |
| 1028 mContactDetailsSection.setSummaryProperties(null /* leftTruncate */, | |
| 1029 false /* leftIsSingleLine */, null /* rightTruncate */, | |
| 1030 false /* rightIsSingleLine */); | |
| 1031 mPaymentMethodSection.setSummaryProperties(null /* leftTruncate */, | |
| 1032 false /* leftIsSingleLine */, null /* rightTruncate */, | |
| 1033 false /* rightIsSingleLine */); | |
| 1034 | |
| 1035 mIsExpandedToFullHeight = true; | 996 mIsExpandedToFullHeight = true; |
| 1036 } | 997 } |
| 1037 | 998 |
| 1038 // Update the section contents when they're selected. | 999 // Update the section contents when they're selected. |
| 1039 mSelectedSection = section; | 1000 mSelectedSection = section; |
| 1040 assert mSelectedSection != mShippingSummarySection; | 1001 assert mSelectedSection != mShippingSummarySection; |
| 1041 if (mSelectedSection == mOrderSummarySection) { | 1002 if (mSelectedSection == mOrderSummarySection) { |
| 1042 mClient.getShoppingCart(new Callback<ShoppingCart>() { | 1003 mClient.getShoppingCart(new Callback<ShoppingCart>() { |
| 1043 @Override | 1004 @Override |
| 1044 public void onResult(ShoppingCart result) { | 1005 public void onResult(ShoppingCart result) { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 sObserverForTest.onPaymentRequestReadyForInput(this); | 1370 sObserverForTest.onPaymentRequestReadyForInput(this); |
| 1410 } | 1371 } |
| 1411 } | 1372 } |
| 1412 | 1373 |
| 1413 private void notifySelectionChecked() { | 1374 private void notifySelectionChecked() { |
| 1414 if (sObserverForTest != null) { | 1375 if (sObserverForTest != null) { |
| 1415 sObserverForTest.onPaymentRequestSelectionChecked(this); | 1376 sObserverForTest.onPaymentRequestSelectionChecked(this); |
| 1416 } | 1377 } |
| 1417 } | 1378 } |
| 1418 } | 1379 } |
| OLD | NEW |