1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 11:26:47 +01:00

Mi Band 5: Add activate display on lift sensitivity

This commit is contained in:
José Rebelo 2022-05-09 13:57:44 +01:00 committed by Gitea
parent 43bcac072d
commit c74bbffb4d
12 changed files with 138 additions and 3 deletions

View File

@ -58,6 +58,7 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_ACTIVATE_DISPLAY_ON_LIFT = "activate_display_on_lift_wrist";
public static final String PREF_DISPLAY_ON_LIFT_START = "display_on_lift_start";
public static final String PREF_DISPLAY_ON_LIFT_END = "display_on_lift_end";
public static final String PREF_DISPLAY_ON_LIFT_SENSITIVITY = "display_on_lift_sensitivity";
public static final String PREF_SLEEP_TIME = "prefs_enable_sleep_time";
public static final String PREF_SLEEP_TIME_START = "prefs_sleep_time_start";

View File

@ -516,6 +516,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
}
String displayOnLiftState = prefs.getString(PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_DO_NOT_DISTURB_OFF);
boolean displayOnLiftScheduled = displayOnLiftState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
boolean displayOnLiftOff = displayOnLiftState.equals(PREF_DO_NOT_DISTURB_OFF);
final Preference rotateWristCycleInfo = findPreference(PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO);
if (rotateWristCycleInfo != null) {
@ -553,16 +554,32 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
});
}
final Preference displayOnLiftSensitivity = findPreference(PREF_DISPLAY_ON_LIFT_SENSITIVITY);
if (displayOnLiftSensitivity != null) {
displayOnLiftSensitivity.setEnabled(!displayOnLiftOff);
displayOnLiftSensitivity.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
notifyPreferenceChanged(PREF_DISPLAY_ON_LIFT_SENSITIVITY);
return true;
}
});
}
final Preference displayOnLift = findPreference(PREF_ACTIVATE_DISPLAY_ON_LIFT);
if (displayOnLift != null) {
displayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
final boolean scheduled = PREF_DO_NOT_DISTURB_SCHEDULED.equals(newVal.toString());
final boolean off = PREF_DO_NOT_DISTURB_OFF.equals(newVal.toString());
Objects.requireNonNull(displayOnLiftStart).setEnabled(scheduled);
Objects.requireNonNull(displayOnLiftEnd).setEnabled(scheduled);
if (rotateWristCycleInfo != null) {
rotateWristCycleInfo.setEnabled(!PREF_DO_NOT_DISTURB_OFF.equals(newVal.toString()));
rotateWristCycleInfo.setEnabled(!off);
}
if (displayOnLiftSensitivity != null) {
displayOnLiftSensitivity.setEnabled(!off);
}
notifyPreferenceChanged(PREF_ACTIVATE_DISPLAY_ON_LIFT);
return true;

View File

@ -0,0 +1,22 @@
/* Copyright (C) 2022 José Rebelo
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.devices.huami;
public enum ActivateDisplayOnLiftSensitivity {
NORMAL,
SENSITIVE
}

View File

@ -35,6 +35,7 @@ import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Locale;
import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -166,6 +167,14 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator {
return getTimePreference(DeviceSettingsPreferenceConst.PREF_DISPLAY_ON_LIFT_END, "00:00", deviceAddress);
}
public static ActivateDisplayOnLiftSensitivity getDisplayOnLiftSensitivity(String deviceAddress) {
final SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
final String pref = prefs.getString(DeviceSettingsPreferenceConst.PREF_DISPLAY_ON_LIFT_SENSITIVITY, "sensitive");
return ActivateDisplayOnLiftSensitivity.valueOf(pref.toUpperCase(Locale.ROOT));
}
public static DisconnectNotificationSetting getDisconnectNotificationSetting(Context context, String deviceAddress) {
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(deviceAddress));

View File

@ -149,6 +149,8 @@ public class HuamiService {
public static final byte[] COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01};
public static final byte[] COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x00};
public static final byte[] COMMAND_SCHEDULE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
public static final byte[] COMMAND_DISPLAY_ON_LIFT_WRIST_SPEED_NORMAL = new byte[]{ENDPOINT_DISPLAY, 0x23, 0x00, 0x00};
public static final byte[] COMMAND_DISPLAY_ON_LIFT_WRIST_SPEED_SENSITIVE = new byte[]{ENDPOINT_DISPLAY, 0x23, 0x00, 0x01};
public static final byte[] COMMAND_ENABLE_GOAL_NOTIFICATION = new byte[]{ENDPOINT_DISPLAY, 0x06, 0x00, 0x01};
public static final byte[] COMMAND_DISABLE_GOAL_NOTIFICATION = new byte[]{ENDPOINT_DISPLAY, 0x06, 0x00, 0x00};
public static final byte[] COMMAND_ENABLE_ROTATE_WRIST_TO_SWITCH_INFO = new byte[]{ENDPOINT_DISPLAY, 0x0d, 0x00, 0x01};

View File

@ -94,7 +94,7 @@ public class MiBand5Coordinator extends HuamiCoordinator {
R.xml.devicesettings_timeformat,
R.xml.devicesettings_dateformat,
R.xml.devicesettings_nightmode,
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_liftwrist_display_sensitivity,
R.xml.devicesettings_swipeunlock,
R.xml.devicesettings_sync_calendar,
R.xml.devicesettings_reserve_reminders_calendar,

View File

@ -72,6 +72,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInf
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.ActivateDisplayOnLift;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.ActivateDisplayOnLiftSensitivity;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.DisconnectNotificationSetting;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
@ -129,6 +130,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotific
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.actions.StopNotificationAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.Mi2NotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband2.Mi2TextNotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband5.MiBand5Support;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.FetchActivityOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.InitOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.InitOperation2021;
@ -151,6 +153,7 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_ALLOW_HIGH_MTU;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BT_CONNECTED_ADVERTISEMENT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DATEFORMAT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DISPLAY_ON_LIFT_SENSITIVITY;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DISPLAY_ON_LIFT_START;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DISPLAY_ON_LIFT_END;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DISCONNECT_NOTIFICATION;
@ -188,6 +191,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DEVICE_ACTION_WOKE_UP_BROADCAST;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DEVICE_ACTION_WOKE_UP_SELECTION;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService.DISPLAY_ITEM_BIT_CLOCK;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService.ENDPOINT_DISPLAY;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiService.ENDPOINT_DISPLAY_ITEMS;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_COUNT;
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.DEFAULT_VALUE_VIBRATION_PROFILE;
@ -2237,6 +2241,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
case PREF_DISPLAY_ON_LIFT_END:
setActivateDisplayOnLiftWrist(builder);
break;
case PREF_DISPLAY_ON_LIFT_SENSITIVITY:
setActivateDisplayOnLiftWristSensitivity(builder);
break;
case PREF_DISCONNECT_NOTIFICATION:
case PREF_DISCONNECT_NOTIFICATION_START:
case PREF_DISCONNECT_NOTIFICATION_END:
@ -2666,6 +2673,23 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
return this;
}
protected HuamiSupport setActivateDisplayOnLiftWristSensitivity(TransactionBuilder builder) {
final ActivateDisplayOnLiftSensitivity sensitivity = HuamiCoordinator.getDisplayOnLiftSensitivity(gbDevice.getAddress());
LOG.info("Setting activate display on lift wrist sensitivity to " + sensitivity);
switch (sensitivity) {
case SENSITIVE:
writeToConfiguration(builder, HuamiService.COMMAND_DISPLAY_ON_LIFT_WRIST_SPEED_SENSITIVE);
break;
case NORMAL:
default:
writeToConfiguration(builder, HuamiService.COMMAND_DISPLAY_ON_LIFT_WRIST_SPEED_NORMAL);
break;
}
return this;
}
protected HuamiSupport setDisplayItems(TransactionBuilder builder) {
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_mi2_display_items_default))));

View File

@ -50,7 +50,6 @@ public class MiBand5Support extends MiBand4Support {
return new MiBand5FWHelper(uri, context);
}
@Override
public boolean supportsSunriseSunsetWindHumidity() {
return true;
@ -60,4 +59,11 @@ public class MiBand5Support extends MiBand4Support {
public int getActivitySampleSize() {
return 8;
}
@Override
public void phase3Initialize(TransactionBuilder builder) {
super.phase3Initialize(builder);
LOG.info("phase3Initialize...");
setActivateDisplayOnLiftWristSensitivity(builder); // TODO? Move this to HuamiSupport?
}
}

View File

@ -272,6 +272,15 @@
<item>@string/p_scheduled</item>
</string-array>
<string-array name="activate_display_on_lift_sensitivity">
<item>@string/normal</item>
<item>@string/sensitive</item>
</string-array>
<string-array name="activate_display_on_lift_sensitivity_values">
<item>@string/p_normal</item>
<item>@string/p_sensitive</item>
</string-array>
<string-array name="mi3_night_mode">
<item>@string/off</item>
<!--

View File

@ -678,6 +678,7 @@
<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="prefs_activate_display_on_lift_sensitivity">Sensitivity</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="lefun_prefs_hydration_reminder_title">Hydration reminder</string>
@ -838,6 +839,8 @@
<string name="mi2_enable_text_notifications_summary"><![CDATA[Needs firmware >= 1.0.1.28 and Mili_pro.ft* installed.]]></string>
<string name="on">On</string>
<string name="off">Off</string>
<string name="normal">Normal</string>
<string name="sensitive">Sensitive</string>
<string name="mi2_dnd_off">Off</string>
<string name="mi3_night_mode_sunset">At sunset</string>
<string name="mi2_dnd_automatic">Automatic (sleep detection)</string>

View File

@ -69,6 +69,9 @@
<item name="p_automatic" type="string">automatic</item>
<item name="p_scheduled" type="string">scheduled</item>
<item name="p_normal" type="string">normal</item>
<item name="p_sensitive" type="string">sensitive</item>
<item name="p_unit_metric" type="string">metric</item>
<item name="p_unit_imperial" type="string">imperial</item>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
android:icon="@drawable/ic_arrow_upward"
android:key="screen_liftwrist_display"
android:persistent="false"
android:title="@string/mi2_prefs_activate_display_on_lift">
<!-- workaround for missing toolbar -->
<PreferenceCategory android:title="@string/mi2_prefs_activate_display_on_lift" />
<ListPreference
android:defaultValue="@string/p_off"
android:entries="@array/activate_display_on_lift"
android:entryValues="@array/activate_display_on_lift_values"
android:key="activate_display_on_lift_wrist"
android:summary="%s"
android:title="@string/mi2_prefs_activate_display_on_lift" />
<ListPreference
android:defaultValue="@string/p_normal"
android:entries="@array/activate_display_on_lift_sensitivity"
android:entryValues="@array/activate_display_on_lift_sensitivity_values"
android:key="display_on_lift_sensitivity"
android:summary="%s"
android:title="@string/prefs_activate_display_on_lift_sensitivity" />
<nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
android:defaultValue="00:00"
android:key="display_on_lift_start"
android:title="@string/mi2_prefs_do_not_disturb_start" />
<nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
android:defaultValue="00:00"
android:key="display_on_lift_end"
android:title="@string/mi2_prefs_do_not_disturb_end" />
</PreferenceScreen>
</androidx.preference.PreferenceScreen>