2017-04-26 00:14:25 +02:00
|
|
|
/* Copyright (C) 2016-2017 Andreas Shimokawa, Carsten Pfeiffer, João
|
|
|
|
Paulo Barraca
|
2017-03-10 14:53:19 +01: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/>. */
|
2016-12-21 13:51:25 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.devices.hplus;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @author João Paulo Barraca <jpbarraca@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2016-12-23 01:10:38 +01:00
|
|
|
import android.annotation.TargetApi;
|
2016-12-21 13:51:25 +01:00
|
|
|
import android.app.Activity;
|
2016-12-23 01:10:38 +01:00
|
|
|
import android.bluetooth.le.ScanFilter;
|
2016-12-21 13:51:25 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.net.Uri;
|
2016-12-23 01:10:38 +01:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.ParcelUuid;
|
2016-12-21 13:51:25 +01:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
2017-01-02 01:58:37 +01:00
|
|
|
import de.greenrobot.dao.query.QueryBuilder;
|
2016-12-21 13:51:25 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
2017-01-02 01:58:37 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivitySampleDao;
|
2016-12-21 13:51:25 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2016-12-23 01:10:38 +01:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
2017-02-06 02:33:15 +01:00
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
|
2016-12-23 01:10:38 +01:00
|
|
|
|
2016-12-21 13:51:25 +01:00
|
|
|
public class HPlusCoordinator extends AbstractDeviceCoordinator {
|
2017-01-23 01:08:36 +01:00
|
|
|
protected static final Logger LOG = LoggerFactory.getLogger(HPlusCoordinator.class);
|
|
|
|
protected static Prefs prefs = GBApplication.getPrefs();
|
2016-12-21 13:51:25 +01:00
|
|
|
|
2016-12-23 01:10:38 +01:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
public Collection<? extends ScanFilter> createBLEScanFilters() {
|
2017-01-02 01:58:37 +01:00
|
|
|
ParcelUuid hpService = new ParcelUuid(HPlusConstants.UUID_SERVICE_HP);
|
|
|
|
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(hpService).build();
|
2016-12-23 01:10:38 +01:00
|
|
|
return Collections.singletonList(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2016-12-21 13:51:25 +01:00
|
|
|
@Override
|
|
|
|
public DeviceType getSupportedType(GBDeviceCandidate candidate) {
|
|
|
|
String name = candidate.getDevice().getName();
|
|
|
|
if (name != null && name.startsWith("HPLUS")) {
|
|
|
|
return DeviceType.HPLUS;
|
|
|
|
}
|
2016-12-23 01:10:38 +01:00
|
|
|
|
2016-12-21 13:51:25 +01:00
|
|
|
return DeviceType.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2017-04-18 11:47:28 +02:00
|
|
|
@Override
|
|
|
|
public int getBondingStyle(GBDevice deviceCandidate){
|
|
|
|
return BONDING_STYLE_NONE;
|
|
|
|
}
|
|
|
|
|
2017-04-19 21:51:23 +02:00
|
|
|
@Override
|
|
|
|
public boolean supportsCalendarEvents() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:51:25 +01:00
|
|
|
@Override
|
|
|
|
public DeviceType getDeviceType() {
|
|
|
|
return DeviceType.HPLUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends Activity> getPairingActivity() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends Activity> getPrimaryActivity() {
|
|
|
|
return ChartsActivity.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InstallHandler findInstallHandler(Uri uri, Context context) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsActivityDataFetching() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsActivityTracking() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SampleProvider<? extends ActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
|
2017-01-02 01:58:37 +01:00
|
|
|
return new HPlusHealthSampleProvider(device, session);
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsScreenshots() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsAlarmConfiguration() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-26 20:55:00 +01:00
|
|
|
@Override
|
|
|
|
public boolean supportsSmartWakeup(GBDevice device) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:51:25 +01:00
|
|
|
@Override
|
|
|
|
public boolean supportsHeartRateMeasurement(GBDevice device) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getTapString() {
|
|
|
|
return R.string.tap_connected_device_for_activity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getManufacturer() {
|
|
|
|
return "Zeblaze";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean supportsAppsManagement() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends Activity> getAppsManagementActivity() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException {
|
2017-01-02 01:58:37 +01:00
|
|
|
Long deviceId = device.getId();
|
|
|
|
QueryBuilder<?> qb = session.getHPlusHealthActivitySampleDao().queryBuilder();
|
|
|
|
qb.where(HPlusHealthActivitySampleDao.Properties.DeviceId.eq(deviceId)).buildDelete().executeDeleteWithoutDetachingEntities();
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
2017-01-23 01:08:36 +01:00
|
|
|
public static byte getLanguage(String address) {
|
2017-02-06 02:33:15 +01:00
|
|
|
String language = prefs.getString("language", "default");
|
|
|
|
Locale locale;
|
|
|
|
|
|
|
|
if (language.equals("default")) {
|
|
|
|
locale = Locale.getDefault();
|
|
|
|
} else {
|
|
|
|
locale = new Locale(language);
|
|
|
|
}
|
2016-12-21 13:51:25 +01:00
|
|
|
|
2017-02-06 02:33:15 +01:00
|
|
|
if (locale.getLanguage().equals(new Locale("cn").getLanguage())){
|
|
|
|
return HPlusConstants.ARG_LANGUAGE_CN;
|
|
|
|
}else{
|
|
|
|
return HPlusConstants.ARG_LANGUAGE_EN;
|
|
|
|
}
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getTimeMode(String address) {
|
2017-02-06 02:33:15 +01:00
|
|
|
String tmode = prefs.getString(HPlusConstants.PREF_HPLUS_TIMEFORMAT, getContext().getString(R.string.p_timeformat_24h));
|
|
|
|
|
|
|
|
if(tmode.equals(getContext().getString(R.string.p_timeformat_24h))) {
|
|
|
|
return HPlusConstants.ARG_TIMEMODE_24H;
|
|
|
|
}else{
|
|
|
|
return HPlusConstants.ARG_TIMEMODE_12H;
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getUnit(String address) {
|
2017-02-06 02:33:15 +01:00
|
|
|
String units = prefs.getString(HPlusConstants.PREF_HPLUS_UNIT, getContext().getString(R.string.p_unit_metric));
|
|
|
|
|
|
|
|
if(units.equals(getContext().getString(R.string.p_unit_metric))){
|
|
|
|
return HPlusConstants.ARG_UNIT_METRIC;
|
|
|
|
}else{
|
|
|
|
return HPlusConstants.ARG_UNIT_IMPERIAL;
|
|
|
|
}
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getUserWeight(String address) {
|
|
|
|
ActivityUser activityUser = new ActivityUser();
|
|
|
|
|
2016-12-23 02:21:05 +01:00
|
|
|
return (byte) (activityUser.getWeightKg() & 0xFF);
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getUserHeight(String address) {
|
|
|
|
ActivityUser activityUser = new ActivityUser();
|
|
|
|
|
2016-12-23 02:21:05 +01:00
|
|
|
return (byte) (activityUser.getHeightCm() & 0xFF);
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getUserAge(String address) {
|
|
|
|
ActivityUser activityUser = new ActivityUser();
|
|
|
|
|
2016-12-23 02:21:05 +01:00
|
|
|
return (byte) (activityUser.getAge() & 0xFF);
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
2016-12-28 14:50:56 +01:00
|
|
|
public static byte getUserGender(String address) {
|
2016-12-21 13:51:25 +01:00
|
|
|
ActivityUser activityUser = new ActivityUser();
|
|
|
|
|
2016-12-28 14:50:56 +01:00
|
|
|
if (activityUser.getGender() == ActivityUser.GENDER_MALE)
|
2017-01-02 01:58:37 +01:00
|
|
|
return HPlusConstants.ARG_GENDER_MALE;
|
2016-12-28 14:50:56 +01:00
|
|
|
|
2017-01-02 01:58:37 +01:00
|
|
|
return HPlusConstants.ARG_GENDER_FEMALE;
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int getGoal(String address) {
|
|
|
|
ActivityUser activityUser = new ActivityUser();
|
|
|
|
|
|
|
|
return activityUser.getStepsGoal();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getScreenTime(String address) {
|
2017-02-06 02:33:15 +01:00
|
|
|
return (byte) (prefs.getInt(HPlusConstants.PREF_HPLUS_SCREENTIME, 5) & 0xFF);
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getAllDayHR(String address) {
|
2017-02-06 02:33:15 +01:00
|
|
|
Boolean value = (prefs.getBoolean(HPlusConstants.PREF_HPLUS_ALLDAYHR, true));
|
2016-12-22 00:57:57 +01:00
|
|
|
|
2017-02-06 02:33:15 +01:00
|
|
|
if(value){
|
|
|
|
return HPlusConstants.ARG_HEARTRATE_ALLDAY_ON;
|
|
|
|
}else{
|
|
|
|
return HPlusConstants.ARG_HEARTRATE_ALLDAY_OFF;
|
|
|
|
}
|
2017-01-10 14:08:45 +01:00
|
|
|
}
|
|
|
|
|
2016-12-22 00:57:57 +01:00
|
|
|
public static byte getSocial(String address) {
|
|
|
|
//TODO: Figure what this is. Returning the default value
|
|
|
|
|
|
|
|
return (byte) 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte getUserWrist(String address) {
|
2017-02-06 02:33:15 +01:00
|
|
|
String value = prefs.getString(HPlusConstants.PREF_HPLUS_WRIST, getContext().getString(R.string.left));
|
|
|
|
|
|
|
|
if(value.equals(getContext().getString(R.string.left))){
|
|
|
|
return HPlusConstants.ARG_WRIST_LEFT;
|
|
|
|
}else{
|
|
|
|
return HPlusConstants.ARG_WRIST_RIGHT;
|
|
|
|
}
|
2016-12-22 00:57:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int getSITStartTime(String address) {
|
2017-02-06 02:33:15 +01:00
|
|
|
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_START_TIME, 0);
|
2016-12-22 00:57:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int getSITEndTime(String address) {
|
2017-02-06 02:33:15 +01:00
|
|
|
return prefs.getInt(HPlusConstants.PREF_HPLUS_SIT_END_TIME, 0);
|
2016-12-22 00:57:57 +01:00
|
|
|
}
|
|
|
|
|
2016-12-21 13:51:25 +01:00
|
|
|
}
|