mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-02-04 04:54:10 +01:00
Mi Band 2: use native notification patterns instead of manually timed ones
What we do now is: - Send a notification with the app icon - Send the vibration pattern right away (this causes the first unwanted vibration to be cancelled immediately and only the pattern is noticable, while the icon stays on screen during the vibration pattern) - (optional) send the text together with a generic sms icon This also fixes problems of text not appearing in newer firmwares when a notification pattern with repeat has been set in Mi Band settings.
This commit is contained in:
parent
4f246b3ed9
commit
669f4bcdd0
@ -37,24 +37,19 @@ public class Mi2NotificationStrategy extends V2NotificationStrategy<MiBand2Suppo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) {
|
protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) {
|
||||||
for (short i = 0; i < vibrationProfile.getRepeat(); i++) {
|
startNotify(builder, vibrationProfile.getAlertLevel(), simpleNotification);
|
||||||
int[] onOffSequence = vibrationProfile.getOnOffSequence();
|
BluetoothGattCharacteristic alert = getSupport().getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL);
|
||||||
for (int j = 0; j < onOffSequence.length; j++) {
|
byte repeat = (byte) (vibrationProfile.getRepeat() * (vibrationProfile.getOnOffSequence().length / 2));
|
||||||
int on = onOffSequence[j];
|
if (repeat > 0) {
|
||||||
on = Math.min(500, on); // longer than 500ms is not possible
|
short vibration = (short) vibrationProfile.getOnOffSequence()[0];
|
||||||
startNotify(builder, vibrationProfile.getAlertLevel(), simpleNotification);
|
short pause = (short) vibrationProfile.getOnOffSequence()[1];
|
||||||
builder.wait(on);
|
int duration = (vibration + pause) * repeat;
|
||||||
stopNotify(builder);
|
builder.write(alert, new byte[]{-1, (byte) (vibration & 255), (byte) (vibration >> 8 & 255), (byte) (pause & 255), (byte) (pause >> 8 & 255), repeat});
|
||||||
|
builder.wait(duration);
|
||||||
|
}
|
||||||
|
|
||||||
if (++j < onOffSequence.length) {
|
if (extraAction != null) {
|
||||||
int off = Math.max(onOffSequence[j], 25); // wait at least 25ms
|
builder.add(extraAction);
|
||||||
builder.wait(off);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (extraAction != null) {
|
|
||||||
builder.add(extraAction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user