Skip to content

Commit

Permalink
Add support for TalkBack (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
cortinico authored Nov 2, 2024
1 parent 36a84a0 commit 588d959
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions slidetoact/src/main/java/com/ncorti/slidetoact/SlideToActView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.util.TypedValue
import android.view.MotionEvent
import android.view.View
import android.view.ViewOutlineProvider
import android.view.accessibility.AccessibilityNodeInfo
import android.view.animation.AnticipateOvershootInterpolator
import android.view.animation.OvershootInterpolator
import android.widget.TextView
Expand All @@ -34,6 +35,8 @@ import androidx.annotation.StyleRes
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.ViewCompat
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat
import androidx.core.widget.TextViewCompat
import com.ncorti.slidetoact.SlideToActIconUtil.createIconAnimator
import com.ncorti.slidetoact.SlideToActIconUtil.loadIconCompat
Expand Down Expand Up @@ -498,6 +501,29 @@ class SlideToActView
if (mStartBounceAnimation) {
startBounceAnimation(mBounceAnimationDuration, mBounceAnimationRepeat)
}

// Accessibility related setup
isClickable = true
accessibilityDelegate =
object : AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View,
info: AccessibilityNodeInfo,
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info.text = text
info.className = this::class.java.name
info.isClickable = true
}
}
ViewCompat.replaceAccessibilityAction(
this,
AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CLICK,
context.getString(R.string.slidetoact_accessibility_action_description),
) { _, _ ->
setCompleted(true, withAnimation = true)
true
}
}

override fun onMeasure(
Expand Down
3 changes: 2 additions & 1 deletion slidetoact/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
<string name="slidetoact_accessibility_action_description">Complete</string>
</resources>

0 comments on commit 588d959

Please sign in to comment.