Search in sources :

Example 21 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class ExternalApiHelper method processApiRequest.

public Intent processApiRequest(Intent intent) {
    Intent result = new Intent();
    OsmandApplication app = (OsmandApplication) mapActivity.getApplication();
    try {
        Uri uri = intent.getData();
        String cmd = uri.getHost().toLowerCase();
        if (API_CMD_SHOW_GPX.equals(cmd) || API_CMD_NAVIGATE_GPX.equals(cmd)) {
            boolean navigate = API_CMD_NAVIGATE_GPX.equals(cmd);
            String path = uri.getQueryParameter(PARAM_PATH);
            boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
            GPXFile gpx = null;
            if (path != null) {
                File f = new File(path);
                if (f.exists()) {
                    gpx = GPXUtilities.loadGPXFile(mapActivity, f);
                }
            } else if (intent.getStringExtra(PARAM_DATA) != null) {
                String gpxStr = intent.getStringExtra(PARAM_DATA);
                if (!Algorithms.isEmpty(gpxStr)) {
                    gpx = GPXUtilities.loadGPXFile(mapActivity, new ByteArrayInputStream(gpxStr.getBytes()));
                }
            } else if (uri.getBooleanQueryParameter(PARAM_URI, false)) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    LOG.debug("uriString=" + intent.getClipData().getItemAt(0).getUri());
                    Uri gpxUri = intent.getClipData().getItemAt(0).getUri();
                    ParcelFileDescriptor gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r");
                    if (gpxParcelDescriptor != null) {
                        FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor();
                        gpx = GPXUtilities.loadGPXFile(mapActivity, new FileInputStream(fileDescriptor));
                    } else {
                        finish = true;
                        resultCode = RESULT_CODE_ERROR_GPX_NOT_FOUND;
                    }
                } else {
                    finish = true;
                    resultCode = RESULT_CODE_ERROR_GPX_NOT_FOUND;
                }
            } else {
                finish = true;
                resultCode = RESULT_CODE_ERROR_GPX_NOT_FOUND;
            }
            if (gpx != null) {
                if (navigate) {
                    final RoutingHelper routingHelper = app.getRoutingHelper();
                    if (routingHelper.isFollowingMode() && !force) {
                        final GPXFile gpxFile = gpx;
                        AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
                        dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {

                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                if (!routingHelper.isFollowingMode()) {
                                    startNavigation(gpxFile, null, null, null, null, null);
                                }
                            }
                        });
                    } else {
                        startNavigation(gpx, null, null, null, null, null);
                    }
                } else {
                    app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
                }
                resultCode = Activity.RESULT_OK;
            } else {
                finish = true;
                resultCode = RESULT_CODE_ERROR_GPX_NOT_FOUND;
            }
        } else if (API_CMD_NAVIGATE.equals(cmd)) {
            String profileStr = uri.getQueryParameter(PARAM_PROFILE);
            final ApplicationMode profile = ApplicationMode.valueOfStringKey(profileStr, DEFAULT_PROFILE);
            boolean validProfile = false;
            for (ApplicationMode mode : VALID_PROFILES) {
                if (mode == profile) {
                    validProfile = true;
                    break;
                }
            }
            if (!validProfile) {
                resultCode = RESULT_CODE_ERROR_INVALID_PROFILE;
            } else {
                String startName = uri.getQueryParameter(PARAM_START_NAME);
                if (Algorithms.isEmpty(startName)) {
                    startName = "";
                }
                String destName = uri.getQueryParameter(PARAM_DEST_NAME);
                if (Algorithms.isEmpty(destName)) {
                    destName = "";
                }
                final LatLon start;
                final PointDescription startDesc;
                String startLatStr = uri.getQueryParameter(PARAM_START_LAT);
                String startLonStr = uri.getQueryParameter(PARAM_START_LON);
                if (!Algorithms.isEmpty(startLatStr) && !Algorithms.isEmpty(startLonStr)) {
                    double lat = Double.parseDouble(uri.getQueryParameter(PARAM_START_LAT));
                    double lon = Double.parseDouble(uri.getQueryParameter(PARAM_START_LON));
                    start = new LatLon(lat, lon);
                    startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
                } else {
                    start = null;
                    startDesc = null;
                }
                double destLat = Double.parseDouble(uri.getQueryParameter(PARAM_DEST_LAT));
                double destLon = Double.parseDouble(uri.getQueryParameter(PARAM_DEST_LON));
                final LatLon dest = new LatLon(destLat, destLon);
                final PointDescription destDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, destName);
                boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
                final RoutingHelper routingHelper = app.getRoutingHelper();
                if (routingHelper.isFollowingMode() && !force) {
                    AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
                    dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            if (!routingHelper.isFollowingMode()) {
                                startNavigation(null, start, startDesc, dest, destDesc, profile);
                            }
                        }
                    });
                } else {
                    startNavigation(null, start, startDesc, dest, destDesc, profile);
                }
            }
        } else if (API_CMD_RECORD_AUDIO.equals(cmd) || API_CMD_RECORD_VIDEO.equals(cmd) || API_CMD_RECORD_PHOTO.equals(cmd) || API_CMD_STOP_AV_REC.equals(cmd)) {
            AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
            if (plugin == null) {
                resultCode = RESULT_CODE_ERROR_PLUGIN_INACTIVE;
                finish = true;
            } else {
                if (API_CMD_STOP_AV_REC.equals(cmd)) {
                    plugin.stopRecording(mapActivity, false);
                } else {
                    double lat = Double.parseDouble(uri.getQueryParameter(PARAM_LAT));
                    double lon = Double.parseDouble(uri.getQueryParameter(PARAM_LON));
                    if (API_CMD_RECORD_AUDIO.equals(cmd)) {
                        plugin.recordAudio(lat, lon, mapActivity);
                    } else if (API_CMD_RECORD_VIDEO.equals(cmd)) {
                        plugin.recordVideo(lat, lon, mapActivity, false);
                    } else if (API_CMD_RECORD_PHOTO.equals(cmd)) {
                        plugin.takePhoto(lat, lon, mapActivity, true, false);
                    }
                }
                resultCode = Activity.RESULT_OK;
            }
        } else if (API_CMD_GET_INFO.equals(cmd)) {
            Location location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
            if (location != null) {
                result.putExtra(PARAM_LAT, location.getLatitude());
                result.putExtra(PARAM_LON, location.getLongitude());
            }
            final RoutingHelper routingHelper = app.getRoutingHelper();
            if (routingHelper.isRouteCalculated()) {
                int time = routingHelper.getLeftTime();
                result.putExtra(PARAM_TIME_LEFT, time);
                long eta = time + System.currentTimeMillis() / 1000;
                result.putExtra(PARAM_ETA, eta);
                result.putExtra(PARAM_DISTANCE_LEFT, routingHelper.getLeftDistance());
                NextDirectionInfo ni = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), true);
                if (ni.distanceTo > 0) {
                    updateTurnInfo("next_", result, ni);
                    ni = routingHelper.getNextRouteDirectionInfoAfter(ni, new NextDirectionInfo(), true);
                    if (ni.distanceTo > 0) {
                        updateTurnInfo("after_next", result, ni);
                    }
                }
                routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false);
                if (ni.distanceTo > 0) {
                    updateTurnInfo("no_speak_next_", result, ni);
                }
            }
            result.putExtra(PARAM_VERSION, VERSION_CODE);
            finish = true;
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_ADD_FAVORITE.equals(cmd)) {
            String name = uri.getQueryParameter(PARAM_NAME);
            String desc = uri.getQueryParameter(PARAM_DESC);
            String category = uri.getQueryParameter(PARAM_CATEGORY);
            double lat = Double.parseDouble(uri.getQueryParameter(PARAM_LAT));
            double lon = Double.parseDouble(uri.getQueryParameter(PARAM_LON));
            String colorTag = uri.getQueryParameter(PARAM_COLOR);
            boolean visible = uri.getBooleanQueryParameter(PARAM_VISIBLE, true);
            if (name == null) {
                name = "";
            }
            if (desc == null) {
                desc = "";
            }
            if (category == null) {
                category = "";
            }
            int color = 0;
            if (!Algorithms.isEmpty(colorTag)) {
                color = ColorDialogs.getColorByTag(colorTag);
                if (color == 0) {
                    LOG.error("Wrong color tag: " + colorTag);
                }
            }
            FavouritePoint fav = new FavouritePoint(lat, lon, name, category);
            fav.setDescription(desc);
            fav.setColor(color);
            fav.setVisible(visible);
            FavouritesDbHelper helper = app.getFavorites();
            helper.addFavourite(fav);
            showOnMap(lat, lon, fav, mapActivity.getMapLayers().getFavouritesLayer().getObjectName(fav));
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_ADD_MAP_MARKER.equals(cmd)) {
            double lat = Double.parseDouble(uri.getQueryParameter(PARAM_LAT));
            double lon = Double.parseDouble(uri.getQueryParameter(PARAM_LON));
            String name = uri.getQueryParameter(PARAM_NAME);
            PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name != null ? name : "");
            MapMarkersHelper markersHelper = app.getMapMarkersHelper();
            markersHelper.addMapMarker(new LatLon(lat, lon), pd);
            MapMarker marker = markersHelper.getFirstMapMarker();
            if (marker != null) {
                showOnMap(lat, lon, marker, mapActivity.getMapLayers().getMapMarkersLayer().getObjectName(marker));
            }
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_START_GPX_REC.equals(cmd)) {
            OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
            if (plugin == null) {
                resultCode = RESULT_CODE_ERROR_PLUGIN_INACTIVE;
                finish = true;
            } else {
                plugin.startGPXMonitoring(null);
            }
            if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
                finish = true;
            }
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_STOP_GPX_REC.equals(cmd)) {
            OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
            if (plugin == null) {
                resultCode = RESULT_CODE_ERROR_PLUGIN_INACTIVE;
                finish = true;
            } else {
                plugin.stopRecording();
            }
            if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
                finish = true;
            }
            resultCode = Activity.RESULT_OK;
        } else if (API_CMD_SUBSCRIBE_VOICE_NOTIFICATIONS.equals(cmd)) {
            // not implemented yet
            resultCode = RESULT_CODE_ERROR_NOT_IMPLEMENTED;
        }
    } catch (Exception e) {
        LOG.error("Error processApiRequest:", e);
        resultCode = RESULT_CODE_ERROR_UNKNOWN;
    }
    return result;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) AudioVideoNotesPlugin(net.osmand.plus.audionotes.AudioVideoNotesPlugin) FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) DialogInterface(android.content.DialogInterface) ApplicationMode(net.osmand.plus.ApplicationMode) Uri(android.net.Uri) OsmandMonitoringPlugin(net.osmand.plus.monitoring.OsmandMonitoringPlugin) NextDirectionInfo(net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo) Intent(android.content.Intent) RoutingHelper(net.osmand.plus.routing.RoutingHelper) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor) FileInputStream(java.io.FileInputStream) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) ByteArrayInputStream(java.io.ByteArrayInputStream) PointDescription(net.osmand.data.PointDescription) ParcelFileDescriptor(android.os.ParcelFileDescriptor) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) Location(net.osmand.Location)

