-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix voiceLanguage NPE and add tests for NavigationSpeechPlayer #1054
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...main/java/com/mapbox/services/android/navigation/ui/v5/voice/Api26AudioFocusDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.mapbox.services.android.navigation.ui.v5.voice; | ||
|
||
import android.media.AudioFocusRequest; | ||
import android.media.AudioManager; | ||
import android.os.Build; | ||
import android.support.annotation.RequiresApi; | ||
|
||
@RequiresApi(api = Build.VERSION_CODES.O) | ||
class Api26AudioFocusDelegate implements AudioFocusDelegate { | ||
|
||
private static final int FOCUS_GAIN = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK; | ||
|
||
private final AudioManager audioManager; | ||
private final AudioFocusRequest audioFocusRequest; | ||
|
||
Api26AudioFocusDelegate(AudioManager audioManager) { | ||
this.audioManager = audioManager; | ||
audioFocusRequest = new AudioFocusRequest.Builder(FOCUS_GAIN).build(); | ||
} | ||
|
||
@Override | ||
public void requestFocus() { | ||
audioManager.requestAudioFocus(audioFocusRequest); | ||
} | ||
|
||
@Override | ||
public void abandonFocus() { | ||
audioManager.abandonAudioFocusRequest(audioFocusRequest); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
.../src/main/java/com/mapbox/services/android/navigation/ui/v5/voice/AudioFocusDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mapbox.services.android.navigation.ui.v5.voice; | ||
|
||
interface AudioFocusDelegate { | ||
|
||
void requestFocus(); | ||
|
||
void abandonFocus(); | ||
} |
24 changes: 24 additions & 0 deletions
24
...n/java/com/mapbox/services/android/navigation/ui/v5/voice/AudioFocusDelegateProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.mapbox.services.android.navigation.ui.v5.voice; | ||
|
||
import android.media.AudioManager; | ||
import android.os.Build; | ||
|
||
class AudioFocusDelegateProvider { | ||
|
||
private final AudioFocusDelegate audioFocusDelegate; | ||
|
||
AudioFocusDelegateProvider(AudioManager audioManager) { | ||
audioFocusDelegate = buildAudioFocusDelegate(audioManager); | ||
} | ||
|
||
AudioFocusDelegate retrieveAudioFocusDelegate() { | ||
return audioFocusDelegate; | ||
} | ||
|
||
private AudioFocusDelegate buildAudioFocusDelegate(AudioManager audioManager) { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
return new Api26AudioFocusDelegate(audioManager); | ||
} | ||
return new SpeechAudioFocusDelegate(audioManager); | ||
} | ||
} |
51 changes: 0 additions & 51 deletions
51
...i/src/main/java/com/mapbox/services/android/navigation/ui/v5/voice/InstructionPlayer.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if you pass in
VoiceInstructionMilestone
into a constructor inSpeechAnnouncement
so this logic can be inSpeechAnnouncement
? Instead of using the builder patternThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was thinking here in terms of usability outside of the turn-by-turn UI.
NavigationSpeechPlayer
is apublic
API, so tying it completely to theVoiceInstructionMilestone
in order to voice something may not make a lot of sense to someone that doesn't want to use the milestones to voice something.I did update the builder though to also take a
VoiceInstructionMilestone
, does that work? Any reasons you don't like the builder pattern here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense! And yea having a builder method that takes in a
VoiceInstructionMilestone
for convenience is 👍