Search in sources :

Example 1 with SampleApplication

use of net.osmand.core.samples.android.sample1.SampleApplication in project Osmand by osmandapp.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SampleApplication app = getMyApplication();
    gestureDetector = new GestureDetector(this, new MapViewOnGestureListener());
    multiTouchSupport = new MultiTouchSupport(this, new MapViewMultiTouchZoomListener());
    // Inflate views
    setContentView(R.layout.activity_main);
    boolean externalStoragePermissionGranted = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
    if (!externalStoragePermissionGranted) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
    }
    // Get map view
    mapView = (AtlasMapRendererView) findViewById(R.id.mapRendererView);
    textZoom = (TextView) findViewById(R.id.text_zoom);
    searchButton = (ImageButton) findViewById(R.id.search_button);
    searchButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showQuickSearch(ShowQuickSearchMode.NEW_IF_EXPIRED, false);
        }
    });
    compassButton = (ImageButton) findViewById(R.id.map_compass_button);
    compassButton.setContentDescription(app.getString("rotate_map_compass_opt"));
    compassDrawable = new CompassDrawable(app.getIconsCache().getIcon(R.drawable.map_compass));
    compassButton.setImageDrawable(compassDrawable);
    compassButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setAzimuth(0f);
        }
    });
    ImageButton myLocationButton = (ImageButton) findViewById(R.id.map_my_location_button);
    myLocationButton.setImageDrawable(app.getIconsCache().getIcon("map_my_location", R.color.color_myloc_distance));
    myLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SampleLocationProvider.isLocationPermissionAvailable(MainActivity.this)) {
                goToLocation();
            } else {
                ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, PERMISSION_REQUEST_LOCATION_ON_BUTTON);
            }
        }
    });
    findViewById(R.id.map_zoom_in_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setZoom(zoom + 1f);
        }
    });
    findViewById(R.id.map_zoom_out_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setZoom(zoom - 1f);
        }
    });
    // Additional log sink
    fileLogSink = QIODeviceLogSink.createFileLogSink(app.getAbsoluteAppPath() + "/osmandcore.log");
    Logger.get().addLogSink(fileLogSink);
    // Get device display density factor
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    displayDensityFactor = displayMetrics.densityDpi / 160.0f;
    referenceTileSize = (int) (256 * displayDensityFactor);
    rasterTileSize = Integer.highestOneBit(referenceTileSize - 1) * 2;
    Log.i(TAG, "displayDensityFactor = " + displayDensityFactor);
    Log.i(TAG, "referenceTileSize = " + referenceTileSize);
    Log.i(TAG, "rasterTileSize = " + rasterTileSize);
    Log.i(TAG, "Going to resolve default embedded style...");
    mapStylesCollection = new MapStylesCollection();
    mapStyle = mapStylesCollection.getResolvedStyleByName("default");
    if (mapStyle == null) {
        Log.e(TAG, "Failed to resolve style 'default'");
        System.exit(0);
    }
    Log.i(TAG, "Going to prepare OBFs collection");
    obfsCollection = new ObfsCollection();
    Log.i(TAG, "Will load OBFs from " + app.getAbsoluteAppPath());
    obfsCollection.addDirectory(app.getAbsoluteAppPath(), false);
    Log.i(TAG, "Going to prepare all resources for renderer");
    mapPresentationEnvironment = new MapPresentationEnvironment(mapStyle, displayDensityFactor, 1.0f, 1.0f, SampleApplication.LANGUAGE);
    // mapPresentationEnvironment->setSettings(configuration.styleSettings);
    mapPrimitiviser = new MapPrimitiviser(mapPresentationEnvironment);
    obfMapObjectsProvider = new ObfMapObjectsProvider(obfsCollection);
    mapPrimitivesProvider = new MapPrimitivesProvider(obfMapObjectsProvider, mapPrimitiviser, rasterTileSize);
    mapObjectsSymbolsProvider = new MapObjectsSymbolsProvider(mapPrimitivesProvider, rasterTileSize);
    mapView.setReferenceTileSizeOnScreenInPixels(referenceTileSize);
    mapView.addSymbolsProvider(mapObjectsSymbolsProvider);
    restoreMapState();
    mapLayerProvider0 = new MapRasterLayerProvider_Software(mapPrimitivesProvider);
    mapView.setMapLayerProvider(0, mapLayerProvider0);
    app.getIconsCache().setDisplayDensityFactor(displayDensityFactor);
    initMapMarkers();
    menu = new MapContextMenu();
    menu.setMainActivity(this);
    if (!InstallOsmandAppDialog.show(getSupportFragmentManager(), this) && externalStoragePermissionGranted) {
        checkMapsInstalled();
    }
}
Also used : MapRasterLayerProvider_Software(net.osmand.core.jni.MapRasterLayerProvider_Software) GestureDetector(android.view.GestureDetector) MapContextMenu(net.osmand.core.samples.android.sample1.mapcontextmenu.MapContextMenu) AtlasMapRendererView(net.osmand.core.android.AtlasMapRendererView) View(android.view.View) TextView(android.widget.TextView) DisplayMetrics(android.util.DisplayMetrics) ImageButton(android.widget.ImageButton) MapPrimitiviser(net.osmand.core.jni.MapPrimitiviser) MapPresentationEnvironment(net.osmand.core.jni.MapPresentationEnvironment) MapPrimitivesProvider(net.osmand.core.jni.MapPrimitivesProvider) MapObjectsSymbolsProvider(net.osmand.core.jni.MapObjectsSymbolsProvider) ObfsCollection(net.osmand.core.jni.ObfsCollection) ObfMapObjectsProvider(net.osmand.core.jni.ObfMapObjectsProvider) IMapStylesCollection(net.osmand.core.jni.IMapStylesCollection) MapStylesCollection(net.osmand.core.jni.MapStylesCollection)

