Fix #3558
This commit is contained in:
parent
6d9d50b81d
commit
3512b82f9b
20 changed files with 174 additions and 144 deletions
|
@ -11,9 +11,6 @@
|
||||||
<ListPreference android:key="coordinates_format" android:title="@string/coords_format" android:summary="@string/coords_format_descr"></ListPreference>
|
<ListPreference android:key="coordinates_format" android:title="@string/coords_format" android:summary="@string/coords_format_descr"></ListPreference>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory android:title="@string/voice_pref_title" android:key="voice">
|
|
||||||
<ListPreference android:title="@string/voice_provider" android:key="voice_provider" android:summary="@string/voice_provider_descr"></ListPreference>
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/misc_pref_title" android:key="misc">
|
<PreferenceCategory android:title="@string/misc_pref_title" android:key="misc">
|
||||||
<ListPreference android:key="osmand_theme" android:title="@string/choose_osmand_theme" android:summary="@string/choose_osmand_theme_descr"></ListPreference>
|
<ListPreference android:key="osmand_theme" android:title="@string/choose_osmand_theme" android:summary="@string/choose_osmand_theme_descr"></ListPreference>
|
||||||
|
|
|
@ -47,4 +47,9 @@
|
||||||
android:summary="@string/delay_to_start_navigation_descr" />
|
android:summary="@string/delay_to_start_navigation_descr" />
|
||||||
-->
|
-->
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory android:title="@string/voice_pref_title" android:key="voice">
|
||||||
|
<ListPreference android:title="@string/voice_provider" android:key="voice_provider" android:summary="@string/voice_provider_descr"></ListPreference>
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
|
@ -439,12 +439,18 @@ public class AppInitializer implements IProgress {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public synchronized void initVoiceDataInDifferentThread(final Activity uiContext, final String voiceProvider, final Runnable run, boolean showDialog) {
|
public synchronized void initVoiceDataInDifferentThread(final Activity uiContext,
|
||||||
|
final ApplicationMode applicationMode,
|
||||||
|
final String voiceProvider,
|
||||||
|
final Runnable run,
|
||||||
|
boolean showDialog) {
|
||||||
|
|
||||||
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)
|
public CommandPlayer createCommandPlayer(String voiceProvider, ApplicationMode applicationMode,
|
||||||
|
OsmandApplication osmandApplication, Activity ctx)
|
||||||
throws CommandPlayerException {
|
throws CommandPlayerException {
|
||||||
if (voiceProvider != null) {
|
if (voiceProvider != null) {
|
||||||
File parent = osmandApplication.getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
File parent = osmandApplication.getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||||
|
@ -454,9 +460,9 @@ public class AppInitializer implements IProgress {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MediaCommandPlayerImpl.isMyData(voiceDir)) {
|
if (MediaCommandPlayerImpl.isMyData(voiceDir)) {
|
||||||
return new MediaCommandPlayerImpl(osmandApplication, osmandApplication.getRoutingHelper().getVoiceRouter(), voiceProvider);
|
return new MediaCommandPlayerImpl(osmandApplication, applicationMode, osmandApplication.getRoutingHelper().getVoiceRouter(), voiceProvider);
|
||||||
} else if (TTSCommandPlayerImpl.isMyData(voiceDir)) {
|
} else if (TTSCommandPlayerImpl.isMyData(voiceDir)) {
|
||||||
return new TTSCommandPlayerImpl(ctx, osmandApplication.getRoutingHelper().getVoiceRouter(), voiceProvider);
|
return new TTSCommandPlayerImpl(ctx, applicationMode, osmandApplication.getRoutingHelper().getVoiceRouter(), voiceProvider);
|
||||||
}
|
}
|
||||||
throw new CommandPlayerException(ctx.getString(R.string.voice_data_not_supported));
|
throw new CommandPlayerException(ctx.getString(R.string.voice_data_not_supported));
|
||||||
}
|
}
|
||||||
|
@ -468,7 +474,7 @@ public class AppInitializer implements IProgress {
|
||||||
if (app.player != null) {
|
if (app.player != null) {
|
||||||
app.player.clear();
|
app.player.clear();
|
||||||
}
|
}
|
||||||
app.player = createCommandPlayer(voiceProvider, app, uiContext);
|
app.player = createCommandPlayer(voiceProvider, applicationMode, app, uiContext);
|
||||||
app.getRoutingHelper().getVoiceRouter().setPlayer(app.player);
|
app.getRoutingHelper().getVoiceRouter().setPlayer(app.player);
|
||||||
if(dlg != null) {
|
if(dlg != null) {
|
||||||
dlg.dismiss();
|
dlg.dismiss();
|
||||||
|
|
|
@ -386,8 +386,9 @@ public class OsmandApplication extends MultiDexApplication {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initVoiceCommandPlayer(final Activity uiContext, boolean warningNoneProvider, Runnable run, boolean showDialog, boolean force) {
|
public void initVoiceCommandPlayer(final Activity uiContext, ApplicationMode applicationMode,
|
||||||
String voiceProvider = osmandSettings.VOICE_PROVIDER.get();
|
boolean warningNoneProvider, Runnable run, boolean showDialog, boolean force) {
|
||||||
|
String voiceProvider = osmandSettings.VOICE_PROVIDER.getModeValue(applicationMode);
|
||||||
if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
|
if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
|
||||||
if (warningNoneProvider && voiceProvider == null) {
|
if (warningNoneProvider && voiceProvider == null) {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(uiContext);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(uiContext);
|
||||||
|
@ -435,7 +436,7 @@ public class OsmandApplication extends MultiDexApplication {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (player == null || !Algorithms.objectEquals(voiceProvider, player.getCurrentVoice()) || force) {
|
if (player == null || !Algorithms.objectEquals(voiceProvider, player.getCurrentVoice()) || force) {
|
||||||
appInitializer.initVoiceDataInDifferentThread(uiContext, voiceProvider, run, showDialog);
|
appInitializer.initVoiceDataInDifferentThread(uiContext, applicationMode, voiceProvider, run, showDialog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -990,7 +990,7 @@ public class OsmandSettings {
|
||||||
SNAP_TO_ROAD.setModeDefaultValue(ApplicationMode.BICYCLE, true);
|
SNAP_TO_ROAD.setModeDefaultValue(ApplicationMode.BICYCLE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final CommonPreference<Boolean> INTERRUPT_MUSIC = new BooleanPreference("interrupt_music", false).makeGlobal();
|
public final CommonPreference<Boolean> INTERRUPT_MUSIC = new BooleanPreference("interrupt_music", false).makeProfile();
|
||||||
|
|
||||||
public final CommonPreference<String> PROXY_HOST = new StringPreference("proxy_host", "127.0.0.1").makeGlobal();
|
public final CommonPreference<String> PROXY_HOST = new StringPreference("proxy_host", "127.0.0.1").makeGlobal();
|
||||||
public final CommonPreference<Integer> PROXY_PORT = new IntPreference("proxy_port", 8118).makeGlobal();
|
public final CommonPreference<Integer> PROXY_PORT = new IntPreference("proxy_port", 8118).makeGlobal();
|
||||||
|
@ -1230,7 +1230,7 @@ public class OsmandSettings {
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
public final OsmandPreference<Integer> AUDIO_STREAM_GUIDANCE = new IntPreference("audio_stream",
|
public final OsmandPreference<Integer> AUDIO_STREAM_GUIDANCE = new IntPreference("audio_stream",
|
||||||
3/*AudioManager.STREAM_MUSIC*/).makeGlobal();
|
3/*AudioManager.STREAM_MUSIC*/).makeProfile();
|
||||||
|
|
||||||
// For now this can be changed only in TestVoiceActivity
|
// For now this can be changed only in TestVoiceActivity
|
||||||
public final OsmandPreference<Integer> BT_SCO_DELAY = new IntPreference("bt_sco_delay", 1500).makeGlobal().cache();
|
public final OsmandPreference<Integer> BT_SCO_DELAY = new IntPreference("bt_sco_delay", 1500).makeGlobal().cache();
|
||||||
|
@ -2675,7 +2675,7 @@ public class OsmandSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
;
|
||||||
}.makeGlobal();
|
}.makeProfile();
|
||||||
|
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
|
|
|
@ -511,8 +511,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
|
|
||||||
app.getLocationProvider().checkIfLastKnownLocationIsValid();
|
app.getLocationProvider().checkIfLastKnownLocationIsValid();
|
||||||
// for voice navigation
|
// for voice navigation
|
||||||
if (settings.AUDIO_STREAM_GUIDANCE.get() != null) {
|
ApplicationMode routingAppMode = getRoutingHelper().getAppMode();
|
||||||
setVolumeControlStream(settings.AUDIO_STREAM_GUIDANCE.get());
|
if (routingAppMode != null && settings.AUDIO_STREAM_GUIDANCE.getModeValue(routingAppMode) != null) {
|
||||||
|
setVolumeControlStream(settings.AUDIO_STREAM_GUIDANCE.getModeValue(routingAppMode));
|
||||||
} else {
|
} else {
|
||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,7 +441,7 @@ public class MapActivityActions implements DialogProvider {
|
||||||
ApplicationMode mode = getRouteMode(from);
|
ApplicationMode mode = getRouteMode(from);
|
||||||
//app.getSettings().APPLICATION_MODE.set(mode);
|
//app.getSettings().APPLICATION_MODE.set(mode);
|
||||||
app.getRoutingHelper().setAppMode(mode);
|
app.getRoutingHelper().setAppMode(mode);
|
||||||
app.initVoiceCommandPlayer(mapActivity, true, null, false, false);
|
app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false);
|
||||||
// save application mode controls
|
// save application mode controls
|
||||||
settings.FOLLOW_THE_ROUTE.set(false);
|
settings.FOLLOW_THE_ROUTE.set(false);
|
||||||
app.getRoutingHelper().setFollowingMode(false);
|
app.getRoutingHelper().setFollowingMode(false);
|
||||||
|
|
|
@ -4,11 +4,9 @@ package net.osmand.plus.activities;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.media.AudioManager;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -49,23 +47,17 @@ import net.osmand.plus.dashboard.DashChooseAppDirFragment.ChooseAppDirFragment;
|
||||||
import net.osmand.plus.dashboard.DashChooseAppDirFragment.MoveFilesToDifferentDirectory;
|
import net.osmand.plus.dashboard.DashChooseAppDirFragment.MoveFilesToDifferentDirectory;
|
||||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||||
import net.osmand.plus.download.DownloadActivity;
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
import net.osmand.plus.download.DownloadActivityType;
|
|
||||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
|
||||||
import net.osmand.plus.render.NativeOsmandLibrary;
|
import net.osmand.plus.render.NativeOsmandLibrary;
|
||||||
import net.osmand.plus.voice.CommandPlayer;
|
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
|
|
||||||
public class SettingsGeneralActivity extends SettingsBaseActivity implements OnRequestPermissionsResultCallback {
|
public class SettingsGeneralActivity extends SettingsBaseActivity implements OnRequestPermissionsResultCallback {
|
||||||
|
|
||||||
public static final String MORE_VALUE = "MORE_VALUE";
|
|
||||||
private Preference applicationDir;
|
private Preference applicationDir;
|
||||||
private ListPreference applicationModePreference;
|
private ListPreference applicationModePreference;
|
||||||
private Preference drivingRegionPreference;
|
private Preference drivingRegionPreference;
|
||||||
|
@ -104,7 +96,6 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
|
||||||
drivingRegionPreference = screen.findPreference(settings.DRIVING_REGION.getId());
|
drivingRegionPreference = screen.findPreference(settings.DRIVING_REGION.getId());
|
||||||
|
|
||||||
addLocalPrefs((PreferenceGroup) screen.findPreference("localization"));
|
addLocalPrefs((PreferenceGroup) screen.findPreference("localization"));
|
||||||
addVoicePrefs((PreferenceGroup) screen.findPreference("voice"));
|
|
||||||
addProxyPrefs((PreferenceGroup) screen.findPreference("proxy"));
|
addProxyPrefs((PreferenceGroup) screen.findPreference("proxy"));
|
||||||
addMiscPreferences((PreferenceGroup) screen.findPreference("misc"));
|
addMiscPreferences((PreferenceGroup) screen.findPreference("misc"));
|
||||||
|
|
||||||
|
@ -112,35 +103,6 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
|
||||||
applicationModePreference.setOnPreferenceChangeListener(this);
|
applicationModePreference.setOnPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addVoicePrefs(PreferenceGroup cat) {
|
|
||||||
if (!Version.isBlackberry((OsmandApplication) getApplication())) {
|
|
||||||
ListPreference lp = createListPreference(
|
|
||||||
settings.AUDIO_STREAM_GUIDANCE,
|
|
||||||
new String[]{getString(R.string.voice_stream_music), getString(R.string.voice_stream_notification),
|
|
||||||
getString(R.string.voice_stream_voice_call)}, new Integer[]{AudioManager.STREAM_MUSIC,
|
|
||||||
AudioManager.STREAM_NOTIFICATION, AudioManager.STREAM_VOICE_CALL}, R.string.choose_audio_stream,
|
|
||||||
R.string.choose_audio_stream_descr);
|
|
||||||
final OnPreferenceChangeListener prev = lp.getOnPreferenceChangeListener();
|
|
||||||
lp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
prev.onPreferenceChange(preference, newValue);
|
|
||||||
CommandPlayer player = getMyApplication().getPlayer();
|
|
||||||
if (player != null) {
|
|
||||||
player.updateAudioStream(settings.AUDIO_STREAM_GUIDANCE.get());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
cat.addPreference(lp);
|
|
||||||
cat.addPreference(createCheckBoxPreference(settings.INTERRUPT_MUSIC, R.string.interrupt_music,
|
|
||||||
R.string.interrupt_music_descr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void addLocalPrefs(PreferenceGroup screen) {
|
private void addLocalPrefs(PreferenceGroup screen) {
|
||||||
drivingRegionPreference.setTitle(R.string.driving_region);
|
drivingRegionPreference.setTitle(R.string.driving_region);
|
||||||
drivingRegionPreference.setSummary(R.string.driving_region_descr);
|
drivingRegionPreference.setSummary(R.string.driving_region_descr);
|
||||||
|
@ -524,7 +486,6 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAllSettings() {
|
public void updateAllSettings() {
|
||||||
reloadVoiceListPreference(getPreferenceScreen());
|
|
||||||
super.updateAllSettings();
|
super.updateAllSettings();
|
||||||
updateApplicationDirTextAndSummary();
|
updateApplicationDirTextAndSummary();
|
||||||
applicationModePreference.setTitle(getString(R.string.settings_preset) + " ["
|
applicationModePreference.setTitle(getString(R.string.settings_preset) + " ["
|
||||||
|
@ -536,19 +497,6 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
String id = preference.getKey();
|
String id = preference.getKey();
|
||||||
if (id.equals(settings.VOICE_PROVIDER.getId())) {
|
|
||||||
if (MORE_VALUE.equals(newValue)) {
|
|
||||||
// listPref.set(oldValue); // revert the change..
|
|
||||||
final Intent intent = new Intent(this, DownloadActivity.class);
|
|
||||||
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
|
|
||||||
intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag());
|
|
||||||
startActivity(intent);
|
|
||||||
} else {
|
|
||||||
super.onPreferenceChange(preference, newValue);
|
|
||||||
getMyApplication().initVoiceCommandPlayer(this, false, null, true, false);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
super.onPreferenceChange(preference, newValue);
|
super.onPreferenceChange(preference, newValue);
|
||||||
if (id.equals(settings.SAFE_MODE.getId())) {
|
if (id.equals(settings.SAFE_MODE.getId())) {
|
||||||
if ((Boolean) newValue) {
|
if ((Boolean) newValue) {
|
||||||
|
@ -710,43 +658,6 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void reloadVoiceListPreference(PreferenceScreen screen) {
|
|
||||||
String[] entries;
|
|
||||||
String[] entrieValues;
|
|
||||||
Set<String> voiceFiles = getVoiceFiles();
|
|
||||||
entries = new String[voiceFiles.size() + 2];
|
|
||||||
entrieValues = new String[voiceFiles.size() + 2];
|
|
||||||
int k = 0;
|
|
||||||
// entries[k++] = getString(R.string.shared_string_none);
|
|
||||||
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
|
|
||||||
entries[k++] = getString(R.string.shared_string_do_not_use);
|
|
||||||
for (String s : voiceFiles) {
|
|
||||||
entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) + " " : "") +
|
|
||||||
FileNameTranslationHelper.getVoiceName(this, s);
|
|
||||||
entrieValues[k] = s;
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
entrieValues[k] = MORE_VALUE;
|
|
||||||
entries[k] = getString(R.string.install_more);
|
|
||||||
registerListPreference(settings.VOICE_PROVIDER, screen, entries, entrieValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private Set<String> getVoiceFiles() {
|
|
||||||
// read available voice data
|
|
||||||
File extStorage = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
|
||||||
Set<String> setFiles = new LinkedHashSet<String>();
|
|
||||||
if (extStorage.exists()) {
|
|
||||||
for (File f : extStorage.listFiles()) {
|
|
||||||
if (f.isDirectory()) {
|
|
||||||
setFiles.add(f.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return setFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
|
@ -7,11 +7,13 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnMultiChoiceClickListener;
|
import android.content.DialogInterface.OnMultiChoiceClickListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.media.AudioManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
|
import android.preference.PreferenceGroup;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
@ -21,6 +23,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.plus.ContextMenuItem;
|
import net.osmand.plus.ContextMenuItem;
|
||||||
|
@ -32,18 +35,27 @@ import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
import net.osmand.plus.OsmandSettings.SpeedConstants;
|
import net.osmand.plus.OsmandSettings.SpeedConstants;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.Version;
|
import net.osmand.plus.Version;
|
||||||
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
|
import net.osmand.plus.download.DownloadActivityType;
|
||||||
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||||
|
import net.osmand.plus.voice.CommandPlayer;
|
||||||
import net.osmand.router.GeneralRouter;
|
import net.osmand.router.GeneralRouter;
|
||||||
import net.osmand.router.GeneralRouter.RoutingParameter;
|
import net.osmand.router.GeneralRouter.RoutingParameter;
|
||||||
import net.osmand.router.GeneralRouter.RoutingParameterType;
|
import net.osmand.router.GeneralRouter.RoutingParameterType;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class SettingsNavigationActivity extends SettingsBaseActivity {
|
public class SettingsNavigationActivity extends SettingsBaseActivity {
|
||||||
|
|
||||||
|
public static final String MORE_VALUE = "MORE_VALUE";
|
||||||
|
|
||||||
private Preference avoidRouting;
|
private Preference avoidRouting;
|
||||||
private Preference preferRouting;
|
private Preference preferRouting;
|
||||||
private Preference reliefFactorRouting;
|
private Preference reliefFactorRouting;
|
||||||
|
@ -223,8 +235,72 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
||||||
} else {
|
} else {
|
||||||
profileDialog();
|
profileDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addVoicePrefs((PreferenceGroup) screen.findPreference("voice"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void reloadVoiceListPreference(PreferenceScreen screen) {
|
||||||
|
String[] entries;
|
||||||
|
String[] entrieValues;
|
||||||
|
Set<String> voiceFiles = getVoiceFiles();
|
||||||
|
entries = new String[voiceFiles.size() + 2];
|
||||||
|
entrieValues = new String[voiceFiles.size() + 2];
|
||||||
|
int k = 0;
|
||||||
|
// entries[k++] = getString(R.string.shared_string_none);
|
||||||
|
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
|
||||||
|
entries[k++] = getString(R.string.shared_string_do_not_use);
|
||||||
|
for (String s : voiceFiles) {
|
||||||
|
entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) + " " : "") +
|
||||||
|
FileNameTranslationHelper.getVoiceName(this, s);
|
||||||
|
entrieValues[k] = s;
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
entrieValues[k] = MORE_VALUE;
|
||||||
|
entries[k] = getString(R.string.install_more);
|
||||||
|
registerListPreference(settings.VOICE_PROVIDER, screen, entries, entrieValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Set<String> getVoiceFiles() {
|
||||||
|
// read available voice data
|
||||||
|
File extStorage = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||||
|
Set<String> setFiles = new LinkedHashSet<String>();
|
||||||
|
if (extStorage.exists()) {
|
||||||
|
for (File f : extStorage.listFiles()) {
|
||||||
|
if (f.isDirectory()) {
|
||||||
|
setFiles.add(f.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return setFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addVoicePrefs(PreferenceGroup cat) {
|
||||||
|
if (!Version.isBlackberry((OsmandApplication) getApplication())) {
|
||||||
|
ListPreference lp = createListPreference(
|
||||||
|
settings.AUDIO_STREAM_GUIDANCE,
|
||||||
|
new String[]{getString(R.string.voice_stream_music), getString(R.string.voice_stream_notification),
|
||||||
|
getString(R.string.voice_stream_voice_call)}, new Integer[]{AudioManager.STREAM_MUSIC,
|
||||||
|
AudioManager.STREAM_NOTIFICATION, AudioManager.STREAM_VOICE_CALL}, R.string.choose_audio_stream,
|
||||||
|
R.string.choose_audio_stream_descr);
|
||||||
|
final Preference.OnPreferenceChangeListener prev = lp.getOnPreferenceChangeListener();
|
||||||
|
lp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
prev.onPreferenceChange(preference, newValue);
|
||||||
|
CommandPlayer player = getMyApplication().getPlayer();
|
||||||
|
if (player != null) {
|
||||||
|
player.updateAudioStream(settings.AUDIO_STREAM_GUIDANCE.get());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
cat.addPreference(lp);
|
||||||
|
cat.addPreference(createCheckBoxPreference(settings.INTERRUPT_MUSIC, R.string.interrupt_music,
|
||||||
|
R.string.interrupt_music_descr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void prepareRoutingPrefs(PreferenceScreen screen) {
|
private void prepareRoutingPrefs(PreferenceScreen screen) {
|
||||||
PreferenceCategory cat = (PreferenceCategory) screen.findPreference("routing_preferences");
|
PreferenceCategory cat = (PreferenceCategory) screen.findPreference("routing_preferences");
|
||||||
|
@ -350,12 +426,9 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void updateAllSettings() {
|
public void updateAllSettings() {
|
||||||
prepareRoutingPrefs(getPreferenceScreen());
|
prepareRoutingPrefs(getPreferenceScreen());
|
||||||
|
reloadVoiceListPreference(getPreferenceScreen());
|
||||||
super.updateAllSettings();
|
super.updateAllSettings();
|
||||||
routerServicePreference.setSummary(getString(R.string.router_service_descr) + " [" + settings.ROUTER_SERVICE.get() + "]");
|
routerServicePreference.setSummary(getString(R.string.router_service_descr) + " [" + settings.ROUTER_SERVICE.get() + "]");
|
||||||
}
|
}
|
||||||
|
@ -363,6 +436,20 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
String id = preference.getKey();
|
String id = preference.getKey();
|
||||||
|
if (id.equals(settings.VOICE_PROVIDER.getId())) {
|
||||||
|
if (MORE_VALUE.equals(newValue)) {
|
||||||
|
// listPref.set(oldValue); // revert the change..
|
||||||
|
final Intent intent = new Intent(this, DownloadActivity.class);
|
||||||
|
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
|
||||||
|
intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag());
|
||||||
|
startActivity(intent);
|
||||||
|
} else {
|
||||||
|
super.onPreferenceChange(preference, newValue);
|
||||||
|
getMyApplication().initVoiceCommandPlayer(
|
||||||
|
this, settings.APPLICATION_MODE.get(), false, null, true, false);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
super.onPreferenceChange(preference, newValue);
|
super.onPreferenceChange(preference, newValue);
|
||||||
if (id.equals(settings.ROUTER_SERVICE.getId())) {
|
if (id.equals(settings.ROUTER_SERVICE.getId())) {
|
||||||
routerServicePreference.setSummary(getString(R.string.router_service_descr) + " ["
|
routerServicePreference.setSummary(getString(R.string.router_service_descr) + " ["
|
||||||
|
|
|
@ -2,12 +2,14 @@ package net.osmand.plus.api;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import net.osmand.plus.ApplicationMode;
|
||||||
|
|
||||||
public interface AudioFocusHelper {
|
public interface AudioFocusHelper {
|
||||||
|
|
||||||
boolean requestFocus(Context context, int streamType);
|
boolean requestFocus(Context context, ApplicationMode applicationMode, int streamType);
|
||||||
|
|
||||||
void onAudioFocusChange(int focusChange);
|
void onAudioFocusChange(int focusChange);
|
||||||
|
|
||||||
boolean abandonFocus(Context context, int streamType);
|
boolean abandonFocus(Context context, ApplicationMode applicationMode, int streamType);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.api;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
|
||||||
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
@ -19,16 +20,16 @@ public class AudioFocusHelperImpl implements AudioManager.OnAudioFocusChangeList
|
||||||
private static final Log log = PlatformUtil.getLog(AudioFocusHelperImpl.class);
|
private static final Log log = PlatformUtil.getLog(AudioFocusHelperImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean requestFocus(Context context, int streamType) {
|
public boolean requestFocus(Context context, ApplicationMode applicationMode, int streamType) {
|
||||||
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.requestAudioFocus(this, streamType,
|
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.requestAudioFocus(this, streamType,
|
||||||
((OsmandApplication) context.getApplicationContext()).getSettings().INTERRUPT_MUSIC.get()?
|
((OsmandApplication) context.getApplicationContext()).getSettings().INTERRUPT_MUSIC.getModeValue(applicationMode)?
|
||||||
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
|
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
|
||||||
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK );
|
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean abandonFocus(Context context, int streamType)
|
public boolean abandonFocus(Context context, ApplicationMode applicationMode, int streamType)
|
||||||
{
|
{
|
||||||
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.abandonAudioFocus(this);
|
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.abandonAudioFocus(this);
|
||||||
|
|
|
@ -173,7 +173,7 @@ public class FailSafeFuntions {
|
||||||
app.getSettings().FOLLOW_THE_ROUTE.set(true);
|
app.getSettings().FOLLOW_THE_ROUTE.set(true);
|
||||||
routingHelper.setFollowingMode(true);
|
routingHelper.setFollowingMode(true);
|
||||||
app.getTargetPointsHelper().updateRouteAndRefresh(true);
|
app.getTargetPointsHelper().updateRouteAndRefresh(true);
|
||||||
app.initVoiceCommandPlayer(ma, true, null, false, false);
|
app.initVoiceCommandPlayer(ma, routingHelper.getAppMode(), true, null, false, false);
|
||||||
if(ma.getDashboard().isVisible()) {
|
if(ma.getDashboard().isVisible()) {
|
||||||
ma.getDashboard().hideDashboard();
|
ma.getDashboard().hideDashboard();
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,8 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
|
||||||
final OsmandApplication app = (OsmandApplication) getApplication();
|
final OsmandApplication app = (OsmandApplication) getApplication();
|
||||||
getSupportActionBar().setTitle(app.getString(R.string.test_voice_prompts) + " (" + entrieValues[which] + ")");
|
getSupportActionBar().setTitle(app.getString(R.string.test_voice_prompts) + " (" + entrieValues[which] + ")");
|
||||||
app.getSettings().VOICE_PROVIDER.set(entrieValues[which]);
|
app.getSettings().VOICE_PROVIDER.set(entrieValues[which]);
|
||||||
app.initVoiceCommandPlayer(TestVoiceActivity.this, true, new Runnable() {
|
app.initVoiceCommandPlayer(TestVoiceActivity.this,
|
||||||
|
app.getSettings().APPLICATION_MODE.get(), true, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.map.WorldRegion;
|
import net.osmand.map.WorldRegion;
|
||||||
import net.osmand.map.WorldRegion.RegionParams;
|
import net.osmand.map.WorldRegion.RegionParams;
|
||||||
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
|
@ -155,7 +156,7 @@ public class DownloadIndexesThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initSettingsFirstMap(WorldRegion reg) {
|
public void initSettingsFirstMap(WorldRegion reg) {
|
||||||
if(app.getSettings().FIRST_MAP_IS_DOWNLOADED.get() || reg == null) {
|
if (app.getSettings().FIRST_MAP_IS_DOWNLOADED.get() || reg == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
app.getSettings().FIRST_MAP_IS_DOWNLOADED.set(true);
|
app.getSettings().FIRST_MAP_IS_DOWNLOADED.set(true);
|
||||||
|
@ -176,7 +177,10 @@ public class DownloadIndexesThread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (setTts != null) {
|
if (setTts != null) {
|
||||||
app.getSettings().VOICE_PROVIDER.set(setTts);
|
List<ApplicationMode> modes = ApplicationMode.allPossibleValues();
|
||||||
|
for (ApplicationMode mode : modes) {
|
||||||
|
app.getSettings().VOICE_PROVIDER.setModeValue(mode, setTts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,6 +251,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
||||||
//updateMenu();
|
//updateMenu();
|
||||||
}
|
}
|
||||||
routingHelper.setAppMode(next);
|
routingHelper.setAppMode(next);
|
||||||
|
mapActivity.getMyApplication().initVoiceCommandPlayer(mapActivity, next, true, null, false, false);
|
||||||
routingHelper.recalculateRouteDueToSettingsChange();
|
routingHelper.recalculateRouteDueToSettingsChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,7 +269,8 @@ public class RoutePreferencesMenu {
|
||||||
entrieValues = new String[voiceFiles.size() + 2];
|
entrieValues = new String[voiceFiles.size() + 2];
|
||||||
int k = 0;
|
int k = 0;
|
||||||
int selected = -1;
|
int selected = -1;
|
||||||
String selectedValue = mapActivity.getMyApplication().getSettings().VOICE_PROVIDER.get();
|
String selectedValue = mapActivity.getMyApplication().getSettings().VOICE_PROVIDER.getModeValue(
|
||||||
|
mapActivity.getMyApplication().getRoutingHelper().getAppMode());
|
||||||
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
|
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
|
||||||
entries[k] = mapActivity.getResources().getString(R.string.shared_string_do_not_use);
|
entries[k] = mapActivity.getResources().getString(R.string.shared_string_do_not_use);
|
||||||
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder();
|
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder();
|
||||||
|
@ -324,8 +325,10 @@ public class RoutePreferencesMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void applyVoiceProvider(MapActivity mapActivity, String provider) {
|
public static void applyVoiceProvider(MapActivity mapActivity, String provider) {
|
||||||
mapActivity.getMyApplication().getSettings().VOICE_PROVIDER.set(provider);
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
mapActivity.getMyApplication().initVoiceCommandPlayer(mapActivity, false, null, true, false);
|
ApplicationMode applicationMode = app.getRoutingHelper().getAppMode();
|
||||||
|
app.getSettings().VOICE_PROVIDER.setModeValue(applicationMode, provider);
|
||||||
|
app.initVoiceCommandPlayer(mapActivity, applicationMode, false, null, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<String> getVoiceFiles(MapActivity mapActivity) {
|
private static Set<String> getVoiceFiles(MapActivity mapActivity) {
|
||||||
|
@ -502,7 +505,7 @@ public class RoutePreferencesMenu {
|
||||||
v.findViewById(R.id.toggle_item).setVisibility(View.GONE);
|
v.findViewById(R.id.toggle_item).setVisibility(View.GONE);
|
||||||
final TextView btn = (TextView) v.findViewById(R.id.select_button);
|
final TextView btn = (TextView) v.findViewById(R.id.select_button);
|
||||||
btn.setTextColor(btn.getLinkTextColors());
|
btn.setTextColor(btn.getLinkTextColors());
|
||||||
String voiceProvider = settings.VOICE_PROVIDER.get();
|
String voiceProvider = settings.VOICE_PROVIDER.getModeValue(routingHelper.getAppMode());
|
||||||
String voiceProviderStr;
|
String voiceProviderStr;
|
||||||
if (voiceProvider != null) {
|
if (voiceProvider != null) {
|
||||||
if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
|
if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class VoiceRouter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger close prompts earlier if delayed for BT SCO connection establishment
|
// Trigger close prompts earlier if delayed for BT SCO connection establishment
|
||||||
if ((settings.AUDIO_STREAM_GUIDANCE.get() == 0) && !AbstractPrologCommandPlayer.btScoStatus) {
|
if ((settings.AUDIO_STREAM_GUIDANCE.getModeValue(router.getAppMode()) == 0) && !AbstractPrologCommandPlayer.btScoStatus) {
|
||||||
btScoDelayDistance = currentSpeed * (double) settings.BT_SCO_DELAY.get() / 1000;
|
btScoDelayDistance = currentSpeed * (double) settings.BT_SCO_DELAY.get() / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,12 +65,15 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
|
||||||
protected String language = "";
|
protected String language = "";
|
||||||
protected int streamType;
|
protected int streamType;
|
||||||
private static int currentVersion;
|
private static int currentVersion;
|
||||||
|
private ApplicationMode applicationMode;
|
||||||
|
|
||||||
|
|
||||||
protected AbstractPrologCommandPlayer(OsmandApplication ctx, String voiceProvider, String configFile, int[] sortedVoiceVersions)
|
protected AbstractPrologCommandPlayer(OsmandApplication ctx, ApplicationMode applicationMode,
|
||||||
|
String voiceProvider, String configFile, int[] sortedVoiceVersions)
|
||||||
throws CommandPlayerException {
|
throws CommandPlayerException {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.sortedVoiceVersions = sortedVoiceVersions;
|
this.sortedVoiceVersions = sortedVoiceVersions;
|
||||||
|
this.applicationMode = applicationMode;
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
|
@ -82,7 +85,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
|
||||||
if (log.isInfoEnabled()) {
|
if (log.isInfoEnabled()) {
|
||||||
log.info("Initializing prolog system : " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
|
log.info("Initializing prolog system : " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
this.streamType = ctx.getSettings().AUDIO_STREAM_GUIDANCE.get();
|
this.streamType = ctx.getSettings().AUDIO_STREAM_GUIDANCE.getModeValue(applicationMode);
|
||||||
init(voiceProvider, ctx.getSettings(), configFile);
|
init(voiceProvider, ctx.getSettings(), configFile);
|
||||||
final Term langVal = solveSimplePredicate("language");
|
final Term langVal = solveSimplePredicate("language");
|
||||||
if (langVal instanceof Struct) {
|
if (langVal instanceof Struct) {
|
||||||
|
@ -90,6 +93,10 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ApplicationMode getApplicationMode() {
|
||||||
|
return applicationMode;
|
||||||
|
}
|
||||||
|
|
||||||
public String getLanguage() {
|
public String getLanguage() {
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
@ -277,9 +284,9 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
|
||||||
mAudioFocusHelper = getAudioFocus();
|
mAudioFocusHelper = getAudioFocus();
|
||||||
}
|
}
|
||||||
if (mAudioFocusHelper != null && ctx != null) {
|
if (mAudioFocusHelper != null && ctx != null) {
|
||||||
boolean audioFocusGranted = mAudioFocusHelper.requestFocus(ctx, streamType);
|
boolean audioFocusGranted = mAudioFocusHelper.requestFocus(ctx, applicationMode, streamType);
|
||||||
// If AudioManager.STREAM_VOICE_CALL try using BT SCO:
|
// If AudioManager.STREAM_VOICE_CALL try using BT SCO:
|
||||||
if (audioFocusGranted && ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) {
|
if (audioFocusGranted && ctx.getSettings().AUDIO_STREAM_GUIDANCE.getModeValue(applicationMode) == 0) {
|
||||||
toggleBtSco(true);
|
toggleBtSco(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,11 +303,11 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
|
||||||
|
|
||||||
protected synchronized void abandonAudioFocus() {
|
protected synchronized void abandonAudioFocus() {
|
||||||
log.debug("abandonAudioFocus");
|
log.debug("abandonAudioFocus");
|
||||||
if ((ctx != null && ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) || (btScoStatus == true)) {
|
if ((ctx != null && ctx.getSettings().AUDIO_STREAM_GUIDANCE.getModeValue(applicationMode) == 0) || (btScoStatus == true)) {
|
||||||
toggleBtSco(false);
|
toggleBtSco(false);
|
||||||
}
|
}
|
||||||
if (ctx != null && mAudioFocusHelper != null) {
|
if (ctx != null && mAudioFocusHelper != null) {
|
||||||
mAudioFocusHelper.abandonFocus(ctx, streamType);
|
mAudioFocusHelper.abandonFocus(ctx, applicationMode, streamType);
|
||||||
}
|
}
|
||||||
mAudioFocusHelper = null;
|
mAudioFocusHelper = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package net.osmand.plus.voice;
|
package net.osmand.plus.voice;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import android.media.MediaPlayer;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.routing.VoiceRouter;
|
import net.osmand.plus.routing.VoiceRouter;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import android.media.MediaPlayer;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,10 +35,10 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
||||||
private VoiceRouter vrt;
|
private VoiceRouter vrt;
|
||||||
|
|
||||||
|
|
||||||
public MediaCommandPlayerImpl(OsmandApplication ctx, VoiceRouter vrt, String voiceProvider)
|
public MediaCommandPlayerImpl(OsmandApplication ctx, ApplicationMode applicationMode, VoiceRouter vrt, String voiceProvider)
|
||||||
throws CommandPlayerException
|
throws CommandPlayerException
|
||||||
{
|
{
|
||||||
super(ctx, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION);
|
super(ctx, applicationMode, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION);
|
||||||
this.vrt = vrt;
|
this.vrt = vrt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
|
||||||
if (mediaPlayer == null) {
|
if (mediaPlayer == null) {
|
||||||
requestAudioFocus();
|
requestAudioFocus();
|
||||||
// Delay first prompt of each batch to allow BT SCO connection being established
|
// Delay first prompt of each batch to allow BT SCO connection being established
|
||||||
if (ctx != null && ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) {
|
if (ctx != null && ctx.getSettings().AUDIO_STREAM_GUIDANCE.getModeValue(getApplicationMode()) == 0) {
|
||||||
try {
|
try {
|
||||||
log.debug("Delaying MediaCommandPlayer for BT SCO");
|
log.debug("Delaying MediaCommandPlayer for BT SCO");
|
||||||
Thread.sleep(ctx.getSettings().BT_SCO_DELAY.get());
|
Thread.sleep(ctx.getSettings().BT_SCO_DELAY.get());
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.ApplicationMode;
|
||||||
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;
|
||||||
|
@ -69,9 +70,9 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
||||||
private HashMap<String, String> params = new HashMap<String, String>();
|
private HashMap<String, String> params = new HashMap<String, String>();
|
||||||
private VoiceRouter vrt;
|
private VoiceRouter vrt;
|
||||||
|
|
||||||
public TTSCommandPlayerImpl(Activity ctx, VoiceRouter vrt, String voiceProvider)
|
public TTSCommandPlayerImpl(Activity ctx, ApplicationMode applicationMode, VoiceRouter vrt, String voiceProvider)
|
||||||
throws CommandPlayerException {
|
throws CommandPlayerException {
|
||||||
super((OsmandApplication) ctx.getApplicationContext(), voiceProvider, CONFIG_FILE, TTS_VOICE_VERSION);
|
super((OsmandApplication) ctx.getApplicationContext(), applicationMode, voiceProvider, CONFIG_FILE, TTS_VOICE_VERSION);
|
||||||
this.vrt = vrt;
|
this.vrt = vrt;
|
||||||
if (Algorithms.isEmpty(language)) {
|
if (Algorithms.isEmpty(language)) {
|
||||||
throw new CommandPlayerException(
|
throw new CommandPlayerException(
|
||||||
|
@ -82,7 +83,8 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
||||||
cSpeechRate = app.getSettings().SPEECH_RATE.get();
|
cSpeechRate = app.getSettings().SPEECH_RATE.get();
|
||||||
}
|
}
|
||||||
initializeEngine(app, ctx);
|
initializeEngine(app, ctx);
|
||||||
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, app.getSettings().AUDIO_STREAM_GUIDANCE.get().toString());
|
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, app.getSettings().AUDIO_STREAM_GUIDANCE
|
||||||
|
.getModeValue(getApplicationMode()).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,7 +113,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
|
||||||
if (ttsRequests++ == 0) {
|
if (ttsRequests++ == 0) {
|
||||||
requestAudioFocus();
|
requestAudioFocus();
|
||||||
// Delay first prompt of each batch to allow BT SCO connection being established
|
// Delay first prompt of each batch to allow BT SCO connection being established
|
||||||
if (ctx.getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) {
|
if (ctx.getSettings().AUDIO_STREAM_GUIDANCE.getModeValue(getApplicationMode()) == 0) {
|
||||||
ttsRequests++;
|
ttsRequests++;
|
||||||
if (android.os.Build.VERSION.SDK_INT < 21) {
|
if (android.os.Build.VERSION.SDK_INT < 21) {
|
||||||
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis());
|
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis());
|
||||||
|
|
Loading…
Reference in a new issue