Skip to content

Commit

Permalink
Revert "android: Fix display scaling issue on some devices"
Browse files Browse the repository at this point in the history
This reverts commit b9f5ff9.
  • Loading branch information
YuKongA committed Nov 3, 2024
1 parent b9f5ff9 commit 5af9efa
Showing 1 changed file with 0 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
package top.yukonga.updater.kmp

import App
import android.content.res.Resources
import android.os.Build
import android.os.Bundle
import android.util.DisplayMetrics
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import kotlin.math.pow
import kotlin.math.sqrt

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val displayMetrics = Resources.getSystem().displayMetrics
val widthPixels = displayMetrics.widthPixels
val heightPixels = displayMetrics.heightPixels
val widthInches = widthPixels / displayMetrics.xdpi
val heightInches = heightPixels / displayMetrics.ydpi
val diagonalPixel = sqrt(widthPixels.toDouble().pow(2.0) + heightPixels.toDouble().pow(2.0))
val screenInches = sqrt(widthInches.toDouble().pow(2.0) + heightInches.toDouble().pow(2.0))
val actualDensityDpi = diagonalPixel / screenInches
val actualDensity = actualDensityDpi / DisplayMetrics.DENSITY_DEFAULT

val metrics = resources.displayMetrics
metrics.density = actualDensity.toFloat()
metrics.densityDpi = actualDensityDpi.toInt()
resources.displayMetrics.setTo(metrics)

AndroidAppContext.init(this)
enableEdgeToEdge()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Expand Down

0 comments on commit 5af9efa

Please sign in to comment.