Skip to content

Commit

Permalink
Merge pull request #5483 from Isira-Seneviratne/HDR_check_improvement
Browse files Browse the repository at this point in the history
refactor: Improve HDR check
  • Loading branch information
Isira-Seneviratne authored Jan 13, 2024
2 parents 444eb69 + 8bd59db commit 98043d3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/src/main/java/com/github/libretube/helpers/DisplayHelper.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package com.github.libretube.helpers

import android.content.Context
import android.hardware.display.DisplayManager
import android.os.Build
import android.view.Display
import androidx.core.content.ContextCompat

object DisplayHelper {
/**
* Detect whether the device supports HDR as the ExoPlayer doesn't handle it properly
* Returns false on and below SDK 24
* Returns false below SDK 24
*/
fun supportsHdr(context: Context): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
context.getSystemService(DisplayManager::class.java).getDisplay(Display.DEFAULT_DISPLAY)
.hdrCapabilities.supportedHdrTypes.isNotEmpty()
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val display = ContextCompat.getDisplayOrDefault(context)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
display.isHdr
} else {
@Suppress("DEPRECATION")
display.hdrCapabilities?.supportedHdrTypes?.isNotEmpty() ?: false
}
} else {
false
}
}
}

0 comments on commit 98043d3

Please sign in to comment.