mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
Use API-compatible activity display lookup
This commit is contained in:
1 parent
155cbbb894
commit
e95ba8d8a2
3 files changed
+32
-3
No files matched your search
@@ -2017,7 +2017,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
|||||||
|
|
||||||
private fun refreshSecondScreenDisplays() {
|
private fun refreshSecondScreenDisplays() {
|
||||||
if (!::displayManager.isInitialized) return
|
if (!::displayManager.isInitialized) return
|
||||||
val primaryId = display?.displayId ?: windowManager.defaultDisplay.displayId
|
val primaryId = windowManager.defaultDisplay.displayId
|
||||||
val candidates = SecondScreenDisplays.available(displayManager, primaryId)
|
val candidates = SecondScreenDisplays.available(displayManager, primaryId)
|
||||||
val oldIds = secondScreenDisplays.map { it.id }.toSet()
|
val oldIds = secondScreenDisplays.map { it.id }.toSet()
|
||||||
secondScreenDisplays = candidates
|
secondScreenDisplays = candidates
|
||||||
@@ -2033,7 +2033,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
private fun currentActivityDisplayId(): Int = display?.displayId ?: windowManager.defaultDisplay.displayId
|
private fun currentActivityDisplayId(): Int = windowManager.defaultDisplay.displayId
|
||||||
|
|
||||||
private fun refreshActivityDisplayId(): Boolean {
|
private fun refreshActivityDisplayId(): Boolean {
|
||||||
val current = currentActivityDisplayId()
|
val current = currentActivityDisplayId()
|
||||||
|
|||||||
@@ -1958,7 +1958,7 @@ class SessionService : Service() {
|
|||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
private fun currentActivityDisplayId(context: Context): Int {
|
private fun currentActivityDisplayId(context: Context): Int {
|
||||||
val activity = context as? android.app.Activity ?: return Display.DEFAULT_DISPLAY
|
val activity = context as? android.app.Activity ?: return Display.DEFAULT_DISPLAY
|
||||||
return activity.display?.displayId ?: activity.windowManager.defaultDisplay.displayId
|
return activity.windowManager.defaultDisplay.displayId
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resume(context: Context) {
|
fun resume(context: Context) {
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.droiddeck.launcher.session
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.Robolectric
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.annotation.Config
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
@Config(sdk = [26, 28, 29, 33], manifest = Config.NONE)
|
||||||
|
class ActivityDisplayCompatibilityTest {
|
||||||
|
@Test fun visibleActivityUsesItsDisplayIdAcrossSupportedAndroidVersions() {
|
||||||
|
val wasRunning = SessionState.running
|
||||||
|
val previousDisplayId = SessionState.activityDisplayId
|
||||||
|
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||||
|
try {
|
||||||
|
SessionState.running = false
|
||||||
|
SessionService.setActivityVisible(activity, true)
|
||||||
|
|
||||||
|
assertEquals(activity.windowManager.defaultDisplay.displayId, SessionState.activityDisplayId)
|
||||||
|
} finally {
|
||||||
|
SessionState.running = wasRunning
|
||||||
|
SessionState.activityDisplayId = previousDisplayId
|
||||||
|
activity.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user