diff --git a/example/src/main/java/com/stripe/example/activity/PaymentSessionActivity.kt b/example/src/main/java/com/stripe/example/activity/PaymentSessionActivity.kt index ae2db8d3901..52190fcbbdd 100644 --- a/example/src/main/java/com/stripe/example/activity/PaymentSessionActivity.kt +++ b/example/src/main/java/com/stripe/example/activity/PaymentSessionActivity.kt @@ -3,6 +3,7 @@ package com.stripe.example.activity import android.content.Intent import android.os.Bundle import android.view.View +import android.view.WindowManager import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import com.google.android.material.snackbar.Snackbar @@ -87,6 +88,7 @@ class PaymentSessionActivity : AppCompatActivity() { .setAllowedShippingCountryCodes(setOf("US", "CA")) .setShippingInformationValidator(ShippingInformationValidator()) .setShippingMethodsFactory(ShippingMethodsFactory()) + .setWindowFlags(WindowManager.LayoutParams.FLAG_SECURE) .setBillingAddressFields(BillingAddressFields.Full) .build(), savedInstanceState = savedInstanceState, diff --git a/stripe/src/main/java/com/stripe/android/PaymentSession.kt b/stripe/src/main/java/com/stripe/android/PaymentSession.kt index a9067584b68..27b44ca2c3a 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentSession.kt +++ b/stripe/src/main/java/com/stripe/android/PaymentSession.kt @@ -237,6 +237,7 @@ class PaymentSession @VisibleForTesting internal constructor( .setIsPaymentSessionActive(true) .setPaymentConfiguration(PaymentConfiguration.getInstance(context)) .setPaymentMethodTypes(config?.paymentMethodTypes.orEmpty()) + .setWindowFlags(config?.windowFlags) .setBillingAddressFields(config?.billingAddressFields ?: BillingAddressFields.None) .build() ) @@ -283,6 +284,7 @@ class PaymentSession @VisibleForTesting internal constructor( .setPaymentSessionConfig(config) .setPaymentSessionData(paymentSessionData) .setIsPaymentSessionActive(true) + .setWindowFlags(config?.windowFlags) .build() ) } diff --git a/stripe/src/main/java/com/stripe/android/PaymentSessionConfig.kt b/stripe/src/main/java/com/stripe/android/PaymentSessionConfig.kt index 1564f94ddab..6f2146afaa5 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentSessionConfig.kt +++ b/stripe/src/main/java/com/stripe/android/PaymentSessionConfig.kt @@ -35,7 +35,8 @@ data class PaymentSessionConfig internal constructor( val billingAddressFields: BillingAddressFields = BillingAddressFields.None, internal val shippingInformationValidator: ShippingInformationValidator? = null, - internal val shippingMethodsFactory: ShippingMethodsFactory? = null + internal val shippingMethodsFactory: ShippingMethodsFactory? = null, + internal val windowFlags: Int? = null ) : Parcelable { init { val countryCodes = Locale.getISOCountries() @@ -95,6 +96,7 @@ data class PaymentSessionConfig internal constructor( private var allowedShippingCountryCodes: Set = emptySet() private var shippingInformationValidator: ShippingInformationValidator? = null private var shippingMethodsFactory: ShippingMethodsFactory? = null + private var windowFlags: Int? = null @LayoutRes private var addPaymentMethodFooterLayoutId: Int = 0 @@ -191,6 +193,15 @@ data class PaymentSessionConfig internal constructor( this.allowedShippingCountryCodes = allowedShippingCountryCodes } + /** + * @param windowFlags optional flags to set on the `Window` object of Stripe Activities + * + * See [WindowManager.LayoutParams](https://developer.android.com/reference/android/view/WindowManager.LayoutParams) + */ + fun setWindowFlags(windowFlags: Int?): Builder = apply { + this.windowFlags = windowFlags + } + /** * @param shippingInformationValidator if specified, will be used to validate * [ShippingInformation] in [PaymentFlowActivity] instead of sending a broadcast with @@ -229,6 +240,7 @@ data class PaymentSessionConfig internal constructor( allowedShippingCountryCodes = allowedShippingCountryCodes, shippingInformationValidator = shippingInformationValidator, shippingMethodsFactory = shippingMethodsFactory, + windowFlags = windowFlags, billingAddressFields = billingAddressFields ) } diff --git a/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodActivity.kt b/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodActivity.kt index 9a102ee9c54..a70e75e05dd 100644 --- a/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodActivity.kt +++ b/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodActivity.kt @@ -89,6 +89,10 @@ class AddPaymentMethodActivity : StripeActivity() { } private fun configureView(args: AddPaymentMethodActivityStarter.Args) { + args.windowFlags?.let { + window.addFlags(it) + } + viewStub.layoutResource = R.layout.add_payment_method_layout val scrollView = viewStub.inflate() as ViewGroup val contentRoot: ViewGroup = diff --git a/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodActivityStarter.kt b/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodActivityStarter.kt index d46198f5871..a6b85c2b8b3 100644 --- a/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodActivityStarter.kt +++ b/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodActivityStarter.kt @@ -35,7 +35,8 @@ class AddPaymentMethodActivityStarter constructor( internal val shouldInitCustomerSessionTokens: Boolean, internal val paymentMethodType: PaymentMethod.Type, internal val paymentConfiguration: PaymentConfiguration?, - @LayoutRes internal val addPaymentMethodFooterLayoutId: Int + @LayoutRes internal val addPaymentMethodFooterLayoutId: Int, + internal val windowFlags: Int? = null ) : ActivityStarter.Args { class Builder : ObjectBuilder { @@ -48,6 +49,7 @@ class AddPaymentMethodActivityStarter constructor( private var paymentConfiguration: PaymentConfiguration? = null @LayoutRes private var addPaymentMethodFooterLayoutId: Int = 0 + private var windowFlags: Int? = null /** * If true, the created Payment Method will be attached to the current Customer @@ -99,6 +101,15 @@ class AddPaymentMethodActivityStarter constructor( this.addPaymentMethodFooterLayoutId = addPaymentMethodFooterLayoutId } + /** + * @param windowFlags optional flags to set on the `Window` object of Stripe Activities + * + * See [WindowManager.LayoutParams](https://developer.android.com/reference/android/view/WindowManager.LayoutParams) + */ + fun setWindowFlags(windowFlags: Int?): Builder = apply { + this.windowFlags = windowFlags + } + @JvmSynthetic internal fun setIsPaymentSessionActive( isPaymentSessionActive: Boolean @@ -129,7 +140,8 @@ class AddPaymentMethodActivityStarter constructor( shouldInitCustomerSessionTokens = shouldInitCustomerSessionTokens, paymentMethodType = paymentMethodType ?: PaymentMethod.Type.Card, paymentConfiguration = paymentConfiguration, - addPaymentMethodFooterLayoutId = addPaymentMethodFooterLayoutId + addPaymentMethodFooterLayoutId = addPaymentMethodFooterLayoutId, + windowFlags = windowFlags ) } } diff --git a/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodCardRowView.kt b/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodCardRowView.kt index 6752452fef8..9941102516b 100644 --- a/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodCardRowView.kt +++ b/stripe/src/main/java/com/stripe/android/view/AddPaymentMethodCardRowView.kt @@ -20,5 +20,6 @@ internal class AddPaymentMethodCardRowView internal constructor( .setPaymentMethodType(PaymentMethod.Type.Card) .setAddPaymentMethodFooter(args.addPaymentMethodFooterLayoutId) .setPaymentConfiguration(args.paymentConfiguration) + .setWindowFlags(args.windowFlags) .build() ) diff --git a/stripe/src/main/java/com/stripe/android/view/PaymentFlowActivity.kt b/stripe/src/main/java/com/stripe/android/view/PaymentFlowActivity.kt index bc8742ff8e0..bf48fc9ba9a 100644 --- a/stripe/src/main/java/com/stripe/android/view/PaymentFlowActivity.kt +++ b/stripe/src/main/java/com/stripe/android/view/PaymentFlowActivity.kt @@ -42,6 +42,7 @@ class PaymentFlowActivity : StripeActivity() { super.onCreate(savedInstanceState) val args = PaymentFlowActivityStarter.Args.create(intent) + args.windowFlags?.let { window.addFlags(it) } customerSession = CustomerSession.getInstance() customerSession.addProductUsageTokenIfValid(TOKEN_PAYMENT_SESSION) diff --git a/stripe/src/main/java/com/stripe/android/view/PaymentFlowActivityStarter.kt b/stripe/src/main/java/com/stripe/android/view/PaymentFlowActivityStarter.kt index a8aa7bd46ba..9102098e35b 100644 --- a/stripe/src/main/java/com/stripe/android/view/PaymentFlowActivityStarter.kt +++ b/stripe/src/main/java/com/stripe/android/view/PaymentFlowActivityStarter.kt @@ -23,12 +23,14 @@ class PaymentFlowActivityStarter : data class Args internal constructor( internal val paymentSessionConfig: PaymentSessionConfig, internal val paymentSessionData: PaymentSessionData, - internal val isPaymentSessionActive: Boolean + internal val isPaymentSessionActive: Boolean, + internal val windowFlags: Int? = null ) : ActivityStarter.Args { class Builder : ObjectBuilder { private var paymentSessionConfig: PaymentSessionConfig? = null private var paymentSessionData: PaymentSessionData? = null private var isPaymentSessionActive = false + private var windowFlags: Int? = null fun setPaymentSessionConfig( paymentSessionConfig: PaymentSessionConfig? @@ -44,6 +46,15 @@ class PaymentFlowActivityStarter : this.isPaymentSessionActive = isPaymentSessionActive } + /** + * @param windowFlags optional flags to set on the `Window` object of Stripe Activities + * + * See [WindowManager.LayoutParams](https://developer.android.com/reference/android/view/WindowManager.LayoutParams) + */ + fun setWindowFlags(windowFlags: Int?): Builder = apply { + this.windowFlags = windowFlags + } + override fun build(): Args { return Args( paymentSessionConfig = paymentSessionConfig @@ -51,7 +62,8 @@ class PaymentFlowActivityStarter : paymentSessionData = requireNotNull(paymentSessionData) { "PaymentFlowActivity launched without PaymentSessionData" }, - isPaymentSessionActive = isPaymentSessionActive + isPaymentSessionActive = isPaymentSessionActive, + windowFlags = windowFlags ) } } diff --git a/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivity.kt b/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivity.kt index 6a6e2f72f6e..72d6c82438c 100644 --- a/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivity.kt +++ b/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivity.kt @@ -51,6 +51,10 @@ class PaymentMethodsActivity : AppCompatActivity() { PaymentMethodsViewModel.Factory(customerSession, args.initialPaymentMethodId) )[PaymentMethodsViewModel::class.java] + args.windowFlags?.let { + window.addFlags(it) + } + startedFromPaymentSession = args.isPaymentSessionActive cardDisplayTextFactory = CardDisplayTextFactory.create(this) diff --git a/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivityStarter.kt b/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivityStarter.kt index ae881a6c060..8e880f84fdf 100644 --- a/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivityStarter.kt +++ b/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivityStarter.kt @@ -45,6 +45,7 @@ class PaymentMethodsActivityStarter : ActivityStarter, internal val paymentConfiguration: PaymentConfiguration?, + internal val windowFlags: Int? = null, internal val billingAddressFields: BillingAddressFields ) : ActivityStarter.Args { class Builder : ObjectBuilder { @@ -56,6 +57,7 @@ class PaymentMethodsActivityStarter : ActivityStarter