Search in sources :

Example 1 with ResourceManager

use of net.osmand.plus.resources.ResourceManager 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 2 with ResourceManager

use of net.osmand.plus.resources.ResourceManager in project Osmand by osmandapp.

the class DownloadTilesDialog method run.

public void run(final int zoom, final int progress, final QuadRect latlonRect, final ITileSource map) {
    cancel = false;
    int numberTiles = 0;
    for (int z = zoom; z <= progress + zoom; z++) {
        int x1 = (int) MapUtils.getTileNumberX(z, latlonRect.left);
        int x2 = (int) MapUtils.getTileNumberX(z, latlonRect.right);
        int y1 = (int) MapUtils.getTileNumberY(z, latlonRect.top);
        int y2 = (int) MapUtils.getTileNumberY(z, latlonRect.bottom);
        numberTiles += (x2 - x1 + 1) * (y2 - y1 + 1);
    }
    final ProgressDialog progressDlg = new ProgressDialog(ctx);
    progressDlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDlg.setMessage(ctx.getString(R.string.shared_string_downloading) + ctx.getString(R.string.shared_string_ellipsis));
    progressDlg.setCancelable(true);
    progressDlg.setMax(numberTiles);
    progressDlg.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            cancel = true;
        }
    });
    final MapTileDownloader instance = MapTileDownloader.getInstance(Version.getFullVersion(app));
    final List<IMapDownloaderCallback> previousCallbacks = instance.getDownloaderCallbacks();
    instance.clearCallbacks();
    callback = new IMapDownloaderCallback() {

        @Override
        public void tileDownloaded(DownloadRequest request) {
            if (request != null) {
                progressDlg.setProgress(progressDlg.getProgress() + 1);
            }
        }
    };
    instance.addDownloaderCallback(callback);
    Runnable r = new Runnable() {

        @Override
        public void run() {
            int requests = 0;
            int limitRequests = 50;
            try {
                ResourceManager rm = app.getResourceManager();
                for (int z = zoom; z <= zoom + progress && !cancel; z++) {
                    int x1 = (int) MapUtils.getTileNumberX(z, latlonRect.left);
                    int x2 = (int) MapUtils.getTileNumberX(z, latlonRect.right);
                    int y1 = (int) MapUtils.getTileNumberY(z, latlonRect.top);
                    int y2 = (int) MapUtils.getTileNumberY(z, latlonRect.bottom);
                    for (int x = x1; x <= x2 && !cancel; x++) {
                        for (int y = y1; y <= y2 && !cancel; y++) {
                            String tileId = rm.calculateTileId(map, x, y, z);
                            if (rm.tileExistOnFileSystem(tileId, map, x, y, z)) {
                                progressDlg.setProgress(progressDlg.getProgress() + 1);
                            } else {
                                rm.hasTileForMapSync(tileId, map, x, y, z, true);
                                requests++;
                            }
                            if (!cancel) {
                                if (requests >= limitRequests) {
                                    requests = 0;
                                    while (instance.isSomethingBeingDownloaded()) {
                                        try {
                                            Thread.sleep(500);
                                        } catch (InterruptedException e) {
                                            throw new IllegalArgumentException(e);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (cancel) {
                    instance.refuseAllPreviousRequests();
                } else {
                    while (instance.isSomethingBeingDownloaded()) {
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            throw new IllegalArgumentException(e);
                        }
                    }
                }
                mapView.refreshMap();
                callback = null;
            } catch (Exception e) {
                // $NON-NLS-1$
                log.error("Exception while downloading tiles ", e);
                instance.refuseAllPreviousRequests();
            } finally {
                instance.clearCallbacks();
                for (IMapDownloaderCallback cbck : previousCallbacks) {
                    instance.addDownloaderCallback(cbck);
                }
                app.getResourceManager().reloadTilesFromFS();
            }
            progressDlg.dismiss();
        }
    };
    // $NON-NLS-1$
    new Thread(r, "Downloading tiles").start();
    progressDlg.show();
}
Also used : IMapDownloaderCallback(net.osmand.map.MapTileDownloader.IMapDownloaderCallback) DialogInterface(android.content.DialogInterface) DownloadRequest(net.osmand.map.MapTileDownloader.DownloadRequest) ResourceManager(net.osmand.plus.resources.ResourceManager) ProgressDialog(android.app.ProgressDialog) MapTileDownloader(net.osmand.map.MapTileDownloader)

Example 3 with ResourceManager

use of net.osmand.plus.resources.ResourceManager in project Osmand by osmandapp.

the class SearchPoiFilterFragment method onListItemClick.

@Override
public void onListItemClick(ListView listView, View v, int position, long id) {
    final Object item = getListAdapter().getItem(position);
    ResourceManager rm = getApp().getResourceManager();
    if (!rm.containsAmenityRepositoryToSearch(false)) {
        Toast.makeText(getActivity(), R.string.data_to_search_poi_not_available, Toast.LENGTH_LONG);
        return;
    }
    if (item instanceof PoiUIFilter) {
        PoiUIFilter model = ((PoiUIFilter) item);
        if (PoiUIFilter.BY_NAME_FILTER_ID.equals(model.getFilterId()) || model instanceof NominatimPoiFilter) {
            model.setFilterByName(searchEditText.getText().toString());
        } else {
            model.setFilterByName(model.getSavedFilterByName());
        }
        showFilterActivity(model.getFilterId());
    } else {
        PoiUIFilter custom = getApp().getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ((AbstractPoiType) item).getKeyName());
        if (custom != null) {
            if (item instanceof PoiType && ((PoiType) item).isAdditional()) {
            // it is already set
            } else {
                custom.setFilterByName(null);
            }
            custom.clearFilter();
            custom.updateTypesToAccept(((AbstractPoiType) item));
            showFilterActivity(custom.getFilterId());
        }
    }
}
Also used : NominatimPoiFilter(net.osmand.plus.poi.NominatimPoiFilter) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) ResourceManager(net.osmand.plus.resources.ResourceManager) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 4 with ResourceManager

use of net.osmand.plus.resources.ResourceManager in project Osmand by osmandapp.

the class MenuController method buildMapDownloadButtonAndSizeInfo.

public void buildMapDownloadButtonAndSizeInfo(final LatLon latLon) {
    new AsyncTask<Void, Void, BinaryMapDataObject>() {

        ResourceManager rm;

        OsmandRegions osmandRegions;

        String selectedFullName = "";

        @Override
        protected void onPreExecute() {
            rm = getMapActivity().getMyApplication().getResourceManager();
            osmandRegions = rm.getOsmandRegions();
        }

        @Override
        protected BinaryMapDataObject doInBackground(Void... voids) {
            int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
            int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
            List<BinaryMapDataObject> mapDataObjects = null;
            try {
                mapDataObjects = osmandRegions.queryBbox(point31x, point31x, point31y, point31y);
            } catch (IOException e) {
                e.printStackTrace();
            }
            BinaryMapDataObject binaryMapDataObject = null;
            if (mapDataObjects != null) {
                Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
                while (it.hasNext()) {
                    BinaryMapDataObject o = it.next();
                    if (o.getTypes() != null) {
                        boolean isRegion = true;
                        for (int i = 0; i < o.getTypes().length; i++) {
                            TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
                            if ("boundary".equals(tp.value)) {
                                isRegion = false;
                                break;
                            }
                        }
                        if (!isRegion || !osmandRegions.contain(o, point31x, point31y)) {
                            it.remove();
                        }
                    }
                }
                double smallestArea = -1;
                for (BinaryMapDataObject o : mapDataObjects) {
                    String downloadName = osmandRegions.getDownloadName(o);
                    if (!Algorithms.isEmpty(downloadName)) {
                        boolean downloaded = checkIfObjectDownloaded(rm, downloadName);
                        if (downloaded) {
                            binaryMapDataObject = null;
                            break;
                        } else {
                            String fullName = osmandRegions.getFullName(o);
                            WorldRegion region = osmandRegions.getRegionData(fullName);
                            if (region != null && region.isRegionMapDownload()) {
                                double area = OsmandRegions.getArea(o);
                                if (smallestArea == -1) {
                                    smallestArea = area;
                                    selectedFullName = fullName;
                                    binaryMapDataObject = o;
                                } else if (area < smallestArea) {
                                    smallestArea = area;
                                    selectedFullName = fullName;
                                    binaryMapDataObject = o;
                                }
                            }
                        }
                    }
                }
            }
            return binaryMapDataObject;
        }

        @Override
        protected void onPostExecute(BinaryMapDataObject binaryMapDataObject) {
            downloadMapDataObject = binaryMapDataObject;
            downloaded = downloadMapDataObject == null;
            if (!downloaded) {
                downloadThread = getMapActivity().getMyApplication().getDownloadThread();
                downloadRegion = osmandRegions.getRegionData(selectedFullName);
                if (downloadRegion != null && downloadRegion.isRegionMapDownload()) {
                    List<IndexItem> indexItems = downloadThread.getIndexes().getIndexItems(downloadRegion);
                    for (IndexItem item : indexItems) {
                        if (item.getType() == DownloadActivityType.NORMAL_FILE && (item.isDownloaded() || downloadThread.isDownloading(item))) {
                            indexItem = item;
                        }
                    }
                }
                leftDownloadButtonController = new TitleButtonController() {

                    @Override
                    public void buttonPressed() {
                        if (indexItem != null) {
                            if (indexItem.getType() == DownloadActivityType.NORMAL_FILE) {
                                new DownloadValidationManager(getMapActivity().getMyApplication()).startDownload(getMapActivity(), indexItem);
                            }
                        }
                    }
                };
                leftDownloadButtonController.caption = downloadRegion != null ? downloadRegion.getLocaleName() : getMapActivity().getString(R.string.shared_string_download);
                leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
                titleProgressController = new TitleProgressController() {

                    @Override
                    public void buttonPressed() {
                        if (indexItem != null) {
                            downloadThread.cancelDownload(indexItem);
                        }
                    }
                };
                if (!downloadThread.getIndexes().isDownloadedFromInternet) {
                    if (getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable()) {
                        downloadThread.runReloadIndexFiles();
                    }
                }
                if (mapContextMenu != null) {
                    mapContextMenu.updateMenuUI();
                }
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : WorldRegion(net.osmand.map.WorldRegion) ResourceManager(net.osmand.plus.resources.ResourceManager) SpannableString(android.text.SpannableString) IOException(java.io.IOException) IndexItem(net.osmand.plus.download.IndexItem) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) DownloadValidationManager(net.osmand.plus.download.DownloadValidationManager)

Example 5 with ResourceManager

use of net.osmand.plus.resources.ResourceManager in project Osmand by osmandapp.

the class FirstUsageWizardFragment method searchMap.

private void searchMap() {
    if (location != null) {
        int point31x = MapUtils.get31TileNumberX(location.getLongitude());
        int point31y = MapUtils.get31TileNumberY(location.getLatitude());
        ResourceManager rm = getMyApplication().getResourceManager();
        OsmandRegions osmandRegions = rm.getOsmandRegions();
        List<BinaryMapDataObject> mapDataObjects = null;
        try {
            mapDataObjects = osmandRegions.queryBbox(point31x, point31x, point31y, point31y);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String selectedFullName = "";
        if (mapDataObjects != null) {
            Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
            while (it.hasNext()) {
                BinaryMapDataObject o = it.next();
                if (!osmandRegions.contain(o, point31x, point31y)) {
                    it.remove();
                }
            }
            for (BinaryMapDataObject o : mapDataObjects) {
                String fullName = osmandRegions.getFullName(o);
                if (fullName.length() > selectedFullName.length()) {
                    selectedFullName = fullName;
                }
            }
        }
        if (!Algorithms.isEmpty(selectedFullName)) {
            WorldRegion downloadRegion = osmandRegions.getRegionData(selectedFullName);
            if (downloadRegion != null && downloadRegion.isRegionMapDownload()) {
                localDownloadRegion = downloadRegion;
                List<IndexItem> indexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
                for (IndexItem item : indexItems) {
                    if (item.getType() == DownloadActivityType.NORMAL_FILE) {
                        localMapIndexItem = item;
                        break;
                    }
                }
            }
        }
        baseMapIndexItem = downloadThread.getIndexes().getWorldBaseMapItem();
        if (localMapIndexItem != null || baseMapIndexItem != null) {
            showMapFoundFragment(getActivity());
        } else {
            closeWizard();
        }
    } else {
        showNoLocationFragment(getActivity());
    }
}
Also used : OsmandRegions(net.osmand.map.OsmandRegions) WorldRegion(net.osmand.map.WorldRegion) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) ResourceManager(net.osmand.plus.resources.ResourceManager) IOException(java.io.IOException) IndexItem(net.osmand.plus.download.IndexItem) LinkedList(java.util.LinkedList)

Aggregations

ResourceManager (net.osmand.plus.resources.ResourceManager)11 Paint (android.graphics.Paint)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 QuadRect (net.osmand.data.QuadRect)3 ITileSource (net.osmand.map.ITileSource)3 SuppressLint (android.annotation.SuppressLint)2 DisplayMetrics (android.util.DisplayMetrics)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 CompoundButton (android.widget.CompoundButton)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Point (com.vividsolutions.jts.geom.Point)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)2 GeometryTile (net.osmand.data.GeometryTile)2 QuadPointDouble (net.osmand.data.QuadPointDouble)2