Skip to content

Commit

Permalink
[LEIP-130] Call Digural API on image capture (#63)
Browse files Browse the repository at this point in the history
* Refactor background process to take in some kind of hook class for custom behaviour.

* Integrate updated camera servic into Cyface app and include code to
trigger digural

* Add trigger call to DiGuRaL API

* Add UI Field to set DiGuRaL server address

* [LEIP-137] Fix digural url field in settings fragment

* Dont inject digural address statically

* Upgrade camera service to 4.2.0

* Cleanup and documentation

* Fix build

---------

Co-authored-by: Klemens Muthmann <[email protected]>
  • Loading branch information
hb0 and muthenberg authored Aug 9, 2023
1 parent 1e9a8a4 commit 04ef163
Show file tree
Hide file tree
Showing 32 changed files with 470 additions and 286 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ jobs:
# Executing build here on Ubuntu stack (1/10th costs of MacOS stack)
# Not using "gradle build" as we don't want to run the tests of all dependencies (e.g. backend)
- name: Assemble with Gradle
run: ./gradlew :ui:cyface:assembleDebug :ui:r4r:assembleDebug
run: ./gradlew :ui:cyface:assembleDebug :ui:r4r:assembleDebug :ui:digural:assembleDebug
- name: Test with Gradle
run: ./gradlew :ui:cyface:testDebugUnitTest :ui:r4r:testDebugUnitTest
run: ./gradlew :ui:cyface:testDebugUnitTest :ui:r4r:testDebugUnitTest :ui:digural:testDebugUnitTest
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ext {
cyfaceAndroidBackendVersion = "7.8.1" // Also update submodule commit ref
cyfaceUtilsVersion = "3.5.0"
cyfaceEnergySettingsVersion = "3.3.4" // Also update submodule commit ref
cyfaceCameraServiceVersion = "4.1.12" // Also update submodule commit ref
cyfaceCameraServiceVersion = "4.2.0" // Also update submodule commit ref
// Maybe keep this in sync with the serialization library version used in `uploader` lib
cyfaceSerializationVersion = "2.3.7" // Keep im sync with version in submodule `backend`
cyfaceUploaderVersion = "1.0.0"
Expand Down Expand Up @@ -88,6 +88,8 @@ ext {
chartVersion = "v3.1.0"
// Can't be a SDK dependency as `appAuthRedirectScheme` needs to be defined at build-time
appAuthVersion = "0.11.1" // Can't move to uploader lib because of dependency issues
retrofitVersion = "2.9.0" // Used by digural UI


// Testing
junitVersion = "1.1.5"
Expand Down
2 changes: 1 addition & 1 deletion camera_service
1 change: 1 addition & 0 deletions ui/cyface/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ apply plugin: 'com.google.android.gms.strict-version-matcher-plugin'
apply plugin: 'io.sentry.android.gradle' // Exception tracking when using proguard
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'androidx.navigation.safeargs.kotlin' // recommended to navigate between fragments
apply plugin: 'kotlin-parcelize'

buildscript {
repositories {
Expand Down
1 change: 1 addition & 0 deletions ui/cyface/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:name="android.permission.MANAGE_ACCOUNTS"
android:maxSdkVersion="22" />

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@
import de.cyface.app.R;
import de.cyface.app.button.AbstractButton;
import de.cyface.app.button.ButtonListener;
import de.cyface.app.notification.CameraEventHandler;
import de.cyface.app.utils.CalibrationDialogListener;
import de.cyface.app.utils.Map;
import de.cyface.camera_service.CameraListener;
import de.cyface.camera_service.background.camera.CameraListener;
import de.cyface.camera_service.CameraPreferences;
import de.cyface.camera_service.CameraService;
import de.cyface.camera_service.foreground.CameraService;
import de.cyface.camera_service.Constants;
import de.cyface.camera_service.UIListener;
import de.cyface.datacapturing.CyfaceDataCapturingService;
Expand Down Expand Up @@ -93,6 +94,10 @@
import de.cyface.utils.Validate;
import io.sentry.Sentry;

// TODO: This class has overstretched its intended scope by several orders of magnitude by now.
// The initial idea was to have this contain all the UI code for the button triggering data
// capturing and providing a ViewModel as soon as too much business logic is in here. This is the
// case now. All this stuff should be moved to a or multiple business logic classes soon.
/**
* The button listener for the button to start and stop the data capturing service.
*
Expand Down Expand Up @@ -699,15 +704,24 @@ private void startCameraService(final long measurementId)
final var staticExposureTime = cameraPreferences.getStaticExposureTime();
final var exposureValueIso100 = cameraPreferences.getStaticExposureValue();

cameraService.start(measurementId, videoModeSelected, rawModeSelected, staticFocusSelected,
staticFocusDistance, staticExposureTimeSelected, staticExposureTime, exposureValueIso100,
distanceBasedTriggeringSelected, triggeringDistance,
cameraService.start(
measurementId,
videoModeSelected,
rawModeSelected,
staticFocusSelected,
staticFocusDistance,
staticExposureTimeSelected,
staticExposureTime,
exposureValueIso100,
distanceBasedTriggeringSelected,
triggeringDistance,
new StartUpFinishedHandler(de.cyface.camera_service.MessageCodes.GLOBAL_BROADCAST_SERVICE_STARTED) {
@Override
public void startUpFinished(final long measurementIdentifier) {
Log.v(Constants.TAG, "startCameraService: CameraService startUpFinished");
}
});
}
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package de.cyface.app

import de.cyface.camera_service.CameraService
import de.cyface.camera_service.foreground.CameraService

/**
* Interface which defines the dependencies implemented by the `MainActivity` to be accessible from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import de.cyface.app.dialog.ModalityDialog
import de.cyface.app.ui.button.DataCapturingButton
import de.cyface.app.utils.Map
import de.cyface.app.utils.ServiceProvider
import de.cyface.camera_service.CameraService
import de.cyface.camera_service.foreground.CameraService
import de.cyface.datacapturing.CyfaceDataCapturingService
import de.cyface.datacapturing.persistence.CapturingPersistenceBehaviour
import de.cyface.persistence.DefaultPersistenceLayer
Expand Down
15 changes: 8 additions & 7 deletions ui/cyface/src/main/kotlin/de/cyface/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ import android.accounts.OperationCanceledException
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.location.Location
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.os.Parcel
import android.util.Log
import android.widget.Toast
import androidx.annotation.MainThread
Expand All @@ -45,16 +43,17 @@ import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import de.cyface.app.auth.LoginActivity
import de.cyface.app.button.UnInterestedListener
import de.cyface.app.databinding.ActivityMainBinding
import de.cyface.app.notification.CameraEventHandler
import de.cyface.app.notification.DataCapturingEventHandler
import de.cyface.app.utils.Constants
import de.cyface.app.utils.Constants.ACCOUNT_TYPE
import de.cyface.app.utils.Constants.AUTHORITY
import de.cyface.app.utils.ServiceProvider
import de.cyface.camera_service.CameraListener
import de.cyface.camera_service.CameraPreferences
import de.cyface.camera_service.CameraService
import de.cyface.camera_service.background.camera.CameraListener
import de.cyface.camera_service.foreground.CameraService
import de.cyface.datacapturing.CyfaceDataCapturingService
import de.cyface.datacapturing.DataCapturingListener
import de.cyface.datacapturing.exception.SetupException
Expand Down Expand Up @@ -148,7 +147,8 @@ class MainActivity : AppCompatActivity(), ServiceProvider, CameraServiceProvider
override fun onCapturingStopped() {}
}

private val unInterestedCameraListener: CameraListener = object : CameraListener {
private val unInterestedCameraListener: CameraListener = object :
CameraListener {
override fun onNewPictureAcquired(picturesCaptured: Int) {}
override fun onNewVideoStarted() {}
override fun onVideoStopped() {}
Expand Down Expand Up @@ -211,7 +211,8 @@ class MainActivity : AppCompatActivity(), ServiceProvider, CameraServiceProvider
cameraService = CameraService(
this.applicationContext,
CameraEventHandler(),
unInterestedCameraListener // here was the capturing button but it registers itself, too
unInterestedCameraListener, // here was the capturing button but it registers itself, too
UnInterestedListener()
)
} catch (e: SetupException) {
throw IllegalStateException(e)
Expand Down Expand Up @@ -541,4 +542,4 @@ class MainActivity : AppCompatActivity(), ServiceProvider, CameraServiceProvider
return existingAccounts.isNotEmpty()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2023 Cyface GmbH
*
* This file is part of the Cyface App for Android.
*
* The Cyface App for Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Cyface App for Android 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the Cyface App for Android. If not, see <http://www.gnu.org/licenses/>.
*/
package de.cyface.app.button

import android.content.Context
import android.location.Location
import de.cyface.camera_service.background.ParcelableCapturingProcessListener
import kotlinx.parcelize.Parcelize

@Parcelize
class UnInterestedListener : ParcelableCapturingProcessListener {

override fun contextBasedInitialization(context: Context) {}
override fun onCameraAccessLost() {}
override fun onPictureCaptured() {}
override fun onRecordingStarted() {}
override fun onRecordingStopped() {}
override fun onCameraError(reason: String) {}
override fun onAboutToCapture(measurementId: Long, location: Location?) {}
override fun shallStop() {}
}
Loading

0 comments on commit 04ef163

Please sign in to comment.