1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-02-09 08:26:48 +01:00

Amazfit Bip: Also make shortcuts sortable

This commit is contained in:
Andreas Shimokawa 2020-11-07 21:03:04 +01:00
parent d20e6516c8
commit f178c478c9
3 changed files with 60 additions and 33 deletions

View File

@ -2318,7 +2318,6 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
} }
protected HuamiSupport setDisplayItemsOld(TransactionBuilder builder, boolean isShortcuts, int defaultSettings, Map<String, Integer> keyPosMap) { protected HuamiSupport setDisplayItemsOld(TransactionBuilder builder, boolean isShortcuts, int defaultSettings, Map<String, Integer> keyPosMap) {
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()); SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
String pages; String pages;
List<String> enabledList; List<String> enabledList;
@ -2335,31 +2334,55 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
enabledList = Arrays.asList(pages.split(",")); enabledList = Arrays.asList(pages.split(","));
} }
LOG.info("enabled items" + enabledList); LOG.info("enabled items" + enabledList);
byte[] command;
byte[] command = new byte[keyPosMap.size() + 4]; if (isShortcuts) {
command[0] = ENDPOINT_DISPLAY_ITEMS; command = new byte[keyPosMap.size() * 2 + 1];
byte index = 1; command[0] = 0x10;
int enabled_mask = DISPLAY_ITEM_BIT_CLOCK; int pos = 1;
// it seem that we first have to put all ENABLED items into the array, oder does matter int index = 0;
for (String key : enabledList) { for (String key : enabledList) {
Integer id = keyPosMap.get(key); Integer id = keyPosMap.get(key);
if (id != null) { if (id != null) {
enabled_mask |= (1 << id.byteValue()); command[pos++] = (byte) (0x80 | index++);
command[3 + id] = index++; command[pos++] = id.byteValue();
}
} }
} for (Map.Entry<String, Integer> entry : keyPosMap.entrySet()) {
// And then all DISABLED ones, order does not matter String key = entry.getKey();
for (Map.Entry<String, Integer> entry : keyPosMap.entrySet()) { int id = entry.getValue();
String key = entry.getKey();
int id = entry.getValue();
if (!enabledList.contains(key)) { if (!enabledList.contains(key)) {
command[3 + id] = index++; 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); if (!enabledList.contains(key)) {
command[2] = (byte) ((enabled_mask >> 8 & 0xff)); 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); builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
return this; return this;

View File

@ -29,7 +29,6 @@ import java.util.Map;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; 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.devices.huami.amazfitbip.AmazfitBipFWHelper;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
@ -80,21 +79,17 @@ public class AmazfitBipSupport extends HuamiSupport {
keyPosMap.put("alipay", 8); keyPosMap.put("alipay", 8);
setDisplayItemsOld(builder, false, R.array.pref_bip_display_items_default, keyPosMap); setDisplayItemsOld(builder, false, R.array.pref_bip_display_items_default, keyPosMap);
//setShortcuts(builder, shortcut_weather, shortcut_alipay);
return this; return this;
} }
private void setShortcuts(TransactionBuilder builder, boolean weather, boolean alipay) { @Override
LOG.info("Setting shortcuts: weather=" + weather + " alipay=" + alipay); 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 setDisplayItemsOld(builder, true, R.array.pref_bip_shortcuts_default, keyPosMap);
// there are actually two alipays set but the second one disabled.... :P return this;
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);
} }
@Override @Override

View File

@ -10,6 +10,15 @@
android:persistent="true" android:persistent="true"
android:summary="@string/mi2_prefs_display_items_summary" android:summary="@string/mi2_prefs_display_items_summary"
android:title="@string/mi2_prefs_display_items" /> 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 <ListPreference
android:icon="@drawable/ic_language" android:icon="@drawable/ic_language"
android:defaultValue="auto" android:defaultValue="auto"