diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index addda01..5ed45e0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,9 +1,10 @@
+ android:versionCode="14"
+ android:versionName="2.3.3">
+
@@ -97,4 +98,4 @@
android:label="@string/title_activity_settings" />
-
+
\ No newline at end of file
diff --git a/app/src/main/java/science/apolline/service/sensor/IOIOService.kt b/app/src/main/java/science/apolline/service/sensor/IOIOService.kt
index 6265473..d7d2e12 100644
--- a/app/src/main/java/science/apolline/service/sensor/IOIOService.kt
+++ b/app/src/main/java/science/apolline/service/sensor/IOIOService.kt
@@ -19,6 +19,7 @@ import com.github.salomonbrys.kodein.instance
import com.google.android.gms.location.LocationRequest
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
+import io.reactivex.functions.BiFunction
import io.reactivex.schedulers.Schedulers
import ioio.lib.api.AnalogInput
import ioio.lib.api.DigitalOutput
@@ -36,9 +37,11 @@ import science.apolline.models.IOIOData
import science.apolline.models.Position
import science.apolline.service.database.SensorDao
import science.apolline.utils.CheckUtility
+import science.apolline.utils.DetectedActivityToString
import java.io.IOException
import java.io.InputStream
import science.apolline.utils.GeoHashHelper
+import science.apolline.utils.ToMostProbableActivity
import science.apolline.view.activity.MainActivity
@@ -53,15 +56,15 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger {
private val mPrefs by injector.instance()
- private var DEVICE_NAME= "Apolline00"
+ private var DEVICE_NAME = "Apolline00"
private var DEVICE_UUID = "ffffffff-ffff-ffff-ffff-ffffffffffff"
override fun createIOIOLooper(): IOIOLooper {
injector.inject(appKodein())
- DEVICE_NAME= mPrefs.getString("device_name","Apolline00")
- DEVICE_UUID = mPrefs.getString("device_uuid","ffffffff-ffff-ffff-ffff-ffffffffffff")
+ DEVICE_NAME = mPrefs.getString("device_name", "Apolline00")
+ DEVICE_UUID = mPrefs.getString("device_uuid", "ffffffff-ffff-ffff-ffff-ffffffffffff")
return object : BaseIOIOLooper() {
private val data = IOIOData()
@@ -89,20 +92,36 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger {
@Throws(ConnectionLostException::class, InterruptedException::class)
override fun loop() {
+
+
try {
- if (CheckUtility.checkFineLocationPermission(applicationContext) && CheckUtility.canGetLocation(applicationContext))
- disposable.add(locationProvider.getUpdatedLocation(request)
- .onExceptionResumeNext(Observable.empty())
- .subscribeOn(Schedulers.io())
- .observeOn(Schedulers.io())
- .subscribe { t ->
- if (t == null)
- info("Get location error")
- else
- position = Position(t.provider, GeoHashHelper.encode(t.latitude, t.longitude), "no")
- }
+ if (CheckUtility.checkFineLocationPermission(applicationContext) && CheckUtility.canGetLocation(applicationContext)) {
+ disposable.add(
+
+ Observable.zip(
+ locationProvider.getUpdatedLocation(request).subscribeOn(Schedulers.io()),
+ locationProvider.getDetectedActivity(0)
+ .map(ToMostProbableActivity())
+ .map(DetectedActivityToString())
+ .subscribeOn(Schedulers.io()),
+ BiFunction> { currentLocation, currentActivity ->
+ Pair(currentLocation, currentActivity)
+ }
+
+ )
+ .onExceptionResumeNext(Observable.empty())
+ .onErrorReturn {
+ error("Error location pair not found $it")
+ }
+ .observeOn(Schedulers.io())
+ .subscribe { t ->
+ if (t == null)
+ info("Get location error")
+ else
+ position = Position(t.first.provider, GeoHashHelper.encode(t.first.latitude, t.first.longitude), t.second)
+ }
)
- else
+ } else
position = Position()
val dataAvailability = this.inputStream!!.available()
@@ -209,11 +228,11 @@ class IOIOService : ioio.lib.util.android.IOIOService(), AnkoLogger {
private var mServiceStatus: Boolean = false
- fun getServiceStatus():Boolean{
+ fun getServiceStatus(): Boolean {
return mServiceStatus
}
- fun setServiceStatus(status:Boolean){
+ fun setServiceStatus(status: Boolean) {
mServiceStatus = status
}
diff --git a/app/src/main/java/science/apolline/utils/DataExport.kt b/app/src/main/java/science/apolline/utils/DataExport.kt
index bc8e1cb..4eaf464 100644
--- a/app/src/main/java/science/apolline/utils/DataExport.kt
+++ b/app/src/main/java/science/apolline/utils/DataExport.kt
@@ -41,7 +41,7 @@ object DataExport : AnkoLogger {
add("Longitude")
add("Latitude")
add("Provider")
- add("Transport")
+ add("Transport_:_Confidence")
}
data!!.entrySet().iterator().forEach {
diff --git a/app/src/main/java/science/apolline/utils/DetectedActivityToString.kt b/app/src/main/java/science/apolline/utils/DetectedActivityToString.kt
new file mode 100644
index 0000000..5c9eb88
--- /dev/null
+++ b/app/src/main/java/science/apolline/utils/DetectedActivityToString.kt
@@ -0,0 +1,26 @@
+package science.apolline.utils
+
+import com.google.android.gms.location.DetectedActivity
+import io.reactivex.functions.Function
+
+/**
+ * Created by sparow on 3/25/2018.
+ */
+class DetectedActivityToString : Function {
+ override fun apply(detectedActivity: DetectedActivity): String {
+ return getNameFromType(detectedActivity.type) + " : " + detectedActivity.confidence
+ }
+
+ private fun getNameFromType(activityType: Int): String {
+ when (activityType) {
+ DetectedActivity.RUNNING -> return "running"
+ DetectedActivity.IN_VEHICLE -> return "in_vehicle"
+ DetectedActivity.ON_BICYCLE -> return "on_bicycle"
+ DetectedActivity.ON_FOOT -> return "on_foot"
+ DetectedActivity.STILL -> return "still"
+ DetectedActivity.UNKNOWN -> return "unknown"
+ DetectedActivity.TILTING -> return "tilting"
+ }
+ return "unknown"
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/science/apolline/utils/ToMostProbableActivity.kt b/app/src/main/java/science/apolline/utils/ToMostProbableActivity.kt
new file mode 100644
index 0000000..d893384
--- /dev/null
+++ b/app/src/main/java/science/apolline/utils/ToMostProbableActivity.kt
@@ -0,0 +1,14 @@
+package science.apolline.utils
+
+import com.google.android.gms.location.ActivityRecognitionResult
+import com.google.android.gms.location.DetectedActivity
+import io.reactivex.functions.Function
+
+/**
+ * Created by sparow on 3/25/2018.
+ */
+class ToMostProbableActivity : Function {
+ override fun apply(activityRecognitionResult: ActivityRecognitionResult): DetectedActivity {
+ return activityRecognitionResult.mostProbableActivity
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/science/apolline/view/fragment/IOIOFragment.kt b/app/src/main/java/science/apolline/view/fragment/IOIOFragment.kt
index 473f030..987b5c9 100644
--- a/app/src/main/java/science/apolline/view/fragment/IOIOFragment.kt
+++ b/app/src/main/java/science/apolline/view/fragment/IOIOFragment.kt
@@ -123,7 +123,7 @@ class IOIOFragment : RootFragment(), FragmentLifecycle, AnkoLogger {
Flowable.empty()
}
.onErrorReturn {
- error("Error device list not fount $it")
+ error("Error device list not found $it")
}
.subscribe {
if (it.isNotEmpty()) {