use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method showPointsListFragment.
private void showPointsListFragment() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
boolean transparentStatusBar = Build.VERSION.SDK_INT >= 21;
int statusBarHeight = transparentStatusBar ? 0 : AndroidUtils.getStatusBarHeight(mapActivity);
int screenHeight = AndroidUtils.getScreenHeight(mapActivity) - statusBarHeight;
RecyclerViewFragment fragment = new RecyclerViewFragment();
fragment.setRecyclerView(pointsRv);
fragment.setWidth(upDownRow.getWidth());
fragment.setHeight(screenHeight - upDownRow.getHeight());
fragment.setTransparentStatusBar(transparentStatusBar);
mapActivity.getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, fragment, RecyclerViewFragment.TAG).commitAllowingStateLoss();
}
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method createSnapToRoadFragmentListener.
private SnapToRoadFragmentListener createSnapToRoadFragmentListener() {
return new SnapToRoadFragmentListener() {
@Override
public void onDestroyView(boolean snapToRoadEnabled) {
if (!snapToRoadEnabled && !editingCtx.isInSnapToRoadMode()) {
toolBarController.setTitle(previousToolBarTitle);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.refreshMap();
}
}
}
@Override
public void onApplicationModeItemClick(ApplicationMode mode) {
enableSnapToRoadMode(mode);
}
};
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method showSnapToRoadMenu.
private void showSnapToRoadMenu(boolean rememberPreviousTitle) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (rememberPreviousTitle) {
previousToolBarTitle = toolBarController.getTitle();
}
toolBarController.setTitle(getString(R.string.snap_to_road));
mapActivity.refreshMap();
SnapToRoadBottomSheetDialogFragment fragment = new SnapToRoadBottomSheetDialogFragment();
fragment.setListener(createSnapToRoadFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), SnapToRoadBottomSheetDialogFragment.TAG);
}
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method saveGpx.
private void saveGpx(final File dir, final String fileName, final boolean showOnMap, final GPXFile gpx, final boolean openTrackActivity, final NewGpxData.ActionType actionType, final SaveType saveType, final boolean close) {
new AsyncTask<Void, Void, String>() {
private ProgressDialog progressDialog;
private File toSave;
@Override
protected void onPreExecute() {
cancelModes();
MapActivity activity = getMapActivity();
if (activity != null) {
progressDialog = new ProgressDialog(activity);
progressDialog.setMessage(getString(R.string.saving_gpx_tracks));
progressDialog.show();
}
}
@Override
protected String doInBackground(Void... voids) {
MeasurementToolLayer measurementLayer = getMeasurementLayer();
MapActivity activity = getMapActivity();
List<WptPt> points = editingCtx.getPoints();
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
if (gpx == null) {
toSave = new File(dir, fileName);
GPXFile gpx = new GPXFile();
if (measurementLayer != null) {
if (saveType == SaveType.LINE) {
TrkSegment segment = new TrkSegment();
if (editingCtx.isInSnapToRoadMode()) {
segment.points.addAll(before.points);
segment.points.addAll(after.points);
} else {
segment.points.addAll(points);
}
Track track = new Track();
track.segments.add(segment);
gpx.tracks.add(track);
} else if (saveType == SaveType.ROUTE_POINT) {
if (editingCtx.isInSnapToRoadMode()) {
TrkSegment segment = new TrkSegment();
segment.points.addAll(before.points);
segment.points.addAll(after.points);
Track track = new Track();
track.segments.add(segment);
gpx.tracks.add(track);
}
Route rt = new Route();
gpx.routes.add(rt);
rt.points.addAll(points);
}
}
if (activity != null) {
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());
gpx.path = toSave.getAbsolutePath();
if (showOnMap) {
activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false);
}
return res;
}
} else {
toSave = new File(gpx.path);
if (measurementLayer != null) {
if (actionType != null) {
switch(actionType) {
case ADD_SEGMENT:
if (editingCtx.isInSnapToRoadMode()) {
List<WptPt> snappedPoints = new ArrayList<>();
snappedPoints.addAll(before.points);
snappedPoints.addAll(after.points);
gpx.addTrkSegment(snappedPoints);
} else {
gpx.addTrkSegment(points);
}
break;
case ADD_ROUTE_POINTS:
gpx.replaceRoutePoints(points);
break;
case EDIT_SEGMENT:
TrkSegment segment = new TrkSegment();
segment.points.addAll(points);
gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment);
break;
}
} else {
gpx.addRoutePoints(points);
}
}
if (activity != null) {
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());
if (showOnMap) {
SelectedGpxFile sf = activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false);
if (sf != null) {
if (actionType == NewGpxData.ActionType.ADD_SEGMENT || actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
sf.processPoints();
}
}
}
return res;
}
}
return null;
}
@Override
protected void onPostExecute(String warning) {
MapActivity activity = getMapActivity();
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (activity != null) {
activity.refreshMap();
if (warning == null) {
saved = true;
if (openTrackActivity) {
dismiss(activity);
} else {
Toast.makeText(activity, MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()), Toast.LENGTH_LONG).show();
if (close) {
dismiss(activity);
}
}
} else {
Toast.makeText(activity, warning, Toast.LENGTH_LONG).show();
}
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class RecyclerViewFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final MapActivity mapActivity = (MapActivity) getActivity();
if (rv == null) {
return null;
}
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int backgroundColor = ContextCompat.getColor(getActivity(), nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
final TypedValue typedValueAttr = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.left_menu_view_bg, typedValueAttr, true);
parent = new FrameLayout(mapActivity);
parent.setLayoutParams(new LayoutParams(width + AndroidUtils.dpToPx(getActivity(), 16), height));
parent.setBackgroundResource(typedValueAttr.resourceId);
mainView = new FrameLayout(mapActivity);
mainView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mainView.setBackgroundColor(backgroundColor);
ImageView shadow = new ImageView(mapActivity);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.BOTTOM;
shadow.setLayoutParams(params);
shadow.setScaleType(ImageView.ScaleType.FIT_XY);
shadow.setImageResource(R.drawable.bg_shadow_onmap);
if (transparentStatusBar) {
AndroidUtils.addStatusBarPadding21v(getActivity(), rv);
rv.setClipToPadding(false);
}
mainView.addView(rv);
mainView.addView(shadow);
parent.addView(mainView);
return parent;
}
Aggregations