mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Mi Band 5: Add support for configuring activity types
This commit is contained in:
parent
682b215985
commit
10d11d4818
@ -20,7 +20,6 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -49,13 +48,10 @@ import java.util.Objects;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.ConfigureWorldClocks;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3.MakibesHR3Constants;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
@ -77,6 +73,7 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF
|
||||
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.huami.HuamiConst.PREF_SHORTCUTS_SORTABLE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_WORKOUT_ACTIVITY_TYPES_SORTABLE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE;
|
||||
@ -350,6 +347,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
|
||||
addPreferenceHandlerFor(PREF_DATEFORMAT);
|
||||
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS);
|
||||
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS_SORTABLE);
|
||||
addPreferenceHandlerFor(PREF_WORKOUT_ACTIVITY_TYPES_SORTABLE);
|
||||
addPreferenceHandlerFor(PREF_SHORTCUTS);
|
||||
addPreferenceHandlerFor(PREF_SHORTCUTS_SORTABLE);
|
||||
addPreferenceHandlerFor(PREF_LANGUAGE);
|
||||
|
@ -59,6 +59,7 @@ public class HuamiConst {
|
||||
|
||||
public static final String PREF_DISPLAY_ITEMS = "display_items";
|
||||
public static final String PREF_DISPLAY_ITEMS_SORTABLE = "display_items_sortable";
|
||||
public static final String PREF_WORKOUT_ACTIVITY_TYPES_SORTABLE = "workout_activity_types_sortable";
|
||||
public static final String PREF_SHORTCUTS = "shortcuts";
|
||||
public static final String PREF_SHORTCUTS_SORTABLE = "shortcuts_sortable";
|
||||
public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty";
|
||||
|
@ -139,7 +139,6 @@ 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;
|
||||
@ -193,14 +192,12 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_BUTTON_ACTION_SELECTION_OFF;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DEVICE_ACTION_FELL_SLEEP_BROADCAST;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DEVICE_ACTION_FELL_SLEEP_SELECTION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DEVICE_ACTION_SELECTION_BROADCAST;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DEVICE_ACTION_SELECTION_OFF;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DEVICE_ACTION_START_NON_WEAR_BROADCAST;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DEVICE_ACTION_START_NON_WEAR_SELECTION;
|
||||
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;
|
||||
@ -2410,6 +2407,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
case HuamiConst.PREF_SHORTCUTS_SORTABLE:
|
||||
setShortcuts(builder);
|
||||
break;
|
||||
case HuamiConst.PREF_WORKOUT_ACTIVITY_TYPES_SORTABLE:
|
||||
setWorkoutActivityTypes(builder);
|
||||
break;
|
||||
case MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO:
|
||||
setRotateWristToSwitchInfo(builder);
|
||||
break;
|
||||
@ -2992,6 +2992,48 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected HuamiSupport setWorkoutActivityTypes(final TransactionBuilder builder) {
|
||||
final SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
|
||||
|
||||
final List<String> allActivityTypes = Arrays.asList(getContext().getResources().getStringArray(R.array.pref_miband5_workout_activity_types_values));
|
||||
final List<String> defaultActivityTypes = Arrays.asList(getContext().getResources().getStringArray(R.array.pref_miband5_workout_activity_types_default));
|
||||
final String activityTypesPref = prefs.getString(HuamiConst.PREF_WORKOUT_ACTIVITY_TYPES_SORTABLE, null);
|
||||
|
||||
final List<String> enabledActivityTypes;
|
||||
if (activityTypesPref == null || activityTypesPref.equals("")) {
|
||||
enabledActivityTypes = defaultActivityTypes;
|
||||
} else {
|
||||
enabledActivityTypes = Arrays.asList(activityTypesPref.split(","));
|
||||
}
|
||||
|
||||
LOG.info("Setting workout types to {}", enabledActivityTypes);
|
||||
|
||||
final byte[] command = new byte[allActivityTypes.size() * 3 + 2];
|
||||
command[0] = 0x0b;
|
||||
command[1] = 0x00;
|
||||
|
||||
int pos = 2;
|
||||
|
||||
for (final String workoutType : enabledActivityTypes) {
|
||||
command[pos++] = HuamiWorkoutActivityType.fromPrefValue(workoutType).getCode();
|
||||
command[pos++] = 0x00;
|
||||
command[pos++] = 0x01;
|
||||
}
|
||||
|
||||
// Send all the remaining disabled workout types
|
||||
for (final String workoutType : allActivityTypes) {
|
||||
if (!enabledActivityTypes.contains(workoutType)) {
|
||||
command[pos++] = HuamiWorkoutActivityType.fromPrefValue(workoutType).getCode();
|
||||
command[pos++] = 0x00;
|
||||
command[pos++] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
writeToChunked(builder, 9, command);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
protected HuamiSupport setBeepSounds(TransactionBuilder builder) {
|
||||
|
||||
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
|
||||
|
@ -0,0 +1,52 @@
|
||||
/* 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.service.devices.huami;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum HuamiWorkoutActivityType {
|
||||
OutdoorRunning(0x01),
|
||||
Walking(0x06),
|
||||
Treadmill(0x08),
|
||||
OutdoorCycling(0x09),
|
||||
IndoorCycling(0x0a),
|
||||
Elliptical(0x0c),
|
||||
PoolSwimming(0x0e),
|
||||
Freestyle(0x10),
|
||||
JumpRope(0x15),
|
||||
RowingMachine(0x17),
|
||||
Yoga(0x3c);
|
||||
|
||||
private final byte code;
|
||||
|
||||
HuamiWorkoutActivityType(final int code) {
|
||||
this.code = (byte) code;
|
||||
}
|
||||
|
||||
public byte getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static HuamiWorkoutActivityType fromPrefValue(final String prefValue) {
|
||||
for (HuamiWorkoutActivityType type : values()) {
|
||||
if (type.name().toLowerCase(Locale.ROOT).equals(prefValue.replace("_", "").toLowerCase(Locale.ROOT))) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No matching HuamiWorkoutActivityType for pref value: " + prefValue);
|
||||
}
|
||||
}
|
@ -65,5 +65,6 @@ public class MiBand5Support extends MiBand4Support {
|
||||
super.phase3Initialize(builder);
|
||||
LOG.info("phase3Initialize...");
|
||||
setActivateDisplayOnLiftWristSensitivity(builder); // TODO? Move this to HuamiSupport?
|
||||
setWorkoutActivityTypes(builder); // TODO: Supported by other bands?
|
||||
}
|
||||
}
|
||||
|
@ -580,6 +580,48 @@
|
||||
<item>@string/p_menuitem_music</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_miband5_workout_activity_types">
|
||||
<item>@string/activity_type_outdoor_running</item>
|
||||
<item>@string/activity_type_walking</item>
|
||||
<item>@string/activity_type_treadmill</item>
|
||||
<item>@string/activity_type_outdoor_cycling</item>
|
||||
<item>@string/activity_type_indoor_cycling</item>
|
||||
<item>@string/activity_type_elliptical</item>
|
||||
<item>@string/activity_type_swimming</item>
|
||||
<item>@string/activity_type_freestyle</item>
|
||||
<item>@string/activity_type_jump_roping</item>
|
||||
<item>@string/activity_type_rowing_machine</item>
|
||||
<item>@string/activity_type_yoga</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_miband5_workout_activity_types_values">
|
||||
<item>outdoor_running</item>
|
||||
<item>walking</item>
|
||||
<item>treadmill</item>
|
||||
<item>outdoor_cycling</item>
|
||||
<item>indoor_cycling</item>
|
||||
<item>elliptical</item>
|
||||
<item>pool_swimming</item>
|
||||
<item>freestyle</item>
|
||||
<item>jump_rope</item>
|
||||
<item>rowing_machine</item>
|
||||
<item>yoga</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_miband5_workout_activity_types_default">
|
||||
<item>outdoor_running</item>
|
||||
<item>walking</item>
|
||||
<item>treadmill</item>
|
||||
<item>outdoor_cycling</item>
|
||||
<item>indoor_cycling</item>
|
||||
<item>elliptical</item>
|
||||
<item>pool_swimming</item>
|
||||
<item>freestyle</item>
|
||||
<item>jump_rope</item>
|
||||
<item>rowing_machine</item>
|
||||
<item>yoga</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_neo_display_items">
|
||||
<item>@string/menuitem_pai</item>
|
||||
<item>@string/menuitem_dnd</item>
|
||||
|
@ -688,6 +688,8 @@
|
||||
<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="mi5_prefs_workout_activity_types">Workout Activity Types</string>
|
||||
<string name="mi5_prefs_workout_activity_types_summary">Choose the activity types to display on the workouts 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="lefun_prefs_hydration_reminder_title">Hydration reminder</string>
|
||||
@ -875,13 +877,17 @@
|
||||
<string name="activity_type_deep_sleep">Deep sleep</string>
|
||||
<string name="activity_type_not_worn">Device not worn</string>
|
||||
<string name="activity_type_running">Running</string>
|
||||
<string name="activity_type_outdoor_running">Outdoor Running</string>
|
||||
<string name="activity_type_walking">Walking</string>
|
||||
<string name="activity_type_freestyle">Freestyle</string>
|
||||
<string name="activity_type_hiking">Hiking</string>
|
||||
<string name="activity_type_climbing">Climbing</string>
|
||||
<string name="activity_type_swimming">Swimming</string>
|
||||
<string name="activity_type_swimming_openwater">Swimming (Open water)</string>
|
||||
<string name="activity_type_indoor_cycling">Indoor Cycling</string>
|
||||
<string name="activity_type_outdoor_cycling">Outdoor Cycling</string>
|
||||
<string name="activity_type_elliptical_trainer">Elliptical Trainer</string>
|
||||
<string name="activity_type_elliptical">Elliptical</string>
|
||||
<string name="activity_type_jump_roping">Jumping Rope</string>
|
||||
<string name="activity_type_yoga">Yoga</string>
|
||||
<string name="activity_type_soccer">Soccer</string>
|
||||
|
@ -20,4 +20,14 @@
|
||||
android:persistent="true"
|
||||
android:summary="@string/bip_prefs_shotcuts_summary"
|
||||
android:title="@string/bip_prefs_shortcuts" />
|
||||
<com.mobeta.android.dslv.DragSortListPreference
|
||||
android:icon="@drawable/ic_activity_unknown_small"
|
||||
android:defaultValue="@array/pref_miband5_workout_activity_types_default"
|
||||
android:dialogTitle="@string/mi5_prefs_workout_activity_types"
|
||||
android:entries="@array/pref_miband5_workout_activity_types"
|
||||
android:entryValues="@array/pref_miband5_workout_activity_types_values"
|
||||
android:key="workout_activity_types_sortable"
|
||||
android:persistent="true"
|
||||
android:summary="@string/mi5_prefs_workout_activity_types_summary"
|
||||
android:title="@string/mi5_prefs_workout_activity_types" />
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
Loading…
Reference in New Issue
Block a user