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

Fix #3708: Content Description Generation For ImageRegionSelectionInteraction #5691

Merged
merged 25 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a3f7f9f
content description
manas-yu Feb 3, 2025
46f1de9
adding test
manas-yu Feb 3, 2025
31feeb7
update
manas-yu Feb 3, 2025
15564ff
test update
manas-yu Feb 4, 2025
8ff2c1e
formatting
manas-yu Feb 4, 2025
2a9ad09
Merge branch 'oppia:develop' into ImageRegionSelectionInteraction
manas-yu Feb 4, 2025
e3d5476
updates
manas-yu Feb 4, 2025
2489d0b
description update
manas-yu Feb 4, 2025
f8e03be
Merge branch 'develop' into ImageRegionSelectionInteraction
manas-yu Feb 7, 2025
486810d
Merge branch 'develop' into ImageRegionSelectionInteraction
manas-yu Feb 10, 2025
5ebab55
requested changes
manas-yu Feb 10, 2025
b6f204c
Merge branch 'ImageRegionSelectionInteraction' of github.com:manas-yu…
manas-yu Feb 10, 2025
5140363
ktlint
manas-yu Feb 10, 2025
db345d6
string update
manas-yu Feb 10, 2025
50d5eae
Merge branch 'develop' into ImageRegionSelectionInteraction
manas-yu Feb 11, 2025
61a8f48
revert
manas-yu Feb 12, 2025
e6c3f97
Merge branch 'develop' into ImageRegionSelectionInteraction
manas-yu Feb 13, 2025
c519e2c
Merge branch 'ImageRegionSelectionInteraction' of github.com:manas-yu…
manas-yu Feb 13, 2025
2c65061
Merge branch 'develop' into ImageRegionSelectionInteraction
manas-yu Feb 14, 2025
ca6377d
resourcehandler
manas-yu Feb 14, 2025
2157360
Merge branch 'ImageRegionSelectionInteraction' of github.com:manas-yu…
manas-yu Feb 14, 2025
6f56b11
string update
manas-yu Feb 17, 2025
0b47822
test update
manas-yu Feb 17, 2025
562164b
Merge branch 'develop' into ImageRegionSelectionInteraction
manas-yu Feb 17, 2025
ac8b83d
Merge branch 'develop' into ImageRegionSelectionInteraction
manas-yu Feb 17, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.fragment.app.FragmentManager
import org.oppia.android.app.model.ImageWithRegions
import org.oppia.android.app.model.UserAnswerState
import org.oppia.android.app.shim.ViewBindingShim
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.app.utility.ClickableAreasImage
import org.oppia.android.app.utility.OnClickableAreaClickedListener
import org.oppia.android.app.view.ViewComponentFactory
Expand Down Expand Up @@ -46,6 +47,7 @@ class ImageRegionSelectionInteractionView @JvmOverloads constructor(
@Inject lateinit var machineLocale: OppiaLocale.MachineLocale
@Inject lateinit var accessibilityService: AccessibilityService
@Inject lateinit var imageLoader: ImageLoader
@Inject lateinit var resourceHandler: AppLanguageResourceHandler

private lateinit var entityId: String
private lateinit var overlayView: FrameLayout
Expand All @@ -64,8 +66,8 @@ class ImageRegionSelectionInteractionView @JvmOverloads constructor(
maybeInitializeClickableAreas()
}

fun setUserAnswerState(userAnswerrState: UserAnswerState) {
this.userAnswerState = userAnswerrState
fun setUserAnswerState(userAnswerState: UserAnswerState) {
this.userAnswerState = userAnswerState
}

fun setEntityId(entityId: String) {
Expand Down Expand Up @@ -118,7 +120,8 @@ class ImageRegionSelectionInteractionView @JvmOverloads constructor(
::entityId.isInitialized &&
::imageUrl.isInitialized &&
::onRegionClicked.isInitialized &&
::overlayView.isInitialized
::overlayView.isInitialized &&
::resourceHandler.isInitialized
) {
loadImage()

Expand All @@ -129,7 +132,8 @@ class ImageRegionSelectionInteractionView @JvmOverloads constructor(
bindingInterface,
isAccessibilityEnabled = accessibilityService.isScreenReaderEnabled(),
clickableAreas,
userAnswerState
userAnswerState,
resourceHandler
)
areasImage.addRegionViews()
performAttachment(areasImage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.oppia.android.app.model.ImageWithRegions.LabeledRegion
import org.oppia.android.app.model.UserAnswerState
import org.oppia.android.app.player.state.ImageRegionSelectionInteractionView
import org.oppia.android.app.shim.ViewBindingShim
import org.oppia.android.app.translation.AppLanguageResourceHandler
import kotlin.math.roundToInt

/** Helper class to handle clicks on an image along with highlighting the selected region. */
Expand All @@ -23,7 +24,8 @@ class ClickableAreasImage(
bindingInterface: ViewBindingShim,
private val isAccessibilityEnabled: Boolean,
private val clickableAreas: List<LabeledRegion>,
userAnswerState: UserAnswerState
userAnswerState: UserAnswerState,
private val resourceHandler: AppLanguageResourceHandler
) {
private var imageLabel: String? = null
private val defaultRegionView by lazy { bindingInterface.getDefaultRegion(parentView) }
Expand Down Expand Up @@ -60,6 +62,16 @@ class ClickableAreasImage(
// Remove any previously selected region excluding 0th index(image view)
if (index > 0) {
childView.setBackgroundResource(0)
if (childView.tag != null) {
val regionLabel = childView.tag as String
clickableAreas.find { it.label == regionLabel }?.let { clickableArea ->
updateRegionContentDescription(
childView,
clickableArea,
regionLabel == imageLabel
)
}
}
}
}
}
Expand Down Expand Up @@ -112,8 +124,13 @@ class ClickableAreasImage(
newView.isFocusable = true
newView.isFocusableInTouchMode = true
newView.tag = clickableArea.label

val isInitiallySelected = clickableArea.label.equals(imageLabel)
updateRegionContentDescription(newView, clickableArea, isInitiallySelected)

newView.initializeToggleRegionTouchListener(clickableArea)
if (clickableArea.label.equals(imageLabel)) {

if (isInitiallySelected) {
showOrHideRegion(newView = newView, clickableArea = clickableArea)
}
if (isAccessibilityEnabled) {
Expand All @@ -123,7 +140,7 @@ class ClickableAreasImage(
showOrHideRegion(newView, clickableArea)
}
}
newView.contentDescription = clickableArea.contentDescription

parentView.addView(newView)
}

Expand All @@ -143,14 +160,18 @@ class ClickableAreasImage(
}

private fun showOrHideRegion(newView: View, clickableArea: LabeledRegion) {
resetRegionSelectionViews()
listener.onClickableAreaTouched(
NamedRegionClickedEvent(
clickableArea.label,
clickableArea.contentDescription
if (clickableArea.label != imageLabel) {
imageLabel = clickableArea.label
resetRegionSelectionViews()
newView.setBackgroundResource(R.drawable.selected_region_background)

listener.onClickableAreaTouched(
NamedRegionClickedEvent(
clickableArea.label,
generateContentDescription(clickableArea, true)
)
)
)
newView.setBackgroundResource(R.drawable.selected_region_background)
}
}

private fun View.initializeShowRegionTouchListener() {
Expand All @@ -172,4 +193,27 @@ class ClickableAreasImage(
return@setOnTouchListener true
}
}

private fun generateContentDescription(
clickableArea: LabeledRegion,
isSelected: Boolean
): String = if (isSelected) {
resourceHandler.getStringInLocaleWithWrapping(
R.string.selected_image_region_selection_content_description,
clickableArea.label
)
} else {
resourceHandler.getStringInLocaleWithWrapping(
R.string.unselected_image_region_selection_content_description,
clickableArea.label
)
}

private fun updateRegionContentDescription(
view: View,
clickableArea: LabeledRegion,
isSelected: Boolean
) {
view.contentDescription = generateContentDescription(clickableArea, isSelected)
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@
<string name="correct">Correct!</string>
<string name="topic_prefix">Topic: %s</string>
<string name="welcome_profile_name">%1$s %2$s!</string>
<string name="selected_image_region_selection_content_description">Image showing %1$s.</string>
<string name="unselected_image_region_selection_content_description">Select %1$s image.</string>
<plurals name="chapter_count">
<item quantity="one">1 Chapter</item>
<item quantity="other">%s Chapters</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withTagValue
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand Down Expand Up @@ -177,7 +178,7 @@ class ImageRegionSelectionInteractionViewTest {
assertThat(regionClickedEvent.value)
.isEqualTo(
NamedRegionClickedEvent(
regionLabel = "Region 3", contentDescription = "You have selected Region 3"
regionLabel = "Region 3", contentDescription = "Image showing Region 3."
)
)
}
Expand Down Expand Up @@ -218,12 +219,26 @@ class ImageRegionSelectionInteractionViewTest {
assertThat(regionClickedEvent.value)
.isEqualTo(
NamedRegionClickedEvent(
regionLabel = "Region 2", contentDescription = "You have selected Region 2"
regionLabel = "Region 2", contentDescription = "Image showing Region 2."
)
)
}
}

@Test
// TODO(#1611): Fix ImageRegionSelectionInteractionViewTest
@RunOn(TestPlatform.ESPRESSO)
fun testImageRegionSelectionInteractionView_initialContentDescriptionRegion3_isCorrect() {
launch(ImageRegionSelectionTestActivity::class.java).use {
onView(
allOf(
withTagValue(`is`("Region 3")),
withContentDescription("Select Region 3 image.")
)
).check(matches(isDisplayed()))
}
}

@Test
// TODO(#1611): Fix ImageRegionSelectionInteractionViewTest
@RunOn(TestPlatform.ESPRESSO)
Expand Down Expand Up @@ -280,7 +295,7 @@ class ImageRegionSelectionInteractionViewTest {
assertThat(regionClickedEvent.value)
.isEqualTo(
NamedRegionClickedEvent(
regionLabel = "Region 2", contentDescription = "You have selected Region 2"
regionLabel = "Region 2", contentDescription = "Image showing Region 2."
)
)
}
Expand Down Expand Up @@ -308,7 +323,7 @@ class ImageRegionSelectionInteractionViewTest {
assertThat(regionClickedEvent.value)
.isEqualTo(
NamedRegionClickedEvent(
regionLabel = "Region 3", contentDescription = "You have selected Region 3"
regionLabel = "Region 3", contentDescription = "Image showing Region 3."
)
)
}
Expand Down Expand Up @@ -352,7 +367,7 @@ class ImageRegionSelectionInteractionViewTest {
assertThat(regionClickedEvent.value)
.isEqualTo(
NamedRegionClickedEvent(
regionLabel = "Region 3", contentDescription = "You have selected Region 3"
regionLabel = "Region 3", contentDescription = "Image showing Region 3."
)
)
}
Expand Down Expand Up @@ -394,7 +409,7 @@ class ImageRegionSelectionInteractionViewTest {
assertThat(regionClickedEvent.value)
.isEqualTo(
NamedRegionClickedEvent(
regionLabel = "Region 2", contentDescription = "You have selected Region 2"
regionLabel = "Region 2", contentDescription = "Image showing Region 2."
)
)
}
Expand Down
Loading