Search in sources :

Example 6 with OsmandMapTileView

use of net.osmand.plus.views.OsmandMapTileView 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 7 with OsmandMapTileView

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

the class MapActivityActions method createReloadTitleDialog.

private Dialog createReloadTitleDialog(final Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
    builder.setMessage(R.string.context_menu_item_update_map_confirm);
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    final OsmandMapTileView mapView = mapActivity.getMapView();
    builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            int zoom = args.getInt(KEY_ZOOM);
            BaseMapLayer mainLayer = mapView.getMainLayer();
            if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
            if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
            final QuadRect tilesRect = tb.getTileBounds();
            int left = (int) Math.floor(tilesRect.left);
            int top = (int) Math.floor(tilesRect.top);
            int width = (int) (Math.ceil(tilesRect.right) - left);
            int height = (int) (Math.ceil(tilesRect.bottom) - top);
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    ((OsmandApplication) mapActivity.getApplication()).getResourceManager().clearTileForMap(null, mapSource, i + left, j + top, zoom);
                }
            }
            mapView.refreshMap();
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseMapLayer(net.osmand.plus.views.BaseMapLayer) RotatedTileBox(net.osmand.data.RotatedTileBox) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) QuadRect(net.osmand.data.QuadRect) MapTileLayer(net.osmand.plus.views.MapTileLayer) ITileSource(net.osmand.map.ITileSource) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView)

Example 8 with OsmandMapTileView

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

the class MapActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this));
    long tm = System.currentTimeMillis();
    app = getMyApplication();
    settings = app.getSettings();
    app.applyTheme(this);
    supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
    boolean portraitMode = AndroidUiHelper.isOrientationPortrait(this);
    boolean largeDevice = AndroidUiHelper.isXLargeDevice(this);
    landscapeLayout = !portraitMode && !largeDevice;
    mapContextMenu.setMapActivity(this);
    super.onCreate(savedInstanceState);
    // Full screen is not used here
    // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
    if (Build.VERSION.SDK_INT >= 21) {
        enterToFullScreen();
        // Navigation Drawer:
        AndroidUtils.addStatusBarPadding21v(this, findViewById(R.id.menuItems));
    }
    int statusBarHeight = 0;
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    }
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int w = dm.widthPixels;
    int h = dm.heightPixels - statusBarHeight;
    mapView = new OsmandMapTileView(this, w, h);
    if (app.getAppInitializer().checkAppVersionChanged() && WhatsNewDialogFragment.SHOW) {
        SecondSplashScreenFragment.SHOW = false;
        WhatsNewDialogFragment.SHOW = false;
        new WhatsNewDialogFragment().show(getSupportFragmentManager(), null);
    }
    mapActions = new MapActivityActions(this);
    mapLayers = new MapActivityLayers(this);
    if (mapViewTrackingUtilities == null) {
        mapViewTrackingUtilities = new MapViewTrackingUtilities(app);
    }
    dashboardOnMap.createDashboardView();
    checkAppInitialization();
    parseLaunchIntentLocation();
    mapView.setTrackBallDelegate(new OsmandMapTileView.OnTrackBallListener() {

        @Override
        public boolean onTrackBallEvent(MotionEvent e) {
            showAndHideMapPosition();
            return MapActivity.this.onTrackballEvent(e);
        }
    });
    mapView.setAccessibilityActions(new MapAccessibilityActions(this));
    mapViewTrackingUtilities.setMapView(mapView);
    // to not let it gc
    downloaderCallback = new IMapDownloaderCallback() {

        @Override
        public void tileDownloaded(DownloadRequest request) {
            if (request != null && !request.error && request.fileToSave != null) {
                ResourceManager mgr = app.getResourceManager();
                mgr.tileDownloaded(request);
            }
            if (request == null || !request.error) {
                mapView.tileDownloaded(request);
            }
        }
    };
    app.getResourceManager().getMapTileDownloader().addDownloaderCallback(downloaderCallback);
    createProgressBarForRouting();
    mapLayers.createLayers(mapView);
    updateStatusBarColor();
    // it tries to continue the last route
    if (settings.FOLLOW_THE_ROUTE.get() && !app.getRoutingHelper().isRouteCalculated() && !app.getRoutingHelper().isRouteBeingCalculated()) {
        FailSafeFuntions.restoreRoutingMode(this);
    } else if (!app.getRoutingHelper().isRoutePlanningMode() && !settings.FOLLOW_THE_ROUTE.get() && app.getTargetPointsHelper().getAllPoints().size() > 0) {
        app.getRoutingHelper().clearCurrentRoute(null, new ArrayList<LatLon>());
        app.getTargetPointsHelper().removeAllWayPoints(false, false);
    }
    if (!settings.isLastKnownMapLocation()) {
        // show first time when application ran
        net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation();
        mapViewTrackingUtilities.setMapLinkedToLocation(true);
        if (location != null) {
            mapView.setLatLon(location.getLatitude(), location.getLongitude());
            mapView.setIntZoom(14);
        }
    }
    addDialogProvider(mapActions);
    OsmandPlugin.onMapActivityCreate(this);
    importHelper = new ImportHelper(this, getMyApplication(), getMapView());
    wakeLockHelper = new WakeLockHelper(getMyApplication());
    if (System.currentTimeMillis() - tm > 50) {
        System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
    }
    mapView.refreshMap(true);
    mapActions.updateDrawerMenu();
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    screenOffReceiver = new ScreenOffReceiver();
    registerReceiver(screenOffReceiver, filter);
    app.getAidlApi().onCreateMapActivity(this);
    mIsDestroyed = false;
}
Also used : IntentFilter(android.content.IntentFilter) IMapDownloaderCallback(net.osmand.map.MapTileDownloader.IMapDownloaderCallback) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) ArrayList(java.util.ArrayList) DownloadRequest(net.osmand.map.MapTileDownloader.DownloadRequest) WhatsNewDialogFragment(net.osmand.plus.dialogs.WhatsNewDialogFragment) ResourceManager(net.osmand.plus.resources.ResourceManager) DisplayMetrics(android.util.DisplayMetrics) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) MapAccessibilityActions(net.osmand.access.MapAccessibilityActions) MotionEvent(android.view.MotionEvent) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) WakeLockHelper(net.osmand.plus.helpers.WakeLockHelper) ImportHelper(net.osmand.plus.helpers.ImportHelper) Location(net.osmand.Location)

