Amazfit Bip S: Support setting shortcuts

This commit is contained in:
Zhong Jianxin 2020-05-13 16:15:12 +08:00
parent 0e888aba3a
commit fc39221782
7 changed files with 102 additions and 0 deletions

View File

@ -67,6 +67,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF
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_EXPOSE_HR_THIRDPARTY;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_SHORTCUTS;
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_OFF;
@ -323,6 +324,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
addPreferenceHandlerFor(PREF_DATEFORMAT);
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS);
addPreferenceHandlerFor(PREF_SHORTCUTS);
addPreferenceHandlerFor(PREF_LANGUAGE);
addPreferenceHandlerFor(PREF_EXPOSE_HR_THIRDPARTY);
addPreferenceHandlerFor(PREF_WEARLOCATION);

View File

@ -59,6 +59,7 @@ public class HuamiConst {
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_SHORTCUTS = "shortcuts";
public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty";
public static final String PREF_USE_CUSTOM_FONT = "use_custom_font";

View File

@ -1801,6 +1801,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
case HuamiConst.PREF_DISPLAY_ITEMS:
setDisplayItems(builder);
break;
case HuamiConst.PREF_SHORTCUTS:
setShortcuts(builder);
break;
case MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO:
setRotateWristToSwitchInfo(builder);
break;
@ -2166,6 +2169,10 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
return this;
}
protected HuamiSupport setShortcuts(TransactionBuilder builder) {
return this;
}
private HuamiSupport setRotateWristToSwitchInfo(TransactionBuilder builder) {
boolean enable = HuamiCoordinator.getRotateWristToSwitchInfo(gbDevice.getAddress());
LOG.info("Setting rotate wrist to cycle info to " + enable);

View File

@ -148,4 +148,56 @@ public class AmazfitBipSSupport extends AmazfitBipSupport {
return this;
}
@Override
protected AmazfitBipSSupport setShortcuts(TransactionBuilder builder) {
if (gbDevice.getFirmwareVersion() == null) {
LOG.warn("Device not initialized yet, won't set shortcuts");
return this;
}
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
Set<String> pages = prefs.getStringSet(HuamiConst.PREF_SHORTCUTS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_bips_shortcuts_default))));
LOG.info("Setting shortcuts to " + (pages == null ? "none" : pages));
byte[] command = new byte[]{
0x1E,
0x00, 0x00, (byte) 0xFD, 0x01, // Status
0x01, 0x00, (byte) 0xFD, 0x11, // Alipay
0x02, 0x00, (byte) 0xFD, 0x10, // NFC
0x03, 0x00, (byte) 0xFD, 0x19, // PAI
0x04, 0x00, (byte) 0xFD, 0x02, // HR
0x05, 0x00, (byte) 0xFD, 0x0B, // Music
0x06, 0x00, (byte) 0xFD, 0x04, // Weather
};
String[] keys = {"status", "alipay", "nfc", "pai", "hr", "music", "weather"};
byte[] ids = {1, 17, 16, 25, 2, 11, 4};
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;
}
}

View File

@ -474,6 +474,36 @@
<item>@string/p_menuitem_settings</item>
</string-array>
<string-array name="pref_bips_shortcuts">
<item>@string/menuitem_status</item>
<item>@string/menuitem_alipay</item>
<item>@string/menuitem_nfc</item>
<item>@string/menuitem_pai</item>
<item>@string/menuitem_hr</item>
<item>@string/menuitem_music</item>
<item>@string/menuitem_weather</item>
</string-array>
<string-array name="pref_bips_shortcuts_values">
<item>@string/p_menuitem_status</item>
<item>@string/p_menuitem_alipay</item>
<item>@string/p_menuitem_nfc</item>
<item>@string/p_menuitem_pai</item>
<item>@string/p_menuitem_hr</item>
<item>@string/p_menuitem_music</item>
<item>@string/p_menuitem_weather</item>
</string-array>
<string-array name="pref_bips_shortcuts_default">
<item>@string/p_menuitem_status</item>
<item>@string/p_menuitem_alipay</item>
<item>@string/p_menuitem_nfc</item>
<item>@string/p_menuitem_pai</item>
<item>@string/p_menuitem_hr</item>
<item>@string/p_menuitem_music</item>
<item>@string/p_menuitem_weather</item>
</string-array>
<string-array name="pref_entries_unit_system">
<item>@string/unit_metric</item>
<item>@string/unit_imperial</item>

View File

@ -536,6 +536,8 @@
<string name="mi3_prefs_band_screen_unlock_summary">Swipe up to unlock the band\'s screen</string>
<string name="mi3_prefs_night_mode">Night mode</string>
<string name="mi3_prefs_night_mode_summary">Lower band screen brightness automatically at night</string>
<string name="bip_prefs_shortcuts">Shortcuts</string>
<string name="bip_prefs_shotcuts_summary">Choose the shortcuts on the band screen</string>
<string name="pref_title_force_white_color_scheme">Force black on white color scheme</string>
<string name="pref_summary_force_white_color_scheme">Useful if you your watch has dark hands</string>
<string name="automatic">Automatic</string>

View File

@ -9,6 +9,14 @@
android:key="display_items"
android:summary="@string/mi2_prefs_display_items_summary"
android:title="@string/mi2_prefs_display_items" />
<MultiSelectListPreference
android:defaultValue="@array/pref_bips_shortcuts_default"
android:dialogTitle="@string/bip_prefs_shortcuts"
android:entries="@array/pref_bips_shortcuts"
android:entryValues="@array/pref_bips_shortcuts_values"
android:key="shortcuts"
android:summary="@string/bip_prefs_shotcuts_summary"
android:title="@string/bip_prefs_shortcuts" />
<ListPreference
android:icon="@drawable/ic_language"
android:defaultValue="auto"