From 5d5d611cdbdf8e20ff22e469d31a553ef60c0088 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 24 Jun 2012 14:04:36 +0200 Subject: [PATCH] Remove deprecated dialog --- OsmAnd/res/values/strings.xml | 1 + .../plus/activities/MapActivityActions.java | 64 ++++++------------- .../activities/ShowRouteInfoActivity.java | 28 +++++++- 3 files changed, 48 insertions(+), 45 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 3c43578521..a24994fb18 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 1. All your modified/created strings are in the top of the file (to make easier find what's translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Save route as GPX Roundabout : take %1$d exit Keep left Keep right diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 9574d0281b..e3c5d4d091 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -81,7 +81,6 @@ public class MapActivityActions implements DialogProvider { private static final int DIALOG_ADD_WAYPOINT = 102; private static final int DIALOG_RELOAD_TITLE = 103; private static final int DIALOG_SHARE_LOCATION = 104; - private static final int DIALOG_ABOUT_ROUTE = 105; private static final int DIALOG_SAVE_DIRECTIONS = 106; private Bundle dialogBundle = new Bundle(); @@ -362,36 +361,11 @@ public class MapActivityActions implements DialogProvider { } protected void aboutRoute() { - mapActivity.showDialog(DIALOG_ABOUT_ROUTE); + Intent intent = new Intent(mapActivity, ShowRouteInfoActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + mapActivity.startActivity(intent); } - private void prepareAboutRouteDialog(Dialog dlg, Bundle args) { - ((AlertDialog)dlg).setMessage(mapActivity.getRoutingHelper().getGeneralRouteInformation()); - } - - private Dialog createAboutRouteDialog(Bundle args) { - DialogInterface.OnClickListener showRoute = new DialogInterface.OnClickListener(){ - @Override - public void onClick(DialogInterface dialog, int which) { - Intent intent = new Intent(mapActivity, ShowRouteInfoActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - mapActivity.startActivity(intent); - } - }; - DialogInterface.OnClickListener saveDirections = new DialogInterface.OnClickListener(){ - @Override - public void onClick(DialogInterface dialog, int which) { - saveDirections(); - } - }; - Builder builder = new AccessibleAlertBuilder(mapActivity); - builder.setTitle(R.string.show_route); - builder.setMessage(mapActivity.getRoutingHelper().getGeneralRouteInformation()); - builder.setPositiveButton(R.string.default_buttons_save, saveDirections); - builder.setNeutralButton(R.string.show_route, showRoute); - builder.setNegativeButton(R.string.close, null); - return builder.create(); - } private boolean checkPointToNavigate(){ MapActivityLayers mapLayers = mapActivity.getMapLayers(); @@ -616,10 +590,11 @@ public class MapActivityActions implements DialogProvider { mapActivity.showDialog(DIALOG_SAVE_DIRECTIONS); } - private Dialog createSaveDirections() { - OsmandSettings settings = getMyApplication().getSettings(); + public static Dialog createSaveDirections(Activity activity) { + final OsmandApplication app = ((OsmandApplication) activity.getApplication()); + OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings(); final File fileDir = settings.extendOsmandPath(ResourceManager.GPX_PATH); - final Dialog dlg = new Dialog(mapActivity); + final Dialog dlg = new Dialog(activity); dlg.setTitle(R.string.save_route_dialog_title); dlg.setContentView(R.layout.save_directions_dialog); final EditText edit = (EditText) dlg.findViewById(R.id.FileNameEdit); @@ -641,7 +616,7 @@ public class MapActivityActions implements DialogProvider { dlg.findViewById(R.id.DuplicateFileName).setVisibility(View.VISIBLE); } else { dlg.dismiss(); - new SaveDirectionsAsyncTask().execute(toSave); + new SaveDirectionsAsyncTask(app).execute(toSave); } } }); @@ -658,15 +633,21 @@ public class MapActivityActions implements DialogProvider { } - private class SaveDirectionsAsyncTask extends AsyncTask { + private static class SaveDirectionsAsyncTask extends AsyncTask { + + private final OsmandApplication app; + + public SaveDirectionsAsyncTask(OsmandApplication app) { + this.app = app; + } @Override protected String doInBackground(File... params) { if (params.length > 0) { File file = params[0]; - GPXFile gpx = mapActivity.getRoutingHelper().generateGPXFileWithRoute(); - GPXUtilities.writeGpxFile(file, gpx, mapActivity); - return mapActivity.getString(R.string.route_successfully_saved_at, file.getName()); + GPXFile gpx = app.getRoutingHelper().generateGPXFileWithRoute(); + GPXUtilities.writeGpxFile(file, gpx, app); + return app.getString(R.string.route_successfully_saved_at, file.getName()); } return null; } @@ -674,7 +655,7 @@ public class MapActivityActions implements DialogProvider { @Override protected void onPostExecute(String result) { if(result != null){ - AccessibleToast.makeText(mapActivity, result, Toast.LENGTH_LONG).show(); + AccessibleToast.makeText(app, result, Toast.LENGTH_LONG).show(); } } @@ -820,10 +801,8 @@ public class MapActivityActions implements DialogProvider { return createReloadTitleDialog(args); case DIALOG_SHARE_LOCATION: return createShareLocationDialog(args); - case DIALOG_ABOUT_ROUTE: - return createAboutRouteDialog(args); case DIALOG_SAVE_DIRECTIONS: - return createSaveDirections(); + return createSaveDirections(mapActivity); } return null; } @@ -844,9 +823,6 @@ public class MapActivityActions implements DialogProvider { v.setText(""); } break; - case DIALOG_ABOUT_ROUTE: - prepareAboutRouteDialog(dialog, args); - break; } } diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java index 03f5388658..3317bb0213 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java @@ -12,8 +12,14 @@ import net.osmand.plus.R; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.TurnPathHelper; +import android.app.Dialog; +import android.graphics.Color; import android.location.Location; import android.os.Bundle; +import android.text.SpannableString; +import android.text.TextPaint; +import android.text.method.LinkMovementMethod; +import android.text.style.ClickableSpan; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.Menu; @@ -21,6 +27,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; @@ -41,8 +48,26 @@ public class ShowRouteInfoActivity extends OsmandListActivity { ListView lv = new ListView(this); lv.setId(android.R.id.list); header = new TextView(this); + TextView linkSaveAs = new TextView(this); helper = ((OsmandApplication)getApplication()).getRoutingHelper(); lv.addHeaderView(header); + lv.addHeaderView(linkSaveAs); + final CharSequence link = getText(R.string.save_route_as_gpx); + SpannableString content = new SpannableString(link); + content.setSpan(new ClickableSpan() { + @Override + public void onClick(View widget) { + MapActivityActions.createSaveDirections(ShowRouteInfoActivity.this).show(); + } + + @Override + public void updateDrawState(TextPaint ds) { + super.updateDrawState(ds); + ds.setColor(Color.GREEN); + } + }, 0, link.length(), 0); + linkSaveAs.setText(content); + linkSaveAs.setMovementMethod(LinkMovementMethod.getInstance()); setContentView(lv); dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); @@ -86,7 +111,8 @@ public class ShowRouteInfoActivity extends OsmandListActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId() == 0){ - //mapActivityActions.saveDirections(); + Dialog dlg = MapActivityActions.createSaveDirections(this); + dlg.show(); } else { return false; }