Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add accessibility traversal rules on AddPaymentMethodActivity #2083

Merged
merged 1 commit into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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