play around with play states, simplify weired nested switch
This commit is contained in:
parent
adfef3db42
commit
6ce63276a3
|
@ -202,7 +202,7 @@ public class DebugActivity extends Activity {
|
||||||
GBApplication.deviceService().onSetMusicInfo(
|
GBApplication.deviceService().onSetMusicInfo(
|
||||||
editContent.getText().toString() + "(artist)",
|
editContent.getText().toString() + "(artist)",
|
||||||
editContent.getText().toString() + "(album)",
|
editContent.getText().toString() + "(album)",
|
||||||
editContent.getText().toString() + "(track)", 90, 10, 2);
|
editContent.getText().toString() + "(track)", 20, 10, 2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
static final byte PHONECONTROL_START = 8;
|
static final byte PHONECONTROL_START = 8;
|
||||||
static final byte PHONECONTROL_END = 9;
|
static final byte PHONECONTROL_END = 9;
|
||||||
|
|
||||||
static final byte MUSICCONTROL_SETMUSICINFO = 16;
|
static final byte MUSICCONTROL_SETMUSICINFO = 0x10;
|
||||||
|
static final byte MUSICCONTROL_SETPLAYSTATE = 0x11;
|
||||||
|
|
||||||
static final byte MUSICCONTROL_PLAYPAUSE = 1;
|
static final byte MUSICCONTROL_PLAYPAUSE = 1;
|
||||||
static final byte MUSICCONTROL_PAUSE = 2;
|
static final byte MUSICCONTROL_PAUSE = 2;
|
||||||
static final byte MUSICCONTROL_PLAY = 3;
|
static final byte MUSICCONTROL_PLAY = 3;
|
||||||
|
@ -119,7 +121,13 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
static final byte MUSICCONTROL_PREVIOUS = 5;
|
static final byte MUSICCONTROL_PREVIOUS = 5;
|
||||||
static final byte MUSICCONTROL_VOLUMEUP = 6;
|
static final byte MUSICCONTROL_VOLUMEUP = 6;
|
||||||
static final byte MUSICCONTROL_VOLUMEDOWN = 7;
|
static final byte MUSICCONTROL_VOLUMEDOWN = 7;
|
||||||
static final byte MUSICCONTROL_GETNOWPLAYING = 7;
|
static final byte MUSICCONTROL_GETNOWPLAYING = 8;
|
||||||
|
|
||||||
|
static final byte MUSICCONTROL_STATE_PAUSED = 0x00;
|
||||||
|
static final byte MUSICCONTROL_STATE_PLAYING = 0x01;
|
||||||
|
static final byte MUSICCONTROL_STATE_REWINDING = 0x02;
|
||||||
|
static final byte MUSICCONTROL_STATE_FASTWORWARDING = 0x03;
|
||||||
|
static final byte MUSICCONTROL_STATE_UNKNOWN = 0x04;
|
||||||
|
|
||||||
static final byte NOTIFICATIONACTION_ACK = 0;
|
static final byte NOTIFICATIONACTION_ACK = 0;
|
||||||
static final byte NOTIFICATIONACTION_NACK = 1;
|
static final byte NOTIFICATIONACTION_NACK = 1;
|
||||||
|
@ -407,7 +415,6 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
if (parts != null) {
|
if (parts != null) {
|
||||||
for (String s : parts) {
|
for (String s : parts) {
|
||||||
if (s == null || s.equals("")) {
|
if (s == null || s.equals("")) {
|
||||||
//buf.put((byte)0x01);
|
|
||||||
buf.put((byte) 0x00);
|
buf.put((byte) 0x00);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -802,20 +809,10 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
icon_id = PebbleIconID.GENERIC_SMS;
|
icon_id = PebbleIconID.GENERIC_SMS;
|
||||||
color_id = PebbleColor.VividViolet;
|
color_id = PebbleColor.VividViolet;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
switch (notificationType) {
|
|
||||||
case TWITTER:
|
case TWITTER:
|
||||||
icon_id = PebbleIconID.NOTIFICATION_TWITTER;
|
icon_id = PebbleIconID.NOTIFICATION_TWITTER;
|
||||||
color_id = PebbleColor.BlueMoon;
|
color_id = PebbleColor.BlueMoon;
|
||||||
break;
|
break;
|
||||||
case EMAIL:
|
|
||||||
icon_id = PebbleIconID.GENERIC_EMAIL;
|
|
||||||
color_id = PebbleColor.JaegerGreen;
|
|
||||||
break;
|
|
||||||
case SMS:
|
|
||||||
icon_id = PebbleIconID.GENERIC_SMS;
|
|
||||||
color_id = PebbleColor.VividViolet;
|
|
||||||
break;
|
|
||||||
case FACEBOOK:
|
case FACEBOOK:
|
||||||
icon_id = PebbleIconID.NOTIFICATION_FACEBOOK;
|
icon_id = PebbleIconID.NOTIFICATION_FACEBOOK;
|
||||||
color_id = PebbleColor.VeryLightBlue;
|
color_id = PebbleColor.VeryLightBlue;
|
||||||
|
@ -829,8 +826,6 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
color_id = PebbleColor.Red;
|
color_id = PebbleColor.Red;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Calculate length first
|
// Calculate length first
|
||||||
byte actions_count;
|
byte actions_count;
|
||||||
short actions_length;
|
short actions_length;
|
||||||
|
@ -1082,14 +1077,34 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
return encodeMessage(ENDPOINT_PHONECONTROL, pebbleCmd, 0, parts);
|
return encodeMessage(ENDPOINT_PHONECONTROL, pebbleCmd, 0, parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] encodeSetMusicState(byte state, int position, int playRate, byte shuffle, byte repeat) {
|
||||||
|
int length = LENGTH_PREFIX + 12;
|
||||||
|
// Encode Prefix
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(length);
|
||||||
|
buf.order(ByteOrder.BIG_ENDIAN);
|
||||||
|
buf.putShort((short) (length - LENGTH_PREFIX));
|
||||||
|
buf.putShort(ENDPOINT_MUSICCONTROL);
|
||||||
|
|
||||||
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
|
buf.put(MUSICCONTROL_SETPLAYSTATE);
|
||||||
|
buf.put(state);
|
||||||
|
buf.putInt(position);
|
||||||
|
buf.putInt(playRate);
|
||||||
|
buf.put(shuffle);
|
||||||
|
buf.put(repeat);
|
||||||
|
|
||||||
|
return buf.array();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] encodeSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
public byte[] encodeSetMusicInfo(String artist, String album, String track, int duration, int trackCount, int trackNr) {
|
||||||
String[] parts = {artist, album, track};
|
String[] parts = {artist, album, track};
|
||||||
if (duration == 0) {
|
if (duration == 0) {
|
||||||
return encodeMessage(ENDPOINT_MUSICCONTROL, MUSICCONTROL_SETMUSICINFO, 0, parts);
|
return encodeMessage(ENDPOINT_MUSICCONTROL, MUSICCONTROL_SETMUSICINFO, 0, parts);
|
||||||
} else {
|
} else {
|
||||||
|
byte[] stateMessage = encodeSetMusicState(MUSICCONTROL_STATE_PLAYING, 0, 100, (byte) 1, (byte) 1);
|
||||||
// Calculate length first
|
// Calculate length first
|
||||||
int length = LENGTH_PREFIX + 13;
|
int length = LENGTH_PREFIX + 9;
|
||||||
if (parts != null) {
|
if (parts != null) {
|
||||||
for (String s : parts) {
|
for (String s : parts) {
|
||||||
if (s == null || s.equals("")) {
|
if (s == null || s.equals("")) {
|
||||||
|
@ -1101,7 +1116,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode Prefix
|
// Encode Prefix
|
||||||
ByteBuffer buf = ByteBuffer.allocate(length);
|
ByteBuffer buf = ByteBuffer.allocate(length + stateMessage.length);
|
||||||
buf.order(ByteOrder.BIG_ENDIAN);
|
buf.order(ByteOrder.BIG_ENDIAN);
|
||||||
buf.putShort((short) (length - LENGTH_PREFIX));
|
buf.putShort((short) (length - LENGTH_PREFIX));
|
||||||
buf.putShort(ENDPOINT_MUSICCONTROL);
|
buf.putShort(ENDPOINT_MUSICCONTROL);
|
||||||
|
@ -1122,11 +1137,12 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
|
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
buf.putInt(duration * 1000);
|
buf.putInt(duration * 1000);
|
||||||
buf.putInt(trackCount);
|
buf.putShort((short) (trackCount & 0xffff));
|
||||||
buf.putInt(trackNr);
|
buf.putShort((short) (trackNr & 0xffff));
|
||||||
|
|
||||||
|
buf.put(stateMessage);
|
||||||
|
|
||||||
return buf.array();
|
return buf.array();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue