added cutout support (#7044)

* added support

* now toggleable in settings

* translation

* added note that it requires restart

* made it enabled by default

* padded buttons to the right if there is a cutout

* checking for cutout instead of android

* reverted button changes

* moved option to advancedTab
This commit is contained in:
alexban011
2022-06-14 20:34:30 +03:00
committed by GitHub
parent cac616a97b
commit fc926420e8
6 changed files with 39 additions and 1 deletions

View File

@ -689,6 +689,7 @@ Show pixel improvements =
Enable Nuclear Weapons =
Experimental Demographics scoreboard =
Show zoom buttons in world screen =
Enable display cutout (requires restart) =
Show tile yields =
Show unit movement arrows =
Continuous rendering =

View File

@ -2,7 +2,9 @@ package com.unciv.app
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationManagerCompat
import androidx.work.WorkManager
import com.badlogic.gdx.backends.android.AndroidApplication
@ -33,10 +35,14 @@ open class AndroidLauncher : AndroidApplication() {
val settings = GameSaver.getSettingsForPlatformLaunchers(filesDir.path)
val fontFamily = settings.fontFamily
// Manage orientation lock
// Manage orientation lock and display cutout
val platformSpecificHelper = PlatformSpecificHelpersAndroid(this)
platformSpecificHelper.allowPortrait(settings.allowAndroidPortrait)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
platformSpecificHelper.toggleDisplayCutout(settings.androidCutout)
}
val androidParameters = UncivGameParameters(
version = BuildConfig.VERSION_NAME,
crashReportSysInfo = CrashReportSysInfoAndroid,

View File

@ -2,6 +2,10 @@ package com.unciv.app
import android.app.Activity
import android.content.pm.ActivityInfo
import android.os.Build
import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
import androidx.annotation.RequiresApi
import com.unciv.ui.utils.GeneralPlatformSpecificHelpers
import kotlin.concurrent.thread
@ -31,6 +35,25 @@ Sources for Info about current orientation in case need:
if (activity.requestedOrientation != orientation) activity.requestedOrientation = orientation
}
override fun hasDisplayCutout(): Boolean {
val displayCutout = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
activity.windowManager.defaultDisplay.cutout
} else {
TODO("VERSION.SDK_INT < Q")
}
return displayCutout != null
}
@RequiresApi(Build.VERSION_CODES.P)
override fun toggleDisplayCutout(androidCutout: Boolean) {
val layoutParams = activity.window.attributes
if (androidCutout) {
layoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
} else {
layoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
}
}
/**
* On Android, local is some android-internal data directory which may or may not be accessible by the user.
* External is probably on an SD-card or similar which is always accessible by the user.

View File

@ -55,6 +55,8 @@ class GameSettings {
var useDemographics: Boolean = false
var showZoomButtons: Boolean = false
var androidCutout: Boolean = false
var multiplayer = GameSettingsMultiplayer()
var showExperimentalWorldWrap = false // We're keeping this as a config due to ANR problems on Android phones for people who don't know what they're doing :/

View File

@ -47,6 +47,9 @@ fun advancedTab(
settings.showExperimentalWorldWrap = it
}
if (UncivGame.Current.platformSpecificHelper?.hasDisplayCutout() == true)
optionsPopup.addCheckbox(this, "Enable display cutout (requires restart)", settings.androidCutout, false) { settings.androidCutout = it }
addMaxZoomSlider(this, settings)
val helper = UncivGame.Current.platformSpecificHelper

View File

@ -16,6 +16,9 @@ interface GeneralPlatformSpecificHelpers {
*/
fun allowPortrait(allow: Boolean) {}
fun hasDisplayCutout(): Boolean { return false }
fun toggleDisplayCutout(androidCutout: Boolean) {}
/**
* Notifies the user that it's their turn while the game is running
*/