mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 01:09:47 +01:00
Mi Band 2: support app icons and textual notifications for more apps
This commit is contained in:
parent
a809ad214d
commit
f07b77f903
@ -264,20 +264,29 @@ public class BLETypeConversions {
|
||||
case GENERIC_SMS:
|
||||
return AlertCategory.SMS;
|
||||
case GENERIC_EMAIL:
|
||||
case GMAIL:
|
||||
case OUTLOOK:
|
||||
case YAHOO_MAIL:
|
||||
return AlertCategory.Email;
|
||||
case GENERIC_NAVIGATION:
|
||||
return AlertCategory.Simple;
|
||||
case CONVERSATIONS:
|
||||
case FACEBOOK_MESSENGER:
|
||||
case GOOGLE_MESSENGER:
|
||||
case GOOGLE_HANGOUTS:
|
||||
case HIPCHAT:
|
||||
case KAKAO_TALK:
|
||||
case LINE:
|
||||
case RIOT:
|
||||
case SIGNAL:
|
||||
case SKYPE:
|
||||
case SNAPCHAT:
|
||||
case TELEGRAM:
|
||||
case WHATSAPP:
|
||||
case CONVERSATIONS:
|
||||
case FACEBOOK:
|
||||
case FACEBOOK_MESSENGER:
|
||||
case TWITTER:
|
||||
case WHATSAPP:
|
||||
case VIBER:
|
||||
case WECHAT:
|
||||
return AlertCategory.InstantMessage;
|
||||
case UNKNOWN:
|
||||
return AlertCategory.Simple;
|
||||
}
|
||||
return AlertCategory.Simple;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public enum AlertCategory {
|
||||
// 251-255 defined by service specification
|
||||
Any(255),
|
||||
Custom(-1),
|
||||
CustomMiBand2(-6);
|
||||
CustomHuami(-6);
|
||||
|
||||
private final int id;
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class AlertNotificationProfile<T extends AbstractBTLEDeviceSupport> exten
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(100);
|
||||
stream.write(BLETypeConversions.fromUint8(alert.getCategory().getId()));
|
||||
stream.write(BLETypeConversions.fromUint8(alert.getNumAlerts()));
|
||||
if (alert.getCategory() == AlertCategory.CustomMiBand2) {
|
||||
if (alert.getCategory() == AlertCategory.CustomHuami) {
|
||||
stream.write(BLETypeConversions.fromUint8(alert.getCustomIcon()));
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ public class AmazfitBipSupport extends MiBand2Support {
|
||||
|
||||
byte customIconId = HuamiIcon.mapToIconId(notificationSpec.type);
|
||||
|
||||
AlertCategory alertCategory = AlertCategory.CustomMiBand2;
|
||||
AlertCategory alertCategory = AlertCategory.CustomHuami;
|
||||
|
||||
// The SMS icon for AlertCategory.SMS is unique and not available as iconId
|
||||
if (notificationSpec.type == NotificationType.GENERIC_SMS) {
|
||||
|
@ -16,21 +16,28 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.common;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory;
|
||||
|
||||
public class SimpleNotification {
|
||||
private final String message;
|
||||
private final AlertCategory alertCategory;
|
||||
private final NotificationType notificationType;
|
||||
|
||||
public SimpleNotification(String message, AlertCategory alertCategory) {
|
||||
public SimpleNotification(String message, AlertCategory alertCategory, NotificationType notificationType) {
|
||||
this.message = message;
|
||||
this.alertCategory = alertCategory;
|
||||
this.notificationType = notificationType;
|
||||
}
|
||||
|
||||
public AlertCategory getAlertCategory() {
|
||||
return alertCategory;
|
||||
}
|
||||
|
||||
public NotificationType getNotificationType() {
|
||||
return notificationType;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
@ -587,7 +587,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
};
|
||||
String message = NotificationUtils.getPreferredTextFor(notificationSpec, 40, 40, getContext());
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.HighPriorityAlert);
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.HighPriorityAlert, null);
|
||||
performPreferredNotification("alarm clock ringing", simpleNotification, MiBandConst.ORIGIN_ALARM_CLOCK, abortAction);
|
||||
}
|
||||
|
||||
@ -653,7 +653,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
};
|
||||
String message = NotificationUtils.getPreferredTextFor(callSpec);
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.IncomingCall);
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.IncomingCall, null);
|
||||
performPreferredNotification("incoming call", simpleNotification, MiBandConst.ORIGIN_INCOMING_CALL, abortAction);
|
||||
} else if ((callSpec.command == CallSpec.CALL_START) || (callSpec.command == CallSpec.CALL_END)) {
|
||||
telephoneRinging = false;
|
||||
@ -745,7 +745,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
return !isLocatingDevice;
|
||||
}
|
||||
};
|
||||
SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert);
|
||||
SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert, null);
|
||||
performDefaultNotification("locating device", simpleNotification, (short) 255, abortAction);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiIcon;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic;
|
||||
@ -30,6 +29,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotificat
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.OverflowStrategy;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiIcon;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||
|
||||
public class Mi2TextNotificationStrategy extends Mi2NotificationStrategy {
|
||||
@ -63,15 +63,13 @@ public class Mi2TextNotificationStrategy extends Mi2NotificationStrategy {
|
||||
|
||||
protected byte[] getNotifyMessage(SimpleNotification simpleNotification) {
|
||||
int numAlerts = 1;
|
||||
if (simpleNotification != null) {
|
||||
switch (simpleNotification.getAlertCategory()) {
|
||||
case Email:
|
||||
return new byte[] { BLETypeConversions.fromUint8(AlertCategory.Email.getId()), BLETypeConversions.fromUint8(numAlerts)};
|
||||
case InstantMessage:
|
||||
return new byte[] { BLETypeConversions.fromUint8(AlertCategory.CustomMiBand2.getId()), BLETypeConversions.fromUint8(numAlerts), HuamiIcon.WECHAT};
|
||||
case News:
|
||||
return new byte[] { BLETypeConversions.fromUint8(AlertCategory.CustomMiBand2.getId()), BLETypeConversions.fromUint8(numAlerts), HuamiIcon.PENGUIN_1};
|
||||
if (simpleNotification != null && simpleNotification.getNotificationType() != null && simpleNotification.getAlertCategory() != AlertCategory.SMS) {
|
||||
byte customIconId = HuamiIcon.mapToIconId(simpleNotification.getNotificationType());
|
||||
if (customIconId == HuamiIcon.EMAIL) {
|
||||
// unfortunately. the email icon breaks the notification, fall back to a standard AlertCategory
|
||||
return new byte[]{BLETypeConversions.fromUint8(AlertCategory.Email.getId()), BLETypeConversions.fromUint8(numAlerts)};
|
||||
}
|
||||
return new byte[]{BLETypeConversions.fromUint8(AlertCategory.CustomHuami.getId()), BLETypeConversions.fromUint8(numAlerts), customIconId};
|
||||
}
|
||||
return new byte[] { BLETypeConversions.fromUint8(AlertCategory.SMS.getId()), BLETypeConversions.fromUint8(numAlerts)};
|
||||
}
|
||||
|
@ -597,7 +597,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
String message = NotificationUtils.getPreferredTextFor(notificationSpec, 40, 40, getContext()).trim();
|
||||
String origin = notificationSpec.type.getGenericType();
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, BLETypeConversions.toAlertCategory(notificationSpec.type));
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, BLETypeConversions.toAlertCategory(notificationSpec.type), notificationSpec.type);
|
||||
performPreferredNotification(origin + " received", origin, simpleNotification, alertLevel, null);
|
||||
}
|
||||
|
||||
@ -610,7 +610,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
};
|
||||
String message = NotificationUtils.getPreferredTextFor(notificationSpec, 40, 40, getContext());
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.HighPriorityAlert);
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.HighPriorityAlert, notificationSpec.type);
|
||||
performPreferredNotification("alarm clock ringing", MiBandConst.ORIGIN_ALARM_CLOCK, simpleNotification, MiBand2Service.ALERT_LEVEL_VIBRATE_ONLY, abortAction);
|
||||
}
|
||||
|
||||
@ -643,7 +643,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
};
|
||||
String message = NotificationUtils.getPreferredTextFor(callSpec);
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.IncomingCall);
|
||||
SimpleNotification simpleNotification = new SimpleNotification(message, AlertCategory.IncomingCall, null);
|
||||
performPreferredNotification("incoming call", MiBandConst.ORIGIN_INCOMING_CALL, simpleNotification, MiBand2Service.ALERT_LEVEL_PHONE_CALL, abortAction);
|
||||
} else if ((callSpec.command == CallSpec.CALL_START) || (callSpec.command == CallSpec.CALL_END)) {
|
||||
telephoneRinging = false;
|
||||
@ -742,7 +742,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
return !isLocatingDevice;
|
||||
}
|
||||
};
|
||||
SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert);
|
||||
SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert, null);
|
||||
performDefaultNotification("locating device", simpleNotification, (short) 255, abortAction);
|
||||
}
|
||||
}
|
||||
|
@ -34,14 +34,22 @@ public class NotificationUtils {
|
||||
return formatText(notificationSpec.sender, notificationSpec.subject, notificationSpec.body, lengthBody, lengthSubject, context);
|
||||
case GENERIC_NAVIGATION:
|
||||
return StringUtils.getFirstOf(notificationSpec.title, notificationSpec.body);
|
||||
case CONVERSATIONS:
|
||||
case FACEBOOK_MESSENGER:
|
||||
case GOOGLE_MESSENGER:
|
||||
case GOOGLE_HANGOUTS:
|
||||
case HIPCHAT:
|
||||
case KAKAO_TALK:
|
||||
case LINE:
|
||||
case RIOT:
|
||||
case SIGNAL:
|
||||
case SKYPE:
|
||||
case SNAPCHAT:
|
||||
case TELEGRAM:
|
||||
case TWITTER:
|
||||
case WHATSAPP:
|
||||
case CONVERSATIONS:
|
||||
case FACEBOOK:
|
||||
case FACEBOOK_MESSENGER:
|
||||
case VIBER:
|
||||
case WECHAT:
|
||||
return StringUtils.ensureNotNull(notificationSpec.body);
|
||||
}
|
||||
return "";
|
||||
|
Loading…
Reference in New Issue
Block a user