@ -15,7 +15,9 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import mozilla.components.browser.toolbar.BrowserToolbar
import org.mozilla.fenix.R
import android.animation.ValueAnimator
import android.view.accessibility.AccessibilityManager
import android.os.Bundle
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import org.mozilla.fenix.utils.Settings
@ -39,23 +41,13 @@ class QuickActionSheet @JvmOverloads constructor(
val handle = findViewById < AppCompatImageButton > ( R . id . quick _action _sheet _handle )
val linearLayout = findViewById < LinearLayout > ( R . id . quick _action _sheet )
val quickActionSheetBehavior = BottomSheetBehavior . from ( linearLayout . parent as View ) as QuickActionSheetBehavior
val accessibilityManager = context
. getSystemService ( Context . ACCESSIBILITY _SERVICE ) as AccessibilityManager
if ( accessibilityManager . isTouchExplorationEnabled ) {
linearLayout . setOnClickListener {
quickActionSheetBehavior . state = when ( quickActionSheetBehavior . state ) {
BottomSheetBehavior . STATE _EXPANDED -> BottomSheetBehavior . STATE _COLLAPSED
else -> BottomSheetBehavior . STATE _EXPANDED
}
}
return
}
handle . setOnClickListener {
bounceSheet ( quickActionSheetBehavior )
}
handle . setAccessibilityDelegate ( HandleAccessibilityDelegate ( quickActionSheetBehavior ) )
val settings = Settings . getInstance ( context )
if ( settings . shouldAutoBounceQuickActionSheet ) {
settings . incrementAutomaticBounceQuickActionSheetCount ( )
@ -87,6 +79,53 @@ class QuickActionSheet @JvmOverloads constructor(
}
}
class HandleAccessibilityDelegate (
private val quickActionSheetBehavior : QuickActionSheetBehavior
) : View . AccessibilityDelegate ( ) {
private var finalState = BottomSheetBehavior . STATE _COLLAPSED
get ( ) = when ( quickActionSheetBehavior . state ) {
BottomSheetBehavior . STATE _EXPANDED ,
BottomSheetBehavior . STATE _HIDDEN ,
BottomSheetBehavior . STATE _COLLAPSED -> {
quickActionSheetBehavior . state
}
else -> field
}
set ( value ) {
field = value
quickActionSheetBehavior . state = value
}
override fun performAccessibilityAction ( host : View ? , action : Int , args : Bundle ? ) : Boolean {
when ( action ) {
AccessibilityNodeInfo . ACTION _CLICK -> {
finalState = when ( quickActionSheetBehavior . state ) {
BottomSheetBehavior . STATE _EXPANDED -> BottomSheetBehavior . STATE _COLLAPSED
else -> BottomSheetBehavior . STATE _EXPANDED
}
}
AccessibilityNodeInfo . ACTION _COLLAPSE ->
finalState = BottomSheetBehavior . STATE _COLLAPSED
AccessibilityNodeInfo . ACTION _EXPAND ->
finalState = BottomSheetBehavior . STATE _EXPANDED
else -> return super . performAccessibilityAction ( host , action , args )
}
host ?. sendAccessibilityEvent ( AccessibilityEvent . TYPE _VIEW _CLICKED )
return true
}
override fun onInitializeAccessibilityNodeInfo ( host : View ? , info : AccessibilityNodeInfo ? ) {
super . onInitializeAccessibilityNodeInfo ( host , info )
info ?. addAction ( when ( finalState ) {
BottomSheetBehavior . STATE _COLLAPSED ,
BottomSheetBehavior . STATE _HIDDEN -> AccessibilityNodeInfo . AccessibilityAction . ACTION _EXPAND
else -> AccessibilityNodeInfo . AccessibilityAction . ACTION _COLLAPSE
} )
}
}
companion object {
const val demoBounceAnimationLength = 600L
const val bounceAnimationLength = 400L