mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-24 01:25:50 +01:00
Mi Band 8: Display items (wip, needs chunked)
This commit is contained in:
parent
5cc40f554e
commit
f978329711
@ -303,7 +303,7 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
// Display
|
// Display
|
||||||
//
|
//
|
||||||
settings.add(R.xml.devicesettings_header_display);
|
settings.add(R.xml.devicesettings_header_display);
|
||||||
settings.add(R.xml.devicesettings_huami2021_displayitems);
|
settings.add(R.xml.devicesettings_xiaomi_displayitems);
|
||||||
settings.add(R.xml.devicesettings_password);
|
settings.add(R.xml.devicesettings_password);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -41,4 +41,11 @@ public final class XiaomiPreferences {
|
|||||||
.setMinute(calendar.get(Calendar.MINUTE))
|
.setMinute(calendar.get(Calendar.MINUTE))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the preference key where to save the list of possible value for a preference, comma-separated.
|
||||||
|
*/
|
||||||
|
public static String getPrefPossibleValuesKey(final String key) {
|
||||||
|
return String.format(Locale.ROOT, "%s_possible_values", key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ public class XiaomiSupport extends AbstractBTLEDeviceSupport {
|
|||||||
@Override
|
@Override
|
||||||
public void onTestNewFunction() {
|
public void onTestNewFunction() {
|
||||||
final TransactionBuilder builder = createTransactionBuilder("test new function");
|
final TransactionBuilder builder = createTransactionBuilder("test new function");
|
||||||
|
sendCommand(builder, 2, 29);
|
||||||
builder.queue(getQueue());
|
builder.queue(getQueue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,11 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.services;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.List;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
@ -31,12 +34,16 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiPreferences;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||||
|
|
||||||
public class XiaomiSystemService extends AbstractXiaomiService {
|
public class XiaomiSystemService extends AbstractXiaomiService {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(XiaomiSystemService.class);
|
private static final Logger LOG = LoggerFactory.getLogger(XiaomiSystemService.class);
|
||||||
@ -62,7 +69,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
|||||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_DEVICE_INFO);
|
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_DEVICE_INFO);
|
||||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_BATTERY);
|
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_BATTERY);
|
||||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_PASSWORD_GET);
|
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_PASSWORD_GET);
|
||||||
getSupport().sendCommand(builder, COMMAND_TYPE, CMD_DISPLAY_ITEMS_GET);
|
// FIXME i think this needs chunked getSupport().sendCommand(builder, COMMAND_TYPE, CMD_DISPLAY_ITEMS_GET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,7 +104,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.warn("Unknown config command {}", cmd.getSubtype());
|
LOG.warn("Unknown system command {}", cmd.getSubtype());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -233,8 +240,50 @@ public class XiaomiSystemService extends AbstractXiaomiService {
|
|||||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setDisplayItems(final TransactionBuilder builder) {
|
||||||
|
final Prefs prefs = getDevicePrefs();
|
||||||
|
final ArrayList<String> allScreens = new ArrayList<>(prefs.getList(XiaomiPreferences.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), Collections.emptyList()));
|
||||||
|
final ArrayList<String> enabledScreens = new ArrayList<>(prefs.getList(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE, Collections.emptyList()));
|
||||||
|
if (allScreens.isEmpty()) {
|
||||||
|
LOG.warn("No list of all screens");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!enabledScreens.contains("setting")) {
|
||||||
|
enabledScreens.add("setting");
|
||||||
|
}
|
||||||
|
// TODO i think this needs chunked
|
||||||
|
}
|
||||||
|
|
||||||
private void handleDisplayItems(final XiaomiProto.DisplayItems displayItems) {
|
private void handleDisplayItems(final XiaomiProto.DisplayItems displayItems) {
|
||||||
LOG.debug("Got {} display items", displayItems.getDisplayItemCount());
|
LOG.debug("Got {} display items", displayItems.getDisplayItemCount());
|
||||||
|
final List<String> allScreens = new ArrayList<>();
|
||||||
|
final List<String> mainScreens = new ArrayList<>();
|
||||||
|
final List<String> moreScreens = new ArrayList<>();
|
||||||
|
for (final XiaomiProto.DisplayItem displayItem : displayItems.getDisplayItemList()) {
|
||||||
|
allScreens.add(displayItem.getCode());
|
||||||
|
if (!displayItem.getDisabled()) {
|
||||||
|
if (displayItem.getInMoreSection()) {
|
||||||
|
moreScreens.add(displayItem.getCode());
|
||||||
|
} else {
|
||||||
|
mainScreens.add(displayItem.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> enabledScreens = new ArrayList<>(mainScreens);
|
||||||
|
if (!moreScreens.isEmpty()) {
|
||||||
|
enabledScreens.add("more");
|
||||||
|
enabledScreens.addAll(moreScreens);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String allScreensPrefValue = StringUtils.join(",", allScreens.toArray(new String[0])).toString();
|
||||||
|
final String prefValue = StringUtils.join(",", enabledScreens.toArray(new String[0])).toString();
|
||||||
|
|
||||||
|
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences()
|
||||||
|
.withPreference(XiaomiPreferences.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), allScreensPrefValue)
|
||||||
|
.withPreference(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE, prefValue);
|
||||||
|
|
||||||
|
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFindPhone(final boolean start) {
|
public void onFindPhone(final boolean start) {
|
||||||
|
@ -1022,6 +1022,66 @@
|
|||||||
<item>headphone</item>
|
<item>headphone</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_xiaomi_apps">
|
||||||
|
<item>@string/menuitem_stats</item>
|
||||||
|
<item>@string/menuitem_workout</item>
|
||||||
|
<item>@string/menuitem_activity</item>
|
||||||
|
<item>@string/menuitem_running</item>
|
||||||
|
<item>@string/menuitem_status</item>
|
||||||
|
<item>@string/menuitem_hr</item>
|
||||||
|
<item>@string/menuitem_pai</item>
|
||||||
|
<item>@string/menuitem_spo2</item>
|
||||||
|
<item>@string/menuitem_sleep</item>
|
||||||
|
<item>@string/menuitem_stress</item>
|
||||||
|
<item>@string/menuitem_weather</item>
|
||||||
|
<item>@string/menuitem_alarm</item>
|
||||||
|
<item>@string/menuitem_settings</item>
|
||||||
|
<item>@string/menuitem_more</item> <!-- dummy item -->
|
||||||
|
<item>@string/menuitem_alerts</item>
|
||||||
|
<item>@string/menuitem_events</item>
|
||||||
|
<item>@string/menuitem_breathing</item>
|
||||||
|
<item>@string/menuitem_female_health</item>
|
||||||
|
<item>@string/menuitem_stopwatch</item>
|
||||||
|
<item>@string/menuitem_music</item>
|
||||||
|
<item>@string/menuitem_findphone</item>
|
||||||
|
<item>@string/menuitem_worldclock</item>
|
||||||
|
<item>@string/menuitem_mutephone</item>
|
||||||
|
<item>@string/menuitem_takephoto</item>
|
||||||
|
<item>@string/menuitem_timer</item>
|
||||||
|
<item>@string/menuitem_flashlight</item>
|
||||||
|
<item>@string/menuitem_pomodoro</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_xiaomi_apps_values">
|
||||||
|
<item>today_act</item>
|
||||||
|
<item>sport</item>
|
||||||
|
<item>sport_record</item>
|
||||||
|
<item>sport_course</item>
|
||||||
|
<item>sport_state</item>
|
||||||
|
<item>heart</item>
|
||||||
|
<item>pai</item>
|
||||||
|
<item>blood_ox</item>
|
||||||
|
<item>sleep</item>
|
||||||
|
<item>press</item>
|
||||||
|
<item>weather</item>
|
||||||
|
<item>alarm</item>
|
||||||
|
<item>setting</item>
|
||||||
|
<item>more</item> <!-- dummy item -->
|
||||||
|
<item>schedule</item>
|
||||||
|
<item>event_reminder</item>
|
||||||
|
<item>breath</item>
|
||||||
|
<item>fm_health</item>
|
||||||
|
<item>stopwatch</item>
|
||||||
|
<item>music</item>
|
||||||
|
<item>find_phone</item>
|
||||||
|
<item>world_clock</item>
|
||||||
|
<item>phone_mute</item>
|
||||||
|
<item>phone_remote</item>
|
||||||
|
<item>count_down</item>
|
||||||
|
<item>flash_light</item>
|
||||||
|
<item>focus</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="pref_miband5_workout_activity_types">
|
<string-array name="pref_miband5_workout_activity_types">
|
||||||
<item>@string/activity_type_outdoor_running</item>
|
<item>@string/activity_type_outdoor_running</item>
|
||||||
<item>@string/activity_type_walking</item>
|
<item>@string/activity_type_walking</item>
|
||||||
|
@ -2407,4 +2407,8 @@
|
|||||||
<string name="pref_navigation_app_osmand">OsmAnd(+)</string>
|
<string name="pref_navigation_app_osmand">OsmAnd(+)</string>
|
||||||
<string name="pref_navigation_app_gmaps">Google Maps</string>
|
<string name="pref_navigation_app_gmaps">Google Maps</string>
|
||||||
<string name="serial_number">Serial Number</string>
|
<string name="serial_number">Serial Number</string>
|
||||||
|
<string name="menuitem_stats">Stats</string>
|
||||||
|
<string name="menuitem_running">Running</string>
|
||||||
|
<string name="menuitem_alerts">Alerts</string>
|
||||||
|
<string name="menuitem_focus">Focus</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
13
app/src/main/res/xml/devicesettings_xiaomi_displayitems.xml
Normal file
13
app/src/main/res/xml/devicesettings_xiaomi_displayitems.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<com.mobeta.android.dslv.DragSortListPreference
|
||||||
|
android:defaultValue="@array/pref_huami2021_empty_array"
|
||||||
|
android:dialogTitle="@string/mi2_prefs_display_items"
|
||||||
|
android:entries="@array/pref_xiaomi_apps"
|
||||||
|
android:entryValues="@array/pref_xiaomi_apps_values"
|
||||||
|
android:icon="@drawable/ic_widgets"
|
||||||
|
android:key="display_items_sortable"
|
||||||
|
android:persistent="true"
|
||||||
|
android:summary="@string/mi2_prefs_display_items_summary"
|
||||||
|
android:title="@string/mi2_prefs_display_items" />
|
||||||
|
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user