mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-24 16:21:16 +02:00
Add HUAMI button/device action to control fitness tracking
- Fitness App Tracking Start already works, Stop is commented out for time being - Catch exception in case the package name for controlled app doesn't exist/work
This commit is contained in:
parent
5224304b6c
commit
65cbea6713
@ -80,6 +80,8 @@ public class HuamiConst {
|
||||
public static final String PREF_BUTTON_ACTION_BROADCAST = "button_action_broadcast";
|
||||
public static final String PREF_BUTTON_ACTION_SELECTION_OFF = "UNKNOWN";
|
||||
public static final String PREF_BUTTON_ACTION_SELECTION_BROADCAST = "BROADCAST";
|
||||
public static final String PREF_BUTTON_ACTION_SELECTION_FITNESS_APP_START = "FITNESS_CONTROL_START";
|
||||
public static final String PREF_BUTTON_ACTION_SELECTION_FITNESS_APP_STOP = "FITNESS_CONTROL_STOP";
|
||||
|
||||
public static final String PREF_DEVICE_ACTION_SELECTION_OFF = "UNKNOWN";
|
||||
public static final String PREF_DEVICE_ACTION_SELECTION_BROADCAST = "BROADCAST";
|
||||
|
@ -22,6 +22,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -29,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
public class OpenTracksController extends Activity {
|
||||
@ -70,7 +72,11 @@ public class OpenTracksController extends Activity {
|
||||
intent.setClassName(packageName, className);
|
||||
intent.putExtra("STATS_TARGET_PACKAGE", context.getPackageName());
|
||||
intent.putExtra("STATS_TARGET_CLASS", "nodomain.freeyourgadget.gadgetbridge.externalevents.OpenTracksController");
|
||||
context.startActivity(intent);
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
GB.toast(e.getMessage(), Toast.LENGTH_LONG, GB.WARN);
|
||||
}
|
||||
}
|
||||
|
||||
public static void startRecording(Context context) {
|
||||
|
@ -93,6 +93,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.OpenTracksController;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||
@ -157,6 +158,8 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
|
||||
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_BUTTON_ACTION_SELECTION_BROADCAST;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_BUTTON_ACTION_SELECTION_FITNESS_APP_START;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_BUTTON_ACTION_SELECTION_FITNESS_APP_STOP;
|
||||
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;
|
||||
@ -1408,10 +1411,18 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
if (prefs.getBoolean(HuamiConst.PREF_BUTTON_ACTION_VIBRATE, false)) {
|
||||
vibrateOnce();
|
||||
}
|
||||
if (buttonPreference.equals(PREF_BUTTON_ACTION_SELECTION_BROADCAST)) {
|
||||
sendSystemBroadcastWithButtonId();
|
||||
} else {
|
||||
handleMediaButton(buttonPreference);
|
||||
switch (buttonPreference) {
|
||||
case PREF_BUTTON_ACTION_SELECTION_BROADCAST:
|
||||
sendSystemBroadcastWithButtonId();
|
||||
break;
|
||||
case PREF_BUTTON_ACTION_SELECTION_FITNESS_APP_START:
|
||||
OpenTracksController.startRecording(this.getContext());
|
||||
break;
|
||||
case PREF_BUTTON_ACTION_SELECTION_FITNESS_APP_STOP:
|
||||
OpenTracksController.stopRecording(this.getContext());
|
||||
break;
|
||||
default:
|
||||
handleMediaButton(buttonPreference);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1419,10 +1430,18 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
if (deviceAction.equals(PREF_DEVICE_ACTION_SELECTION_OFF)) {
|
||||
return;
|
||||
}
|
||||
if (deviceAction.equals(PREF_DEVICE_ACTION_SELECTION_BROADCAST)) {
|
||||
sendSystemBroadcast(message);
|
||||
}else {
|
||||
handleMediaButton(deviceAction);
|
||||
switch (deviceAction) {
|
||||
case PREF_BUTTON_ACTION_SELECTION_BROADCAST:
|
||||
sendSystemBroadcast(message);
|
||||
break;
|
||||
case PREF_BUTTON_ACTION_SELECTION_FITNESS_APP_START:
|
||||
OpenTracksController.startRecording(this.getContext());
|
||||
break;
|
||||
case PREF_BUTTON_ACTION_SELECTION_FITNESS_APP_STOP:
|
||||
OpenTracksController.stopRecording(this.getContext());
|
||||
break;
|
||||
default:
|
||||
handleMediaButton(deviceAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1654,6 +1654,12 @@
|
||||
<item>@string/pref_media_forward</item>
|
||||
<item>@string/pref_media_rewind</item>
|
||||
<item>@string/pref_device_action_broadcast</item>
|
||||
<item>@string/pref_device_action_fitness_app_control_start</item>
|
||||
<!--
|
||||
Enable when OpenTracks allows to be stopped via intent
|
||||
https://github.com/OpenTracksApp/OpenTracks/issues/1103
|
||||
<item>@string/pref_device_action_fitness_app_control_stop</item>
|
||||
-->
|
||||
</string-array>
|
||||
|
||||
<string-array name="button_action_values">
|
||||
@ -1668,6 +1674,12 @@
|
||||
<item>@string/pref_media_forward_value</item>
|
||||
<item>@string/pref_media_rewind_value</item>
|
||||
<item>@string/pref_device_action_broadcast_value</item>
|
||||
<item>@string/pref_device_action_fitness_app_control_start_value</item>
|
||||
<!--
|
||||
Enable when OpenTracks allows to be stopped via intent
|
||||
https://github.com/OpenTracksApp/OpenTracks/issues/1103
|
||||
<item>@string/pref_device_action_fitness_app_control_stop_value</item>
|
||||
-->
|
||||
</string-array>
|
||||
|
||||
<string-array name="device_action_options">
|
||||
@ -1676,6 +1688,12 @@
|
||||
<item>@string/pref_media_pause</item>
|
||||
<item>@string/pref_media_playpause</item>
|
||||
<item>@string/pref_device_action_broadcast</item>
|
||||
<item>@string/pref_device_action_fitness_app_control_start</item>
|
||||
<!--
|
||||
Enable when OpenTracks allows to be stopped via intent
|
||||
https://github.com/OpenTracksApp/OpenTracks/issues/1103
|
||||
<item>@string/pref_device_action_fitness_app_control_stop</item>
|
||||
-->
|
||||
</string-array>
|
||||
|
||||
<string-array name="device_action_values">
|
||||
@ -1684,6 +1702,12 @@
|
||||
<item>@string/pref_media_pause_value</item>
|
||||
<item>@string/pref_media_playpause_value</item>
|
||||
<item>@string/pref_device_action_broadcast_value</item>
|
||||
<item>@string/pref_device_action_fitness_app_control_start_value</item>
|
||||
<!--
|
||||
Enable when OpenTracks allows to be stopped via intent
|
||||
https://github.com/OpenTracksApp/OpenTracks/issues/1103
|
||||
<item>@string/pref_device_action_fitness_app_control_stop_value</item>
|
||||
-->
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_hybridhr_buttonfunctions">
|
||||
|
@ -1495,6 +1495,8 @@
|
||||
<string name="pref_media_forward">Skip forward</string>
|
||||
<string name="pref_media_rewind">Skip back</string>
|
||||
<string name="pref_device_action_broadcast">Send Broadcast</string>
|
||||
<string name="pref_device_action_fitness_app_control_start">Fitness App Tracking Start</string>
|
||||
<string name="pref_device_action_fitness_app_control_stop">Fitness App Tracking Stop</string>
|
||||
<!-- Translators: the ### indicate number of digits, keep intact -->
|
||||
<string name="distance_format_meters">###m</string>
|
||||
<!-- Translators: the ### indicate number of digits, keep intact -->
|
||||
|
@ -106,6 +106,8 @@
|
||||
<item name="pref_media_forward_value" translatable="false" type="string">FORWARD</item>
|
||||
<item name="pref_media_rewind_value" translatable="false" type="string">REWIND</item>
|
||||
<item name="pref_device_action_broadcast_value" translatable="false" type="string">BROADCAST</item>
|
||||
<item name="pref_device_action_fitness_app_control_start_value" translatable="false" type="string">FITNESS_CONTROL_START</item>
|
||||
<item name="pref_device_action_fitness_app_control_stop_value" translatable="false" type="string">FITNESS_CONTROL_STOP</item>
|
||||
<item name="pref_title_touch_voice_assistant" type="string">Voice Assistant</item>
|
||||
<item name="pref_title_touch_anc" type="string">Active Noise Cancelling</item>
|
||||
<item name="pref_title_touch_quick_ambient" type="string">Quick Ambient Sound</item>
|
||||
|
Loading…
Reference in New Issue
Block a user