Skip to content
Open
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
11 changes: 7 additions & 4 deletions catroid/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import com.android.build.api.dsl.ManagedVirtualDevice

/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2025 The Catrobat Team
* Copyright (C) 2010-2025 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -22,7 +20,6 @@ import com.android.build.api.dsl.ManagedVirtualDevice
* 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/>.
*/

buildscript {
repositories {
google()
Expand Down Expand Up @@ -52,6 +49,7 @@ ext {
projectVersion = "0.9"
gdxVersion = "1.9.10"
mockitoVersion = "3.12.4"
mockkVersion = "1.12.5"
espressoVersion = "3.1.0"
playServicesVersion = '17.0.1'
cameraXVersion = "1.0.0-beta07"
Expand Down Expand Up @@ -492,6 +490,9 @@ dependencies {

testImplementation 'junit:junit:4.13.2'
testImplementation "org.mockito:mockito-core:$mockitoVersion"

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

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

testImplementation 'org.powermock:powermock:1.6.6'
Expand All @@ -512,6 +513,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
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
Expand Up @@ -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-2025 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() {
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
} catch (e: RuntimeException) {
throw e
}
}

@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 "
+ "has been received when stop() is called. This happens if stop() "
+ "is called immediately after start(). The failure lets the application "
+ "take action accordingly to clean up the output file "
+ "(delete the output file, for instance), since the output file "
+ "is not properly constructed when this happens.")
)
}
recorder.reset()
recorder.release()
isRecording = false
}
}
Loading