Separate mute and sending voice notifications
This commit is contained in:
parent
6c37768663
commit
36e18d2651
5 changed files with 57 additions and 58 deletions
|
@ -1,12 +1,13 @@
|
||||||
package net.osmand.plus;
|
package net.osmand.plus;
|
||||||
|
|
||||||
import android.app.Activity;
|
import java.io.File;
|
||||||
import android.app.AlertDialog;
|
import java.io.FileInputStream;
|
||||||
import android.app.ProgressDialog;
|
import java.io.FileOutputStream;
|
||||||
import android.content.Context;
|
import java.io.IOException;
|
||||||
import android.content.DialogInterface;
|
import java.lang.reflect.Field;
|
||||||
import android.content.Intent;
|
import java.util.ArrayList;
|
||||||
import android.content.SharedPreferences;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
@ -29,23 +30,23 @@ import net.osmand.plus.render.RendererRegistry;
|
||||||
import net.osmand.plus.resources.ResourceManager;
|
import net.osmand.plus.resources.ResourceManager;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.views.corenative.NativeCoreContext;
|
import net.osmand.plus.views.corenative.NativeCoreContext;
|
||||||
|
import net.osmand.plus.voice.CommandPlayer;
|
||||||
import net.osmand.plus.voice.CommandPlayerException;
|
import net.osmand.plus.voice.CommandPlayerException;
|
||||||
import net.osmand.plus.voice.CommandPlayerFactory;
|
import net.osmand.plus.voice.MediaCommandPlayerImpl;
|
||||||
|
import net.osmand.plus.voice.TTSCommandPlayerImpl;
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
import net.osmand.router.RoutingConfiguration;
|
import net.osmand.router.RoutingConfiguration;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.File;
|
import android.app.Activity;
|
||||||
import java.io.FileInputStream;
|
import android.app.AlertDialog;
|
||||||
import java.io.FileOutputStream;
|
import android.app.ProgressDialog;
|
||||||
import java.io.IOException;
|
import android.content.Context;
|
||||||
import java.lang.reflect.Field;
|
import android.content.DialogInterface;
|
||||||
import java.util.ArrayList;
|
import android.content.Intent;
|
||||||
import java.util.List;
|
import android.content.SharedPreferences;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import btools.routingapp.BRouterServiceConnection;
|
import btools.routingapp.BRouterServiceConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -319,13 +320,32 @@ public class AppInitializer implements IProgress {
|
||||||
final ProgressDialog dlg = showDialog ? ProgressDialog.show(uiContext, app.getString(R.string.loading_data),
|
final ProgressDialog dlg = showDialog ? ProgressDialog.show(uiContext, app.getString(R.string.loading_data),
|
||||||
app.getString(R.string.voice_data_initializing)) : null;
|
app.getString(R.string.voice_data_initializing)) : null;
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
|
public CommandPlayer createCommandPlayer(String voiceProvider, OsmandApplication osmandApplication, Activity ctx)
|
||||||
|
throws CommandPlayerException {
|
||||||
|
if (voiceProvider != null) {
|
||||||
|
File parent = osmandApplication.getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||||
|
File voiceDir = new File(parent, voiceProvider);
|
||||||
|
if (!voiceDir.exists()) {
|
||||||
|
throw new CommandPlayerException(ctx.getString(R.string.voice_data_unavailable));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MediaCommandPlayerImpl.isMyData(voiceDir)) {
|
||||||
|
return new MediaCommandPlayerImpl(osmandApplication, osmandApplication.getRoutingHelper().getVoiceRouter(), voiceProvider);
|
||||||
|
} else if (TTSCommandPlayerImpl.isMyData(voiceDir)) {
|
||||||
|
return new TTSCommandPlayerImpl(ctx, osmandApplication.getRoutingHelper().getVoiceRouter(), voiceProvider);
|
||||||
|
}
|
||||||
|
throw new CommandPlayerException(ctx.getString(R.string.voice_data_not_supported));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (app.player != null) {
|
if (app.player != null) {
|
||||||
app.player.clear();
|
app.player.clear();
|
||||||
}
|
}
|
||||||
app.player = CommandPlayerFactory.createCommandPlayer(voiceProvider, app, uiContext);
|
app.player = createCommandPlayer(voiceProvider, app, uiContext);
|
||||||
app.getRoutingHelper().getVoiceRouter().setPlayer(app.player);
|
app.getRoutingHelper().getVoiceRouter().setPlayer(app.player);
|
||||||
if(dlg != null) {
|
if(dlg != null) {
|
||||||
dlg.dismiss();
|
dlg.dismiss();
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class VoiceRouter {
|
||||||
|
|
||||||
|
|
||||||
protected CommandBuilder getNewCommandPlayerToPlay(){
|
protected CommandBuilder getNewCommandPlayerToPlay(){
|
||||||
if(player == null || mute){
|
if(player == null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
lastAnnouncement = System.currentTimeMillis();
|
lastAnnouncement = System.currentTimeMillis();
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package net.osmand.plus.voice;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
|
||||||
import net.osmand.plus.R;
|
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
public class CommandPlayerFactory {
|
|
||||||
public static CommandPlayer createCommandPlayer(String voiceProvider, OsmandApplication osmandApplication, Activity ctx)
|
|
||||||
throws CommandPlayerException {
|
|
||||||
if (voiceProvider != null) {
|
|
||||||
File parent = osmandApplication.getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
|
||||||
File voiceDir = new File(parent, voiceProvider);
|
|
||||||
if (!voiceDir.exists()) {
|
|
||||||
throw new CommandPlayerException(ctx.getString(R.string.voice_data_unavailable));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MediaCommandPlayerImpl.isMyData(voiceDir)) {
|
|
||||||
return new MediaCommandPlayerImpl(osmandApplication, voiceProvider);
|
|
||||||
} else if (TTSCommandPlayerImpl.isMyData(voiceDir)) {
|
|
||||||
return new TTSCommandPlayerImpl(ctx, voiceProvider);
|
|
||||||
}
|
|
||||||
throw new CommandPlayerException(ctx.getString(R.string.voice_data_not_supported));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.routing.VoiceRouter;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
@ -30,12 +31,14 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
||||||
private MediaPlayer mediaPlayer;
|
private MediaPlayer mediaPlayer;
|
||||||
// indicates that player is ready to play first file
|
// indicates that player is ready to play first file
|
||||||
private List<String> filesToPlay = Collections.synchronizedList(new ArrayList<String>());
|
private List<String> filesToPlay = Collections.synchronizedList(new ArrayList<String>());
|
||||||
|
private VoiceRouter vrt;
|
||||||
|
|
||||||
|
|
||||||
public MediaCommandPlayerImpl(OsmandApplication ctx, String voiceProvider)
|
public MediaCommandPlayerImpl(OsmandApplication ctx, VoiceRouter vrt, String voiceProvider)
|
||||||
throws CommandPlayerException
|
throws CommandPlayerException
|
||||||
{
|
{
|
||||||
super(ctx, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION);
|
super(ctx, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION);
|
||||||
|
this.vrt = vrt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,6 +60,9 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
||||||
// Called from the calculating route thread.
|
// Called from the calculating route thread.
|
||||||
@Override
|
@Override
|
||||||
public synchronized void playCommands(CommandBuilder builder) {
|
public synchronized void playCommands(CommandBuilder builder) {
|
||||||
|
if(vrt.isMute()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
filesToPlay.addAll(builder.execute());
|
filesToPlay.addAll(builder.execute());
|
||||||
|
|
||||||
// If we have not already started to play audio, start.
|
// If we have not already started to play audio, start.
|
||||||
|
|
|
@ -14,6 +14,7 @@ import net.osmand.PlatformUtil;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.SettingsActivity;
|
import net.osmand.plus.activities.SettingsActivity;
|
||||||
|
import net.osmand.plus.routing.VoiceRouter;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -69,10 +70,12 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
||||||
private TextToSpeech mTts;
|
private TextToSpeech mTts;
|
||||||
private Context mTtsContext;
|
private Context mTtsContext;
|
||||||
private HashMap<String, String> params = new HashMap<String, String>();
|
private HashMap<String, String> params = new HashMap<String, String>();
|
||||||
|
private VoiceRouter vrt;
|
||||||
|
|
||||||
protected TTSCommandPlayerImpl(Activity ctx, String voiceProvider)
|
public TTSCommandPlayerImpl(Activity ctx, VoiceRouter vrt, String voiceProvider)
|
||||||
throws CommandPlayerException {
|
throws CommandPlayerException {
|
||||||
super((OsmandApplication) ctx.getApplicationContext(), voiceProvider, CONFIG_FILE, TTS_VOICE_VERSION);
|
super((OsmandApplication) ctx.getApplicationContext(), voiceProvider, CONFIG_FILE, TTS_VOICE_VERSION);
|
||||||
|
this.vrt = vrt;
|
||||||
if (Algorithms.isEmpty(language)) {
|
if (Algorithms.isEmpty(language)) {
|
||||||
throw new CommandPlayerException(
|
throw new CommandPlayerException(
|
||||||
ctx.getString(R.string.voice_data_corrupted));
|
ctx.getString(R.string.voice_data_corrupted));
|
||||||
|
@ -100,17 +103,16 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
||||||
// Called from the calculating route thread.
|
// Called from the calculating route thread.
|
||||||
@Override
|
@Override
|
||||||
public synchronized void playCommands(CommandBuilder builder) {
|
public synchronized void playCommands(CommandBuilder builder) {
|
||||||
if (mTts != null) {
|
final List<String> execute = builder.execute(); //list of strings, the speech text, play it
|
||||||
final List<String> execute = builder.execute(); //list of strings, the speech text, play it
|
StringBuilder bld = new StringBuilder();
|
||||||
StringBuilder bld = new StringBuilder();
|
for (String s : execute) {
|
||||||
for (String s : execute) {
|
bld.append(s).append(' ');
|
||||||
bld.append(s).append(' ');
|
}
|
||||||
}
|
sendAlertToPebble(bld.toString());
|
||||||
|
if (mTts != null && !vrt.isMute()) {
|
||||||
if (ttsRequests++ == 0)
|
if (ttsRequests++ == 0)
|
||||||
requestAudioFocus();
|
requestAudioFocus();
|
||||||
log.debug("ttsRequests="+ttsRequests);
|
log.debug("ttsRequests="+ttsRequests);
|
||||||
sendAlertToPebble(bld.toString());
|
|
||||||
|
|
||||||
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis());
|
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis());
|
||||||
mTts.speak(bld.toString(), TextToSpeech.QUEUE_ADD, params);
|
mTts.speak(bld.toString(), TextToSpeech.QUEUE_ADD, params);
|
||||||
// Audio focus will be released when onUtteranceCompleted() completed is called by the TTS engine.
|
// Audio focus will be released when onUtteranceCompleted() completed is called by the TTS engine.
|
||||||
|
|
Loading…
Reference in a new issue