mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-15 21:27:51 +01:00
Amazfit Bip: Support app icons in notifications
This commit is contained in:
parent
fdcc51cb98
commit
4c8728c78f
@ -0,0 +1,97 @@
|
|||||||
|
/* Copyright (C) 2017 Andreas Shimokawa
|
||||||
|
|
||||||
|
This file is part of Gadgetbridge.
|
||||||
|
|
||||||
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Gadgetbridge is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
package nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip;
|
||||||
|
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||||
|
|
||||||
|
public class AmazfitBipIcon {
|
||||||
|
// icons which are unsure which app they are for are suffixed with _NN
|
||||||
|
public static final int CHAT = 0;
|
||||||
|
public static final int PENGUIN_1 = 1;
|
||||||
|
public static final int MI_CHAT_2 = 2;
|
||||||
|
public static final int FACEBOOK = 3;
|
||||||
|
public static final int TWITTER = 4;
|
||||||
|
public static final int MI_APP_5 = 5;
|
||||||
|
public static final int SNAPCHAT = 6;
|
||||||
|
public static final int WHATSAPP = 7;
|
||||||
|
public static final int RED_WHITE_FIRE_8 = 8;
|
||||||
|
public static final int CHINESE_9 = 9;
|
||||||
|
public static final int ALARM_CLOCK = 10;
|
||||||
|
public static final int APP_11 = 11;
|
||||||
|
public static final int CAMERA_12 = 12;
|
||||||
|
public static final int CHAT_BLUE_13 = 13;
|
||||||
|
public static final int COW_14 = 14;
|
||||||
|
public static final int CHINESE_15 = 15;
|
||||||
|
public static final int CHINESE_16 = 16;
|
||||||
|
public static final int STAR_17 = 17;
|
||||||
|
public static final int APP_18 = 18;
|
||||||
|
public static final int CHINESE_19 = 19;
|
||||||
|
public static final int CHINESE_20 = 20;
|
||||||
|
public static final int CALENDAR = 21;
|
||||||
|
public static final int FACEBOOK_MESSENGER = 22;
|
||||||
|
public static final int WHATSAPP_CALL_23 = 23;
|
||||||
|
public static final int LINE = 24;
|
||||||
|
public static final int TELEGRAM = 25;
|
||||||
|
public static final int KAKAOTALK = 26;
|
||||||
|
public static final int SKYPE = 27;
|
||||||
|
public static final int VKONTAKTE = 28;
|
||||||
|
public static final int POKEMONGO = 29;
|
||||||
|
public static final int HANGOUTS = 30;
|
||||||
|
public static final int MI_31 = 31;
|
||||||
|
public static final int CHINESE_32 = 32;
|
||||||
|
public static final int CHINESE_33 = 33;
|
||||||
|
public static final int EMAIL = 34;
|
||||||
|
public static final int WEATHER = 35;
|
||||||
|
public static final int HR_WARNING_36 = 36;
|
||||||
|
|
||||||
|
|
||||||
|
public static int mapToIconId(NotificationType type) {
|
||||||
|
switch (type) {
|
||||||
|
case UNKNOWN:
|
||||||
|
return APP_11;
|
||||||
|
case CONVERSATIONS:
|
||||||
|
return CHAT;
|
||||||
|
case GENERIC_EMAIL:
|
||||||
|
return EMAIL;
|
||||||
|
case GENERIC_NAVIGATION:
|
||||||
|
return APP_11;
|
||||||
|
case GENERIC_SMS:
|
||||||
|
return CHAT;
|
||||||
|
case GENERIC_CALENDAR:
|
||||||
|
return CALENDAR;
|
||||||
|
case FACEBOOK:
|
||||||
|
return FACEBOOK;
|
||||||
|
case FACEBOOK_MESSENGER:
|
||||||
|
return FACEBOOK_MESSENGER;
|
||||||
|
case RIOT:
|
||||||
|
return CHAT;
|
||||||
|
case SIGNAL:
|
||||||
|
return CHAT_BLUE_13;
|
||||||
|
case TWITTER:
|
||||||
|
return TWITTER;
|
||||||
|
case TELEGRAM:
|
||||||
|
return TELEGRAM;
|
||||||
|
case WHATSAPP:
|
||||||
|
return WHATSAPP;
|
||||||
|
case GENERIC_ALARM_CLOCK:
|
||||||
|
return ALARM_CLOCK;
|
||||||
|
}
|
||||||
|
return APP_11;
|
||||||
|
}
|
||||||
|
}
|
@ -37,7 +37,8 @@ public enum AlertCategory {
|
|||||||
// 10-250 reserved for future use
|
// 10-250 reserved for future use
|
||||||
// 251-255 defined by service specification
|
// 251-255 defined by service specification
|
||||||
Any(255),
|
Any(255),
|
||||||
Custom(-1);
|
Custom(-1),
|
||||||
|
CustomAmazfitBip(-6);
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
|
@ -95,10 +95,17 @@ public class AlertNotificationProfile<T extends AbstractBTLEDeviceSupport> exten
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void newAlert(TransactionBuilder builder, NewAlert alert) {
|
||||||
|
newAlert(builder, alert, OverflowStrategy.TRUNCATE);
|
||||||
|
}
|
||||||
|
|
||||||
protected byte[] getAlertMessage(NewAlert alert, String message, int chunk) throws IOException {
|
protected byte[] getAlertMessage(NewAlert alert, String message, int chunk) throws IOException {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(100);
|
ByteArrayOutputStream stream = new ByteArrayOutputStream(100);
|
||||||
stream.write(BLETypeConversions.fromUint8(alert.getCategory().getId()));
|
stream.write(BLETypeConversions.fromUint8(alert.getCategory().getId()));
|
||||||
stream.write(BLETypeConversions.fromUint8(alert.getNumAlerts()));
|
stream.write(BLETypeConversions.fromUint8(alert.getNumAlerts()));
|
||||||
|
if (alert.getCategory() == AlertCategory.CustomAmazfitBip) {
|
||||||
|
stream.write(BLETypeConversions.fromUint8(alert.getCustomIcon()));
|
||||||
|
}
|
||||||
|
|
||||||
if (message.length() > 0) {
|
if (message.length() > 0) {
|
||||||
stream.write(BLETypeConversions.toUtf8s(message));
|
stream.write(BLETypeConversions.toUtf8s(message));
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification;
|
package nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification;
|
||||||
|
|
||||||
|
import android.icu.util.IslamicCalendar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.new_alert.xml&u=org.bluetooth.characteristic.new_alert.xml
|
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.new_alert.xml&u=org.bluetooth.characteristic.new_alert.xml
|
||||||
*
|
*
|
||||||
@ -47,6 +49,7 @@ public class NewAlert {
|
|||||||
private final AlertCategory category;
|
private final AlertCategory category;
|
||||||
private final int numAlerts;
|
private final int numAlerts;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
private int customIcon = -1;
|
||||||
|
|
||||||
public NewAlert(AlertCategory category, int /*uint8*/ numAlerts, String /*utf8s*/ message) {
|
public NewAlert(AlertCategory category, int /*uint8*/ numAlerts, String /*utf8s*/ message) {
|
||||||
this.category = category;
|
this.category = category;
|
||||||
@ -54,6 +57,13 @@ public class NewAlert {
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NewAlert(AlertCategory category, int /*uint8*/ numAlerts, String /*utf8s*/ message, int customIcon) {
|
||||||
|
this.category = category;
|
||||||
|
this.numAlerts = numAlerts;
|
||||||
|
this.message = message;
|
||||||
|
this.customIcon = customIcon;
|
||||||
|
}
|
||||||
|
|
||||||
public AlertCategory getCategory() {
|
public AlertCategory getCategory() {
|
||||||
return category;
|
return category;
|
||||||
}
|
}
|
||||||
@ -65,4 +75,8 @@ public class NewAlert {
|
|||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCustomIcon() {
|
||||||
|
return customIcon;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,26 +16,33 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.AmazfitBipIcon;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.AmazfitBipService;
|
import nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.AmazfitBipService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.AmazfitBipWeatherConditions;
|
import nodomain.freeyourgadget.gadgetbridge.devices.amazfitbip.AmazfitBipWeatherConditions;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||||
|
|
||||||
public class AmazfitBipSupport extends MiBand2Support {
|
public class AmazfitBipSupport extends MiBand2Support {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipSupport.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NotificationStrategy getNotificationStrategy() {
|
public NotificationStrategy getNotificationStrategy() {
|
||||||
return new AmazfitBipTextNotificationStrategy(this);
|
return new AmazfitBipTextNotificationStrategy(this);
|
||||||
@ -49,8 +56,8 @@ public class AmazfitBipSupport extends MiBand2Support {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String senderOrTiltle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
|
String senderOrTiltle = StringUtils.getFirstOf(notificationSpec.sender, notificationSpec.title);
|
||||||
String message = StringUtils.truncate(senderOrTiltle, 32) + "\0";
|
|
||||||
|
|
||||||
|
String message = StringUtils.truncate(senderOrTiltle, 32) + "\0";
|
||||||
if (notificationSpec.subject != null) {
|
if (notificationSpec.subject != null) {
|
||||||
message += StringUtils.truncate(notificationSpec.subject, 128) + "\n\n";
|
message += StringUtils.truncate(notificationSpec.subject, 128) + "\n\n";
|
||||||
}
|
}
|
||||||
@ -58,9 +65,26 @@ public class AmazfitBipSupport extends MiBand2Support {
|
|||||||
message += StringUtils.truncate(notificationSpec.body, 128);
|
message += StringUtils.truncate(notificationSpec.body, 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
String origin = notificationSpec.type.getGenericType();
|
try {
|
||||||
SimpleNotification simpleNotification = new SimpleNotification(message, BLETypeConversions.toAlertCategory(notificationSpec.type));
|
TransactionBuilder builder = performInitialized("new notification");
|
||||||
performPreferredNotification(origin + " received", origin, simpleNotification, MiBand2Service.ALERT_LEVEL_MESSAGE, null);
|
AlertNotificationProfile<?> profile = new AlertNotificationProfile(this);
|
||||||
|
profile.setMaxLength(255); // TODO: find out real limit, certainly it is more than 18 which is default
|
||||||
|
|
||||||
|
int customIconId = AmazfitBipIcon.mapToIconId(notificationSpec.type);
|
||||||
|
|
||||||
|
AlertCategory alertCategory = AlertCategory.CustomAmazfitBip;
|
||||||
|
|
||||||
|
// The SMS icon for AlertCategory.SMS is unique and not available as iconId
|
||||||
|
if (notificationSpec.type == NotificationType.GENERIC_SMS) {
|
||||||
|
alertCategory = AlertCategory.SMS;
|
||||||
|
}
|
||||||
|
|
||||||
|
NewAlert alert = new NewAlert(alertCategory, 1, message, customIconId);
|
||||||
|
profile.newAlert(builder, alert);
|
||||||
|
builder.queue(getQueue());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
LOG.error("Unable to send notification to Amazfit Bip", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,6 +30,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.Mi2TextNotif
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
|
// This class in no longer in use except for incoming calls
|
||||||
class AmazfitBipTextNotificationStrategy extends Mi2TextNotificationStrategy {
|
class AmazfitBipTextNotificationStrategy extends Mi2TextNotificationStrategy {
|
||||||
|
|
||||||
AmazfitBipTextNotificationStrategy(MiBand2Support support) {
|
AmazfitBipTextNotificationStrategy(MiBand2Support support) {
|
||||||
|
Loading…
Reference in New Issue
Block a user