mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 09:17:29 +01:00
Huami: Unify menu id lookup tables and simplify code
This commit is contained in:
parent
5b55898059
commit
9d6f9f7d57
@ -0,0 +1,53 @@
|
||||
/* Copyright (C) 2020 Andreas Shimokawa
|
||||
|
||||
This file is part of Gadgetbridge.
|
||||
|
||||
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Gadgetbridge is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class HuamiMenuType {
|
||||
public static final Map<String, Integer> idLookup = new HashMap<String, Integer>() {{
|
||||
put("status", 0x01);
|
||||
put("hr", 0x02);
|
||||
put("workout", 0x03);
|
||||
put("weather", 0x04);
|
||||
put("notifications", 0x06);
|
||||
put("more", 0x07);
|
||||
put("dnd", 0x08);
|
||||
put("alarm", 0x09);
|
||||
put("takephoto", 0x0a);
|
||||
put("music", 0x0b);
|
||||
put("stopwatch", 0x0c);
|
||||
put("timer", 0x0d);
|
||||
put("findphone", 0x0e);
|
||||
put("mutephone", 0x0f);
|
||||
put("nfc", 0x10);
|
||||
put("alipay", 0x11);
|
||||
put("settings", 0x13);
|
||||
put("activity", 0x14);
|
||||
put("eventreminder", 0x15);
|
||||
put("compass", 0x16);
|
||||
put("pai", 0x19);
|
||||
put("worldclock", 0x1a);
|
||||
put("timer_stopwatch", 0x1b);
|
||||
put("stress", 0x1c);
|
||||
put("period", 0x1d);
|
||||
put("spo2", 0x24);
|
||||
put("breathing",0x33);
|
||||
put("alexa", 0x39);
|
||||
}};
|
||||
}
|
@ -2388,7 +2388,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected HuamiSupport setDisplayItemsNew(TransactionBuilder builder, boolean isShortcuts, int defaultSettings, Map<String, Integer> keyIdMap) {
|
||||
protected HuamiSupport setDisplayItemsNew(TransactionBuilder builder, boolean isShortcuts, int defaultSettings) {
|
||||
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
|
||||
String pages;
|
||||
List<String> enabledList;
|
||||
@ -2409,9 +2409,8 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
LOG.info("enabled items" + enabledList);
|
||||
|
||||
byte[] command = new byte[(keyIdMap.size() + 1) * 4 + 1];
|
||||
byte[] command = new byte[(enabledList.size() + 1) * 4 + 1];
|
||||
command[0] = 0x1e;
|
||||
// it seem that we first have to put all ENABLED items into the array, oder does matter
|
||||
|
||||
int pos = 1;
|
||||
int index = 0;
|
||||
@ -2422,7 +2421,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
command[pos++] = 0x12;
|
||||
|
||||
for (String key : enabledList) {
|
||||
Integer id = keyIdMap.get(key);
|
||||
Integer id = HuamiMenuType.idLookup.get(key);
|
||||
if (id != null) {
|
||||
command[pos++] = (byte) index++;
|
||||
command[pos++] = 0x00;
|
||||
@ -2430,18 +2429,6 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
command[pos++] = id.byteValue();
|
||||
}
|
||||
}
|
||||
// And then all DISABLED ones, order does not matter
|
||||
for (Map.Entry<String, Integer> entry : keyIdMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
int id = entry.getValue();
|
||||
|
||||
if (!enabledList.contains(key)) {
|
||||
command[pos++] = (byte) index++;
|
||||
command[pos++] = 0x01;
|
||||
command[pos++] = menuType;
|
||||
command[pos++] = (byte) id;
|
||||
}
|
||||
}
|
||||
writeToChunked(builder, 2, command);
|
||||
|
||||
return this;
|
||||
|
@ -23,8 +23,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||
@ -37,49 +35,13 @@ public class AmazfitBand5Support extends MiBand5Support {
|
||||
|
||||
@Override
|
||||
protected AmazfitBand5Support setDisplayItems(TransactionBuilder builder) {
|
||||
Map<String, Integer> keyIdMap = new LinkedHashMap<>();
|
||||
keyIdMap.put("status", 0x01);
|
||||
keyIdMap.put("pai", 0x19);
|
||||
keyIdMap.put("hr", 0x02);
|
||||
keyIdMap.put("spo2", 0x24);
|
||||
keyIdMap.put("notifications", 0x06);
|
||||
keyIdMap.put("breathing", 0x33);
|
||||
keyIdMap.put("eventreminder", 0x15);
|
||||
keyIdMap.put("weather", 0x04);
|
||||
keyIdMap.put("workout", 0x03);
|
||||
keyIdMap.put("more", 0x07);
|
||||
keyIdMap.put("stress", 0x1c);
|
||||
keyIdMap.put("period", 0x1d);
|
||||
|
||||
setDisplayItemsNew(builder, false, R.array.pref_amazfitband5_display_items_default, keyIdMap);
|
||||
setDisplayItemsNew(builder, false, R.array.pref_amazfitband5_display_items_default);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AmazfitBand5Support setShortcuts(TransactionBuilder builder) {
|
||||
Map<String, Integer> keyIdMap = new LinkedHashMap<>();
|
||||
keyIdMap.put("notifications", 0x06);
|
||||
keyIdMap.put("weather", 0x04);
|
||||
keyIdMap.put("music", 0x0b);
|
||||
keyIdMap.put("timer", 0x0d);
|
||||
keyIdMap.put("alarm", 0x09);
|
||||
keyIdMap.put("findphone", 0x0e);
|
||||
keyIdMap.put("worldclock", 0x1a);
|
||||
keyIdMap.put("status", 0x01);
|
||||
keyIdMap.put("pai", 0x19);
|
||||
keyIdMap.put("hr", 0x02);
|
||||
keyIdMap.put("spo2", 0x24);
|
||||
keyIdMap.put("stress", 0x1c);
|
||||
keyIdMap.put("eventreminder", 0x15);
|
||||
keyIdMap.put("dnd", 0x08);
|
||||
keyIdMap.put("stopwatch", 0x0c);
|
||||
keyIdMap.put("workout", 0x03);
|
||||
keyIdMap.put("mutephone", 0x0f);
|
||||
keyIdMap.put("period", 0x1d);
|
||||
keyIdMap.put("takephoto", 0x0a);
|
||||
keyIdMap.put("alexa", 0x39);
|
||||
setDisplayItemsNew(builder, true, R.array.pref_amazfitband5_shortcuts_default, keyIdMap);
|
||||
|
||||
setDisplayItemsNew(builder, true, R.array.pref_amazfitband5_shortcuts_default);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbips;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -26,15 +25,8 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbips.AmazfitBipSFWHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
@ -117,37 +109,13 @@ public class AmazfitBipSSupport extends AmazfitBipSupport {
|
||||
|
||||
@Override
|
||||
protected AmazfitBipSSupport setDisplayItems(TransactionBuilder builder) {
|
||||
Map<String, Integer> keyIdMap = new LinkedHashMap<>();
|
||||
keyIdMap.put("status", 0x01);
|
||||
keyIdMap.put("hr", 0x02);
|
||||
keyIdMap.put("pai", 0x19);
|
||||
keyIdMap.put("workout", 0x03);
|
||||
keyIdMap.put("alipay", 0x11);
|
||||
keyIdMap.put("nfc", 0x10);
|
||||
keyIdMap.put("weather", 0x04);
|
||||
keyIdMap.put("alarm", 0x09);
|
||||
keyIdMap.put("timer", 0x1b);
|
||||
keyIdMap.put("compass", 0x16);
|
||||
keyIdMap.put("worldclock", 0x1a);
|
||||
keyIdMap.put("music", 0x0b);
|
||||
keyIdMap.put("settings", 0x13);
|
||||
|
||||
setDisplayItemsNew(builder, false, R.array.pref_bips_display_items_default, keyIdMap);
|
||||
setDisplayItemsNew(builder, false, R.array.pref_bips_display_items_default);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AmazfitBipSSupport setShortcuts(TransactionBuilder builder) {
|
||||
Map<String, Integer> keyIdMap = new LinkedHashMap<>();
|
||||
keyIdMap.put("status", 0x01);
|
||||
keyIdMap.put("alipay", 0x11);
|
||||
keyIdMap.put("nfc", 0x10);
|
||||
keyIdMap.put("pai", 0x19);
|
||||
keyIdMap.put("hr", 0x02);
|
||||
keyIdMap.put("music", 0x0b);
|
||||
keyIdMap.put("weather", 0x04);
|
||||
|
||||
setDisplayItemsNew(builder, true, R.array.pref_bips_display_items_default, keyIdMap);
|
||||
setDisplayItemsNew(builder, true, R.array.pref_bips_display_items_default);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||
@ -66,21 +64,7 @@ public class AmazfitGTSSupport extends AmazfitBipSupport {
|
||||
|
||||
@Override
|
||||
protected AmazfitGTSSupport setDisplayItems(TransactionBuilder builder) {
|
||||
Map<String, Integer> keyIdMap = new LinkedHashMap<>();
|
||||
keyIdMap.put("status", 0x01);
|
||||
keyIdMap.put("pai", 0x19);
|
||||
keyIdMap.put("hr", 0x02);
|
||||
keyIdMap.put("workout", 0x03);
|
||||
keyIdMap.put("activity", 0x14);
|
||||
keyIdMap.put("weather", 0x04);
|
||||
keyIdMap.put("music", 0x0b);
|
||||
keyIdMap.put("notifications", 0x06);
|
||||
keyIdMap.put("alarm", 0x09);
|
||||
keyIdMap.put("eventreminder", 0x15);
|
||||
keyIdMap.put("more", 0x07);
|
||||
keyIdMap.put("settings", 0x13);
|
||||
|
||||
setDisplayItemsNew(builder, false, R.array.pref_gts_display_items_default, keyIdMap);
|
||||
setDisplayItemsNew(builder, false, R.array.pref_gts_display_items_default);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
|
||||
@ -37,46 +35,13 @@ public class MiBand5Support extends MiBand4Support {
|
||||
|
||||
@Override
|
||||
protected MiBand5Support setDisplayItems(TransactionBuilder builder) {
|
||||
Map<String, Integer> keyIdMap = new LinkedHashMap<>();
|
||||
keyIdMap.put("status", 0x01);
|
||||
keyIdMap.put("pai", 0x19);
|
||||
keyIdMap.put("hr", 0x02);
|
||||
keyIdMap.put("notifications", 0x06);
|
||||
keyIdMap.put("breathing", 0x33);
|
||||
keyIdMap.put("eventreminder", 0x15);
|
||||
keyIdMap.put("weather", 0x04);
|
||||
keyIdMap.put("workout", 0x03);
|
||||
keyIdMap.put("more", 0x07);
|
||||
keyIdMap.put("stress", 0x1c);
|
||||
keyIdMap.put("period", 0x1d);
|
||||
|
||||
setDisplayItemsNew(builder, false, R.array.pref_miband5_display_items_default, keyIdMap);
|
||||
setDisplayItemsNew(builder, false, R.array.pref_miband5_display_items_default);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MiBand5Support setShortcuts(TransactionBuilder builder) {
|
||||
Map<String, Integer> keyIdMap = new LinkedHashMap<>();
|
||||
keyIdMap.put("notifications", 0x06);
|
||||
keyIdMap.put("weather", 0x04);
|
||||
keyIdMap.put("music", 0x0b);
|
||||
keyIdMap.put("timer", 0x0d);
|
||||
keyIdMap.put("alarm", 0x09);
|
||||
keyIdMap.put("findphone", 0x0e);
|
||||
keyIdMap.put("worldclock", 0x1a);
|
||||
keyIdMap.put("status", 0x01);
|
||||
keyIdMap.put("pai", 0x19);
|
||||
keyIdMap.put("hr", 0x02);
|
||||
keyIdMap.put("stress", 0x1c);
|
||||
keyIdMap.put("eventreminder", 0x15);
|
||||
keyIdMap.put("dnd", 0x08);
|
||||
keyIdMap.put("stopwatch", 0x0c);
|
||||
keyIdMap.put("workout", 0x03);
|
||||
keyIdMap.put("mutephone", 0x0f);
|
||||
keyIdMap.put("period", 0x1d);
|
||||
keyIdMap.put("takephoto", 0x0a);
|
||||
setDisplayItemsNew(builder, true, R.array.pref_miband5_shortcuts_default, keyIdMap);
|
||||
|
||||
setDisplayItemsNew(builder, true, R.array.pref_miband5_shortcuts_default);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -356,8 +356,8 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_miband5_shortcuts">
|
||||
<item>@string/menuitem_weather</item>
|
||||
<item>@string/menuitem_notifications</item>
|
||||
<item>@string/menuitem_weather</item>
|
||||
<item>@string/menuitem_music</item>
|
||||
<item>@string/menuitem_timer</item>
|
||||
<item>@string/menuitem_alarm</item>
|
||||
@ -449,8 +449,8 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_amazfitband5_shortcuts">
|
||||
<item>@string/menuitem_weather</item>
|
||||
<item>@string/menuitem_notifications</item>
|
||||
<item>@string/menuitem_weather</item>
|
||||
<item>@string/menuitem_music</item>
|
||||
<item>@string/menuitem_timer</item>
|
||||
<item>@string/menuitem_alarm</item>
|
||||
@ -648,7 +648,7 @@
|
||||
<item>@string/p_menuitem_nfc</item>
|
||||
<item>@string/p_menuitem_weather</item>
|
||||
<item>@string/p_menuitem_alarm</item>
|
||||
<item>@string/p_menuitem_timer</item>
|
||||
<item>@string/p_menuitem_timer_stopwatch</item>
|
||||
<item>@string/p_menuitem_compass</item>
|
||||
<item>@string/p_menuitem_worldclock</item>
|
||||
<item>@string/p_menuitem_music</item>
|
||||
|
@ -46,6 +46,7 @@
|
||||
<item name="p_menuitem_mutephone" type="string">mutephone</item>
|
||||
<item name="p_menuitem_takephoto" type="string">takephoto</item>
|
||||
<item name="p_menuitem_alexa" type="string">alexa</item>
|
||||
<item name="p_menuitem_timer_stopwatch" type="string">timer_stopwatch</item>
|
||||
|
||||
<item name="p_off" type="string">off</item>
|
||||
<item name="p_on" type="string">on</item>
|
||||
|
Loading…
Reference in New Issue
Block a user