From 1be1c0e6396ba513d46189d980677806de27a2e9 Mon Sep 17 00:00:00 2001 From: Koen Rabaey Date: Mon, 7 Apr 2014 21:14:42 +0200 Subject: [PATCH] add option to keep playing music --- OsmAnd/res/values/strings.xml | 2 ++ OsmAnd/res/xml/navigation_settings.xml | 1 + .../src/net/osmand/plus/OsmandSettings.java | 6 ++++++ .../SettingsNavigationActivity.java | 1 + .../osmand/plus/api/AudioFocusHelperImpl.java | 19 ++++++++++++++++--- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 3795c6f956..93afafac79 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -447,6 +447,8 @@ Auto zoom map Snap position to roads during navigation Snap to road + Interrupt music when making announcement + Interrupt Music Changes in 0.8.2: \n\t* Improved Routing \n\t* Dynamic map widgets diff --git a/OsmAnd/res/xml/navigation_settings.xml b/OsmAnd/res/xml/navigation_settings.xml index 06b77b2c16..1a1a1b2be2 100644 --- a/OsmAnd/res/xml/navigation_settings.xml +++ b/OsmAnd/res/xml/navigation_settings.xml @@ -14,6 +14,7 @@ + INTERRUPT_MUSIC = new BooleanPreference("interrupt_music", false).makeProfile().cache(); + { + INTERRUPT_MUSIC.setModeDefaultValue(ApplicationMode.CAR, true); + INTERRUPT_MUSIC.setModeDefaultValue(ApplicationMode.PEDESTRIAN, true); + } + // this value string is synchronized with settings_pref.xml preference name public static final String SAVE_CURRENT_TRACK = "save_current_track"; //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 67dbb6a1bf..bd2ed3c8c9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -85,6 +85,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { registerBooleanPreference(settings.SNAP_TO_ROAD, screen); + registerBooleanPreference(settings.INTERRUPT_MUSIC, screen); registerBooleanPreference(settings.USE_COMPASS_IN_NAVIGATION, screen); Integer[] intValues = new Integer[] { 0, 5, 10, 15, 20, 25, 30, 45, 60, 90}; diff --git a/OsmAnd/src/net/osmand/plus/api/AudioFocusHelperImpl.java b/OsmAnd/src/net/osmand/plus/api/AudioFocusHelperImpl.java index 08a2f56162..e5df3cebc5 100644 --- a/OsmAnd/src/net/osmand/plus/api/AudioFocusHelperImpl.java +++ b/OsmAnd/src/net/osmand/plus/api/AudioFocusHelperImpl.java @@ -20,14 +20,27 @@ public class AudioFocusHelperImpl implements AudioManager.OnAudioFocusChangeList @Override public boolean requestFocus(ClientContext context, int streamType) { AudioManager mAudioManager = (AudioManager) ((Context) context).getSystemService(Context.AUDIO_SERVICE); - return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.requestAudioFocus(this, streamType, - AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); + if (context.getSettings().INTERRUPT_MUSIC.get()) + { + return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.requestAudioFocus(this, streamType, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK); + } + else + { + return true; + } } @Override public boolean abandonFocus(ClientContext context, int streamType) { AudioManager mAudioManager = (AudioManager) ((Context) context).getSystemService(Context.AUDIO_SERVICE); - return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.abandonAudioFocus(this); + if (context.getSettings().INTERRUPT_MUSIC.get()) + { + return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.abandonAudioFocus(this); + } + else + { + return true; + } } @Override