mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-15 21:27:51 +01:00
Amazfit Bip: support E-Mail icon and do also send notifications from unknown sources
This commit is contained in:
parent
6f522ec5f2
commit
b19cf85a12
@ -17,9 +17,16 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
||||||
|
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.NotificationType;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
|
||||||
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.NotificationUtils;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||||
|
|
||||||
public class AmazfitBipSupport extends MiBand2Support {
|
public class AmazfitBipSupport extends MiBand2Support {
|
||||||
@Override
|
@Override
|
||||||
@ -27,6 +34,24 @@ public class AmazfitBipSupport extends MiBand2Support {
|
|||||||
return new AmazfitBipTextNotificationStrategy(this);
|
return new AmazfitBipTextNotificationStrategy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNotification(NotificationSpec notificationSpec) {
|
||||||
|
if (notificationSpec.type == NotificationType.GENERIC_ALARM_CLOCK) {
|
||||||
|
onAlarmClock(notificationSpec);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String message = NotificationUtils.getPreferredTextFor(notificationSpec, 40, 40, getContext()).trim();
|
||||||
|
|
||||||
|
// Fixup purging notification text in getPreferredTextFor() in case of UNKNOWN
|
||||||
|
if (notificationSpec.type == NotificationType.UNKNOWN) {
|
||||||
|
message = StringUtils.getFirstOf(notificationSpec.title, notificationSpec.body);
|
||||||
|
|
||||||
|
}
|
||||||
|
String origin = notificationSpec.type.getGenericType();
|
||||||
|
SimpleNotification simpleNotification = new SimpleNotification(message, BLETypeConversions.toAlertCategory(notificationSpec.type));
|
||||||
|
performPreferredNotification(origin + " received", origin, simpleNotification, MiBand2Service.ALERT_LEVEL_MESSAGE, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFindDevice(boolean start) {
|
public void onFindDevice(boolean start) {
|
||||||
CallSpec callSpec = new CallSpec();
|
CallSpec callSpec = new CallSpec();
|
||||||
|
@ -16,10 +16,15 @@
|
|||||||
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 android.support.annotation.NonNull;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory;
|
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.btle.profiles.alertnotification.OverflowStrategy;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.Mi2TextNotificationStrategy;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.Mi2TextNotificationStrategy;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
||||||
@ -33,14 +38,27 @@ class AmazfitBipTextNotificationStrategy extends Mi2TextNotificationStrategy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) {
|
protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) {
|
||||||
if (simpleNotification != null && simpleNotification.getAlertCategory() == AlertCategory.IncomingCall) {
|
|
||||||
// incoming calls are notified solely via NewAlert including caller ID
|
|
||||||
sendAlert(simpleNotification, builder);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (simpleNotification != null && !StringUtils.isEmpty(simpleNotification.getMessage())) {
|
if (simpleNotification != null && !StringUtils.isEmpty(simpleNotification.getMessage())) {
|
||||||
sendAlert(simpleNotification, builder);
|
sendAlert(simpleNotification, builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void sendAlert(@NonNull SimpleNotification simpleNotification, TransactionBuilder builder) {
|
||||||
|
AlertNotificationProfile<?> profile = new AlertNotificationProfile<>(getSupport());
|
||||||
|
|
||||||
|
AlertCategory category = simpleNotification.getAlertCategory();
|
||||||
|
switch (simpleNotification.getAlertCategory()) {
|
||||||
|
// only these are confirmed working so far on Amazfit Bip
|
||||||
|
case Email:
|
||||||
|
case IncomingCall:
|
||||||
|
case SMS:
|
||||||
|
break;
|
||||||
|
// default to SMS for non working categories
|
||||||
|
default:
|
||||||
|
category = AlertCategory.SMS;
|
||||||
|
}
|
||||||
|
NewAlert alert = new NewAlert(category, 1, simpleNotification.getMessage());
|
||||||
|
profile.newAlert(builder, alert, OverflowStrategy.MAKE_MULTIPLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,7 +435,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performPreferredNotification(String task, String notificationOrigin, SimpleNotification simpleNotification, int alertLevel, BtLEAction extraAction) {
|
protected void performPreferredNotification(String task, String notificationOrigin, SimpleNotification simpleNotification, int alertLevel, BtLEAction extraAction) {
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized(task);
|
TransactionBuilder builder = performInitialized(task);
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
@ -529,7 +529,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
|||||||
performPreferredNotification(origin + " received", origin, simpleNotification, alertLevel, null);
|
performPreferredNotification(origin + " received", origin, simpleNotification, alertLevel, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onAlarmClock(NotificationSpec notificationSpec) {
|
protected void onAlarmClock(NotificationSpec notificationSpec) {
|
||||||
alarmClockRinging = true;
|
alarmClockRinging = true;
|
||||||
AbortTransactionAction abortAction = new StopNotificationAction(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL)) {
|
AbortTransactionAction abortAction = new StopNotificationAction(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL)) {
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user