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 10 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 @@ -64,8 +64,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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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 +122,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 +138,7 @@ class ClickableAreasImage(
showOrHideRegion(newView, clickableArea)
}
}
newView.contentDescription = clickableArea.contentDescription

parentView.addView(newView)
}

Expand All @@ -143,14 +158,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 +191,22 @@ class ClickableAreasImage(
return@setOnTouchListener true
}
}

private fun generateContentDescription(
clickableArea: LabeledRegion,
isSelected: Boolean
): String {
if (isSelected) {
return "This is a ${clickableArea.label} image."
}
return "Select ${clickableArea.label} image."
}

private fun updateRegionContentDescription(
view: View,
clickableArea: LabeledRegion,
isSelected: Boolean
) {
view.contentDescription = generateContentDescription(clickableArea, isSelected)
}
}
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 = "This is a Region 3 image."
)
)
}
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 = "This is a Region 2 image."
)
)
}
}

@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 = "This is a Region 2 image."
)
)
}
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 = "This is a Region 3 image."
)
)
}
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 = "This is a Region 3 image."
)
)
}
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 = "This is a Region 2 image."
)
)
}
Expand Down
Loading