mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
a11y: add custom action to be able to close the alert.
This commit is contained in:
parent
fe3a41e4e9
commit
71a2a4d31a
@ -21,9 +21,11 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
|
||||
import androidx.core.view.ViewCompat
|
||||
import com.tapadoo.alerter.Alerter
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.platform.VectorBaseActivity
|
||||
import im.vector.app.core.resources.StringProvider
|
||||
import im.vector.app.core.utils.isAnimationEnabled
|
||||
import im.vector.app.features.MainActivity
|
||||
import im.vector.app.features.analytics.ui.consent.AnalyticsOptInActivity
|
||||
@ -46,6 +48,7 @@ import javax.inject.Singleton
|
||||
@Singleton
|
||||
class PopupAlertManager @Inject constructor(
|
||||
private val clock: Clock,
|
||||
private val stringProvider: StringProvider,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
@ -282,6 +285,9 @@ class PopupAlertManager @Inject constructor(
|
||||
}
|
||||
currentIsDismissed()
|
||||
}
|
||||
.setOnShowListener {
|
||||
handleAccessibility(activity)
|
||||
}
|
||||
.enableSwipeToDismiss()
|
||||
.enableInfiniteDuration(true)
|
||||
.apply {
|
||||
@ -297,6 +303,24 @@ class PopupAlertManager @Inject constructor(
|
||||
.show()
|
||||
}
|
||||
|
||||
/* a11y */
|
||||
private fun handleAccessibility(activity: Activity) {
|
||||
activity.window.decorView.findViewById<View>(R.id.llAlertBackground)?.let { alertView ->
|
||||
alertView.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_YES
|
||||
|
||||
// Add close action for a11y (same action than swipe). User can select the action by swiping on the screen vertically,
|
||||
// and double tap to perform the action
|
||||
ViewCompat.addAccessibilityAction(
|
||||
alertView,
|
||||
stringProvider.getString(R.string.action_close)
|
||||
) { _, _ ->
|
||||
currentIsDismissed()
|
||||
Alerter.hide()
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun currentIsDismissed() {
|
||||
// current alert has been hidden
|
||||
if (currentAlerter?.isLight == false) {
|
||||
|
Loading…
Reference in New Issue
Block a user