From 6e1b4b7b853fdc8a77d057a68fb92e384cd5e637 Mon Sep 17 00:00:00 2001 From: TanishMoral11 Date: Thu, 9 Jan 2025 05:39:26 +0530 Subject: [PATCH] fix-talback-focus --- .../OnboardingFragmentPresenterV1.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/src/main/java/org/oppia/android/app/onboarding/OnboardingFragmentPresenterV1.kt b/app/src/main/java/org/oppia/android/app/onboarding/OnboardingFragmentPresenterV1.kt index a10847e8c79..acf288298bd 100644 --- a/app/src/main/java/org/oppia/android/app/onboarding/OnboardingFragmentPresenterV1.kt +++ b/app/src/main/java/org/oppia/android/app/onboarding/OnboardingFragmentPresenterV1.kt @@ -6,6 +6,7 @@ import android.view.ViewGroup import android.widget.ImageView import android.widget.LinearLayout import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.accessibility.AccessibilityNodeInfoCompat import androidx.fragment.app.Fragment import androidx.viewpager2.widget.ViewPager2 import org.oppia.android.R @@ -81,6 +82,17 @@ class OnboardingFragmentPresenterV1 @Inject constructor( positionOffset: Float, positionOffsetPixels: Int ) { + if (positionOffsetPixels == 0 && position > 0) { + binding.onboardingSlideViewPager.apply { + contentDescription = getViewPagerContentAndDescription(position) + announceForAccessibility(contentDescription) + + performAccessibilityAction( + AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS, + null + ) + } + } } override fun onPageSelected(position: Int) { @@ -96,6 +108,24 @@ class OnboardingFragmentPresenterV1 @Inject constructor( }) } + private fun getViewPagerContentAndDescription(position: Int): String { + val slideTitle = when (position) { + 1 -> resourceHandler.getStringInLocale(R.string.onboarding_slide_1_title) + 2 -> resourceHandler.getStringInLocale(R.string.onboarding_slide_2_title) + 3 -> resourceHandler.getStringInLocale(R.string.onboarding_slide_3_title) + else -> "" + } + + val slideDescription = when (position) { + 1 -> resourceHandler.getStringInLocale(R.string.onboarding_slide_1_description) + 2 -> resourceHandler.getStringInLocale(R.string.onboarding_slide_2_description) + 3 -> resourceHandler.getStringInLocale(R.string.onboarding_slide_3_description) + else -> "" + } + + return "$slideTitle, $slideDescription" + } + private fun createViewPagerAdapter(): BindableAdapter { return multiTypeBuilderFactory.create { viewModel -> when (viewModel) {