Skip to content

Commit 19e14b9

Browse files
authored
Merge pull request #4 from GeoTecINIT/inject-service
Recording service injection
2 parents 68603f1 + 5d54c36 commit 19e14b9

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To install the library you have to add the dependency in your `build.gradle`:
2828

2929
```groovy
3030
dependencies {
31-
implementation 'io.github.geotecinit:wear-os-sensors:1.0.0'
31+
implementation 'io.github.geotecinit:wear-os-sensors:1.1.0'
3232
}
3333
```
3434

wearossensors/build.gradle

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ android {
3131
withJavadocJar()
3232
withSourcesJar()
3333
}
34+
35+
singleVariant('debug') {
36+
withSourcesJar()
37+
}
3438
}
3539
}
3640

@@ -39,7 +43,7 @@ publishing {
3943
release(MavenPublication) {
4044
groupId = 'io.github.geotecinit'
4145
artifactId = 'wear-os-sensors'
42-
version = '1.0.0'
46+
version = '1.1.0'
4347

4448
afterEvaluate {
4549
from components.release
@@ -74,6 +78,16 @@ publishing {
7478
}
7579
}
7680
}
81+
82+
debug(MavenPublication) {
83+
groupId = 'io.github.geotecinit'
84+
artifactId = 'wear-os-sensors'
85+
version = '1.1.0-debug'
86+
87+
afterEvaluate {
88+
from components.debug
89+
}
90+
}
7791
}
7892

7993
repositories {
@@ -96,7 +110,7 @@ dependencies {
96110
implementation 'com.google.android.gms:play-services-wearable:17.1.0'
97111
implementation 'com.google.code.gson:gson:2.9.0'
98112
implementation 'com.google.android.gms:play-services-location:20.0.0'
99-
api 'io.github.geotecinit:background-sensors:1.0.0'
113+
api 'io.github.geotecinit:background-sensors:1.1.0'
100114
testImplementation 'junit:junit:4.13.2'
101115
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
102116
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

wearossensors/src/main/java/es/uji/geotec/wearossensors/messaging/handlers/AbstractMessagingHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import es.uji.geotec.wearossensors.permissions.PermissionsManager;
1717
import es.uji.geotec.wearossensors.records.callbacks.RecordCallbackProvider;
1818
import es.uji.geotec.wearossensors.sensor.WearSensor;
19-
import es.uji.geotec.wearossensors.services.WearSensorRecordingService;
19+
import es.uji.geotec.wearossensors.services.RecordingServiceManager;
2020

2121
public abstract class AbstractMessagingHandler {
2222

@@ -25,7 +25,7 @@ public abstract class AbstractMessagingHandler {
2525

2626
public AbstractMessagingHandler(Context context) {
2727
this.context = context;
28-
this.serviceManager = new ServiceManager(context, WearSensorRecordingService.class);
28+
this.serviceManager = new ServiceManager(context, RecordingServiceManager.getService(context));
2929
}
3030

3131
public void handleMessage(MessageEvent event) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package es.uji.geotec.wearossensors.services;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
6+
public class RecordingServiceManager {
7+
8+
private static final String PREFERENCES_NAME = "WEAROSSENSORS_PREFS";
9+
private static final String RECORDING_SERVICE_KEY = "RECORDING_SERVICE";
10+
11+
public static void setService(Context context, Class<?> permissionsActivity) {
12+
SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
13+
SharedPreferences.Editor editor = preferences.edit();
14+
editor.putString(RECORDING_SERVICE_KEY, permissionsActivity.getName());
15+
editor.apply();
16+
}
17+
18+
public static Class<?> getService(Context context) {
19+
SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
20+
String className = preferences.getString(RECORDING_SERVICE_KEY, WearSensorRecordingService.class.getName());
21+
22+
Class<?> permissionsActivityClass = null;
23+
try {
24+
permissionsActivityClass = Class.forName(className);
25+
} catch (ClassNotFoundException e) {
26+
e.printStackTrace();
27+
}
28+
return permissionsActivityClass;
29+
}
30+
}

0 commit comments

Comments
 (0)