mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Xiaomi: Add wear mode preference
This commit is contained in:
parent
d28cff478c
commit
4051c7f7d4
@ -54,6 +54,7 @@ public class DeviceSettingsPreferenceConst {
|
||||
public static final String PREF_TIMEFORMAT_AUTO = "auto";
|
||||
public static final String PREF_WEARLOCATION = "wearlocation";
|
||||
public static final String PREF_WEARDIRECTION = "weardirection";
|
||||
public static final String PREF_WEARMODE = "wearmode";
|
||||
public static final String PREF_VIBRATION_ENABLE = "vibration_enable";
|
||||
public static final String PREF_NOTIFICATION_ENABLE = "notification_enable";
|
||||
public static final String PREF_SCREEN_BRIGHTNESS = "screen_brightness";
|
||||
|
@ -539,6 +539,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
addPreferenceHandlerFor(PREF_ALWAYS_ON_DISPLAY_FOLLOW_WATCHFACE);
|
||||
addPreferenceHandlerFor(PREF_ALWAYS_ON_DISPLAY_STYLE);
|
||||
addPreferenceHandlerFor(PREF_WEARDIRECTION);
|
||||
addPreferenceHandlerFor(PREF_WEARMODE);
|
||||
|
||||
addPreferenceHandlerFor(PREF_VOLUME);
|
||||
addPreferenceHandlerFor(PREF_CROWN_VIBRATION);
|
||||
|
@ -349,6 +349,12 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
|
||||
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
|
||||
final List<Integer> settings = new ArrayList<>();
|
||||
|
||||
if (supports(device, FEAT_WEAR_MODE)) {
|
||||
// TODO we should be able to get this from the band - right now it must be changed
|
||||
// at least once from the band itself
|
||||
settings.add(R.xml.devicesettings_wearmode);
|
||||
}
|
||||
|
||||
//
|
||||
// Time
|
||||
//
|
||||
|
@ -33,6 +33,7 @@ public final class XiaomiPreferences {
|
||||
public static final String PREF_CANNED_MESSAGES_MIN = "canned_messages_min";
|
||||
public static final String PREF_CANNED_MESSAGES_MAX = "canned_messages_max";
|
||||
|
||||
public static final String FEAT_WEAR_MODE = "feat_wear_mode";
|
||||
public static final String FEAT_DEVICE_ACTIONS = "feat_device_actions";
|
||||
public static final String FEAT_DISPLAY_ITEMS = "feat_display_items";
|
||||
public static final String FEAT_STRESS = "feat_stress";
|
||||
|
@ -293,8 +293,6 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
|
||||
notification3.setBody("?");
|
||||
}
|
||||
|
||||
// TODO unknown caller i18n
|
||||
|
||||
final XiaomiProto.Notification2 notification2 = XiaomiProto.Notification2.newBuilder()
|
||||
.setNotification3(notification3)
|
||||
.build();
|
||||
@ -477,7 +475,6 @@ public class XiaomiNotificationService extends AbstractXiaomiService implements
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO avoid resize?
|
||||
final Bitmap bmp = BitmapUtil.toBitmap(icon);
|
||||
final Bitmap bmpResized = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||
final Canvas canvas = new Canvas(bmpResized);
|
||||
|
@ -75,11 +75,14 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
||||
public static final int CMD_CAMERA_REMOTE_GET = 7;
|
||||
public static final int CMD_CAMERA_REMOTE_SET = 8;
|
||||
public static final int CMD_PASSWORD_GET = 9;
|
||||
public static final int CMD_MISC_SETTING_GET = 14;
|
||||
public static final int CMD_MISC_SETTING_SET = 15;
|
||||
public static final int CMD_FIND_PHONE = 17;
|
||||
public static final int CMD_FIND_WATCH = 18;
|
||||
public static final int CMD_PASSWORD_SET = 21;
|
||||
public static final int CMD_DISPLAY_ITEMS_GET = 29;
|
||||
public static final int CMD_DISPLAY_ITEMS_SET = 30;
|
||||
public static final int CMD_MISC_SETTING_SET_FROM_BAND = 42;
|
||||
public static final int CMD_DEVICE_STATE_GET = 78;
|
||||
public static final int CMD_DEVICE_STATE = 79;
|
||||
|
||||
@ -130,6 +133,9 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
||||
case CMD_PASSWORD_GET:
|
||||
handlePassword(cmd.getSystem().getPassword());
|
||||
return;
|
||||
case CMD_MISC_SETTING_SET:
|
||||
LOG.debug("Got misc setting set ack, status={}", cmd.getStatus());
|
||||
return;
|
||||
case CMD_CAMERA_REMOTE_GET:
|
||||
handleCameraRemote(cmd.getSystem().getCamera());
|
||||
return;
|
||||
@ -149,6 +155,9 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
||||
case CMD_DISPLAY_ITEMS_GET:
|
||||
handleDisplayItems(cmd.getSystem().getDisplayItems());
|
||||
return;
|
||||
case CMD_MISC_SETTING_SET_FROM_BAND:
|
||||
handleMiscSettingSet(cmd.getSystem().getMiscSettingSet());
|
||||
return;
|
||||
case CMD_DEVICE_STATE_GET:
|
||||
handleBasicDeviceState(cmd.getSystem().hasBasicDeviceState()
|
||||
? cmd.getSystem().getBasicDeviceState()
|
||||
@ -167,6 +176,9 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
||||
@Override
|
||||
public boolean onSendConfiguration(final String config, final Prefs prefs) {
|
||||
switch (config) {
|
||||
case DeviceSettingsPreferenceConst.PREF_WEARMODE:
|
||||
setWearMode();
|
||||
return true;
|
||||
case DeviceSettingsPreferenceConst.PREF_CAMERA_REMOTE:
|
||||
setCameraRemoteConfig();
|
||||
return true;
|
||||
@ -350,6 +362,69 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||
}
|
||||
|
||||
private void handleMiscSettingSet(final XiaomiProto.MiscSettingSet miscSettingSet) {
|
||||
LOG.debug("Got misc setting set");
|
||||
|
||||
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences();
|
||||
|
||||
if (miscSettingSet.hasWearingMode()) {
|
||||
final String wearMode;
|
||||
|
||||
switch (miscSettingSet.getWearingMode().getMode()) {
|
||||
case 0:
|
||||
wearMode = "band";
|
||||
break;
|
||||
case 1:
|
||||
wearMode = "pebble";
|
||||
break;
|
||||
case 2:
|
||||
wearMode = "necklace";
|
||||
break;
|
||||
default:
|
||||
wearMode = null;
|
||||
LOG.warn("Unknown wear mode {}", miscSettingSet.getWearingMode().getMode());
|
||||
break;
|
||||
}
|
||||
|
||||
eventUpdatePreferences.withPreference(XiaomiPreferences.FEAT_WEAR_MODE, wearMode != null)
|
||||
.withPreference(DeviceSettingsPreferenceConst.PREF_WEARMODE, wearMode);
|
||||
}
|
||||
|
||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||
}
|
||||
|
||||
private void setWearMode() {
|
||||
final String wearMode = getDevicePrefs().getString(DeviceSettingsPreferenceConst.PREF_WEARMODE, "band");
|
||||
|
||||
LOG.debug("Set wear mode to {}", wearMode);
|
||||
|
||||
final int wearModeInt;
|
||||
|
||||
if ("band".equals(wearMode)) {
|
||||
wearModeInt = 0;
|
||||
} else if ("pebble".equals(wearMode)) {
|
||||
wearModeInt = 1;
|
||||
} else if ("necklace".equals(wearMode)) {
|
||||
wearModeInt = 2;
|
||||
} else {
|
||||
LOG.warn("Unknown wear mode {}", wearMode);
|
||||
return;
|
||||
}
|
||||
|
||||
getSupport().sendCommand(
|
||||
"set wear mode",
|
||||
XiaomiProto.Command.newBuilder()
|
||||
.setType(COMMAND_TYPE)
|
||||
.setSubtype(CMD_MISC_SETTING_SET)
|
||||
.setSystem(XiaomiProto.System.newBuilder().setMiscSettingSet(
|
||||
XiaomiProto.MiscSettingSet.newBuilder().setWearingMode(
|
||||
XiaomiProto.WearingMode.newBuilder().setMode(wearModeInt)
|
||||
)
|
||||
))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private void handleCameraRemote(final XiaomiProto.Camera camera) {
|
||||
LOG.debug("Got camera remote enabled={}", camera.getEnabled());
|
||||
|
||||
|
@ -110,9 +110,9 @@ message System {
|
||||
optional WidgetParts widgetsSingle = 29;
|
||||
|
||||
// 2, 14
|
||||
optional DoNotDisturb dnd2 = 34;
|
||||
optional MiscSettingGet miscSettingGet = 34;
|
||||
// 2, 15
|
||||
optional DndSync dndSync = 35;
|
||||
optional MiscSettingSet miscSettingSet = 35;
|
||||
|
||||
// 2, 46
|
||||
optional VibrationPatterns vibrationPatterns = 38;
|
||||
@ -240,10 +240,30 @@ message DoNotDisturb {
|
||||
optional uint32 status = 1; // 0 enabled, 2 disabled
|
||||
}
|
||||
|
||||
message DoNotDisturb2 {
|
||||
message MiscSettingGet {
|
||||
optional uint32 setting = 1; // 2 dndSync
|
||||
}
|
||||
|
||||
message MiscSettingSet {
|
||||
optional MiscNotificationSettings miscNotificationSettings = 1;
|
||||
optional DndSync dndSync = 2;
|
||||
optional WearingMode wearingMode = 3;
|
||||
}
|
||||
|
||||
message MiscNotificationSettings {
|
||||
optional uint32 wakeScreen = 1; // 0 ignore 1 enable 2 disable
|
||||
optional uint32 onlyWhenPhoneLocked = 2; // 0 ignore 1 enable 2 disable
|
||||
}
|
||||
|
||||
message DndSync {
|
||||
optional uint32 enabled = 1; // 0/1
|
||||
}
|
||||
|
||||
message WearingMode {
|
||||
// 0 Band Mode (wristband)
|
||||
// 1 Pebble Mode (show buckle)
|
||||
// 2 Necklace mode (neck strap)
|
||||
optional uint32 mode = 1;
|
||||
}
|
||||
|
||||
message FirmwareInstallRequest {
|
||||
|
@ -161,6 +161,17 @@
|
||||
<item>buttons_on_right</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="wearmode">
|
||||
<item>@string/wearmode_band</item>
|
||||
<item>@string/wearmode_pebble</item>
|
||||
<item>@string/wearmode_necklace</item>
|
||||
</string-array>
|
||||
<string-array name="wearmode_values">
|
||||
<item>band</item>
|
||||
<item>pebble</item>
|
||||
<item>necklace</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="orientation">
|
||||
<item>@string/horizontal</item>
|
||||
<item>@string/vertical</item>
|
||||
|
@ -619,6 +619,9 @@
|
||||
<string name="vertical">Vertical</string>
|
||||
<string name="buttons_on_left">Buttons on left</string>
|
||||
<string name="buttons_on_right">Buttons on right</string>
|
||||
<string name="wearmode_band">Band (wristband)</string>
|
||||
<string name="wearmode_pebble">Pebble (shoe buckle)</string>
|
||||
<string name="wearmode_necklace">Necklace (neck strap)</string>
|
||||
<string name="miband_pairing_using_dummy_userdata">No valid user data given, using dummy user data for now.</string>
|
||||
<string name="miband_pairing_tap_hint">When your Mi Band vibrates and blinks, tap it a few times in a row.</string>
|
||||
<string name="appinstaller_install">Install</string>
|
||||
@ -650,6 +653,7 @@
|
||||
<string name="sleep_activity_date_range">From %1$s to %2$s</string>
|
||||
<string name="prefs_wearside">Wearing left or right?</string>
|
||||
<string name="prefs_weardirection">Wearing direction</string>
|
||||
<string name="prefs_wearmode">Wearing mode</string>
|
||||
<string name="pref_screen_vibration_profile">Vibration profile</string>
|
||||
<string name="vibration_profile_default">Default</string>
|
||||
<string name="vibration_profile_staccato">Staccato</string>
|
||||
|
12
app/src/main/res/xml/devicesettings_wearmode.xml
Normal file
12
app/src/main/res/xml/devicesettings_wearmode.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<ListPreference
|
||||
android:defaultValue="band"
|
||||
android:entries="@array/wearmode"
|
||||
android:entryValues="@array/wearmode_values"
|
||||
android:icon="@drawable/ic_switch_left"
|
||||
android:key="wearmode"
|
||||
android:title="@string/prefs_wearmode"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user