Skip to content

Commit

Permalink
Update DensityUtil.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaggly committed Feb 21, 2023
1 parent 1d1108b commit 28299ac
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions app/src/main/java/com/snaggly/ksw_toolkit/util/adb/DensityUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,28 @@ import com.snaggly.ksw_toolkit.util.commander.AppStarter
import kotlin.math.min

object DensityUtil {
private var tabletModeTurnedOn = false

fun turnOnTabletMode(context: Context) {
if (tabletModeTurnedOn)
return
val displayMetrics = context.resources.displayMetrics
val tabletDpi = Integer.max(
(min(
displayMetrics.widthPixels,
displayMetrics.heightPixels
) * 160) / Integer.max(600, 320), 120
)
tabletModeTurnedOn = try {
try {
AdbManager.sendCommand("wm density $tabletDpi", context)
true
} catch (e: Exception) {
false
}
} catch (_: Exception) { }
}

fun turnOffTabletMode(context: Context) {
if (!tabletModeTurnedOn)
return
val dpi = {
val dpi : Int =
if (context.resources.displayMetrics.heightPixels > 480)
240
else
160
}
tabletModeTurnedOn = try {

try {
AdbManager.sendCommand("wm density $dpi", context)
false
} catch (e: Exception) {
true
}
} catch (_: Exception) { }
}
}

0 comments on commit 28299ac

Please sign in to comment.