1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 19:06:53 +01:00

Make button action setting per-device, enable for amazfip bip

TODO:
- preference migration
- support vibration on bip
This commit is contained in:
Andreas Shimokawa 2019-11-14 12:33:36 +01:00
parent e8a597295c
commit 25bb16b0c3
9 changed files with 98 additions and 96 deletions

View File

@ -16,13 +16,17 @@ import org.slf4j.LoggerFactory;
import java.util.Objects;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
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.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.XTimePreference;
import nodomain.freeyourgadget.gadgetbridge.util.XTimePreferenceFragment;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.*;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DATEFORMAT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_SCREEN_ORIENTATION;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_TIMEFORMAT;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_WEARLOCATION;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION;
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_END;
@ -370,25 +374,12 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
});
}
EditTextPreference mibandTimeOffset = findPreference(MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS);
if (mibandTimeOffset != null) {
mibandTimeOffset.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
@Override
public void onBindEditText(@NonNull EditText editText) {
editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
}
});
}
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_BROADCAST_DELAY, InputType.TYPE_CLASS_NUMBER);
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_PRESS_MAX_INTERVAL, InputType.TYPE_CLASS_NUMBER);
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_PRESS_COUNT, InputType.TYPE_CLASS_NUMBER);
setInputTypeFor(MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS, InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
setInputTypeFor(MakibesHR3Constants.PREF_FIND_PHONE_DURATION, InputType.TYPE_CLASS_NUMBER);
EditTextPreference findPhoneDuration = findPreference(MakibesHR3Constants.PREF_FIND_PHONE_DURATION);
if (findPhoneDuration != null) {
findPhoneDuration.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
@Override
public void onBindEditText(@NonNull EditText editText) {
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
}
});
}
}
static DeviceSpecificSettingsFragment newInstance(String settingsFileSuffix, @NonNull int[] supportedSettings) {
@ -431,4 +422,16 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
});
}
}
private void setInputTypeFor(final String preferenceKey, final int editTypeFlags) {
EditTextPreference textPreference = findPreference(preferenceKey);
if (textPreference != null) {
textPreference.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
@Override
public void onBindEditText(@NonNull EditText editText) {
editText.setInputType(editTypeFlags);
}
});
}
}
}

View File

@ -63,6 +63,13 @@ public class HuamiConst {
public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty";
public static final String PREF_USE_CUSTOM_FONT = "use_custom_font";
public static final String PREF_BUTTON_ACTION_ENABLE = "button_action_enable";
public static final String PREF_BUTTON_ACTION_VIBRATE = "button_action_vibrate";
public static final String PREF_BUTTON_ACTION_PRESS_COUNT = "button_action_press_count";
public static final String PREF_BUTTON_ACTION_PRESS_MAX_INTERVAL = "button_action_press_max_interval";
public static final String PREF_BUTTON_ACTION_BROADCAST_DELAY = "button_action_broadcast_delay";
public static final String PREF_BUTTON_ACTION_BROADCAST = "button_action_broadcast";
public static int toActivityKind(int rawType) {
switch (rawType) {
case TYPE_DEEP_SLEEP:

View File

@ -86,6 +86,7 @@ public class AmazfitBipCoordinator extends HuamiCoordinator {
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_disconnectnotification,
R.xml.devicesettings_expose_hr_thirdparty,
R.xml.devicesettings_buttonactions,
R.xml.devicesettings_pairingkey
};
}

View File

@ -84,6 +84,7 @@ public class MiBand2Coordinator extends HuamiCoordinator {
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_rotatewrist_cycleinfo,
R.xml.devicesettings_expose_hr_thirdparty,
R.xml.devicesettings_buttonactions,
R.xml.devicesettings_pairingkey
};
}

View File

@ -27,12 +27,6 @@ public final class MiBandConst {
public static final String PREF_MIBAND_ALARMS = "mi_alarms";
public static final String PREF_MIBAND_DONT_ACK_TRANSFER = "mi_dont_ack_transfer";
public static final String PREF_MIBAND_RESERVE_ALARM_FOR_CALENDAR = "mi_reserve_alarm_calendar";
public static final String PREF_MIBAND_BUTTON_ACTION_ENABLE = "mi2_enable_button_action";
public static final String PREF_MIBAND_BUTTON_ACTION_VIBRATE = "mi2_button_action_vibrate";
public static final String PREF_MIBAND_BUTTON_PRESS_COUNT = "mi_button_press_count";
public static final String PREF_MIBAND_BUTTON_PRESS_MAX_DELAY = "mi_button_press_count_max_delay";
public static final String PREF_MIBAND_BUTTON_ACTION_DELAY = "mi_button_press_count_match_delay";
public static final String PREF_MIBAND_BUTTON_PRESS_BROADCAST = "mi_button_press_broadcast";
public static final String PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION = "mi_hr_sleep_detection";
public static final String PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS = "device_time_offset_hours";
public static final String PREF_MI2_DATEFORMAT = "mi2_dateformat";

View File

@ -1090,7 +1090,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
return;
}
String requiredButtonPressMessage = prefs.getString(MiBandConst.PREF_MIBAND_BUTTON_PRESS_BROADCAST,
String requiredButtonPressMessage = prefs.getString(HuamiConst.PREF_BUTTON_ACTION_BROADCAST,
this.getContext().getString(R.string.mi2_prefs_button_press_broadcast_default_value));
Intent in = new Intent();
@ -1098,7 +1098,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
in.putExtra("button_id", currentButtonActionId);
LOG.info("Sending " + requiredButtonPressMessage + " with button_id " + currentButtonActionId);
this.getContext().getApplicationContext().sendBroadcast(in);
if (prefs.getBoolean(MiBandConst.PREF_MIBAND_BUTTON_ACTION_VIBRATE, false)) {
if (prefs.getBoolean(HuamiConst.PREF_BUTTON_ACTION_VIBRATE, false)) {
performPreferredNotification(null, null, null, HuamiService.ALERT_LEVEL_VIBRATE_ONLY, null);
}
@ -1215,18 +1215,17 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
}
}
public void handleButtonEvent() {
///logMessageContent(value);
private void handleButtonEvent() {
// If disabled we return from function immediately
Prefs prefs = GBApplication.getPrefs();
if (!prefs.getBoolean(MiBandConst.PREF_MIBAND_BUTTON_ACTION_ENABLE, false)) {
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
if (!prefs.getBoolean(HuamiConst.PREF_BUTTON_ACTION_ENABLE, false)) {
return;
}
int buttonPressMaxDelay = prefs.getInt(MiBandConst.PREF_MIBAND_BUTTON_PRESS_MAX_DELAY, 2000);
int buttonActionDelay = prefs.getInt(MiBandConst.PREF_MIBAND_BUTTON_ACTION_DELAY, 0);
int requiredButtonPressCount = prefs.getInt(MiBandConst.PREF_MIBAND_BUTTON_PRESS_COUNT, 0);
int buttonPressMaxDelay = prefs.getInt(HuamiConst.PREF_BUTTON_ACTION_PRESS_MAX_INTERVAL, 2000);
int buttonActionDelay = prefs.getInt(HuamiConst.PREF_BUTTON_ACTION_BROADCAST_DELAY, 0);
int requiredButtonPressCount = prefs.getInt(HuamiConst.PREF_BUTTON_ACTION_PRESS_COUNT, 0);
if (requiredButtonPressCount > 0) {
long timeSinceLastPress = System.currentTimeMillis() - currentButtonPressTime;
@ -1244,7 +1243,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
currentButtonTimerActivationTime = currentButtonPressTime;
if (buttonActionDelay > 0) {
LOG.info("Activating timer");
final Timer buttonActionTimer = new Timer("Mi Band Button Action Timer");
final Timer buttonActionTimer = new Timer("Huami Button Action Timer");
buttonActionTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {

View File

@ -79,11 +79,6 @@ public class AmazfitBipSupport extends HuamiSupport {
onSetCallState(callSpec);
}
@Override
public void handleButtonEvent() {
// ignore
}
@Override
protected AmazfitBipSupport setDisplayItems(TransactionBuilder builder) {
if (gbDevice.getFirmwareVersion() == null) {

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
android:key="screen_button_actions"
android:persistent="false"
android:summary="@string/mi2_prefs_button_actions_summary"
android:title="@string/mi2_prefs_button_actions">
<!-- workaround for missing toolbar -->
<PreferenceCategory android:title="@string/mi2_prefs_button_action" />
public static final String PREF_BUTTON_ACTION_PRESS_DELAY = "button_action_press_count_delay";
<CheckBoxPreference
android:defaultValue="false"
android:key="button_action_enable"
android:summary="@string/mi2_prefs_button_action_summary"
android:title="@string/mi2_prefs_button_action" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="button_action_enable"
android:key="button_action_vibrate"
android:summary="@string/mi2_prefs_button_action_vibrate_summary"
android:title="@string/mi2_prefs_button_action_vibrate" />
<EditTextPreference
android:defaultValue="6"
android:dependency="button_action_enable"
android:inputType="number"
android:key="button_action_press_count"
android:summary="@string/mi2_prefs_button_press_count_summary"
android:title="@string/mi2_prefs_button_press_count" />
<EditTextPreference
android:defaultValue="@string/mi2_prefs_button_press_broadcast_default_value"
android:dependency="button_action_enable"
android:key="button_action_broadcast"
android:summary="@string/mi2_prefs_button_press_broadcast_summary"
android:title="@string/mi2_prefs_button_press_broadcast" />
<EditTextPreference
android:defaultValue="2000"
android:dependency="button_action_enable"
android:inputType="number"
android:key="button_action_press_max_interval"
android:summary="@string/mi2_prefs_button_press_count_max_delay_summary"
android:title="@string/mi2_prefs_button_press_count_max_delay" />
<EditTextPreference
android:defaultValue="0"
android:dependency="button_action_enable"
android:inputType="number"
android:key="button_action_broadcast_delay"
android:summary="@string/mi2_prefs_button_press_count_match_delay_summary"
android:title="@string/mi2_prefs_button_press_count_match_delay" />
</PreferenceScreen>
</androidx.preference.PreferenceScreen>

View File

@ -22,62 +22,6 @@
android:summary="@string/mi2_prefs_goal_notification_summary"
android:title="@string/mi2_prefs_goal_notification" />
<PreferenceScreen
android:key="mi2_button_actions_key"
android:summary="@string/mi2_prefs_button_actions_summary"
android:title="@string/mi2_prefs_button_actions"
android:persistent="false">
<!-- workaround for missing toolbar -->
<PreferenceCategory
android:title="@string/mi2_prefs_button_action"
/>
<CheckBoxPreference
android:defaultValue="false"
android:key="mi2_enable_button_action"
android:summary="@string/mi2_prefs_button_action_summary"
android:title="@string/mi2_prefs_button_action" />
<CheckBoxPreference
android:defaultValue="false"
android:dependency="mi2_enable_button_action"
android:key="mi2_button_action_vibrate"
android:summary="@string/mi2_prefs_button_action_vibrate_summary"
android:title="@string/mi2_prefs_button_action_vibrate" />
<EditTextPreference
android:defaultValue="6"
android:dependency="mi2_enable_button_action"
android:inputType="number"
android:key="mi_button_press_count"
android:summary="@string/mi2_prefs_button_press_count_summary"
android:title="@string/mi2_prefs_button_press_count" />
<EditTextPreference
android:defaultValue="@string/mi2_prefs_button_press_broadcast_default_value"
android:dependency="mi2_enable_button_action"
android:key="mi_button_press_broadcast"
android:summary="@string/mi2_prefs_button_press_broadcast_summary"
android:title="@string/mi2_prefs_button_press_broadcast" />
<EditTextPreference
android:defaultValue="2000"
android:dependency="mi2_enable_button_action"
android:inputType="number"
android:key="mi_button_press_count_max_delay"
android:summary="@string/mi2_prefs_button_press_count_max_delay_summary"
android:title="@string/mi2_prefs_button_press_count_max_delay" />
<EditTextPreference
android:defaultValue="0"
android:dependency="mi2_enable_button_action"
android:inputType="number"
android:key="mi_button_press_count_match_delay"
android:summary="@string/mi2_prefs_button_press_count_match_delay_summary"
android:title="@string/mi2_prefs_button_press_count_match_delay" />
</PreferenceScreen>
<EditTextPreference
android:defaultValue="0"
android:inputType="number"