diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml
index 80b6681359..7b5b10d37a 100644
--- a/OsmAnd/AndroidManifest.xml
+++ b/OsmAnd/AndroidManifest.xml
@@ -49,6 +49,7 @@
+
diff --git a/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java b/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java
index 9c82329d07..91779e8e7c 100644
--- a/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java
+++ b/OsmAnd/src/net/osmand/plus/AsyncLoadingThread.java
@@ -7,6 +7,7 @@ import java.util.Stack;
import org.apache.commons.logging.Log;
import android.os.Handler;
+import android.os.HandlerThread;
import android.os.Looper;
import net.osmand.Algoritms;
@@ -45,34 +46,15 @@ public class AsyncLoadingThread extends Thread {
}
private void startPoiLoadingThread() {
- if (asyncLoadingPoi == null) {
- Thread th = new Thread(new Runnable() {
- @Override
- public void run() {
- Looper.prepare();
- asyncLoadingPoi = new Handler();
- Looper.loop();
- }
- }, "Loading poi");
- th.start();
- }
- while(asyncLoadingPoi != null){
- // wait
- }
+ HandlerThread h = new HandlerThread("Loading poi");
+ h.start();
+ asyncLoadingPoi = new Handler(h.getLooper());
}
private void startTransportLoadingThread() {
- new Thread(new Runnable() {
- @Override
- public void run() {
- Looper.prepare();
- asyncLoadingTransport = new Handler();
- Looper.loop();
- }
- }, "Loading transport").start();
- while(asyncLoadingTransport != null){
- // wait
- }
+ HandlerThread h = new HandlerThread("Loading transport");
+ h.start();
+ asyncLoadingTransport = new Handler(h.getLooper());
}
private int calculateProgressStatus(){
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
index f149df9fe0..2b77ad6e55 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java
@@ -59,6 +59,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
private static final String MORE_VALUE = "MORE_VALUE";
private Preference saveCurrentTrack;
+ private Preference testVoiceCommands;
private EditTextPreference applicationDir;
private ListPreference tileSourcePreference;
@@ -294,6 +295,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
localIndexes.setOnPreferenceClickListener(this);
saveCurrentTrack =(Preference) screen.findPreference(OsmandSettings.SAVE_CURRENT_TRACK);
saveCurrentTrack.setOnPreferenceClickListener(this);
+ testVoiceCommands =(Preference) screen.findPreference("test_voice_commands");
+ testVoiceCommands.setOnPreferenceClickListener(this);
routeServiceEnabled =(CheckBoxPreference) screen.findPreference(OsmandSettings.SERVICE_OFF_ENABLED);
routeServiceEnabled.setOnPreferenceChangeListener(this);
applicationDir = (EditTextPreference) screen.findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
@@ -656,27 +659,13 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
if(preference.getKey().equals(OsmandSettings.LOCAL_INDEXES)){
startActivity(new Intent(this, LocalIndexesActivity.class));
return true;
+ } else if(preference == testVoiceCommands){
+ startActivity(new Intent(this, TestVoiceActivity.class));
+ return true;
} else if(preference == saveCurrentTrack){
SavingTrackHelper helper = new SavingTrackHelper(this);
if (helper.hasDataToSave()) {
- progressDlg = ProgressDialog.show(this, getString(R.string.saving_gpx_tracks), getString(R.string.saving_gpx_tracks), true);
- final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg);
- impl.setRunnable("SavingGPX", new Runnable() { //$NON-NLS-1$
- @Override
- public void run() {
- try {
- SavingTrackHelper helper = new SavingTrackHelper(SettingsActivity.this);
- helper.saveDataToGpx();
- helper.close();
- } finally {
- if (progressDlg != null) {
- progressDlg.dismiss();
- progressDlg = null;
- }
- }
- }
- });
- impl.run();
+ saveCurrentTracks();
} else {
helper.close();
}
@@ -684,6 +673,27 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
}
return false;
}
+
+ private void saveCurrentTracks() {
+ progressDlg = ProgressDialog.show(this, getString(R.string.saving_gpx_tracks), getString(R.string.saving_gpx_tracks), true);
+ final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg);
+ impl.setRunnable("SavingGPX", new Runnable() { //$NON-NLS-1$
+ @Override
+ public void run() {
+ try {
+ SavingTrackHelper helper = new SavingTrackHelper(SettingsActivity.this);
+ helper.saveDataToGpx();
+ helper.close();
+ } finally {
+ if (progressDlg != null) {
+ progressDlg.dismiss();
+ progressDlg = null;
+ }
+ }
+ }
+ });
+ impl.run();
+ }
public static void installMapLayers(final Activity activity, final ResultMatcher result){
final OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
diff --git a/OsmAnd/src/net/osmand/plus/activities/TestVoiceActivity.java b/OsmAnd/src/net/osmand/plus/activities/TestVoiceActivity.java
new file mode 100644
index 0000000000..43f7478e8a
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/activities/TestVoiceActivity.java
@@ -0,0 +1,125 @@
+/**
+ *
+ */
+package net.osmand.plus.activities;
+
+import net.osmand.plus.R;
+import net.osmand.plus.voice.AbstractPrologCommandPlayer;
+import net.osmand.plus.voice.CommandBuilder;
+import net.osmand.plus.voice.CommandPlayer;
+import net.osmand.plus.voice.CommandPlayerException;
+import net.osmand.plus.voice.CommandPlayerFactory;
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.ScrollView;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.LinearLayout.LayoutParams;
+
+/**
+ * Test Voice activity
+ */
+public class TestVoiceActivity extends Activity {
+
+
+ private CommandPlayer player;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+
+ final OsmandApplication app = ((OsmandApplication) getApplication());
+ app.showDialogInitializingCommandPlayer(this, true);
+
+
+ LinearLayout gl = new LinearLayout(this);
+ gl.setOrientation(LinearLayout.VERTICAL);
+ gl.setPadding(3, 3, 3, 3);
+
+ TextView tv = new TextView(this);
+ tv.setText("Press buttons and listen various voice instructions, if you don't hear anything probably they are missed.");
+ tv.setPadding(0, 5, 0, 7);
+
+ ScrollView sv = new ScrollView(this);
+ gl.addView(sv, new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
+ android.view.ViewGroup.LayoutParams.FILL_PARENT));
+ final LinearLayout ll = new LinearLayout(this);
+ ll.setOrientation(LinearLayout.VERTICAL);
+ sv.addView(ll, new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
+ android.view.ViewGroup.LayoutParams.FILL_PARENT));
+
+ // add buttons
+ new AsyncTask() {
+
+ private ProgressDialog dlg;
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+ dlg = ProgressDialog.show(app, "Loading", "Initializing voice player...", true, false);
+ }
+ @Override
+ protected CommandPlayer doInBackground(Void... params) {
+ try {
+ return CommandPlayerFactory.createCommandPlayer(app.getSettings().VOICE_PROVIDER.get(), app, TestVoiceActivity.this);
+ } catch (CommandPlayerException e) {
+ return null;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(CommandPlayer p) {
+ dlg.dismiss();
+ if (p == null) {
+ Toast.makeText(TestVoiceActivity.this, "Voice player not initialized", Toast.LENGTH_SHORT).show();
+ } else {
+ addButtons(ll, p);
+
+ }
+ }
+ }.execute((Void)null);
+
+
+
+ setContentView(gl);
+ }
+
+ private void addButtons(final LinearLayout ll, CommandPlayer p) {
+ addButton(ll, "New route is calculated (15350 m)", builder(p).newRouteCalculated(15350));
+ addButton(ll, "Prepare 400 m make UT", builder(p).prepareMakeUT(400));
+ addButton(ll, "Prepare 320 m make right turn", builder(p).prepareTurn(AbstractPrologCommandPlayer.A_RIGHT, 320));
+ addButton(ll, "In 370 m make right sharp turn", builder(p).turn(AbstractPrologCommandPlayer.A_RIGHT_SH, 320));
+ ll.forceLayout();
+ }
+
+
+
+ private CommandBuilder builder(CommandPlayer p){
+ return p.newCommandBuilder();
+ }
+
+
+ public void addButton(ViewGroup layout, String description, final CommandBuilder builder){
+ Button button = new Button(this);
+ button.setText(description);
+ button.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
+ button.setPadding(10, 5, 10, 2);
+
+ layout.addView(button);
+ button.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ builder.play();
+ }
+ });
+ }
+
+}
diff --git a/OsmAnd/src/net/osmand/plus/activities/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/activities/VoiceRouter.java
index 959be77e04..e7174cb637 100644
--- a/OsmAnd/src/net/osmand/plus/activities/VoiceRouter.java
+++ b/OsmAnd/src/net/osmand/plus/activities/VoiceRouter.java
@@ -60,6 +60,10 @@ public class VoiceRouter {
}
+ public CommandPlayer getPlayer() {
+ return player;
+ }
+
public void setMute(boolean mute) {
this.mute = mute;
}