From 69c9a2bd162d0b8c12eff184c21e809736ed4cf1 Mon Sep 17 00:00:00 2001 From: Vraj Desai <43074241+vrajdesai78@users.noreply.github.com> Date: Wed, 9 Nov 2022 22:40:30 +0530 Subject: [PATCH] Fixes #4586: Improve text scaling according to screen reader (#4695) ## Explanation Fixes #4586: Changed layout_width to sp instead of dp as per this [comment](https://github.com/oppia/oppia-android/issues/4586#issuecomment-1304039347). This actually solves the problem of text scaling. Improved text scaling by setting layout_height and layout_width to wrap_content and setting min_height = 48dp and min_width = 48dp (may vary in some cases). Introduced a tests which will make sure that width is set in SP not in DP. Note: In accessibility scanner it still shows to improve text scaling but visually or practically this solution looks accurate. ## Essential Checklist - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)). ## Screenshots For Mobile (Promoted Story Card) Default Fonts | Large Fonts :-------------------------:|:-------------------------: ![Screenshot from 2022-11-05 01-27-47](https://user-images.githubusercontent.com/43074241/200065857-3408aca5-7cac-484b-bef8-91aac6a35047.png) | ![Screenshot from 2022-11-05 01-28-36](https://user-images.githubusercontent.com/43074241/200065890-89013801-4b13-4fec-a53c-e77b802eedde.png) ![Screenshot from 2022-11-05 01-30-00](https://user-images.githubusercontent.com/43074241/200066086-30a9b533-5a29-4f86-919d-a0fdc3ab8e9b.png) | ![Screenshot from 2022-11-05 01-29-23](https://user-images.githubusercontent.com/43074241/200066127-8718ce6c-d22f-4d7d-96b4-9f2698bc3185.png) ## Screenshots for Tablet (Promoted Story Card) Default Fonts | Large Fonts :-------------------------:|:-------------------------: ![Screenshot from 2022-11-05 01-31-14](https://user-images.githubusercontent.com/43074241/200066306-d0ebedeb-af87-43e4-9509-a7a50e95d77e.png) | ![Screenshot from 2022-11-05 01-31-36](https://user-images.githubusercontent.com/43074241/200066339-6f52bd98-012a-42c7-ab44-ea6ca1593554.png) ![Screenshot from 2022-11-05 01-24-34](https://user-images.githubusercontent.com/43074241/200066489-10dcf823-b6bd-4704-9dba-9bdc6d0cf44e.png) | ![Screenshot from 2022-11-05 01-25-16](https://user-images.githubusercontent.com/43074241/200066530-6c43a78e-8465-4693-8cdf-7438b23e8b3a.png) Failing robolectric tests when we change the width in dp. ![Screenshot from 2022-11-07 14-39-57](https://user-images.githubusercontent.com/43074241/200274329-2040e1bc-ae14-465f-a0a2-3c562e53fb66.png) --- .../faq_single_activity.xml | 2 +- .../resume_lesson_fragment.xml | 9 ++--- .../main/res/layout-sw600dp/help_activity.xml | 7 ++-- .../res/layout-sw600dp/option_activity.xml | 3 +- .../res/layout-sw600dp/story_fragment.xml | 2 +- .../main/res/layout/admin_auth_activity.xml | 2 +- .../administrator_controls_activity.xml | 3 +- .../main/res/layout/app_language_activity.xml | 2 +- .../main/res/layout/app_version_activity.xml | 5 ++- .../res/layout/audio_language_activity.xml | 2 +- .../layout/completed_story_list_fragment.xml | 2 +- .../res/layout/developer_options_activity.xml | 3 +- .../main/res/layout/exploration_activity.xml | 3 +- .../main/res/layout/faq_single_activity.xml | 2 +- .../layout/force_network_type_fragment.xml | 3 +- app/src/main/res/layout/help_activity.xml | 3 +- .../layout/hints_and_solution_fragment.xml | 2 +- app/src/main/res/layout/home_activity.xml | 3 +- .../layout/license_text_viewer_activity.xml | 6 ++- .../mark_chapters_completed_fragment.xml | 3 +- .../mark_stories_completed_fragment.xml | 3 +- .../layout/mark_topics_completed_fragment.xml | 3 +- .../math_expression_parser_fragment.xml | 3 +- .../main/res/layout/my_downloads_fragment.xml | 3 +- .../layout/ongoing_topic_list_fragment.xml | 2 +- app/src/main/res/layout/option_activity.xml | 3 +- .../main/res/layout/pin_password_activity.xml | 4 +- .../layout/profile_and_device_id_activity.xml | 3 +- .../main/res/layout/profile_edit_activity.xml | 3 +- .../main/res/layout/profile_list_fragment.xml | 2 +- .../res/layout/profile_picture_activity.xml | 3 +- .../res/layout/profile_progress_header.xml | 11 +++-- .../res/layout/profile_rename_activity.xml | 2 +- .../res/layout/profile_reset_pin_activity.xml | 2 +- .../main/res/layout/promoted_story_card.xml | 4 -- .../res/layout/reading_text_size_activity.xml | 2 +- .../res/layout/revision_card_activity.xml | 2 +- app/src/main/res/layout/story_fragment.xml | 2 +- app/src/main/res/layout/topic_fragment.xml | 2 +- .../res/layout/topic_practice_footer_view.xml | 3 +- .../res/layout/view_event_logs_fragment.xml | 3 +- app/src/main/res/values/dimens.xml | 6 ++- app/src/main/res/values/styles.xml | 2 + .../android/app/home/HomeActivityTest.kt | 40 +++++++++++++++++++ 44 files changed, 121 insertions(+), 59 deletions(-) diff --git a/app/src/main/res/layout-sw600dp-land/faq_single_activity.xml b/app/src/main/res/layout-sw600dp-land/faq_single_activity.xml index 43e9dddbb6d..e37111661f0 100644 --- a/app/src/main/res/layout-sw600dp-land/faq_single_activity.xml +++ b/app/src/main/res/layout-sw600dp-land/faq_single_activity.xml @@ -19,7 +19,7 @@ + android:baselineAligned="false" + android:orientation="horizontal"> + android:layout_weight="1" + android:background="@color/component_color_resume_lesson_activity_background_color"> - diff --git a/app/src/main/res/layout-sw600dp/help_activity.xml b/app/src/main/res/layout-sw600dp/help_activity.xml index 6608535b50e..f39a382d510 100644 --- a/app/src/main/res/layout-sw600dp/help_activity.xml +++ b/app/src/main/res/layout-sw600dp/help_activity.xml @@ -43,10 +43,10 @@ android:background="@color/component_color_help_activity_background_color" android:contentDescription="@string/help_activity_back_arrow_description" android:padding="12dp" - app:srcCompat="@drawable/ic_arrow_back_black_24_dp" android:visibility="gone" app:layout_constraintStart_toEndOf="@id/multipane_guideline" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/ic_arrow_back_black_24_dp" /> diff --git a/app/src/main/res/layout-sw600dp/option_activity.xml b/app/src/main/res/layout-sw600dp/option_activity.xml index 767faf4a5dc..abb585e8a4c 100644 --- a/app/src/main/res/layout-sw600dp/option_activity.xml +++ b/app/src/main/res/layout-sw600dp/option_activity.xml @@ -87,9 +87,10 @@ diff --git a/app/src/main/res/layout-sw600dp/story_fragment.xml b/app/src/main/res/layout-sw600dp/story_fragment.xml index 2480192d109..66fb3c73a8c 100644 --- a/app/src/main/res/layout-sw600dp/story_fragment.xml +++ b/app/src/main/res/layout-sw600dp/story_fragment.xml @@ -28,7 +28,7 @@ diff --git a/app/src/main/res/layout/app_language_activity.xml b/app/src/main/res/layout/app_language_activity.xml index b4e0066560b..6667ff04848 100644 --- a/app/src/main/res/layout/app_language_activity.xml +++ b/app/src/main/res/layout/app_language_activity.xml @@ -18,7 +18,7 @@ diff --git a/app/src/main/res/layout/exploration_activity.xml b/app/src/main/res/layout/exploration_activity.xml index e8f070619a3..5da95d484d3 100755 --- a/app/src/main/res/layout/exploration_activity.xml +++ b/app/src/main/res/layout/exploration_activity.xml @@ -27,7 +27,7 @@ - diff --git a/app/src/main/res/layout/faq_single_activity.xml b/app/src/main/res/layout/faq_single_activity.xml index 76371a3dc8a..22bf7a86930 100644 --- a/app/src/main/res/layout/faq_single_activity.xml +++ b/app/src/main/res/layout/faq_single_activity.xml @@ -19,7 +19,7 @@ diff --git a/app/src/main/res/layout/hints_and_solution_fragment.xml b/app/src/main/res/layout/hints_and_solution_fragment.xml index 5226f9e0d13..161860f39a6 100644 --- a/app/src/main/res/layout/hints_and_solution_fragment.xml +++ b/app/src/main/res/layout/hints_and_solution_fragment.xml @@ -27,7 +27,7 @@ diff --git a/app/src/main/res/layout/license_text_viewer_activity.xml b/app/src/main/res/layout/license_text_viewer_activity.xml index 3c52db29068..868662524de 100644 --- a/app/src/main/res/layout/license_text_viewer_activity.xml +++ b/app/src/main/res/layout/license_text_viewer_activity.xml @@ -16,7 +16,7 @@ @@ -40,7 +42,7 @@ - + diff --git a/app/src/main/res/layout/mark_chapters_completed_fragment.xml b/app/src/main/res/layout/mark_chapters_completed_fragment.xml index e7bbd5fe6fb..fc5c60c372c 100644 --- a/app/src/main/res/layout/mark_chapters_completed_fragment.xml +++ b/app/src/main/res/layout/mark_chapters_completed_fragment.xml @@ -31,8 +31,9 @@ diff --git a/app/src/main/res/layout/pin_password_activity.xml b/app/src/main/res/layout/pin_password_activity.xml index 8819be7d779..36d3f8258c9 100644 --- a/app/src/main/res/layout/pin_password_activity.xml +++ b/app/src/main/res/layout/pin_password_activity.xml @@ -31,7 +31,7 @@ @@ -98,6 +98,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:fontFamily="sans-serif" + android:minWidth="60dp" android:text="@{Integer.toString(viewModel.ongoingTopicCount)}" android:textColor="@color/component_color_profile_progress_activity_stories_progress_text_color" android:textSize="24sp" /> @@ -105,9 +106,10 @@ @@ -153,9 +155,10 @@ diff --git a/app/src/main/res/layout/profile_rename_activity.xml b/app/src/main/res/layout/profile_rename_activity.xml index b1265610492..d3936c473c0 100644 --- a/app/src/main/res/layout/profile_rename_activity.xml +++ b/app/src/main/res/layout/profile_rename_activity.xml @@ -20,7 +20,7 @@ 12dp 60dp 60dp - 280dp 20dp 20dp 28dp @@ -541,7 +540,10 @@ 8dp 8dp - 280dp + + 280sp + + 280sp 16sp 8dp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 4a0e5f652aa..eebc151f544 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -414,6 +414,7 @@ wrap_content 12dp 12dp + 144dp @drawable/start_over_button_background sans-serif-medium @drawable/ic_start_over_24dp @@ -430,6 +431,7 @@ 4dp 12dp 12dp + 144dp @drawable/state_button_primary_background @drawable/ic_arrow_right_alt_24dp @color/color_def_white diff --git a/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt index bd0def48687..22973649017 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/home/HomeActivityTest.kt @@ -4,6 +4,7 @@ import android.app.Application import android.content.Context import android.content.Intent import android.content.res.Configuration +import android.util.TypedValue import android.view.View import android.widget.TextView import androidx.appcompat.app.AppCompatActivity @@ -52,6 +53,7 @@ import org.oppia.android.app.application.ApplicationInjectorProvider import org.oppia.android.app.application.ApplicationModule import org.oppia.android.app.application.ApplicationStartupListenerModule import org.oppia.android.app.application.testing.TestingBuildFlavorModule +import org.oppia.android.app.customview.LessonThumbnailImageView import org.oppia.android.app.devoptions.DeveloperOptionsModule import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity @@ -62,6 +64,7 @@ import org.oppia.android.app.model.OppiaLanguage.BRAZILIAN_PORTUGUESE_VALUE import org.oppia.android.app.model.OppiaLanguage.ENGLISH import org.oppia.android.app.model.OppiaLanguage.ENGLISH_VALUE import org.oppia.android.app.model.ProfileId +import org.oppia.android.app.model.ReadingTextSize import org.oppia.android.app.model.ScreenName import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule import org.oppia.android.app.profile.ProfileChooserActivity @@ -75,6 +78,7 @@ import org.oppia.android.app.topic.TopicActivity import org.oppia.android.app.translation.AppLanguageLocaleHandler import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule import org.oppia.android.app.translation.testing.TestActivityRecreator +import org.oppia.android.app.utility.FontScaleConfigurationUtil import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape import org.oppia.android.data.backends.gae.NetworkConfigProdModule import org.oppia.android.data.backends.gae.NetworkModule @@ -198,6 +202,9 @@ class HomeActivityTest { @Inject lateinit var dataProviderTestMonitor: DataProviderTestMonitor.Factory + @Inject + lateinit var fontScaleConfigurationUtil: FontScaleConfigurationUtil + private val internalProfileId: Int = 0 private val internalProfileId1: Int = 1 private val longNameInternalProfileId: Int = 3 @@ -893,6 +900,39 @@ class HomeActivityTest { } } + @Test + @RunOn(TestPlatform.ROBOLECTRIC) // TODO(#4700): Make this test work on Espresso. + fun testHomeActivity_promotedStoryHasScalableWidth() { + fontScaleConfigurationUtil.adjustFontScale(context, ReadingTextSize.EXTRA_LARGE_TEXT_SIZE) + fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS) + storyProgressTestHelper.markInProgressSavedFractionsStory0Exp0( + profileId = profileId1, + timestampOlderThanOneWeek = false + ) + logIntoUserTwice() + launch(createHomeActivityIntent(internalProfileId1)).use { + testCoroutineDispatchers.runCurrent() + scrollToPosition(position = 1) + onView( + atPositionOnView( + recyclerViewId = R.id.home_recycler_view, + position = 1, + targetViewId = R.id.promoted_story_list_recycler_view + ) + ).check { view, _ -> + val promotedStoryCard = + view.findViewById(R.id.lesson_thumbnail) + val promotedStoryCardWidth = promotedStoryCard?.width?.toFloat() + val expectedWidthInPixels = TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_SP, + 280F, + context.resources.displayMetrics + ) + assertThat(promotedStoryCardWidth).isWithin(1e-5f).of(expectedWidthInPixels) + } + } + } + @Test fun testHomeActivity_promotedCard_topicNameIsCorrect() { fakeOppiaClock.setFakeTimeMode(FakeOppiaClock.FakeTimeMode.MODE_UPTIME_MILLIS)