Example 2 with SampleApplication

use of net.osmand.core.samples.android.sample1.SampleApplication in project Osmand by osmandapp.

the class PointDescription method getLocationName.

public static String getLocationName(SampleApplication ctx, double lat, double lon, boolean sh) {
    SampleApplication app = SampleApplication.getApp(ctx);
    int f = app.getCoordinatesFormat();
    if (f == PointDescription.UTM_FORMAT) {
        UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
        return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " " + ((long) pnt.northing);
    } else {
        try {
            return ctx.getString(sh ? "short_location_on_map" : "location_on_map", LocationConvert.convert(lat, f), LocationConvert.convert(lon, f));
        } catch (RuntimeException e) {
            e.printStackTrace();
            return ctx.getString(sh ? "short_location_on_map" : "location_on_map", 0, 0);
        }
    }
}
Also used : SampleApplication(net.osmand.core.samples.android.sample1.SampleApplication) LatLonPoint(com.jwetherell.openmap.common.LatLonPoint) UTMPoint(com.jwetherell.openmap.common.UTMPoint) LatLonPoint(com.jwetherell.openmap.common.LatLonPoint) UTMPoint(com.jwetherell.openmap.common.UTMPoint)

Example 3 with SampleApplication

use of net.osmand.core.samples.android.sample1.SampleApplication in project Osmand by osmandapp.

the class QuickSearchListFragment method showOnMap.

private void showOnMap(SearchResult searchResult) {
    if (searchResult.location != null) {
        SampleApplication app = getMyApplication();
        String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
        boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate();
        PointDescription pointDescription = null;
        Object object = searchResult.object;
        switch(searchResult.objectType) {
            case POI:
                Amenity a = (Amenity) object;
                String poiSimpleFormat = SampleFormatter.getPoiStringWithoutType(a, lang, transliterate);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
                pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(a));
                break;
            case HOUSE:
                String typeNameHouse = null;
                String name = searchResult.localeName;
                if (searchResult.relatedObject instanceof City) {
                    name = ((City) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true) + " " + name;
                } else if (searchResult.relatedObject instanceof Street) {
                    String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    typeNameHouse = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    name = s + " " + name;
                } else if (searchResult.localeRelatedObjectName != null) {
                    name = searchResult.localeRelatedObjectName + " " + name;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name);
                pointDescription.setIconName("ic_action_building");
                break;
            case LOCATION:
                pointDescription = new PointDescription(searchResult.location.getLatitude(), searchResult.location.getLongitude());
                pointDescription.setIconName("ic_action_world_globe");
                break;
            case STREET_INTERSECTION:
                String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult);
                if (Algorithms.isEmpty(typeNameIntersection)) {
                    typeNameIntersection = null;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameIntersection, QuickSearchListItem.getName(app, searchResult));
                pointDescription.setIconName("ic_action_intersection");
                break;
        }
        dialogFragment.hideToolbar();
        dialogFragment.hide();
        getMainActivity().showOnMap(searchResult.location, searchResult.preferredZoom);
        getMainActivity().getContextMenu().show(searchResult.location, pointDescription, object);
    }
}
Also used : SampleApplication(net.osmand.core.samples.android.sample1.SampleApplication) Amenity(net.osmand.data.Amenity) PointDescription(net.osmand.core.samples.android.sample1.data.PointDescription) Street(net.osmand.data.Street) City(net.osmand.data.City)

