Merge branch 'master' into feature-weather
This commit is contained in:
commit
c962dbbac2
|
@ -47,7 +47,7 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
|
||||||
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
|
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
|
||||||
ProgressBar busyIndicator = (ProgressBar) view.findViewById(R.id.device_busy_indicator);
|
ProgressBar busyIndicator = (ProgressBar) view.findViewById(R.id.device_busy_indicator);
|
||||||
|
|
||||||
deviceNameLabel.setText(device.getName());
|
deviceNameLabel.setText(getUniqueDeviceName(device));
|
||||||
deviceInfoLabel.setText(device.getInfoString());
|
deviceInfoLabel.setText(device.getInfoString());
|
||||||
|
|
||||||
if (device.isBusy()) {
|
if (device.isBusy()) {
|
||||||
|
@ -93,4 +93,25 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getUniqueDeviceName(GBDevice device) {
|
||||||
|
String deviceName = device.getName();
|
||||||
|
if (!isUniqueDeviceName(device, deviceName)) {
|
||||||
|
deviceName = deviceName + " " + device.getShortAddress();
|
||||||
|
}
|
||||||
|
return deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isUniqueDeviceName(GBDevice device, String deviceName) {
|
||||||
|
for (int i = 0; i < getCount(); i++) {
|
||||||
|
GBDevice item = getItem(i);
|
||||||
|
if (item == device) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (deviceName.equals(item.getName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -309,6 +310,22 @@ public class GBDevice implements Parcelable {
|
||||||
return "Device " + getName() + ", " + getAddress() + ", " + getStateString();
|
return "Device " + getName() + ", " + getAddress() + ", " + getStateString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a shortened form of the device's address, in order to form a
|
||||||
|
* unique name in companion with #getName().
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public String getShortAddress() {
|
||||||
|
String address = getAddress();
|
||||||
|
if (address != null) {
|
||||||
|
if (address.length() > 5) {
|
||||||
|
return address.substring(address.length() - 5);
|
||||||
|
}
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
// Note: the order is important!
|
// Note: the order is important!
|
||||||
NOT_CONNECTED,
|
NOT_CONNECTED,
|
||||||
|
|
|
@ -408,6 +408,8 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOG.error("Unable to set time on MI device", ex);
|
LOG.error("Unable to set time on MI device", ex);
|
||||||
}
|
}
|
||||||
|
//TODO: once we have a common strategy for sending events (e.g. EventHandler), remove this call from here. Meanwhile it does no harm.
|
||||||
|
sendCalendarEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -796,7 +798,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
LOG.info("MI Band pairing result: " + value);
|
LOG.info("MI Band pairing result: " + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendEvents() {
|
/**
|
||||||
|
* Fetch the events from the android device calendars and set the alarms on the miband.
|
||||||
|
*/
|
||||||
|
private void sendCalendarEvents() {
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized("Send upcoming events");
|
TransactionBuilder builder = performInitialized("Send upcoming events");
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
||||||
|
@ -811,16 +816,17 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
int iteration = 0;
|
int iteration = 0;
|
||||||
ArrayList<GBAlarm> alarmList = new ArrayList<>();
|
ArrayList<GBAlarm> alarmList = new ArrayList<>();
|
||||||
for(CalendarEvents.CalendarEvent mEvt : mEvents) {
|
for(CalendarEvents.CalendarEvent mEvt : mEvents) {
|
||||||
if (iteration >= availableSlots) {
|
if (iteration >= availableSlots || iteration > 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
int slotToUse = 2 - iteration;
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTimeInMillis(mEvt.getBegin());
|
calendar.setTimeInMillis(mEvt.getBegin());
|
||||||
byte[] calBytes = MiBandDateConverter.calendarToRawBytes(calendar);
|
byte[] calBytes = MiBandDateConverter.calendarToRawBytes(calendar);
|
||||||
|
|
||||||
byte[] alarmMessage = new byte[]{
|
byte[] alarmMessage = new byte[]{
|
||||||
MiBandService.COMMAND_SET_TIMER,
|
MiBandService.COMMAND_SET_TIMER,
|
||||||
(byte)(2-iteration),
|
(byte) slotToUse,
|
||||||
(byte) 1,
|
(byte) 1,
|
||||||
calBytes[0],
|
calBytes[0],
|
||||||
calBytes[1],
|
calBytes[1],
|
||||||
|
|
|
@ -54,21 +54,32 @@ public class AppMessageHandlerPebStyle extends AppMessageHandler {
|
||||||
private byte[] encodePebStyleConfig() {
|
private byte[] encodePebStyleConfig() {
|
||||||
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
|
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
|
||||||
//settings that give good legibility on pebble time
|
//settings that give good legibility on pebble time
|
||||||
pairs.add(new Pair<>(KEY_MAIN_CLOCK, (Object) 1)); //0 analog
|
|
||||||
pairs.add(new Pair<>(KEY_SECOND_HAND, (Object) 0)); //1 enabled
|
pairs.add(new Pair<>(KEY_SECOND_HAND, (Object) 0)); //1 enabled
|
||||||
pairs.add(new Pair<>(KEY_BLUETOOTH_ALERT, (Object) 0)); //1 silent, 2 weak, up to 5
|
pairs.add(new Pair<>(KEY_BLUETOOTH_ALERT, (Object) 0)); //1 silent, 2 weak, up to 5
|
||||||
pairs.add(new Pair<>(KEY_TEMPERATURE_FORMAT, (Object) 1)); //0 fahrenheit
|
pairs.add(new Pair<>(KEY_TEMPERATURE_FORMAT, (Object) 1)); //0 fahrenheit
|
||||||
pairs.add(new Pair<>(KEY_LOCATION_SERVICE, (Object) 2)); //0 uto, 1 manual
|
pairs.add(new Pair<>(KEY_LOCATION_SERVICE, (Object) 2)); //0 uto, 1 manual
|
||||||
pairs.add(new Pair<>(KEY_SECONDARY_INFO_TYPE, (Object) 3)); //1 time, 2 location
|
|
||||||
pairs.add(new Pair<>(KEY_SIDEBAR_LOCATION, (Object) 1)); //0 right
|
pairs.add(new Pair<>(KEY_SIDEBAR_LOCATION, (Object) 1)); //0 right
|
||||||
pairs.add(new Pair<>(KEY_COLOR_SELECTION, (Object) 1)); //1 custom
|
pairs.add(new Pair<>(KEY_COLOR_SELECTION, (Object) 1)); //1 custom
|
||||||
pairs.add(new Pair<>(KEY_MAIN_COLOR, (Object) PebbleColor.Black));
|
pairs.add(new Pair<>(KEY_MAIN_COLOR, (Object) PebbleColor.Black));
|
||||||
pairs.add(new Pair<>(KEY_MAIN_BG_COLOR, (Object) PebbleColor.White));
|
pairs.add(new Pair<>(KEY_MAIN_BG_COLOR, (Object) PebbleColor.White));
|
||||||
pairs.add(new Pair<>(KEY_WEATHER_TEMP, (Object) 10)); //2 = Deutsch
|
pairs.add(new Pair<>(KEY_SIDEBAR_BG_COLOR, (Object) PebbleColor.MediumSpringGreen));
|
||||||
|
|
||||||
|
//DIGITAL settings
|
||||||
/*
|
/*
|
||||||
pairs.add(new Pair<>(KEY_SETTING_COLOR_SIDEBAR, (Object) Color.parseColor("#00aaff")));
|
pairs.add(new Pair<>(KEY_MAIN_CLOCK, (Object) 1)); //0 analog
|
||||||
|
pairs.add(new Pair<>(KEY_SECONDARY_INFO_TYPE, (Object) 3)); //1 time, 2 location
|
||||||
|
*/
|
||||||
|
//ANALOG + DIGITAL settings
|
||||||
|
pairs.add(new Pair<>(KEY_MAIN_CLOCK, (Object) 0)); //0 analog, 1 digital
|
||||||
|
pairs.add(new Pair<>(KEY_SECONDARY_INFO_TYPE, (Object) 1)); //1 time, 2 location
|
||||||
|
|
||||||
|
|
||||||
|
//WEATHER
|
||||||
|
/*
|
||||||
|
//comment the same key in the general section above!
|
||||||
|
pairs.add(new Pair<>(KEY_LOCATION_SERVICE, (Object) 0)); //0 auto, 1 manual
|
||||||
|
pairs.add(new Pair<>(KEY_WEATHER_CODE, (Object) 3));
|
||||||
|
pairs.add(new Pair<>(KEY_WEATHER_TEMP, (Object) 10));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
byte[] testMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
|
byte[] testMessage = mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs);
|
||||||
|
|
Loading…
Reference in New Issue