Use DisplayManager to show all display metrics
This commit is contained in:
parent
23e7d8693a
commit
f9b7db0e44
|
@ -3,9 +3,13 @@ package com.lhw.pdf
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
|
import android.hardware.display.DisplayManager
|
||||||
|
import android.hardware.display.DisplayManager.DisplayListener
|
||||||
import android.media.MediaRouter
|
import android.media.MediaRouter
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.DisplayMetrics
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
import android.view.WindowManager
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.google.android.material.navigation.NavigationView
|
import com.google.android.material.navigation.NavigationView
|
||||||
|
@ -28,6 +32,7 @@ import kotlin.math.min
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
private lateinit var appBarConfiguration: AppBarConfiguration
|
||||||
private lateinit var binding: ActivityMainBinding
|
private lateinit var binding: ActivityMainBinding
|
||||||
|
private lateinit var displayManager: DisplayManager
|
||||||
private lateinit var mediaRouter: MediaRouter
|
private lateinit var mediaRouter: MediaRouter
|
||||||
private val thumbnailWidth = 500
|
private val thumbnailWidth = 500
|
||||||
private val thumbnailHeight = 700
|
private val thumbnailHeight = 700
|
||||||
|
@ -39,6 +44,20 @@ class MainActivity : AppCompatActivity() {
|
||||||
private val thumbnailImageViews = mutableListOf<ImageView>()
|
private val thumbnailImageViews = mutableListOf<ImageView>()
|
||||||
private val defaultCachedFileName = "cached.pdf"
|
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 {
|
private fun inputStreamToCache(outputFilename: String, inputStream: InputStream): File {
|
||||||
val fileCached = File(cacheDir, outputFilename)
|
val fileCached = File(cacheDir, outputFilename)
|
||||||
val output = FileOutputStream(fileCached)
|
val output = FileOutputStream(fileCached)
|
||||||
|
@ -67,9 +86,11 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun makePresentationView() {
|
private fun makePresentationView() {
|
||||||
|
presentation = null
|
||||||
mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO)?.presentationDisplay?.let { display ->
|
mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO)?.presentationDisplay?.let { display ->
|
||||||
presentation = MyPresentation(this, display)
|
presentation = MyPresentation(this, display)
|
||||||
updatePresentationImages()
|
updatePresentationImages()
|
||||||
|
presentation?.setOnCancelListener { presentation = null }
|
||||||
presentation?.show()
|
presentation?.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,8 +122,26 @@ class MainActivity : AppCompatActivity() {
|
||||||
reLayoutThumbnails()
|
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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
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
|
mediaRouter = getSystemService(Context.MEDIA_ROUTER_SERVICE) as MediaRouter
|
||||||
//val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
|
//val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
|
||||||
//windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) //Doesn't seem to actually fill the vacant space by default
|
//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)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
updateDisplayText()
|
||||||
|
displayManager.registerDisplayListener(displayListener, null)
|
||||||
|
|
||||||
setSupportActionBar(binding.appBarMain.toolbar)
|
setSupportActionBar(binding.appBarMain.toolbar)
|
||||||
|
|
||||||
// Load previous pdf, or included test pdf first
|
// Load previous pdf, or included test pdf first
|
||||||
|
|
|
@ -54,4 +54,18 @@
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
tools:showIn="@layout/content_main" />
|
tools:showIn="@layout/content_main" />
|
||||||
</HorizontalScrollView>
|
</HorizontalScrollView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_displays"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="308dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textSize="20sp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue