Search in sources :

Example 1 with MapControlsLayer

use of net.osmand.plus.views.MapControlsLayer in project Osmand by osmandapp.

the class MapActivityActions method createMainOptionsMenu.

public ContextMenuAdapter createMainOptionsMenu() {
    final OsmandMapTileView mapView = mapActivity.getMapView();
    final OsmandApplication app = mapActivity.getMyApplication();
    ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter();
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.home, mapActivity).setIcon(R.drawable.map_dashboard).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_dashboard_open");
            MapActivity.clearPrevActivityIntent();
            mapActivity.closeDrawer();
            mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.DASHBOARD, viewCoordinates);
            return true;
        }
    }).createItem());
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.map_markers, mapActivity).setIcon(R.drawable.ic_action_flag_dark).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_markers_open");
            MapActivity.clearPrevActivityIntent();
            MapMarkersDialogFragment.showInstance(mapActivity);
            return true;
        }
    }).createItem());
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_my_places, mapActivity).setIcon(R.drawable.ic_action_fav_dark).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_myplaces_open");
            Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getFavoritesActivity());
            newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            mapActivity.startActivity(newIntent);
            return true;
        }
    }).createItem());
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.search_button, mapActivity).setIcon(R.drawable.ic_action_search_dark).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_search_open");
            mapActivity.showQuickSearch(MapActivity.ShowQuickSearchMode.NEW_IF_EXPIRED, false);
            return true;
        }
    }).createItem());
    if (settings.SHOW_LEGACY_SEARCH.get()) {
        optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.legacy_search, mapActivity).setIcon(R.drawable.ic_action_search_dark).setListener(new ContextMenuAdapter.ItemClickListener() {

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
                app.logEvent(mapActivity, "drawer_legacy_search_open");
                Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getSearchActivity());
                LatLon loc = mapActivity.getMapLocation();
                newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude());
                newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude());
                if (mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
                    newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true);
                }
                newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                mapActivity.startActivity(newIntent);
                return true;
            }
        }).createItem());
    }
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.get_directions, mapActivity).setIcon(R.drawable.ic_action_gdirections_dark).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_directions_open");
            MapControlsLayer mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer();
            if (mapControlsLayer != null) {
                mapControlsLayer.doRoute(false);
            }
            return true;
        }
    }).createItem());
    /*
		optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_point_options, mapActivity)
				.setIcon(R.drawable.ic_action_marker_dark)
				.setListener(new ContextMenuAdapter.ItemClickListener() {
					@Override
					public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
						MapActivity.clearPrevActivityIntent();
						mapActivity.getMapLayers().getContextMenuLayer().showContextMenu(mapView.getLatitude(), mapView.getLongitude(), true);
						return true;
					}
				}).createItem());
		*/
    optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.configure_map, mapActivity).setIcon(R.drawable.ic_action_layers_dark).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_config_map_open");
            MapActivity.clearPrevActivityIntent();
            mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP, viewCoordinates);
            return false;
        }
    }).createItem());
    String d = getString(R.string.welmode_download_maps);
    if (app.getDownloadThread().getIndexes().isDownloadedFromInternet) {
        List<IndexItem> updt = app.getDownloadThread().getIndexes().getItemsToUpdate();
        if (updt != null && updt.size() > 0) {
            d += " (" + updt.size() + ")";
        }
    }
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.welmode_download_maps, null).setTitle(d).setIcon(R.drawable.ic_type_archive).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_download_maps_open");
            Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getDownloadActivity());
            newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            mapActivity.startActivity(newIntent);
            return true;
        }
    }).createItem());
    if (Version.isGooglePlayEnabled(app) || Version.isDeveloperVersion(app)) {
        optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.osm_live, mapActivity).setIcon(R.drawable.ic_action_osm_live).setListener(new ContextMenuAdapter.ItemClickListener() {

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
                app.logEvent(mapActivity, "drawer_osm_live_open");
                Intent intent = new Intent(mapActivity, OsmLiveActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                mapActivity.startActivity(intent);
                return false;
            }
        }).createItem());
    }
    if (WikivoyageDbHelper.isDbFileExists(app)) {
        optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_travel, mapActivity).setIcon(R.drawable.ic_action_travel).setListener(new ItemClickListener() {

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
                MapActivity.clearPrevActivityIntent();
                WikivoyageExploreDialogFragment.showInstance(mapActivity.getSupportFragmentManager());
                return true;
            }
        }).createItem());
    }
    optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.measurement_tool, mapActivity).setIcon(R.drawable.ic_action_ruler).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
            MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager());
            return true;
        }
    }).createItem());
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.layer_map_appearance, mapActivity).setIcon(R.drawable.ic_configure_screen_dark).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_config_screen_open");
            MapActivity.clearPrevActivityIntent();
            mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN, viewCoordinates);
            return false;
        }
    }).createItem());
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.prefs_plugins, mapActivity).setIcon(R.drawable.ic_extension_dark).setListener(new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_plugins_open");
            Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getPluginsActivity());
            newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            mapActivity.startActivity(newIntent);
            return true;
        }
    }).createItem());
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_settings, mapActivity).setIcon(R.drawable.ic_action_settings).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_settings_open");
            final Intent settings = new Intent(mapActivity, getMyApplication().getAppCustomization().getSettingsActivity());
            settings.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            mapActivity.startActivity(settings);
            return true;
        }
    }).createItem());
    /*
		optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.configure_map, mapActivity)
				.setIcon(R.drawable.ic_action_layers_dark)
				.setListener(new ContextMenuAdapter.ItemClickListener() {
					@Override
					public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
						MapActivity.clearPrevActivityIntent();
						mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP);
						return false;
					}
				}).createItem());
		*/
    optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_help, mapActivity).setIcon(R.drawable.ic_action_help).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
            app.logEvent(mapActivity, "drawer_help_open");
            Intent intent = new Intent(mapActivity, HelpActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            mapActivity.startActivity(intent);
            return true;
        }
    }).createItem());
    // ////////// Others
    OsmandPlugin.registerOptionsMenu(mapActivity, optionsMenuHelper);
    // Place divider between functionality and configuration related menu items
    int dividerItemIndex = -1;
    for (int i = 0; i < optionsMenuHelper.length(); i++) {
        if (optionsMenuHelper.getItem(i).getTitleId() == R.string.layer_map_appearance) {
            dividerItemIndex = i;
            break;
        }
    }
    ItemBuilder divider = new ItemBuilder().setLayout(R.layout.drawer_divider);
    divider.setPosition(dividerItemIndex >= 0 ? dividerItemIndex : 8);
    optionsMenuHelper.addItem(divider.createItem());
    getMyApplication().getAppCustomization().prepareOptionsMenu(mapActivity, optionsMenuHelper);
    return optionsMenuHelper;
}
Also used : MapControlsLayer(net.osmand.plus.views.MapControlsLayer) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem) Intent(android.content.Intent) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) IndexItem(net.osmand.plus.download.IndexItem) OsmLiveActivity(net.osmand.plus.liveupdates.OsmLiveActivity) LatLon(net.osmand.data.LatLon) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder)

Example 2 with MapControlsLayer

use of net.osmand.plus.views.MapControlsLayer in project Osmand by osmandapp.

the class MapActivity method onRequestPermissionsResult.

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull final int[] grantResults) {
    if (grantResults.length > 0) {
        OsmandPlugin.onRequestPermissionsResult(requestCode, permissions, grantResults);
        MapControlsLayer mcl = mapView.getLayerByClass(MapControlsLayer.class);
        if (mcl != null) {
            mcl.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
        if (requestCode == DownloadActivity.PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0 && permissions.length > 0 && Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permissions[0])) {
            permissionAsked = true;
            permissionGranted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
        } else if (requestCode == FirstUsageWizardFragment.FIRST_USAGE_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION && grantResults.length > 0 && permissions.length > 0 && Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permissions[0])) {
            new Timer().schedule(new TimerTask() {

                @Override
                public void run() {
                    FirstUsageWizardFragment wizardFragment = getFirstUsageWizardFragment();
                    if (wizardFragment != null) {
                        wizardFragment.processStoragePermission(grantResults[0] == PackageManager.PERMISSION_GRANTED);
                    }
                }
            }, 1);
        } else if (requestCode == FirstUsageWizardFragment.FIRST_USAGE_LOCATION_PERMISSION) {
            new Timer().schedule(new TimerTask() {

                @Override
                public void run() {
                    FirstUsageWizardFragment wizardFragment = getFirstUsageWizardFragment();
                    if (wizardFragment != null) {
                        wizardFragment.processLocationPermission(grantResults[0] == PackageManager.PERMISSION_GRANTED);
                    }
                }
            }, 1);
        }
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
Also used : MapControlsLayer(net.osmand.plus.views.MapControlsLayer) Timer(java.util.Timer) TimerTask(java.util.TimerTask) FirstUsageWizardFragment(net.osmand.plus.firstusage.FirstUsageWizardFragment)

Example 3 with MapControlsLayer

use of net.osmand.plus.views.MapControlsLayer in project Osmand by osmandapp.

the class MapActivityLayers method createLayers.

public void createLayers(final OsmandMapTileView mapView) {
    OsmandApplication app = getApplication();
    RoutingHelper routingHelper = app.getRoutingHelper();
    // first create to make accessible
    mapTextLayer = new MapTextLayer();
    // 5.95 all labels
    mapView.addLayer(mapTextLayer, 5.95f);
    // 8. context menu layer
    contextMenuLayer = new ContextMenuLayer(activity);
    mapView.addLayer(contextMenuLayer, 8);
    // mapView.addLayer(underlayLayer, -0.5f);
    mapTileLayer = new MapTileLayer(true);
    mapView.addLayer(mapTileLayer, 0.0f);
    mapView.setMainLayer(mapTileLayer);
    // 0.5 layer
    mapVectorLayer = new MapVectorLayer(mapTileLayer, false);
    mapView.addLayer(mapVectorLayer, 0.5f);
    downloadedRegionsLayer = new DownloadedRegionsLayer();
    mapView.addLayer(downloadedRegionsLayer, 0.5f);
    // 0.9 gpx layer
    gpxLayer = new GPXLayer();
    mapView.addLayer(gpxLayer, 0.9f);
    // 1. route layer
    routeLayer = new RouteLayer(routingHelper);
    mapView.addLayer(routeLayer, 1);
    // 2. osm bugs layer
    // 3. poi layer
    poiMapLayer = new POIMapLayer(activity);
    mapView.addLayer(poiMapLayer, 3);
    // 4. favorites layer
    mFavouritesLayer = new FavouritesLayer();
    mapView.addLayer(mFavouritesLayer, 4);
    // 4.6 measurement tool layer
    measurementToolLayer = new MeasurementToolLayer();
    mapView.addLayer(measurementToolLayer, 4.6f);
    // 5. transport layer
    transportStopsLayer = new TransportStopsLayer(activity);
    mapView.addLayer(transportStopsLayer, 5);
    // 5.95 all text labels
    // 6. point location layer
    locationLayer = new PointLocationLayer(activity.getMapViewTrackingUtilities());
    mapView.addLayer(locationLayer, 6);
    // 7. point navigation layer
    navigationLayer = new PointNavigationLayer(activity);
    mapView.addLayer(navigationLayer, 7);
    // 7.3 map markers layer
    mapMarkersLayer = new MapMarkersLayer(activity);
    mapView.addLayer(mapMarkersLayer, 7.3f);
    // 7.5 Impassible roads
    impassableRoadsLayer = new ImpassableRoadsLayer(activity);
    mapView.addLayer(impassableRoadsLayer, 7.5f);
    // 7.8 ruler control layer
    rulerControlLayer = new RulerControlLayer(activity);
    mapView.addLayer(rulerControlLayer, 7.8f);
    // 8. context menu layer
    // 9. map info layer
    mapInfoLayer = new MapInfoLayer(activity, routeLayer);
    mapView.addLayer(mapInfoLayer, 9);
    // 11. route info layer
    mapControlsLayer = new MapControlsLayer(activity);
    mapView.addLayer(mapControlsLayer, 11);
    // 12. quick actions layer
    mapQuickActionLayer = new MapQuickActionLayer(activity, contextMenuLayer);
    mapView.addLayer(mapQuickActionLayer, 12);
    contextMenuLayer.setMapQuickActionLayer(mapQuickActionLayer);
    mapControlsLayer.setMapQuickActionLayer(mapQuickActionLayer);
    transparencyListener = new StateChangedListener<Integer>() {

        @Override
        public void stateChanged(Integer change) {
            mapTileLayer.setAlpha(change);
            mapVectorLayer.setAlpha(change);
            mapView.refreshMap();
        }
    };
    app.getSettings().MAP_TRANSPARENCY.addListener(transparencyListener);
    OsmandPlugin.createLayers(mapView, activity);
    app.getAppCustomization().createLayers(mapView, activity);
    app.getAidlApi().registerMapLayers(activity);
}
Also used : MapControlsLayer(net.osmand.plus.views.MapControlsLayer) PointLocationLayer(net.osmand.plus.views.PointLocationLayer) MapMarkersLayer(net.osmand.plus.views.MapMarkersLayer) OsmandApplication(net.osmand.plus.OsmandApplication) POIMapLayer(net.osmand.plus.views.POIMapLayer) MeasurementToolLayer(net.osmand.plus.measurementtool.MeasurementToolLayer) ImpassableRoadsLayer(net.osmand.plus.views.ImpassableRoadsLayer) ContextMenuLayer(net.osmand.plus.views.ContextMenuLayer) RoutingHelper(net.osmand.plus.routing.RoutingHelper) MapVectorLayer(net.osmand.plus.render.MapVectorLayer) RouteLayer(net.osmand.plus.views.RouteLayer) MapQuickActionLayer(net.osmand.plus.views.MapQuickActionLayer) GPXLayer(net.osmand.plus.views.GPXLayer) FavouritesLayer(net.osmand.plus.views.FavouritesLayer) PointNavigationLayer(net.osmand.plus.views.PointNavigationLayer) RulerControlLayer(net.osmand.plus.views.RulerControlLayer) MapTextLayer(net.osmand.plus.views.MapTextLayer) DownloadedRegionsLayer(net.osmand.plus.views.DownloadedRegionsLayer) MapTileLayer(net.osmand.plus.views.MapTileLayer) MapInfoLayer(net.osmand.plus.views.MapInfoLayer) TransportStopsLayer(net.osmand.plus.views.TransportStopsLayer)

Aggregations

MapControlsLayer (net.osmand.plus.views.MapControlsLayer)3 OsmandApplication (net.osmand.plus.OsmandApplication)2 Intent (android.content.Intent)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 LatLon (net.osmand.data.LatLon)1 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)1 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1 ItemBuilder (net.osmand.plus.ContextMenuItem.ItemBuilder)1 IndexItem (net.osmand.plus.download.IndexItem)1 FirstUsageWizardFragment (net.osmand.plus.firstusage.FirstUsageWizardFragment)1 OsmLiveActivity (net.osmand.plus.liveupdates.OsmLiveActivity)1 MeasurementToolLayer (net.osmand.plus.measurementtool.MeasurementToolLayer)1 MapVectorLayer (net.osmand.plus.render.MapVectorLayer)1 RoutingHelper (net.osmand.plus.routing.RoutingHelper)1 ContextMenuLayer (net.osmand.plus.views.ContextMenuLayer)1 DownloadedRegionsLayer (net.osmand.plus.views.DownloadedRegionsLayer)1 FavouritesLayer (net.osmand.plus.views.FavouritesLayer)1 GPXLayer (net.osmand.plus.views.GPXLayer)1