Bug fixes

This commit is contained in:
mamutcho 2019-12-11 19:38:12 +02:00
parent dfe62fa28f
commit 632f46bc8b
5 changed files with 220 additions and 123 deletions

View File

@ -43,11 +43,11 @@ import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
public class WatchXPlusDeviceCoordinator extends AbstractDeviceCoordinator { public class WatchXPlusDeviceCoordinator extends AbstractDeviceCoordinator {
private static final Logger LOG = LoggerFactory.getLogger(WatchXPlusDeviceSupport.class); private static final Logger LOG = LoggerFactory.getLogger(WatchXPlusDeviceSupport.class);
public static final int FindPhone_ON = -1; private static final int FindPhone_ON = -1;
public static final int FindPhone_OFF = 0; public static final int FindPhone_OFF = 0;
public static boolean isBPCalibrated = false; public static boolean isBPCalibrated = false;
protected static Prefs prefs = GBApplication.getPrefs(); private static Prefs prefs = GBApplication.getPrefs();
@NonNull @NonNull
@Override @Override
@ -59,7 +59,7 @@ public class WatchXPlusDeviceCoordinator extends AbstractDeviceCoordinator {
} }
@Override @Override
protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException { protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) {
} }
@ -185,6 +185,7 @@ Prefs from device settings on main page
// return time format pref // return time format pref
public static byte getTimeMode(SharedPreferences sharedPrefs) { public static byte getTimeMode(SharedPreferences sharedPrefs) {
String timeMode = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, getContext().getString(R.string.p_timeformat_24h)); String timeMode = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, getContext().getString(R.string.p_timeformat_24h));
assert timeMode != null;
if (timeMode.equals(getContext().getString(R.string.p_timeformat_24h))) { if (timeMode.equals(getContext().getString(R.string.p_timeformat_24h))) {
return WatchXPlusConstants.ARG_SET_TIMEMODE_24H; return WatchXPlusConstants.ARG_SET_TIMEMODE_24H;
} else { } else {
@ -202,6 +203,7 @@ Prefs from device settings on main page
public static boolean shouldEnableHeadsUpScreen(SharedPreferences sharedPrefs) { public static boolean shouldEnableHeadsUpScreen(SharedPreferences sharedPrefs) {
String liftMode = sharedPrefs.getString(WatchXPlusConstants.PREF_ACTIVATE_DISPLAY, getContext().getString(R.string.p_on)); String liftMode = sharedPrefs.getString(WatchXPlusConstants.PREF_ACTIVATE_DISPLAY, getContext().getString(R.string.p_on));
// WatchXPlus doesn't support scheduled intervals. Treat it as "on". // WatchXPlus doesn't support scheduled intervals. Treat it as "on".
assert liftMode != null;
return !liftMode.equals(getContext().getString(R.string.p_off)); return !liftMode.equals(getContext().getString(R.string.p_off));
} }
@ -209,6 +211,7 @@ Prefs from device settings on main page
public static boolean shouldEnableDisconnectReminder(SharedPreferences sharedPrefs) { public static boolean shouldEnableDisconnectReminder(SharedPreferences sharedPrefs) {
String lostReminder = sharedPrefs.getString(WatchXPlusConstants.PREF_DISCONNECT_REMIND, getContext().getString(R.string.p_on)); String lostReminder = sharedPrefs.getString(WatchXPlusConstants.PREF_DISCONNECT_REMIND, getContext().getString(R.string.p_on));
// WatchXPlus doesn't support scheduled intervals. Treat it as "on". // WatchXPlus doesn't support scheduled intervals. Treat it as "on".
assert lostReminder != null;
return !lostReminder.equals(getContext().getString(R.string.p_off)); return !lostReminder.equals(getContext().getString(R.string.p_off));
} }
@ -219,6 +222,7 @@ Prefs from device settings on main page
public static int getFindPhone(SharedPreferences sharedPrefs) { public static int getFindPhone(SharedPreferences sharedPrefs) {
String findPhone = sharedPrefs.getString(WatchXPlusConstants.PREF_FIND_PHONE, getContext().getString(R.string.p_off)); String findPhone = sharedPrefs.getString(WatchXPlusConstants.PREF_FIND_PHONE, getContext().getString(R.string.p_off));
assert findPhone != null;
if (findPhone.equals(getContext().getString(R.string.p_off))) { if (findPhone.equals(getContext().getString(R.string.p_off))) {
return FindPhone_OFF; return FindPhone_OFF;
} else if (findPhone.equals(getContext().getString(R.string.p_on))) { } else if (findPhone.equals(getContext().getString(R.string.p_on))) {
@ -230,6 +234,7 @@ Prefs from device settings on main page
int iDuration; int iDuration;
try { try {
assert duration != null;
iDuration = Integer.valueOf(duration); iDuration = Integer.valueOf(duration);
} catch (Exception ex) { } catch (Exception ex) {
iDuration = 60; iDuration = 60;
@ -250,6 +255,7 @@ Prefs from device settings on main page
public static boolean getQuiteHours(SharedPreferences sharedPrefs, Calendar startOut, Calendar endOut) { public static boolean getQuiteHours(SharedPreferences sharedPrefs, Calendar startOut, Calendar endOut) {
String doNotDisturb = sharedPrefs.getString(WatchXPlusConstants.PREF_DO_NOT_DISTURB, getContext().getString(R.string.p_off)); String doNotDisturb = sharedPrefs.getString(WatchXPlusConstants.PREF_DO_NOT_DISTURB, getContext().getString(R.string.p_off));
assert doNotDisturb != null;
if (doNotDisturb.equals(getContext().getString(R.string.p_off))) { if (doNotDisturb.equals(getContext().getString(R.string.p_off))) {
LOG.info(" DND is disabled "); LOG.info(" DND is disabled ");
return false; return false;
@ -303,38 +309,38 @@ Values from device specific settings page
*/ */
// read altitude from preferences // read altitude from preferences
public static int getAltitude(String address) { public static int getAltitude(String address) {
return (int) prefs.getInt(WatchXPlusConstants.PREF_ALTITUDE, 200); return prefs.getInt(WatchXPlusConstants.PREF_ALTITUDE, 200);
} }
// read repeat call notification // read repeat call notification
public static int getRepeatOnCall(String address) { public static int getRepeatOnCall(String address) {
return (int) prefs.getInt(WatchXPlusConstants.PREF_REPEAT, 1); return prefs.getInt(WatchXPlusConstants.PREF_REPEAT, 1);
} }
//read continious call notification //read continious call notification
public static boolean getContiniousVibrationOnCall(String address) { public static boolean getContiniousVibrationOnCall(String address) {
return (boolean) prefs.getBoolean(WatchXPlusConstants.PREF_CONTINIOUS, false); return prefs.getBoolean(WatchXPlusConstants.PREF_CONTINIOUS, false);
} }
//read missed call notification //read missed call notification
public static boolean getMissedCallReminder(String address) { public static boolean getMissedCallReminder(String address) {
return (boolean) prefs.getBoolean(WatchXPlusConstants.PREF_MISSED_CALL, false); return prefs.getBoolean(WatchXPlusConstants.PREF_MISSED_CALL, false);
} }
//read missed call notification //read missed call notification
public static int getMissedCallRepeat(String address) { public static int getMissedCallRepeat(String address) {
return (int) prefs.getInt(WatchXPlusConstants.PREF_MISSED_CALL_REPEAT, 0); return prefs.getInt(WatchXPlusConstants.PREF_MISSED_CALL_REPEAT, 0);
} }
//read button reject call settings //read button reject call settings
public static boolean getButtonReject(String address) { public static boolean getButtonReject(String address) {
return (boolean) prefs.getBoolean(WatchXPlusConstants.PREF_BUTTON_REJECT, false); return prefs.getBoolean(WatchXPlusConstants.PREF_BUTTON_REJECT, false);
} }
//read shake wrist reject call settings //read shake wrist reject call settings
public static boolean getShakeReject(String address) { public static boolean getShakeReject(String address) {
return (boolean) prefs.getBoolean(WatchXPlusConstants.PREF_SHAKE_REJECT, false); return prefs.getBoolean(WatchXPlusConstants.PREF_SHAKE_REJECT, false);
} }
/* /*

View File

@ -23,7 +23,6 @@ import android.preference.Preference;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity; import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
public class WatchXPlusPreferenceActivity extends AbstractSettingsActivity { public class WatchXPlusPreferenceActivity extends AbstractSettingsActivity {
@Override @Override

View File

@ -13,14 +13,9 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public class WatchXPlusSampleProvider extends AbstractSampleProvider<WatchXPlusActivitySample> { public class WatchXPlusSampleProvider extends AbstractSampleProvider<WatchXPlusActivitySample> {
private GBDevice mDevice;
private DaoSession mSession;
public WatchXPlusSampleProvider(GBDevice device, DaoSession session) { public WatchXPlusSampleProvider(GBDevice device, DaoSession session) {
super(device, session); super(device, session);
mSession = session;
mDevice = device;
} }
@Override @Override

View File

@ -17,12 +17,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */ along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.lenovo.watchxplus; package nodomain.freeyourgadget.gadgetbridge.service.devices.lenovo.watchxplus;
import android.app.AlertDialog;
import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -31,14 +29,13 @@ import android.os.Handler;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.IntRange; import androidx.annotation.IntRange;
import androidx.annotation.MainThread;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
@ -50,13 +47,9 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.UUID; import java.util.UUID;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.DebugActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity; import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
@ -97,17 +90,15 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
protected static Prefs prefs = GBApplication.getPrefs(); private static Prefs prefs = GBApplication.getPrefs();
private boolean needsAuth; private boolean needsAuth;
private int sequenceNumber = 0; private int sequenceNumber = 0;
private boolean isCalibrationActive = false; private boolean isCalibrationActive = false;
private Map<Integer, Integer> dataToFetch = new LinkedHashMap<>(); private final Map<Integer, Integer> dataToFetch = new LinkedHashMap<>();
private int requestedDataTimestamp; private int requestedDataTimestamp;
private int dataSlots = 0; private int dataSlots = 0;
private DataType currentDataType; private DataType currentDataType;
@ -123,6 +114,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String broadcastAction = intent.getAction(); String broadcastAction = intent.getAction();
assert broadcastAction != null;
switch (broadcastAction) { switch (broadcastAction) {
case WatchXPlusConstants.ACTION_CALIBRATION: case WatchXPlusConstants.ACTION_CALIBRATION:
enableCalibration(intent.getBooleanExtra(WatchXPlusConstants.ACTION_ENABLE, false)); enableCalibration(intent.getBooleanExtra(WatchXPlusConstants.ACTION_ENABLE, false));
@ -230,7 +222,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
try { try {
TransactionBuilder builder = performInitialized("showNotification"); TransactionBuilder builder = performInitialized("showNotification");
byte[] command = WatchXPlusConstants.CMD_NOTIFICATION_TEXT_TASK; byte[] command = WatchXPlusConstants.CMD_NOTIFICATION_TEXT_TASK;
byte[] text = notificationText.getBytes("UTF-8"); byte[] text = notificationText.getBytes(StandardCharsets.UTF_8);
byte[] messagePart; byte[] messagePart;
int messageLength = text.length; int messageLength = text.length;
@ -280,13 +272,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
return this; return this;
} }
public WatchXPlusDeviceSupport authorizationRequest(TransactionBuilder builder, boolean firstConnect) { public void authorizationRequest(TransactionBuilder builder, boolean firstConnect) {
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(WatchXPlusConstants.CMD_AUTHORIZATION_TASK, buildCommand(WatchXPlusConstants.CMD_AUTHORIZATION_TASK,
WatchXPlusConstants.TASK, WatchXPlusConstants.TASK,
new byte[]{(byte) (firstConnect ? 0x00 : 0x01)})); //possibly not the correct meaning new byte[]{(byte) (firstConnect ? 0x00 : 0x01)})); //possibly not the correct meaning
return this;
} }
private void enableCalibration(boolean enable) { private void enableCalibration(boolean enable) {
@ -388,9 +379,9 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
/** send command to request watch firmware version /** send command to request watch firmware version
* @param builder * @param builder - transaction builder
*/ */
public WatchXPlusDeviceSupport getFirmwareVersion(TransactionBuilder builder) { private WatchXPlusDeviceSupport getFirmwareVersion(TransactionBuilder builder) {
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(WatchXPlusConstants.CMD_FIRMWARE_INFO, buildCommand(WatchXPlusConstants.CMD_FIRMWARE_INFO,
WatchXPlusConstants.READ_VALUE)); WatchXPlusConstants.READ_VALUE));
@ -399,7 +390,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
/** send command to request watch battery state /** send command to request watch battery state
* @param builder * @param builder - transaction builder
*/ */
private WatchXPlusDeviceSupport getBatteryState(TransactionBuilder builder) { private WatchXPlusDeviceSupport getBatteryState(TransactionBuilder builder) {
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
@ -410,7 +401,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
/** initialize device on connect /** initialize device on connect
* @param builder * @param builder - transaction builder
*/ */
public WatchXPlusDeviceSupport initialize(TransactionBuilder builder) { public WatchXPlusDeviceSupport initialize(TransactionBuilder builder) {
getFirmwareVersion(builder) getFirmwareVersion(builder)
@ -479,6 +470,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
} }
private boolean isRinging = false; // store ringing state
private boolean outCall = false; // store outgoing call state
private boolean isMissedCall = false; // missed call state
private int remainingRepeats = 0; // initialize call notification reminds
private int remainingMissedRepeats = 0; // initialize missed call notification reminds
/** send notification on watch when phone rings /** send notification on watch when phone rings
* @param callSpec - phone state * @param callSpec - phone state
* send notification on incoming call, cancel notification when call is answered, ignored or rejected * send notification on incoming call, cancel notification when call is answered, ignored or rejected
@ -486,11 +483,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
* TODO add missed call reminder (send notification to watch at desired period) * TODO add missed call reminder (send notification to watch at desired period)
*/ */
// variables to handle ring notifications // variables to handle ring notifications
boolean isRinging = false; // store ringing state
boolean outCall = false; // store outgoing call state
boolean isMissedCall = false; // missed call state
int remainingRepeats = 0; // initialize call notification reminds
int remainingMissedRepeats = 0; // initialize missed call notification reminds
@Override @Override
public void onSetCallState(final CallSpec callSpec) { public void onSetCallState(final CallSpec callSpec) {
final int repeatDelay = 5000; // repeat delay of 5 sec (watch show call notifications for about 5 sec.) final int repeatDelay = 5000; // repeat delay of 5 sec (watch show call notifications for about 5 sec.)
@ -513,6 +506,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
isRinging = true; isRinging = true;
isMissedCall = false; isMissedCall = false;
remainingRepeats = repeatCount; remainingRepeats = repeatCount;
LOG.info(" Incomming call ");
if (("Phone".equals(callSpec.name)) || (callSpec.name.contains("ropusn")) || (callSpec.name.contains("issed"))) { if (("Phone".equals(callSpec.name)) || (callSpec.name.contains("ropusn")) || (callSpec.name.contains("issed"))) {
// do nothing for notifications without caller name, e.g. system call event // do nothing for notifications without caller name, e.g. system call event
} else { } else {
@ -532,6 +526,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
remainingRepeats = 0; remainingRepeats = 0;
// stop handler // stop handler
handler.removeCallbacks(this); handler.removeCallbacks(this);
cancelNotification();
} }
} }
}, repeatDelay); }, repeatDelay);
@ -542,27 +537,32 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
outCall = false; outCall = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Call start ");
break; break;
case CallSpec.CALL_REJECT: case CallSpec.CALL_REJECT:
isRinging = false; isRinging = false;
outCall = false; outCall = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Call reject ");
break; break;
case CallSpec.CALL_ACCEPT: case CallSpec.CALL_ACCEPT:
isRinging = false; isRinging = false;
outCall = false; outCall = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Call accept ");
break; break;
case CallSpec.CALL_OUTGOING: case CallSpec.CALL_OUTGOING:
outCall = true; outCall = true;
isRinging = false; isRinging = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Outgoing call ");
break; break;
case CallSpec.CALL_END: case CallSpec.CALL_END:
if ((isRinging) && (!outCall)) { if ((isRinging) && (!outCall)) {
LOG.info(" End call ");
// it's a missed call, don't clear notification to preserve small icon near bluetooth // it's a missed call, don't clear notification to preserve small icon near bluetooth
isRinging = false; isRinging = false;
outCall = false; outCall = false;
@ -570,6 +570,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
remainingMissedRepeats = repeatCountMissed; remainingMissedRepeats = repeatCountMissed;
// send missed call notification if enabled in settings // send missed call notification if enabled in settings
if (missedCall) { if (missedCall) {
LOG.info(" Missed call ");
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, "Missed call"); sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, "Missed call");
// repeat missed call notification // repeat missed call notification
final Handler handler = new Handler(); final Handler handler = new Handler();
@ -586,6 +587,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
isMissedCall = false; isMissedCall = false;
// stop handler // stop handler
handler.removeCallbacks(this); handler.removeCallbacks(this);
cancelNotification();
} }
} }
}, repeatMissedDelay); }, repeatMissedDelay);
@ -595,12 +597,14 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
outCall = false; outCall = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Outgoing call end ");
} }
break; break;
default: default:
isRinging = false; isRinging = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Call default ");
break; break;
} }
} }
@ -616,12 +620,16 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
if (buttonReject) { if (buttonReject) {
LOG.info(" call rejected "); LOG.info(" call rejected ");
isRinging = false; isRinging = false;
remainingRepeats = 0;
isMissedCall = false;
callCmd.event = GBDeviceEventCallControl.Event.REJECT; callCmd.event = GBDeviceEventCallControl.Event.REJECT;
evaluateGBDeviceEvent(callCmd); evaluateGBDeviceEvent(callCmd);
cancelNotification(); cancelNotification();
} else { } else {
LOG.info(" call ignored "); LOG.info(" call ignored ");
isRinging = false; isRinging = false;
remainingRepeats = 0;
isMissedCall = false;
callCmd.event = GBDeviceEventCallControl.Event.IGNORE; callCmd.event = GBDeviceEventCallControl.Event.IGNORE;
evaluateGBDeviceEvent(callCmd); evaluateGBDeviceEvent(callCmd);
cancelNotification(); cancelNotification();
@ -638,14 +646,13 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
/** set personal info - read it from About me /** set personal info - read it from About me
* @param builder * @param builder - transaction builder
* @param height - user height in meters * @param height - user height in meters
* @param weight - user weight in kg * @param weight - user weight in kg
* @param age - user age * @param age - user age
* @param gender - user age * @param gender - user age
* send personal information on watch
*/ */
private WatchXPlusDeviceSupport setPersonalInformation(TransactionBuilder builder, int height, int weight, int age, int gender) { private void setPersonalInformation(TransactionBuilder builder, int height, int weight, int age, int gender) {
LOG.warn(" Setting Personal Information... height:"+height+" weight:"+weight+" age:"+age+" gender:"+gender); LOG.warn(" Setting Personal Information... height:"+height+" weight:"+weight+" age:"+age+" gender:"+gender);
byte[] command = WatchXPlusConstants.CMD_SET_PERSONAL_INFO; byte[] command = WatchXPlusConstants.CMD_SET_PERSONAL_INFO;
@ -659,7 +666,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
buildCommand(command, buildCommand(command,
WatchXPlusConstants.WRITE_VALUE, WatchXPlusConstants.WRITE_VALUE,
bArr)); bArr));
return this;
} }
/** handle get/set personal info /** handle get/set personal info
@ -727,7 +733,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onFetchRecordedData(int dataTypes) { public void onFetchRecordedData(int dataTypes) {
TransactionBuilder builder = null; TransactionBuilder builder;
try { try {
builder = performInitialized("fetchData"); builder = performInitialized("fetchData");
@ -807,7 +813,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
case ActivityUser.PREF_USER_STEPS_GOAL: case ActivityUser.PREF_USER_STEPS_GOAL:
setFitnessGoal(builder); setFitnessGoal(builder);
break; break;
// settings from App Settings -> WatchXPlus settings // settings from App Settings -> WatchXPlus settings
case WatchXPlusConstants.PREF_POWER_MODE: case WatchXPlusConstants.PREF_POWER_MODE:
setPowerMode(); setPowerMode();
@ -826,7 +831,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
case WatchXPlusConstants.PREF_BP_CAL_SWITCH: case WatchXPlusConstants.PREF_BP_CAL_SWITCH:
sendBloodPressureCalibration(); sendBloodPressureCalibration();
break; break;
// settings from device card // settings from device card
case WatchXPlusConstants.PREF_ACTIVATE_DISPLAY: case WatchXPlusConstants.PREF_ACTIVATE_DISPLAY:
setHeadsUpScreen(builder, sharedPreferences); setHeadsUpScreen(builder, sharedPreferences);
@ -863,7 +867,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
/** set long sit reminder time /** set long sit reminder time
* @param builder * @param builder - transaction builder
* @param enable - state (true - enabled or false - disabled) * @param enable - state (true - enabled or false - disabled)
* @param hourStart - begin hour * @param hourStart - begin hour
* @param minuteStart - begin minute * @param minuteStart - begin minute
@ -898,29 +902,28 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
/** get Long sit settings from app, and send it to watch /** get Long sit settings from app, and send it to watch
* @param builder * @param builder - transaction builder
* @param sharedPreferences * @param sharedPreferences - shared preferences
* @return
*/ */
private WatchXPlusDeviceSupport setLongSitHours(TransactionBuilder builder, SharedPreferences sharedPreferences) { private void setLongSitHours(TransactionBuilder builder, SharedPreferences sharedPreferences) {
Calendar start = new GregorianCalendar(); Calendar start = new GregorianCalendar();
Calendar end = new GregorianCalendar(); Calendar end = new GregorianCalendar();
boolean enable = WatchXPlusDeviceCoordinator.getLongSitHours(sharedPreferences, start, end); boolean enable = WatchXPlusDeviceCoordinator.getLongSitHours(sharedPreferences, start, end);
if (enable) { if (enable) {
int period = prefs.getInt(WatchXPlusConstants.PREF_LONGSIT_PERIOD, 60); int period = prefs.getInt(WatchXPlusConstants.PREF_LONGSIT_PERIOD, 60);
return this.setLongSitHours(builder, enable, this.setLongSitHours(builder, enable,
start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE), start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE),
end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE), end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE),
period); period);
} else { } else {
// disable Long sit reminder // disable Long sit reminder
LOG.info(" Long sit reminder are disabled"); LOG.info(" Long sit reminder are disabled");
return this.setLongSitSwitch(builder, enable); this.setLongSitSwitch(builder, enable);
} }
} }
/** set long sit reminder switch /** set long sit reminder switch
* @param tbuilder * @param tbuilder - transaction builder
* @param enable - true or false * @param enable - true or false
* enabled or disables long sit reminder (inactivity reminder) on watch * enabled or disables long sit reminder (inactivity reminder) on watch
*/ */
@ -936,7 +939,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
/** set do not disturb time /** set do not disturb time
* @param builder * @param builder - transaction builder
* @param enable - state (true - enabled or false - disabled) * @param enable - state (true - enabled or false - disabled)
* @param hourStart - begin hour * @param hourStart - begin hour
* @param minuteStart - begin minute * @param minuteStart - begin minute
@ -962,7 +965,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
/** set do not disturb switch /** set do not disturb switch
* @param tbuilder * @param tbuilder - transaction builder
* @param enable - true or false * @param enable - true or false
* enabled or disables DND on watch * enabled or disables DND on watch
*/ */
@ -976,22 +979,21 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
/** get DND settings from app, and send it to watch /** get DND settings from app, and send it to watch
* @param builder * @param builder - transaction builder
* @param sharedPreferences * @param sharedPreferences - shared preferences
* @return
*/ */
private WatchXPlusDeviceSupport setQuiteHours(TransactionBuilder builder, SharedPreferences sharedPreferences) { private void setQuiteHours(TransactionBuilder builder, SharedPreferences sharedPreferences) {
Calendar start = new GregorianCalendar(); Calendar start = new GregorianCalendar();
Calendar end = new GregorianCalendar(); Calendar end = new GregorianCalendar();
boolean enable = WatchXPlusDeviceCoordinator.getQuiteHours(sharedPreferences, start, end); boolean enable = WatchXPlusDeviceCoordinator.getQuiteHours(sharedPreferences, start, end);
if (enable) { if (enable) {
return this.setQuiteHours(builder, enable, this.setQuiteHours(builder, enable,
start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE), start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE),
end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE)); end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE));
} else { } else {
// disable DND // disable DND
LOG.info(" Quiet hours are disabled"); LOG.info(" Quiet hours are disabled");
return this.setQuiteHoursSwitch(builder, enable); this.setQuiteHoursSwitch(builder, enable);
} }
} }
@ -999,7 +1001,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
* switch watch power mode * switch watch power mode
* modes (0- normal, 1- energysaving, 2- only watch) * modes (0- normal, 1- energysaving, 2- only watch)
*/ */
private WatchXPlusDeviceSupport setPowerMode() { private void setPowerMode() {
int settingRead = prefs.getInt(WatchXPlusConstants.PREF_POWER_MODE, 0); int settingRead = prefs.getInt(WatchXPlusConstants.PREF_POWER_MODE, 0);
byte[] bArr = new byte[1]; byte[] bArr = new byte[1];
bArr[0] = (byte) settingRead; bArr[0] = (byte) settingRead;
@ -1014,7 +1016,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to set power mode", e); LOG.warn("Unable to set power mode", e);
} }
return this;
} }
/** request watch units /** request watch units
@ -1037,7 +1038,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
/** set watch units /** set watch units
* *
*/ */
private WatchXPlusDeviceSupport setUnitsSettings() { private void setUnitsSettings() {
int units = 0; int units = 0;
if (getContext().getString(R.string.p_unit_metric).equals(units)) { if (getContext().getString(R.string.p_unit_metric).equals(units)) {
LOG.info(" Changed units: metric"); LOG.info(" Changed units: metric");
@ -1058,11 +1059,10 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to set units", e); LOG.warn("Unable to set units", e);
} }
return this;
} }
/** request status of blood pressure calibration /** request status of blood pressure calibration
* @param builder * @param builder - transaction builder
*/ */
private WatchXPlusDeviceSupport getBloodPressureCalibrationStatus(TransactionBuilder builder) { private WatchXPlusDeviceSupport getBloodPressureCalibrationStatus(TransactionBuilder builder) {
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
@ -1075,12 +1075,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
/** send blood pressure calibration to watch /** send blood pressure calibration to watch
* TODO add better error handling if blood pressure calibration is failed * TODO add better error handling if blood pressure calibration is failed
*/ */
private WatchXPlusDeviceSupport sendBloodPressureCalibration() { private void sendBloodPressureCalibration() {
try { try {
int beginCalibration = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_SWITCH, 0); int beginCalibration = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_SWITCH, 0);
if (beginCalibration == 1) { if (beginCalibration == 1) {
LOG.warn(" Calibrating BP - cancel " + beginCalibration); LOG.warn(" Calibrating BP - cancel " + beginCalibration);
return this; return;
} }
int mLowP = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_LOW, 80); int mLowP = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_LOW, 80);
int mHighP = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_HIGH, 130); int mHighP = prefs.getInt(WatchXPlusConstants.PREF_BP_CAL_HIGH, 130);
@ -1093,7 +1093,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
byte mStart = 0x01; // initiate calibration byte mStart = 0x01; // initiate calibration
byte[] bArr = new byte[5]; byte[] bArr = new byte[5];
bArr[0] = (byte) mStart; // byte[08] bArr[0] = mStart; // byte[08]
bArr[1] = (byte) (mHighP >> 8); // byte[09] bArr[1] = (byte) (mHighP >> 8); // byte[09]
bArr[2] = (byte) mHighP; // byte[10] bArr[2] = (byte) mHighP; // byte[10]
bArr[3] = (byte) (mLowP >> 8); // byte[11] bArr[3] = (byte) (mLowP >> 8); // byte[11]
@ -1107,7 +1107,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to send BP Calibration", e); LOG.warn("Unable to send BP Calibration", e);
} }
return this;
} }
/** handle watch response if blood pressure is calibrated /** handle watch response if blood pressure is calibrated
@ -1115,11 +1114,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
* save result to global variable (uses for BP measurement) * save result to global variable (uses for BP measurement)
*/ */
private void handleBloodPressureCalibrationStatus(byte[] value) { private void handleBloodPressureCalibrationStatus(byte[] value) {
if (Conversion.fromByteArr16(value[8]) != 0) { WatchXPlusDeviceCoordinator.isBPCalibrated = Conversion.fromByteArr16(value[8]) == 0;
WatchXPlusDeviceCoordinator.isBPCalibrated = false;
} else {
WatchXPlusDeviceCoordinator.isBPCalibrated = true;
}
} }
/** handle watch response for result of blood pressure calibration /** handle watch response for result of blood pressure calibration
@ -1171,7 +1166,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
int second = prefs.getInt("wxp_newcmd_second", 0); int second = prefs.getInt("wxp_newcmd_second", 0);
byte[] command = new byte[]{(byte) first, (byte) second}; byte[] command = new byte[]{(byte) first, (byte) second};
LOG.info("testing new command " + command); LOG.info("testing new command " + Arrays.toString(command));
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(command, buildCommand(command,
WatchXPlusConstants.READ_VALUE)); WatchXPlusConstants.READ_VALUE));
@ -1187,27 +1182,139 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
public void onSendWeather(WeatherSpec weatherSpec) { public void onSendWeather(WeatherSpec weatherSpec) {
try { try {
TransactionBuilder builder = performInitialized("setWeather"); TransactionBuilder builder = performInitialized("setWeather");
int currentTemp = 0; int currentTemp;
int todayMinTemp = 0; int todayMinTemp;
int todayMaxTemp = 0; int todayMaxTemp;
byte[] command = WatchXPlusConstants.CMD_WEATHER_SET; byte[] command = WatchXPlusConstants.CMD_WEATHER_SET;
byte[] weatherInfo = new byte[5]; byte[] weatherInfo = new byte[5];
String currentCondition = weatherSpec.currentCondition; int currentCondition = weatherSpec.currentConditionCode;
// set weather icon // set weather icon
int currentConditionCode = 0; // 0 is sunny int currentConditionCode = 0; // 0 is sunny
switch (currentCondition) { switch (currentCondition) {
case "Overcast clouds": //Group 2xx: Thunderstorm
case 200: //thunderstorm with light rain: //11d
case 201: //thunderstorm with rain: //11d
case 202: //thunderstorm with heavy rain: //11d
currentConditionCode = 1024;
break;
case 210: //light thunderstorm:: //11d
case 211: //thunderstorm: //11d
case 212: //heavy thunderstorm: //11d
case 221: //ragged thunderstorm: //11d
case 230: //thunderstorm with light drizzle: //11d
case 231: //thunderstorm with drizzle: //11d
case 232: //thunderstorm with heavy drizzle: //11d
currentConditionCode = 1025;
break;
//Group 3xx: Drizzle
case 300: //light intensity drizzle: //09d
case 301: //drizzle: //09d
case 302: //heavy intensity drizzle: //09d
case 310: //light intensity drizzle rain: //09d
case 500: //light rain: //10d
currentConditionCode = 256;
break;
case 311: //drizzle rain: //09d
case 312: //heavy intensity drizzle rain: //09d
case 313: //shower rain and drizzle: //09d
case 314: //heavy shower rain and drizzle: //09d
case 321: //shower drizzle: //09d
case 501: //moderate rain: //10d
currentConditionCode = 1280;
break;
//Group 5xx: Rain
case 511: //freezing rain: //13d
case 520: //light intensity shower rain: //09d
case 521: //shower rain: //09d
case 502: //heavy intensity rain: //10d
case 503: //very heavy rain: //10d
case 504: //extreme rain: //10d
case 522: //heavy intensity shower rain: //09d
case 531: //ragged shower rain: //09d
currentConditionCode = 258;
break;
//Group 6xx: Snow
case 600: //light snow:
case 601: //snow: //[[file:13d.png]]
currentConditionCode = 513;
break;
case 620: //light shower snow: //[[file:13d.png]]
currentConditionCode = 514;
break;
case 602: //heavy snow: //[[file:13d.png]]
case 621: //shower snow: //[[file:13d.png]]
case 622: //heavy shower snow: //[[file:13d.png]]
currentConditionCode = 515;
break;
case 611: //sleet: //[[file:13d.png]]
case 612: //shower sleet: //[[file:13d.png]]
currentConditionCode = 1026;
break;
case 615: //light rain and snow: //[[file:13d.png]]
case 616: //rain and snow: //[[file:13d.png]]
currentConditionCode = 4;
break;
//Group 7xx: Atmosphere
case 741: //fog: //[[file:50d.png]]
case 701: //mist: //[[file:50d.png]]
case 711: //smoke: //[[file:50d.png]]
currentConditionCode = 5;
break;
case 721: //haze: //[[file:50d.png]]
currentConditionCode = 3;
break;
case 731: //sandcase dust whirls: //[[file:50d.png]]
currentConditionCode = 771;
break;
case 751: //sand: //[[file:50d.png]]
case 761: //dust: //[[file:50d.png]]
case 762: //volcanic ash: //[[file:50d.png]]
case 771: //squalls: //[[file:50d.png]]
currentConditionCode = 769;
break;
case 781: //tornado: //[[file:50d.png]]
case 900: //tornado
currentConditionCode = 1283;
break;
//Group 800: Clear
case 800: //clear sky
currentConditionCode = 0;
break;
//Group 80x: Clouds
case 801: //few clouds: //[[file:02d.png]] [[file:02n.png]]
case 802: //scattered clouds: //[[file:03d.png]] [[file:03d.png]]
case 803: //broken clouds: //[[file:04d.png]] [[file:03d.png]]
currentConditionCode = 1; currentConditionCode = 1;
case "Broken clouds": break;
case 804: //overcast clouds: //[[file:04d.png]] [[file:04d.png]]
currentConditionCode = 2; currentConditionCode = 2;
break; break;
//Group 90x: Extreme
case 901: //tropical storm
case 903: //cold
case 904: //hot
case 905: //windy
case 906: //hail
currentConditionCode = 1027;
break;
//Group 9xx: Additional
case 951: //calm
case 952: //light breeze
case 953: //gentle breeze
case 954: //moderate breeze
case 955: //fresh breeze
case 956: //strong breeze
case 957: //high windcase near gale
case 958: //gale
case 959: //severe gale
case 960: //storm
case 961: //violent storm
case 902: //hurricane
case 962: //hurricane
currentConditionCode = 261;
break;
} }
if ((currentCondition.contains("Fog")) || (currentCondition.contains("fog"))) { currentConditionCode = 3; } LOG.info( "Weather cond: " + currentCondition + " icon: " + currentConditionCode);
if ((currentCondition.contains("Rain")) || (currentCondition.contains("rain"))) { currentConditionCode = 257; }
if ((currentCondition.contains("Snow")) || (currentCondition.contains("snow"))) { currentConditionCode = 514; }
if ((currentCondition.contains("Sand")) || (currentCondition.contains("sand"))) { currentConditionCode = 769; }
if ((currentCondition.contains("Dust")) || (currentCondition.contains("dust"))) { currentConditionCode = 769; }
if ((currentCondition.contains("Sleet")) || (currentCondition.contains("sleet"))) { currentConditionCode = 1026; }
// calculate for temps under 0 // calculate for temps under 0
currentTemp = (Math.abs(weatherSpec.currentTemp)) - 273; currentTemp = (Math.abs(weatherSpec.currentTemp)) - 273;
if (currentTemp < 0) { if (currentTemp < 0) {
@ -1304,11 +1411,11 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
return true; return true;
} else if (WatchXPlusConstants.UUID_CHARACTERISTIC_DATABASE_READ.equals(characteristicUUID)) { } else if (WatchXPlusConstants.UUID_CHARACTERISTIC_DATABASE_READ.equals(characteristicUUID)) {
LOG.info(" Value change for characteristic DATABASE: " + characteristicUUID + " value " + value); LOG.info(" Value change for characteristic DATABASE: " + characteristicUUID + " value " + Arrays.toString(value));
handleContentDataChunk(value); handleContentDataChunk(value);
return true; return true;
} else { } else {
LOG.info(" Unhandled characteristic changed: " + characteristicUUID + " value " + value); LOG.info(" Unhandled characteristic changed: " + characteristicUUID + " value " + Arrays.toString(value));
logMessageContent(characteristic.getValue()); logMessageContent(characteristic.getValue());
} }
@ -1516,10 +1623,8 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} else { } else {
LOG.warn(" Got unsupported data package type: " + type); LOG.warn(" Got unsupported data package type: " + type);
} }
} catch (GBException ex) {
LOG.info((ex.getMessage()));
} catch (Exception ex) { } catch (Exception ex) {
LOG.info(ex.getMessage()); LOG.info((ex.getMessage()));
} }
} }
@ -1569,7 +1674,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
TransactionBuilder builder = performInitialized("handleAck"); TransactionBuilder builder = performInitialized("handleAck");
builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand((byte) 0x00)); buildCommand());
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to response to ACK", e); LOG.warn("Unable to response to ACK", e);
@ -1577,14 +1682,14 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
// This is only for ACK response // This is only for ACK response
private byte[] buildCommand(byte action) { private byte[] buildCommand() {
byte[] result = new byte[7]; byte[] result = new byte[7];
System.arraycopy(WatchXPlusConstants.CMD_HEADER, 0, result, 0, 5); System.arraycopy(WatchXPlusConstants.CMD_HEADER, 0, result, 0, 5);
result[2] = (byte) (result.length - 6); result[2] = (byte) (result.length - 6);
result[3] = WatchXPlusConstants.REQUEST; result[3] = WatchXPlusConstants.REQUEST;
result[4] = (byte) sequenceNumber++; result[4] = (byte) sequenceNumber++;
result[5] = action; result[5] = (byte) 0;
result[result.length - 1] = calculateChecksum(result); result[result.length - 1] = calculateChecksum(result);
return result; return result;
@ -1631,10 +1736,8 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
sample.setProvider(provider); sample.setProvider(provider);
provider.addGBActivitySample(sample); provider.addGBActivitySample(sample);
} catch (GBException ex) {
LOG.info((ex.getMessage()));
} catch (Exception ex) { } catch (Exception ex) {
LOG.info(ex.getMessage()); LOG.info((ex.getMessage()));
} }
} }
} }
@ -1687,7 +1790,8 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
private WatchXPlusActivitySample createSample(DBHandler dbHandler, int timestamp) { private WatchXPlusActivitySample createSample(DBHandler dbHandler, int timestamp) {
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId(); Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId(); Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
WatchXPlusActivitySample sample = new WatchXPlusActivitySample(
return new WatchXPlusActivitySample(
timestamp, // ts timestamp, // ts
deviceId, userId, // User id deviceId, userId, // User id
null, // Raw Data null, // Raw Data
@ -1698,8 +1802,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
ActivitySample.NOT_MEASURED, // Distance ActivitySample.NOT_MEASURED, // Distance
ActivitySample.NOT_MEASURED // Calories ActivitySample.NOT_MEASURED // Calories
); );
return sample;
} }
private byte[] buildCommand(byte[] command, byte action) { private byte[] buildCommand(byte[] command, byte action) {
@ -1740,7 +1842,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
/** handle watch response for battery level /** handle watch response for battery level
* @param value * @param value - returned value
*/ */
private void handleBatteryState(byte[] value) { private void handleBatteryState(byte[] value) {
batteryInfo.state = value[8] == 1 ? BatteryState.BATTERY_NORMAL : BatteryState.BATTERY_LOW; batteryInfo.state = value[8] == 1 ? BatteryState.BATTERY_NORMAL : BatteryState.BATTERY_LOW;
@ -1779,8 +1881,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
if (1 != value[8]) { if (1 != value[8]) {
z = false; z = false;
} }
LOG.info(" disconnectReminder: " + Boolean.valueOf(z) + " val: " + value[8]); LOG.info(" disconnectReminder: " + z + " val: " + value[8]);
return;
} }
// read preferences // read preferences
@ -1797,7 +1898,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
activityUser.getAge(),activityUser.getGender()); activityUser.getAge(),activityUser.getGender());
} }
private Handler mFindPhoneHandler = new Handler(); private final Handler mFindPhoneHandler = new Handler();
private void onReverseFindDevice(boolean start) { private void onReverseFindDevice(boolean start) {
if (start) { if (start) {
@ -1832,8 +1933,8 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
} }
// Set Lift Wrist to Light Screen based on saved preferences // Set Lift Wrist to Light Screen based on saved preferences
private WatchXPlusDeviceSupport setHeadsUpScreen(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) { private void setHeadsUpScreen(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) {
return this.setHeadsUpScreen(transactionBuilder, this.setHeadsUpScreen(transactionBuilder,
WatchXPlusDeviceCoordinator.shouldEnableHeadsUpScreen(sharedPreferences)); WatchXPlusDeviceCoordinator.shouldEnableHeadsUpScreen(sharedPreferences));
} }
@ -1860,8 +1961,8 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
return this; return this;
} }
private WatchXPlusDeviceSupport setDisconnectReminder(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) { private void setDisconnectReminder(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) {
return this.setDisconnectReminder(transactionBuilder, this.setDisconnectReminder(transactionBuilder,
WatchXPlusDeviceCoordinator.shouldEnableDisconnectReminder(sharedPreferences)); WatchXPlusDeviceCoordinator.shouldEnableDisconnectReminder(sharedPreferences));
} }
@ -1874,22 +1975,20 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
// Request status of Disconnect reminder // Request status of Disconnect reminder
public WatchXPlusDeviceSupport getDisconnectReminderStatus(TransactionBuilder transactionBuilder) { private void getDisconnectReminderStatus(TransactionBuilder transactionBuilder) {
transactionBuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), transactionBuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(WatchXPlusConstants.CMD_DISCONNECT_REMIND, buildCommand(WatchXPlusConstants.CMD_DISCONNECT_REMIND,
WatchXPlusConstants.READ_VALUE)); WatchXPlusConstants.READ_VALUE));
return this;
} }
// Request status of Lift Wrist to Light Screen, and Shake to Ignore/Reject Call // Request status of Lift Wrist to Light Screen, and Shake to Ignore/Reject Call
public WatchXPlusDeviceSupport getShakeStatus(TransactionBuilder transactionBuilder) { private void getShakeStatus(TransactionBuilder transactionBuilder) {
transactionBuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), transactionBuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE),
buildCommand(WatchXPlusConstants.CMD_SHAKE_SWITCH, buildCommand(WatchXPlusConstants.CMD_SHAKE_SWITCH,
WatchXPlusConstants.READ_VALUE)); WatchXPlusConstants.READ_VALUE));
return this;
} }
// calibrate altitude // calibrate altitude
private WatchXPlusDeviceSupport setAltitude(TransactionBuilder transactionBuilder) { private void setAltitude(TransactionBuilder transactionBuilder) {
int mAltitude = WatchXPlusDeviceCoordinator.getAltitude(getDevice().getAddress()); int mAltitude = WatchXPlusDeviceCoordinator.getAltitude(getDevice().getAddress());
if (mAltitude < 0) { if (mAltitude < 0) {
mAltitude = (Math.abs(mAltitude) ^ 65535) + 1; mAltitude = (Math.abs(mAltitude) ^ 65535) + 1;
@ -1905,7 +2004,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
WatchXPlusConstants.WRITE_VALUE, WatchXPlusConstants.WRITE_VALUE,
bArr)); bArr));
LOG.info(" setAltitude: " + mAltitude); LOG.info(" setAltitude: " + mAltitude);
return this;
} }
// set time format // set time format
@ -1920,8 +2018,8 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
return this; return this;
} }
private WatchXPlusDeviceSupport setLanguageAndTimeFormat(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) { private void setLanguageAndTimeFormat(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) {
return this.setLanguageAndTimeFormat(transactionBuilder, this.setLanguageAndTimeFormat(transactionBuilder,
WatchXPlusDeviceCoordinator.getTimeMode(sharedPreferences), WatchXPlusDeviceCoordinator.getTimeMode(sharedPreferences),
WatchXPlusDeviceCoordinator.getLanguage(sharedPreferences)); WatchXPlusDeviceCoordinator.getLanguage(sharedPreferences));
} }
@ -1940,7 +2038,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
case 2: case 2:
return 1.0d * Math.pow(10.0d, -3.0d) * ((double) i2); return 1.0d * Math.pow(10.0d, -3.0d) * ((double) i2);
case 3: case 3:
return (double) (1 * i2); return (double) (i2);
case 4: case 4:
return 10.0d * Math.pow(10.0d, -6.0d) * ((double) i2); return 10.0d * Math.pow(10.0d, -6.0d) * ((double) i2);
case 5: case 5:

View File

@ -65,7 +65,6 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport {
private static final Logger LOG = LoggerFactory.getLogger(XWatchSupport.class); private static final Logger LOG = LoggerFactory.getLogger(XWatchSupport.class);
private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo(); private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
TransactionBuilder builder = null; TransactionBuilder builder = null;
private DeviceInfo mDeviceInfo;
private byte dayToFetch; //0 = Today; 1 = Yesterday ... private byte dayToFetch; //0 = Today; 1 = Yesterday ...
private byte maxDayToFetch; private byte maxDayToFetch;
long lastButtonTimestamp; long lastButtonTimestamp;
@ -359,7 +358,7 @@ public class XWatchSupport extends AbstractBTLEDeviceSupport {
private void handleDeviceInfo(byte[] value, int status) { private void handleDeviceInfo(byte[] value, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) { if (status == BluetoothGatt.GATT_SUCCESS) {
mDeviceInfo = new DeviceInfo(value); DeviceInfo mDeviceInfo = new DeviceInfo(value);
LOG.warn("Device info: " + mDeviceInfo); LOG.warn("Device info: " + mDeviceInfo);
versionCmd.hwVersion = "1.0"; versionCmd.hwVersion = "1.0";
versionCmd.fwVersion = "1.0"; versionCmd.fwVersion = "1.0";