Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion catroid/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2025 The Catrobat Team
* Copyright (C) 2010-2026 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -54,6 +54,7 @@ ext {
projectVersion = "0.9"
gdxVersion = "1.13.0"
mockitoVersion = '5.14.2'
mockkVersion = "1.14.7"
espressoVersion = '3.6.1'
playServicesVersion = '18.1.1'
cameraXVersion = '1.4.0'
Expand Down Expand Up @@ -478,6 +479,8 @@ dependencies {

testImplementation "org.mockito:mockito-core:$mockitoVersion"

testImplementation "io.mockk:mockk:${mockkVersion}"

testImplementation 'org.hamcrest:hamcrest-library:1.3'

testImplementation 'org.robolectric:robolectric:4.16'
Expand All @@ -494,6 +497,8 @@ dependencies {
androidTestImplementation "org.mockito:mockito-android:$mockitoVersion"
androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"

androidTestImplementation "io.mockk:mockk-android:${mockkVersion}"

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2025 The Catrobat Team
* Copyright (C) 2010-2026 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -28,6 +28,9 @@ import android.graphics.Rect
import androidx.test.annotation.UiThreadTest
import androidx.test.core.app.ApplicationProvider
import androidx.test.rule.GrantPermissionRule
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.catrobat.catroid.ProjectManager
import org.catrobat.catroid.camera.VisualDetectionHandler.facesForSensors
import org.catrobat.catroid.camera.VisualDetectionHandler.updateFaceDetectionStatusSensorValues
Expand All @@ -44,7 +47,6 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.mockito.Mockito

class SensorHandlerTest {
@get:Rule
Expand Down Expand Up @@ -118,18 +120,19 @@ class SensorHandlerTest {
@UiThreadTest
fun testMicRelease() {
val loudnessSensor = SensorLoudness()
val soundRecorder = Mockito.mock(SoundRecorder::class.java)
val soundRecorder = mockk<SoundRecorder>(relaxed = true)
loudnessSensor.soundRecorder = soundRecorder

Mockito.`when`(soundRecorder.isRecording).thenReturn(false)
SensorHandler.getInstance(ApplicationProvider.getApplicationContext()).setSensorLoudness(loudnessSensor)
every { soundRecorder.isRecording } returns false
SensorHandler.getInstance(ApplicationProvider.getApplicationContext())
.setSensorLoudness(loudnessSensor)

SensorHandler.startSensorListener(ApplicationProvider.getApplicationContext())
Mockito.`when`(soundRecorder.isRecording).thenReturn(true)
Mockito.verify(soundRecorder).start()
every { soundRecorder.isRecording } returns true
verify { soundRecorder.start() }

SensorHandler.stopSensorListeners()
Mockito.verify(soundRecorder).stop()
verify { soundRecorder.stop() }
}

@After
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2025 The Catrobat Team
* Copyright (C) 2010-2026 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -20,38 +20,23 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.catrobat.catroid.soundrecorder;
package org.catrobat.catroid.soundrecorder

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageButton;
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.widget.ImageButton

@SuppressLint("AppCompatCustomView")
public class RecordButton extends ImageButton {
private RecordState state = RecordState.STOP;
class RecordButton @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0
) : ImageButton(context, attrs, defStyle) {

public RecordButton(Context context) {
super(context);
}
var state: RecordState = RecordState.STOP

public RecordButton(Context context, AttributeSet attrs) {
super(context, attrs);
}

public RecordButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public RecordState getState() {
return state;
}

public void setState(RecordState state) {
this.state = state;
}

public enum RecordState {
RECORD, STOP;
}
enum class RecordState {
RECORD, STOP
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2026 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.catrobat.catroid.soundrecorder

import android.media.MediaRecorder
import android.util.Log
import java.io.File
import java.io.IOException

class SoundRecorder @JvmOverloads constructor(
val path: String,
private val recorder: MediaRecorder = MediaRecorder()
) {
var isRecording: Boolean = false
private set

val maxAmplitude: Int
get() = recorder.maxAmplitude

companion object {
private val TAG: String = SoundRecorder::class.java.simpleName
}

@Throws(IOException::class, RuntimeException::class)
fun start() {

Check warning

Code scanning / detekt

Restrict the number of throw statements in methods. Warning

Too many throw statements in the function start. The maximum number of allowed throw statements is 2.
val soundFile = File(path)
if (soundFile.exists() && !soundFile.delete()) {
throw IOException("Could not delete existing file at $path")
}
val directory = soundFile.parentFile
if (directory == null || (!directory.exists() && !directory.mkdirs())) {
throw IOException("Path to file could not be created.")
}

try {
recorder.reset()
recorder.setAudioSource(MediaRecorder.AudioSource.MIC)
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
recorder.setOutputFile(path)
recorder.prepare()
recorder.start()
isRecording = true
} catch (e: IllegalStateException) {
throw e

Check warning

Code scanning / detekt

Do not rethrow a caught exception of the same type. Warning

Do not rethrow a caught exception of the same type.
} catch (e: RuntimeException) {

Check warning

Code scanning / detekt

The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled. Warning

The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.
throw e

Check warning

Code scanning / detekt

Do not rethrow a caught exception of the same type. Warning

Do not rethrow a caught exception of the same type.
}
}

@Throws(IOException::class)
fun stop() {
try {
recorder.stop()
} catch (_: RuntimeException) {
Log.d(
TAG, ("Note that a RuntimeException is intentionally "
+ "thrown to the application, if no valid audio/video data "

Check warning

Code scanning / detekt

Checks if condition chaining is wrapped right Warning

Line must not begin with "+"
+ "has been received when stop() is called. This happens if stop() "

Check warning

Code scanning / detekt

Checks if condition chaining is wrapped right Warning

Line must not begin with "+"
+ "is called immediately after start(). The failure lets the application "

Check warning

Code scanning / detekt

Checks if condition chaining is wrapped right Warning

Line must not begin with "+"
+ "take action accordingly to clean up the output file "

Check warning

Code scanning / detekt

Checks if condition chaining is wrapped right Warning

Line must not begin with "+"
+ "(delete the output file, for instance), since the output file "

Check warning

Code scanning / detekt

Checks if condition chaining is wrapped right Warning

Line must not begin with "+"
+ "is not properly constructed when this happens.")

Check warning

Code scanning / detekt

Checks if condition chaining is wrapped right Warning

Line must not begin with "+"
)
}
recorder.reset()
recorder.release()
isRecording = false
}
}
Loading
Loading