mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 01:09:47 +01:00
Amazfit Bip: Also make shortcuts sortable
This commit is contained in:
parent
d20e6516c8
commit
f178c478c9
@ -2318,7 +2318,6 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
protected HuamiSupport setDisplayItemsOld(TransactionBuilder builder, boolean isShortcuts, int defaultSettings, Map<String, Integer> keyPosMap) {
|
||||
|
||||
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
|
||||
String pages;
|
||||
List<String> enabledList;
|
||||
@ -2335,31 +2334,55 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
enabledList = Arrays.asList(pages.split(","));
|
||||
}
|
||||
LOG.info("enabled items" + enabledList);
|
||||
byte[] command;
|
||||
|
||||
byte[] command = new byte[keyPosMap.size() + 4];
|
||||
command[0] = ENDPOINT_DISPLAY_ITEMS;
|
||||
byte index = 1;
|
||||
int enabled_mask = DISPLAY_ITEM_BIT_CLOCK;
|
||||
// it seem that we first have to put all ENABLED items into the array, oder does matter
|
||||
for (String key : enabledList) {
|
||||
Integer id = keyPosMap.get(key);
|
||||
if (id != null) {
|
||||
enabled_mask |= (1 << id.byteValue());
|
||||
command[3 + id] = index++;
|
||||
if (isShortcuts) {
|
||||
command = new byte[keyPosMap.size() * 2 + 1];
|
||||
command[0] = 0x10;
|
||||
int pos = 1;
|
||||
int index = 0;
|
||||
for (String key : enabledList) {
|
||||
Integer id = keyPosMap.get(key);
|
||||
if (id != null) {
|
||||
command[pos++] = (byte) (0x80 | index++);
|
||||
command[pos++] = id.byteValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
// And then all DISABLED ones, order does not matter
|
||||
for (Map.Entry<String, Integer> entry : keyPosMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
int id = entry.getValue();
|
||||
for (Map.Entry<String, Integer> entry : keyPosMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
int id = entry.getValue();
|
||||
|
||||
if (!enabledList.contains(key)) {
|
||||
command[3 + id] = index++;
|
||||
if (!enabledList.contains(key)) {
|
||||
command[pos++] = (byte) index++;
|
||||
command[pos++] = (byte) id;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
command = new byte[keyPosMap.size() + 4];
|
||||
command[0] = ENDPOINT_DISPLAY_ITEMS;
|
||||
byte index = 1;
|
||||
int enabled_mask = DISPLAY_ITEM_BIT_CLOCK;
|
||||
// it seem that we first have to put all ENABLED items into the array, oder does matter
|
||||
for (String key : enabledList) {
|
||||
Integer id = keyPosMap.get(key);
|
||||
if (id != null) {
|
||||
enabled_mask |= (1 << id.byteValue());
|
||||
command[3 + id] = index++;
|
||||
}
|
||||
}
|
||||
// And then all DISABLED ones, order does not matter
|
||||
for (Map.Entry<String, Integer> entry : keyPosMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
int id = entry.getValue();
|
||||
|
||||
command[1] = (byte) (enabled_mask & 0xff);
|
||||
command[2] = (byte) ((enabled_mask >> 8 & 0xff));
|
||||
if (!enabledList.contains(key)) {
|
||||
command[3 + id] = index++;
|
||||
}
|
||||
}
|
||||
|
||||
command[1] = (byte) (enabled_mask & 0xff);
|
||||
command[2] = (byte) ((enabled_mask >> 8 & 0xff));
|
||||
}
|
||||
|
||||
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
|
||||
return this;
|
||||
|
@ -29,7 +29,6 @@ import java.util.Map;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbip.AmazfitBipFWHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
@ -80,21 +79,17 @@ public class AmazfitBipSupport extends HuamiSupport {
|
||||
keyPosMap.put("alipay", 8);
|
||||
|
||||
setDisplayItemsOld(builder, false, R.array.pref_bip_display_items_default, keyPosMap);
|
||||
//setShortcuts(builder, shortcut_weather, shortcut_alipay);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void setShortcuts(TransactionBuilder builder, boolean weather, boolean alipay) {
|
||||
LOG.info("Setting shortcuts: weather=" + weather + " alipay=" + alipay);
|
||||
@Override
|
||||
protected AmazfitBipSupport setShortcuts(TransactionBuilder builder) {
|
||||
Map<String, Integer> keyPosMap = new LinkedHashMap<>();
|
||||
keyPosMap.put("alipay", 1);
|
||||
keyPosMap.put("weather", 2);
|
||||
|
||||
// Basically a hack to put weather first always, if alipay is the only enabled one
|
||||
// there are actually two alipays set but the second one disabled.... :P
|
||||
byte[] command = new byte[]{0x10,
|
||||
(byte) ((alipay || weather) ? 0x80 : 0x00), (byte) (weather ? 0x02 : 0x01),
|
||||
(byte) ((alipay && weather) ? 0x81 : 0x01), 0x01,
|
||||
};
|
||||
|
||||
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
|
||||
setDisplayItemsOld(builder, true, R.array.pref_bip_shortcuts_default, keyPosMap);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,15 @@
|
||||
android:persistent="true"
|
||||
android:summary="@string/mi2_prefs_display_items_summary"
|
||||
android:title="@string/mi2_prefs_display_items" />
|
||||
<com.mobeta.android.dslv.DragSortListPreference
|
||||
android:defaultValue="@array/pref_bip_shortcuts_default"
|
||||
android:dialogTitle="@string/bip_prefs_shortcuts"
|
||||
android:entries="@array/pref_bip_shortcuts"
|
||||
android:entryValues="@array/pref_bip_shortcuts_values"
|
||||
android:key="shortcuts_sortable"
|
||||
android:persistent="true"
|
||||
android:summary="@string/bip_prefs_shotcuts_summary"
|
||||
android:title="@string/bip_prefs_shortcuts" />
|
||||
<ListPreference
|
||||
android:icon="@drawable/ic_language"
|
||||
android:defaultValue="auto"
|
||||
|
Loading…
Reference in New Issue
Block a user