2021-01-10 23:37:09 +01:00
|
|
|
/* Copyright (C) 2016-2021 Andreas Shimokawa, Carsten Pfeiffer, Cre3per,
|
2019-11-23 21:52:46 +01:00
|
|
|
Daniele Gobbetti, José Rebelo, Petr Kadlec, protomors
|
2019-10-02 22:57:31 +02:00
|
|
|
|
|
|
|
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/>. */
|
|
|
|
package nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3;
|
|
|
|
|
2019-10-09 15:42:03 +02:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
2019-10-16 15:37:29 +02:00
|
|
|
import java.util.ArrayList;
|
2019-10-09 15:42:03 +02:00
|
|
|
import java.util.Calendar;
|
2019-10-16 15:37:29 +02:00
|
|
|
import java.util.List;
|
2019-10-03 11:52:46 +02:00
|
|
|
|
2019-10-02 22:57:31 +02:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
2019-10-03 11:52:46 +02:00
|
|
|
import android.content.SharedPreferences;
|
2019-10-06 15:46:15 +02:00
|
|
|
import android.net.Uri;
|
2019-10-02 22:57:31 +02:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
2019-10-02 23:45:19 +02:00
|
|
|
import org.slf4j.Logger;
|
2019-10-02 22:57:31 +02:00
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2019-10-07 15:28:54 +02:00
|
|
|
import de.greenrobot.dao.query.QueryBuilder;
|
2020-01-04 23:40:50 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2019-10-02 22:57:31 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2019-10-02 23:45:19 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
2022-07-10 22:01:20 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractBLEDeviceCoordinator;
|
2019-10-02 22:57:31 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
2019-10-07 15:28:54 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.MakibesHR3ActivitySampleDao;
|
2019-10-02 22:57:31 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
2020-01-04 23:40:50 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
2019-10-02 22:57:31 +02:00
|
|
|
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
|
|
|
|
|
2019-10-02 23:45:19 +02:00
|
|
|
|
2022-07-10 22:01:20 +02:00
|
|
|
public class MakibesHR3Coordinator extends AbstractBLEDeviceCoordinator {
|
2019-10-02 22:57:31 +02:00
|
|
|
|
2019-10-10 11:32:52 +02:00
|
|
|
public static final int FindPhone_ON = -1;
|
|
|
|
public static final int FindPhone_OFF = 0;
|
|
|
|
|
2019-10-02 23:45:19 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(MakibesHR3Coordinator.class);
|
2019-10-02 22:57:31 +02:00
|
|
|
|
|
|
|
|
2019-10-08 16:07:43 +02:00
|
|
|
public static boolean shouldEnableHeadsUpScreen(SharedPreferences sharedPrefs) {
|
2022-03-07 17:42:46 +01:00
|
|
|
String liftMode = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, getContext().getString(R.string.p_on));
|
2019-10-08 16:07:43 +02:00
|
|
|
|
|
|
|
// Makibes HR3 doesn't support scheduled intervals. Treat it as "on".
|
2019-10-08 17:18:41 +02:00
|
|
|
return !liftMode.equals(getContext().getString(R.string.p_off));
|
2019-10-08 16:07:43 +02:00
|
|
|
}
|
|
|
|
|
2019-10-08 16:46:33 +02:00
|
|
|
public static boolean shouldEnableLostReminder(SharedPreferences sharedPrefs) {
|
2022-03-07 17:52:50 +01:00
|
|
|
String lostReminder = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_DISCONNECT_NOTIFICATION, getContext().getString(R.string.p_on));
|
2019-10-08 16:07:43 +02:00
|
|
|
|
2019-10-08 16:46:33 +02:00
|
|
|
// Makibes HR3 doesn't support scheduled intervals. Treat it as "on".
|
2019-10-08 17:18:41 +02:00
|
|
|
return !lostReminder.equals(getContext().getString(R.string.p_off));
|
2019-10-08 16:07:43 +02:00
|
|
|
}
|
|
|
|
|
2019-10-08 16:46:33 +02:00
|
|
|
public static byte getTimeMode(SharedPreferences sharedPrefs) {
|
2020-01-04 23:40:50 +01:00
|
|
|
GBPrefs gbPrefs = new GBPrefs(new Prefs(sharedPrefs));
|
|
|
|
|
|
|
|
String timeMode = gbPrefs.getTimeFormat();
|
2019-10-03 11:52:46 +02:00
|
|
|
|
2019-10-08 16:46:33 +02:00
|
|
|
if (timeMode.equals(getContext().getString(R.string.p_timeformat_24h))) {
|
|
|
|
return MakibesHR3Constants.ARG_SET_TIMEMODE_24H;
|
|
|
|
} else {
|
|
|
|
return MakibesHR3Constants.ARG_SET_TIMEMODE_12H;
|
|
|
|
}
|
2019-10-03 11:52:46 +02:00
|
|
|
}
|
|
|
|
|
2019-10-09 15:42:03 +02:00
|
|
|
/**
|
|
|
|
* @param startOut out Only hour/minute are used.
|
|
|
|
* @param endOut out Only hour/minute are used.
|
|
|
|
* @return True if quite hours are enabled.
|
|
|
|
*/
|
|
|
|
public static boolean getQuiteHours(SharedPreferences sharedPrefs, Calendar startOut, Calendar endOut) {
|
2022-03-06 23:48:47 +01:00
|
|
|
String doNotDisturb = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO, getContext().getString(R.string.p_off));
|
2019-10-09 15:42:03 +02:00
|
|
|
|
|
|
|
if (doNotDisturb.equals(getContext().getString(R.string.p_off))) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2022-03-06 23:48:47 +01:00
|
|
|
String start = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO_START, "00:00");
|
|
|
|
String end = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_NOAUTO_END, "00:00");
|
2019-10-09 15:42:03 +02:00
|
|
|
|
|
|
|
DateFormat df = new SimpleDateFormat("HH:mm");
|
|
|
|
|
|
|
|
try {
|
|
|
|
startOut.setTime(df.parse(start));
|
|
|
|
endOut.setTime(df.parse(end));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Unexpected exception in MiBand2Coordinator.getTime: " + e.getMessage());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 11:32:52 +02:00
|
|
|
/**
|
|
|
|
* @return {@link #FindPhone_OFF}, {@link #FindPhone_ON}, or the duration
|
|
|
|
*/
|
|
|
|
public static int getFindPhone(SharedPreferences sharedPrefs) {
|
2022-03-07 17:42:46 +01:00
|
|
|
String findPhone = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_FIND_PHONE, getContext().getString(R.string.p_off));
|
2019-10-10 11:32:52 +02:00
|
|
|
|
|
|
|
if (findPhone.equals(getContext().getString(R.string.p_off))) {
|
|
|
|
return FindPhone_OFF;
|
|
|
|
} else if (findPhone.equals(getContext().getString(R.string.p_on))) {
|
|
|
|
return FindPhone_ON;
|
|
|
|
} else { // Duration
|
2022-03-07 17:42:46 +01:00
|
|
|
String duration = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_FIND_PHONE_DURATION, "0");
|
2019-10-10 11:32:52 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
int iDuration;
|
|
|
|
|
|
|
|
try {
|
|
|
|
iDuration = Integer.valueOf(duration);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
LOG.warn(ex.getMessage());
|
|
|
|
iDuration = 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iDuration;
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Unexpected exception in MiBand2Coordinator.getTime: " + e.getMessage());
|
|
|
|
return FindPhone_ON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-02 22:57:31 +02:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
|
|
|
|
String name = candidate.getDevice().getName();
|
|
|
|
|
2019-10-16 15:37:29 +02:00
|
|
|
List<String> deviceNames = new ArrayList<String>(){{
|
|
|
|
add("Y808"); // Chinese version
|
|
|
|
add("MAKIBES HR3"); // English version
|
|
|
|
}};
|
|
|
|
|
|
|
|
if (name != null) {
|
|
|
|
if (deviceNames.contains(name)) {
|
|
|
|
return DeviceType.MAKIBESHR3;
|
|
|
|
}
|
2019-10-02 22:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return DeviceType.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
2019-10-07 15:28:54 +02:00
|
|
|
Long deviceId = device.getId();
|
|
|
|
QueryBuilder<?> qb = session.getMakibesHR3ActivitySampleDao().queryBuilder();
|
|
|
|
qb.where(MakibesHR3ActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
2019-10-02 22:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-12 19:44:45 +02:00
|
|
|
public int getBondingStyle() {
|
2019-10-16 16:41:32 +02:00
|
|
|
return BONDING_STYLE_BOND;
|
2019-10-02 22:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsCalendarEvents() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsRealtimeData() {
|
2019-10-03 11:52:46 +02:00
|
|
|
return true;
|
2019-10-02 22:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsWeather() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsFindDevice() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DeviceType getDeviceType() {
|
|
|
|
return DeviceType.MAKIBESHR3;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Class<? extends Activity> getPairingActivity() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsActivityDataFetching() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsActivityTracking() {
|
2019-10-03 11:52:46 +02:00
|
|
|
return true;
|
2019-10-02 22:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SampleProvider<? extends ActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
|
2019-10-03 11:52:46 +02:00
|
|
|
return new MakibesHR3SampleProvider(device, session);
|
2019-10-02 22:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InstallHandler findInstallHandler(Uri uri, Context context) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsScreenshots() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-06-13 23:02:26 +02:00
|
|
|
public int getAlarmSlotCount(GBDevice device) {
|
2019-10-06 15:47:53 +02:00
|
|
|
return 8;
|
2019-10-02 22:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsSmartWakeup(GBDevice device) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getManufacturer() {
|
|
|
|
return "Makibes";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-06-11 00:31:38 +02:00
|
|
|
public boolean supportsAppsManagement(final GBDevice device) {
|
2019-10-02 22:57:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends Activity> getAppsManagementActivity() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-10-02 23:45:19 +02:00
|
|
|
@Override
|
|
|
|
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
|
|
|
|
return new int[]{
|
2019-10-08 16:07:43 +02:00
|
|
|
R.xml.devicesettings_timeformat,
|
2019-10-08 16:46:33 +02:00
|
|
|
R.xml.devicesettings_liftwrist_display,
|
2019-10-09 15:42:03 +02:00
|
|
|
R.xml.devicesettings_disconnectnotification,
|
2019-10-10 11:32:52 +02:00
|
|
|
R.xml.devicesettings_donotdisturb_no_auto,
|
2021-11-03 17:13:22 +01:00
|
|
|
R.xml.devicesettings_find_phone,
|
|
|
|
R.xml.devicesettings_transliteration
|
2019-10-02 23:45:19 +02:00
|
|
|
};
|
|
|
|
}
|
2019-10-02 22:57:31 +02:00
|
|
|
}
|