diff --git a/app/src/main/java/com/lhw/pdf/MainActivity.kt b/app/src/main/java/com/lhw/pdf/MainActivity.kt index 335efdd..c0790ef 100644 --- a/app/src/main/java/com/lhw/pdf/MainActivity.kt +++ b/app/src/main/java/com/lhw/pdf/MainActivity.kt @@ -3,9 +3,13 @@ package com.lhw.pdf import android.content.Context import android.content.Intent import android.graphics.PorterDuff +import android.hardware.display.DisplayManager +import android.hardware.display.DisplayManager.DisplayListener import android.media.MediaRouter import android.os.Bundle +import android.util.DisplayMetrics import android.view.Menu +import android.view.WindowManager import android.widget.ImageView import com.google.android.material.snackbar.Snackbar import com.google.android.material.navigation.NavigationView @@ -28,6 +32,7 @@ import kotlin.math.min class MainActivity : AppCompatActivity() { private lateinit var appBarConfiguration: AppBarConfiguration private lateinit var binding: ActivityMainBinding + private lateinit var displayManager: DisplayManager private lateinit var mediaRouter: MediaRouter private val thumbnailWidth = 500 private val thumbnailHeight = 700 @@ -39,6 +44,20 @@ class MainActivity : AppCompatActivity() { private val thumbnailImageViews = mutableListOf() private val defaultCachedFileName = "cached.pdf" + private val displayListener = object: DisplayListener { + override fun onDisplayAdded(p0: Int) { + updateDisplayText() + } + + override fun onDisplayChanged(p0: Int) { + updateDisplayText() + } + + override fun onDisplayRemoved(p0: Int) { + updateDisplayText() + } + } + private fun inputStreamToCache(outputFilename: String, inputStream: InputStream): File { val fileCached = File(cacheDir, outputFilename) val output = FileOutputStream(fileCached) @@ -67,9 +86,11 @@ class MainActivity : AppCompatActivity() { } private fun makePresentationView() { + presentation = null mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO)?.presentationDisplay?.let { display -> presentation = MyPresentation(this, display) updatePresentationImages() + presentation?.setOnCancelListener { presentation = null } presentation?.show() } } @@ -101,8 +122,26 @@ class MainActivity : AppCompatActivity() { reLayoutThumbnails() } + private fun updateDisplayText() { + val displayText = binding.appBarMain.contentMain.textDisplays + val text = StringBuilder() + //displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION).forEach { + displayManager.displays.forEach { + val displayMetrics = DisplayMetrics() + @Suppress("DEPRECATION") + it.getMetrics(displayMetrics) + val s = "displayId ${it.displayId} $displayMetrics" + println(s) + text.append(s) + text.append("\n") + } + displayText.text = text.toString() + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + displayManager = getSystemService(Context.DISPLAY_SERVICE) as DisplayManager mediaRouter = getSystemService(Context.MEDIA_ROUTER_SERVICE) as MediaRouter //val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView) //windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) //Doesn't seem to actually fill the vacant space by default @@ -110,6 +149,9 @@ class MainActivity : AppCompatActivity() { binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) + updateDisplayText() + displayManager.registerDisplayListener(displayListener, null) + setSupportActionBar(binding.appBarMain.toolbar) // Load previous pdf, or included test pdf first diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index c1892e8..8b41bc3 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -54,4 +54,18 @@ android:orientation="horizontal" tools:showIn="@layout/content_main" /> + + \ No newline at end of file