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

OsmAnd: Make navigation instructions configurable

This commit is contained in:
José Rebelo 2023-05-22 11:57:15 +01:00 committed by Andreas Shimokawa
parent cc30276f45
commit 592356faf1
3 changed files with 50 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.IBinder; import android.os.IBinder;
import android.os.PowerManager;
import android.os.RemoteException; import android.os.RemoteException;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.widget.Toast; import android.widget.Toast;
@ -27,6 +28,7 @@ import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.model.NavigationInfoSpec; import nodomain.freeyourgadget.gadgetbridge.model.NavigationInfoSpec;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class OsmandEventReceiver { public class OsmandEventReceiver {
private static final Logger LOG = LoggerFactory.getLogger(OsmandEventReceiver.class); private static final Logger LOG = LoggerFactory.getLogger(OsmandEventReceiver.class);
@ -60,9 +62,12 @@ public class OsmandEventReceiver {
public void updateNavigationInfo(ADirectionInfo directionInfo) { public void updateNavigationInfo(ADirectionInfo directionInfo) {
navigationInfoSpec.nextAction = directionInfo.getTurnType(); navigationInfoSpec.nextAction = directionInfo.getTurnType();
navigationInfoSpec.distanceToTurn = directionInfo.getDistanceTo(); navigationInfoSpec.distanceToTurn = directionInfo.getDistanceTo();
GBApplication.deviceService().onSetNavigationInfo(navigationInfoSpec);
LOG.error("Distance: " + directionInfo.getDistanceTo() + " turnType: " + directionInfo.getTurnType()); if (shouldSendNavigation()) {
GBApplication.deviceService().onSetNavigationInfo(navigationInfoSpec);
}
LOG.debug("Distance: {}, turnType: {}", directionInfo.getDistanceTo(), directionInfo.getTurnType());
} }
@Override @Override
@ -74,7 +79,7 @@ public class OsmandEventReceiver {
List<String> played = params.getPlayed(); List<String> played = params.getPlayed();
for (String instuction : played) { for (String instuction : played) {
navigationInfoSpec.instruction = instuction; navigationInfoSpec.instruction = instuction;
LOG.error("instruction: " + instuction); LOG.debug("instruction: {}", instuction);
// only first one for now // only first one for now
break; break;
} }
@ -90,7 +95,7 @@ public class OsmandEventReceiver {
public void onServiceConnected(ComponentName className, public void onServiceConnected(ComponentName className,
IBinder service) { IBinder service) {
mIOsmAndAidlInterface = IOsmAndAidlInterface.Stub.asInterface(service); mIOsmAndAidlInterface = IOsmAndAidlInterface.Stub.asInterface(service);
GB.toast("OsmAnd service conncted", Toast.LENGTH_SHORT, GB.INFO); LOG.info("OsmAnd service connected");
registerForNavigationUpdates(true, 6666); // what is this id for? registerForNavigationUpdates(true, 6666); // what is this id for?
registerForVoiceRouterMessages(true, 6667); registerForVoiceRouterMessages(true, 6667);
// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("osmand.api://GET_INFO")); // Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("osmand.api://GET_INFO"));
@ -99,7 +104,7 @@ public class OsmandEventReceiver {
public void onServiceDisconnected(ComponentName className) { public void onServiceDisconnected(ComponentName className) {
mIOsmAndAidlInterface = null; mIOsmAndAidlInterface = null;
GB.toast("OsmAnd service disconnected", Toast.LENGTH_SHORT, GB.INFO); LOG.info("OsmAnd service disconnected");
} }
}; };
@ -108,7 +113,6 @@ public class OsmandEventReceiver {
if (!bindService()) { if (!bindService()) {
LOG.warn("Could not bind to OsmAnd"); LOG.warn("Could not bind to OsmAnd");
} }
} }
private boolean bindService() { private boolean bindService() {
@ -117,10 +121,10 @@ public class OsmandEventReceiver {
intent.setPackage(OSMAND_PACKAGE_NAME); intent.setPackage(OSMAND_PACKAGE_NAME);
boolean res = app.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); boolean res = app.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
if (res) { if (res) {
GB.toast("bound to OsmAnd service", Toast.LENGTH_SHORT, GB.INFO); LOG.info("Bound to OsmAnd service");
return true; return true;
} else { } else {
GB.toast("could not bind to OsmAnd service", Toast.LENGTH_SHORT, GB.INFO); LOG.warn("Could not bind to OsmAnd service");
return false; return false;
} }
} else { } else {
@ -149,12 +153,31 @@ public class OsmandEventReceiver {
return -1L; return -1L;
} }
private boolean shouldSendNavigation() {
final Prefs prefs = GBApplication.getPrefs();
final boolean navigationForward = prefs.getBoolean("navigation_forward", true);
if (!navigationForward) {
return false;
}
final boolean navigationScreenOn = prefs.getBoolean("nagivation_screen_on", true);
if (!navigationScreenOn) {
final PowerManager powermanager = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
if (powermanager != null && powermanager.isScreenOn()) {
LOG.info("Not forwarding navigation instructions, screen seems to be on and settings do not allow this");
return false;
}
}
return true;
}
/** /**
* Method to register for Voice Router voice messages during navigation. Notifies user about voice messages. * Method to register for Voice Router voice messages during navigation. Notifies user about voice messages.
* *
* @param subscribeToUpdates (boolean) - boolean flag to subscribe or unsubscribe from messages * @param subscribeToUpdates (boolean) - boolean flag to subscribe or unsubscribe from messages
* @param callbackId (long) - id of callback, needed to unsubscribe from messages * @param callbackId (long) - id of callback, needed to unsubscribe from messages
* @param callback (IOsmAndAidlCallback) - callback to notify user on voice message
*/ */
public long registerForVoiceRouterMessages(boolean subscribeToUpdates, long callbackId) { public long registerForVoiceRouterMessages(boolean subscribeToUpdates, long callbackId) {
ANavigationVoiceRouterMessageParams params = new ANavigationVoiceRouterMessageParams(); ANavigationVoiceRouterMessageParams params = new ANavigationVoiceRouterMessageParams();

View File

@ -324,6 +324,7 @@
<string name="pref_pebble_privacy_mode_content">Shift the notification text off-screen</string> <string name="pref_pebble_privacy_mode_content">Shift the notification text off-screen</string>
<string name="pref_pebble_privacy_mode_complete">Show only the notification icon</string> <string name="pref_pebble_privacy_mode_complete">Show only the notification icon</string>
<string name="pref_header_location">Location</string> <string name="pref_header_location">Location</string>
<string name="pref_header_navigation">Navigation</string>
<string name="pref_title_location_aquire">Acquire location</string> <string name="pref_title_location_aquire">Acquire location</string>
<string name="pref_title_location_latitude">Latitude</string> <string name="pref_title_location_latitude">Latitude</string>
<string name="pref_title_location_longitude">Longitude</string> <string name="pref_title_location_longitude">Longitude</string>
@ -2025,6 +2026,8 @@
<string name="fossil_hr_button_config_info">Some buttons cannot be configured because their functions are hard-coded in the watch firmware.\n\nWarning: long-pressing the upper button when a watchface from the official Fossil app is installed will also toggle between showing/hiding widgets.</string> <string name="fossil_hr_button_config_info">Some buttons cannot be configured because their functions are hard-coded in the watch firmware.\n\nWarning: long-pressing the upper button when a watchface from the official Fossil app is installed will also toggle between showing/hiding widgets.</string>
<string name="pref_title_opentracks_packagename">OpenTracks package name</string> <string name="pref_title_opentracks_packagename">OpenTracks package name</string>
<string name="pref_summary_opentracks_packagename">Used for starting/stopping GPS track recording in external fitness app.</string> <string name="pref_summary_opentracks_packagename">Used for starting/stopping GPS track recording in external fitness app.</string>
<string name="pref_summary_navigation_forward">Forward instructions from navigation apps to the watch</string>
<string name="pref_title_navigation_forward">Send navigation to watch</string>
<string name="watchface_dialog_pre_setting_position">pre-setting position to %s</string> <string name="watchface_dialog_pre_setting_position">pre-setting position to %s</string>
<string name="watchface_setting_light_up_on_notification">Light up on new notification</string> <string name="watchface_setting_light_up_on_notification">Light up on new notification</string>

View File

@ -148,6 +148,20 @@
android:summary="@string/pref_summary_opentracks_packagename" android:summary="@string/pref_summary_opentracks_packagename"
android:title="@string/pref_title_opentracks_packagename" /> android:title="@string/pref_title_opentracks_packagename" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_header_navigation">
<CheckBoxPreference
android:defaultValue="true"
android:key="navigation_forward"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_navigation_forward"
android:title="@string/pref_title_navigation_forward" />
<CheckBoxPreference
android:defaultValue="true"
android:dependency="navigation_forward"
android:key="nagivation_screen_on"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_title_whenscreenon" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/preferences_category_device_specific_settings"> <PreferenceCategory android:title="@string/preferences_category_device_specific_settings">
<Preference <Preference