mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-06-05 21:49:48 +02:00
Compare commits
3 Commits
0.47.2
...
plugdio/ma
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f231af3ae3 | ||
|
|
33ad3163d7 | ||
|
|
3651ef090b |
@@ -28,5 +28,6 @@ public class GBDeviceEventCallControl extends GBDeviceEvent {
|
||||
OUTGOING,
|
||||
REJECT,
|
||||
START,
|
||||
IGNORE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,11 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.Looper;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -29,27 +33,38 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Locale;
|
||||
import java.util.SimpleTimeZone;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiWeatherConditions;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipFWHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
||||
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.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.amazfitbip.operations.AmazfitBipFetchLogsOperation;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiIcon;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.receivers.GBCallControlReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Version;
|
||||
|
||||
@@ -57,6 +72,9 @@ public class AmazfitBipSupport extends MiBand2Support {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipSupport.class);
|
||||
|
||||
private boolean buttonActionConfirmationReceived = false;
|
||||
private boolean buttonActionApproved = false;
|
||||
|
||||
public AmazfitBipSupport() {
|
||||
super(LOG);
|
||||
}
|
||||
@@ -119,7 +137,90 @@ public class AmazfitBipSupport extends MiBand2Support {
|
||||
|
||||
@Override
|
||||
public void handleButtonEvent() {
|
||||
// ignore
|
||||
super.handleButtonEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runButtonAction() {
|
||||
final Prefs prefs = GBApplication.getPrefs();
|
||||
|
||||
if (currentButtonTimerActivationTime != currentButtonPressTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String requiredButtonPressMessage = prefs.getString(MiBandConst.PREF_MIBAND_BUTTON_PRESS_BROADCAST,
|
||||
this.getContext().getString(R.string.mi2_prefs_button_press_broadcast_default_value));
|
||||
|
||||
if (prefs.getBoolean("require_button_action_confirmazion", false)) {
|
||||
|
||||
buttonActionConfirmationReceived = false;
|
||||
buttonActionApproved = false;
|
||||
LOG.debug("ButtonAction - Ringing the device");
|
||||
//ringing the device
|
||||
onFindDevice(true);
|
||||
//wating for accept or reject
|
||||
final Timer buttonActionAckTimer = new Timer("Mi Band Button Action Timer");
|
||||
buttonActionAckTimer.scheduleAtFixedRate(new TimerTask() {
|
||||
|
||||
int j = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
j++;
|
||||
if (buttonActionConfirmationReceived) {
|
||||
if (buttonActionApproved) {
|
||||
executeButtonAction(requiredButtonPressMessage, prefs.getBoolean(MiBandConst.PREF_MIBAND_BUTTON_ACTION_VIBRATE, false));
|
||||
}
|
||||
|
||||
//TODO: send a proper notification to the device
|
||||
/*
|
||||
NotificationSpec notificationSpec = new NotificationSpec();
|
||||
notificationSpec.type = NotificationType.VIBER;
|
||||
notificationSpec.sender = "ButtonAction1";
|
||||
notificationSpec.sender = "ButtonAction2";
|
||||
notificationSpec.subject = "ButtonAction3";
|
||||
notificationSpec.body = buttonActionApproved ? "Button Action approved" : "Button Action rejected";
|
||||
AmazfitBipSupport.super.onNotification(notificationSpec);
|
||||
*/
|
||||
buttonActionAckTimer.cancel();
|
||||
} else if (j > 20) {
|
||||
buttonActionAckTimer.cancel();
|
||||
//stop ringing
|
||||
onFindDevice(false);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}, 0, 500);
|
||||
} else {
|
||||
executeButtonAction(requiredButtonPressMessage, prefs.getBoolean(MiBandConst.PREF_MIBAND_BUTTON_ACTION_VIBRATE, false));
|
||||
}
|
||||
|
||||
currentButtonActionId = 0;
|
||||
|
||||
currentButtonPressCount = 0;
|
||||
currentButtonPressTime = System.currentTimeMillis();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processActionConfirmation(GBDeviceEventCallControl callEvent) {
|
||||
LOG.info("ButtonAction - processActionConfirmation received: " + callEvent.event);
|
||||
buttonActionConfirmationReceived = true;
|
||||
if ((callEvent.event == GBDeviceEventCallControl.Event.IGNORE) || (callEvent.event == GBDeviceEventCallControl.Event.ACCEPT)) {
|
||||
buttonActionApproved = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void executeButtonAction(String requiredButtonPressMessage, boolean vibrate) {
|
||||
LOG.info("ButtonAction - fire intent");
|
||||
Intent in = new Intent();
|
||||
in.setAction(requiredButtonPressMessage);
|
||||
in.putExtra("button_id", currentButtonActionId);
|
||||
LOG.info("Sending " + requiredButtonPressMessage + " with button_id " + currentButtonActionId);
|
||||
this.getContext().getApplicationContext().sendBroadcast(in);
|
||||
if (vibrate) {
|
||||
performPreferredNotification(null, null, null, MiBand2Service.ALERT_LEVEL_VIBRATE_ONLY, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -131,10 +131,10 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ge
|
||||
public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
|
||||
// We introduce key press counter for notification purposes
|
||||
private static int currentButtonActionId = 0;
|
||||
private static int currentButtonPressCount = 0;
|
||||
private static long currentButtonPressTime = 0;
|
||||
private static long currentButtonTimerActivationTime = 0;
|
||||
protected static int currentButtonActionId = 0;
|
||||
protected static int currentButtonPressCount = 0;
|
||||
protected static long currentButtonPressTime = 0;
|
||||
protected static long currentButtonTimerActivationTime = 0;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MiBand2Support.class);
|
||||
private final DeviceInfoProfile<MiBand2Support> deviceInfoProfile;
|
||||
@@ -922,11 +922,15 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
case HuamiDeviceEvent.CALL_REJECT:
|
||||
callCmd.event = GBDeviceEventCallControl.Event.REJECT;
|
||||
evaluateGBDeviceEvent(callCmd);
|
||||
// this event will be used to process button action confirmation
|
||||
processActionConfirmation(callCmd);
|
||||
break;
|
||||
case HuamiDeviceEvent.CALL_IGNORE:
|
||||
LOG.info("ignore call (not yet supported)");
|
||||
//callCmd.event = GBDeviceEventCallControl.Event.IGNORE;
|
||||
callCmd.event = GBDeviceEventCallControl.Event.IGNORE;
|
||||
//evaluateGBDeviceEvent(callCmd);
|
||||
// this event will be used to process button action confirmation
|
||||
processActionConfirmation(callCmd);
|
||||
break;
|
||||
case HuamiDeviceEvent.BUTTON_PRESSED:
|
||||
LOG.info("button pressed");
|
||||
@@ -964,6 +968,10 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
public void processActionConfirmation(GBDeviceEventCallControl callEvent) {
|
||||
// Not supported for MiBand2, but needed for BIP
|
||||
}
|
||||
|
||||
public void handleButtonEvent() {
|
||||
///logMessageContent(value);
|
||||
|
||||
|
||||
@@ -82,6 +82,9 @@
|
||||
|
||||
<string name="pref_title_language">Language</string>
|
||||
|
||||
<string name="pref_title_require_button_action_confirmazion">Require conformation on screen after Button Action</string>
|
||||
<string name="pref_summary_require_button_action_confirmazion">You can approve or reject the button action on the screen</string>
|
||||
|
||||
<string name="pref_title_minimize_priority">Hide the Gadgetbridge notification</string>
|
||||
<string name="pref_summary_minimize_priority_off">The icon in the status bar and the notification in the lockscreen are shown</string>
|
||||
<string name="pref_summary_minimize_priority_on">The icon in the status bar and the notification in the lockscreen are hidden</string>
|
||||
|
||||
@@ -193,6 +193,11 @@
|
||||
android:key="amazfitbip_language"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_title_language" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="require_button_action_confirmazion"
|
||||
android:summary="@string/pref_summary_require_button_action_confirmazion"
|
||||
android:title="@string/pref_title_require_button_action_confirmazion" />
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:icon="@drawable/ic_device_pebble"
|
||||
|
||||
Reference in New Issue
Block a user