| 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 android.content.Context; | 7 import android.content.Context; |
| 8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.view.LayoutInflater; | 9 import android.view.LayoutInflater; |
| 10 import android.view.View; | 10 import android.view.View; |
| 11 import android.view.View.OnClickListener; | 11 import android.view.View.OnClickListener; |
| 12 import android.view.ViewGroup; | 12 import android.view.ViewGroup; |
| 13 import android.view.ViewGroup.MarginLayoutParams; | 13 import android.view.ViewGroup.MarginLayoutParams; |
| 14 import android.widget.ImageView; | 14 import android.widget.ImageView; |
| 15 import android.widget.TextView; | 15 import android.widget.TextView; |
| 16 | 16 |
| 17 import org.chromium.base.ApiCompatibilityUtils; | 17 import org.chromium.base.ApiCompatibilityUtils; |
| 18 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
| 19 import org.chromium.mojom.payments.PaymentComplete; |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * Displays the status of a payment request to the user. | 22 * Displays the status of a payment request to the user. |
| 22 */ | 23 */ |
| 23 public class PaymentResultUIManager { | 24 public class PaymentResultUIManager { |
| 24 private final ViewGroup mResultLayout; | 25 private final ViewGroup mResultLayout; |
| 25 | 26 |
| 26 /** | 27 /** |
| 27 * Constructs a UI that indicates the status of the payment request. | 28 * Constructs a UI that indicates the status of the payment request. |
| 28 * | 29 * |
| (...skipping 27 matching lines...) Expand all Loading... |
| 56 (MarginLayoutParams) pageInfoGroup.getLayoutParams(), titleEndMa
rgin); | 57 (MarginLayoutParams) pageInfoGroup.getLayoutParams(), titleEndMa
rgin); |
| 57 | 58 |
| 58 // Indicate that we're processing the data. | 59 // Indicate that we're processing the data. |
| 59 TextView messageView = (TextView) mResultLayout.findViewById(R.id.messag
e); | 60 TextView messageView = (TextView) mResultLayout.findViewById(R.id.messag
e); |
| 60 messageView.setText(R.string.payments_processing_message); | 61 messageView.setText(R.string.payments_processing_message); |
| 61 } | 62 } |
| 62 | 63 |
| 63 /** | 64 /** |
| 64 * Updates the UI to display whether or not the payment request was successf
ul. | 65 * Updates the UI to display whether or not the payment request was successf
ul. |
| 65 * | 66 * |
| 66 * @param paymentSuccess Whether or not the payment request was successful. | 67 * @param result Whether or not the payment request was successful. |
| 67 * @param callback Callback to run upon dismissal. | 68 * @param callback Callback to run upon dismissal. |
| 68 */ | 69 */ |
| 69 public void update(boolean paymentSuccess, final Runnable callback) { | 70 public void update(int result, final Runnable callback) { |
| 70 if (mResultLayout.getParent() == null || paymentSuccess) { | 71 if (mResultLayout.getParent() == null || result == PaymentComplete.UNKNO
WN |
| 72 || result == PaymentComplete.SUCCESS) { |
| 71 // Dismiss the dialog immediately. | 73 // Dismiss the dialog immediately. |
| 72 callback.run(); | 74 callback.run(); |
| 73 } else { | 75 } else { |
| 74 // Describe the error. | 76 // Describe the error. |
| 75 Context context = mResultLayout.getContext(); | 77 Context context = mResultLayout.getContext(); |
| 76 TextView resultMessage = (TextView) mResultLayout.findViewById(R.id.
message); | 78 TextView resultMessage = (TextView) mResultLayout.findViewById(R.id.
message); |
| 77 resultMessage.setText(context.getString(R.string.payments_error_mess
age)); | 79 resultMessage.setText(context.getString(R.string.payments_error_mess
age)); |
| 78 resultMessage.setTextColor(ApiCompatibilityUtils.getColor( | 80 resultMessage.setTextColor(ApiCompatibilityUtils.getColor( |
| 79 context.getResources(), R.color.error_text_color)); | 81 context.getResources(), R.color.error_text_color)); |
| 80 ApiCompatibilityUtils.setTextAlignment(resultMessage, View.TEXT_ALIG
NMENT_VIEW_START); | 82 ApiCompatibilityUtils.setTextAlignment(resultMessage, View.TEXT_ALIG
NMENT_VIEW_START); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 * TODO(dfalcantara): The dialog should listen for configuration changes and
resize accordingly. | 125 * TODO(dfalcantara): The dialog should listen for configuration changes and
resize accordingly. |
| 124 */ | 126 */ |
| 125 public static int computeMaxWidth(Context context, int availableWidth, int a
vailableHeight) { | 127 public static int computeMaxWidth(Context context, int availableWidth, int a
vailableHeight) { |
| 126 int baseUnit = context.getResources().getDimensionPixelSize(R.dimen.dial
og_width_unit); | 128 int baseUnit = context.getResources().getDimensionPixelSize(R.dimen.dial
og_width_unit); |
| 127 int maxSize = Math.min(availableWidth, availableHeight); | 129 int maxSize = Math.min(availableWidth, availableHeight); |
| 128 int multiplier = maxSize / baseUnit; | 130 int multiplier = maxSize / baseUnit; |
| 129 int floatingDialogWidth = multiplier * baseUnit; | 131 int floatingDialogWidth = multiplier * baseUnit; |
| 130 return floatingDialogWidth; | 132 return floatingDialogWidth; |
| 131 } | 133 } |
| 132 } | 134 } |
| OLD | NEW |