Loading libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/desktopmode/ManageWindowsViewContainer.kt +31 −1 Original line number Diff line number Diff line Loading @@ -122,7 +122,8 @@ abstract class ManageWindowsViewContainer( snapshot.hardwareBuffer, snapshot.colorSpace ) val scaledSnapshotBitmap = snapshotBitmap?.let { val croppedBitmap = snapshotBitmap?.let { cropBitmap(it) } val scaledSnapshotBitmap = croppedBitmap?.let { Bitmap.createScaledBitmap( it, instanceIconWidth.toInt(), instanceIconHeight.toInt(), true /* filter */ ) Loading Loading @@ -160,6 +161,35 @@ abstract class ManageWindowsViewContainer( menuHeight += iconMargin.toInt() } private fun cropBitmap( bitmapToCrop: Bitmap ): Bitmap { val ratioToMatch = ICON_WIDTH_DP / ICON_HEIGHT_DP val bitmapWidth = bitmapToCrop.width val bitmapHeight = bitmapToCrop.height if (bitmapWidth > bitmapHeight * ratioToMatch) { // Crop based on height val newWidth = bitmapHeight * ratioToMatch return Bitmap.createBitmap( bitmapToCrop, ((bitmapWidth - newWidth) / 2).toInt(), 0, newWidth.toInt(), bitmapHeight ) } else { // Crop based on width val newHeight = bitmapWidth / ratioToMatch return Bitmap.createBitmap( bitmapToCrop, 0, ((bitmapHeight - newHeight) / 2).toInt(), bitmapWidth, newHeight.toInt() ) } } companion object { private const val MENU_RADIUS_DP = 26f private const val ICON_WIDTH_DP = 204f Loading Loading
libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/desktopmode/ManageWindowsViewContainer.kt +31 −1 Original line number Diff line number Diff line Loading @@ -122,7 +122,8 @@ abstract class ManageWindowsViewContainer( snapshot.hardwareBuffer, snapshot.colorSpace ) val scaledSnapshotBitmap = snapshotBitmap?.let { val croppedBitmap = snapshotBitmap?.let { cropBitmap(it) } val scaledSnapshotBitmap = croppedBitmap?.let { Bitmap.createScaledBitmap( it, instanceIconWidth.toInt(), instanceIconHeight.toInt(), true /* filter */ ) Loading Loading @@ -160,6 +161,35 @@ abstract class ManageWindowsViewContainer( menuHeight += iconMargin.toInt() } private fun cropBitmap( bitmapToCrop: Bitmap ): Bitmap { val ratioToMatch = ICON_WIDTH_DP / ICON_HEIGHT_DP val bitmapWidth = bitmapToCrop.width val bitmapHeight = bitmapToCrop.height if (bitmapWidth > bitmapHeight * ratioToMatch) { // Crop based on height val newWidth = bitmapHeight * ratioToMatch return Bitmap.createBitmap( bitmapToCrop, ((bitmapWidth - newWidth) / 2).toInt(), 0, newWidth.toInt(), bitmapHeight ) } else { // Crop based on width val newHeight = bitmapWidth / ratioToMatch return Bitmap.createBitmap( bitmapToCrop, 0, ((bitmapHeight - newHeight) / 2).toInt(), bitmapWidth, newHeight.toInt() ) } } companion object { private const val MENU_RADIUS_DP = 26f private const val ICON_WIDTH_DP = 204f Loading