[Android] Collect the WindowLayoutInfo in the BaseActivity
Nicolas Pomepuy
git at videolan.org
Mon Jul 4 12:09:47 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Jul 1 07:39:20 2022 +0200| [e48e370b08ff97785d07ead926c8d4d7ea35f052] | committer: Duncan McNamara
Collect the WindowLayoutInfo in the BaseActivity
> https://code.videolan.org/videolan/vlc-android/commit/e48e370b08ff97785d07ead926c8d4d7ea35f052
---
.../src/org/videolan/vlc/gui/BaseActivity.kt | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
index fc78c96de..7f9b7e668 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/BaseActivity.kt
@@ -17,6 +17,13 @@ import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.BaseContextWrappingDelegate
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.lifecycleScope
+import androidx.lifecycle.repeatOnLifecycle
+import androidx.window.layout.WindowInfoTracker
+import androidx.window.layout.WindowLayoutInfo
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
import org.videolan.resources.AppContextProvider
import org.videolan.tools.KeyHelper
import org.videolan.tools.Settings
@@ -33,6 +40,7 @@ abstract class BaseActivity : AppCompatActivity() {
private var currentNightMode: Int = 0
private var startColor: Int = 0
lateinit var settings: SharedPreferences
+ var windowLayoutInfo: WindowLayoutInfo? = null
open val displayTitle = false
open fun forcedTheme():Int? = null
@@ -53,6 +61,15 @@ abstract class BaseActivity : AppCompatActivity() {
UiTools.invalidateBitmaps()
UiTools.currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
}
+ lifecycleScope.launch(Dispatchers.Main) {
+ lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) {
+ WindowInfoTracker.getOrCreate(this at BaseActivity)
+ .windowLayoutInfo(this at BaseActivity)
+ .collect { layoutInfo ->
+ windowLayoutInfo = layoutInfo
+ }
+ }
+ }
}
@RequiresApi(Build.VERSION_CODES.O)
More information about the Android
mailing list