Add confirmation dialog; fix small things
This commit is contained in:
parent
edb25fbd95
commit
4ef1d86dfc
3 changed files with 51 additions and 9 deletions
|
@ -97,6 +97,7 @@ import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
|
||||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
||||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment;
|
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment;
|
||||||
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
|
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
|
||||||
|
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
import net.osmand.plus.resources.ResourceManager;
|
import net.osmand.plus.resources.ResourceManager;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
|
@ -500,6 +501,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (getMeasurementToolFragment() != null) {
|
||||||
|
getMeasurementToolFragment().showQuitDialog();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (prevActivityIntent != null && getSupportFragmentManager().getBackStackEntryCount() == 0) {
|
if (prevActivityIntent != null && getSupportFragmentManager().getBackStackEntryCount() == 0) {
|
||||||
prevActivityIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
prevActivityIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||||
LatLon loc = getMapLocation();
|
LatLon loc = getMapLocation();
|
||||||
|
@ -1675,6 +1680,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
return fragment!= null && !fragment.isDetached() && !fragment.isRemoving() ? (QuickSearchDialogFragment) fragment : null;
|
return fragment!= null && !fragment.isDetached() && !fragment.isRemoving() ? (QuickSearchDialogFragment) fragment : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MeasurementToolFragment getMeasurementToolFragment() {
|
||||||
|
Fragment fragment = getSupportFragmentManager().findFragmentByTag(MeasurementToolFragment.TAG);
|
||||||
|
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (MeasurementToolFragment) fragment : null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isTopToolbarActive() {
|
public boolean isTopToolbarActive() {
|
||||||
MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer();
|
MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer();
|
||||||
return mapInfoLayer.hasTopToolbar();
|
return mapInfoLayer.hasTopToolbar();
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
|
@ -71,7 +72,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
||||||
boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
|
boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
|
||||||
|
|
||||||
pointsSt = mapActivity.getString(R.string.points).toLowerCase();
|
pointsSt = getString(R.string.points).toLowerCase();
|
||||||
|
|
||||||
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_measurement_tool, null);
|
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_measurement_tool, null);
|
||||||
|
|
||||||
|
@ -145,11 +146,11 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
|
|
||||||
if (portrait) {
|
if (portrait) {
|
||||||
toolBarController = new MeasurementToolBarController();
|
toolBarController = new MeasurementToolBarController();
|
||||||
toolBarController.setTitle(mapActivity.getString(R.string.measurement_tool_action_bar));
|
toolBarController.setTitle(getString(R.string.measurement_tool_action_bar));
|
||||||
toolBarController.setOnBackButtonClickListener(new View.OnClickListener() {
|
toolBarController.setOnBackButtonClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mapActivity.onBackPressed();
|
showQuitDialog();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
toolBarController.setOnCloseButtonClickListener(new View.OnClickListener() {
|
toolBarController.setOnCloseButtonClickListener(new View.OnClickListener() {
|
||||||
|
@ -169,7 +170,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
if (measurementLayer.getPointsCount() > 0) {
|
if (measurementLayer.getPointsCount() > 0) {
|
||||||
saveAsGpxOnClick(mapActivity);
|
saveAsGpxOnClick(mapActivity);
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(mapActivity, mapActivity.getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_clear_all:
|
case R.id.action_clear_all:
|
||||||
|
@ -279,7 +280,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
MapActivity activity = getMapActivity();
|
MapActivity activity = getMapActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
progressDialog = new ProgressDialog(activity);
|
progressDialog = new ProgressDialog(activity);
|
||||||
progressDialog.setMessage(activity.getString(R.string.saving_gpx_tracks));
|
progressDialog.setMessage(getString(R.string.saving_gpx_tracks));
|
||||||
progressDialog.show();
|
progressDialog.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,7 +302,6 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
}
|
}
|
||||||
MapActivity activity = getMapActivity();
|
MapActivity activity = getMapActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
// todo
|
|
||||||
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());
|
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());
|
||||||
gpx.path = toSave.getAbsolutePath();
|
gpx.path = toSave.getAbsolutePath();
|
||||||
if (showOnMap) {
|
if (showOnMap) {
|
||||||
|
@ -318,7 +318,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
if (warning == null) {
|
if (warning == null) {
|
||||||
Toast.makeText(activity,
|
Toast.makeText(activity,
|
||||||
MessageFormat.format(activity.getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()),
|
MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()),
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(activity, warning, Toast.LENGTH_LONG).show();
|
Toast.makeText(activity, warning, Toast.LENGTH_LONG).show();
|
||||||
|
@ -430,6 +430,36 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showQuitDialog() {
|
||||||
|
final MapActivity mapActivity = getMapActivity();
|
||||||
|
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
|
if (mapActivity != null && measurementLayer != null) {
|
||||||
|
if (measurementLayer.getPointsCount() < 1) {
|
||||||
|
dismiss(mapActivity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new AlertDialog.Builder(mapActivity)
|
||||||
|
.setTitle(getString(R.string.are_you_sure))
|
||||||
|
.setMessage(getString(R.string.unsaved_changes_will_be_lost))
|
||||||
|
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dismiss(mapActivity);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.shared_string_cancel, null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dismiss(MapActivity mapActivity) {
|
||||||
|
try {
|
||||||
|
mapActivity.getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class MeasurementToolBarController extends TopToolbarController {
|
private static class MeasurementToolBarController extends TopToolbarController {
|
||||||
|
|
||||||
MeasurementToolBarController() {
|
MeasurementToolBarController() {
|
||||||
|
|
|
@ -160,8 +160,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
||||||
|
|
||||||
boolean undoPointOnClick() {
|
boolean undoPointOnClick() {
|
||||||
measurementPoints.remove(measurementPoints.size() - 1);
|
measurementPoints.remove(measurementPoints.size() - 1);
|
||||||
WptPt pt = measurementPoints.get(measurementPoints.size() - 1);
|
if (measurementPoints.size() > 0) {
|
||||||
view.getAnimatedDraggingThread().startMoving(pt.getLatitude(), pt.getLongitude(), view.getZoom(), true);
|
WptPt pt = measurementPoints.get(measurementPoints.size() - 1);
|
||||||
|
view.getAnimatedDraggingThread().startMoving(pt.getLatitude(), pt.getLongitude(), view.getZoom(), true);
|
||||||
|
}
|
||||||
return measurementPoints.size() > 0;
|
return measurementPoints.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue