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 10, 2025
1 parent 07b8aee commit 7a2eabd
Show file tree
Hide file tree
Showing 23 changed files with 154 additions and 109 deletions.
50 changes: 25 additions & 25 deletions Paintroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

apply plugin: 'com.android.library'
apply plugin: 'com.hiya.jacoco-android'
apply plugin: "com.mxalbert.gradle.jacoco-android"
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'kotlin-android'
apply plugin: 'org.catrobat.gradle.androidemulators'
Expand Down Expand Up @@ -51,14 +51,14 @@ emulators {
}

jacoco {
toolVersion = "0.8.7"
toolVersion = "0.8.10"
}

jacocoAndroidUnitTestReport {
csv.enabled false
html.enabled true
xml.enabled true
destination project.getBuildDir().getPath() + "/reports/jacoco/jacocoTestDebugUnitTestReport"
csv.required = false
html.required = true
xml.required = true
destination = project.getBuildDir().getPath() + "/reports/jacoco/jacocoTestDebugUnitTestReport"
}

android {
Expand All @@ -68,8 +68,6 @@ android {
minSdkVersion rootProject.ext.androidMinSdkVersion
targetSdkVersion rootProject.ext.androidTargetSdkVersion
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
versionCode rootProject.ext.androidVersionCode
versionName rootProject.ext.androidVersionName
}

compileOptions {
Expand All @@ -85,33 +83,36 @@ android {
signedRelease {
}
debug {
testCoverageEnabled = project.hasProperty('enableCoverage')
// Multidex is required as espresso and mockito/bytebuddy are adding more functions
// than should be allowed by law.
// See https://github.com/mockito/mockito/issues/1112
multiDexEnabled true
enableUnitTestCoverage = 'project.hasProperty(\'enableCoverage\')'
enableAndroidTestCoverage = 'project.hasProperty(\'enableCoverage\')'
}
}

lintOptions {
// specific ignores should be defined via lint.xml file
lintConfig file('config/lint.xml')
ignore 'ClickableViewAccessibility', 'StaticFieldLeak', 'GradleDependency', 'OldTargetApi', 'LintBaseline'
textReport true
xmlReport true
htmlReport true
xmlOutput file("build/reports/lint-report.xml")
htmlOutput file("build/reports/lint-report.html")
}

testOptions {
unitTests.returnDefaultValues = true
animationsDisabled = true
}

packagingOptions {
exclude "META-INF/AL2.0"
exclude "META-INF/LGPL2.1"
resources {
excludes += ['META-INF/AL2.0', 'META-INF/LGPL2.1', "**/attach_hotspot_windows.dll"]
merges += ['META-INF/licenses/ASM']
}
}

namespace 'org.catrobat.paintroid'
lint {
htmlOutput file('build/reports/lint-report.html')
htmlReport true
ignore 'ClickableViewAccessibility', 'StaticFieldLeak', 'GradleDependency', 'OldTargetApi', 'LintBaseline'
lintConfig file('config/lint.xml')
textReport true
xmlOutput file('build/reports/lint-report.xml')
xmlReport true
}
}

Expand All @@ -135,16 +136,15 @@ dependencies {
implementation 'com.jraska:falcon:2.2.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.18.3'
testImplementation 'org.mockito:mockito-core:3.6.28'
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'

androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'org.mockito:mockito-android:2.18.3'
androidTestImplementation 'org.mockito:mockito-android:5.15.2'
androidTestImplementation 'tools.fastlane:screengrab:2.1.0'
androidTestImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
Expand Down
6 changes: 3 additions & 3 deletions Paintroid/gradle/code_quality_tasks.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ task checkstyle(type: Checkstyle) {
ignoreFailures false

reports {
xml.enabled = true
xml.required = true
xml.destination file("build/reports/checkstyle.xml")
}
}
Expand All @@ -63,8 +63,8 @@ task pmd(type: Pmd) {
ignoreFailures false

reports {
xml.enabled = true
html.enabled = true
xml.required = true
html.required = true
xml.destination file("build/reports/pmd.xml")
}
}
Expand Down
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
1 change: 0 additions & 1 deletion Paintroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.catrobat.paintroid"
android:installLocation="auto">

<uses-permission android:name="android.permission.INTERNET"/>
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
Loading

0 comments on commit 7a2eabd

Please sign in to comment.