Skip to content

Commit

Permalink
PAINTROID-762 Update to Android 14
Browse files Browse the repository at this point in the history
  • Loading branch information
foenabua committed Feb 1, 2025
1 parent 07b8aee commit b775c69
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ class FileFromOtherSourceIntegrationTest {
val fos = requireNonNull.let {
it?.let { it1 -> resolver?.openOutputStream(it1) }
}
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos))
assert(fos != null)
fos?.let { bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it) }
?.let { Assert.assertTrue(it) }
fos!!.close()
} catch (e: IOException) {
throw AssertionError("Picture file could not be created.", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,8 @@ class LayerIntegrationTest {
)
val imageUri = Uri.fromFile(imageFile)
launchActivityRule.activity.myContentResolver.openOutputStream(imageUri).use { fos ->
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos))
fos?.let { bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it) }
?.let { Assert.assertTrue(it) }
}
deletionFileList.add(imageFile)
return imageUri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class MainActivityIntentTest {
try {
val fos = Objects.requireNonNull(imageUri)
?.let { contentResolver?.openOutputStream(it) }
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos))
fos?.let { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
?.let { Assert.assertTrue(it) }
assert(fos != null)
fos?.close()
} catch (e: IOException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ class MenuFileActivityIntegrationTest {
val imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
try {
val fos = imageUri?.let { resolver.openOutputStream(it) }
assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos))
fos?.let { bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it) }
?.let { assertTrue(it) }
assert(fos != null)
fos?.close()
} catch (e: IOException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ class OraFileIntentTest {
val imageUri = resolver!!.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)
try {
val fos = Objects.requireNonNull(imageUri)?.let { resolver!!.openOutputStream(it) }
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos))
fos?.let { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
?.let { Assert.assertTrue(it) }
assert(fos != null)
fos!!.close()
} catch (e: IOException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ class OpenedFromPocketCodeNewImageTest {
val imageUri = Uri.fromFile(imageFile)
try {
val fos = activity?.contentResolver?.openOutputStream(Objects.requireNonNull(imageUri))
Assert.assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos))
fos?.let { bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it) }
?.let { Assert.assertTrue(it) }
assert(fos != null)
fos?.close()
} catch (e: IOException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class OpenedFromPocketCodeWithImageTest {
val fos = activity!!.contentResolver.openOutputStream(
Objects.requireNonNull(uncompressedImageUri)
)
assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos))
assertTrue(fos?.let { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) } == true)
assert(fos != null)
fos!!.close()
} catch (e: IOException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,12 @@ class TextToolIntegrationTest {
testSurfacseBitmapAndPixelAmountAfter()

if (surfaceBitmapHeight != null && canvasPoint != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, 1,
canvasPoint.x.toInt(), 0, 1, surfaceBitmapHeight
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, 1,
canvasPoint.x.toInt(), 0, 1, surfaceBitmapHeight
)
}
}

testPixelAmountBeforeAndPixelDrawingSurface()
Expand All @@ -413,10 +415,12 @@ class TextToolIntegrationTest {

private fun testSurfacseBitmapAndPixelAmountAfter() {
if (surfaceBitmapHeight != null && canvasPoint != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, 1,
canvasPoint.x.toInt(), 0, 1, surfaceBitmapHeight
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, 1,
canvasPoint.x.toInt(), 0, 1, surfaceBitmapHeight
)
}
}
var pixelAmountAfter = pixelsDrawingSurface?.let { countPixelsWithColor(it, Color.BLACK) }
if (pixelAmountAfter != null) {
Expand Down Expand Up @@ -453,19 +457,23 @@ class TextToolIntegrationTest {
layerModel?.currentLayer?.bitmap?.eraseColor(Color.TRANSPARENT)
onTopBarView().performClickCheckmark()
if (surfaceBitmapHeight != null && canvasPoint != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, 1,
canvasPoint.x.toInt(), 0, 1, surfaceBitmapHeight
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, 1,
canvasPoint.x.toInt(), 0, 1, surfaceBitmapHeight
)
}
}
}

private fun testVariablesInIfStatementsWithSurfacseBitmap() {
if (surfaceBitmapHeight != null && canvasPoint != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, 1,
canvasPoint.x.toInt(), 0, 1, surfaceBitmapHeight
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, 1,
canvasPoint.x.toInt(), 0, 1, surfaceBitmapHeight
)
}
}

if (pixelAmountBefore != null) {
Expand Down Expand Up @@ -544,10 +552,12 @@ class TextToolIntegrationTest {
val pixelsDrawingSurface = surfaceBitmapWidth?.let { IntArray(it) }

if (surfaceBitmapWidth != null && canvasPoint != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
}
}

var pixelAmount = pixelsDrawingSurface?.let { countPixelsWithColor(it, Color.BLACK) }
Expand All @@ -556,10 +566,12 @@ class TextToolIntegrationTest {
}
onTopBarView().performUndo()
if (surfaceBitmapWidth != null && canvasPoint != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
}
}

Assert.assertEquals(
Expand All @@ -569,10 +581,12 @@ class TextToolIntegrationTest {
onTopBarView().performRedo()

if (surfaceBitmapWidth != null && canvasPoint != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
}
}

pixelAmount = pixelsDrawingSurface?.let { countPixelsWithColor(it, Color.BLACK) }
Expand Down Expand Up @@ -600,10 +614,12 @@ class TextToolIntegrationTest {
val pixelsDrawingSurface = surfaceBitmapWidth?.let { IntArray(it) }

if (surfaceBitmapWidth != null && canvasPoint != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
}
}

var pixelAmount = pixelsDrawingSurface?.let { countPixelsWithColor(it, Color.WHITE) }
Expand All @@ -618,10 +634,12 @@ class TextToolIntegrationTest {
Assert.assertEquals(Color.BLACK.toLong(), selectedColor?.toLong())
onTopBarView().performClickCheckmark()
if (surfaceBitmapWidth != null && canvasPoint != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
canvasPoint.y.toInt(), surfaceBitmapWidth, 1
)
}
}

pixelAmount = pixelsDrawingSurface?.let { countPixelsWithColor(it, Color.BLACK) }
Expand Down Expand Up @@ -665,10 +683,12 @@ class TextToolIntegrationTest {

if (surfaceBitmapWidth != null) {
textTool?.toolPosition?.y?.let {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
it.toInt(), surfaceBitmapWidth, 1
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
it.toInt(), surfaceBitmapWidth, 1
)
}
}
}

Expand All @@ -688,10 +708,12 @@ class TextToolIntegrationTest {

if (surfaceBitmapWidth != null) {
textTool?.toolPosition?.y?.let {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
it.toInt(), surfaceBitmapWidth, 1
)
if (pixelsDrawingSurface != null) {
layerModel?.currentLayer?.bitmap?.getPixels(
pixelsDrawingSurface, 0, surfaceBitmapWidth, 0,
it.toInt(), surfaceBitmapWidth, 1
)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Paintroid/src/main/java/org/catrobat/paintroid/FileIO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object FileIO {
canvas.drawBitmap(currentBitmap, 0f, 0f, null)
currentBitmap = newBitmap
}
if (currentBitmap != null && !currentBitmap.compress(
if (currentBitmap != null && outputStream != null && !currentBitmap.compress(
compressFormat,
compressQuality,
outputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class ClippingTool(

fun copyBitmapOfCurrentLayer() {
if (workspace.bitmapOfCurrentLayer != null) {
newBitmap = workspace.bitmapOfCurrentLayer?.copy(workspace.bitmapOfCurrentLayer?.config, true)
newBitmap = workspace.bitmapOfCurrentLayer?.config?.let {
workspace.bitmapOfCurrentLayer?.copy(
it, true)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ plugins {
}

ext {
androidCompileSdkVersion = 33
androidCompileSdkVersion = 34
androidMinSdkVersion = 21
androidTargetSdkVersion = 33
androidTargetSdkVersion = 34

androidSupportLibraryVersion = '28.0.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,22 @@ class ZoomableImageView :
override fun onDown(motionEvent: MotionEvent) = false
override fun onShowPress(motionEvent: MotionEvent) = Unit
override fun onSingleTapUp(motionEvent: MotionEvent) = true
override fun onScroll(mE: MotionEvent, mE1: MotionEvent, v: Float, v1: Float) = false
override fun onScroll(
e1: MotionEvent?,
e2: MotionEvent,
distanceX: Float,
distanceY: Float
): Boolean {
TODO("Not yet implemented")
}

override fun onLongPress(motionEvent: MotionEvent) = Unit
override fun onFling(mE: MotionEvent, mE1: MotionEvent, v: Float, v1: Float) = false
override fun onFling(
e1: MotionEvent?,
e2: MotionEvent,
velocityX: Float,
velocityY: Float
): Boolean {
TODO("Not yet implemented")
}
}

0 comments on commit b775c69

Please sign in to comment.