summaryrefslogtreecommitdiff
path: root/app/src/main/java/no/topi/fiken/display/DisplayService.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/no/topi/fiken/display/DisplayService.java')
-rw-r--r--app/src/main/java/no/topi/fiken/display/DisplayService.java102
1 files changed, 102 insertions, 0 deletions
diff --git a/app/src/main/java/no/topi/fiken/display/DisplayService.java b/app/src/main/java/no/topi/fiken/display/DisplayService.java
new file mode 100644
index 0000000..c907138
--- /dev/null
+++ b/app/src/main/java/no/topi/fiken/display/DisplayService.java
@@ -0,0 +1,102 @@
+package no.topi.fiken.display;
+
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Binder;
+
+public interface DisplayService {
+
+ enum IntentExtra {
+ DEVICE_NAME,
+ DEVICE_ADDRESS,
+ DEVICE_IS_DISPLAY,
+ RSSI,
+ SCANNING,
+ CONNECTED,
+ }
+
+ public static enum IntentAction {
+ DEVICE_UPDATE;
+
+ private final String key = getClass().getName() + "." + name();
+
+ public Intent intent() {
+ return new Intent(key);
+ }
+
+ public static final IntentFilter ALL_FILTER = new IntentFilter() {{
+ for (DefaultDisplayService.IntentAction intentAction : DefaultDisplayService.IntentAction.values()) {
+ addAction(intentAction.key);
+ }
+ }};
+
+ public static IntentAction valueOf(Intent intent) {
+ try {
+ return valueOf(intent.getAction().replaceAll(".*\\.", ""));
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+ }
+
+ public class LocalBinder extends Binder {
+ private final DisplayService service;
+
+ public LocalBinder(DisplayService service) {
+ this.service = service;
+ }
+
+ DisplayService getService() {
+ return service;
+ }
+ }
+
+ boolean initialize();
+
+ void startScan();
+
+ void stopScan();
+
+ boolean connect(String address);
+
+ public void disconnect();
+
+ class DeviceInfo {
+ final String address;
+ int rssi = 0;
+ Boolean isDisplay = null;
+ String name;
+
+ DeviceInfo(String address, int rssi) {
+ this.address = address;
+ this.rssi = rssi;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ DeviceInfo that = (DeviceInfo) o;
+
+ return address.equals(that.address);
+ }
+
+ @Override
+ public int hashCode() {
+ return address.hashCode();
+ }
+
+ public void update(Intent intent) {
+ if (intent.hasExtra(IntentExtra.DEVICE_IS_DISPLAY.name())) {
+ isDisplay = intent.getBooleanExtra(IntentExtra.DEVICE_IS_DISPLAY.name(), false);
+ }
+ if (intent.hasExtra(IntentExtra.RSSI.name())) {
+ rssi = intent.getIntExtra(IntentExtra.RSSI.name(), 0);
+ }
+ if (intent.hasExtra(IntentExtra.DEVICE_NAME.name())) {
+ name = intent.getStringExtra(IntentExtra.DEVICE_NAME.name());
+ }
+ }
+ }
+}