2017-03-10 14:53:19 +01:00
|
|
|
/* Copyright (C) 2016-2017 Carsten Pfeiffer
|
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
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/>. */
|
2016-08-17 00:53:16 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
|
|
|
|
|
2016-11-27 01:09:20 +01:00
|
|
|
import android.annotation.TargetApi;
|
2016-08-17 00:53:16 +02:00
|
|
|
import android.bluetooth.BluetoothDevice;
|
2016-11-27 01:09:20 +01:00
|
|
|
import android.bluetooth.le.ScanFilter;
|
2016-08-17 00:53:16 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.net.Uri;
|
2016-11-27 01:09:20 +01:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.ParcelUuid;
|
|
|
|
import android.support.annotation.NonNull;
|
2016-08-17 00:53:16 +02:00
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2017-07-15 15:01:07 +02:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
2016-11-27 01:09:20 +01:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
2017-07-15 15:01:07 +02:00
|
|
|
import java.util.Date;
|
2017-07-09 16:17:13 +02:00
|
|
|
import java.util.Set;
|
2016-11-27 01:09:20 +01:00
|
|
|
|
2016-11-13 20:47:24 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2016-08-17 00:53:16 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
2016-11-29 22:22:54 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
2016-12-11 02:10:07 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband2.MiBand2FWInstallHandler;
|
2016-11-29 22:22:54 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
2016-10-11 20:23:25 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2016-08-17 00:53:16 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
2016-11-13 20:47:24 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2016-08-17 00:53:16 +02:00
|
|
|
|
2017-07-15 15:01:07 +02:00
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DO_NOT_DISTURB_END;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DO_NOT_DISTURB_START;
|
|
|
|
|
2016-08-17 00:53:16 +02:00
|
|
|
public class MiBand2Coordinator extends MiBandCoordinator {
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(MiBand2Coordinator.class);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DeviceType getDeviceType() {
|
|
|
|
return DeviceType.MIBAND2;
|
|
|
|
}
|
|
|
|
|
2016-11-27 01:09:20 +01:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
public Collection<? extends ScanFilter> createBLEScanFilters() {
|
|
|
|
ParcelUuid mi2Service = new ParcelUuid(MiBandService.UUID_SERVICE_MIBAND2_SERVICE);
|
|
|
|
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(mi2Service).build();
|
|
|
|
return Collections.singletonList(filter);
|
|
|
|
}
|
|
|
|
|
2016-11-27 02:41:52 +01:00
|
|
|
@NonNull
|
2016-08-17 00:53:16 +02:00
|
|
|
@Override
|
2016-11-27 01:09:20 +01:00
|
|
|
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
|
2016-11-27 02:41:52 +01:00
|
|
|
if (candidate.supportsService(MiBand2Service.UUID_SERVICE_MIBAND2_SERVICE)) {
|
|
|
|
return DeviceType.MIBAND2;
|
|
|
|
}
|
|
|
|
|
2016-11-27 01:09:20 +01:00
|
|
|
// and a heuristic for now
|
2016-08-17 00:53:16 +02:00
|
|
|
try {
|
|
|
|
BluetoothDevice device = candidate.getDevice();
|
2017-01-28 23:24:02 +01:00
|
|
|
// if (isHealthWearable(device)) {
|
2016-08-17 00:53:16 +02:00
|
|
|
String name = device.getName();
|
2016-11-27 01:09:20 +01:00
|
|
|
if (name != null && name.equalsIgnoreCase(MiBandConst.MI_BAND2_NAME)) {
|
|
|
|
return DeviceType.MIBAND2;
|
|
|
|
}
|
2017-01-28 23:24:02 +01:00
|
|
|
// }
|
2016-08-17 00:53:16 +02:00
|
|
|
} catch (Exception ex) {
|
|
|
|
LOG.error("unable to check device support", ex);
|
|
|
|
}
|
2016-11-27 01:09:20 +01:00
|
|
|
return DeviceType.UNKNOWN;
|
2016-08-17 00:53:16 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-11 20:23:25 +02:00
|
|
|
@Override
|
|
|
|
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
2016-11-18 21:14:04 +01:00
|
|
|
return true;
|
2016-10-11 20:23:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsAlarmConfiguration() {
|
2016-10-20 20:08:17 +02:00
|
|
|
return true;
|
2016-10-11 20:23:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsActivityDataFetching() {
|
2016-11-18 21:14:04 +01:00
|
|
|
return true;
|
2016-10-11 20:23:25 +02:00
|
|
|
}
|
|
|
|
|
2016-11-29 22:22:54 +01:00
|
|
|
@Override
|
|
|
|
public SampleProvider<? extends AbstractActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
|
|
|
|
return new MiBand2SampleProvider(device, session);
|
|
|
|
}
|
|
|
|
|
2016-11-13 20:47:24 +01:00
|
|
|
public static DateTimeDisplay getDateDisplay(Context context) throws IllegalArgumentException {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
String dateFormatTime = context.getString(R.string.p_dateformat_time);
|
|
|
|
if (dateFormatTime.equals(prefs.getString(MiBandConst.PREF_MI2_DATEFORMAT, dateFormatTime))) {
|
|
|
|
return DateTimeDisplay.TIME;
|
|
|
|
}
|
|
|
|
return DateTimeDisplay.DATE_TIME;
|
|
|
|
}
|
2016-11-13 21:33:43 +01:00
|
|
|
|
|
|
|
public static boolean getActivateDisplayOnLiftWrist() {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
return prefs.getBoolean(MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT, true);
|
|
|
|
}
|
2016-12-11 02:10:07 +01:00
|
|
|
|
2017-07-09 16:17:13 +02:00
|
|
|
public static Set<String> getDisplayItems() {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
return prefs.getStringSet(MiBandConst.PREF_MI2_DISPLAY_ITEMS, null);
|
|
|
|
}
|
2017-07-15 00:40:58 +02:00
|
|
|
|
|
|
|
public static boolean getGoalNotification() {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
return prefs.getBoolean(MiBandConst.PREF_MI2_GOAL_NOTIFICATION, false);
|
|
|
|
}
|
|
|
|
|
2017-07-09 14:30:03 +02:00
|
|
|
public static boolean getRotateWristToSwitchInfo() {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
return prefs.getBoolean(MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO, false);
|
|
|
|
}
|
2017-07-09 16:17:13 +02:00
|
|
|
|
2017-07-15 15:01:07 +02:00
|
|
|
public static Date getDoNotDisturbStart() {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
String time = prefs.getString(PREF_MI2_DO_NOT_DISTURB_START, "01:00");
|
|
|
|
|
|
|
|
DateFormat df = new SimpleDateFormat("HH:mm");
|
|
|
|
try {
|
|
|
|
return df.parse(time);
|
|
|
|
} catch(Exception e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Date();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Date getDoNotDisturbEnd() {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
String time = prefs.getString(PREF_MI2_DO_NOT_DISTURB_END, "06:00");
|
|
|
|
|
|
|
|
DateFormat df = new SimpleDateFormat("HH:mm");
|
|
|
|
try {
|
|
|
|
return df.parse(time);
|
|
|
|
} catch(Exception e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Date();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static DoNotDisturb getDoNotDisturb(Context context) {
|
|
|
|
Prefs prefs = GBApplication.getPrefs();
|
|
|
|
|
|
|
|
String dndOff = context.getString(R.string.p_off);
|
|
|
|
String dndAutomatic = context.getString(R.string.p_automatic);
|
|
|
|
String dndScheduled = context.getString(R.string.p_scheduled);
|
|
|
|
|
|
|
|
String pref = prefs.getString(MiBandConst.PREF_MI2_DO_NOT_DISTURB, dndOff);
|
|
|
|
|
|
|
|
if (dndAutomatic.equals(pref)) {
|
|
|
|
return DoNotDisturb.AUTOMATIC;
|
|
|
|
} else if (dndScheduled.equals(pref)) {
|
|
|
|
return DoNotDisturb.SCHEDULED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DoNotDisturb.OFF;
|
|
|
|
}
|
|
|
|
|
2016-12-11 02:10:07 +01:00
|
|
|
@Override
|
|
|
|
public InstallHandler findInstallHandler(Uri uri, Context context) {
|
|
|
|
MiBand2FWInstallHandler handler = new MiBand2FWInstallHandler(uri, context);
|
|
|
|
return handler.isValid() ? handler : null;
|
|
|
|
}
|
2017-01-26 20:55:00 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsSmartWakeup(GBDevice device) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-17 00:53:16 +02:00
|
|
|
}
|