mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-26 09:37:33 +01:00
Amazfit Bip S: Fix setting display items
This commit is contained in:
parent
f06c9fb8e7
commit
0e888aba3a
@ -79,7 +79,7 @@ public class AmazfitBipSCoordinator extends HuamiCoordinator {
|
||||
@Override
|
||||
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
|
||||
return new int[]{
|
||||
R.xml.devicesettings_amazfitbip,
|
||||
R.xml.devicesettings_amazfitbips,
|
||||
R.xml.devicesettings_timeformat,
|
||||
R.xml.devicesettings_wearlocation,
|
||||
R.xml.devicesettings_custom_emoji_font,
|
||||
|
@ -17,6 +17,7 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -25,7 +26,13 @@ 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.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.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
@ -83,4 +90,62 @@ public class AmazfitBipSSupport extends AmazfitBipSupport {
|
||||
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AmazfitBipSSupport setDisplayItems(TransactionBuilder builder) {
|
||||
if (gbDevice.getFirmwareVersion() == null) {
|
||||
LOG.warn("Device not initialized yet, won't set menu items");
|
||||
return this;
|
||||
}
|
||||
|
||||
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
|
||||
Set<String> pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_bips_display_items_default))));
|
||||
LOG.info("Setting display items to " + (pages == null ? "none" : pages));
|
||||
byte[] command = new byte[]{
|
||||
0x1E,
|
||||
0x00, 0x00, (byte) 0xFF, 0x01, // Status
|
||||
0x01, 0x00, (byte) 0xFF, 0x02, // HR
|
||||
0x02, 0x00, (byte) 0xFF, 0x19, // PAI
|
||||
0x03, 0x00, (byte) 0xFF, 0x03, // Workout
|
||||
0x04, 0x00, (byte) 0xFF, 0x11, // Alipay
|
||||
0x05, 0x00, (byte) 0xFF, 0x10, // NFC
|
||||
0x06, 0x00, (byte) 0xFF, 0x04, // Weather
|
||||
0x07, 0x00, (byte) 0xFF, 0x09, // Alarm
|
||||
0x08, 0x00, (byte) 0xFF, 0x1B, // Timer
|
||||
0x09, 0x00, (byte) 0xFF, 0x16, // Compass
|
||||
0x0A, 0x00, (byte) 0xFF, 0x1A, // Unknown
|
||||
0x0B, 0x00, (byte) 0xFF, 0x0B, // Music
|
||||
0x0C, 0x00, (byte) 0xFF, 0x13 // Settings
|
||||
};
|
||||
|
||||
String[] keys = {"status", "hr", "pai", "workout", "alipay", "nfc", "weather", "alarm", "timer", "compass", "unknown", "music", "settings"};
|
||||
byte[] ids = {1, 2, 25, 3, 17, 16, 4, 9, 27, 22, 26, 11, 19};
|
||||
|
||||
if (pages != null) {
|
||||
// it seem that we first have to put all ENABLED items into the array
|
||||
int pos = 1;
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
String key = keys[i];
|
||||
byte id = ids[i];
|
||||
if (pages.contains(key)) {
|
||||
command[pos + 1] = 0x00;
|
||||
command[pos + 3] = id;
|
||||
pos += 4;
|
||||
}
|
||||
}
|
||||
// And then all DISABLED ones
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
String key = keys[i];
|
||||
byte id = ids[i];
|
||||
if (!pages.contains(key)) {
|
||||
command[pos + 1] = 0x01;
|
||||
command[pos + 3] = id;
|
||||
pos += 4;
|
||||
}
|
||||
}
|
||||
writeToChunked(builder, 2, command);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -426,6 +426,54 @@
|
||||
<item>@string/p_menuitem_more</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_bips_display_items">
|
||||
<item>@string/menuitem_status</item>
|
||||
<item>@string/menuitem_hr</item>
|
||||
<item>@string/menuitem_pai</item>
|
||||
<item>@string/menuitem_workout</item>
|
||||
<item>@string/menuitem_alipay</item>
|
||||
<item>@string/menuitem_nfc</item>
|
||||
<item>@string/menuitem_weather</item>
|
||||
<item>@string/menuitem_alarm</item>
|
||||
<item>@string/menuitem_timer</item>
|
||||
<item>@string/menuitem_compass</item>
|
||||
<item>@string/menuitem_unknown</item>
|
||||
<item>@string/menuitem_music</item>
|
||||
<item>@string/menuitem_settings</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_bips_display_items_values">
|
||||
<item>@string/p_menuitem_status</item>
|
||||
<item>@string/p_menuitem_hr</item>
|
||||
<item>@string/p_menuitem_pai</item>
|
||||
<item>@string/p_menuitem_workout</item>
|
||||
<item>@string/p_menuitem_alipay</item>
|
||||
<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_compass</item>
|
||||
<item>@string/p_menuitem_unknown</item>
|
||||
<item>@string/p_menuitem_music</item>
|
||||
<item>@string/p_menuitem_settings</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_bips_display_items_default">
|
||||
<item>@string/p_menuitem_status</item>
|
||||
<item>@string/p_menuitem_hr</item>
|
||||
<item>@string/p_menuitem_pai</item>
|
||||
<item>@string/p_menuitem_workout</item>
|
||||
<item>@string/p_menuitem_alipay</item>
|
||||
<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_compass</item>
|
||||
<item>@string/p_menuitem_unknown</item>
|
||||
<item>@string/p_menuitem_music</item>
|
||||
<item>@string/p_menuitem_settings</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_entries_unit_system">
|
||||
<item>@string/unit_metric</item>
|
||||
<item>@string/unit_imperial</item>
|
||||
|
@ -772,6 +772,7 @@
|
||||
<string name="menuitem_hr">Heart Rate</string>
|
||||
<string name="menuitem_eventreminder">Event Reminder</string>
|
||||
<string name="menuitem_workout">Workout</string>
|
||||
<string name="menuitem_unknown">Unknown</string>
|
||||
<string name="watch9_time_minutes">Minutes:</string>
|
||||
<string name="watch9_time_hours">Hours:</string>
|
||||
<string name="watch9_time_seconds">Seconds:</string>
|
||||
|
@ -37,6 +37,7 @@
|
||||
<item name="p_menuitem_pai" type="string">pai</item>
|
||||
<item name="p_menuitem_eventreminder" type="string">eventreminder</item>
|
||||
<item name="p_menuitem_workout" type="string">workout</item>
|
||||
<item name="p_menuitem_unknown" type="string">unknown</item>
|
||||
|
||||
<item name="p_off" type="string">off</item>
|
||||
<item name="p_on" type="string">on</item>
|
||||
|
20
app/src/main/res/xml/devicesettings_amazfitbips.xml
Normal file
20
app/src/main/res/xml/devicesettings_amazfitbips.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<MultiSelectListPreference
|
||||
android:icon="@drawable/ic_widgets"
|
||||
android:defaultValue="@array/pref_bips_display_items_default"
|
||||
android:dialogTitle="@string/mi2_prefs_display_items"
|
||||
android:entries="@array/pref_bips_display_items"
|
||||
android:entryValues="@array/pref_bips_display_items_values"
|
||||
android:key="display_items"
|
||||
android:summary="@string/mi2_prefs_display_items_summary"
|
||||
android:title="@string/mi2_prefs_display_items" />
|
||||
<ListPreference
|
||||
android:icon="@drawable/ic_language"
|
||||
android:defaultValue="auto"
|
||||
android:entries="@array/pref_amazfitbip_language"
|
||||
android:entryValues="@array/pref_amazfitbip_language_values"
|
||||
android:key="language"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_title_language" />
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user