Remove deprecated dialog

This commit is contained in:
Victor Shcherb 2012-06-24 14:04:36 +02:00
parent 6fc4774cfd
commit 5d5d611cdb
3 changed files with 48 additions and 45 deletions

View file

@ -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
-->
<string name="save_route_as_gpx">Save route as GPX</string>
<string name="route_roundabout">Roundabout : take %1$d exit</string>
<string name="route_kl">Keep left</string>
<string name="route_kr">Keep right</string>

View file

@ -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);
}
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<File, Void, String> {
private static class SaveDirectionsAsyncTask extends AsyncTask<File, Void, String> {
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;
}
}

View file

@ -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;
}