Skip to content

Commit

Permalink
Add accessibility traversal rules on AddPaymentMethodActivity (#2083)
Browse files Browse the repository at this point in the history
Traverse to footer after payment method form
  • Loading branch information
mshafrir-stripe authored Jan 21, 2020
1 parent 5a3eefa commit 8787804
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions stripe/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<item type="id" name="stripe_default_reader_id" />
<item type="id" name="stripe_payment_methods_add_card" />
<item type="id" name="stripe_payment_methods_add_fpx" />
<item type="id" name="stripe_add_payment_method_form" />
<item type="id" name="stripe_add_payment_method_footer" />
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package com.stripe.android.view

import android.app.Activity
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.text.util.Linkify
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.core.text.util.LinkifyCompat
import androidx.core.view.ViewCompat
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.stripe.android.CustomerSession
Expand Down Expand Up @@ -47,7 +50,9 @@ class AddPaymentMethodActivity : StripeActivity() {
}

private val addPaymentMethodView: AddPaymentMethodView by lazy {
createPaymentMethodView(args)
createPaymentMethodView(args).also {
it.id = R.id.stripe_add_payment_method_form
}
}

private val customerSession: CustomerSession by lazy {
Expand Down Expand Up @@ -98,16 +103,12 @@ class AddPaymentMethodActivity : StripeActivity() {
val contentRoot: ViewGroup =
scrollView.findViewById(R.id.stripe_add_payment_method_content_root)
contentRoot.addView(addPaymentMethodView)

if (args.addPaymentMethodFooterLayoutId > 0) {
val footerView = layoutInflater.inflate(
args.addPaymentMethodFooterLayoutId, contentRoot, false
)
if (footerView is TextView) {
LinkifyCompat.addLinks(footerView, Linkify.ALL)
footerView.movementMethod = LinkMovementMethod.getInstance()
createFooterView(contentRoot)?.let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
addPaymentMethodView.accessibilityTraversalBefore = it.id
it.accessibilityTraversalAfter = addPaymentMethodView.id
}
contentRoot.addView(footerView)
contentRoot.addView(it)
}

setTitle(titleStringRes)
Expand All @@ -133,6 +134,25 @@ class AddPaymentMethodActivity : StripeActivity() {
}
}

private fun createFooterView(
contentRoot: ViewGroup
): View? {
return if (args.addPaymentMethodFooterLayoutId > 0) {
val footerView = layoutInflater.inflate(
args.addPaymentMethodFooterLayoutId, contentRoot, false
)
footerView.id = R.id.stripe_add_payment_method_footer
if (footerView is TextView) {
LinkifyCompat.addLinks(footerView, Linkify.ALL)
ViewCompat.enableAccessibleClickableSpanSupport(footerView)
footerView.movementMethod = LinkMovementMethod.getInstance()
}
footerView
} else {
null
}
}

public override fun onActionSave() {
createPaymentMethod(viewModel, addPaymentMethodView.createParams)
}
Expand Down

0 comments on commit 8787804

Please sign in to comment.