Example 9 with OsmandMapTileView

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

the class MapActivityLayers method showMultichoicePoiFilterDialog.

public void showMultichoicePoiFilterDialog(final OsmandMapTileView mapView, final DismissListener listener) {
    final OsmandApplication app = getApplication();
    final PoiFiltersHelper poiFilters = app.getPoiFilters();
    final ContextMenuAdapter adapter = new ContextMenuAdapter();
    final List<PoiUIFilter> list = new ArrayList<>();
    for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
        addFilterToList(adapter, list, f, true);
    }
    for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) {
        addFilterToList(adapter, list, f, true);
    }
    list.add(poiFilters.getCustomPOIFilter());
    final ArrayAdapter<ContextMenuItem> listAdapter = adapter.createListAdapter(activity, app.getSettings().isLightContent());
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final ListView listView = new ListView(activity);
    listView.setDivider(null);
    listView.setClickable(true);
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ContextMenuItem item = listAdapter.getItem(position);
            item.setSelected(!item.getSelected());
            item.getItemClickListener().onContextMenuClick(listAdapter, position, position, item.getSelected(), null);
            listAdapter.notifyDataSetChanged();
        }
    });
    builder.setView(listView).setTitle(R.string.show_poi_over_map).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            for (int i = 0; i < listAdapter.getCount(); i++) {
                ContextMenuItem item = listAdapter.getItem(i);
                PoiUIFilter filter = list.get(i);
                if (item.getSelected()) {
                    getApplication().getPoiFilters().addSelectedPoiFilter(filter);
                } else {
                    getApplication().getPoiFilters().removeSelectedPoiFilter(filter);
                }
            }
            mapView.refreshMap();
        }
    }).setNegativeButton(R.string.shared_string_cancel, null).setNeutralButton(" ", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            showSingleChoicePoiFilterDialog(mapView, listener);
        }
    });
    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
            Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_singleselect);
            neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
            neutralButton.setContentDescription(app.getString(R.string.shared_string_filters));
        }
    });
    alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            listener.dismiss();
        }
    });
    alertDialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ListView(android.widget.ListView) Button(android.widget.Button)

Example 10 with OsmandMapTileView

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

the class RouteInfoWidgetsFactory method createIntermediateDistanceControl.

public TextInfoWidget createIntermediateDistanceControl(final MapActivity map) {
    final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper();
    DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, R.drawable.widget_intermediate_day, R.drawable.widget_intermediate_night) {

        @Override
        protected void click(OsmandMapTileView view) {
            if (targets.getIntermediatePoints().size() > 1) {
                map.getMapActions().openIntermediatePointsDialog();
            } else {
                super.click(view);
            }
        }

        @Override
        public LatLon getPointToNavigate() {
            TargetPoint p = targets.getFirstIntermediatePoint();
            return p == null ? null : p.point;
        }

        @Override
        public int getDistance() {
            if (getPointToNavigate() != null && map.getRoutingHelper().isRouteCalculated()) {
                return map.getRoutingHelper().getLeftDistanceNextIntermediate();
            }
            return super.getDistance();
        }
    };
    return distanceControl;
}
Also used : OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Aggregations

OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)25 View (android.view.View)9 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)7 ContextMenuItem (net.osmand.plus.ContextMenuItem)7 ArrayAdapter (android.widget.ArrayAdapter)5 TextView (android.widget.TextView)5 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 OsmandSettings (net.osmand.plus.OsmandSettings)5 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 AdapterView (android.widget.AdapterView)4 ImageView (android.widget.ImageView)4 MapActivity (net.osmand.plus.activities.MapActivity)4 Intent (android.content.Intent)3 ListView (android.widget.ListView)3 ArrayList (java.util.ArrayList)3 Location (net.osmand.Location)3 LatLon (net.osmand.data.LatLon)3 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)3