diff --git a/MusicController/.classpath b/MusicController/.classpath
new file mode 100644
index 0000000..5176974
--- /dev/null
+++ b/MusicController/.classpath
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/MusicController/.project b/MusicController/.project
new file mode 100644
index 0000000..6d412d5
--- /dev/null
+++ b/MusicController/.project
@@ -0,0 +1,33 @@
+
+
+ MusicController
+
+
+
+
+
+ com.android.ide.eclipse.adt.ResourceManagerBuilder
+
+
+
+
+ com.android.ide.eclipse.adt.PreCompilerBuilder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ com.android.ide.eclipse.adt.ApkBuilder
+
+
+
+
+
+ com.android.ide.eclipse.adt.AndroidNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/MusicController/.settings/org.eclipse.jdt.core.prefs b/MusicController/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..b080d2d
--- /dev/null
+++ b/MusicController/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/MusicController/AndroidManifest.xml b/MusicController/AndroidManifest.xml
new file mode 100644
index 0000000..b19a0ba
--- /dev/null
+++ b/MusicController/AndroidManifest.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MusicController/bin/AndroidManifest.xml b/MusicController/bin/AndroidManifest.xml
new file mode 100644
index 0000000..b19a0ba
--- /dev/null
+++ b/MusicController/bin/AndroidManifest.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MusicController/bin/MusicController.apk b/MusicController/bin/MusicController.apk
new file mode 100644
index 0000000..1b1880c
Binary files /dev/null and b/MusicController/bin/MusicController.apk differ
diff --git a/MusicController/bin/classes.dex b/MusicController/bin/classes.dex
new file mode 100644
index 0000000..ef3a7c5
Binary files /dev/null and b/MusicController/bin/classes.dex differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/BluetoothLeService$1.class b/MusicController/bin/classes/com/example/musiccontroller/BluetoothLeService$1.class
new file mode 100644
index 0000000..43cb19d
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/BluetoothLeService$1.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/BluetoothLeService.class b/MusicController/bin/classes/com/example/musiccontroller/BluetoothLeService.class
new file mode 100644
index 0000000..a401e9e
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/BluetoothLeService.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/BuildConfig.class b/MusicController/bin/classes/com/example/musiccontroller/BuildConfig.class
new file mode 100644
index 0000000..a8e1d7d
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/BuildConfig.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/MainActivity$1$1.class b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$1$1.class
new file mode 100644
index 0000000..b3423c9
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$1$1.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/MainActivity$1.class b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$1.class
new file mode 100644
index 0000000..cc4d125
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$1.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/MainActivity$2.class b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$2.class
new file mode 100644
index 0000000..513df4e
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$2.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/MainActivity$3.class b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$3.class
new file mode 100644
index 0000000..a0027f7
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$3.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/MainActivity$4.class b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$4.class
new file mode 100644
index 0000000..873a3d7
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/MainActivity$4.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/MainActivity.class b/MusicController/bin/classes/com/example/musiccontroller/MainActivity.class
new file mode 100644
index 0000000..d2e7faa
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/MainActivity.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/R$attr.class b/MusicController/bin/classes/com/example/musiccontroller/R$attr.class
new file mode 100644
index 0000000..481c749
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/R$attr.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/R$dimen.class b/MusicController/bin/classes/com/example/musiccontroller/R$dimen.class
new file mode 100644
index 0000000..78a8a2d
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/R$dimen.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/R$drawable.class b/MusicController/bin/classes/com/example/musiccontroller/R$drawable.class
new file mode 100644
index 0000000..1ca3f6c
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/R$drawable.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/R$id.class b/MusicController/bin/classes/com/example/musiccontroller/R$id.class
new file mode 100644
index 0000000..8819870
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/R$id.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/R$layout.class b/MusicController/bin/classes/com/example/musiccontroller/R$layout.class
new file mode 100644
index 0000000..bf1f6f4
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/R$layout.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/R$menu.class b/MusicController/bin/classes/com/example/musiccontroller/R$menu.class
new file mode 100644
index 0000000..46c3034
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/R$menu.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/R$string.class b/MusicController/bin/classes/com/example/musiccontroller/R$string.class
new file mode 100644
index 0000000..3562a97
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/R$string.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/R$style.class b/MusicController/bin/classes/com/example/musiccontroller/R$style.class
new file mode 100644
index 0000000..50f07a8
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/R$style.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/R.class b/MusicController/bin/classes/com/example/musiccontroller/R.class
new file mode 100644
index 0000000..99b089c
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/R.class differ
diff --git a/MusicController/bin/classes/com/example/musiccontroller/SimpleKeysStatus.class b/MusicController/bin/classes/com/example/musiccontroller/SimpleKeysStatus.class
new file mode 100644
index 0000000..9251baf
Binary files /dev/null and b/MusicController/bin/classes/com/example/musiccontroller/SimpleKeysStatus.class differ
diff --git a/MusicController/bin/dexedLibs/android-support-v4-8b6bb5ca3cbba831dbc8c882aacb4dff.jar b/MusicController/bin/dexedLibs/android-support-v4-8b6bb5ca3cbba831dbc8c882aacb4dff.jar
new file mode 100644
index 0000000..9d59050
Binary files /dev/null and b/MusicController/bin/dexedLibs/android-support-v4-8b6bb5ca3cbba831dbc8c882aacb4dff.jar differ
diff --git a/MusicController/bin/dexedLibs/android-support-v4-d557b3809920ce68878dad3026839f12.jar b/MusicController/bin/dexedLibs/android-support-v4-d557b3809920ce68878dad3026839f12.jar
new file mode 100644
index 0000000..3156173
Binary files /dev/null and b/MusicController/bin/dexedLibs/android-support-v4-d557b3809920ce68878dad3026839f12.jar differ
diff --git a/MusicController/bin/jarlist.cache b/MusicController/bin/jarlist.cache
new file mode 100644
index 0000000..0565465
--- /dev/null
+++ b/MusicController/bin/jarlist.cache
@@ -0,0 +1,3 @@
+# cache for current jar dependency. DO NOT EDIT.
+# format is
+# Encoding is UTF-8
diff --git a/MusicController/bin/res/crunch/drawable-hdpi/ic_launcher.png b/MusicController/bin/res/crunch/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..efa7c5f
Binary files /dev/null and b/MusicController/bin/res/crunch/drawable-hdpi/ic_launcher.png differ
diff --git a/MusicController/bin/res/crunch/drawable-mdpi/ic_launcher.png b/MusicController/bin/res/crunch/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..ec27f2e
Binary files /dev/null and b/MusicController/bin/res/crunch/drawable-mdpi/ic_launcher.png differ
diff --git a/MusicController/bin/res/crunch/drawable-xhdpi/ic_launcher.png b/MusicController/bin/res/crunch/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..92fc57d
Binary files /dev/null and b/MusicController/bin/res/crunch/drawable-xhdpi/ic_launcher.png differ
diff --git a/MusicController/bin/res/crunch/drawable-xxhdpi/ic_launcher.png b/MusicController/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..b6f8f4e
Binary files /dev/null and b/MusicController/bin/res/crunch/drawable-xxhdpi/ic_launcher.png differ
diff --git a/MusicController/bin/resources.ap_ b/MusicController/bin/resources.ap_
new file mode 100644
index 0000000..01ea0c8
Binary files /dev/null and b/MusicController/bin/resources.ap_ differ
diff --git a/MusicController/gen/com/example/musiccontroller/BuildConfig.java b/MusicController/gen/com/example/musiccontroller/BuildConfig.java
new file mode 100644
index 0000000..436aec4
--- /dev/null
+++ b/MusicController/gen/com/example/musiccontroller/BuildConfig.java
@@ -0,0 +1,6 @@
+/** Automatically generated file. DO NOT MODIFY */
+package com.example.musiccontroller;
+
+public final class BuildConfig {
+ public final static boolean DEBUG = true;
+}
\ No newline at end of file
diff --git a/MusicController/gen/com/example/musiccontroller/R.java b/MusicController/gen/com/example/musiccontroller/R.java
new file mode 100644
index 0000000..9aebb61
--- /dev/null
+++ b/MusicController/gen/com/example/musiccontroller/R.java
@@ -0,0 +1,70 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package com.example.musiccontroller;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class dimen {
+ /** Default screen margins, per the Android Design guidelines.
+
+ Customize dimensions originally defined in res/values/dimens.xml (such as
+ screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
+
+ */
+ public static final int activity_horizontal_margin=0x7f040000;
+ public static final int activity_vertical_margin=0x7f040001;
+ }
+ public static final class drawable {
+ public static final int ic_launcher=0x7f020000;
+ }
+ public static final class id {
+ public static final int action_settings=0x7f080002;
+ public static final int nextsong=0x7f080000;
+ public static final int scan=0x7f080001;
+ }
+ public static final class layout {
+ public static final int activity_main=0x7f030000;
+ }
+ public static final class menu {
+ public static final int main=0x7f070000;
+ }
+ public static final class string {
+ public static final int action_settings=0x7f050001;
+ public static final int app_name=0x7f050000;
+ public static final int hello_world=0x7f050002;
+ }
+ public static final class style {
+ /**
+ Base application theme, dependent on API level. This theme is replaced
+ by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+
+
+ Theme customizations available in newer API levels can go in
+ res/values-vXX/styles.xml, while customizations related to
+ backward-compatibility can go here.
+
+
+ Base application theme for API 11+. This theme completely replaces
+ AppBaseTheme from res/values/styles.xml on API 11+ devices.
+
+ API 11 theme customizations can go here.
+
+ Base application theme for API 14+. This theme completely replaces
+ AppBaseTheme from BOTH res/values/styles.xml and
+ res/values-v11/styles.xml on API 14+ devices.
+
+ API 14 theme customizations can go here.
+ */
+ public static final int AppBaseTheme=0x7f060000;
+ /** Application theme.
+ All customizations that are NOT specific to a particular API-level can go here.
+ */
+ public static final int AppTheme=0x7f060001;
+ }
+}
diff --git a/MusicController/ic_launcher-web.png b/MusicController/ic_launcher-web.png
new file mode 100644
index 0000000..a18cbb4
Binary files /dev/null and b/MusicController/ic_launcher-web.png differ
diff --git a/MusicController/libs/android-support-v4.jar b/MusicController/libs/android-support-v4.jar
new file mode 100644
index 0000000..96644ed
Binary files /dev/null and b/MusicController/libs/android-support-v4.jar differ
diff --git a/MusicController/proguard-project.txt b/MusicController/proguard-project.txt
new file mode 100644
index 0000000..f2fe155
--- /dev/null
+++ b/MusicController/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/MusicController/project.properties b/MusicController/project.properties
new file mode 100644
index 0000000..ce39f2d
--- /dev/null
+++ b/MusicController/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-18
diff --git a/MusicController/res/drawable-hdpi/ic_launcher.png b/MusicController/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..288b665
Binary files /dev/null and b/MusicController/res/drawable-hdpi/ic_launcher.png differ
diff --git a/MusicController/res/drawable-mdpi/ic_launcher.png b/MusicController/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..6ae570b
Binary files /dev/null and b/MusicController/res/drawable-mdpi/ic_launcher.png differ
diff --git a/MusicController/res/drawable-xhdpi/ic_launcher.png b/MusicController/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..d4fb7cd
Binary files /dev/null and b/MusicController/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/MusicController/res/drawable-xxhdpi/ic_launcher.png b/MusicController/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..85a6081
Binary files /dev/null and b/MusicController/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/MusicController/res/layout/activity_main.xml b/MusicController/res/layout/activity_main.xml
new file mode 100644
index 0000000..92bd3de
--- /dev/null
+++ b/MusicController/res/layout/activity_main.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MusicController/res/menu/main.xml b/MusicController/res/menu/main.xml
new file mode 100644
index 0000000..c002028
--- /dev/null
+++ b/MusicController/res/menu/main.xml
@@ -0,0 +1,9 @@
+
diff --git a/MusicController/res/values-sw600dp/dimens.xml b/MusicController/res/values-sw600dp/dimens.xml
new file mode 100644
index 0000000..44f01db
--- /dev/null
+++ b/MusicController/res/values-sw600dp/dimens.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/MusicController/res/values-sw720dp-land/dimens.xml b/MusicController/res/values-sw720dp-land/dimens.xml
new file mode 100644
index 0000000..61e3fa8
--- /dev/null
+++ b/MusicController/res/values-sw720dp-land/dimens.xml
@@ -0,0 +1,9 @@
+
+
+
+ 128dp
+
+
diff --git a/MusicController/res/values-v11/styles.xml b/MusicController/res/values-v11/styles.xml
new file mode 100644
index 0000000..3c02242
--- /dev/null
+++ b/MusicController/res/values-v11/styles.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
diff --git a/MusicController/res/values-v14/styles.xml b/MusicController/res/values-v14/styles.xml
new file mode 100644
index 0000000..a91fd03
--- /dev/null
+++ b/MusicController/res/values-v14/styles.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
diff --git a/MusicController/res/values/dimens.xml b/MusicController/res/values/dimens.xml
new file mode 100644
index 0000000..55c1e59
--- /dev/null
+++ b/MusicController/res/values/dimens.xml
@@ -0,0 +1,7 @@
+
+
+
+ 16dp
+ 16dp
+
+
diff --git a/MusicController/res/values/strings.xml b/MusicController/res/values/strings.xml
new file mode 100644
index 0000000..813c8ad
--- /dev/null
+++ b/MusicController/res/values/strings.xml
@@ -0,0 +1,8 @@
+
+
+
+ MusicController
+ Settings
+ Hello world!
+
+
diff --git a/MusicController/res/values/styles.xml b/MusicController/res/values/styles.xml
new file mode 100644
index 0000000..6ce89c7
--- /dev/null
+++ b/MusicController/res/values/styles.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
diff --git a/MusicController/src/com/example/musiccontroller/BluetoothLeService.java b/MusicController/src/com/example/musiccontroller/BluetoothLeService.java
new file mode 100644
index 0000000..3e6bf64
--- /dev/null
+++ b/MusicController/src/com/example/musiccontroller/BluetoothLeService.java
@@ -0,0 +1,178 @@
+package com.example.musiccontroller;
+
+import java.util.List;
+import java.util.UUID;
+
+import android.app.Service;
+import android.bluetooth.*;
+import android.content.Intent;
+import android.media.AudioManager;
+import android.os.IBinder;
+import android.util.Log;
+import android.widget.Toast;
+
+enum SimpleKeysStatus {
+ // Warning: The order in which these are defined matters.
+ OFF_OFF, OFF_ON, ON_OFF, ON_ON;
+}
+
+public class BluetoothLeService extends Service {
+ private final static String TAG = BluetoothLeService.class.getSimpleName();
+
+ private BluetoothManager mBluetoothManager;
+ private BluetoothAdapter mBluetoothAdapter;
+ private String mBluetoothDeviceAddress;
+ private BluetoothGatt mBluetoothGatt;
+ private int mConnectionState = STATE_DISCONNECTED;
+
+ private static final int STATE_DISCONNECTED = 0;
+ private static final int STATE_CONNECTING = 1;
+ private static final int STATE_CONNECTED = 2;
+
+ public final static String ACTION_GATT_CONNECTED =
+ "com.example.bluetooth.le.ACTION_GATT_CONNECTED";
+ public final static String ACTION_GATT_DISCONNECTED =
+ "com.example.bluetooth.le.ACTION_GATT_DISCONNECTED";
+ public final static String ACTION_GATT_SERVICES_DISCOVERED =
+ "com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED";
+ public final static String ACTION_DATA_AVAILABLE =
+ "com.example.bluetooth.le.ACTION_DATA_AVAILABLE";
+ public final static String EXTRA_DATA =
+ "com.example.bluetooth.le.EXTRA_DATA";
+
+ static final String CMDTOGGLEPAUSE = "togglepause";
+ static final String CMDPAUSE = "pause";
+ static final String CMDPREVIOUS = "previous";
+ static final String CMDNEXT = "next";
+ static final String SERVICECMD = "com.android.music.musicservicecommand";
+ static final String CMDNAME = "command";
+ static final String CMDSTOP = "stop";
+
+ private static final UUID SIMPLE_KEYS_SERVICE_UUID = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb");
+ private static final UUID SIMPLE_KEYS_DATA_UUID = UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb");
+ private BluetoothGattCharacteristic keyCharacteristic;
+
+
+ private BluetoothDevice sensorTag;
+
+ @Override
+ public void onStart(Intent intent, int startId) {
+ sensorTag = intent.getExtras().getParcelable("SensorTag");
+ Log.i(TAG, "Blconnected "+ sensorTag.getName());
+ mBluetoothGatt = sensorTag.connectGatt(this, false, mGattCallback);
+ }
+
+ // Various callback methods defined by the BLE API.
+ private final BluetoothGattCallback mGattCallback =
+ new BluetoothGattCallback() {
+ @Override
+ public void onConnectionStateChange(BluetoothGatt gatt, int status,
+ int newState) {
+ String intentAction;
+ if (newState == BluetoothProfile.STATE_CONNECTED) {
+ intentAction = ACTION_GATT_CONNECTED;
+ mConnectionState = STATE_CONNECTED;
+ broadcastUpdate(intentAction);
+ Log.i(TAG, "Connected to GATT server.");
+ Log.i(TAG, "Attempting to start service discovery:" +
+ mBluetoothGatt.discoverServices());
+
+ } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
+ intentAction = ACTION_GATT_DISCONNECTED;
+ mConnectionState = STATE_DISCONNECTED;
+ Log.i(TAG, "Disconnected from GATT server.");
+ broadcastUpdate(intentAction);
+ }
+ }
+
+ @Override
+ public void onCharacteristicChanged (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
+ /*
+ * The key state is encoded into 1 unsigned byte.
+ * bit 0 designates the right key.
+ * bit 1 designates the left key.
+ * bit 2 designates the side key.
+ *
+ * Weird, in the userguide left and right are opposite.
+ */
+ Log.i(TAG, "onCharacteristicChanged");
+ if (characteristic == keyCharacteristic){
+ Integer encodedInteger = characteristic.getIntValue(0x11, 0);
+
+ SimpleKeysStatus newValue = SimpleKeysStatus.values()[encodedInteger % 4];
+ Log.i(TAG, "newValue " + newValue.toString());
+ if (newValue == SimpleKeysStatus.OFF_ON){
+ AudioManager mAudioManager = (AudioManager) getSystemService(BluetoothLeService.this.AUDIO_SERVICE);
+
+ if(mAudioManager.isMusicActive()) {
+ Intent i = new Intent(SERVICECMD);
+ i.putExtra(CMDNAME , CMDNEXT );
+ BluetoothLeService.this.sendBroadcast(i);
+ }
+ }
+ else if (newValue == SimpleKeysStatus.ON_OFF){
+ AudioManager mAudioManager = (AudioManager) getSystemService(BluetoothLeService.this.AUDIO_SERVICE);
+
+ if(mAudioManager.isMusicActive()) {
+ Intent i = new Intent(SERVICECMD);
+ i.putExtra(CMDNAME , CMDPREVIOUS);
+ BluetoothLeService.this.sendBroadcast(i);
+ }
+ }
+ }
+ }
+
+ @Override
+ // New services discovered
+ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
+ if (status == BluetoothGatt.GATT_SUCCESS) {
+ Log.i(TAG, "onServicesDiscovered received");
+ broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
+ List services = gatt.getServices();
+ for (int i = 0; i < services.size(); i++){
+ Log.i(TAG, "service " + services.get(i).getUuid());
+ }
+ keyCharacteristic = gatt.getService(SIMPLE_KEYS_SERVICE_UUID).getCharacteristic(SIMPLE_KEYS_DATA_UUID);
+ boolean notification_enabled = gatt.setCharacteristicNotification(keyCharacteristic, true);
+ Log.i(TAG, "notification_enabled: " + notification_enabled);
+
+ BluetoothGattDescriptor descriptor = keyCharacteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
+ descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
+ mBluetoothGatt.writeDescriptor(descriptor);
+// Toast.makeText(BluetoothLeService.this, "", 5000).show();
+ } else {
+ Log.w(TAG, "onServicesDiscovered received: " + status);
+ }
+ }
+
+ @Override
+ // Result of a characteristic read operation
+ public void onCharacteristicRead(BluetoothGatt gatt,
+ BluetoothGattCharacteristic characteristic,
+ int status) {
+
+ Log.i(TAG, characteristic.getUuid().toString());
+ if (status == BluetoothGatt.GATT_SUCCESS) {
+ broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
+ }
+ }
+ };
+ private void broadcastUpdate(final String action) {
+ final Intent intent = new Intent(action);
+ sendBroadcast(intent);
+ }
+
+ private void broadcastUpdate(final String action,
+ final BluetoothGattCharacteristic characteristic) {
+ final Intent intent = new Intent(action);
+// sendBroadcast(intent);
+ }
+
+
+ @Override
+ public IBinder onBind(Intent arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
+
diff --git a/MusicController/src/com/example/musiccontroller/MainActivity.java b/MusicController/src/com/example/musiccontroller/MainActivity.java
new file mode 100644
index 0000000..c1e46ac
--- /dev/null
+++ b/MusicController/src/com/example/musiccontroller/MainActivity.java
@@ -0,0 +1,131 @@
+package com.example.musiccontroller;
+
+import android.media.AudioManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.app.Activity;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothManager;
+import android.content.Context;
+import android.content.Intent;
+import android.view.Menu;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.util.Log;
+
+public class MainActivity extends Activity {
+ Button nextSong;
+ static private final String TAG = "MusicController";
+ static final String CMDTOGGLEPAUSE = "togglepause";
+ static final String CMDPAUSE = "pause";
+ static final String CMDPREVIOUS = "previous";
+ static final String CMDNEXT = "next";
+ static final String SERVICECMD = "com.android.music.musicservicecommand";
+ static final String CMDNAME = "command";
+ static final String CMDSTOP = "stop";
+ private static final int REQUEST_ENABLE_BT = 0;
+ private BluetoothAdapter mBluetoothAdapter;
+ private static final long SCAN_PERIOD = 10000;
+ private boolean mScanning;
+ private Handler mHandler;
+ private Button scanBLE;
+
+ private BluetoothAdapter.LeScanCallback mLeScanCallback =
+ new BluetoothAdapter.LeScanCallback() {
+ @Override
+ public void onLeScan(final BluetoothDevice device, int rssi,
+ byte[] scanRecord) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Log.i(TAG,"Found device " + device.getName());
+ if (device.getName().contains("SensorTag") ){
+ Log.i(TAG,"Starting service...");
+ mBluetoothAdapter.stopLeScan(mLeScanCallback);
+ Intent intent = new Intent(MainActivity.this, BluetoothLeService.class);
+ intent.putExtra("SensorTag",device);
+ startService(intent);
+ }
+ }
+ });
+ }
+ };
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ scanBLE = (Button) findViewById(R.id.scan);
+ scanBLE.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ scanLeDevice(true);
+ }
+ });
+
+ nextSong = (Button) findViewById(R.id.nextsong);
+ nextSong.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+// Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
+// i.putExtra(Intent.EXTRA_KEY_EVENT,new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT));
+// //i.putExtra(Intent.EXTRA_KEY_EVENT, KeyEvent.KEYCODE_MEDIA_NEXT);
+// sendOrderedBroadcast(i, null);
+// Log.i(TAG, "Send intent in broadcast");
+
+// AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+//
+// if(mAudioManager.isMusicActive()) {
+// Intent i = new Intent(SERVICECMD);
+// i.putExtra(CMDNAME , CMDNEXT );
+// MainActivity.this.sendBroadcast(i);
+// }
+
+
+ }
+ });
+
+ final BluetoothManager bluetoothManager =
+ (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
+ mBluetoothAdapter = bluetoothManager.getAdapter();
+ if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
+ Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+ startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
+ }
+
+ scanLeDevice(true);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
+
+ private void scanLeDevice(final boolean enable) {
+ Log.i(TAG, "starting scanLeDevice");
+ mScanning = true;
+ mBluetoothAdapter.startLeScan(mLeScanCallback);
+ if (enable) {
+ // Stops scanning after a pre-defined scan period.
+ mHandler = new Handler();
+ mHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mScanning = false;
+ mBluetoothAdapter.stopLeScan(mLeScanCallback);
+ }
+ }, SCAN_PERIOD);
+
+ } else {
+ mScanning = false;
+ mBluetoothAdapter.stopLeScan(mLeScanCallback);
+ }
+
+ }
+}
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29