Example 22 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class WaypointDialogHelper method updatePointInfoView.

public static void updatePointInfoView(final OsmandApplication app, final Activity activity, View localView, final LocationPointWrapper ps, final boolean mapCenter, final boolean nightMode, final boolean edit, final boolean topBar) {
    WaypointHelper wh = app.getWaypointHelper();
    final LocationPoint point = ps.getPoint();
    TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
    if (!topBar) {
        AndroidUtils.setTextPrimaryColor(activity, text, nightMode);
    }
    TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
    if (!edit) {
        localView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                showOnMap(app, activity, point, mapCenter);
            }
        });
    }
    TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
    ((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(activity, app, nightMode));
    int dist = -1;
    boolean startPoint = ps.type == WaypointHelper.TARGETS && ((TargetPoint) ps.point).start;
    if (!startPoint) {
        if (!wh.isRouteCalculated()) {
            if (activity instanceof MapActivity) {
                dist = (int) MapUtils.getDistance(((MapActivity) activity).getMapView().getLatitude(), ((MapActivity) activity).getMapView().getLongitude(), point.getLatitude(), point.getLongitude());
            }
        } else {
            dist = wh.getRouteDistance(ps);
        }
    }
    if (dist > 0) {
        textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
    } else {
        textDist.setText("");
    }
    TextView textDeviation = (TextView) localView.findViewById(R.id.waypoint_deviation);
    if (textDeviation != null) {
        if (dist > 0 && ps.deviationDistance > 0) {
            String devStr = "+" + OsmAndFormatter.getFormattedDistance(ps.deviationDistance, app);
            textDeviation.setText(devStr);
            if (!topBar) {
                int colorId = nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light;
                AndroidUtils.setTextSecondaryColor(activity, textDeviation, nightMode);
                if (ps.deviationDirectionRight) {
                    textDeviation.setCompoundDrawablesWithIntrinsicBounds(app.getIconsCache().getIcon(R.drawable.ic_small_turn_right, colorId), null, null, null);
                } else {
                    textDeviation.setCompoundDrawablesWithIntrinsicBounds(app.getIconsCache().getIcon(R.drawable.ic_small_turn_left, colorId), null, null, null);
                }
            }
            textDeviation.setVisibility(View.VISIBLE);
        } else {
            textDeviation.setText("");
            textDeviation.setVisibility(View.GONE);
        }
    }
    String descr;
    PointDescription pd = point.getPointDescription(app);
    if (Algorithms.isEmpty(pd.getName())) {
        descr = pd.getTypeName();
    } else {
        descr = pd.getName();
    }
    if (textShadow != null) {
        textShadow.setText(descr);
    }
    text.setText(descr);
    String pointDescription = "";
    TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
    if (descText != null) {
        AndroidUtils.setTextSecondaryColor(activity, descText, nightMode);
        switch(ps.type) {
            case WaypointHelper.TARGETS:
                TargetPoint targetPoint = (TargetPoint) ps.point;
                if (targetPoint.start) {
                    pointDescription = activity.getResources().getString(R.string.starting_point);
                } else {
                    pointDescription = targetPoint.getPointDescription(activity).getTypeName();
                }
                break;
            case WaypointHelper.FAVORITES:
                FavouritePoint favPoint = (FavouritePoint) ps.point;
                pointDescription = Algorithms.isEmpty(favPoint.getCategory()) ? activity.getResources().getString(R.string.shared_string_favorites) : favPoint.getCategory();
                break;
        }
    }
    if (Algorithms.objectEquals(descr, pointDescription)) {
        pointDescription = "";
    }
    if (dist > 0 && !Algorithms.isEmpty(pointDescription)) {
        pointDescription = "  •  " + pointDescription;
    }
    if (descText != null) {
        descText.setText(pointDescription);
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) LocationPoint(net.osmand.data.LocationPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) SuppressLint(android.annotation.SuppressLint) FavouritePoint(net.osmand.data.FavouritePoint) PointDescription(net.osmand.data.PointDescription) TextView(android.widget.TextView) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 23 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class WaypointDialogHelper method getStandardPoints.

protected List<Object> getStandardPoints() {
    final List<Object> points = new ArrayList<>();
    boolean rc = waypointHelper.isRouteCalculated();
    for (int i = 0; i < WaypointHelper.MAX; i++) {
        List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i);
        if ((rc || i == WaypointHelper.WAYPOINTS || i == WaypointHelper.TARGETS) && waypointHelper.isTypeVisible(i)) {
            if (points.size() > 0) {
                points.add(true);
            }
            points.add(i);
            if (i == WaypointHelper.TARGETS) {
                TargetPoint start = app.getTargetPointsHelper().getPointToStart();
                if (start == null) {
                    LatLon latLon;
                    Location loc = app.getLocationProvider().getLastKnownLocation();
                    if (loc != null) {
                        latLon = new LatLon(loc.getLatitude(), loc.getLongitude());
                    } else {
                        latLon = new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude());
                    }
                    start = TargetPoint.createStartPoint(latLon, new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location)));
                } else {
                    String oname = start.getOnlyName().length() > 0 ? start.getOnlyName() : (mapActivity.getString(R.string.route_descr_map_location) + " " + mapActivity.getString(R.string.route_descr_lat_lon, start.getLatitude(), start.getLongitude()));
                    start = TargetPoint.createStartPoint(new LatLon(start.getLatitude(), start.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_LOCATION, oname));
                }
                points.add(new LocationPointWrapper(null, WaypointHelper.TARGETS, start, 0f, 0));
            } else if ((i == WaypointHelper.POI || i == WaypointHelper.FAVORITES || i == WaypointHelper.WAYPOINTS) && rc) {
                if (waypointHelper.isTypeEnabled(i)) {
                    points.add(new RadiusItem(i));
                }
            }
            if (tp != null && tp.size() > 0) {
                points.addAll(tp);
            }
            points.add(false);
        }
    }
    return points;
}
Also used : ArrayList(java.util.ArrayList) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) SuppressLint(android.annotation.SuppressLint) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) Location(net.osmand.Location)

Example 24 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class WptPtMenuBuilder method getCollapsableWaypointsView.

private CollapsableView getCollapsableWaypointsView(final Context context, boolean collapsed, @NonNull final GPXUtilities.GPXFile gpxFile, WptPt selectedPoint) {
    LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
    List<WptPt> points = gpxFile.getPoints();
    for (int i = 0; i < points.size() && i < 10; i++) {
        final WptPt point = points.get(i);
        boolean selected = selectedPoint != null && selectedPoint.equals(point);
        TextViewEx button = buildButtonInCollapsableView(context, selected, false);
        button.setText(point.name);
        if (!selected) {
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    LatLon latLon = new LatLon(point.getLatitude(), point.getLongitude());
                    PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, point.name);
                    mapActivity.getContextMenu().show(latLon, pointDescription, point);
                }
            });
        }
        view.addView(button);
    }
    if (points.size() > 10) {
        TextViewEx button = buildButtonInCollapsableView(context, false, true);
        button.setText(context.getString(R.string.shared_string_show_all));
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                OsmAndAppCustomization appCustomization = app.getAppCustomization();
                final Intent intent = new Intent(context, appCustomization.getTrackActivity());
                intent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxFile.path);
                intent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                context.startActivity(intent);
            }
        });
        view.addView(button);
    }
    return new CollapsableView(view, this, collapsed);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) Intent(android.content.Intent) View(android.view.View) LatLon(net.osmand.data.LatLon) TextViewEx(net.osmand.plus.widgets.TextViewEx) OsmAndAppCustomization(net.osmand.plus.OsmAndAppCustomization) PointDescription(net.osmand.data.PointDescription) LinearLayout(android.widget.LinearLayout)

