1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-28 11:35:48 +01:00

Amazfit Cor: Allow setting menu items

(Also rename/refactor stuff from Mi Band 2 to Huami - still WIP)
This commit is contained in:
Andreas Shimokawa 2018-08-01 22:56:01 +02:00
parent c708bc6e52
commit 486d7bdca6
20 changed files with 182 additions and 80 deletions

View File

@ -29,11 +29,11 @@ import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitcor.AmazfitCorSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband3.MiBand3Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.id115.ID115Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.liveview.LiveviewSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand2Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.no1f1.No1F1Support;
@ -116,7 +116,7 @@ public class DeviceSupportFactory {
deviceSupport = new ServiceDeviceSupport(new MiBandSupport(), EnumSet.of(ServiceDeviceSupport.Flags.THROTTLING, ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;
case MIBAND2:
deviceSupport = new ServiceDeviceSupport(new MiBand2Support(), EnumSet.of(ServiceDeviceSupport.Flags.THROTTLING, ServiceDeviceSupport.Flags.BUSY_CHECKING));
deviceSupport = new ServiceDeviceSupport(new HuamiSupport(), EnumSet.of(ServiceDeviceSupport.Flags.THROTTLING, ServiceDeviceSupport.Flags.BUSY_CHECKING));
break;
case MIBAND3:
deviceSupport = new ServiceDeviceSupport(new MiBand3Support(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));

View File

@ -14,13 +14,14 @@
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.service.devices.huami.miband2;
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.AbstractMiBandOperation;
public abstract class AbstractMiBand2Operation extends AbstractMiBandOperation<MiBand2Support> {
protected AbstractMiBand2Operation(MiBand2Support support) {
public abstract class AbstractHuamiOperation extends AbstractMiBandOperation<HuamiSupport> {
protected AbstractHuamiOperation(HuamiSupport support) {
super(support);
}

View File

@ -16,7 +16,7 @@
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.service.devices.huami.miband2;
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -102,13 +102,13 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotificat
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.deviceinfo.DeviceInfoProfile;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.heartrate.HeartRateProfile;
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiBatteryInfo;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.actions.StopNotificationAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.FetchActivityOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.FetchSportsSummaryOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.InitOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.UpdateFirmwareOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.Mi2NotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.Mi2TextNotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.actions.StopNotificationAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchActivityOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.InitOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.RealtimeSamplesSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -135,7 +135,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VI
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefIntValue;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.getNotificationPrefStringValue;
public class MiBand2Support extends AbstractBTLEDeviceSupport {
public class HuamiSupport extends AbstractBTLEDeviceSupport {
// We introduce key press counter for notification purposes
private static int currentButtonActionId = 0;
@ -143,9 +143,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
private static long currentButtonPressTime = 0;
private static long currentButtonTimerActivationTime = 0;
private static final Logger LOG = LoggerFactory.getLogger(MiBand2Support.class);
private final DeviceInfoProfile<MiBand2Support> deviceInfoProfile;
private final HeartRateProfile<MiBand2Support> heartRateProfile;
private static final Logger LOG = LoggerFactory.getLogger(HuamiSupport.class);
private final DeviceInfoProfile<HuamiSupport> deviceInfoProfile;
private final HeartRateProfile<HuamiSupport> heartRateProfile;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@ -170,11 +170,11 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
private RealtimeSamplesSupport realtimeSamplesSupport;
private boolean alarmClockRinging;
public MiBand2Support() {
public HuamiSupport() {
this(LOG);
}
public MiBand2Support(Logger logger) {
public HuamiSupport(Logger logger) {
super(logger);
addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS);
addSupportedService(GattService.UUID_SERVICE_GENERIC_ATTRIBUTE);
@ -253,19 +253,19 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return timestamp;
}
public MiBand2Support setCurrentTimeWithService(TransactionBuilder builder) {
public HuamiSupport setCurrentTimeWithService(TransactionBuilder builder) {
GregorianCalendar now = BLETypeConversions.createCalendar();
byte[] bytes = getTimeBytes(now, TimeUnit.SECONDS);
builder.write(getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_CURRENT_TIME), bytes);
return this;
}
public MiBand2Support setLowLatency(TransactionBuilder builder) {
public HuamiSupport setLowLatency(TransactionBuilder builder) {
// TODO: low latency?
return this;
}
public MiBand2Support setHighLatency(TransactionBuilder builder) {
public HuamiSupport setHighLatency(TransactionBuilder builder) {
// TODO: high latency?
return this;
}
@ -283,7 +283,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
// MB2: AVL
// TODO: tear down the notifications on quit
public MiBand2Support enableNotifications(TransactionBuilder builder, boolean enable) {
public HuamiSupport enableNotifications(TransactionBuilder builder, boolean enable) {
builder.notify(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_NOTIFICATION), enable);
builder.notify(getCharacteristic(GattService.UUID_SERVICE_CURRENT_TIME), enable);
// Notify CHARACTERISTIC9 to receive random auth code
@ -291,7 +291,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
public MiBand2Support enableFurtherNotifications(TransactionBuilder builder, boolean enable) {
public HuamiSupport enableFurtherNotifications(TransactionBuilder builder, boolean enable) {
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), enable);
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO), enable);
builder.notify(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_DEVICEEVENT), enable);
@ -310,7 +310,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return super.connect();
}
private MiBand2Support sendDefaultNotification(TransactionBuilder builder, SimpleNotification simpleNotification, short repeat, BtLEAction extraAction) {
private HuamiSupport sendDefaultNotification(TransactionBuilder builder, SimpleNotification simpleNotification, short repeat, BtLEAction extraAction) {
LOG.info("Sending notification to MiBand: (" + repeat + " times)");
NotificationStrategy strategy = getNotificationStrategy();
for (short i = 0; i < repeat; i++) {
@ -330,7 +330,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
* @param extraAction an extra action to be executed after every vibration and flash sequence. Allows to abort the repetition, for example.
* @param builder
*/
private MiBand2Support sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, int flashTimes, int flashColour, int originalColour, long flashDuration, BtLEAction extraAction, TransactionBuilder builder) {
private HuamiSupport sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, int flashTimes, int flashColour, int originalColour, long flashDuration, BtLEAction extraAction, TransactionBuilder builder) {
getNotificationStrategy().sendCustomNotification(vibrationProfile, simpleNotification, flashTimes, flashColour, originalColour, flashDuration, extraAction, builder);
LOG.info("Sending notification to MiBand");
return this;
@ -355,14 +355,14 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
private static final byte[] startHeartMeasurementContinuous = new byte[]{0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 1};
private static final byte[] stopHeartMeasurementContinuous = new byte[]{0x15, MiBandService.COMMAND_SET__HR_CONTINUOUS, 0};
private MiBand2Support requestBatteryInfo(TransactionBuilder builder) {
private HuamiSupport requestBatteryInfo(TransactionBuilder builder) {
LOG.debug("Requesting Battery Info!");
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO);
builder.read(characteristic);
return this;
}
public MiBand2Support requestDeviceInfo(TransactionBuilder builder) {
public HuamiSupport requestDeviceInfo(TransactionBuilder builder) {
LOG.debug("Requesting Device Info!");
deviceInfoProfile.requestDeviceInfo(builder);
return this;
@ -375,7 +375,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
* @return
*/
private MiBand2Support setFitnessGoal(TransactionBuilder transaction) {
private HuamiSupport setFitnessGoal(TransactionBuilder transaction) {
LOG.info("Attempting to set Fitness Goal...");
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_8_USER_SETTINGS);
if (characteristic != null) {
@ -399,7 +399,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
* @return
*/
private MiBand2Support setUserInfo(TransactionBuilder transaction) {
private HuamiSupport setUserInfo(TransactionBuilder transaction) {
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_8_USER_SETTINGS);
if (characteristic == null) {
return this;
@ -460,7 +460,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
* @param builder
* @return
*/
private MiBand2Support setWearLocation(TransactionBuilder builder) {
private HuamiSupport setWearLocation(TransactionBuilder builder) {
LOG.info("Attempting to set wear location...");
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_8_USER_SETTINGS);
if (characteristic != null) {
@ -519,7 +519,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
*
* @param builder
*/
private MiBand2Support setHeartrateSleepSupport(TransactionBuilder builder) {
private HuamiSupport setHeartrateSleepSupport(TransactionBuilder builder) {
final boolean enableHrSleepSupport = MiBandCoordinator.getHeartrateSleepSupport(getDevice().getAddress());
if (characteristicHRControlPoint != null) {
builder.notify(characteristicHRControlPoint, true);
@ -535,7 +535,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
private MiBand2Support setHeartrateMeasurementInterval(TransactionBuilder builder, int minutes) {
private HuamiSupport setHeartrateMeasurementInterval(TransactionBuilder builder, int minutes) {
if (characteristicHRControlPoint != null) {
builder.notify(characteristicHRControlPoint, true);
LOG.info("Setting heart rate measurement interval to " + minutes + " minutes");
@ -744,7 +744,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
}
}
public MiBand2Support sendReboot(TransactionBuilder builder) {
public HuamiSupport sendReboot(TransactionBuilder builder) {
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_FIRMWARE), new byte[] { MiBand2Service.COMMAND_FIRMWARE_REBOOT});
return this;
}
@ -1312,7 +1312,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
* Fetch the events from the android device calendars and set the alarms on the miband.
* @param builder
*/
private MiBand2Support sendCalendarEvents(TransactionBuilder builder) {
private HuamiSupport sendCalendarEvents(TransactionBuilder builder) {
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION);
Prefs prefs = GBApplication.getPrefs();
@ -1402,7 +1402,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
}
private MiBand2Support setDateDisplay(TransactionBuilder builder) {
private HuamiSupport setDateDisplay(TransactionBuilder builder) {
DateTimeDisplay dateTimeDisplay = HuamiCoordinator.getDateDisplay(getContext());
LOG.info("Setting date display to " + dateTimeDisplay);
switch (dateTimeDisplay) {
@ -1416,7 +1416,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
private MiBand2Support setTimeFormat(TransactionBuilder builder) {
private HuamiSupport setTimeFormat(TransactionBuilder builder) {
boolean is24Format = DateFormat.is24HourFormat(getContext());
LOG.info("Setting 24h time format to " + is24Format);
if (is24Format) {
@ -1427,7 +1427,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
private MiBand2Support setGoalNotification(TransactionBuilder builder) {
private HuamiSupport setGoalNotification(TransactionBuilder builder) {
boolean enable = HuamiCoordinator.getGoalNotification();
LOG.info("Setting goal notification to " + enable);
if (enable) {
@ -1438,7 +1438,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
private MiBand2Support setActivateDisplayOnLiftWrist(TransactionBuilder builder) {
private HuamiSupport setActivateDisplayOnLiftWrist(TransactionBuilder builder) {
ActivateDisplayOnLift displayOnLift = HuamiCoordinator.getActivateDisplayOnLiftWrist(getContext());
LOG.info("Setting activate display on lift wrist to " + displayOnLift);
@ -1469,7 +1469,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
protected MiBand2Support setDisplayItems(TransactionBuilder builder) {
protected HuamiSupport setDisplayItems(TransactionBuilder builder) {
Set<String> pages = HuamiCoordinator.getDisplayItems();
LOG.info("Setting display items to " + (pages == null ? "none" : pages));
@ -1497,7 +1497,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
private MiBand2Support setRotateWristToSwitchInfo(TransactionBuilder builder) {
private HuamiSupport setRotateWristToSwitchInfo(TransactionBuilder builder) {
boolean enable = HuamiCoordinator.getRotateWristToSwitchInfo();
LOG.info("Setting rotate wrist to cycle info to " + enable);
if (enable) {
@ -1508,12 +1508,12 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
private MiBand2Support setDisplayCaller(TransactionBuilder builder) {
private HuamiSupport setDisplayCaller(TransactionBuilder builder) {
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand2Service.COMMAND_ENABLE_DISPLAY_CALLER);
return this;
}
private MiBand2Support setDoNotDisturb(TransactionBuilder builder) {
private HuamiSupport setDoNotDisturb(TransactionBuilder builder) {
DoNotDisturb doNotDisturb = HuamiCoordinator.getDoNotDisturb(getContext());
LOG.info("Setting do not disturb to " + doNotDisturb);
switch (doNotDisturb) {
@ -1546,7 +1546,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
private MiBand2Support setInactivityWarnings(TransactionBuilder builder) {
private HuamiSupport setInactivityWarnings(TransactionBuilder builder) {
boolean enable = HuamiCoordinator.getInactivityWarnings();
LOG.info("Setting inactivity warnings to " + enable);
@ -1600,7 +1600,7 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
return this;
}
private MiBand2Support setDistanceUnit(TransactionBuilder builder) {
private HuamiSupport setDistanceUnit(TransactionBuilder builder) {
MiBandConst.DistanceUnit unit = HuamiCoordinator.getDistanceUnit();
LOG.info("Setting distance unit to " + unit);
if (unit == MiBandConst.DistanceUnit.METRIC) {

View File

@ -14,7 +14,7 @@
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.service.devices.huami.miband2.actions;
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.actions;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;

View File

@ -51,16 +51,16 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotificat
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiIcon;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.operations.AmazfitBipFetchLogsOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand2Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.FetchActivityOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.FetchSportsSummaryOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchActivityOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchSportsSummaryOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Version;
public class AmazfitBipSupport extends MiBand2Support {
public class AmazfitBipSupport extends HuamiSupport {
private static final Logger LOG = LoggerFactory.getLogger(AmazfitBipSupport.class);

View File

@ -26,14 +26,14 @@ 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.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.Mi2TextNotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand2Support;
// This class in no longer in use except for incoming calls
class AmazfitBipTextNotificationStrategy extends Mi2TextNotificationStrategy {
AmazfitBipTextNotificationStrategy(MiBand2Support support) {
AmazfitBipTextNotificationStrategy(HuamiSupport support) {
super(support);
}

View File

@ -38,7 +38,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.operations.AbstractFetchOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.AbstractFetchOperation;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB;

View File

@ -19,14 +19,64 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitcor;
import android.content.Context;
import android.net.Uri;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitcor.AmazfitCorFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitcor.AmazfitCorService;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class AmazfitCorSupport extends AmazfitBipSupport {
private static final Logger LOG = LoggerFactory.getLogger(AmazfitCorSupport.class);
@Override
protected AmazfitCorSupport setDisplayItems(TransactionBuilder builder) {
Prefs prefs = GBApplication.getPrefs();
Set<String> pages = prefs.getStringSet("cor_display_items", null);
LOG.info("Setting display items to " + (pages == null ? "none" : pages));
byte[] command = AmazfitCorService.COMMAND_CHANGE_SCREENS.clone();
if (pages != null) {
if (pages.contains("status")) {
command[1] |= 0x02;
}
if (pages.contains("notification")) {
command[1] |= 0x04;
}
if (pages.contains("activity")) {
command[1] |= 0x08;
}
if (pages.contains("weather")) {
command[1] |= 0x10;
}
if (pages.contains("alarm")) {
command[1] |= 0x20;
}
if (pages.contains("timer")) {
command[1] |= 0x40;
}
if (pages.contains("settings")) {
command[1] |= 0x80;
}
if (pages.contains("alipay")) {
command[2] |= 0x01;
}
}
builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
return this;
}
@Override
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
return new AmazfitCorFWHelper(uri, context);

View File

@ -24,13 +24,14 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.V2NotificationStrategy;
public class Mi2NotificationStrategy extends V2NotificationStrategy<MiBand2Support> {
public class Mi2NotificationStrategy extends V2NotificationStrategy<HuamiSupport> {
private final BluetoothGattCharacteristic alertLevelCharacteristic;
public Mi2NotificationStrategy(MiBand2Support support) {
public Mi2NotificationStrategy(HuamiSupport support) {
super(support);
alertLevelCharacteristic = support.getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL);
}

View File

@ -30,12 +30,13 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotificat
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.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
public class Mi2TextNotificationStrategy extends Mi2NotificationStrategy {
private final BluetoothGattCharacteristic newAlertCharacteristic;
public Mi2TextNotificationStrategy(MiBand2Support support) {
public Mi2TextNotificationStrategy(HuamiSupport support) {
super(support);
newAlertCharacteristic = support.getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_NEW_ALERT);
}

View File

@ -15,7 +15,7 @@
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.service.devices.huami.miband2.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -40,8 +40,8 @@ import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.AbstractMiBand2Operation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand2Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuamiOperation;
import nodomain.freeyourgadget.gadgetbridge.util.ArrayUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -49,7 +49,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
* An operation that fetches activity data. For every fetch, a new operation must
* be created, i.e. an operation may not be reused for multiple fetches.
*/
public abstract class AbstractFetchOperation extends AbstractMiBand2Operation {
public abstract class AbstractFetchOperation extends AbstractHuamiOperation {
private static final Logger LOG = LoggerFactory.getLogger(AbstractFetchOperation.class);
protected byte lastPacketCounter;
@ -59,7 +59,7 @@ public abstract class AbstractFetchOperation extends AbstractMiBand2Operation {
protected Calendar startTimestamp;
protected int expectedDataLength;
public AbstractFetchOperation(MiBand2Support support) {
public AbstractFetchOperation(HuamiSupport support) {
super(support);
}

View File

@ -14,7 +14,7 @@
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.service.devices.huami.miband2.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations;
import android.text.format.DateUtils;
import android.widget.Toast;
@ -42,7 +42,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.User;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand2Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -55,7 +55,7 @@ public class FetchActivityOperation extends AbstractFetchOperation {
private List<MiBandActivitySample> samples = new ArrayList<>(60*24); // 1day per default
public FetchActivityOperation(MiBand2Support support) {
public FetchActivityOperation(HuamiSupport support) {
super(support);
setName("fetching activity data");
}

View File

@ -15,7 +15,7 @@
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.service.devices.huami.miband2.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations;
import android.support.annotation.NonNull;
import android.widget.Toast;
@ -43,7 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.ActivityDetailsParser;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand2Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -59,7 +59,7 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
private ByteArrayOutputStream buffer;
public FetchSportsDetailsOperation(@NonNull BaseActivitySummary summary, @NonNull MiBand2Support support, @NonNull String lastSyncTimeKey) {
public FetchSportsDetailsOperation(@NonNull BaseActivitySummary summary, @NonNull HuamiSupport support, @NonNull String lastSyncTimeKey) {
super(support);
setName("fetching sport details");
this.summary = summary;

View File

@ -14,7 +14,7 @@
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.service.devices.huami.miband2.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -46,7 +46,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.WaitAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.BipActivityType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand2Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
/**
@ -58,7 +58,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
private ByteArrayOutputStream buffer = new ByteArrayOutputStream(140);
public FetchSportsSummaryOperation(MiBand2Support support) {
public FetchSportsSummaryOperation(HuamiSupport support) {
super(support);
setName("fetching sport summaries");
}

View File

@ -14,7 +14,7 @@
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.service.devices.huami.miband2.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -41,17 +41,17 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand2Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class InitOperation extends AbstractBTLEOperation<MiBand2Support> {
public class InitOperation extends AbstractBTLEOperation<HuamiSupport> {
private static final Logger LOG = LoggerFactory.getLogger(InitOperation.class);
private final TransactionBuilder builder;
private final boolean needsAuth;
private final byte authFlags;
public InitOperation(boolean needsAuth, byte authFlags, MiBand2Support support, TransactionBuilder builder) {
public InitOperation(boolean needsAuth, byte authFlags, HuamiSupport support, TransactionBuilder builder) {
super(support);
this.needsAuth = needsAuth;
this.authFlags = authFlags;

View File

@ -14,7 +14,7 @@
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.service.devices.huami.miband2.operations;
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
@ -39,13 +39,13 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareInfo;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.AbstractMiBand2Operation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.AbstractHuamiOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiFirmwareType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.MiBand2Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class UpdateFirmwareOperation extends AbstractMiBand2Operation {
public class UpdateFirmwareOperation extends AbstractHuamiOperation {
private static final Logger LOG = LoggerFactory.getLogger(UpdateFirmwareOperation.class);
protected final Uri uri;
@ -54,7 +54,7 @@ public class UpdateFirmwareOperation extends AbstractMiBand2Operation {
protected final Prefs prefs = GBApplication.getPrefs();
protected HuamiFirmwareInfo firmwareInfo;
public UpdateFirmwareOperation(Uri uri, MiBand2Support support) {
public UpdateFirmwareOperation(Uri uri, HuamiSupport support) {
super(support);
this.uri = uri;
fwCControlChar = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_FIRMWARE);

View File

@ -217,6 +217,7 @@
<item>@string/p_menuitem_settings</item>
<item>@string/p_menuitem_alipay</item>
</string-array>
<string-array name="pref_bip_display_items_default">
<item>@string/p_menuitem_status</item>
<item>@string/p_menuitem_activity</item>
@ -227,6 +228,39 @@
<item>@string/p_menuitem_settings</item>
</string-array>
<string-array name="pref_cor_display_items">
<item>@string/menuitem_status</item>
<item>@string/menuitem_notifications</item>
<item>@string/menuitem_activity</item>
<item>@string/menuitem_weather</item>
<item>@string/menuitem_alarm</item>
<item>@string/menuitem_timer</item>
<item>@string/menuitem_settings</item>
<item>@string/menuitem_alipay</item>
</string-array>
<string-array name="pref_cor_display_items_values">
<item>@string/p_menuitem_status</item>
<item>@string/p_menuitem_notifications</item>
<item>@string/p_menuitem_activity</item>
<item>@string/p_menuitem_weather</item>
<item>@string/p_menuitem_alarm</item>
<item>@string/p_menuitem_timer</item>
<item>@string/p_menuitem_settings</item>
<item>@string/p_menuitem_alipay</item>
</string-array>
<string-array name="pref_cor_display_items_default">
<item>@string/p_menuitem_status</item>
<item>@string/p_menuitem_notifications</item>
<item>@string/p_menuitem_activity</item>
<item>@string/p_menuitem_weather</item>
<item>@string/p_menuitem_alarm</item>
<item>@string/p_menuitem_timer</item>
<item>@string/p_menuitem_settings</item>
</string-array>
<string-array name="pref_entries_unit_system">
<item>@string/unit_metric</item>
<item>@string/unit_imperial</item>

View File

@ -251,6 +251,7 @@
<string name="preferences_category_device_specific_settings">Device specific settings</string>
<string name="preferences_miband_settings">Mi Band / Amazfit settings</string>
<string name="preferences_amazfitbip_settings">Amazfit Bip settings</string>
<string name="preferences_amazfitcor_settings">Amazfit Cor settings</string>s
<string name="male">Male</string>
<string name="female">Female</string>
<string name="other">Other</string>
@ -582,6 +583,7 @@
<string name="menuitem_shortcut_alipay">Alipay (Shortcut)</string>
<string name="menuitem_shortcut_weather">Weather (Shortcut)</string>
<string name="menuitem_status">Status</string>
<string name="menuitem_notifications">Notifications</string>
<string name="menuitem_activity">Activity</string>
<string name="menuitem_weather">Weather</string>
<string name="menuitem_alarm">Alarm</string>

View File

@ -29,6 +29,7 @@
<item name="p_menuitem_compass" type="string">compass</item>
<item name="p_menuitem_settings" type="string">settings</item>
<item name="p_menuitem_alipay" type="string">alipay</item>
<item name="p_menuitem_notifications" type="string">notifications</item>
<item name="p_off" type="string">off</item>
<item name="p_on" type="string">on</item>

View File

@ -202,6 +202,18 @@
android:summary="@string/mi2_prefs_display_items_summary"
android:title="@string/mi2_prefs_display_items"/>
</PreferenceScreen>
<PreferenceScreen
android:icon="@drawable/ic_device_miband"
android:title="@string/preferences_amazfitcor_settings">
<MultiSelectListPreference
android:dialogTitle="@string/mi2_prefs_display_items"
android:defaultValue="@array/pref_cor_display_items_default"
android:entries="@array/pref_cor_display_items"
android:entryValues="@array/pref_cor_display_items_values"
android:key="cor_display_items"
android:summary="@string/mi2_prefs_display_items_summary"
android:title="@string/mi2_prefs_display_items"/>
</PreferenceScreen>
<PreferenceScreen
android:icon="@drawable/ic_device_pebble"
android:key="pref_key_pebble"