-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5483 from Isira-Seneviratne/HDR_check_improvement
refactor: Improve HDR check
- Loading branch information
Showing
1 changed file
with
13 additions
and
6 deletions.
There are no files selected for viewing
19 changes: 13 additions & 6 deletions
19
app/src/main/java/com/github/libretube/helpers/DisplayHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |