Search in sources :

Example 36 with MapActivity

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();
    }
}
Also used : MapActivity(net.osmand.plus.activities.MapActivity)

Example 37 with MapActivity

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);
        }
    };
}
Also used : SnapToRoadFragmentListener(net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadFragmentListener) ApplicationMode(net.osmand.plus.ApplicationMode) MapActivity(net.osmand.plus.activities.MapActivity)

Example 38 with MapActivity

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);
    }
}
Also used : MapActivity(net.osmand.plus.activities.MapActivity)

Example 39 with MapActivity

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);
}
Also used : TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) ProgressDialog(android.app.ProgressDialog) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) List(java.util.List) ArrayList(java.util.ArrayList) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) Track(net.osmand.plus.GPXUtilities.Track) Route(net.osmand.plus.GPXUtilities.Route) MapActivity(net.osmand.plus.activities.MapActivity)

Example 40 with MapActivity

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;
}
Also used : LayoutParams(android.widget.LinearLayout.LayoutParams) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity) TypedValue(android.util.TypedValue) Nullable(android.support.annotation.Nullable)

Aggregations

MapActivity (net.osmand.plus.activities.MapActivity)85 View (android.view.View)39 ImageView (android.widget.ImageView)28 TextView (android.widget.TextView)28 RecyclerView (android.support.v7.widget.RecyclerView)15 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)14 AlertDialog (android.support.v7.app.AlertDialog)12 Nullable (android.support.annotation.Nullable)11 DialogInterface (android.content.DialogInterface)10 AdapterView (android.widget.AdapterView)9 LatLon (net.osmand.data.LatLon)9 OsmandApplication (net.osmand.plus.OsmandApplication)9 Bundle (android.os.Bundle)7 Button (android.widget.Button)7 EditText (android.widget.EditText)7 ImageButton (android.widget.ImageButton)7 FavouritePoint (net.osmand.data.FavouritePoint)7 Fragment (android.support.v4.app.Fragment)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 ViewTreeObserver (android.view.ViewTreeObserver)6