mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-12 18:57:36 +01:00
TLW64: Support notifications
This commit is contained in:
parent
fc2a7c6f8d
commit
654019e2c0
@ -29,5 +29,18 @@ public final class TLW64Constants {
|
||||
public static final byte CMD_DATETIME = (byte) 0xa3;
|
||||
public static final byte CMD_USER_DATA = (byte) 0xa9;
|
||||
public static final byte CMD_ALARM = (byte) 0xab;
|
||||
public static final byte CMD_NOTIFICATION = (byte) 0xc1;
|
||||
public static final byte CMD_ICON = (byte) 0xc3;
|
||||
|
||||
// Notifications
|
||||
public static final byte NOTIFICATION_HEADER = (byte) 0x01;
|
||||
public static final byte NOTIFICATION_CALL = (byte) 0x02; // displays "call" on screen
|
||||
public static final byte NOTIFICATION_SMS = (byte) 0x03; // displays "mms" on screen
|
||||
public static final byte NOTIFICATION_STOP = (byte) 0x04; // to stop showing incoming call
|
||||
|
||||
// Icons
|
||||
public static final byte ICON_QQ = (byte) 0x01;
|
||||
public static final byte ICON_WECHAT = (byte) 0x02;
|
||||
public static final byte ICON_MAIL = (byte) 0x04;
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
import static org.apache.commons.lang3.math.NumberUtils.min;
|
||||
|
||||
public class TLW64Support extends AbstractBTLEDeviceSupport {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TLW64Support.class);
|
||||
@ -89,7 +91,20 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onNotification(NotificationSpec notificationSpec) {
|
||||
|
||||
switch (notificationSpec.type) {
|
||||
case GENERIC_SMS:
|
||||
showNotification(TLW64Constants.NOTIFICATION_SMS, notificationSpec.sender);
|
||||
setVibration(1, 1);
|
||||
break;
|
||||
case WECHAT:
|
||||
showIcon(TLW64Constants.ICON_WECHAT);
|
||||
setVibration(1, 1);
|
||||
break;
|
||||
default:
|
||||
showIcon(TLW64Constants.ICON_MAIL);
|
||||
setVibration(1, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -115,7 +130,13 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
|
||||
if (callSpec.command == CallSpec.CALL_INCOMING) {
|
||||
showNotification(TLW64Constants.NOTIFICATION_CALL, callSpec.name);
|
||||
setVibration(3, 5);
|
||||
} else {
|
||||
stopNotification();
|
||||
setVibration(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -347,4 +368,60 @@ public class TLW64Support extends AbstractBTLEDeviceSupport {
|
||||
|
||||
builder.write(ctrlCharacteristic, userBytes);
|
||||
}
|
||||
|
||||
private void showIcon(int iconId) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("showIcon");
|
||||
byte[] msg = new byte[]{
|
||||
TLW64Constants.CMD_ICON,
|
||||
(byte) iconId
|
||||
};
|
||||
builder.write(ctrlCharacteristic, msg);
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
GB.toast(getContext(), "Error showing icon: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private void showNotification(int type, String text) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("showNotification");
|
||||
int length;
|
||||
byte[] bytes;
|
||||
byte[] msg;
|
||||
|
||||
// send text
|
||||
bytes = text.getBytes("EUC-JP");
|
||||
length = min(bytes.length, 18);
|
||||
msg = new byte[length + 2];
|
||||
msg[0] = TLW64Constants.CMD_NOTIFICATION;
|
||||
msg[1] = TLW64Constants.NOTIFICATION_HEADER;
|
||||
System.arraycopy(bytes, 0, msg, 2, length);
|
||||
builder.write(ctrlCharacteristic, msg);
|
||||
|
||||
// send notification type
|
||||
msg = new byte[2];
|
||||
msg[0] = TLW64Constants.CMD_NOTIFICATION;
|
||||
msg[1] = (byte) type;
|
||||
builder.write(ctrlCharacteristic, msg);
|
||||
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
GB.toast(getContext(), "Error showing notificaton: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopNotification() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("clearNotification");
|
||||
byte[] msg = new byte[]{
|
||||
TLW64Constants.CMD_NOTIFICATION,
|
||||
TLW64Constants.NOTIFICATION_STOP
|
||||
};
|
||||
builder.write(ctrlCharacteristic, msg);
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Unable to stop notification", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user