use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method disableSnapToRoadMode.
private void disableSnapToRoadMode() {
toolBarController.setTopBarSwitchVisible(false);
toolBarController.setTitle(previousToolBarTitle);
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
editingCtx.setInSnapToRoadMode(false);
editingCtx.cancelSnapToRoad();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE);
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
mapActivity.refreshMap();
}
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method hidePointsListFragment.
private void hidePointsListFragment() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
try {
FragmentManager manager = mapActivity.getSupportFragmentManager();
Fragment fragment = manager.findFragmentByTag(RecyclerViewFragment.TAG);
if (fragment != null) {
manager.beginTransaction().remove(fragment).commitAllowingStateLoss();
}
} catch (Exception e) {
// ignore
}
}
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method createMeasurementAdapterListener.
private MeasurementAdapterListener createMeasurementAdapterListener(final ItemTouchHelper touchHelper) {
return new MeasurementAdapterListener() {
final MapActivity mapActivity = getMapActivity();
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
private int fromPosition;
private int toPosition;
@Override
public void onRemoveClick(int position) {
if (measurementLayer != null) {
removePoint(measurementLayer, position);
}
}
@Override
public void onItemClick(int position) {
if (mapActivity != null && measurementLayer != null) {
if (pointsListOpened) {
hidePointsList();
}
OsmandMapTileView tileView = mapActivity.getMapView();
if (portrait) {
previousMapPosition = tileView.getMapPosition();
tileView.setMapPosition(MIDDLE_TOP_CONSTANT);
}
mapActivity.refreshMap();
measurementLayer.moveMapToPoint(position);
measurementLayer.selectPoint(position);
}
}
@Override
public void onDragStarted(RecyclerView.ViewHolder holder) {
fromPosition = holder.getAdapterPosition();
touchHelper.startDrag(holder);
}
@Override
public void onDragEnded(RecyclerView.ViewHolder holder) {
if (mapActivity != null && measurementLayer != null) {
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
editingCtx.getCommandManager().execute(new ReorderPointCommand(measurementLayer, fromPosition, toPosition));
adapter.notifyDataSetChanged();
disable(redoBtn);
updateText();
mapActivity.refreshMap();
saved = false;
}
}
}
};
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final MapActivity mapActivity = (MapActivity) getActivity();
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
editingCtx.setApplication(mapActivity.getMyApplication());
editingCtx.setProgressListener(new MeasurementEditingContext.SnapToRoadProgressListener() {
@Override
public void showProgressBar() {
MeasurementToolFragment.this.showProgressBar();
}
@Override
public void updateProgress(int progress) {
((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setProgress(progress);
}
@Override
public void hideProgressBar() {
((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setVisibility(View.GONE);
progressBarVisible = false;
}
@Override
public void refresh() {
measurementLayer.refreshMap();
updateText();
}
});
measurementLayer.setEditingCtx(editingCtx);
// Handling screen rotation
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
Fragment selectedPointFragment = fragmentManager.findFragmentByTag(SelectedPointBottomSheetDialogFragment.TAG);
if (selectedPointFragment != null) {
SelectedPointBottomSheetDialogFragment fragment = (SelectedPointBottomSheetDialogFragment) selectedPointFragment;
fragment.setListener(createSelectedPointFragmentListener());
}
Fragment optionsFragment = fragmentManager.findFragmentByTag(OptionsBottomSheetDialogFragment.TAG);
if (optionsFragment != null) {
((OptionsBottomSheetDialogFragment) optionsFragment).setListener(createOptionsFragmentListener());
}
Fragment snapToRoadFragment = fragmentManager.findFragmentByTag(SnapToRoadBottomSheetDialogFragment.TAG);
if (snapToRoadFragment != null) {
((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener());
}
Fragment saveAsNewTrackFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(SaveAsNewTrackBottomSheetDialogFragment.TAG);
if (saveAsNewTrackFragment != null) {
((SaveAsNewTrackBottomSheetDialogFragment) saveAsNewTrackFragment).setListener(createSaveAsNewTrackFragmentListener());
}
// the RecyclerViewFragment will exist without view. This is necessary to remove it.
if (!portrait) {
hidePointsListFragment();
}
editingCtx.getCommandManager().resetMeasurementLayer(measurementLayer);
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final int backgroundColor = ContextCompat.getColor(getActivity(), nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
upIcon = getContentIcon(R.drawable.ic_action_arrow_up);
downIcon = getContentIcon(R.drawable.ic_action_arrow_down);
pointsSt = getString(R.string.points).toLowerCase();
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_measurement_tool, null);
mainView = view.findViewById(R.id.main_view);
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
pointsListContainer = view.findViewById(R.id.points_list_container);
if (portrait && pointsListContainer != null) {
pointsListContainer.setBackgroundColor(backgroundColor);
}
if (progressBarVisible) {
showProgressBar();
}
distanceTv = (TextView) mainView.findViewById(R.id.measurement_distance_text_view);
pointsTv = (TextView) mainView.findViewById(R.id.measurement_points_text_view);
distanceToCenterTv = (TextView) mainView.findViewById(R.id.distance_to_center_text_view);
mainIcon = (ImageView) mainView.findViewById(R.id.main_icon);
final NewGpxData newGpxData = editingCtx.getNewGpxData();
if (editingCtx.getNewGpxData() != null) {
ActionType actionType = newGpxData.getActionType();
if (actionType == ActionType.ADD_SEGMENT || actionType == ActionType.EDIT_SEGMENT) {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
} else {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_markers_dark));
}
} else {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
}
upDownBtn = (ImageView) mainView.findViewById(R.id.up_down_button);
upDownBtn.setImageDrawable(upIcon);
mainView.findViewById(R.id.cancel_move_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cancelMovePointMode();
}
});
mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cancelAddPointBeforeOrAfterMode();
}
});
upDownRow = mainView.findViewById(R.id.up_down_row);
upDownRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!pointsListOpened && editingCtx.getPointsCount() > 0 && editingCtx.getSelectedPointPosition() == -1) {
showPointsList();
} else {
hidePointsList();
}
}
});
mainView.findViewById(R.id.apply_move_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
applyMovePointMode();
}
});
mainView.findViewById(R.id.apply_point_before_after_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
applyAddPointBeforeAfterMode();
}
});
mainView.findViewById(R.id.add_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addPointBeforeAfter();
}
});
mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle args = new Bundle();
args.putBoolean(OptionsBottomSheetDialogFragment.SNAP_TO_ROAD_ENABLED_KEY, editingCtx.isInSnapToRoadMode());
args.putBoolean(OptionsBottomSheetDialogFragment.ADD_LINE_MODE_KEY, newGpxData != null);
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
fragment.setArguments(args);
fragment.setUsedOnMap(true);
fragment.setListener(createOptionsFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG);
}
});
undoBtn = ((ImageButton) mainView.findViewById(R.id.undo_point_button));
redoBtn = ((ImageButton) mainView.findViewById(R.id.redo_point_button));
undoBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_undo_dark));
undoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editingCtx.getCommandManager().undo();
if (editingCtx.getCommandManager().canUndo()) {
enable(undoBtn);
} else {
disable(undoBtn);
}
hidePointsListIfNoPoints();
if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
adapter.notifyDataSetChanged();
enable(redoBtn);
updateText();
}
});
redoBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_redo_dark));
redoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editingCtx.getCommandManager().redo();
if (editingCtx.getCommandManager().canRedo()) {
enable(redoBtn);
} else {
disable(redoBtn);
}
hidePointsListIfNoPoints();
if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
adapter.notifyDataSetChanged();
enable(undoBtn);
updateText();
}
});
mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addCenterPoint();
}
});
measurementLayer.setOnSingleTapListener(new MeasurementToolLayer.OnSingleTapListener() {
@Override
public void onAddPoint() {
addPoint();
}
@Override
public void onSelectPoint(int selectedPointPos) {
if (pointsListOpened) {
hidePointsList();
}
if (selectedPointPos != -1) {
openSelectedPointMenu(mapActivity);
}
}
});
measurementLayer.setOnMeasureDistanceToCenterListener(new MeasurementToolLayer.OnMeasureDistanceToCenter() {
@Override
public void onMeasure(float distance) {
String distStr = OsmAndFormatter.getFormattedDistance(distance, mapActivity.getMyApplication());
distanceToCenterTv.setText(" – " + distStr);
}
});
measurementLayer.setOnEnterMovePointModeListener(new MeasurementToolLayer.OnEnterMovePointModeListener() {
@Override
public void onEnterMovePointMode() {
if (pointsListOpened) {
hidePointsList();
}
switchMovePointMode(true);
}
});
if (!editingCtx.getCommandManager().canUndo()) {
disable(undoBtn);
}
if (!editingCtx.getCommandManager().canRedo()) {
disable(redoBtn);
}
if (editingCtx.getPointsCount() < 1) {
disable(upDownBtn);
}
toolBarController = new MeasurementToolBarController(newGpxData);
if (editingCtx.getSelectedPointPosition() != -1) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
}
if (newGpxData != null) {
NewGpxData.ActionType actionType = newGpxData.getActionType();
if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
toolBarController.setTitle(getString(R.string.add_route_points));
} else if (actionType == NewGpxData.ActionType.ADD_SEGMENT) {
toolBarController.setTitle(getString(R.string.add_line));
} else if (actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
toolBarController.setTitle(getString(R.string.edit_line));
}
} else {
toolBarController.setTitle(getString(R.string.measurement_tool_action_bar));
}
toolBarController.setOnBackButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
quit(false);
}
});
toolBarController.setOnSaveViewClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editingCtx.getPointsCount() > 0) {
addToGpx(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
}
});
toolBarController.setOnSwitchCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (!checked) {
disableSnapToRoadMode();
}
}
});
mapActivity.showTopToolbar(toolBarController);
adapter = new MeasurementToolAdapter(getMapActivity(), editingCtx.getPoints(), newGpxData != null ? newGpxData.getActionType() : null);
if (portrait) {
pointsRv = mainView.findViewById(R.id.measure_points_recycler_view);
} else {
pointsRv = new RecyclerView(getActivity());
}
final ItemTouchHelper touchHelper = new ItemTouchHelper(new MeasurementToolItemTouchHelperCallback(adapter));
touchHelper.attachToRecyclerView(pointsRv);
adapter.setAdapterListener(createMeasurementAdapterListener(touchHelper));
pointsRv.setLayoutManager(new LinearLayoutManager(getContext()));
pointsRv.setAdapter(adapter);
enterMeasurementMode();
if (editingCtx.isInSnapToRoadMode()) {
showSnapToRoadControls();
}
if (newGpxData != null && !gpxPointsAdded) {
NewGpxData.ActionType actionType = newGpxData.getActionType();
if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
displayRoutePoints();
gpxPointsAdded = true;
} else if (actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
displaySegmentPoints();
gpxPointsAdded = true;
}
}
if (saved == null) {
saved = newGpxData != null && (newGpxData.getActionType() == NewGpxData.ActionType.ADD_ROUTE_POINTS || newGpxData.getActionType() == NewGpxData.ActionType.EDIT_SEGMENT);
}
return view;
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method showQuitDialog.
private void showQuitDialog(boolean hidePointsListFirst) {
final MapActivity mapActivity = getMapActivity();
MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (mapActivity != null && measurementLayer != null) {
if (pointsListOpened && hidePointsListFirst) {
hidePointsList();
return;
}
if (editingCtx.getPointsCount() == 0 || saved) {
dismiss(mapActivity);
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
if (editingCtx.getNewGpxData() == null) {
final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
final LayoutInflater inflater = mapActivity.getLayoutInflater();
final View view = inflater.inflate(R.layout.close_measurement_tool_dialog, null);
final SwitchCompat showOnMapToggle = (SwitchCompat) view.findViewById(R.id.toggle_show_on_map);
builder.setView(view);
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (showOnMapToggle.isChecked()) {
final String name = new SimpleDateFormat("yyyy-MM-dd_HH-mm_EEE", Locale.US).format(new Date());
String fileName = name + GPX_SUFFIX;
File fout = new File(dir, fileName);
int ind = 1;
while (fout.exists()) {
fileName = name + "_" + (++ind) + GPX_SUFFIX;
fout = new File(dir, fileName);
}
saveNewGpx(dir, fileName, true, SaveType.LINE, true);
} else {
dismiss(mapActivity);
}
}
});
} else {
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dismiss(mapActivity);
}
});
}
builder.setTitle(getString(R.string.exit_without_saving)).setMessage(getString(R.string.unsaved_changes_will_be_lost)).setNegativeButton(R.string.shared_string_cancel, null);
builder.show();
}
}
Aggregations