Fix plan road map control button bug and disable ability to add new points

This commit is contained in:
Dima-1 2020-09-09 14:55:47 +03:00
parent b912307d8d
commit 240e532bde
4 changed files with 74 additions and 31 deletions

View file

@ -116,13 +116,20 @@
tools:src="@drawable/ic_action_remove_dark"
android:contentDescription="@string/snap_to_road" />
<include
layout="@layout/map_ruler"
android:layout_width="@dimen/map_ruler_width"
<LinearLayout
android:id="@+id/map_ruler_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="@dimen/map_button_margin"
android:layout_marginLeft="@dimen/map_button_margin" />
android:layout_gravity="bottom">
<include
layout="@layout/map_ruler"
android:layout_width="@dimen/map_ruler_width"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="@dimen/map_button_margin"
android:layout_marginLeft="@dimen/map_button_margin" />
</LinearLayout>
</LinearLayout>

View file

@ -117,6 +117,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
SaveAsNewTrackFragmentListener {
public static final String TAG = MeasurementToolFragment.class.getSimpleName();
public static final String TAPS_DISABLED_KEY = "taps_disabled_key";
private RecyclerView pointsRv;
private String previousToolBarTitle = "";
@ -459,19 +460,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} else if (!editingCtx.isNewData() && !editingCtx.hasRoutePoints() && !editingCtx.hasRoute() && editingCtx.getPointsCount() > 1) {
enterApproximationMode(mapActivity);
}
} else {
measurementLayer.setTapsDisabled(savedInstanceState.getBoolean(TAPS_DISABLED_KEY));
}
return view;
}
private void enterApproximationMode(MapActivity mapActivity) {
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) {
layer.setTapsDisabled(true);
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this);
}
}
public boolean isInEditMode() {
return !planRouteMode && !editingCtx.isNewData() && !directionMode;
}
@ -912,7 +907,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void onChangeApplicationMode(ApplicationMode mode, RouteBetweenPointsDialogType dialogType,
RouteBetweenPointsDialogMode dialogMode) {
RouteBetweenPointsDialogMode dialogMode) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
ChangeRouteType changeRouteType = ChangeRouteType.NEXT_SEGMENT;
@ -939,6 +934,15 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (measurementLayer != null) {
outState.putBoolean(TAPS_DISABLED_KEY, measurementLayer.isTapsDisabled());
}
}
private StartPlanRouteListener createStartPlanRouteListener() {
return new StartPlanRouteListener() {
@Override
@ -1050,13 +1054,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void onSaveAsNewTrack(String folderName, String fileName, boolean showOnMap, boolean simplifiedTrack) {
File dir = getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
if (folderName != null) {
dir = new File(dir, folderName);
OsmandApplication app = getMyApplication();
if (app != null) {
File dir = getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
if (folderName != null) {
dir = new File(dir, folderName);
}
fileName = fileName + GPX_FILE_EXT;
SaveType saveType = simplifiedTrack ? SaveType.LINE : SaveType.ROUTE_POINT;
saveNewGpx(dir, fileName, showOnMap, saveType, SaveAction.SHOW_IS_SAVED_FRAGMENT);
}
fileName = fileName + GPX_FILE_EXT;
SaveType saveType = simplifiedTrack ? SaveType.LINE : SaveType.ROUTE_POINT;
saveNewGpx(dir, fileName, showOnMap, saveType, SaveAction.SHOW_IS_SAVED_FRAGMENT);
}
private MeasurementAdapterListener createMeasurementAdapterListener(final ItemTouchHelper touchHelper) {
@ -2112,11 +2119,28 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
updateToolbar();
}
private void enterApproximationMode(MapActivity mapActivity) {
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) {
FragmentManager manager = mapActivity.getSupportFragmentManager();
manager.beginTransaction()
.hide(this).commit();
layer.setTapsDisabled(true);
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this);
AndroidUiHelper.setVisibility(mapActivity, View.GONE, R.id.map_ruler_container);
}
}
private void exitApproximationMode() {
editingCtx.setInApproximationMode(false);
MeasurementToolLayer layer = getMeasurementLayer();
if (layer != null) {
MapActivity mapActivity = getMapActivity();
if (layer != null && mapActivity != null) {
FragmentManager manager = mapActivity.getSupportFragmentManager();
manager.beginTransaction()
.show(this).commit();
layer.setTapsDisabled(false);
AndroidUiHelper.setVisibility(mapActivity, View.VISIBLE, R.id.map_ruler_container);
}
}
}

View file

@ -107,6 +107,10 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
this.tapsDisabled = tapsDisabled;
}
public boolean isTapsDisabled() {
return tapsDisabled;
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (inMeasurementMode && !tapsDisabled && editingCtx.getSelectedPointPosition() == -1) {

View file

@ -433,7 +433,7 @@ public class MapControlsLayer extends OsmandMapLayer {
}
} else {
ActivityCompat.requestPermissions(mapActivity,
new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION);
}
}
@ -478,7 +478,7 @@ public class MapControlsLayer extends OsmandMapLayer {
public void navigateButton() {
if (!OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
ActivityCompat.requestPermissions(mapActivity,
new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION);
} else {
final MapContextMenu menu = mapActivity.getContextMenu();
@ -504,8 +504,8 @@ public class MapControlsLayer extends OsmandMapLayer {
} else {
AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
bld.setTitle(R.string.new_directions_point_dialog);
final int[] defaultVls = new int[] {0};
bld.setSingleChoiceItems(new String[] {
final int[] defaultVls = new int[]{0};
bld.setSingleChoiceItems(new String[]{
mapActivity.getString(R.string.clear_intermediate_points),
mapActivity.getString(R.string.keep_intermediate_points)
}, 0, new DialogInterface.OnClickListener() {
@ -883,8 +883,12 @@ public class MapControlsLayer extends OsmandMapLayer {
menuControl.updateVisibility(showButtons);
mapZoomIn.updateVisibility(!routeDialogOpened && !contextMenuOpened && !isInTrackAppearanceMode() && (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !portrait));
mapZoomOut.updateVisibility(!routeDialogOpened && !contextMenuOpened && !isInTrackAppearanceMode() && (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !portrait));
mapZoomIn.updateVisibility(!routeDialogOpened && !contextMenuOpened && !isInTrackAppearanceMode()
&& (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !portrait)
&& (!isInGpxApproximationMode() || !isPotrait()));
mapZoomOut.updateVisibility(!routeDialogOpened && !contextMenuOpened && !isInTrackAppearanceMode()
&& (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !portrait)
&& (!isInGpxApproximationMode() || !isPotrait()));
boolean forceHideCompass = routeDialogOpened || trackDialogOpened
|| isInMeasurementToolMode() || isInPlanRouteMode() || contextMenuOpened || isInChoosingRoutesMode() || isInTrackAppearanceMode() || isInWaypointsChoosingMode();
compassHud.forceHideCompass = forceHideCompass;
@ -985,7 +989,7 @@ public class MapControlsLayer extends OsmandMapLayer {
public void updateMyLocationVisibility(MapHudButton backToLocationControl, RoutingHelper rh, boolean dialogOpened) {
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
boolean visible = !(tracked && rh.isFollowingMode());
boolean visible = !(tracked && rh.isFollowingMode()) && (!isInGpxApproximationMode() || !isPotrait());
backToLocationControl.updateVisibility(visible && !dialogOpened && !isInPlanRouteMode()
&& !isInTrackAppearanceMode() && (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !isPotrait()));
}
@ -1036,7 +1040,7 @@ public class MapControlsLayer extends OsmandMapLayer {
}
public void showTransparencyBar(CommonPreference<Integer> transparenPreference,
boolean isTransparencyBarEnabled) {
boolean isTransparencyBarEnabled) {
this.isTransparencyBarEnabled = isTransparencyBarEnabled;
ApplicationMode appMode = app.getSettings().getApplicationMode();
if (MapControlsLayer.transparencySetting != transparenPreference) {
@ -1295,12 +1299,16 @@ public class MapControlsLayer extends OsmandMapLayer {
return mapActivity.getMapLayers().getGpxLayer().isInTrackAppearanceMode();
}
private boolean isInGpxApproximationMode() {
return mapActivity.getMapLayers().getMeasurementToolLayer().isTapsDisabled();
}
private boolean isInChoosingRoutesMode() {
return MapRouteInfoMenu.chooseRoutesVisible;
}
private boolean isInWaypointsChoosingMode() {
return MapRouteInfoMenu.waypointsVisible;
return MapRouteInfoMenu.waypointsVisible;
}
public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) {