diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml
index 05fffbabe6..4640af7d61 100644
--- a/OsmAnd/AndroidManifest.xml
+++ b/OsmAnd/AndroidManifest.xml
@@ -147,8 +147,6 @@
-
-
diff --git a/OsmAnd/res/layout/sherpafy_loading.xml b/OsmAnd/res/layout/sherpafy_loading.xml
new file mode 100644
index 0000000000..6dbf486f72
--- /dev/null
+++ b/OsmAnd/res/layout/sherpafy_loading.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/sherpafy_start.xml b/OsmAnd/res/layout/sherpafy_start.xml
index 1fb1de84f3..cff01b1992 100644
--- a/OsmAnd/res/layout/sherpafy_start.xml
+++ b/OsmAnd/res/layout/sherpafy_start.xml
@@ -1,22 +1,37 @@
-
-
-
-
+
+
+
+
+
-
\ No newline at end of file
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/sherpafy_tour_info.xml b/OsmAnd/res/layout/sherpafy_tour_info.xml
index 47fcb80c30..7fe229ed67 100644
--- a/OsmAnd/res/layout/sherpafy_tour_info.xml
+++ b/OsmAnd/res/layout/sherpafy_tour_info.xml
@@ -5,24 +5,27 @@
android:orientation="vertical" >
@@ -31,7 +34,6 @@
android:id="@+id/start_tour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:gravity="right"
android:layout_marginRight="5dp"
android:text="@string/start_tour" />
@@ -42,7 +44,7 @@
android:layout_height="fill_parent" >
- "Selecting tour...
+ Overview
+ Selecting tour...
No stages provided
Download more
No tour selected
diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
index b62ac7b92d..43ce04b448 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
@@ -63,6 +63,7 @@ import android.util.TypedValue;
import android.view.accessibility.AccessibilityManager;
import android.widget.CheckBox;
import android.widget.LinearLayout;
+import android.widget.ProgressBar;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
@@ -96,8 +97,7 @@ public class OsmandApplication extends Application {
OsmAndTaskManager taskManager;
// start variables
- private ProgressDialogImplementation startDialog;
- private List startingWarnings;
+ private ProgressImplementation startDialog;
private Handler uiHandler;
private GPXFile gpxFileToDisplay;
private SavingTrackHelper savingTrackHelper;
@@ -307,33 +307,31 @@ public class OsmandApplication extends Application {
public static final int PROGRESS_DIALOG = 5;
- /**
- * @param activity
- * that supports onCreateDialog({@link #PROGRESS_DIALOG}) and returns @param progressdialog
- * @param progressDialog
- * - it should be exactly the same as onCreateDialog
- * @return
- */
public void checkApplicationIsBeingInitialized(Activity activity, ProgressDialog progressDialog) {
// start application if it was previously closed
startApplication();
synchronized (OsmandApplication.this) {
if (startDialog != null) {
- try {
- SpecialPhrases.setLanguage(this, osmandSettings);
- } catch (IOException e) {
- LOG.error("I/O exception", e);
- Toast error = Toast.makeText(this, "Error while reading the special phrases. Restart OsmAnd if possible",
- Toast.LENGTH_LONG);
- error.show();
- }
-
progressDialog.setTitle(getString(R.string.loading_data));
progressDialog.setMessage(getString(R.string.reading_indexes));
activity.showDialog(PROGRESS_DIALOG);
startDialog.setDialog(progressDialog);
- } else if (startingWarnings != null) {
- showWarnings(startingWarnings, activity);
+ } else {
+ progressDialog.dismiss();
+ }
+ }
+ }
+
+ public void checkApplicationIsBeingInitialized(Activity activity, TextView tv, ProgressBar progressBar,
+ Runnable onClose) {
+ // start application if it was previously closed
+ startApplication();
+ synchronized (OsmandApplication.this) {
+ if (startDialog != null ) {
+ tv.setText(getString(R.string.loading_data));
+ startDialog.setProgressBar(tv, progressBar, onClose);
+ } else if (onClose != null) {
+ onClose.run();
}
}
}
@@ -433,7 +431,7 @@ public class OsmandApplication extends Application {
if(dlg != null) {
dlg.dismiss();
}
- showWarning(uiContext, e.getError());
+ showToastMessage(e.getError());
}
}
}).start();
@@ -513,7 +511,7 @@ public class OsmandApplication extends Application {
return;
}
applicationInitializing = true;
- startDialog = new ProgressDialogImplementation(this, null, false);
+ startDialog = new ProgressImplementation(this, null, false);
startDialog.setRunnable("Initializing app", new Runnable() { //$NON-NLS-1$
@Override
@@ -530,6 +528,12 @@ public class OsmandApplication extends Application {
private void startApplicationBackground() {
List warnings = new ArrayList();
try {
+ try {
+ SpecialPhrases.setLanguage(this, osmandSettings);
+ } catch (IOException e) {
+ LOG.error("I/O exception", e);
+ warnings.add("Error while reading the special phrases. Restart OsmAnd if possible");
+ }
if (!Version.isBlackberry(this)) {
if (osmandSettings.NATIVE_RENDERING_FAILED.get()) {
osmandSettings.SAFE_MODE.set(true);
@@ -574,17 +578,23 @@ public class OsmandApplication extends Application {
} finally {
synchronized (OsmandApplication.this) {
final ProgressDialog toDismiss;
+ final Runnable pb;
if (startDialog != null) {
toDismiss = startDialog.getDialog();
+ pb = startDialog.getFinishRunnable();
} else {
toDismiss = null;
+ pb = null;
}
startDialog = null;
- if (toDismiss != null) {
+ if (toDismiss != null || pb != null) {
uiHandler.post(new Runnable() {
@Override
public void run() {
+ if(pb != null) {
+
+ }
if (toDismiss != null) {
// TODO handling this dialog is bad, we need a better standard way
toDismiss.dismiss();
@@ -592,38 +602,28 @@ public class OsmandApplication extends Application {
}
}
});
- showWarnings(warnings, toDismiss.getContext());
- } else {
- startingWarnings = warnings;
+ }
+ if (warnings != null && !warnings.isEmpty()) {
+ showToastMessage(formatWarnings(warnings).toString());
}
}
}
}
- protected void showWarnings(List warnings, final Context uiContext) {
- if (warnings != null && !warnings.isEmpty()) {
- final StringBuilder b = new StringBuilder();
- boolean f = true;
- for (String w : warnings) {
- if (f) {
- f = false;
- } else {
- b.append('\n');
- }
- b.append(w);
+ private StringBuilder formatWarnings(List warnings) {
+ final StringBuilder b = new StringBuilder();
+ boolean f = true;
+ for (String w : warnings) {
+ if (f) {
+ f = false;
+ } else {
+ b.append('\n');
}
- showWarning(uiContext, b.toString());
+ b.append(w);
}
+ return b;
}
- private void showWarning(final Context uiContext, final String b) {
- uiHandler.post(new Runnable() {
- @Override
- public void run() {
- AccessibleToast.makeText(uiContext, b, Toast.LENGTH_LONG).show();
- }
- });
- }
private class DefaultExceptionHandler implements UncaughtExceptionHandler {
diff --git a/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java b/OsmAnd/src/net/osmand/plus/ProgressImplementation.java
similarity index 69%
rename from OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java
rename to OsmAnd/src/net/osmand/plus/ProgressImplementation.java
index 301d2b7f83..9069e090ce 100644
--- a/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java
+++ b/OsmAnd/src/net/osmand/plus/ProgressImplementation.java
@@ -7,8 +7,10 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.Handler;
import android.os.Message;
+import android.widget.ProgressBar;
+import android.widget.TextView;
-public class ProgressDialogImplementation implements IProgress {
+public class ProgressImplementation implements IProgress {
private static final int HANDLER_START_TASK = OsmAndConstants.UI_HANDLER_PROGRESS + 1;
private static final int HADLER_UPDATE_PROGRESS = OsmAndConstants.UI_HANDLER_PROGRESS + 2;
@@ -22,54 +24,70 @@ public class ProgressDialogImplementation implements IProgress {
private Thread run;
private Context context;
private ProgressDialog dialog = null;
+ private ProgressBar progressBar = null;
+ private Runnable finishRunnable = null;
private final boolean cancelable;
+ private TextView tv;
- public ProgressDialogImplementation(Context ctx, ProgressDialog dlg, boolean cancelable){
+ public ProgressImplementation(Context ctx, ProgressDialog dlg, boolean cancelable) {
this.cancelable = cancelable;
context = ctx;
setDialog(dlg);
-
- mViewUpdateHandler = new Handler(){
+
+ mViewUpdateHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
- if(dialog != null){
- switch (msg.what) {
- case HANDLER_START_TASK:
- dialog.setMessage(message);
- if (isIndeterminate()) {
- dialog.setMax(1);
- dialog.setIndeterminate(true);
- } else {
- dialog.setIndeterminate(false);
- dialog.setMax(work);
- }
- dialog.show();
- break;
- case HADLER_UPDATE_PROGRESS:
- dialog.setProgress(msg.arg1);
- break;
+
+ switch (msg.what) {
+ case HANDLER_START_TASK:
+ if (dialog != null) {
+ dialog.setMessage(message);
+ if (isIndeterminate()) {
+ dialog.setMax(1);
+ dialog.setIndeterminate(true);
+ } else {
+ dialog.setIndeterminate(false);
+ dialog.setMax(work);
+ }
+ dialog.show();
}
+ if (tv != null) {
+ tv.setText(message);
+ }
+ if (progressBar != null) {
+ if (isIndeterminate()) {
+ progressBar.setMax(1);
+ progressBar.setIndeterminate(true);
+ } else {
+ progressBar.setIndeterminate(false);
+ progressBar.setMax(work);
+ }
+ }
+ break;
+ case HADLER_UPDATE_PROGRESS:
+ if (dialog != null) {
+ dialog.setProgress(msg.arg1);
+ } else if (progressBar != null) {
+ progressBar.setProgress(msg.arg1);
+ }
+ break;
}
}
- };
+ };
}
- public ProgressDialogImplementation(ProgressDialog dlg, boolean cancelable){
+ public ProgressImplementation(ProgressDialog dlg, boolean cancelable){
this(dlg.getContext(), dlg, cancelable);
}
- public ProgressDialogImplementation(final ProgressDialog dlg){
- this(dlg, false);
- }
-
- public static ProgressDialogImplementation createProgressDialog(Context ctx, String title, String message, int style) {
+ public static ProgressImplementation createProgressDialog(Context ctx, String title, String message, int style) {
return createProgressDialog(ctx, title, message, style, null);
}
- public static ProgressDialogImplementation createProgressDialog(Context ctx, String title, String message, int style, final DialogInterface.OnCancelListener listener) {
+ public static ProgressImplementation createProgressDialog(Context ctx, String title, String message, int style, final DialogInterface.OnCancelListener listener) {
ProgressDialog dlg = new ProgressDialog(ctx) {
@Override
public void cancel() {
@@ -98,7 +116,13 @@ public class ProgressDialogImplementation implements IProgress {
// failure, must be older device
}
dlg.setProgressStyle(style);
- return new ProgressDialogImplementation(dlg, true);
+ return new ProgressImplementation(dlg, true);
+ }
+
+ public void setProgressBar(TextView tv, ProgressBar progressBar, Runnable finish) {
+ this.tv = tv;
+ this.progressBar = progressBar;
+ this.finishRunnable = finish;
}
public void setDialog(ProgressDialog dlg){
@@ -188,7 +212,11 @@ public class ProgressDialogImplementation implements IProgress {
public ProgressDialog getDialog() {
return dialog;
}
-
+
+ public Runnable getFinishRunnable() {
+ return finishRunnable;
+ }
+
@Override
public void startWork(int work) {
this.work = work;
diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java
index c70c293b6a..89bcd35e86 100644
--- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java
@@ -18,7 +18,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.DrivingRegion;
import net.osmand.plus.OsmandSettings.MetricsConstants;
-import net.osmand.plus.ProgressDialogImplementation;
+import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
@@ -345,7 +345,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
private File to;
private Context ctx;
private File from;
- protected ProgressDialogImplementation progress;
+ protected ProgressImplementation progress;
private Runnable runOnSuccess;
public MoveFilesToDifferentDirectory(Context ctx, File from, File to) {
@@ -360,7 +360,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
@Override
protected void onPreExecute() {
- progress = ProgressDialogImplementation.createProgressDialog(
+ progress = ProgressImplementation.createProgressDialog(
ctx, ctx.getString(R.string.copying_osmand_files),
ctx.getString(R.string.copying_osmand_files_descr, to.getPath()),
ProgressDialog.STYLE_HORIZONTAL);
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java
index 7e41095a34..30c2b8ff31 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java
@@ -13,7 +13,7 @@ import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
-import net.osmand.plus.ProgressDialogImplementation;
+import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandListActivity;
@@ -200,7 +200,7 @@ public class LocalOpenstreetmapActivity extends OsmandListActivity {
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_PROGRESS_UPLOAD:
- return ProgressDialogImplementation.createProgressDialog(
+ return ProgressImplementation.createProgressDialog(
LocalOpenstreetmapActivity.this,
getString(R.string.uploading),
getString(R.string.local_openstreetmap_uploading),
diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectTourActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectTourActivity.java
deleted file mode 100644
index 2661fbfa23..0000000000
--- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafySelectTourActivity.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package net.osmand.plus.sherpafy;
-
-import java.util.List;
-
-import net.osmand.IProgress;
-import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.R;
-import net.osmand.plus.activities.DownloadIndexActivity;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.ProgressDialog;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
-
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-
-/**
- */
-public class SherpafySelectTourActivity extends SherlockFragmentActivity {
-
- private SherpafyCustomization customization;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- if (!(getMyApplication().getAppCustomization() instanceof SherpafyCustomization)) {
- getMyApplication().setAppCustomization(new SherpafyCustomization());
- }
- customization = (SherpafyCustomization) getMyApplication().getAppCustomization();
- setTheme(R.style.OsmandLightTheme);
- ((OsmandApplication) getApplication()).setLanguage(this);
- super.onCreate(savedInstanceState);
- getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
- getSupportActionBar().setDisplayHomeAsUpEnabled(false);
- getSupportActionBar().setTitle(R.string.sherpafy_app_name);
- super.setContentView(R.layout.sherpafy_start);
-
- ProgressDialog startProgressDialog = new ProgressDialog(this);
- getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
-
- setContentView();
-
- // FIXME is this needed?
-// if (customization.getTourInformations().isEmpty()) {
-// customization.onIndexingFiles(IProgress.EMPTY_PROGRESS, new ConcurrentHashMap());
-// }
- }
-
- private OsmandApplication getMyApplication() {
- return (OsmandApplication) getApplication();
- }
-
- private void setContentView() {
- final Button selectTour = (Button) findViewById(R.id.select_tour);
- selectTour.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // creating alert dialog with multiple tours to select
- AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
- final List tours = customization.getTourInformations();
- if (customization.getSelectedTour() != null) {
- String[] tourNames = new String[tours.size()];
- // creating list of tour names to select
- for (int i = 0; i < tours.size(); i++) {
- tourNames[i] = tours.get(i).getName();
- }
- int i;
- for (i = 0; i < tours.size(); i++) {
- if (customization.getSelectedTour().equals(tours.get(i))) {
- break;
- }
- }
-
- adb.setSingleChoiceItems(tourNames, i, new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- selectTour(tours.get(i));
- dialogInterface.dismiss();
- }
- });
- } else {
- String[] tourNames = new String[tours.size() + 1];
- tourNames[0] = getString(R.string.none);
- for (int i = 1; i < tours.size() + 1; i++) {
- tourNames[i] = tours.get(i - 1).getName();
- }
- adb.setSingleChoiceItems(tourNames, 0, new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- if (i == 0) {
- return;
- }
- selectTour(tours.get(i - 1));
- dialogInterface.dismiss();
- }
- });
- }
-
- adb.setTitle(R.string.select_tour);
- adb.setNegativeButton(R.string.default_buttons_cancel, null);
- adb.show();
- }
- });
-
- Button downloadTour = (Button) findViewById(R.id.download_tour);
- downloadTour.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final Intent download = new Intent(v.getContext(), DownloadIndexActivity.class);
- download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
- v.getContext().startActivity(download);
- }
- });
- }
-
-
- private Activity getActivity() {
- return this;
- }
-
- private void selectTour(final TourInformation tour){
- new AsyncTask(){
- private ProgressDialog dlg;
-
- protected void onPreExecute() {
- dlg = new ProgressDialog(getActivity());
- dlg.setTitle(R.string.selecting_tour_progress);
- dlg.setMessage(getString(R.string.indexing_tour, tour == null ? "" : tour.getName()));
- dlg.show();
- };
-
- @Override
- protected Void doInBackground(TourInformation... params) {
- customization.selectTour(params[0], IProgress.EMPTY_PROGRESS);
- return null;
- }
-
- protected void onPostExecute(Void result) {
- dlg.dismiss();
-
- Intent intent = new Intent(getApplicationContext(), TourViewActivity.class);
- startActivity(intent);
- finish();
- };
- }.execute(tour);
- }
-}
diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java
index c79bc14556..606e923043 100644
--- a/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java
+++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourInformation.java
@@ -77,6 +77,8 @@ public class TourInformation {
stage = null;
} else if(stage != null && tag.equals("description")) {
stage.description = text;
+ } else if(stage != null && tag.equals("fullDescription")) {
+ stage.fullDescription = text;
} else if(stage != null && tag.equals("gpx")) {
if(text.startsWith(FILE_PREFIX)) {
stage.gpxFile = new File(folder, text.substring(FILE_PREFIX.length()));
@@ -139,6 +141,7 @@ public class TourInformation {
File gpxFile;
String name = "";
String description = "";
+ String fullDescription = "";
public String getName() {
return name;
@@ -148,6 +151,10 @@ public class TourInformation {
return description;
}
+ public String getFullDescription() {
+ return fullDescription;
+ }
+
public File getGpxFile() {
return gpxFile;
}
diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java
index bb29b24ebd..ba6746bf74 100644
--- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java
+++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java
@@ -5,30 +5,43 @@ import java.util.List;
import net.osmand.IProgress;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
+import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.MapActivity;
+import android.app.Activity;
+import android.app.AlertDialog;
import android.app.ProgressDialog;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
+import android.os.AsyncTask;
import android.os.Bundle;
-import android.text.SpannableString;
-import android.text.method.LinkMovementMethod;
-import android.text.style.ClickableSpan;
+import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
+import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.actionbarsherlock.app.SherlockFragmentActivity;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuItem;
+import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;
/**
*/
public class TourViewActivity extends SherlockFragmentActivity {
+ private static final int GO_TO_MAP = 1;
+ private static final int SETTINGS_ID = 2;
+ private static final int STATE_TOUR_VIEW = 1;
+ private static final int STATE_LOADING = 0;
+ private static final int STATE_SELECT_TOUR = -1;
+ int state = 0;
private SherpafyCustomization customization;
ImageView img;
TextView description;
@@ -36,6 +49,7 @@ public class TourViewActivity extends SherlockFragmentActivity {
List stagesInfo;
TourInformation curTour;
RadioGroup stages;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -46,13 +60,27 @@ public class TourViewActivity extends SherlockFragmentActivity {
setTheme(R.style.OsmandLightTheme);
((OsmandApplication) getApplication()).setLanguage(this);
super.onCreate(savedInstanceState);
- getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
+ if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ||
+ getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
+ getSherlock().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
+ }
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle(R.string.sherpafy_app_name);
- ProgressDialog startProgressDialog = new ProgressDialog(this);
- getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
-
+ setContentView(R.layout.sherpafy_loading);
+ state = STATE_LOADING;
+ getMyApplication().checkApplicationIsBeingInitialized(this, (TextView) findViewById(R.id.ProgressMessage),
+ (ProgressBar) findViewById(R.id.ProgressBar), new Runnable() {
+ @Override
+ public void run() {
+ setMainContent();
+ }
+ });
+
+ }
+
+
+ private void setTourInfoContent() {
setContentView(R.layout.sherpafy_tour_info);
ToggleButton collapser = (ToggleButton) findViewById(R.id.collapse);
@@ -64,12 +92,13 @@ public class TourViewActivity extends SherlockFragmentActivity {
customization.selectStage(null, IProgress.EMPTY_PROGRESS);
fullDescription.setText(curTour.getFulldescription());
description.setText((curTour.getShortDescription()));
+ ((TextView)findViewById(R.id.tour_name)).setText(getString(R.string.overview));
prepareBitmap();
} else {
- //-1 because there's one more item Overview, which is not exactly a stage.
customization.selectStage(stagesInfo.get(i - 1), IProgress.EMPTY_PROGRESS);
description.setText(stagesInfo.get(i - 1).getDescription());
- fullDescription.setText("");
+ fullDescription.setText(stagesInfo.get(i - 1).getFullDescription());
+ ((TextView)findViewById(R.id.tour_name)).setText(stagesInfo.get(i - 1).getName());
}
}
});
@@ -83,36 +112,56 @@ public class TourViewActivity extends SherlockFragmentActivity {
} else {
stages.setVisibility(View.GONE);
}
-
}
});
-
- TextView settings = (TextView) findViewById(R.id.btn_settings);
- SpannableString content = new SpannableString(settings.getText());
- content.setSpan(new ClickableSpan() {
-
- @Override
- public void onClick(View widget) {
- Intent intent = new Intent(getApplicationContext(), SherpafySelectTourActivity.class);
- startActivity(intent);
- }
- }, 0, content.length(), 0);
- settings.setText(content);
- settings.setMovementMethod(LinkMovementMethod.getInstance());
}
- @Override
- protected void onResume() {
- super.onResume();
+ private void startSettings() {
+ if(state != STATE_SELECT_TOUR) {
+ setTourSelectionContentView();
+ state = STATE_SELECT_TOUR;
+ }
+ }
+
+ private void setMainContent() {
if(customization.getSelectedTour() != null) {
+ if(state != STATE_TOUR_VIEW) {
+ setTourInfoContent();
+ state = STATE_TOUR_VIEW;
+ }
getSupportActionBar().setTitle(customization.getSelectedTour().getName());
updateTourView();
} else {
-// Intent intent = new Intent(getApplicationContext(), SherpafySelectTourActivity.class);
-// startActivity(intent);
- //
+ startSettings();
}
}
+
+ @Override
+ public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
+ createMenuItem(menu, GO_TO_MAP, R.string.start_tour,
+ 0, 0,/*R.drawable.ic_action_marker_light,*/
+ MenuItem.SHOW_AS_ACTION_ALWAYS| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
+ createMenuItem(menu, SETTINGS_ID, R.string.osmo_share_session,
+ R.drawable.ic_action_settings_light, R.drawable.ic_action_settings_dark,
+ MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconLight, int iconDark, int menuItemType) {
+// int r = getMyApplication().getSettings().isLightActionBar() ? iconLight : iconDark;
+ int r = iconLight;
+ MenuItem menuItem = m.add(0, id, 0, titleRes);
+ if (r != 0) {
+ menuItem.setIcon(r);
+ }
+ menuItem.setShowAsActionFlags(menuItemType).setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ @Override
+ public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
+ return onOptionsItemSelected(item);
+ }
+ });
+ return menuItem;
+ }
private void updateTourView() {
@@ -126,39 +175,33 @@ public class TourViewActivity extends SherlockFragmentActivity {
fullDescription.setVisibility(View.VISIBLE);
Button start_tour = (Button) findViewById(R.id.start_tour);
- //in case of reloading view - remove all previous radio buttons
+ // in case of reloading view - remove all previous radio buttons
stages.removeAllViews();
start_tour.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- MapActivity.launchMapActivityMoveToTop(GetActivity());
+ goToMap();
}
});
-
- //get count of radio buttons
+ // get count of radio buttons
final int count = stagesInfo.size() + 1;
final RadioButton[] rb = new RadioButton[count];
rb[0] = new RadioButton(this);
rb[0].setId(0);
stages.addView(rb[0]);
- rb[0].setText("Overview");
- rb[0].setTextColor(getResources().getColor(R.color.color_black));
- //add radio buttons to view
+ rb[0].setText(getString(R.string.overview));
+ // add radio buttons to view
for (int i = 1; i < count; i++) {
rb[i] = new RadioButton(this);
rb[i].setId(i);
stages.addView(rb[i]);
rb[i].setText(stagesInfo.get(i - 1).getName());
- rb[i].setTextColor(getResources().getColor(R.color.color_black));
}
TourInformation.StageInformation curStage = customization.getSelectedStage();
-
- //if there's no current stage - overview should be selected
if (curStage == null) {
- //DIRTY HACK, I dunno why, but after activity onResume it's not possible to just check item 0
stages.check(0);
description.setText(curTour.getShortDescription());
fullDescription.setText(curTour.getFulldescription());
@@ -176,6 +219,11 @@ public class TourViewActivity extends SherlockFragmentActivity {
}
}
}
+
+ private void goToMap() {
+ MapActivity.launchMapActivityMoveToTop(getActivity());
+ // TODO select GPX
+ }
private void prepareBitmap() {
final Bitmap imageBitmap = curTour.getImageBitmap();
@@ -194,7 +242,117 @@ public class TourViewActivity extends SherlockFragmentActivity {
return (OsmandApplication) getApplication();
}
- private TourViewActivity GetActivity() {
+
+ @Override
+ public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
+ if (item.getItemId() == GO_TO_MAP) {
+ goToMap();
+ return true;
+ } else if (item.getItemId() == SETTINGS_ID) {
+ startSettings();
+ return true;
+ } else {
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+
+ private void setTourSelectionContentView() {
+ setContentView(R.layout.sherpafy_start);
+ final Button selectTour = (Button) findViewById(R.id.select_tour);
+ final Button downloadTour = (Button) findViewById(R.id.download_tour);
+ int width = Math.max(downloadTour.getWidth(), selectTour.getWidth());
+ downloadTour.setWidth(width);
+ selectTour.setWidth(width);
+ selectTour.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ // creating alert dialog with multiple tours to select
+ AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
+ final List tours = customization.getTourInformations();
+ if (customization.getSelectedTour() != null) {
+ String[] tourNames = new String[tours.size()];
+ // creating list of tour names to select
+ for (int i = 0; i < tours.size(); i++) {
+ tourNames[i] = tours.get(i).getName();
+ }
+ int i;
+ for (i = 0; i < tours.size(); i++) {
+ if (customization.getSelectedTour().equals(tours.get(i))) {
+ break;
+ }
+ }
+
+ adb.setSingleChoiceItems(tourNames, i, new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ selectTour(tours.get(i));
+ dialogInterface.dismiss();
+ }
+ });
+ } else {
+ String[] tourNames = new String[tours.size() + 1];
+ tourNames[0] = getString(R.string.none);
+ for (int i = 1; i < tours.size() + 1; i++) {
+ tourNames[i] = tours.get(i - 1).getName();
+ }
+ adb.setSingleChoiceItems(tourNames, 0, new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ if (i == 0) {
+ return;
+ }
+ selectTour(tours.get(i - 1));
+ dialogInterface.dismiss();
+ }
+ });
+ }
+
+ adb.setTitle(R.string.select_tour);
+ adb.setNegativeButton(R.string.default_buttons_cancel, null);
+ adb.show();
+ }
+ });
+
+ downloadTour.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final Intent download = new Intent(v.getContext(), DownloadIndexActivity.class);
+ download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ v.getContext().startActivity(download);
+ }
+ });
+ }
+
+
+ private Activity getActivity() {
return this;
}
+
+ private void selectTour(final TourInformation tour){
+ new AsyncTask(){
+ private ProgressDialog dlg;
+
+ protected void onPreExecute() {
+ dlg = new ProgressDialog(getActivity());
+ dlg.setTitle(R.string.selecting_tour_progress);
+ dlg.setMessage(getString(R.string.indexing_tour, tour == null ? "" : tour.getName()));
+ dlg.show();
+ };
+
+ @Override
+ protected Void doInBackground(TourInformation... params) {
+ customization.selectTour(params[0], IProgress.EMPTY_PROGRESS);
+ return null;
+ }
+
+ protected void onPostExecute(Void result) {
+ dlg.dismiss();
+ setTourInfoContent();
+ };
+ }.execute(tour);
+ }
+
}