forked from upstream-mirrors/OpenTracks
Address comments.
This commit is contained in:
+11
-4
@@ -38,12 +38,17 @@ public class FroyoStatusAnnouncerTask
|
|||||||
implements OnUtteranceCompletedListener, OnAudioFocusChangeListener {
|
implements OnUtteranceCompletedListener, OnAudioFocusChangeListener {
|
||||||
|
|
||||||
private AudioManager audioManager;
|
private AudioManager audioManager;
|
||||||
|
private final static HashMap<String, String> SPEACH_PARAMS = new HashMap<String, String>();
|
||||||
|
static {
|
||||||
|
SPEACH_PARAMS.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "not_used");
|
||||||
|
}
|
||||||
|
|
||||||
public FroyoStatusAnnouncerTask(Context context) {
|
public FroyoStatusAnnouncerTask(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void onTtsInit(int status) {
|
protected void onTtsInit(int status) {
|
||||||
super.onTtsInit(status);
|
super.onTtsInit(status);
|
||||||
if (status == TextToSpeech.SUCCESS) {
|
if (status == TextToSpeech.SUCCESS) {
|
||||||
@@ -51,14 +56,16 @@ public class FroyoStatusAnnouncerTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void speakAnnouncment(String announcement) {
|
protected void speakAnnouncment(String announcement) {
|
||||||
audioManager.requestAudioFocus(this,
|
int result = audioManager.requestAudioFocus(this,
|
||||||
TextToSpeech.Engine.DEFAULT_STREAM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
|
TextToSpeech.Engine.DEFAULT_STREAM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
|
||||||
|
if (result == AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
|
||||||
|
Log.w(TAG, "FroyoStatusAnnouncerTask: Request audio focus failed.");
|
||||||
|
}
|
||||||
// We don't care about the id.
|
// We don't care about the id.
|
||||||
// It is supplied here to force onUtteranceCompleted to be called.
|
// It is supplied here to force onUtteranceCompleted to be called.
|
||||||
HashMap<String, String> params = new HashMap<String, String>();
|
tts.speak(announcement, TextToSpeech.QUEUE_FLUSH, SPEACH_PARAMS);
|
||||||
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "not_used");
|
|
||||||
tts.speak(announcement, TextToSpeech.QUEUE_FLUSH, params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class StatusAnnouncerFactory {
|
|||||||
*/
|
*/
|
||||||
public PeriodicTask create(Context context) {
|
public PeriodicTask create(Context context) {
|
||||||
if (hasTts) {
|
if (hasTts) {
|
||||||
if (ApiFeatures.getInstance().supportsAudioFocus()) {
|
if (ApiFeatures.getInstance().isAudioFocusSupported()) {
|
||||||
return new FroyoStatusAnnouncerTask(context);
|
return new FroyoStatusAnnouncerTask(context);
|
||||||
} else {
|
} else {
|
||||||
return new StatusAnnouncerTask(context);
|
return new StatusAnnouncerTask(context);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class ApiFeatures {
|
|||||||
return getApiLevel() >= 9;
|
return getApiLevel() >= 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsAudioFocus() {
|
public boolean isAudioFocusSupported() {
|
||||||
return getApiLevel() >= 8;
|
return getApiLevel() >= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user