diff --git a/WORKSPACE b/WORKSPACE index 0c20dcd36a1..231078d0d6e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -125,9 +125,9 @@ git_repository( # to correctly size in-line SVGs (such as those needed for LaTeX-based math expressions). git_repository( name = "androidsvg", - commit = "1265eb1087056cf3fc2e10442e5545bc65c109ce", + commit = "5bc9c7553e94c3476e8ea32baea3c77567228fcd", remote = "https://github.com/oppia/androidsvg", - shallow_since = "1686302944 -0700", + shallow_since = "1686304726 -0700", ) git_repository( diff --git a/app/build.gradle b/app/build.gradle index 71b759c6475..72dbb1d3cff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,6 +23,7 @@ android { includeCompileClasspath true } } + vectorDrawables { useSupportLibrary true } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/app/src/main/java/org/oppia/android/app/customview/ContinueButtonView.kt b/app/src/main/java/org/oppia/android/app/customview/ContinueButtonView.kt index bd3e44d8865..dd599820187 100644 --- a/app/src/main/java/org/oppia/android/app/customview/ContinueButtonView.kt +++ b/app/src/main/java/org/oppia/android/app/customview/ContinueButtonView.kt @@ -11,8 +11,6 @@ import org.oppia.android.app.utility.lifecycle.LifecycleSafeTimerFactory import org.oppia.android.app.view.ViewComponentFactory import org.oppia.android.app.view.ViewComponentImpl import org.oppia.android.domain.oppialogger.OppiaLogger -import org.oppia.android.util.platformparameter.EnableContinueButtonAnimation -import org.oppia.android.util.platformparameter.PlatformParameterValue import org.oppia.android.util.system.OppiaClock import javax.inject.Inject @@ -25,12 +23,14 @@ class ContinueButtonView @JvmOverloads constructor( defStyleAttr: Int = R.style.StateButtonActive ) : androidx.appcompat.widget.AppCompatButton(context, attrs, defStyleAttr) { - @field:[Inject EnableContinueButtonAnimation] - lateinit var enableContinueButtonAnimation: PlatformParameterValue - @Inject lateinit var fragment: Fragment - @Inject lateinit var oppiaClock: OppiaClock - @Inject lateinit var lifecycleSafeTimerFactory: LifecycleSafeTimerFactory - @Inject lateinit var oppiaLogger: OppiaLogger + @Inject + lateinit var fragment: Fragment + @Inject + lateinit var oppiaClock: OppiaClock + @Inject + lateinit var lifecycleSafeTimerFactory: LifecycleSafeTimerFactory + @Inject + lateinit var oppiaLogger: OppiaLogger private var shouldAnimateContinueButtonLateinit: Boolean? = null private val shouldAnimateContinueButton: Boolean @@ -119,13 +119,11 @@ class ContinueButtonView @JvmOverloads constructor( private fun startAnimating() { val animation = AnimationUtils.loadAnimation(context, R.anim.wobble_button_animation) - if (enableContinueButtonAnimation.value) { - startAnimation(animation) - // Repeat the animation after a fixed interval. - lifecycleSafeTimerFactory.createTimer(INTERVAL_BETWEEN_CONTINUE_BUTTON_ANIM_MS) - .observe(fragment) { - startAnimating() - } - } + startAnimation(animation) + // Repeat the animation after a fixed interval. + lifecycleSafeTimerFactory.createTimer(INTERVAL_BETWEEN_CONTINUE_BUTTON_ANIM_MS) + .observe(fragment) { + startAnimating() + } } } diff --git a/app/src/main/res/layout/audio_fragment.xml b/app/src/main/res/layout/audio_fragment.xml index d849e51c03c..20ca0081c0e 100755 --- a/app/src/main/res/layout/audio_fragment.xml +++ b/app/src/main/res/layout/audio_fragment.xml @@ -36,6 +36,20 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> + + @color/color_palette_concept_card_toolbar_color @color/color_palette_audio_fragment_background_color + @color/color_palette_icon_background_secondary_color @color/color_palette_icon_background_secondary_color @color/color_palette_seekbar_progress_background_color @color/color_palette_seekbar_thumb_shadow_color diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 4361dce5674..65e5ca43e22 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -8,8 +8,6 @@ 12dp 1000 1000 - 8dp - 28dp 24dp 4dp 18dp @@ -769,4 +767,10 @@ 28dp 32dp 8dp + + + 8dp + 28dp + 20dp + 3dp diff --git a/app/src/sharedTest/java/org/oppia/android/app/player/exploration/ExplorationActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/player/exploration/ExplorationActivityTest.kt index 27c75850e7d..e1cce42d8f3 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/player/exploration/ExplorationActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/player/exploration/ExplorationActivityTest.kt @@ -226,7 +226,6 @@ class ExplorationActivityTest { @Before fun setUp() { Intents.init() - TestPlatformParameterModule.forceEnableContinueButtonAnimation(false) setUpTestApplicationComponent() testCoroutineDispatchers.registerIdlingResource() profileTestHelper.initializeProfiles() @@ -1071,7 +1070,7 @@ class ExplorationActivityTest { onView(withId(R.id.action_audio_player)).perform(click()) testCoroutineDispatchers.runCurrent() - onView(withId(R.id.play_pause_audio_icon)).check(matches(isDisplayed())) + onView(withId(R.id.audio_bar_container)).check(matches(isDisplayed())) onView(withText(context.getString(R.string.cellular_data_alert_dialog_title))) .check(doesNotExist()) } @@ -1295,6 +1294,43 @@ class ExplorationActivityTest { explorationDataController.stopPlayingExploration(isCompletion = false) } + @Test + fun testExplorationActivity_loadingAudio_progressbarIsDisplayed() { + markAllSpotlightsSeen() + setUpAudio() + launch( + createExplorationActivityIntent( + internalProfileId, + RATIOS_TOPIC_ID, + RATIOS_STORY_ID_0, + RATIOS_EXPLORATION_ID_0, + shouldSavePartialProgress = false + ) + ).use { + explorationDataController.startPlayingNewExploration( + internalProfileId, + RATIOS_TOPIC_ID, + RATIOS_STORY_ID_0, + RATIOS_EXPLORATION_ID_0 + ) + networkConnectionUtil.setCurrentConnectionStatus(ProdConnectionStatus.LOCAL) + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.action_audio_player)).perform(click()) + + testCoroutineDispatchers.runCurrent() + onView(withId(R.id.audio_bar_container)).check(matches(isDisplayed())) + onView(withId(R.id.audio_fragment_voiceover_progressbar)).check(matches(isDisplayed())) + + waitForTheView(withDrawable(R.drawable.ic_pause_circle_filled_white_24dp)) + onView(withId(R.id.play_pause_audio_icon)).check( + matches( + withDrawable(R.drawable.ic_pause_circle_filled_white_24dp) + ) + ) + } + explorationDataController.stopPlayingExploration(isCompletion = false) + } + // TODO(#89): Check this test case too. It works in pair with below test cases. @Test fun testExpActivity_showUnsavedExpDialog_cancel_dismissesDialog() { diff --git a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt index 02dfe4b1731..24ac673be8d 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/player/state/StateFragmentTest.kt @@ -4749,7 +4749,6 @@ class StateFragmentTest { } private fun setUpTest() { - TestPlatformParameterModule.forceEnableContinueButtonAnimation(false) Intents.init() setUpTestApplicationComponent() testCoroutineDispatchers.registerIdlingResource() diff --git a/app/src/test/java/org/oppia/android/app/player/state/StateFragmentLocalTest.kt b/app/src/test/java/org/oppia/android/app/player/state/StateFragmentLocalTest.kt index 1153c881562..a90c507ad4b 100644 --- a/app/src/test/java/org/oppia/android/app/player/state/StateFragmentLocalTest.kt +++ b/app/src/test/java/org/oppia/android/app/player/state/StateFragmentLocalTest.kt @@ -269,7 +269,6 @@ class StateFragmentLocalTest { @Test fun testContinueInteractionAnim_openPrototypeExp_checkContinueButtonAnimatesAfter45Seconds() { - TestPlatformParameterModule.forceEnableContinueButtonAnimation(true) launchForExploration(TEST_EXPLORATION_ID_2).use { startPlayingExploration() testCoroutineDispatchers.runCurrent() @@ -339,7 +338,6 @@ class StateFragmentLocalTest { @Test fun testConIntAnim_openProtExp_orientLandscapeAfter30Sec_checkAnimHasNotStarted() { - TestPlatformParameterModule.forceEnableContinueButtonAnimation(true) launchForExploration(TEST_EXPLORATION_ID_2).use { startPlayingExploration() @@ -353,7 +351,6 @@ class StateFragmentLocalTest { @Test fun testConIntAnim_openProtExp_orientLandAfter30Sec_checkAnimStartsIn15SecAfterOrientChange() { - TestPlatformParameterModule.forceEnableContinueButtonAnimation(true) launchForExploration(TEST_EXPLORATION_ID_2).use { startPlayingExploration() @@ -368,7 +365,6 @@ class StateFragmentLocalTest { @Test fun testContNavBtnAnim_openMathExp_checkContNavBtnAnimatesAfter45Seconds() { - TestPlatformParameterModule.forceEnableContinueButtonAnimation(true) launchForExploration(TEST_EXPLORATION_ID_5).use { startPlayingExploration() onView(withId(R.id.state_recycler_view)).perform( @@ -391,7 +387,6 @@ class StateFragmentLocalTest { @Ignore("Continue navigation animation behavior fails during testing") @Test fun testContNavBtnAnim_openMathExp_playThroughSecondState_checkContBtnDoesNotAnimateAfter45Sec() { - TestPlatformParameterModule.forceEnableContinueButtonAnimation(true) launchForExploration(TEST_EXPLORATION_ID_5).use { startPlayingExploration() onView(withId(R.id.state_recycler_view)).perform( @@ -424,7 +419,6 @@ class StateFragmentLocalTest { @Ignore("Continue navigation animation behavior fails during testing") @Test fun testConIntAnim_openFractions_expId1_checkButtonDoesNotAnimate() { - TestPlatformParameterModule.forceEnableContinueButtonAnimation(true) launchForExploration(TEST_EXPLORATION_ID_2).use { startPlayingExploration() playThroughTestState1() diff --git a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaKenyaModule.kt b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaKenyaModule.kt index 1b3293d56f5..6adc922bc11 100644 --- a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaKenyaModule.kt +++ b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaKenyaModule.kt @@ -8,7 +8,6 @@ import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING_DEFAULT_VALUE import org.oppia.android.util.platformparameter.CacheLatexRendering import org.oppia.android.util.platformparameter.ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE -import org.oppia.android.util.platformparameter.ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE @@ -18,7 +17,6 @@ import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLE import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation -import org.oppia.android.util.platformparameter.EnableContinueButtonAnimation import org.oppia.android.util.platformparameter.EnableDownloadsSupport import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi import org.oppia.android.util.platformparameter.EnableExtraTopicTabsUi @@ -215,14 +213,6 @@ class PlatformParameterAlphaKenyaModule { ) } - @Provides - @EnableContinueButtonAnimation - fun provideEnableContinueButtonAnimation(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( - ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE - ) - } - @Provides @EnableSpotlightUi fun enableSpotlightUi(): PlatformParameterValue { diff --git a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaModule.kt b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaModule.kt index 8addae7b9fd..7ca4dcc66b0 100644 --- a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaModule.kt +++ b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterAlphaModule.kt @@ -8,7 +8,6 @@ import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING_DEFAULT_VALUE import org.oppia.android.util.platformparameter.CacheLatexRendering import org.oppia.android.util.platformparameter.ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE -import org.oppia.android.util.platformparameter.ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE @@ -17,7 +16,6 @@ import org.oppia.android.util.platformparameter.ENABLE_LANGUAGE_SELECTION_UI_DEF import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation -import org.oppia.android.util.platformparameter.EnableContinueButtonAnimation import org.oppia.android.util.platformparameter.EnableDownloadsSupport import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi import org.oppia.android.util.platformparameter.EnableExtraTopicTabsUi @@ -216,14 +214,6 @@ class PlatformParameterAlphaModule { ) } - @Provides - @EnableContinueButtonAnimation - fun provideEnableContinueButtonAnimation(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( - ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE - ) - } - @Provides @EnableAppAndOsDeprecation fun provideEnableAppAndOsDeprecation(): PlatformParameterValue { diff --git a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterModule.kt b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterModule.kt index c2a211472fc..26e25bd3590 100644 --- a/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterModule.kt +++ b/domain/src/main/java/org/oppia/android/domain/platformparameter/PlatformParameterModule.kt @@ -8,7 +8,6 @@ import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING_DEFAULT_VALUE import org.oppia.android.util.platformparameter.CacheLatexRendering import org.oppia.android.util.platformparameter.ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE -import org.oppia.android.util.platformparameter.ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE @@ -18,7 +17,6 @@ import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLE import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_SPOTLIGHT_UI_DEFAULT_VALUE import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation -import org.oppia.android.util.platformparameter.EnableContinueButtonAnimation import org.oppia.android.util.platformparameter.EnableDownloadsSupport import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi import org.oppia.android.util.platformparameter.EnableExtraTopicTabsUi @@ -221,14 +219,6 @@ class PlatformParameterModule { ) } - @Provides - @EnableContinueButtonAnimation - fun provideEnableContinueButtonAnimation(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( - ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE - ) - } - @Provides @EnableAppAndOsDeprecation fun provideEnableAppAndOsDeprecation(): PlatformParameterValue { diff --git a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterModule.kt b/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterModule.kt index 7ff02772a65..9341414bfd8 100644 --- a/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterModule.kt +++ b/testing/src/main/java/org/oppia/android/testing/platformparameter/TestPlatformParameterModule.kt @@ -9,7 +9,6 @@ import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING import org.oppia.android.util.platformparameter.CACHE_LATEX_RENDERING_DEFAULT_VALUE import org.oppia.android.util.platformparameter.CacheLatexRendering import org.oppia.android.util.platformparameter.ENABLE_APP_AND_OS_DEPRECATION_DEFAULT_VALUE -import org.oppia.android.util.platformparameter.ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_DOWNLOADS_SUPPORT_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EDIT_ACCOUNTS_OPTIONS_UI_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_EXTRA_TOPIC_TABS_UI_DEFAULT_VALUE @@ -17,7 +16,6 @@ import org.oppia.android.util.platformparameter.ENABLE_INTERACTION_CONFIG_CHANGE import org.oppia.android.util.platformparameter.ENABLE_LANGUAGE_SELECTION_UI_DEFAULT_VALUE import org.oppia.android.util.platformparameter.ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE import org.oppia.android.util.platformparameter.EnableAppAndOsDeprecation -import org.oppia.android.util.platformparameter.EnableContinueButtonAnimation import org.oppia.android.util.platformparameter.EnableDownloadsSupport import org.oppia.android.util.platformparameter.EnableEditAccountsOptionsUi import org.oppia.android.util.platformparameter.EnableExtraTopicTabsUi @@ -206,14 +204,6 @@ class TestPlatformParameterModule { fun provideEnableInteractionConfigChangeStateRetention(): PlatformParameterValue = PlatformParameterValue.createDefaultParameter(enableInteractionConfigChangeStateRetention) - @Provides - @EnableContinueButtonAnimation - fun provideEnableContinueButtonAnimation(): PlatformParameterValue { - return PlatformParameterValue.createDefaultParameter( - enableContinueButtonAnimation - ) - } - @Provides @EnableSpotlightUi fun provideEnableSpotlightUi(): PlatformParameterValue { @@ -304,7 +294,6 @@ class TestPlatformParameterModule { fun forceEnableDownloadsSupport(value: Boolean) { enableDownloadsSupport = value } - private var enableContinueButtonAnimation = ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE /** Enables forcing [EnableLanguageSelectionUi] platform parameter flag from tests. */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) @@ -354,12 +343,6 @@ class TestPlatformParameterModule { enablePerformanceMetricsCollection = value } - /** Enables forcing [EnableContinueButtonAnimation] platform parameter flag from tests. */ - @VisibleForTesting(otherwise = VisibleForTesting.NONE) - fun forceEnableContinueButtonAnimation(value: Boolean) { - enableContinueButtonAnimation = value - } - /** Enables forcing [EnableSpotlightUi] platform parameter flag from tests. */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) fun forceEnableSpotlightUi(value: Boolean) { diff --git a/utility/build.gradle b/utility/build.gradle index 52164f42b34..5039f921dd3 100644 --- a/utility/build.gradle +++ b/utility/build.gradle @@ -82,7 +82,7 @@ dependencies { 'androidx.appcompat:appcompat:1.0.2', 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03', 'androidx.work:work-runtime-ktx:2.4.0', - 'com.github.oppia:androidsvg:1265eb1087056cf3fc2e10442e5545bc65c109ce', + 'com.github.oppia:androidsvg:5bc9c7553e94c3476e8ea32baea3c77567228fcd', 'com.github.oppia:kotlitex:43139c140833c7120f351d63d74b42c253d2b213', 'com.github.bumptech.glide:glide:4.11.0', 'com.google.dagger:dagger:2.24', diff --git a/utility/src/main/java/org/oppia/android/util/parser/image/UrlImageParser.kt b/utility/src/main/java/org/oppia/android/util/parser/image/UrlImageParser.kt index b18934a1897..137652bd013 100644 --- a/utility/src/main/java/org/oppia/android/util/parser/image/UrlImageParser.kt +++ b/utility/src/main/java/org/oppia/android/util/parser/image/UrlImageParser.kt @@ -268,6 +268,8 @@ class UrlImageParser private constructor( var drawableWidth = drawable.intrinsicWidth.toFloat() var drawableHeight = drawable.intrinsicHeight.toFloat() + val maxContentItemPadding = + context.resources.getDimensionPixelSize(R.dimen.maximum_content_item_padding) if (autoResizeImage) { // Treat the drawable's dimensions as dp so that the image scales for higher density // displays. @@ -291,8 +293,7 @@ class UrlImageParser private constructor( drawableHeight *= multipleFactor drawableWidth *= multipleFactor } - val maxContentItemPadding = - context.resources.getDimensionPixelSize(R.dimen.maximum_content_item_padding) + val maximumImageSize = maxAvailableWidth - maxContentItemPadding if (drawableWidth >= maximumImageSize) { // The multipleFactor value is used to make sure that the aspect ratio of the image @@ -311,6 +312,10 @@ class UrlImageParser private constructor( } } + if (drawableWidth >= (maxAvailableWidth - maxContentItemPadding)) { + drawableWidth -= maxContentItemPadding + } + val drawableLeft = if (imageCenterAlign && !isRTLMode()) { calculateInitialMargin(maxAvailableWidth, drawableWidth) } else { diff --git a/utility/src/main/java/org/oppia/android/util/parser/svg/ScalableVectorGraphic.kt b/utility/src/main/java/org/oppia/android/util/parser/svg/ScalableVectorGraphic.kt index 06dc224ad89..6692d90d875 100644 --- a/utility/src/main/java/org/oppia/android/util/parser/svg/ScalableVectorGraphic.kt +++ b/utility/src/main/java/org/oppia/android/util/parser/svg/ScalableVectorGraphic.kt @@ -3,9 +3,9 @@ package org.oppia.android.util.parser.svg import android.graphics.Picture import android.graphics.RectF import android.text.TextPaint -import com.caverock.androidsvg.RenderOptions -import com.caverock.androidsvg.SVG -import com.caverock.androidsvg.utils.RenderOptionsBase +import com.caverock.androidsvg.androidrendering.RenderOptions +import com.caverock.androidsvg.androidrendering.RenderOptionsBase +import com.caverock.androidsvg.androidrendering.SVG import org.oppia.android.util.parser.image.ImageTransformation /** @@ -39,18 +39,14 @@ class ScalableVectorGraphic { } /** - * Returns the [SvgSizeSpecs] corresponding to this SVG, based on the specified [textPaint]. If a - * [TextPaint] is supplied, the returns specs will include text-based adjustments (for in-line - * images). Otherwise, the returned specs will be arranged for rendering the SVG in a standalone - * manner. + * Returns the [SvgSizeSpecs] corresponding to this SVG. + * + * The returned specs will be arranged for rendering the SVG in a standalone manner. */ - fun computeSizeSpecs(textPaint: TextPaint?): SvgSizeSpecs { - val options = RenderOptionsBase().also { if (textPaint != null) it.textPaint(textPaint) } + fun computeSizeSpecs(): SvgSizeSpecs { + val options = RenderOptionsBase() val documentWidth = parsedSvg.value.getDocumentWidthOrNull(options) val documentHeight = parsedSvg.value.getDocumentHeightOrNull(options) - val verticalAlignment = if (textPaint != null) { - adjustAlignmentForAndroid(parsedSvg.value.getVerticalAlignment(options)) - } else 0f val viewBox: RectF? = parsedSvg.value.documentViewBox val viewBoxWidth = viewBox?.width() @@ -75,16 +71,54 @@ class ScalableVectorGraphic { intrinsicHeight, renderedWidth = imageFileNameWidth ?: intrinsicWidth, renderedHeight = imageFileNameHeight ?: intrinsicHeight, + verticalAlignment = 0f + ) + } + + /** + * Returns the [SvgSizeSpecs] corresponding to this SVG, based on the specified [textPaint]. + * Based on the supplied [TextPaint], the returned specs will include text-based adjustments + * (for in-line images). + */ + fun computeSizeSpecsForTextPicture(textPaint: TextPaint?): SvgSizeSpecs { + val options = textPaint?.let { RenderOptionsBase().textPaint(it) } ?: RenderOptionsBase() + val documentWidth = parsedSvg.value.getDocumentWidthOrNull(options) + val documentHeight = parsedSvg.value.getDocumentHeightOrNull(options) + + val imageFileNameWidth = extractedWidth?.toFloat() + val imageFileNameHeight = extractedHeight?.toFloat() + + val fontMetrics = textPaint?.fontMetrics + val fontHeight = fontMetrics?.descent?.minus(fontMetrics.ascent) ?: 0f + + val adjustedWidth = + imageFileNameWidth?.convertExToPx(fontHeight) ?: documentWidth ?: DEFAULT_SIZE_PX + val adjustedHeight = + imageFileNameHeight?.convertExToPx(fontHeight) ?: documentHeight ?: DEFAULT_SIZE_PX + + val verticalAlignment = textPaint?.let { + adjustAlignmentForAndroid(parsedSvg.value.getVerticalAlignment(options)) + } ?: 0f + + return SvgSizeSpecs( + adjustedWidth, + adjustedHeight, + renderedWidth = adjustedWidth, + renderedHeight = adjustedHeight, verticalAlignment ) } + private fun Float.convertExToPx(fontHeight: Float): Float { + return this * fontHeight * 0.5f + } + /** * Returns an Android [Picture] including the draw instructions for rendering this SVG within a * line of text whose size and style is configured by the provided [textPaint]. */ fun renderToTextPicture(textPaint: TextPaint): Picture { - return computeSizeSpecs(textPaint).let { (width, height, _) -> + return computeSizeSpecsForTextPicture(textPaint).let { (width, height, _) -> val options = RenderOptions().textPaint(textPaint).viewPort(0f, 0f, width, height) as RenderOptions parsedSvg.value.renderToPicture(options) diff --git a/utility/src/main/java/org/oppia/android/util/parser/svg/SvgPictureDrawable.kt b/utility/src/main/java/org/oppia/android/util/parser/svg/SvgPictureDrawable.kt index 8178e745dca..2197ba013aa 100644 --- a/utility/src/main/java/org/oppia/android/util/parser/svg/SvgPictureDrawable.kt +++ b/utility/src/main/java/org/oppia/android/util/parser/svg/SvgPictureDrawable.kt @@ -100,11 +100,17 @@ abstract class SvgPictureDrawable( * when [textPaint] is null and text rendering when otherwise. */ protected fun reinitialize(textPaint: TextPaint?) { - picture = textPaint?.let { - scalableVectorGraphic.renderToTextPicture(it) - } ?: scalableVectorGraphic.renderToBlockPicture() + val newPicture = if (textPaint != null) { + intrinsicSize = scalableVectorGraphic.computeSizeSpecsForTextPicture(textPaint) + scalableVectorGraphic.renderToTextPicture(textPaint) + } else { + intrinsicSize = scalableVectorGraphic.computeSizeSpecs() + scalableVectorGraphic.renderToBlockPicture() + } + + picture = newPicture + // TODO(#4246): Fix both SVG rendering performance and upscaling to ensure images aren't blurry. - intrinsicSize = scalableVectorGraphic.computeSizeSpecs(textPaint) if (scalableVectorGraphic.shouldBeRenderedAsBitmap()) { recomputeBitmap() } diff --git a/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterConstants.kt b/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterConstants.kt index 8cb1e1b4297..fa0deba044c 100644 --- a/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterConstants.kt +++ b/utility/src/main/java/org/oppia/android/util/platformparameter/PlatformParameterConstants.kt @@ -170,17 +170,6 @@ const val ENABLE_PERFORMANCE_METRICS_COLLECTION = "enable_performance_metrics_co /** Default value for whether to record performance metrics. */ const val ENABLE_PERFORMANCE_METRICS_COLLECTION_DEFAULT_VALUE = false -/** - * Qualifier for the platform parameter that controls whether to animate the continue button - * interaction and navigation items. This is used to disable the animation during testing because - * Espresso has known problems while testing views that contain animations. - */ -@Qualifier -annotation class EnableContinueButtonAnimation - -/** Default value for whether to enable continue button animation. */ -const val ENABLE_CONTINUE_BUTTON_ANIMATION_DEFAULT_VALUE = true - /** * Qualifier for the platform parameter that controls the time interval in minutes of uploading * previously recorded performance metrics to the remote service.