Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio indicators computed in koin service #11

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0ac1dda
remove compose extended icons dependency
nicolas-f Mar 13, 2024
33d3a5b
do not redraw axe when updating spectrogram data
nicolas-f Mar 13, 2024
c8e8532
better x axis
nicolas-f Mar 13, 2024
34e6418
better refresh of spectrogram
nicolas-f Mar 13, 2024
6004f88
change lbl
nicolas-f Mar 14, 2024
87282b8
add database code into nc
nicolas-f Mar 14, 2024
8bbc8d8
Move measurement to service in order to avoid shutdown
nicolas-f Mar 15, 2024
109ef7f
update compose multiplatform
nicolas-f Mar 18, 2024
8664a27
progress in android service feature foreground service for measurements
nicolas-f Mar 18, 2024
7ce01dd
Use android service for long running forward tasks
nicolas-f Mar 25, 2024
f93f331
build legend with at least left and right time axis legend
nicolas-f Mar 25, 2024
6046973
sql add frequencies
nicolas-f Mar 25, 2024
aa10494
rename measurement serce, have to devise a method to manage database …
nicolas-f Mar 26, 2024
6f41edf
try to keep regular x legend steps
nicolas-f Mar 27, 2024
ebc6211
Catch window state (background state on android)
nicolas-f Mar 27, 2024
9f540b1
Merge branch 'uidev' of github.com:nicolas-f/NoiseCaptureKotlin into …
nicolas-f Mar 28, 2024
d86d3dc
Use factory for android audio source
nicolas-f Mar 28, 2024
785ff34
Do not collect audio samples in measurement screen but connect to mea…
nicolas-f Mar 29, 2024
be0cda7
functions measurement service
nicolas-f Mar 29, 2024
8b7e5e2
rework, MeasurementService will collect and store data from various s…
nicolas-f Apr 2, 2024
6d4a2c6
forget laeq indicator
nicolas-f Apr 2, 2024
328ce92
Add tabs ui without content (except spectrogram), spectrum, spectrogr…
nicolas-f Apr 2, 2024
e52bf5c
if android permissions is not granded it is denied not unknown
nicolas-f Apr 3, 2024
ea84bec
logging and js service
nicolas-f Apr 3, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ jobs:
with:
key: noisecapturejs
path: |
$GITHUB_WORKSPACE/webApp/build
webApp/build
shared/build
- name: Build
run: >
./gradlew
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ build/
.cxx
local.properties
venv/
yarn.lock
5 changes: 5 additions & 0 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:allowBackup="true"
Expand All @@ -29,6 +30,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service android:name=".AndroidMeasurementService"
android:foregroundServiceType="location|microphone"
/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.noise_planet.noisecapture.starter

import android.annotation.SuppressLint
import android.app.Activity
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle
import android.os.IBinder
import androidx.activity.compose.setContent
import androidx.compose.ui.platform.LocalLifecycleOwner
import com.bumble.appyx.navigation.integration.NodeActivity
Expand All @@ -12,28 +17,86 @@ import org.koin.android.logger.AndroidLogger
import org.koin.core.context.stopKoin
import org.koin.dsl.module
import org.noise_planet.noisecapture.AndroidAudioSource
import org.noise_planet.noisecapture.AudioSource
import org.noise_planet.noisecapture.AndroidDatabase
import org.noise_planet.noisecapture.AndroidMeasurementService
import org.noise_planet.noisecapture.DatabaseDriverFactory
import org.noise_planet.noisecapture.shared.MeasurementService
import org.noise_planet.noisecapture.shared.initKoin
import org.noise_planet.noisecapture.shared.root.RootNode
import org.noise_planet.noisecapture.shared.ui.theme.AppyxStarterKitTheme
import kotlin.reflect.KProperty

class MainActivity : NodeActivity() {
val androidLogger = AndroidLogger()

private val foregroundServiceConnection = ForegroundServiceConnection()
internal class ForegroundServiceConnection : ServiceConnection {
@SuppressLint("MissingPermission")
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
println("onServiceConnected $name $service")
// This is called when the connection with the service has been
// established, giving us the service object we can use to
// interact with the service. Because we have bound to a explicit
// service that we know is running in our own process, we can
// cast its IBinder to a concrete class and directly access it.
if(service != null) {
val androidMeasurementService =
(service as AndroidMeasurementService.LocalBinder).service

}
}

override fun onServiceDisconnected(name: ComponentName?) {

}
}

override fun onDestroy() {
super.onDestroy()
stopKoin()
}

override fun onRestart() {
super.onRestart()
println("onRestart")
}

override fun onStop() {
super.onStop()
println("OnStop")
}

fun onStorageStateChange(property : KProperty<*>, oldValue :Boolean, newValue: Boolean) {
// bind this application context to Android Foreground service if storage is launched
// in order to avoid application shutdown by Android when moved in background
if(newValue) {
val intent = Intent(applicationContext, AndroidMeasurementService::class.java)
if (applicationContext.bindService(intent, foregroundServiceConnection,
Context.BIND_AUTO_CREATE)) {
androidLogger.info("Bind with foreground service")
} else{
androidLogger.info("Can't bind with foreground service")
}
} else {
applicationContext.unbindService(foregroundServiceConnection)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val koinApplication = initKoin(
additionalModules = listOf(
module {
single<Context> { applicationContext }
single<Activity> { this@MainActivity }
single<AudioSource> { AndroidAudioSource() }
single<MeasurementService> {
val measurementService = MeasurementService(AndroidAudioSource(logger), androidLogger)
measurementService.storageObservers.add(::onStorageStateChange)
measurementService}
single<DatabaseDriverFactory> { AndroidDatabase(applicationContext) }
}
)
).logger(AndroidLogger())
).logger(androidLogger)
setContent {
AppyxStarterKitTheme {
NodeHost(
Expand Down
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ agp = "8.1.1"
android-compile-sdk = "34"
android-min-sdk = "23"
android-target-sdk = "32"
androidDriver = "2.0.1"
androidx-activity-compose = "1.8.2"
androidx-lifecycle = "2.7.0"
androidx-test-espresso-core = "3.5.1"
Expand All @@ -25,8 +26,11 @@ appcompat = "1.6.1"
kotxresources= "0.4.0"
kotxdatetime = "0.5.0"
kotlinWrappersVersion = "1.0.0-pre.700"
sqliteFramework = "2.4.0"

[libraries]
androidx-sqlite-framework = { module = "androidx.sqlite:sqlite-framework", version.ref = "sqliteFramework" }
sqldelight-android-driver = { module = "app.cash.sqldelight:android-driver", version.ref = "androidDriver" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" }
androidx-core = { module = "androidx.core:core-ktx", version.ref = "core-ktx" }
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" }
Expand All @@ -49,5 +53,7 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
kotlinx-resources-test = { module = "com.goncalossilva:resources", version.ref = "kotxresources" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotxdatetime" }
kotlin-browser = { module = "org.jetbrains.kotlin-wrappers:kotlin-browser", version.ref = "kotlinWrappersVersion" }
sqldelight-native-driver = { module = "app.cash.sqldelight:native-driver", version.ref = "androidDriver" }
sqldelight-driver = { module = "app.cash.sqldelight:web-worker-driver", version.ref = "androidDriver" }


Loading
Loading