Skip to content

Commit

Permalink
Merge pull request #4 from GeoTecINIT/inject-service
Browse files Browse the repository at this point in the history
Recording service injection
  • Loading branch information
matey97 authored Sep 29, 2022
2 parents 68603f1 + 5d54c36 commit 19e14b9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To install the library you have to add the dependency in your `build.gradle`:

```groovy
dependencies {
implementation 'io.github.geotecinit:wear-os-sensors:1.0.0'
implementation 'io.github.geotecinit:wear-os-sensors:1.1.0'
}
```

Expand Down
18 changes: 16 additions & 2 deletions wearossensors/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ android {
withJavadocJar()
withSourcesJar()
}

singleVariant('debug') {
withSourcesJar()
}
}
}

Expand All @@ -39,7 +43,7 @@ publishing {
release(MavenPublication) {
groupId = 'io.github.geotecinit'
artifactId = 'wear-os-sensors'
version = '1.0.0'
version = '1.1.0'

afterEvaluate {
from components.release
Expand Down Expand Up @@ -74,6 +78,16 @@ publishing {
}
}
}

debug(MavenPublication) {
groupId = 'io.github.geotecinit'
artifactId = 'wear-os-sensors'
version = '1.1.0-debug'

afterEvaluate {
from components.debug
}
}
}

repositories {
Expand All @@ -96,7 +110,7 @@ dependencies {
implementation 'com.google.android.gms:play-services-wearable:17.1.0'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.google.android.gms:play-services-location:20.0.0'
api 'io.github.geotecinit:background-sensors:1.0.0'
api 'io.github.geotecinit:background-sensors:1.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import es.uji.geotec.wearossensors.permissions.PermissionsManager;
import es.uji.geotec.wearossensors.records.callbacks.RecordCallbackProvider;
import es.uji.geotec.wearossensors.sensor.WearSensor;
import es.uji.geotec.wearossensors.services.WearSensorRecordingService;
import es.uji.geotec.wearossensors.services.RecordingServiceManager;

public abstract class AbstractMessagingHandler {

Expand All @@ -25,7 +25,7 @@ public abstract class AbstractMessagingHandler {

public AbstractMessagingHandler(Context context) {
this.context = context;
this.serviceManager = new ServiceManager(context, WearSensorRecordingService.class);
this.serviceManager = new ServiceManager(context, RecordingServiceManager.getService(context));
}

public void handleMessage(MessageEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package es.uji.geotec.wearossensors.services;

import android.content.Context;
import android.content.SharedPreferences;

public class RecordingServiceManager {

private static final String PREFERENCES_NAME = "WEAROSSENSORS_PREFS";
private static final String RECORDING_SERVICE_KEY = "RECORDING_SERVICE";

public static void setService(Context context, Class<?> permissionsActivity) {
SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString(RECORDING_SERVICE_KEY, permissionsActivity.getName());
editor.apply();
}

public static Class<?> getService(Context context) {
SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
String className = preferences.getString(RECORDING_SERVICE_KEY, WearSensorRecordingService.class.getName());

Class<?> permissionsActivityClass = null;
try {
permissionsActivityClass = Class.forName(className);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return permissionsActivityClass;
}
}

0 comments on commit 19e14b9

Please sign in to comment.