Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions app/src/main/java/helium314/keyboard/latin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading