mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-26 00:21:45 +01:00
Add method to set the language of the watch. Note: Android Studio seems to have done automatic code formatting here.
This commit is contained in:
parent
876515f1fd
commit
0a6d0bd178
@ -34,6 +34,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@ -106,6 +107,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
addSupportedService(ZeTimeConstants.UUID_SERVICE_EXTEND);
|
||||
addSupportedService(ZeTimeConstants.UUID_SERVICE_HEART_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||
LOG.info("Initializing");
|
||||
@ -129,6 +131,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
requestBatteryInfo(builder);
|
||||
setUserInfo(builder);
|
||||
setUserGoals(builder);
|
||||
setLanguage(builder);
|
||||
requestActivityInfo(builder);
|
||||
synchronizeTime(builder);
|
||||
initMusicVolume(builder);
|
||||
@ -143,8 +146,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
public void onSendConfiguration(String config) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("sendConfiguration");
|
||||
switch(config)
|
||||
{
|
||||
switch (config) {
|
||||
case ZeTimeConstants.PREF_WRIST:
|
||||
setWrist(builder);
|
||||
break;
|
||||
@ -291,8 +293,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
|
||||
for (Alarm alarm : alarms) {
|
||||
if(remindersOnWatch[alarm.getPosition()][0] == 0)
|
||||
{
|
||||
if (remindersOnWatch[alarm.getPosition()][0] == 0) {
|
||||
alarmMessage = new byte[]{
|
||||
ZeTimeConstants.CMD_PREAMBLE,
|
||||
ZeTimeConstants.CMD_REMINDERS,
|
||||
@ -457,8 +458,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
notification[notification_length - 1] = ZeTimeConstants.CMD_END;
|
||||
callIncoming = false;
|
||||
}
|
||||
if(notification != null)
|
||||
{
|
||||
if (notification != null) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("setCallState");
|
||||
sendMsgToWatch(builder, notification);
|
||||
@ -628,8 +628,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
if (buildnumber.compareTo("B4.1") >= 0) // if using firmware 1.7 Build 41 and above use newer icons
|
||||
{
|
||||
weather[9] = Weather.mapToZeTimeCondition(weatherSpec.currentConditionCode);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
weather[9] = Weather.mapToZeTimeConditionOld(weatherSpec.currentConditionCode);
|
||||
}
|
||||
for (int forecast = 0; forecast < 3; forecast++) {
|
||||
@ -670,8 +669,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
int subject_length = 0;
|
||||
int body_length = notificationSpec.body.getBytes(StandardCharsets.UTF_8).length;
|
||||
if(body_length > 256)
|
||||
{
|
||||
if (body_length > 256) {
|
||||
body_length = 256;
|
||||
}
|
||||
int notification_length = body_length;
|
||||
@ -698,26 +696,22 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
(byte) ((time.get(Calendar.SECOND) % 10) + '0'),
|
||||
};
|
||||
|
||||
if (notificationSpec.sender != null)
|
||||
{
|
||||
if (notificationSpec.sender != null) {
|
||||
notification_length += notificationSpec.sender.getBytes(StandardCharsets.UTF_8).length;
|
||||
subject_length = notificationSpec.sender.getBytes(StandardCharsets.UTF_8).length;
|
||||
subject = new byte[subject_length];
|
||||
System.arraycopy(notificationSpec.sender.getBytes(StandardCharsets.UTF_8), 0, subject, 0, subject_length);
|
||||
} else if(notificationSpec.phoneNumber != null)
|
||||
{
|
||||
} else if (notificationSpec.phoneNumber != null) {
|
||||
notification_length += notificationSpec.phoneNumber.getBytes(StandardCharsets.UTF_8).length;
|
||||
subject_length = notificationSpec.phoneNumber.getBytes(StandardCharsets.UTF_8).length;
|
||||
subject = new byte[subject_length];
|
||||
System.arraycopy(notificationSpec.phoneNumber.getBytes(StandardCharsets.UTF_8), 0, subject, 0, subject_length);
|
||||
} else if(notificationSpec.subject != null)
|
||||
{
|
||||
} else if (notificationSpec.subject != null) {
|
||||
notification_length += notificationSpec.subject.getBytes(StandardCharsets.UTF_8).length;
|
||||
subject_length = notificationSpec.subject.getBytes(StandardCharsets.UTF_8).length;
|
||||
subject = new byte[subject_length];
|
||||
System.arraycopy(notificationSpec.subject.getBytes(StandardCharsets.UTF_8), 0, subject, 0, subject_length);
|
||||
} else if(notificationSpec.title != null)
|
||||
{
|
||||
} else if (notificationSpec.title != null) {
|
||||
notification_length += notificationSpec.title.getBytes(StandardCharsets.UTF_8).length;
|
||||
subject_length = notificationSpec.title.getBytes(StandardCharsets.UTF_8).length;
|
||||
subject = new byte[subject_length];
|
||||
@ -738,8 +732,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
System.arraycopy(datetimeBytes, 0, notification, 9 + subject_length + body_length, datetimeBytes.length);
|
||||
notification[notification_length - 1] = ZeTimeConstants.CMD_END;
|
||||
|
||||
switch(notificationSpec.type)
|
||||
{
|
||||
switch (notificationSpec.type) {
|
||||
case GENERIC_SMS:
|
||||
notification[5] = ZeTimeConstants.NOTIFICATION_SMS;
|
||||
break;
|
||||
@ -893,28 +886,24 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (ZeTimeConstants.UUID_NOTIFY_CHARACTERISTIC.equals(characteristicUUID))
|
||||
{
|
||||
} else if (ZeTimeConstants.UUID_NOTIFY_CHARACTERISTIC.equals(characteristicUUID)) {
|
||||
byte[] data = receiveCompleteMsg(characteristic.getValue());
|
||||
if (isMsgFormatOK(data)) {
|
||||
switch (data[1])
|
||||
{
|
||||
switch (data[1]) {
|
||||
case ZeTimeConstants.CMD_MUSIC_CONTROL:
|
||||
handleMusicControl(data);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
|
||||
logMessageContent(characteristic.getValue());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isMsgFormatOK(byte[] msg)
|
||||
{
|
||||
private boolean isMsgFormatOK(byte[] msg) {
|
||||
if (msg != null) {
|
||||
if (msg[0] == ZeTimeConstants.CMD_PREAMBLE) {
|
||||
if ((msg[3] != 0) || (msg[4] != 0)) {
|
||||
@ -931,8 +920,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
return false;
|
||||
}
|
||||
|
||||
private byte[] receiveCompleteMsg(byte[] msg)
|
||||
{
|
||||
private byte[] receiveCompleteMsg(byte[] msg) {
|
||||
if (msgPart == 0) {
|
||||
int payloadSize = (msg[4] << 8) & 0xff00 | (msg[3] & 0xff);
|
||||
if (payloadSize > 14) {
|
||||
@ -943,8 +931,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
} else {
|
||||
return msg;
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
byte[] completeMsg = new byte[lastMsg.length + msg.length];
|
||||
System.arraycopy(lastMsg, 0, completeMsg, 0, lastMsg.length);
|
||||
System.arraycopy(msg, 0, completeMsg, lastMsg.length, msg.length);
|
||||
@ -1023,11 +1010,9 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
private void handleBatteryInfo(byte[] value) {
|
||||
batteryCmd.level = ((short) value[5]);
|
||||
if(batteryCmd.level <= 25)
|
||||
{
|
||||
if (batteryCmd.level <= 25) {
|
||||
batteryCmd.state = BatteryState.BATTERY_LOW;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
batteryCmd.state = BatteryState.BATTERY_NORMAL;
|
||||
}
|
||||
evaluateGBDeviceEvent(batteryCmd);
|
||||
@ -1036,8 +1021,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
private void handleDeviceInfo(byte[] value) {
|
||||
value[value.length - 1] = 0; // convert the end to a String end
|
||||
byte[] string = Arrays.copyOfRange(value, 6, value.length - 1);
|
||||
if(value[5] == 5)
|
||||
{
|
||||
if (value[5] == 5) {
|
||||
versionCmd.fwVersion = new String(string);
|
||||
} else {
|
||||
versionCmd.hwVersion = new String(string);
|
||||
@ -1045,24 +1029,20 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
evaluateGBDeviceEvent(versionCmd);
|
||||
}
|
||||
|
||||
private void handleActivityFetching(byte[] msg)
|
||||
{
|
||||
private void handleActivityFetching(byte[] msg) {
|
||||
availableStepsData = (int) ((msg[5] & 0xff) | (msg[6] << 8) & 0xff00);
|
||||
availableSleepData = (int) ((msg[7] & 0xff) | (msg[8] << 8) & 0xff00);
|
||||
availableHeartRateData = (int) ((msg[9] & 0xff) | (msg[10] << 8) & 0xff00);
|
||||
if (availableStepsData > 0) {
|
||||
getStepData();
|
||||
} else if(availableHeartRateData > 0)
|
||||
{
|
||||
} else if (availableHeartRateData > 0) {
|
||||
getHeartRateData();
|
||||
} else if(availableSleepData > 0)
|
||||
{
|
||||
} else if (availableSleepData > 0) {
|
||||
getSleepData();
|
||||
}
|
||||
}
|
||||
|
||||
private void getStepData()
|
||||
{
|
||||
private void getStepData() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("fetchStepData");
|
||||
builder.write(writeCharacteristic, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||
@ -1080,8 +1060,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteStepData()
|
||||
{
|
||||
private void deleteStepData() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("deleteStepData");
|
||||
sendMsgToWatch(builder, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||
@ -1097,8 +1076,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void getHeartRateData()
|
||||
{
|
||||
private void getHeartRateData() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("fetchHeartRateData");
|
||||
builder.write(writeCharacteristic, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||
@ -1115,8 +1093,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteHeartRateData()
|
||||
{
|
||||
private void deleteHeartRateData() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("deleteHeartRateData");
|
||||
sendMsgToWatch(builder, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||
@ -1132,8 +1109,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void getSleepData()
|
||||
{
|
||||
private void getSleepData() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("fetchSleepData");
|
||||
builder.write(writeCharacteristic, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||
@ -1151,8 +1127,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteSleepData()
|
||||
{
|
||||
private void deleteSleepData() {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized("deleteSleepData");
|
||||
sendMsgToWatch(builder, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||
@ -1168,8 +1143,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleStepsData(byte[] msg)
|
||||
{
|
||||
private void handleStepsData(byte[] msg) {
|
||||
ZeTimeActivitySample sample = new ZeTimeActivitySample();
|
||||
Calendar now = GregorianCalendar.getInstance();
|
||||
int timestamp = (msg[10] << 24) & 0xff000000 | (msg[9] << 16) & 0xff0000 | (msg[8] << 8) & 0xff00 | (msg[7] & 0xff);
|
||||
@ -1209,15 +1183,13 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
if (availableHeartRateData > 0) {
|
||||
getHeartRateData();
|
||||
} else if(availableSleepData > 0)
|
||||
{
|
||||
} else if (availableSleepData > 0) {
|
||||
getSleepData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSleepData(byte[] msg)
|
||||
{
|
||||
private void handleSleepData(byte[] msg) {
|
||||
ZeTimeActivitySample sample = new ZeTimeActivitySample();
|
||||
Calendar now = GregorianCalendar.getInstance();
|
||||
int timestamp = (msg[10] << 24) & 0xff000000 | (msg[9] << 16) & 0xff0000 | (msg[8] << 8) & 0xff00 | (msg[7] & 0xff);
|
||||
@ -1226,11 +1198,9 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sample.setTimestamp(timestamp);
|
||||
if (msg[11] == 0) {
|
||||
sample.setRawKind(ActivityKind.TYPE_DEEP_SLEEP);
|
||||
} else if(msg[11] == 1)
|
||||
{
|
||||
} else if (msg[11] == 1) {
|
||||
sample.setRawKind(ActivityKind.TYPE_LIGHT_SLEEP);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
sample.setRawKind(ActivityKind.TYPE_UNKNOWN);
|
||||
}
|
||||
|
||||
@ -1261,8 +1231,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleHeartRateData(byte[] msg)
|
||||
{
|
||||
private void handleHeartRateData(byte[] msg) {
|
||||
ZeTimeActivitySample sample = new ZeTimeActivitySample();
|
||||
Calendar now = GregorianCalendar.getInstance();
|
||||
int timestamp = (msg[10] << 24) & 0xff000000 | (msg[9] << 16) & 0xff0000 | (msg[8] << 8) & 0xff00 | (msg[7] & 0xff);
|
||||
@ -1318,23 +1287,19 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
if (!prefs.getBoolean(ZeTimeConstants.PREF_ZETIME_DONT_DEL_ACTDATA, false)) {
|
||||
deleteHeartRateData();
|
||||
}
|
||||
if(availableSleepData > 0)
|
||||
{
|
||||
if (availableSleepData > 0) {
|
||||
getSleepData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMsgToWatch(TransactionBuilder builder, byte[] msg)
|
||||
{
|
||||
if(msg.length > maxMsgLength)
|
||||
{
|
||||
private void sendMsgToWatch(TransactionBuilder builder, byte[] msg) {
|
||||
if (msg.length > maxMsgLength) {
|
||||
int msgpartlength = 0;
|
||||
byte[] msgpart = null;
|
||||
|
||||
do {
|
||||
if((msg.length - msgpartlength) < maxMsgLength)
|
||||
{
|
||||
if ((msg.length - msgpartlength) < maxMsgLength) {
|
||||
msgpart = new byte[msg.length - msgpartlength];
|
||||
System.arraycopy(msg, msgpartlength, msgpart, 0, msg.length - msgpartlength);
|
||||
msgpartlength += (msg.length - msgpartlength);
|
||||
@ -1345,15 +1310,13 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
builder.write(writeCharacteristic, msgpart);
|
||||
} while (msgpartlength < msg.length);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
builder.write(writeCharacteristic, msg);
|
||||
}
|
||||
builder.write(ackCharacteristic, new byte[]{ZeTimeConstants.CMD_ACK_WRITE});
|
||||
}
|
||||
|
||||
private void handleMusicControl(byte[] musicControlMsg)
|
||||
{
|
||||
private void handleMusicControl(byte[] musicControlMsg) {
|
||||
if (musicControlMsg[2] == ZeTimeConstants.CMD_SEND) {
|
||||
switch (musicControlMsg[5]) {
|
||||
case 0: // play current song
|
||||
@ -1411,16 +1374,13 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void replyMsgToWatch(TransactionBuilder builder, byte[] msg)
|
||||
{
|
||||
if(msg.length > maxMsgLength)
|
||||
{
|
||||
private void replyMsgToWatch(TransactionBuilder builder, byte[] msg) {
|
||||
if (msg.length > maxMsgLength) {
|
||||
int msgpartlength = 0;
|
||||
byte[] msgpart = null;
|
||||
|
||||
do {
|
||||
if((msg.length - msgpartlength) < maxMsgLength)
|
||||
{
|
||||
if ((msg.length - msgpartlength) < maxMsgLength) {
|
||||
msgpart = new byte[msg.length - msgpartlength];
|
||||
System.arraycopy(msg, msgpartlength, msgpart, 0, msg.length - msgpartlength);
|
||||
msgpartlength += (msg.length - msgpartlength);
|
||||
@ -1431,14 +1391,12 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
builder.write(replyCharacteristic, msgpart);
|
||||
} while (msgpartlength < msg.length);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
builder.write(replyCharacteristic, msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void synchronizeTime(TransactionBuilder builder)
|
||||
{
|
||||
private void synchronizeTime(TransactionBuilder builder) {
|
||||
Calendar now = GregorianCalendar.getInstance();
|
||||
byte[] timeSync = new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||
ZeTimeConstants.CMD_DATE_TIME,
|
||||
@ -1462,8 +1420,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
// function serving the settings
|
||||
private void setWrist(TransactionBuilder builder)
|
||||
{
|
||||
private void setWrist(TransactionBuilder builder) {
|
||||
String value = GBApplication.getPrefs().getString(ZeTimeConstants.PREF_WRIST, "left");
|
||||
|
||||
byte[] wrist = {ZeTimeConstants.CMD_PREAMBLE,
|
||||
@ -1481,15 +1438,12 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, wrist);
|
||||
}
|
||||
|
||||
private void setScreenTime(TransactionBuilder builder)
|
||||
{
|
||||
private void setScreenTime(TransactionBuilder builder) {
|
||||
int value = GBApplication.getPrefs().getInt(ZeTimeConstants.PREF_SCREENTIME, 30);
|
||||
if(value > ZeTimeConstants.MAX_SCREEN_ON_TIME)
|
||||
{
|
||||
if (value > ZeTimeConstants.MAX_SCREEN_ON_TIME) {
|
||||
GB.toast(getContext(), "Value for screen on time is greater than 18h! ", Toast.LENGTH_LONG, GB.ERROR);
|
||||
value = ZeTimeConstants.MAX_SCREEN_ON_TIME;
|
||||
} else if(value < ZeTimeConstants.MIN_SCREEN_ON_TIME)
|
||||
{
|
||||
} else if (value < ZeTimeConstants.MIN_SCREEN_ON_TIME) {
|
||||
GB.toast(getContext(), "Value for screen on time is lesser than 10s! ", Toast.LENGTH_LONG, GB.ERROR);
|
||||
value = ZeTimeConstants.MIN_SCREEN_ON_TIME;
|
||||
}
|
||||
@ -1506,8 +1460,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, screentime);
|
||||
}
|
||||
|
||||
private void setUserInfo(TransactionBuilder builder)
|
||||
{
|
||||
private void setUserInfo(TransactionBuilder builder) {
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
byte gender = (byte) activityUser.getGender();
|
||||
int age = activityUser.getAge();
|
||||
@ -1517,11 +1470,9 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
if (gender == ActivityUser.GENDER_MALE) // translate gender for zetime
|
||||
{
|
||||
gender = 0;
|
||||
} else if(gender == ActivityUser.GENDER_FEMALE)
|
||||
{
|
||||
} else if (gender == ActivityUser.GENDER_FEMALE) {
|
||||
gender = 1;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
gender = 2;
|
||||
}
|
||||
|
||||
@ -1539,8 +1490,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, userinfo);
|
||||
}
|
||||
|
||||
private void setUserGoals(TransactionBuilder builder)
|
||||
{
|
||||
private void setUserGoals(TransactionBuilder builder) {
|
||||
ActivityUser activityUser = new ActivityUser();
|
||||
int steps = activityUser.getStepsGoal() / 100; // ZeTime expect the steps in 100 increment
|
||||
int calories = activityUser.getCaloriesBurnt();
|
||||
@ -1594,8 +1544,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, goal_activeTime);
|
||||
}
|
||||
|
||||
private void setHeartRateLimits(TransactionBuilder builder)
|
||||
{
|
||||
private void setHeartRateLimits(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
|
||||
boolean alarmEnabled = prefs.getBoolean(ZeTimeConstants.PREF_ZETIME_HEARTRATE_ALARM, false);
|
||||
@ -1614,8 +1563,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, heartrateAlarm);
|
||||
}
|
||||
|
||||
private void initMusicVolume(TransactionBuilder builder)
|
||||
{
|
||||
private void initMusicVolume(TransactionBuilder builder) {
|
||||
replyMsgToWatch(builder, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||
ZeTimeConstants.CMD_MUSIC_CONTROL,
|
||||
ZeTimeConstants.CMD_REQUEST_RESPOND,
|
||||
@ -1626,8 +1574,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
ZeTimeConstants.CMD_END});
|
||||
}
|
||||
|
||||
private void setAnalogMode(TransactionBuilder builder)
|
||||
{
|
||||
private void setAnalogMode(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
int mode = prefs.getInt(ZeTimeConstants.PREF_ANALOG_MODE, 0);
|
||||
|
||||
@ -1642,8 +1589,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, analog);
|
||||
}
|
||||
|
||||
private void setActivityTracking(TransactionBuilder builder)
|
||||
{
|
||||
private void setActivityTracking(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
boolean tracking = prefs.getBoolean(ZeTimeConstants.PREF_ACTIVITY_TRACKING, false);
|
||||
|
||||
@ -1654,15 +1600,13 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
(byte) 0x0,
|
||||
(byte) 0x9,
|
||||
ZeTimeConstants.CMD_END};
|
||||
if(tracking)
|
||||
{
|
||||
if (tracking) {
|
||||
activity[5] = (byte) 0xa;
|
||||
}
|
||||
sendMsgToWatch(builder, activity);
|
||||
}
|
||||
|
||||
private void setDisplayOnMovement(TransactionBuilder builder)
|
||||
{
|
||||
private void setDisplayOnMovement(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
boolean movement = prefs.getBoolean(ZeTimeConstants.PREF_HANDMOVE_DISPLAY, false);
|
||||
|
||||
@ -1675,15 +1619,13 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
(byte) 0xe,
|
||||
(byte) 0x0,
|
||||
ZeTimeConstants.CMD_END};
|
||||
if(movement)
|
||||
{
|
||||
if (movement) {
|
||||
handmove[7] = (byte) 0x1;
|
||||
}
|
||||
sendMsgToWatch(builder, handmove);
|
||||
}
|
||||
|
||||
private void setDoNotDisturb(TransactionBuilder builder)
|
||||
{
|
||||
private void setDoNotDisturb(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
String scheduled = prefs.getString(ZeTimeConstants.PREF_DO_NOT_DISTURB, "off");
|
||||
String dndScheduled = getContext().getString(R.string.p_scheduled);
|
||||
@ -1711,8 +1653,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
(byte) calendar_end.get(Calendar.MINUTE),
|
||||
ZeTimeConstants.CMD_END};
|
||||
|
||||
if(scheduled.equals(dndScheduled))
|
||||
{
|
||||
if (scheduled.equals(dndScheduled)) {
|
||||
doNotDisturb[5] = (byte) 0x1;
|
||||
}
|
||||
sendMsgToWatch(builder, doNotDisturb);
|
||||
@ -1724,8 +1665,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void setCaloriesType(TransactionBuilder builder)
|
||||
{
|
||||
private void setCaloriesType(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
int type = prefs.getInt(ZeTimeConstants.PREF_CALORIES_TYPE, 0);
|
||||
|
||||
@ -1740,8 +1680,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, calories);
|
||||
}
|
||||
|
||||
private void setTimeFormate(TransactionBuilder builder)
|
||||
{
|
||||
private void setTimeFormate(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
int type = prefs.getInt(ZeTimeConstants.PREF_TIME_FORMAT, 0);
|
||||
|
||||
@ -1763,8 +1702,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, timeformat);
|
||||
}
|
||||
|
||||
private void setDateFormate(TransactionBuilder builder)
|
||||
{
|
||||
private void setDateFormate(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
int type = prefs.getInt(ZeTimeConstants.PREF_DATE_FORMAT, 0);
|
||||
|
||||
@ -1786,14 +1724,12 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, dateformat);
|
||||
}
|
||||
|
||||
private void setInactivityAlert(TransactionBuilder builder)
|
||||
{
|
||||
private void setInactivityAlert(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
boolean enabled = prefs.getBoolean(ZeTimeConstants.PREF_INACTIVITY_ENABLE, false);
|
||||
int threshold = prefs.getInt(ZeTimeConstants.PREF_INACTIVITY_THRESHOLD, 60);
|
||||
|
||||
if(threshold > 0xff)
|
||||
{
|
||||
if (threshold > 0xff) {
|
||||
threshold = 0xff;
|
||||
GB.toast(getContext(), "Value for inactivity threshold is greater than 255min! ", Toast.LENGTH_LONG, GB.ERROR);
|
||||
}
|
||||
@ -1815,8 +1751,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
ZeTimeConstants.CMD_END
|
||||
};
|
||||
|
||||
if(enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
String start = prefs.getString(ZeTimeConstants.PREF_INACTIVITY_START, "06:00");
|
||||
String end = prefs.getString(ZeTimeConstants.PREF_INACTIVITY_END, "22:00");
|
||||
DateFormat df_start = new SimpleDateFormat("HH:mm");
|
||||
@ -1855,8 +1790,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, inactivity);
|
||||
}
|
||||
|
||||
private void setShockStrength(TransactionBuilder builder)
|
||||
{
|
||||
private void setShockStrength(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
int shockStrength = prefs.getInt(ZeTimeConstants.PREF_SHOCK_STRENGTH, 255);
|
||||
|
||||
@ -1873,8 +1807,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sendMsgToWatch(builder, strength);
|
||||
}
|
||||
|
||||
private void setSignaling(TransactionBuilder builder, String signalingType)
|
||||
{
|
||||
private void setSignaling(TransactionBuilder builder, String signalingType) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
int signalType = prefs.getInt(signalingType, 0);
|
||||
|
||||
@ -1889,8 +1822,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
ZeTimeConstants.CMD_END
|
||||
};
|
||||
|
||||
switch(signalingType)
|
||||
{
|
||||
switch (signalingType) {
|
||||
case ZeTimeConstants.PREF_SMS_SIGNALING:
|
||||
signaling[5] = ZeTimeConstants.SMS_TYPE;
|
||||
break;
|
||||
@ -2025,8 +1957,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
// }
|
||||
}
|
||||
|
||||
private void getDateTimeFormat(byte[] msg)
|
||||
{
|
||||
private void getDateTimeFormat(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
|
||||
prefs.putString(ZeTimeConstants.PREF_DATE_FORMAT, Integer.toString(msg[5]));
|
||||
@ -2034,8 +1965,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getSignaling(byte[] msg)
|
||||
{
|
||||
private void getSignaling(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
|
||||
prefs.putString(ZeTimeConstants.PREF_ANTI_LOSS_SIGNALING, Integer.toString(msg[5]));
|
||||
@ -2050,8 +1980,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getDoNotDisturb(byte[] msg)
|
||||
{
|
||||
private void getDoNotDisturb(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
String starttime = String.format("%02d:%02d", msg[6], msg[7]);
|
||||
String endtime = String.format("%02d:%02d", msg[8], msg[9]);
|
||||
@ -2066,38 +1995,32 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getAnalogMode(byte[] msg)
|
||||
{
|
||||
private void getAnalogMode(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
|
||||
prefs.putString(ZeTimeConstants.PREF_ANALOG_MODE, Integer.toString(msg[5]));
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getActivityTracking(byte[] msg)
|
||||
{
|
||||
private void getActivityTracking(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
|
||||
if(0x1 == msg[6])
|
||||
{
|
||||
if (0x1 == msg[6]) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_ACTIVITY_TRACKING, false);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_ACTIVITY_TRACKING, true);
|
||||
}
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getScreenTime(byte[] msg)
|
||||
{
|
||||
private void getScreenTime(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
|
||||
prefs.putString(ZeTimeConstants.PREF_SCREENTIME, Integer.toString((msg[5] | (msg[6] << 8))));
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getWrist(byte[] msg)
|
||||
{
|
||||
private void getWrist(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
|
||||
if (ZeTimeConstants.WEAR_ON_LEFT_WRIST == msg[5]) {
|
||||
@ -2108,79 +2031,67 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getHeartRateMeasurement(byte[] msg)
|
||||
{
|
||||
private void getHeartRateMeasurement(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
prefs.putString(ZeTimeConstants.PREF_ZETIME_HEARTRATE_INTERVAL, Integer.toString((msg[5] * 60))); // multiply with 60 because of the conversion from minutes to seconds
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getHeartRateLimits(byte[] msg)
|
||||
{
|
||||
private void getHeartRateLimits(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getInactivityAlert(byte[] msg)
|
||||
{
|
||||
private void getInactivityAlert(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
String starttime = String.format("%02d:%02d", msg[7], msg[8]);
|
||||
String endtime = String.format("%02d:%02d", msg[9], msg[10]);
|
||||
|
||||
prefs.putString(ZeTimeConstants.PREF_INACTIVITY_THRESHOLD, Integer.toString(msg[6]));
|
||||
if(0 != msg[5])
|
||||
{
|
||||
if (0 != msg[5]) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_ENABLE, true);
|
||||
prefs.putString(ZeTimeConstants.PREF_INACTIVITY_START, starttime);
|
||||
prefs.putString(ZeTimeConstants.PREF_INACTIVITY_END, endtime);
|
||||
if (0 != (msg[5] & (1 << 0))) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_MO, true);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_MO, false);
|
||||
}
|
||||
if (0 != (msg[5] & (1 << 1))) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_TU, true);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_TU, false);
|
||||
}
|
||||
if (0 != (msg[5] & (1 << 2))) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_WE, true);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_WE, false);
|
||||
}
|
||||
if (0 != (msg[5] & (1 << 3))) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_TH, true);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_TH, false);
|
||||
}
|
||||
if (0 != (msg[5] & (1 << 4))) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_FR, true);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_FR, false);
|
||||
}
|
||||
if (0 != (msg[5] & (1 << 5))) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_SA, true);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_SA, false);
|
||||
}
|
||||
if (0 != (msg[5] & (1 << 6))) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_SU, true);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_INACTIVITY_SU, false);
|
||||
}
|
||||
}
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
private void getCaloriesType(byte[] msg)
|
||||
{
|
||||
private void getCaloriesType(byte[] msg) {
|
||||
SharedPreferences prefs = GBApplication.getPrefs().getPreferences();
|
||||
SharedPreferences.Editor myedit = prefs.edit();
|
||||
|
||||
@ -2188,8 +2099,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
myedit.apply();
|
||||
}
|
||||
|
||||
private void getDisplayOnMovement(byte[] msg)
|
||||
{
|
||||
private void getDisplayOnMovement(byte[] msg) {
|
||||
SharedPreferences.Editor prefs = GBApplication.getPrefs().getPreferences().edit();
|
||||
if (0 != (msg[6] & (1 << 6))) {
|
||||
prefs.putBoolean(ZeTimeConstants.PREF_HANDMOVE_DISPLAY, true);
|
||||
@ -2204,11 +2114,84 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void storeActualReminders(byte[] msg)
|
||||
{
|
||||
private void storeActualReminders(byte[] msg) {
|
||||
if (msg[3] == 0xb) // there is a reminder on the watch
|
||||
{
|
||||
System.arraycopy(msg, 6, remindersOnWatch[msg[5] - 1], 0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
private void setLanguage(TransactionBuilder builder) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
String language = prefs.getString("language", "default");
|
||||
Locale locale;
|
||||
|
||||
byte[] languageMsg = {
|
||||
ZeTimeConstants.CMD_PREAMBLE,
|
||||
ZeTimeConstants.CMD_LANGUAGE_SETTINGS,
|
||||
ZeTimeConstants.CMD_REQUEST,
|
||||
(byte) 0x1,
|
||||
(byte) 0x0,
|
||||
(byte) 0x0,
|
||||
ZeTimeConstants.CMD_END
|
||||
};
|
||||
|
||||
if (language.equals("default") || (language == null)) {
|
||||
locale = Locale.getDefault();
|
||||
language = locale.getLanguage();
|
||||
}
|
||||
|
||||
switch (language) {
|
||||
case "zh":
|
||||
languageMsg[5] = 1;
|
||||
break;
|
||||
case "tw":
|
||||
case "hk":
|
||||
case "mo":
|
||||
languageMsg[5] = 2;
|
||||
break;
|
||||
case "ko":
|
||||
languageMsg[5] = 3;
|
||||
break;
|
||||
case "th":
|
||||
languageMsg[5] = 4;
|
||||
break;
|
||||
case "ja":
|
||||
languageMsg[5] = 5;
|
||||
break;
|
||||
case "fr":
|
||||
languageMsg[5] = 6;
|
||||
break;
|
||||
case "es":
|
||||
languageMsg[5] = 7;
|
||||
break;
|
||||
case "de":
|
||||
languageMsg[5] = 8;
|
||||
break;
|
||||
case "it":
|
||||
languageMsg[5] = 9;
|
||||
break;
|
||||
case "pl":
|
||||
languageMsg[5] = 10;
|
||||
break;
|
||||
case "pt":
|
||||
languageMsg[5] = 11;
|
||||
break;
|
||||
case "ru":
|
||||
languageMsg[5] = 12;
|
||||
break;
|
||||
case "nl":
|
||||
languageMsg[5] = 13;
|
||||
break;
|
||||
case "ro":
|
||||
languageMsg[5] = 32;
|
||||
break;
|
||||
case "hu":
|
||||
languageMsg[5] = 33;
|
||||
break;
|
||||
case "en":
|
||||
default:
|
||||
languageMsg[5] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user