Example 4 with SampleApplication

use of net.osmand.core.samples.android.sample1.SampleApplication in project Osmand by osmandapp.

the class DirectionDrawable method setColorId.

public void setColorId(int clrId) {
    // R.color.color_ok, R.color.color_unknown, R.color.color_warning
    if (arrowImage != null) {
        IconsCache iconsCache = ((SampleApplication) ctx.getApplicationContext()).getIconsCache();
        arrowImage = iconsCache.getIcon(resourceId, clrId);
    } else {
        paintRouteDirection.setColor(ctx.getResources().getColor(clrId));
    }
}
Also used : SampleApplication(net.osmand.core.samples.android.sample1.SampleApplication) IconsCache(net.osmand.core.samples.android.sample1.IconsCache)

Example 5 with SampleApplication

use of net.osmand.core.samples.android.sample1.SampleApplication in project Osmand by osmandapp.

the class MenuController method getMenuController.

public static MenuController getMenuController(MainActivity mainActivity, LatLon latLon, PointDescription pointDescription, Object object, MenuType menuType) {
    SampleApplication app = mainActivity.getMyApplication();
    MenuController menuController = null;
    if (object != null) {
        if (object instanceof Amenity) {
            menuController = new AmenityMenuController(mainActivity, pointDescription, (Amenity) object);
        } else if (object instanceof LatLon) {
            if (pointDescription.isMyLocation()) {
                menuController = new MyLocationMenuController(mainActivity, pointDescription);
            }
        }
    }
    if (menuController == null) {
        menuController = new PointDescriptionMenuController(mainActivity, pointDescription);
    }
    menuController.menuType = menuType;
    menuController.setLatLon(latLon);
    return menuController;
}
Also used : SampleApplication(net.osmand.core.samples.android.sample1.SampleApplication) Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) AmenityMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.AmenityMenuController) MyLocationMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.MyLocationMenuController) PointDescriptionMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.PointDescriptionMenuController) AmenityMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.AmenityMenuController) PointDescriptionMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.PointDescriptionMenuController) MyLocationMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.MyLocationMenuController)

Aggregations

SampleApplication (net.osmand.core.samples.android.sample1.SampleApplication)6 LatLonPoint (com.jwetherell.openmap.common.LatLonPoint)2 UTMPoint (com.jwetherell.openmap.common.UTMPoint)2 IconsCache (net.osmand.core.samples.android.sample1.IconsCache)2 Amenity (net.osmand.data.Amenity)2 DisplayMetrics (android.util.DisplayMetrics)1 GestureDetector (android.view.GestureDetector)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 TextView (android.widget.TextView)1 AtlasMapRendererView (net.osmand.core.android.AtlasMapRendererView)1 IMapStylesCollection (net.osmand.core.jni.IMapStylesCollection)1 MapObjectsSymbolsProvider (net.osmand.core.jni.MapObjectsSymbolsProvider)1 MapPresentationEnvironment (net.osmand.core.jni.MapPresentationEnvironment)1 MapPrimitivesProvider (net.osmand.core.jni.MapPrimitivesProvider)1 MapPrimitiviser (net.osmand.core.jni.MapPrimitiviser)1 MapRasterLayerProvider_Software (net.osmand.core.jni.MapRasterLayerProvider_Software)1 MapStylesCollection (net.osmand.core.jni.MapStylesCollection)1 ObfMapObjectsProvider (net.osmand.core.jni.ObfMapObjectsProvider)1 ObfsCollection (net.osmand.core.jni.ObfsCollection)1