I\'m particularly interested in high contrast text
, color correction
, and magnification
settings. I did some research online, couldn\'t fi
Though reflection solution helps with some devices I was unable to get "isHighTextContrastEnabled" via reflection on my OnePlus 5 device. So I ended up with another method when reflection fails. Just rendering text on a bitmap and then manually checking if there is a specific color (different from black and white) in the bitmap (cause in "High Contrast" mode it will be black and white).
Here is the code in Kotlin:
private fun isHighTextContrastEnabledWithBmp(): Boolean {
val bmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bmp)
val testColor = Color.GREEN
val paint = Paint().apply {
color = testColor
textSize = 5f
}
canvas.drawText("1", 0f, 10f, paint)
val pixels = IntArray(bmp.width * bmp.height)
bmp.getPixels(
pixels, 0, bmp.width,
0, 0, bmp.height, bmp.width
)
val result = pixels.any { it == testColor }.not()
return result
}