diff --git a/app/src/main/java/helium314/keyboard/latin/App.kt b/app/src/main/java/helium314/keyboard/latin/App.kt index e321ce3cf..4afce1ab8 100644 --- a/app/src/main/java/helium314/keyboard/latin/App.kt +++ b/app/src/main/java/helium314/keyboard/latin/App.kt @@ -57,6 +57,11 @@ class App : Application(), Configuration.Provider { packageInfo.versionCode }) on Android ${android.os.Build.VERSION.RELEASE} (SDK ${android.os.Build.VERSION.SDK_INT})" ) + val config = resources.configuration + Log.i( + "startup", "Device ${android.os.Build.MANUFACTURER} ${android.os.Build.MODEL}, screen ${config.screenWidthDp}x${config.screenHeightDp}dp " + + "(smallest ${config.smallestScreenWidthDp}dp, density ${resources.displayMetrics.densityDpi}dpi)" + ) } companion object { diff --git a/app/src/main/java/helium314/keyboard/latin/utils/ScreenProfile.kt b/app/src/main/java/helium314/keyboard/latin/utils/ScreenProfile.kt index 0f00d2500..f393f020a 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/ScreenProfile.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/ScreenProfile.kt @@ -3,7 +3,6 @@ package helium314.keyboard.latin.utils import android.content.Context import android.content.res.Configuration -import android.util.Log import androidx.annotation.VisibleForTesting import kotlin.math.roundToInt @@ -58,7 +57,11 @@ object ScreenProfileProvider { val availableHeightDp = if (config.screenHeightDp > 0) config.screenHeightDp else if (density > 0f) (heightPx / density).roundToInt() else 0 val isFoldable = isFoldableDevice(context) - val isBothDimensionsLarge = (availableWidthDp >= 500 && availableHeightDp >= 500) + // Unfolded foldables are nearly square (e.g. 588x706dp), but a phone with a small display size setting can also + // be 500dp or more in both dimensions. Phones are tall and narrow, so they must not get the relaxed 500dp limit. + val isNearlySquare = maxOf(availableWidthDp, availableHeightDp) * 10 <= minOf(availableWidthDp, availableHeightDp) * 16 + val isBothDimensionsLarge = (availableWidthDp >= 600 && availableHeightDp >= 600) + || (isNearlySquare && availableWidthDp >= 500 && availableHeightDp >= 500) || (isFoldable && availableWidthDp >= 500 && availableHeightDp >= 450) val isSmallestWidthLarge = config.smallestScreenWidthDp >= 600 diff --git a/app/src/test/java/helium314/keyboard/latin/utils/ScreenProfileTest.kt b/app/src/test/java/helium314/keyboard/latin/utils/ScreenProfileTest.kt index 3f4dfc8d7..e66cbc5e6 100644 --- a/app/src/test/java/helium314/keyboard/latin/utils/ScreenProfileTest.kt +++ b/app/src/test/java/helium314/keyboard/latin/utils/ScreenProfileTest.kt @@ -85,6 +85,23 @@ class ScreenProfileTest { assertEquals(ScreenProfile.LARGE, profile) } + @Test + fun testScreenProfilePhoneWithSmallDisplaySizeIsCompact() { + // Regular phone (not a foldable) with a small "display size" setting: 500dp or more in both dimensions, but tall and narrow + val portrait = Configuration().apply { + screenWidthDp = 520 + screenHeightDp = 1150 + smallestScreenWidthDp = 520 + } + assertEquals(ScreenProfile.COMPACT, ScreenProfileProvider.getScreenProfile(context, portrait)) + val landscape = Configuration().apply { + screenWidthDp = 1150 + screenHeightDp = 520 + smallestScreenWidthDp = 520 + } + assertEquals(ScreenProfile.COMPACT, ScreenProfileProvider.getScreenProfile(context, landscape)) + } + @Test fun testScreenProfileFoldableFoldedLandscapeIsCompact() { // Foldable device when folded in landscape (width >= 600, but height < 600 and smallestScreenWidthDp < 600) gets COMPACT profile