Home > OS >  getDisplay() return Display
getDisplay() return Display

Time:10-28

I know it's a really stupid question or a beginner question, but I was trying to replace the windowManager.defaultDisplay.orientation since it's been deprecated and it suggested me to do this. The issue I am having is I see the return value is Display and it confuses me a lot, I don't know or what expects me to put as a returning value. Can someone please help, I know it ain't much but hopefully you could understand that I spend like 25 minutes trying to figure it out. If anybody doesn't understand of the question or have further questions, please let me know. Thank you in advance.

The code:

private fun rotateBitmap(source: Bitmap, angle: Float): Bitmap {
        val matrix = Matrix()
        matrix.postRotate(angle)
        return Bitmap.createBitmap(source, 0, 0, source.width, source.height, matrix, true)
    }

fun getDisplay(displayID: Int): Display {
        when (displayID) {
            Surface.ROTATION_0 -> {
                rotateBitmap(BitmapFactory.decodeFile(photoFile.absolutePath), 0f)
            }
            Surface.ROTATION_90 -> {
                rotateBitmap(BitmapFactory.decodeFile(photoFile.absolutePath), 90f)
            }
            Surface.ROTATION_180 -> {
                rotateBitmap(BitmapFactory.decodeFile(photoFile.absolutePath), 180f)
            }
            Surface.ROTATION_270 -> {
                rotateBitmap(BitmapFactory.decodeFile(photoFile.absolutePath), 270f)
            }
        }
        
        return //The problem is right here, don't know what to return on Display!
    }

CodePudding user response:

Try this :

fun getDisplay(displayID: Int): Display {
    when (displayID) {
        Surface.ROTATION_0 -> {
            rotateBitmap(BitmapFactory.decodeFile(photoFile.absolutePath), 0f)
        }
        Surface.ROTATION_90 -> {
            rotateBitmap(BitmapFactory.decodeFile(photoFile.absolutePath), 90f)
        }
        Surface.ROTATION_180 -> {
            rotateBitmap(BitmapFactory.decodeFile(photoFile.absolutePath), 180f)
        }
        Surface.ROTATION_270 -> {
            rotateBitmap(BitmapFactory.decodeFile(photoFile.absolutePath), 270f)
        }
    }
    val displayManager: DisplayManager =
        applicationContext.getSystemService<Any>(Context.DISPLAY_SERVICE) as DisplayManager
    return displayManager.getDisplay(displayID);
    //This should work!
}

Hope this helps!

  • Related