Example 25 with PointDescription

use of net.osmand.data.PointDescription in project Osmand by osmandapp.

the class MapMarkersDbHelper method insertLast.

private void insertLast(SQLiteConnection db, MapMarker marker, boolean saveExisting) {
    long currentTime;
    if (saveExisting) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, -1);
        currentTime = cal.getTimeInMillis();
    } else {
        currentTime = System.currentTimeMillis();
    }
    if (marker.id == null) {
        marker.id = String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100);
    }
    marker.creationDate = currentTime;
    String descr = PointDescription.serializeToString(marker.getOriginalPointDescription());
    int active = marker.history ? 0 : 1;
    long visited = saveExisting ? currentTime : 0;
    PointDescription pointDescription = marker.getOriginalPointDescription();
    if (pointDescription != null && !pointDescription.isSearchingAddress(context)) {
        SearchHistoryHelper.getInstance(context).addNewItemToHistory(marker.getLatitude(), marker.getLongitude(), pointDescription);
    }
    if (!marker.history) {
        db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[] { marker.id, TAIL_NEXT_VALUE });
    }
    db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " (" + MARKERS_COL_ID + ", " + MARKERS_COL_LAT + ", " + MARKERS_COL_LON + ", " + MARKERS_COL_DESCRIPTION + ", " + MARKERS_COL_ACTIVE + ", " + MARKERS_COL_ADDED + ", " + MARKERS_COL_VISITED + ", " + MARKERS_COL_GROUP_NAME + ", " + MARKERS_COL_GROUP_KEY + ", " + MARKERS_COL_COLOR + ", " + MARKERS_COL_NEXT_KEY + ", " + MARKERS_COL_DISABLED + ", " + MARKERS_COL_SELECTED + ", " + MARKERS_COL_MAP_OBJECT_NAME + ") " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] { marker.id, marker.getLatitude(), marker.getLongitude(), descr, active, currentTime, visited, marker.groupName, marker.groupKey, marker.colorIndex, marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE, 0, 0, marker.mapObjectName });
}
Also used : Random(java.util.Random) Calendar(java.util.Calendar) PointDescription(net.osmand.data.PointDescription)

Aggregations

PointDescription (net.osmand.data.PointDescription)72 LatLon (net.osmand.data.LatLon)44 View (android.view.View)16 ImageView (android.widget.ImageView)13 TextView (android.widget.TextView)13 ArrayList (java.util.ArrayList)13 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)13 FavouritePoint (net.osmand.data.FavouritePoint)12 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)11 OsmandApplication (net.osmand.plus.OsmandApplication)10 OsmandSettings (net.osmand.plus.OsmandSettings)10 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 Amenity (net.osmand.data.Amenity)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 RoutingHelper (net.osmand.plus.routing.RoutingHelper)7 Intent (android.content.Intent)6 Paint (android.graphics.Paint)6 LinearLayout (android.widget.LinearLayout)6 Location (net.osmand.Location)6 DialogInterface (android.content.DialogInterface)5