From 11b1d89259957f32e73f41bc230e757187d2af3b Mon Sep 17 00:00:00 2001 From: YASH SHARMA <158801815+whyash8@users.noreply.github.com> Date: Tue, 14 Jan 2025 02:34:08 +0530 Subject: [PATCH] Fix #5625: Migrate away from scaledDensity (#5644) This PR updates the `FontScaleConfigurationUtil` class to remove the usage of the deprecated `scaledDensity` property and replace it with `TypedValue.applyDimension` for scaling font sizes. This change ensures that the code adheres to modern Android API standards . Fixes #5625: This issue was related to the usage of the deprecated `scaledDensity` property ### Changes: **Removed deprecated `scaledDensity`:** - Updated the `adjustFontScale` method to calculate the scaled density using `TypedValue.applyDimension`. - Applied the new scaled density without using the deprecated property. ## 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)). --------- Co-authored-by: Adhiambo Peres <59600948+adhiamboperes@users.noreply.github.com> --- .../android/app/utility/FontScaleConfigurationUtil.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/utility/FontScaleConfigurationUtil.kt b/app/src/main/java/org/oppia/android/app/utility/FontScaleConfigurationUtil.kt index 6570499f35b..8a1505e21a6 100644 --- a/app/src/main/java/org/oppia/android/app/utility/FontScaleConfigurationUtil.kt +++ b/app/src/main/java/org/oppia/android/app/utility/FontScaleConfigurationUtil.kt @@ -3,6 +3,7 @@ package org.oppia.android.app.utility import android.content.Context import android.content.Context.WINDOW_SERVICE import android.util.DisplayMetrics +import android.util.TypedValue import android.view.WindowManager import org.oppia.android.app.model.ReadingTextSize import javax.inject.Inject @@ -21,16 +22,18 @@ class FontScaleConfigurationUtil @Inject constructor() { // TODO(#3616): Migrate to the proper SDK 30+ APIs. @Suppress("DEPRECATION") // The code is correct for targeted versions of Android. windowManager!!.defaultDisplay.getMetrics(metrics) - // TODO(#5625): Migrate away from scaledDensity. + val scaledDensity = TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_SP, 1.0f, metrics + ) * configuration.fontScale @Suppress("DEPRECATION") - metrics.scaledDensity = configuration.fontScale * metrics.density + metrics.scaledDensity = scaledDensity context.createConfigurationContext(configuration) context.resources.displayMetrics.setTo(metrics) } private fun getReadingTextSizeConfigurationUtil(readingTextSize: ReadingTextSize): Float { return when (readingTextSize) { - ReadingTextSize.SMALL_TEXT_SIZE -> .8f + ReadingTextSize.SMALL_TEXT_SIZE -> 0.8f ReadingTextSize.MEDIUM_TEXT_SIZE -> 1.0f ReadingTextSize.LARGE_TEXT_SIZE -> 1.2f ReadingTextSize.EXTRA_LARGE_TEXT_SIZE -> 1.4f