1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 10:35:50 +01:00

Ímplement sorting menu items for newer Huami devices

- Amazfit GTR/GTS
- Amazfit Bip S
- Mi Band 5/Amazfit Band 5
This commit is contained in:
Andreas Shimokawa 2020-11-06 21:47:54 +01:00
parent e1f2e0c830
commit 8cb2fb980a
6 changed files with 59 additions and 49 deletions

View File

@ -92,10 +92,12 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_END; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_END;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_START; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_START;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_END; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_END;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_EXPOSE_HR_THIRDPARTY; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_EXPOSE_HR_THIRDPARTY;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_SHORTCUTS; import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_SHORTCUTS;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_SHORTCUTS_SORTABLE;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_OFF; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_OFF;
@ -352,7 +354,9 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
addPreferenceHandlerFor(PREF_MI2_DATEFORMAT); addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
addPreferenceHandlerFor(PREF_DATEFORMAT); addPreferenceHandlerFor(PREF_DATEFORMAT);
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS); addPreferenceHandlerFor(PREF_DISPLAY_ITEMS);
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS_SORTABLE);
addPreferenceHandlerFor(PREF_SHORTCUTS); addPreferenceHandlerFor(PREF_SHORTCUTS);
addPreferenceHandlerFor(PREF_SHORTCUTS_SORTABLE);
addPreferenceHandlerFor(PREF_LANGUAGE); addPreferenceHandlerFor(PREF_LANGUAGE);
addPreferenceHandlerFor(PREF_EXPOSE_HR_THIRDPARTY); addPreferenceHandlerFor(PREF_EXPOSE_HR_THIRDPARTY);
addPreferenceHandlerFor(PREF_WEARLOCATION); addPreferenceHandlerFor(PREF_WEARLOCATION);

View File

@ -61,7 +61,9 @@ public class HuamiConst {
public static final String PREF_DISCONNECT_NOTIFICATION_END = "disconnect_notification_end"; public static final String PREF_DISCONNECT_NOTIFICATION_END = "disconnect_notification_end";
public static final String PREF_DISPLAY_ITEMS = "display_items"; public static final String PREF_DISPLAY_ITEMS = "display_items";
public static final String PREF_DISPLAY_ITEMS_SORTABLE = "display_items_sortable";
public static final String PREF_SHORTCUTS = "shortcuts"; public static final String PREF_SHORTCUTS = "shortcuts";
public static final String PREF_SHORTCUTS_SORTABLE = "shortcuts_sortable";
public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty"; public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty";
public static final String PREF_USE_CUSTOM_FONT = "use_custom_font"; public static final String PREF_USE_CUSTOM_FONT = "use_custom_font";

View File

@ -1884,9 +1884,11 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
setDisconnectNotification(builder); setDisconnectNotification(builder);
break; break;
case HuamiConst.PREF_DISPLAY_ITEMS: case HuamiConst.PREF_DISPLAY_ITEMS:
case HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE:
setDisplayItems(builder); setDisplayItems(builder);
break; break;
case HuamiConst.PREF_SHORTCUTS: case HuamiConst.PREF_SHORTCUTS:
case HuamiConst.PREF_SHORTCUTS_SORTABLE:
setShortcuts(builder); setShortcuts(builder);
break; break;
case MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO: case MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO:
@ -2314,47 +2316,46 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
} }
protected HuamiSupport setDisplayItemsNew(TransactionBuilder builder, boolean isShortcuts, int defaultSettings, Map<String, Integer> keyIdMap) { protected HuamiSupport setDisplayItemsNew(TransactionBuilder builder, boolean isShortcuts, int defaultSettings, Map<String, Integer> keyIdMap) {
if (gbDevice.getFirmwareVersion() == null) {
LOG.warn("Device not initialized yet, won't set menu items");
return this;
}
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()); SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
Set<String> pages; String pages;
List<String> enabledList;
byte menuType; byte menuType;
if (isShortcuts) { if (isShortcuts) {
menuType = (byte) 0xfd; menuType = (byte) 0xfd;
pages = prefs.getStringSet(HuamiConst.PREF_SHORTCUTS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_bips_shortcuts_default)))); pages = prefs.getString(HuamiConst.PREF_SHORTCUTS_SORTABLE, null);
LOG.info("Setting shortcuts to " + (pages == null ? "none" : pages)); LOG.info("Setting shortcuts");
} else { } else {
menuType = (byte) 0xff; menuType = (byte) 0xff;
pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(defaultSettings)))); pages = prefs.getString(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE, null);
LOG.info("Setting display items to " + (pages == null ? "none" : pages)); LOG.info("Setting menu items");
} }
if (pages == null) {
enabledList = Arrays.asList(getContext().getResources().getStringArray(defaultSettings));
} else {
enabledList = Arrays.asList(pages.split(","));
}
LOG.info("enabled items" + enabledList);
if (pages != null) {
byte[] command = new byte[keyIdMap.size() * 4 + 1]; byte[] command = new byte[keyIdMap.size() * 4 + 1];
command[0] = 0x1e; command[0] = 0x1e;
// it seem that we first have to put all ENABLED items into the array // it seem that we first have to put all ENABLED items into the array, oder does matter
int pos = 1; int pos = 1;
int index = 0; int index = 0;
for (Map.Entry<String, Integer> entry : keyIdMap.entrySet()) { for (String key : enabledList) {
String key = entry.getKey(); Integer id = keyIdMap.get(key);
int id = entry.getValue(); if (id != null) {
if (pages.contains(key)) {
command[pos++] = (byte) index++; command[pos++] = (byte) index++;
command[pos++] = 0x00; command[pos++] = 0x00;
command[pos++] = menuType; command[pos++] = menuType;
command[pos++] = (byte) id; command[pos++] = id.byteValue();
} }
} }
// And then all DISABLED ones // And then all DISABLED ones, order does not matter
for (Map.Entry<String, Integer> entry : keyIdMap.entrySet()) { for (Map.Entry<String, Integer> entry : keyIdMap.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
int id = entry.getValue(); int id = entry.getValue();
if (!pages.contains(key)) { if (!enabledList.contains(key)) {
command[pos++] = (byte) index++; command[pos++] = (byte) index++;
command[pos++] = 0x01; command[pos++] = 0x01;
command[pos++] = (byte) menuType; command[pos++] = (byte) menuType;
@ -2362,7 +2363,6 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
} }
} }
writeToChunked(builder, 2, command); writeToChunked(builder, 2, command);
}
return this; return this;
} }

