Search in sources :

Example 1 with MapRenderRepositories

use of net.osmand.plus.render.MapRenderRepositories in project Osmand by osmandapp.

the class ContextMenuLayer method showContextMenu.

private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
    LatLon objectLatLon = null;
    Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false, showUnknownLocation);
    NativeOsmandLibrary nativeLib = NativeOsmandLibrary.getLoadedLibrary();
    if (nativeLib != null) {
        MapRenderRepositories maps = activity.getMyApplication().getResourceManager().getRenderer();
        RenderingContext rc = maps.getVisibleRenderingContext();
        RenderedObject[] renderedObjects = null;
        if (rc != null && rc.zoom == tileBox.getZoom()) {
            double lat = MapUtils.get31LatitudeY((int) (rc.topY * rc.tileDivisor));
            double lon = MapUtils.get31LongitudeX((int) (rc.leftX * rc.tileDivisor));
            float x = tileBox.getPixXFromLatLon(lat, lon);
            float y = tileBox.getPixYFromLatLon(lat, lon);
            renderedObjects = nativeLib.searchRenderedObjectsFromContext(rc, (int) (point.x - x), (int) (point.y - y));
        }
        if (renderedObjects != null) {
            int TILE_SIZE = 256;
            double cosRotateTileSize = Math.cos(Math.toRadians(rc.rotate)) * TILE_SIZE;
            double sinRotateTileSize = Math.sin(Math.toRadians(rc.rotate)) * TILE_SIZE;
            for (RenderedObject r : renderedObjects) {
                double cx = r.getBbox().centerX();
                double cy = r.getBbox().centerY();
                double dTileX = (cx * cosRotateTileSize + cy * sinRotateTileSize) / (TILE_SIZE * TILE_SIZE);
                double dTileY = (cy * cosRotateTileSize - cx * sinRotateTileSize) / (TILE_SIZE * TILE_SIZE);
                int x31 = (int) ((dTileX + rc.leftX) * rc.tileDivisor);
                int y31 = (int) ((dTileY + rc.topY) * rc.tileDivisor);
                double lat = MapUtils.get31LatitudeY(y31);
                double lon = MapUtils.get31LongitudeX(x31);
                r.setLabelLatLon(new LatLon(lat, lon));
            }
            IContextMenuProvider poiMenuProvider = activity.getMapLayers().getPoiMapLayer();
            for (RenderedObject renderedObject : renderedObjects) {
                if (renderedObject.getX() != null && renderedObject.getX().size() == 1 && renderedObject.getY() != null && renderedObject.getY().size() == 1) {
                    objectLatLon = new LatLon(MapUtils.get31LatitudeY(renderedObject.getY().get(0)), MapUtils.get31LongitudeX(renderedObject.getX().get(0)));
                } else if (renderedObject.getLabelLatLon() != null) {
                    objectLatLon = renderedObject.getLabelLatLon();
                }
                if (renderedObject.getId() != null) {
                    List<String> names = new ArrayList<>();
                    if (!Algorithms.isEmpty(renderedObject.getName())) {
                        names.add(renderedObject.getName());
                    }
                    for (Entry<String, String> entry : renderedObject.getTags().entrySet()) {
                        if (entry.getKey().startsWith("name:") && !entry.getValue().equals("")) {
                            names.add(entry.getValue());
                        }
                        if (entry.getKey().equals("name") && !entry.getValue().equals("")) {
                            names.add(entry.getValue());
                        }
                    }
                    LatLon searchLatLon = objectLatLon;
                    if (searchLatLon == null) {
                        searchLatLon = tileBox.getLatLonFromPixel(point.x, point.y);
                    }
                    Amenity amenity = findAmenity(activity.getMyApplication(), renderedObject.getId() >> 7, names, searchLatLon, 50);
                    if (amenity != null) {
                        if (renderedObject.getX() != null && renderedObject.getX().size() > 1 && renderedObject.getY() != null && renderedObject.getY().size() > 1) {
                            amenity.getX().addAll(renderedObject.getX());
                            amenity.getY().addAll(renderedObject.getY());
                        }
                        boolean exists = false;
                        for (Object o : selectedObjects.keySet()) {
                            if (o instanceof Amenity && ((Amenity) o).compareTo(amenity) == 0) {
                                exists = true;
                                break;
                            }
                        }
                        if (!exists) {
                            selectedObjects.put(amenity, poiMenuProvider);
                        }
                        continue;
                    }
                    selectedObjects.put(renderedObject, null);
                }
            }
        }
    }
    for (Map.Entry<Object, IContextMenuProvider> entry : selectedObjects.entrySet()) {
        IContextMenuProvider provider = entry.getValue();
        if (provider != null && provider.runExclusiveAction(entry.getKey(), showUnknownLocation)) {
            return true;
        }
    }
    if (selectedObjects.size() == 1) {
        Object selectedObj = selectedObjects.keySet().iterator().next();
        LatLon latLon = objectLatLon;
        PointDescription pointDescription = null;
        final IContextMenuProvider provider = selectedObjects.get(selectedObj);
        if (provider != null) {
            if (latLon == null) {
                latLon = provider.getObjectLocation(selectedObj);
            }
            pointDescription = provider.getObjectName(selectedObj);
        }
        if (latLon == null) {
            latLon = getLatLon(point, tileBox);
        }
        if (mInAddGpxPointMode) {
            String title = pointDescription == null ? "" : pointDescription.getName();
            mAddGpxPointBottomSheetHelper.setTitle(title);
            view.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), view.getZoom(), true);
        } else {
            showContextMenu(latLon, pointDescription, selectedObj, provider);
        }
        return true;
    } else if (selectedObjects.size() > 1) {
        selectedObjectContextMenuProvider = null;
        showContextMenuForSelectedObjects(getLatLon(point, tileBox), selectedObjects);
        return true;
    } else if (showUnknownLocation) {
        hideVisibleMenues();
        selectedObjectContextMenuProvider = null;
        LatLon latLon = getLatLon(point, tileBox);
        activity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
        if (mInAddGpxPointMode) {
            mAddGpxPointBottomSheetHelper.setTitle("");
            view.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), view.getZoom(), true);
        } else {
            menu.show(latLon, null, null);
        }
        return true;
    }
    return false;
}
Also used : RenderingContext(net.osmand.RenderingContext) Amenity(net.osmand.data.Amenity) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) Paint(android.graphics.Paint) LatLon(net.osmand.data.LatLon) RenderedObject(net.osmand.NativeLibrary.RenderedObject) PointDescription(net.osmand.data.PointDescription) NativeOsmandLibrary(net.osmand.plus.render.NativeOsmandLibrary) MapRenderRepositories(net.osmand.plus.render.MapRenderRepositories) CallbackWithObject(net.osmand.CallbackWithObject) RenderedObject(net.osmand.NativeLibrary.RenderedObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MapRenderRepositories

use of net.osmand.plus.render.MapRenderRepositories in project Osmand by osmandapp.

the class AppInitializer method checkVectorIndexesDownloaded.

// TODO
public void checkVectorIndexesDownloaded(final Activity ctx) {
    OsmandApplication app = (OsmandApplication) ctx.getApplication();
    MapRenderRepositories maps = app.getResourceManager().getRenderer();
    SharedPreferences pref = ctx.getPreferences(Context.MODE_WORLD_WRITEABLE);
    boolean check = pref.getBoolean(VECTOR_INDEXES_CHECK, true);
    // do not show each time
    if (check && new Random().nextInt() % 5 == 1) {
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        if (maps.isEmpty()) {
            builder.setMessage(R.string.vector_data_missing);
        } else if (!maps.basemapExists()) {
            builder.setMessage(R.string.basemap_missing);
        } else {
            return;
        }
        builder.setPositiveButton(R.string.shared_string_download, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                ctx.startActivity(new Intent(ctx, DownloadActivity.class));
            }
        });
        builder.setNeutralButton(R.string.shared_string_no_thanks, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                ctx.getPreferences(Context.MODE_WORLD_WRITEABLE).edit().putBoolean(VECTOR_INDEXES_CHECK, false).commit();
            }
        });
        builder.setNegativeButton(R.string.first_time_continue, null);
        builder.show();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) PendingIntent(android.app.PendingIntent) LiveUpdatesHelper.getPendingIntent(net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent) Intent(android.content.Intent) LiveUpdatesHelper.setAlarmForPendingIntent(net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIntent) SuppressLint(android.annotation.SuppressLint) Random(java.util.Random) MapRenderRepositories(net.osmand.plus.render.MapRenderRepositories)

Example 3 with MapRenderRepositories

use of net.osmand.plus.render.MapRenderRepositories in project Osmand by osmandapp.

the class TrackSegmentFragment method updateHeader.

private void updateHeader() {
    imageView = (ImageView) headerView.findViewById(R.id.imageView);
    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            GpxDataItem gpxDataItem = getGpxDataItem();
            GPXFile gpx = getGpx();
            WptPt pointToShow = gpx != null ? gpx.findPointToShow() : null;
            if (pointToShow != null) {
                LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude());
                final OsmandSettings settings = app.getSettings();
                String trackName = "";
                if (gpx.showCurrentTrack) {
                    trackName = getString(R.string.shared_string_currently_recording_track);
                } else if (gpxDataItem != null) {
                    trackName = gpxDataItem.getFile().getName();
                } else {
                    trackName = gpx.path;
                }
                settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, trackName), false, getRect());
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        }
    });
    final View splitColorView = headerView.findViewById(R.id.split_color_view);
    final View divider = headerView.findViewById(R.id.divider);
    final View splitIntervalView = headerView.findViewById(R.id.split_interval_view);
    final View colorView = headerView.findViewById(R.id.color_view);
    vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle);
    final ProgressBar progressBar = (ProgressBar) headerView.findViewById(R.id.mapLoadProgress);
    final boolean selected = getGpx() != null && ((getGpx().showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) || (getGpx().path != null && app.getSelectedGpxHelper().getSelectedFileByPath(getGpx().path) != null));
    vis.setChecked(selected);
    vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked) {
                selectedSplitInterval = 0;
            }
            SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
            final List<GpxDisplayGroup> groups = getDisplayGroups();
            if (groups.size() > 0) {
                updateSplit(groups, vis.isChecked() ? sf : null);
                if (getGpxDataItem() != null) {
                    updateSplitInDatabase();
                }
            }
            updateSplitIntervalView(splitIntervalView);
            updateColorView(colorView);
        }
    });
    updateColorView(colorView);
    colorView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            colorListPopupWindow = new ListPopupWindow(getActivity());
            colorListPopupWindow.setAnchorView(colorView);
            colorListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
            colorListPopupWindow.setModal(true);
            colorListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
            colorListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
            colorListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
            final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(getActivity(), getGpx().getColor(0), GpxAppearanceAdapterType.TRACK_COLOR);
            colorListPopupWindow.setAdapter(gpxApprAdapter);
            colorListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    AppearanceListItem item = gpxApprAdapter.getItem(position);
                    if (item != null) {
                        if (item.getAttrName() == CURRENT_TRACK_COLOR_ATTR) {
                            int clr = item.getColor();
                            if (vis.isChecked()) {
                                SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
                                if (clr != 0 && sf.getModifiableGpxFile() != null) {
                                    sf.getModifiableGpxFile().setColor(clr);
                                    if (getGpxDataItem() != null) {
                                        app.getGpxDatabase().updateColor(getGpxDataItem(), clr);
                                    }
                                }
                            } else if (getGpxDataItem() != null) {
                                app.getGpxDatabase().updateColor(getGpxDataItem(), clr);
                            }
                            if (getGpx().showCurrentTrack) {
                                app.getSettings().CURRENT_TRACK_COLOR.set(clr);
                            }
                            refreshTrackBitmap();
                        }
                    }
                    colorListPopupWindow.dismiss();
                    updateColorView(colorView);
                }
            });
            colorListPopupWindow.show();
        }
    });
    boolean hasPath = getGpx() != null && (getGpx().tracks.size() > 0 || getGpx().routes.size() > 0);
    if (rotatedTileBox == null || mapBitmap == null || mapTrackBitmap == null) {
        QuadRect rect = getRect();
        if (rect.left != 0 && rect.top != 0) {
            progressBar.setVisibility(View.VISIBLE);
            double clat = rect.bottom / 2 + rect.top / 2;
            double clon = rect.left / 2 + rect.right / 2;
            WindowManager mgr = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics dm = new DisplayMetrics();
            mgr.getDefaultDisplay().getMetrics(dm);
            RotatedTileBoxBuilder boxBuilder = new RotatedTileBoxBuilder().setLocation(clat, clon).setZoom(15).density(dm.density).setPixelDimensions(dm.widthPixels, AndroidUtils.dpToPx(app, 152f), 0.5f, 0.5f);
            rotatedTileBox = boxBuilder.build();
            while (rotatedTileBox.getZoom() < 17 && rotatedTileBox.containsLatLon(rect.top, rect.left) && rotatedTileBox.containsLatLon(rect.bottom, rect.right)) {
                rotatedTileBox.setZoom(rotatedTileBox.getZoom() + 1);
            }
            while (rotatedTileBox.getZoom() >= 7 && (!rotatedTileBox.containsLatLon(rect.top, rect.left) || !rotatedTileBox.containsLatLon(rect.bottom, rect.right))) {
                rotatedTileBox.setZoom(rotatedTileBox.getZoom() - 1);
            }
            final DrawSettings drawSettings = new DrawSettings(!app.getSettings().isLightContent(), true);
            final ResourceManager resourceManager = app.getResourceManager();
            final MapRenderRepositories renderer = resourceManager.getRenderer();
            if (resourceManager.updateRenderedMapNeeded(rotatedTileBox, drawSettings)) {
                resourceManager.updateRendererMap(rotatedTileBox, new AsyncLoadingThread.OnMapLoadedListener() {

                    @Override
                    public void onMapLoaded(boolean interrupted) {
                        app.runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                if (updateEnable) {
                                    mapBitmap = renderer.getBitmap();
                                    if (mapBitmap != null) {
                                        progressBar.setVisibility(View.GONE);
                                        refreshTrackBitmap();
                                    }
                                }
                            }
                        });
                    }
                });
            }
            imageView.setVisibility(View.VISIBLE);
        } else {
            imageView.setVisibility(View.GONE);
        }
    } else {
        refreshTrackBitmap();
    }
    if (hasPath) {
        if (getGpx() != null && !getGpx().showCurrentTrack && adapter.getCount() > 0) {
            prepareSplitIntervalAdapterData();
            setupSplitIntervalView(splitIntervalView);
            updateSplitIntervalView(splitIntervalView);
            splitIntervalView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    splitListPopupWindow = new ListPopupWindow(getActivity());
                    splitListPopupWindow.setAnchorView(splitIntervalView);
                    splitListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
                    splitListPopupWindow.setModal(true);
                    splitListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
                    splitListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
                    splitListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
                    splitListPopupWindow.setAdapter(new ArrayAdapter<>(getTrackActivity(), R.layout.popup_list_text_item, options));
                    splitListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            selectedSplitInterval = position;
                            SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
                            final List<GpxDisplayGroup> groups = getDisplayGroups();
                            if (groups.size() > 0) {
                                updateSplit(groups, vis.isChecked() ? sf : null);
                                if (getGpxDataItem() != null) {
                                    updateSplitInDatabase();
                                }
                            }
                            splitListPopupWindow.dismiss();
                            updateSplitIntervalView(splitIntervalView);
                        }
                    });
                    splitListPopupWindow.show();
                }
            });
            splitIntervalView.setVisibility(View.VISIBLE);
        } else {
            splitIntervalView.setVisibility(View.GONE);
        }
        splitColorView.setVisibility(View.VISIBLE);
        divider.setVisibility(View.VISIBLE);
    } else {
        splitColorView.setVisibility(View.GONE);
        divider.setVisibility(View.GONE);
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) GpxDisplayGroup(net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup) QuadRect(net.osmand.data.QuadRect) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager) AppearanceListItem(net.osmand.plus.dialogs.ConfigureMapMenu.AppearanceListItem) ListPopupWindow(android.support.v7.widget.ListPopupWindow) GpxAppearanceAdapter(net.osmand.plus.dialogs.ConfigureMapMenu.GpxAppearanceAdapter) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) MapRenderRepositories(net.osmand.plus.render.MapRenderRepositories) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ProgressBar(android.widget.ProgressBar) ResourceManager(net.osmand.plus.resources.ResourceManager) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) OsmandSettings(net.osmand.plus.OsmandSettings) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) LatLon(net.osmand.data.LatLon) RotatedTileBoxBuilder(net.osmand.data.RotatedTileBox.RotatedTileBoxBuilder) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) PointDescription(net.osmand.data.PointDescription) AdapterView(android.widget.AdapterView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) AsyncLoadingThread(net.osmand.plus.resources.AsyncLoadingThread) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

MapRenderRepositories (net.osmand.plus.render.MapRenderRepositories)3 Paint (android.graphics.Paint)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 ArrayList (java.util.ArrayList)2 LatLon (net.osmand.data.LatLon)2 PointDescription (net.osmand.data.PointDescription)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 AlertDialog (android.support.v7.app.AlertDialog)1 ListPopupWindow (android.support.v7.widget.ListPopupWindow)1 DisplayMetrics (android.util.DisplayMetrics)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 CompoundButton (android.widget.CompoundButton)1