Commit d6dd515c authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[Autofill Assistant] Fork more of the payment request UI.

Before this change we only had a fork of the payment request logic, not
the UI underneath. This makes customizing the UI tricky without exposing larger
parts of the Payment Request UI to Autofill Assisatnt.

This patch tries to fork the PaymentRequestUI in a non invasive way. This
includes the java classes and the corresponding xml. We accept the potential
of being broken by changes in payments/ to non-forked parts and will fix that
on the Autofill Assistant side as needed and merge back later if that makes
sense.

As an example of how to customize the UI on the Autofill Assistant side, this
patch includes a customized PaymentRequestBottomBar (java and xml). The buttons
need more styling, which will be done in an upcoming change.

R=gogerald@chromium.org, twellington@chromium.org

    another use case. It should go away once we refactor the existing API
    and share more code.

Binary-Size: Increase is temporary due to a payment request UI reuse for
Bug: 806868
Change-Id: Iec801cc7d667e39c58e3604c0f62ea8289e90a1e
Reviewed-on: https://chromium-review.googlesource.com/c/1316730
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606401}
parent 33205a78
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!-- Autofill Assistant specific PaymentRequestUI dialog
Sits at the bottom of the screen like a Bottom Sheet.
-->
<org.chromium.chrome.browser.widget.BoundedLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/autofill_assistant_payment_request"
android:orientation="vertical"
android:gravity="center"
app:maxWidthLandscape="@dimen/payments_ui_max_dialog_width"
app:maxWidthPortrait="@dimen/payments_ui_max_dialog_width"
android:background="@android:color/white" >
<include layout="@layout/payment_request_header" />
<include layout="@layout/payment_request_spinny" />
<org.chromium.chrome.browser.widget.FadingEdgeScrollView
android:id="@+id/option_container"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:visibility="gone" >
<LinearLayout
android:id="@+id/payment_container_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</org.chromium.chrome.browser.widget.FadingEdgeScrollView>
<include layout="@layout/autofill_assistant_payment_request_bottom_bar" />
</org.chromium.chrome.browser.widget.BoundedLinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!-- Autofill Assistant specific bottom of the payment request UI. -->
<org.chromium.chrome.browser.autofill_assistant.ui.PaymentRequestBottomBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottom_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="@dimen/editor_dialog_section_large_spacing"
android:background="@android:color/white"
android:gravity="end"
android:orientation="horizontal"
android:visibility="gone" >
<!-- TODO(crbug.com/806868): Make the autofill assistant chip layouts into
styles and use those for these buttons.
-->
<org.chromium.ui.widget.ButtonCompat
android:id="@+id/button_secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="36dp"
android:text="@string/payments_edit_button"
style="@style/TextButton" />
<org.chromium.ui.widget.ButtonCompat
android:id="@+id/button_primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="36dp"
android:text="@string/payments_pay_button"
style="@style/FilledButton.Flat" />
</org.chromium.chrome.browser.autofill_assistant.ui.PaymentRequestBottomBar>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.payments;
package org.chromium.chrome.browser.autofill_assistant;
import android.content.Context;
import android.os.Handler;
......@@ -15,13 +15,21 @@ import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
import org.chromium.chrome.browser.favicon.FaviconHelper;
import org.chromium.chrome.browser.autofill_assistant.ui.PaymentRequestUI;
import org.chromium.chrome.browser.payments.AddressEditor;
import org.chromium.chrome.browser.payments.AutofillAddress;
import org.chromium.chrome.browser.payments.AutofillContact;
import org.chromium.chrome.browser.payments.AutofillPaymentApp;
import org.chromium.chrome.browser.payments.AutofillPaymentInstrument;
import org.chromium.chrome.browser.payments.BasicCardUtils;
import org.chromium.chrome.browser.payments.CardEditor;
import org.chromium.chrome.browser.payments.ContactEditor;
import org.chromium.chrome.browser.payments.ShippingStrings;
import org.chromium.chrome.browser.payments.ui.ContactDetailsSection;
import org.chromium.chrome.browser.payments.ui.PaymentInformation;
import org.chromium.chrome.browser.payments.ui.PaymentRequestUI;
import org.chromium.chrome.browser.payments.ui.PaymentRequestUI.Client;
import org.chromium.chrome.browser.payments.ui.SectionInformation;
import org.chromium.chrome.browser.payments.ui.ShoppingCart;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ssl.SecurityStateModel;
import org.chromium.chrome.browser.widget.prefeditor.Completable;
import org.chromium.chrome.browser.widget.prefeditor.EditableOption;
......@@ -43,7 +51,7 @@ import java.util.Map;
* TODO(crbug.com/806868): Refactor shared codes with PaymentRequestImpl to a common place when the
* UX is fixed.
*/
public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client {
public class AutofillAssistantPaymentRequest implements Client {
private static final String BASIC_CARD_PAYMENT_METHOD = "basic-card";
private static final Comparator<Completable> COMPLETENESS_COMPARATOR =
(a, b) -> (b.isComplete() ? 1 : 0) - (a.isComplete() ? 1 : 0);
......@@ -189,15 +197,6 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client
// 'Confirm'.
mUI.updatePayButtonText(R.string.autofill_assistant_payment_info_confirm);
final FaviconHelper faviconHelper = new FaviconHelper();
faviconHelper.getLocalFaviconImageForURL(Profile.getLastUsedProfile(),
mWebContents.getLastCommittedUrl(),
activity.getResources().getDimensionPixelSize(R.dimen.payments_favicon_size),
(bitmap, iconUrl) -> {
if (mUI != null && bitmap != null) mUI.setTitleBitmap(bitmap);
faviconHelper.destroy();
});
mAddressEditor.setEditorDialog(mUI.getEditorDialog());
mCardEditor.setEditorDialog(mUI.getCardEditorDialog());
if (mContactEditor != null) mContactEditor.setEditorDialog(mUI.getEditorDialog());
......
......@@ -15,7 +15,6 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.payments.AutofillAssistantPaymentRequest;
import org.chromium.chrome.browser.preferences.autofill_assistant.AutofillAssistantPreferences;
import org.chromium.chrome.browser.snackbar.SnackbarManager;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.autofill_assistant.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import org.chromium.chrome.autofill_assistant.R;
/** Autofill Assistant specific bottom bar for the payment request UI. */
public class PaymentRequestBottomBar extends LinearLayout {
private View mPrimaryButton;
private View mSecondaryButton;
/** Constructor for when the PaymentRequestBottomBar is inflated from XML. */
public PaymentRequestBottomBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mPrimaryButton = findViewById(R.id.button_primary);
mSecondaryButton = findViewById(R.id.button_secondary);
}
}
......@@ -36,8 +36,12 @@ import org.chromium.chrome.browser.widget.animation.AnimatorProperties;
* A fullscreen semitransparent dialog used for dimming Chrome when overlaying a bottom sheet
* dialog/CCT or an alert dialog on top of it. FLAG_DIM_BEHIND is not being used because it causes
* the web contents of a payment handler CCT to also dim on some versions of Android (e.g., Nougat).
*
* Note: Do not use this class outside of the payments.ui package!
* TODO(crbug.com/806868): Revert the visibility to package default again when it is no longer used
* by Autofill Assistant.
*/
/* package */ class DimmingDialog {
public class DimmingDialog {
/**
* Length of the animation to either show the UI or expand it to full height. Note that click of
* 'Pay' button in PaymentRequestUI is not accepted until the animation is done, so this
......@@ -60,8 +64,7 @@ import org.chromium.chrome.browser.widget.animation.AnimatorProperties;
* @param activity The activity on top of which the dialog should be displayed.
* @param dismissListener The listener for the dismissal of this dialog.
*/
/* package */ DimmingDialog(
Activity activity, DialogInterface.OnDismissListener dismissListener) {
public DimmingDialog(Activity activity, DialogInterface.OnDismissListener dismissListener) {
// To handle the specced animations, the dialog is entirely contained within a translucent
// FrameLayout. This could eventually be converted to a real BottomSheetDialog, but that
// requires exploration of how interactions would work when the dialog can be sent back and
......@@ -87,14 +90,14 @@ import org.chromium.chrome.browser.widget.animation.AnimatorProperties;
* Makes sure that the color of the icons in the status bar makes the icons visible.
* @param window The window whose status bar icon color is being set.
*/
/* package */ static void setVisibleStatusBarIconColor(Window window) {
public static void setVisibleStatusBarIconColor(Window window) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
ApiCompatibilityUtils.setStatusBarIconColor(window.getDecorView().getRootView(),
!ColorUtils.shouldUseLightForegroundOnBackground(window.getStatusBarColor()));
}
/** @param bottomSheetView The view to show in the bottom sheet. */
/* package */ void addBottomSheetView(View bottomSheetView) {
public void addBottomSheetView(View bottomSheetView) {
FrameLayout.LayoutParams bottomSheetParams =
new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
bottomSheetParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
......@@ -103,12 +106,12 @@ import org.chromium.chrome.browser.widget.animation.AnimatorProperties;
}
/** Show the dialog. */
/* package */ void show() {
public void show() {
mDialog.show();
}
/** Hide the dialog without dismissing it. */
/* package */ void hide() {
public void hide() {
mDialog.hide();
}
......@@ -117,7 +120,7 @@ import org.chromium.chrome.browser.widget.animation.AnimatorProperties;
*
* @param isAnimated If true, the dialog dismissal is animated.
*/
/* package */ void dismiss(boolean isAnimated) {
public void dismiss(boolean isAnimated) {
if (!mDialog.isShowing()) return;
if (isAnimated) {
new DisappearingAnimator(true);
......@@ -127,7 +130,7 @@ import org.chromium.chrome.browser.widget.animation.AnimatorProperties;
}
/** @param overlay The overlay to show. This can be an error dialog, for example. */
/* package */ void showOverlay(View overlay) {
public void showOverlay(View overlay) {
// Animate the bottom sheet going away.
new DisappearingAnimator(false);
......@@ -140,7 +143,7 @@ import org.chromium.chrome.browser.widget.animation.AnimatorProperties;
}
/** @return Whether the dialog is currently animating disappearance. */
/* package */ boolean isAnimatingDisappearance() {
public boolean isAnimatingDisappearance() {
return mIsAnimatingDisappearance;
}
......@@ -190,7 +193,7 @@ import org.chromium.chrome.browser.widget.animation.AnimatorProperties;
private class DisappearingAnimator extends AnimatorListenerAdapter {
private final boolean mIsDialogClosing;
/* package */ DisappearingAnimator(boolean removeDialog) {
public DisappearingAnimator(boolean removeDialog) {
mIsDialogClosing = removeDialog;
View child = mFullContainer.getChildAt(0);
......
......@@ -127,7 +127,7 @@ public abstract class PaymentRequestSection extends LinearLayout implements View
static final int DISPLAY_MODE_FOCUSED = 5;
/** Checking mode: Gray background, spinner overlay hides everything except the title. */
static final int DISPLAY_MODE_CHECKING = 6;
public static final int DISPLAY_MODE_CHECKING = 6;
protected final SectionDelegate mDelegate;
protected final int mLargeSpacing;
......
......@@ -619,15 +619,6 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
mErrorView.setBitmap(bitmap);
}
/**
* Update default text on the pay button to the given text.
*
* @param textResId The resource id of the text to be shown on the button.
*/
public void updatePayButtonText(int textResId) {
mPayButton.setText(textResId);
}
/**
* Updates the line items in response to a changed shipping address or option.
*
......
......@@ -118,9 +118,12 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/autofill/keyboard_accessory/PasswordAccessorySheetCoordinator.java",
"java/src/org/chromium/chrome/browser/autofill/keyboard_accessory/PasswordAccessorySheetViewBinder.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/AnimatedProgressBar.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantPaymentRequest.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantUiController.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/AutofillAssistantUiDelegate.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/InitScreenController.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/ui/PaymentRequestBottomBar.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/ui/PaymentRequestUI.java",
"java/src/org/chromium/chrome/browser/background_task_scheduler/NativeBackgroundTask.java",
"java/src/org/chromium/chrome/browser/banners/AppBannerManager.java",
"java/src/org/chromium/chrome/browser/banners/AppBannerUiDelegateAndroid.java",
......@@ -1144,7 +1147,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/payments/AutofillContact.java",
"java/src/org/chromium/chrome/browser/payments/AutofillPaymentApp.java",
"java/src/org/chromium/chrome/browser/payments/AutofillPaymentInstrument.java",
"java/src/org/chromium/chrome/browser/payments/AutofillAssistantPaymentRequest.java",
"java/src/org/chromium/chrome/browser/payments/BasicCardUtils.java",
"java/src/org/chromium/chrome/browser/payments/CanMakePaymentQuery.java",
"java/src/org/chromium/chrome/browser/payments/CardEditor.java",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment