mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-10 12:09:27 +01:00
Add-Buttons-Events-Config (#1761)
This commit is contained in:
parent
378475aa3d
commit
7394b1cce3
@ -29,5 +29,7 @@ public class GBDeviceEventMusicControl extends GBDeviceEvent {
|
||||
PREVIOUS,
|
||||
VOLUMEUP,
|
||||
VOLUMEDOWN,
|
||||
FORWARD,
|
||||
REWIND
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,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_buttonactions_with_longpress,
|
||||
R.xml.devicesettings_pairingkey
|
||||
};
|
||||
}
|
||||
|
@ -152,6 +152,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
private static int currentButtonPressCount = 0;
|
||||
private static long currentButtonPressTime = 0;
|
||||
private static long currentButtonTimerActivationTime = 0;
|
||||
private Timer buttonActionTimer = null;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HuamiSupport.class);
|
||||
private final DeviceInfoProfile<HuamiSupport> deviceInfoProfile;
|
||||
@ -1106,6 +1107,23 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
if (currentButtonTimerActivationTime != currentButtonPressTime) {
|
||||
return;
|
||||
}
|
||||
//handle user events settings. 0 is long press, rest are button_id 1-3
|
||||
switch (currentButtonActionId) {
|
||||
case 0:
|
||||
handleMediaButton(prefs.getString("button_long_press_action_selection","UNKNOWN"));
|
||||
break;
|
||||
case 1:
|
||||
handleMediaButton(prefs.getString("button_single_press_action_selection", "UNKNOWN"));
|
||||
break;
|
||||
case 2:
|
||||
handleMediaButton(prefs.getString("button_double_press_action_selection", "UNKNOWN"));
|
||||
break;
|
||||
case 3:
|
||||
handleMediaButton(prefs.getString("button_triple_press_action_selection", "UNKNOWN"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
String requiredButtonPressMessage = prefs.getString(HuamiConst.PREF_BUTTON_ACTION_BROADCAST,
|
||||
this.getContext().getString(R.string.mi2_prefs_button_press_broadcast_default_value));
|
||||
@ -1115,16 +1133,25 @@ 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(HuamiConst.PREF_BUTTON_ACTION_VIBRATE, false)) {
|
||||
vibrateOnce();
|
||||
}
|
||||
|
||||
currentButtonActionId = 0;
|
||||
|
||||
currentButtonPressCount = 0;
|
||||
currentButtonPressTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void handleMediaButton(String MediaAction) {
|
||||
if (MediaAction.equals("UNKNOWN")) {
|
||||
return;
|
||||
}
|
||||
GBDeviceEventMusicControl deviceEventMusicControl = new GBDeviceEventMusicControl();
|
||||
deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.valueOf(MediaAction);
|
||||
evaluateGBDeviceEvent(deviceEventMusicControl);
|
||||
}
|
||||
|
||||
private void handleDeviceEvent(byte[] value) {
|
||||
if (value == null || value.length == 0) {
|
||||
return;
|
||||
@ -1148,6 +1175,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
break;
|
||||
case HuamiDeviceEvent.BUTTON_PRESSED_LONG:
|
||||
LOG.info("button long-pressed ");
|
||||
handleLongButtonEvent();
|
||||
break;
|
||||
case HuamiDeviceEvent.START_NONWEAR:
|
||||
LOG.info("non-wear start detected");
|
||||
@ -1258,6 +1286,20 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleLongButtonEvent(){
|
||||
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
|
||||
|
||||
if (!prefs.getBoolean(HuamiConst.PREF_BUTTON_ACTION_ENABLE, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentButtonActionId = 0;
|
||||
currentButtonPressTime = System.currentTimeMillis();
|
||||
currentButtonTimerActivationTime = currentButtonPressTime;
|
||||
runButtonAction();
|
||||
|
||||
}
|
||||
|
||||
private void handleButtonEvent() {
|
||||
|
||||
// If disabled we return from function immediately
|
||||
@ -1267,7 +1309,6 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -1280,31 +1321,32 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
currentButtonPressCount = 1;
|
||||
currentButtonActionId = 0;
|
||||
}
|
||||
if (buttonActionTimer != null){
|
||||
buttonActionTimer.cancel();
|
||||
}
|
||||
|
||||
currentButtonPressTime = System.currentTimeMillis();
|
||||
if (currentButtonPressCount == requiredButtonPressCount) {
|
||||
currentButtonTimerActivationTime = currentButtonPressTime;
|
||||
if (buttonActionDelay > 0) {
|
||||
LOG.info("Activating timer");
|
||||
final Timer buttonActionTimer = new Timer("Huami Button Action Timer");
|
||||
buttonActionTimer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
runButtonAction();
|
||||
buttonActionTimer.cancel();
|
||||
}
|
||||
}, buttonActionDelay, buttonActionDelay);
|
||||
}
|
||||
else {
|
||||
LOG.info("Activating button action");
|
||||
runButtonAction();
|
||||
}
|
||||
LOG.info("Activating button timer");
|
||||
buttonActionTimer = new Timer("Huami Button Action Timer");
|
||||
buttonActionTimer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
runButtonAction();
|
||||
buttonActionTimer.cancel();
|
||||
}
|
||||
}, buttonPressMaxDelay, buttonPressMaxDelay);
|
||||
|
||||
currentButtonActionId++;
|
||||
currentButtonPressCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCharacteristicChanged(BluetoothGatt gatt,
|
||||
BluetoothGattCharacteristic characteristic) {
|
||||
|
@ -64,6 +64,12 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
||||
case PLAYPAUSE:
|
||||
keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
|
||||
break;
|
||||
case REWIND:
|
||||
keyCode = KeyEvent.KEYCODE_MEDIA_REWIND;
|
||||
break;
|
||||
case FORWARD:
|
||||
keyCode = KeyEvent.KEYCODE_MEDIA_FAST_FORWARD;
|
||||
break;
|
||||
case VOLUMEUP:
|
||||
// change default and fall through, :P
|
||||
volumeAdjust = AudioManager.ADJUST_RAISE;
|
||||
|
@ -604,4 +604,53 @@
|
||||
<item>14</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="button_action_options">
|
||||
<item>@string/pref_button_action_disabled</item>
|
||||
<item>@string/pref_media_play</item>
|
||||
<item>@string/pref_media_pause</item>
|
||||
<item>@string/pref_media_playpause</item>
|
||||
<item>@string/pref_media_next</item>
|
||||
<item>@string/pref_media_previous</item>
|
||||
<item>@string/pref_media_volumeup</item>
|
||||
<item>@string/pref_media_volumedown</item>
|
||||
<item>@string/pref_media_forward</item>
|
||||
<item>@string/pref_media_rewind</item>
|
||||
</string-array>
|
||||
|
||||
<string name="pref_button_action_disabled">Disabled</string>
|
||||
<string name="pref_media_play">Media Play</string>
|
||||
<string name="pref_media_pause">Media Pause</string>
|
||||
<string name="pref_media_playpause">Toggle playback</string>
|
||||
<string name="pref_media_next">Next Track</string>
|
||||
<string name="pref_media_previous">Previous Track</string>
|
||||
<string name="pref_media_volumeup">Volume Up</string>
|
||||
<string name="pref_media_volumedown">Volume Down</string>
|
||||
<string name="pref_media_forward">Skip forward</string>
|
||||
<string name="pref_media_rewind">Skip back</string>
|
||||
|
||||
<string-array name="button_action_values">
|
||||
<item>@string/pref_button_action_disabled_value</item>
|
||||
<item>@string/pref_media_play_value</item>
|
||||
<item>@string/pref_media_pause_value</item>
|
||||
<item>@string/pref_media_playpause_value</item>
|
||||
<item>@string/pref_media_next_value</item>
|
||||
<item>@string/pref_media_previous_value</item>
|
||||
<item>@string/pref_media_volumeup_value</item>
|
||||
<item>@string/pref_media_volumedown_value</item>
|
||||
<item>@string/pref_media_forward_value</item>
|
||||
<item>@string/pref_media_rewind_value</item>
|
||||
|
||||
</string-array>
|
||||
|
||||
<string name="pref_button_action_disabled_value" translatable="false">UNKNOWN</string>
|
||||
<string name="pref_media_play_value" translatable="false">PLAY</string>
|
||||
<string name="pref_media_pause_value" translatable="false">PAUSE</string>
|
||||
<string name="pref_media_playpause_value" translatable="false">PLAYPAUSE</string>
|
||||
<string name="pref_media_next_value" translatable="false">NEXT</string>
|
||||
<string name="pref_media_previous_value" translatable="false">PREVIOUS</string>
|
||||
<string name="pref_media_volumeup_value" translatable="false">VOLUMEUP</string>
|
||||
<string name="pref_media_volumedown_value" translatable="false">VOLUMEDOWN</string>
|
||||
<string name="pref_media_forward_value" translatable="false">FORWARD</string>
|
||||
<string name="pref_media_rewind_value" translatable="false">REWIND</string>
|
||||
|
||||
</resources>
|
||||
|
@ -463,9 +463,9 @@
|
||||
<string name="mi2_prefs_button_actions">Button actions</string>
|
||||
<string name="mi2_prefs_button_actions_summary">Specify button press actions</string>
|
||||
<string name="mi2_prefs_button_press_count">Button press count</string>
|
||||
<string name="mi2_prefs_button_press_count_summary">Number of button presses to trigger message broadcast</string>
|
||||
<string name="mi2_prefs_button_press_count_summary">Number of button presses to trigger an Event 1. Subsequent same amount of presses create Event 2 and so on.</string>
|
||||
<string name="mi2_prefs_button_press_broadcast">Broadcast message to send</string>
|
||||
<string name="mi2_prefs_button_press_broadcast_summary">Broadcast message on defined number of button presses reached</string>
|
||||
<string name="mi2_prefs_button_press_broadcast_summary">Broadcast message sent with the event. Parameter `button_id` is added automatically to each message.</string>
|
||||
<string name="mi2_prefs_button_press_broadcast_default_value" translatable="false">nodomain.freeyourgadget.gadgetbridge.ButtonPressed</string>
|
||||
<string name="mi2_prefs_button_action">Enable button action</string>
|
||||
<string name="mi2_prefs_button_action_summary">Enable action on specified number of button presses</string>
|
||||
@ -473,8 +473,6 @@
|
||||
<string name="mi2_prefs_button_action_vibrate_summary">Enable band vibration on button action triggered</string>
|
||||
<string name="mi2_prefs_button_press_count_max_delay">Maximum delay between presses</string>
|
||||
<string name="mi2_prefs_button_press_count_max_delay_summary">Maximum delay between button presses in milliseconds</string>
|
||||
<string name="mi2_prefs_button_press_count_match_delay">Delay after button action</string>
|
||||
<string name="mi2_prefs_button_press_count_match_delay_summary">Delay after one button action match (number is in button_id intent extra) or 0 for immediately</string>
|
||||
<string name="mi2_prefs_goal_notification">Goal notification</string>
|
||||
<string name="mi2_prefs_goal_notification_summary">The band will vibrate when the daily steps goal is reached</string>
|
||||
<string name="mi2_prefs_display_items">Display items</string>
|
||||
@ -773,6 +771,14 @@
|
||||
<string name="qhybrid_offset_timezone">offset timezone by</string>
|
||||
<string name="qhybrid_changes_delay_prompt">change might take some seconds…</string>
|
||||
<string name="qhybrid_offset_time_by">offset time by</string>
|
||||
|
||||
<string name="huami_prefs_button_single_press_action_selection_title">Event 1 action</string>
|
||||
<string name="huami_prefs_button_double_press_action_selection_title">Event 2 action</string>
|
||||
<string name="huami_prefs_button_triple_press_action_selection_title">Event 3 action</string>
|
||||
<string name="huami_prefs_button_variable_actions">Detailed button press settings</string>
|
||||
<string name="huami_prefs_button_long_press_action_selection_title">Long press button action</string>
|
||||
|
||||
|
||||
<plurals name="widget_alarm_target_hours">
|
||||
<item quantity="one">%d hour</item>
|
||||
<item quantity="two">%d hours</item>
|
||||
|
@ -24,35 +24,59 @@
|
||||
android:summary="@string/mi2_prefs_button_action_vibrate_summary"
|
||||
android:title="@string/mi2_prefs_button_action_vibrate" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="6"
|
||||
<ListPreference
|
||||
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" />
|
||||
android:entries="@array/button_action_options"
|
||||
android:entryValues="@array/button_action_values"
|
||||
android:key="button_single_press_action_selection"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:summary="%s"
|
||||
android:title="@string/huami_prefs_button_single_press_action_selection_title" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="@string/mi2_prefs_button_press_broadcast_default_value"
|
||||
<ListPreference
|
||||
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" />
|
||||
android:entries="@array/button_action_options"
|
||||
android:entryValues="@array/button_action_values"
|
||||
android:key="button_double_press_action_selection"
|
||||
android:summary="%s"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:title="@string/huami_prefs_button_double_press_action_selection_title" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="2000"
|
||||
<ListPreference
|
||||
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" />
|
||||
android:entries="@array/button_action_options"
|
||||
android:entryValues="@array/button_action_values"
|
||||
android:key="button_triple_press_action_selection"
|
||||
android:summary="%s"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:title="@string/huami_prefs_button_triple_press_action_selection_title" />
|
||||
|
||||
<PreferenceCategory android:title="@string/huami_prefs_button_variable_actions">
|
||||
|
||||
<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" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<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>
|
||||
|
@ -0,0 +1,90 @@
|
||||
<?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";
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="button_action_enable"
|
||||
android:summary="@string/mi2_prefs_button_action_summary"
|
||||
android:title="@string/mi2_prefs_button_action" />
|
||||
|
||||
<SwitchPreference
|
||||
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" />
|
||||
|
||||
<ListPreference
|
||||
android:dependency="button_action_enable"
|
||||
android:entries="@array/button_action_options"
|
||||
android:entryValues="@array/button_action_values"
|
||||
android:key="button_single_press_action_selection"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:summary="%s"
|
||||
android:title="@string/huami_prefs_button_single_press_action_selection_title" />
|
||||
|
||||
<ListPreference
|
||||
android:dependency="button_action_enable"
|
||||
android:entries="@array/button_action_options"
|
||||
android:entryValues="@array/button_action_values"
|
||||
android:key="button_double_press_action_selection"
|
||||
android:summary="%s"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:title="@string/huami_prefs_button_double_press_action_selection_title" />
|
||||
|
||||
<ListPreference
|
||||
android:dependency="button_action_enable"
|
||||
android:entries="@array/button_action_options"
|
||||
android:entryValues="@array/button_action_values"
|
||||
android:key="button_triple_press_action_selection"
|
||||
android:summary="%s"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:title= "@string/huami_prefs_button_triple_press_action_selection_title" />
|
||||
|
||||
<ListPreference
|
||||
android:dependency="button_action_enable"
|
||||
android:entries="@array/button_action_options"
|
||||
android:entryValues="@array/button_action_values"
|
||||
android:key="button_long_press_action_selection"
|
||||
android:defaultValue="@string/pref_button_action_disabled_value"
|
||||
android:summary="%s"
|
||||
android:title="@string/huami_prefs_button_long_press_action_selection_title" />
|
||||
<PreferenceCategory android:title="@string/huami_prefs_button_variable_actions">
|
||||
|
||||
<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" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user