Compare commits
3 Commits
master
...
fullscreen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4289ad1dd9 | ||
|
|
da38e9d96b | ||
|
|
025e18113b |
@ -32,6 +32,11 @@ android {
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
buildConfigField 'boolean', 'ENABLE_PLAY_SERVICES', 'true'
|
||||
|
||||
//these are used to help determine the resolution
|
||||
buildConfigField 'boolean', 'FORCE_PORTRAIT_GEOMETRY', 'true'
|
||||
buildConfigField 'int', "MAX_DIMENSION", "1280"
|
||||
buildConfigField 'int', "MIN_DIMENSION", "360"
|
||||
|
||||
// Ignore Sentry packages that cause lint failure
|
||||
lintOptions {
|
||||
lintConfig file("$projectDir/src/main/resources/lint.xml")
|
||||
|
||||
@ -356,7 +356,7 @@ class MainActivity : AppCompatActivity(), SessionListFragment.SessionSelection,
|
||||
val windowManager = applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
|
||||
val orientation = applicationContext.resources.configuration.orientation
|
||||
deviceDimensions.saveDeviceDimensions(windowManager, DisplayMetrics(), orientation)
|
||||
deviceDimensions.saveDeviceDimensions(windowManager, DisplayMetrics(), orientation, defaultSharedPreferences)
|
||||
session.geometry = deviceDimensions.getScreenResolution()
|
||||
}
|
||||
|
||||
|
||||
@ -1,42 +1,59 @@
|
||||
package tech.ula.utils
|
||||
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Point
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.WindowManager
|
||||
import tech.ula.BuildConfig
|
||||
|
||||
class DeviceDimensions {
|
||||
private var height = 720
|
||||
private var width = 1480
|
||||
private var height = 720f
|
||||
private var width = 1480f
|
||||
private var scaling = 1f
|
||||
|
||||
fun saveDeviceDimensions(windowManager: WindowManager, displayMetrics: DisplayMetrics, orientation: Int) {
|
||||
val navBarSize = getNavigationBarSize(windowManager)
|
||||
fun saveDeviceDimensions(windowManager: WindowManager, displayMetrics: DisplayMetrics, orientation: Int, sharedPreferences: SharedPreferences) {
|
||||
var scalingMin = 1f
|
||||
var scalingMax = 1f
|
||||
windowManager.defaultDisplay.getRealMetrics(displayMetrics)
|
||||
height = displayMetrics.heightPixels
|
||||
width = displayMetrics.widthPixels
|
||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
height = displayMetrics.heightPixels.toFloat()
|
||||
width = displayMetrics.widthPixels.toFloat()
|
||||
|
||||
when (orientation) {
|
||||
Configuration.ORIENTATION_PORTRAIT -> if (navBarSize.y > 0) height += navBarSize.y
|
||||
Configuration.ORIENTATION_LANDSCAPE -> if (navBarSize.x > 0) width += navBarSize.x
|
||||
else -> return
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val displayCutout = windowManager.defaultDisplay.cutout
|
||||
if (displayCutout != null) {
|
||||
height -= displayCutout.safeInsetBottom + displayCutout.safeInsetTop
|
||||
width -= displayCutout.safeInsetLeft + displayCutout.safeInsetRight
|
||||
}
|
||||
}
|
||||
|
||||
if (sharedPreferences.getBoolean("pref_custom_scaling_enabled", false)) {
|
||||
scaling = sharedPreferences.getString("pref_scaling", "1.0")!!.toFloat()
|
||||
} else {
|
||||
if (height > width) {
|
||||
scalingMax = height / BuildConfig.MAX_DIMENSION
|
||||
scalingMin = width / BuildConfig.MIN_DIMENSION
|
||||
} else {
|
||||
scalingMax = width / BuildConfig.MAX_DIMENSION
|
||||
scalingMin = height / BuildConfig.MIN_DIMENSION
|
||||
}
|
||||
if (scalingMin < 1f)
|
||||
scalingMin = 1f
|
||||
if (scalingMax < 1f)
|
||||
scalingMax = 1f
|
||||
if (scalingMax < scalingMin)
|
||||
scaling = scalingMax
|
||||
else
|
||||
scaling = scalingMin
|
||||
}
|
||||
|
||||
height = height / scaling
|
||||
width = width / scaling
|
||||
}
|
||||
|
||||
fun getScreenResolution(): String {
|
||||
return when (height > width) {
|
||||
true -> "${height}x$width"
|
||||
false -> "${width}x$height"
|
||||
return when ((height > width) && BuildConfig.FORCE_PORTRAIT_GEOMETRY) {
|
||||
true -> "${height.toInt()}x${width.toInt()}"
|
||||
false -> "${width.toInt()}x${height.toInt()}"
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNavigationBarSize(windowManager: WindowManager): Point {
|
||||
val display = windowManager.defaultDisplay
|
||||
val appSize = Point()
|
||||
val screenSize = Point()
|
||||
display.getSize(appSize)
|
||||
display.getRealSize(screenSize)
|
||||
|
||||
return Point(screenSize.x - appSize.x, screenSize.y - appSize.y)
|
||||
}
|
||||
}
|
||||
@ -281,5 +281,8 @@
|
||||
<string name="pref_clear_auto_start_title">Autostart Einstellungen löschen</string>
|
||||
<string name="pref_clear_auto_start_summary">Keine App mehr automatisch starten, bis wieder aktiviert wird.</string>
|
||||
<string name="auto_start_checkbox">Autostart aktivieren</string>
|
||||
<string name="pref_custom_scaling_enabled_title">Benuterdefinierten Skalierfaktor verwenden</string>
|
||||
<string name="pref_custom_scaling_enabled_summary">Erlaubt das Einstellen eines benutzerdefinierten Skalierfaktors, um die Display Auflösung der VNC Sitzung zu verringern.</string>
|
||||
<string name="pref_scaling_title">Skalierfaktor festlegen</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@ -149,6 +149,9 @@
|
||||
<string name="pref_default_landing_page_message">Select the page you would like to open the app with.</string>
|
||||
<string name="pref_clear_auto_start_title">Clear Auto Start Settings</string>
|
||||
<string name="pref_clear_auto_start_summary">Stops any app from auto starting until enabled again.</string>
|
||||
<string name="pref_custom_scaling_enabled_title">Use Custom Graphical Scaling Factor</string>
|
||||
<string name="pref_custom_scaling_enabled_summary">Allows specifying a custom scaling factor to decrease the resolution of the VNC session.</string>
|
||||
<string name="pref_scaling_title">Set Custom Scaling Factor</string>
|
||||
<string name="pref_proot_category">PRoot Preferences</string>
|
||||
<string name="pref_proot_debugging_enabled_title">PRoot Debugging Logs Enabled</string>
|
||||
<string name="pref_proot_debugging_enabled_summary">Only necessary if having problems with the app. Log file stored at\n/mnt/sdcard/PRoot_Debug_Log</string>
|
||||
|
||||
@ -18,6 +18,19 @@
|
||||
android:title="@string/pref_clear_auto_start_title"
|
||||
android:summary="@string/pref_clear_auto_start_summary"
|
||||
app:iconSpaceReserved="false"/>
|
||||
<CheckBoxPreference
|
||||
android:key="pref_custom_scaling_enabled"
|
||||
android:title="@string/pref_custom_scaling_enabled_title"
|
||||
android:summary="@string/pref_custom_scaling_enabled_summary"
|
||||
android:defaultValue="false"
|
||||
app:iconSpaceReserved="false"/>
|
||||
<EditTextPreference
|
||||
android:dependency="pref_custom_scaling_enabled"
|
||||
android:key="pref_scaling"
|
||||
android:title="@string/pref_scaling_title"
|
||||
android:inputType="number"
|
||||
android:defaultValue="1"
|
||||
app:iconSpaceReserved="false"/>
|
||||
<CheckBoxPreference
|
||||
android:key="pref_opt_in"
|
||||
android:title="@string/opt_in_preference"
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package tech.ula.utils
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.Display
|
||||
@ -11,6 +12,7 @@ import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import tech.ula.BuildConfig
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class DeviceDimensionsTest {
|
||||
@ -27,6 +29,9 @@ class DeviceDimensionsTest {
|
||||
@Mock
|
||||
lateinit var mockDisplay: Display
|
||||
|
||||
@Mock
|
||||
lateinit var mockSharedPreferences: SharedPreferences
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
mockDeviceDimensions = DeviceDimensions()
|
||||
@ -41,15 +46,19 @@ class DeviceDimensionsTest {
|
||||
@Test
|
||||
fun `Device dimensions that are taller in height will have the height value first`() {
|
||||
setDimensions(mockDisplayMetrics, width = 100, height = 200)
|
||||
mockDeviceDimensions.saveDeviceDimensions(mockWindowManager, mockDisplayMetrics, Configuration.ORIENTATION_PORTRAIT)
|
||||
mockDeviceDimensions.saveDeviceDimensions(mockWindowManager, mockDisplayMetrics, Configuration.ORIENTATION_PORTRAIT, mockSharedPreferences)
|
||||
val geometry = mockDeviceDimensions.getScreenResolution()
|
||||
assertEquals(geometry, "200x100")
|
||||
if (BuildConfig.FORCE_PORTRAIT_GEOMETRY) {
|
||||
assertEquals(geometry, "200x100")
|
||||
} else {
|
||||
assertEquals(geometry, "100x200")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Device dimensions that are longer in width will have the width value first`() {
|
||||
setDimensions(mockDisplayMetrics, width = 300, height = 200)
|
||||
mockDeviceDimensions.saveDeviceDimensions(mockWindowManager, mockDisplayMetrics, Configuration.ORIENTATION_PORTRAIT)
|
||||
mockDeviceDimensions.saveDeviceDimensions(mockWindowManager, mockDisplayMetrics, Configuration.ORIENTATION_PORTRAIT, mockSharedPreferences)
|
||||
val geometry = mockDeviceDimensions.getScreenResolution()
|
||||
assertEquals(geometry, "300x200")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user