View File

@ -1,20 +1,22 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<MultiSelectListPreference <com.mobeta.android.dslv.DragSortListPreference
android:icon="@drawable/ic_widgets" android:icon="@drawable/ic_widgets"
android:defaultValue="@array/pref_bips_display_items_default" android:defaultValue="@array/pref_bips_display_items_default"
android:dialogTitle="@string/mi2_prefs_display_items" android:dialogTitle="@string/mi2_prefs_display_items"
android:entries="@array/pref_bips_display_items" android:entries="@array/pref_bips_display_items"
android:entryValues="@array/pref_bips_display_items_values" android:entryValues="@array/pref_bips_display_items_values"
android:key="display_items" android:key="display_items_sortable"
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" />
<MultiSelectListPreference <com.mobeta.android.dslv.DragSortListPreference
android:defaultValue="@array/pref_bips_shortcuts_default" android:defaultValue="@array/pref_bips_shortcuts_default"
android:dialogTitle="@string/bip_prefs_shortcuts" android:dialogTitle="@string/bip_prefs_shortcuts"
android:entries="@array/pref_bips_shortcuts" android:entries="@array/pref_bips_shortcuts"
android:entryValues="@array/pref_bips_shortcuts_values" android:entryValues="@array/pref_bips_shortcuts_values"
android:key="shortcuts" android:key="shortcuts_sortable"
android:persistent="true"
android:summary="@string/bip_prefs_shotcuts_summary" android:summary="@string/bip_prefs_shotcuts_summary"
android:title="@string/bip_prefs_shortcuts" /> android:title="@string/bip_prefs_shortcuts" />
<ListPreference <ListPreference

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<MultiSelectListPreference <com.mobeta.android.dslv.DragSortListPreference
android:icon="@drawable/ic_widgets" android:icon="@drawable/ic_widgets"
android:defaultValue="@array/pref_gts_display_items_default" android:defaultValue="@array/pref_gts_display_items_default"
android:dialogTitle="@string/mi2_prefs_display_items" android:dialogTitle="@string/mi2_prefs_display_items"
android:entries="@array/pref_gts_display_items" android:entries="@array/pref_gts_display_items"
android:entryValues="@array/pref_gts_display_items_values" android:entryValues="@array/pref_gts_display_items_values"
android:key="display_items" android:key="display_items_sortable"
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" />
<ListPreference <ListPreference

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<MultiSelectListPreference <com.mobeta.android.dslv.DragSortListPreference
android:icon="@drawable/ic_widgets" android:icon="@drawable/ic_widgets"
android:defaultValue="@array/pref_miband5_display_items_default" android:defaultValue="@array/pref_miband5_display_items_default"
android:dialogTitle="@string/mi2_prefs_display_items" android:dialogTitle="@string/mi2_prefs_display_items"
android:entries="@array/pref_miband5_display_items" android:entries="@array/pref_miband5_display_items"
android:entryValues="@array/pref_miband5_display_items_values" android:entryValues="@array/pref_miband5_display_items_values"
android:key="display_items" android:key="display_items_sortable"
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" />
<ListPreference <ListPreference