Search in sources :

Example 6 with ResourceManager

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

the class MapillaryFiltersFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final MapActivity mapActivity = (MapActivity) getActivity();
    final OsmandSettings settings = getSettings();
    final MapillaryPlugin plugin = OsmandPlugin.getPlugin(MapillaryPlugin.class);
    final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final int backgroundColor = ContextCompat.getColor(getActivity(), nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
    final DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
    final View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_mapillary_filters, null);
    view.findViewById(R.id.mapillary_filters_linear_layout).setBackgroundColor(backgroundColor);
    final View toggleRow = view.findViewById(R.id.toggle_row);
    final boolean selected = settings.SHOW_MAPILLARY.get();
    final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
    int toggleIconColorId;
    int toggleIconId;
    if (selected) {
        toggleIconId = R.drawable.ic_action_view;
        toggleIconColorId = nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light;
    } else {
        toggleIconId = R.drawable.ic_action_hide;
        toggleIconColorId = nightMode ? 0 : R.color.icon_color;
    }
    ((AppCompatTextView) toggleRow.findViewById(R.id.toggle_row_title)).setText(toggleActionStringId);
    final Drawable drawable = getIcon(toggleIconId, toggleIconColorId);
    ((AppCompatImageView) toggleRow.findViewById(R.id.toggle_row_icon)).setImageDrawable(drawable);
    final CompoundButton toggle = (CompoundButton) toggleRow.findViewById(R.id.toggle_row_toggle);
    toggle.setOnCheckedChangeListener(null);
    toggle.setChecked(selected);
    toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
            plugin.updateLayers(mapActivity.getMapView(), mapActivity);
            mapActivity.getDashboard().refreshContent(true);
        }
    });
    toggleRow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            toggle.setChecked(!toggle.isChecked());
        }
    });
    final Button reloadTile = (Button) view.findViewById(R.id.button_reload_tile);
    reloadTile.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ResourceManager manager = getMyApplication().getResourceManager();
            manager.clearCacheAndTiles(TileSourceManager.getMapillaryVectorSource());
            manager.clearCacheAndTiles(TileSourceManager.getMapillaryRasterSource());
            mapActivity.refreshMap();
        }
    });
    final int colorRes = nightMode ? R.color.color_white : R.color.icon_color;
    ((AppCompatImageView) view.findViewById(R.id.mapillary_filters_user_icon)).setImageDrawable(getIcon(R.drawable.ic_action_user, colorRes));
    ((AppCompatImageView) view.findViewById(R.id.mapillary_filters_date_icon)).setImageDrawable(getIcon(R.drawable.ic_action_data, colorRes));
    ((AppCompatImageView) view.findViewById(R.id.mapillary_filters_tile_cache_icon)).setImageDrawable(getIcon(R.drawable.ic_layer_top_dark, colorRes));
    final DelayAutoCompleteTextView textView = (DelayAutoCompleteTextView) view.findViewById(R.id.auto_complete_text_view);
    textView.setAdapter(new MapillaryAutoCompleteAdapter(getContext(), R.layout.auto_complete_suggestion, getMyApplication()));
    String selectedUsername = settings.MAPILLARY_FILTER_USERNAME.get();
    if (!selectedUsername.equals("") && settings.USE_MAPILLARY_FILTER.get()) {
        textView.setText(selectedUsername);
        textView.setSelection(selectedUsername.length());
    }
    textView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            hideKeyboard();
            mapActivity.getDashboard().refreshContent(true);
        }
    });
    textView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == EditorInfo.IME_ACTION_DONE) {
                hideKeyboard();
                mapActivity.getDashboard().refreshContent(true);
                return true;
            }
            return false;
        }
    });
    textView.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            view.findViewById(R.id.warning_linear_layout).setVisibility(View.GONE);
            if (!settings.MAPILLARY_FILTER_USERNAME.get().equals("") || settings.MAPILLARY_FILTER_TO_DATE.get() != 0 || settings.MAPILLARY_FILTER_FROM_DATE.get() != 0) {
                changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
            } else {
                changeButtonState((Button) view.findViewById(R.id.button_apply), .5f, false);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    ImageView imageView = (ImageView) view.findViewById(R.id.warning_image_view);
    imageView.setImageDrawable(getPaintedContentIcon(R.drawable.ic_small_warning, getResources().getColor(R.color.color_warning)));
    final EditText dateFromEt = (EditText) view.findViewById(R.id.date_from_edit_text);
    final DatePickerDialog.OnDateSetListener dateFromDialog = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker v, int year, int monthOfYear, int dayOfMonth) {
            Calendar from = Calendar.getInstance();
            from.set(Calendar.YEAR, year);
            from.set(Calendar.MONTH, monthOfYear);
            from.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            dateFromEt.setText(dateFormat.format(from.getTime()));
            settings.MAPILLARY_FILTER_FROM_DATE.set(from.getTimeInMillis());
            changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
            mapActivity.getDashboard().refreshContent(true);
        }
    };
    dateFromEt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Calendar now = Calendar.getInstance();
            new DatePickerDialog(mapActivity, dateFromDialog, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)).show();
        }
    });
    dateFromEt.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
    final EditText dateToEt = (EditText) view.findViewById(R.id.date_to_edit_text);
    final DatePickerDialog.OnDateSetListener dateToDialog = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker v, int year, int monthOfYear, int dayOfMonth) {
            Calendar to = Calendar.getInstance();
            to.set(Calendar.YEAR, year);
            to.set(Calendar.MONTH, monthOfYear);
            to.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            dateToEt.setText(dateFormat.format(to.getTime()));
            settings.MAPILLARY_FILTER_TO_DATE.set(to.getTimeInMillis());
            changeButtonState((Button) view.findViewById(R.id.button_apply), 1, true);
            mapActivity.getDashboard().refreshContent(true);
        }
    };
    dateToEt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Calendar now = Calendar.getInstance();
            new DatePickerDialog(mapActivity, dateToDialog, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)).show();
        }
    });
    dateToEt.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
    if (settings.USE_MAPILLARY_FILTER.get()) {
        long to = settings.MAPILLARY_FILTER_TO_DATE.get();
        if (to != 0) {
            dateToEt.setText(dateFormat.format(new Date(to)));
        }
        long from = settings.MAPILLARY_FILTER_FROM_DATE.get();
        if (from != 0) {
            dateFromEt.setText(dateFormat.format(new Date(from)));
        }
    }
    final Button apply = (Button) view.findViewById(R.id.button_apply);
    changeButtonState(apply, .5f, false);
    apply.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String username = textView.getText().toString();
            String dateFrom = dateFromEt.getText().toString();
            String dateTo = dateToEt.getText().toString();
            if (!settings.MAPILLARY_FILTER_USERNAME.get().equals("") || !dateFrom.equals("") || !dateTo.equals("")) {
                settings.USE_MAPILLARY_FILTER.set(true);
            }
            if (dateFrom.equals("")) {
                settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
            }
            if (dateTo.equals("")) {
                settings.MAPILLARY_FILTER_TO_DATE.set(0L);
            }
            if (!username.equals("") && settings.MAPILLARY_FILTER_USERNAME.get().equals("")) {
                view.findViewById(R.id.warning_linear_layout).setVisibility(View.VISIBLE);
            } else {
                mapActivity.getDashboard().hideDashboard();
            }
            changeButtonState(apply, .5f, false);
            plugin.updateLayers(mapActivity.getMapView(), mapActivity);
            hideKeyboard();
        }
    });
    final Button clear = (Button) view.findViewById(R.id.button_clear);
    clear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            textView.setText("");
            dateFromEt.setText("");
            dateToEt.setText("");
            settings.USE_MAPILLARY_FILTER.set(false);
            settings.MAPILLARY_FILTER_USER_KEY.set("");
            settings.MAPILLARY_FILTER_USERNAME.set("");
            settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
            settings.MAPILLARY_FILTER_TO_DATE.set(0L);
            plugin.updateLayers(mapActivity.getMapView(), mapActivity);
            hideKeyboard();
        }
    });
    return view;
}
Also used : DelayAutoCompleteTextView(net.osmand.plus.views.controls.DelayAutoCompleteTextView) KeyEvent(android.view.KeyEvent) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AppCompatTextView(android.support.v7.widget.AppCompatTextView) TextView(android.widget.TextView) DelayAutoCompleteTextView(net.osmand.plus.views.controls.DelayAutoCompleteTextView) ImageView(android.widget.ImageView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) MapActivity(net.osmand.plus.activities.MapActivity) EditText(android.widget.EditText) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) AppCompatTextView(android.support.v7.widget.AppCompatTextView) Drawable(android.graphics.drawable.Drawable) ResourceManager(net.osmand.plus.resources.ResourceManager) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) TextView(android.widget.TextView) DelayAutoCompleteTextView(net.osmand.plus.views.controls.DelayAutoCompleteTextView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) OsmandSettings(net.osmand.plus.OsmandSettings) Date(java.util.Date) ContextThemeWrapper(android.view.ContextThemeWrapper) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) AdapterView(android.widget.AdapterView) DatePicker(android.widget.DatePicker) CompoundButton(android.widget.CompoundButton)

Example 7 with ResourceManager

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

the class TileSourceProxyProvider method obtainImage.

@Override
public SWIGTYPE_p_QByteArray obtainImage(IMapTiledDataProvider.Request request) {
    byte[] image;
    try {
        ResourceManager rm = app.getResourceManager();
        String tileFilename = rm.calculateTileId(tileSource, request.getTileId().getX(), request.getTileId().getY(), request.getZoom().swigValue());
        final TileReadyCallback tileReadyCallback = new TileReadyCallback(tileSource, request.getTileId().getX(), request.getTileId().getY(), request.getZoom().swigValue());
        rm.getMapTileDownloader().addDownloaderCallback(tileReadyCallback);
        while (rm.getBitmapTilesCache().getTileForMapAsync(tileFilename, tileSource, request.getTileId().getX(), request.getTileId().getY(), request.getZoom().swigValue(), true) == null) {
            synchronized (tileReadyCallback.getSync()) {
                if (tileReadyCallback.isReady()) {
                    break;
                }
                try {
                    tileReadyCallback.getSync().wait(50);
                } catch (InterruptedException e) {
                }
            }
        }
        rm.getMapTileDownloader().removeDownloaderCallback(tileReadyCallback);
        image = tileSource.getBytes(request.getTileId().getX(), request.getTileId().getY(), request.getZoom().swigValue(), app.getAppPath(IndexConstants.TILES_INDEX_DIR).getAbsolutePath());
    } catch (IOException e) {
        return SwigUtilities.emptyQByteArray();
    }
    if (image == null)
        return SwigUtilities.emptyQByteArray();
    return SwigUtilities.createQByteArrayAsCopyOf(image);
}
Also used : ResourceManager(net.osmand.plus.resources.ResourceManager) IOException(java.io.IOException)

Example 8 with ResourceManager

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

Example 9 with ResourceManager

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

the class MapillaryImageDialog method fetchTiles.

public void fetchTiles() {
    RotatedTileBox tileBox = getMapActivity().getMapView().getCurrentRotatedTileBox().copy();
    if (fetchedTileLat == tileBox.getLatitude() && fetchedTileLon == tileBox.getLongitude()) {
        return;
    }
    ITileSource map = TileSourceManager.getMapillaryVectorSource();
    int nzoom = tileBox.getZoom();
    if (nzoom < map.getMinimumZoomSupported()) {
        return;
    }
    ResourceManager mgr = getMapActivity().getMyApplication().getResourceManager();
    final QuadRect tilesRect = tileBox.getTileBounds();
    // recalculate for ellipsoid coordinates
    float ellipticTileCorrection = 0;
    if (map.isEllipticYTile()) {
        ellipticTileCorrection = (float) (MapUtils.getTileEllipsoidNumberY(nzoom, tileBox.getLatitude()) - tileBox.getCenterTileY());
    }
    int left = (int) Math.floor(tilesRect.left);
    int top = (int) Math.floor(tilesRect.top + ellipticTileCorrection);
    int width = (int) Math.ceil(tilesRect.right - left);
    int height = (int) Math.ceil(tilesRect.bottom + ellipticTileCorrection - top);
    int dzoom = nzoom - TILE_ZOOM;
    int div = (int) Math.pow(2.0, dzoom);
    Map<String, Pair<QuadPointDouble, GeometryTile>> tiles = new HashMap<>();
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int tileX = (left + i) / div;
            int tileY = (top + j) / div;
            String tileId = mgr.calculateTileId(map, tileX, tileY, TILE_ZOOM);
            Pair<QuadPointDouble, GeometryTile> p = tiles.get(tileId);
            if (p == null) {
                GeometryTile tile = null;
                // asking tile image async
                boolean imgExist = mgr.tileExistOnFileSystem(tileId, map, tileX, tileY, TILE_ZOOM);
                if (imgExist) {
                    if (sync) {
                        tile = mgr.getGeometryTilesCache().getTileForMapSync(tileId, map, tileX, tileY, TILE_ZOOM, false);
                        sync = false;
                    } else {
                        tile = mgr.getGeometryTilesCache().getTileForMapAsync(tileId, map, tileX, tileY, TILE_ZOOM, false);
                    }
                }
                if (tile != null) {
                    tiles.put(tileId, new Pair<>(new QuadPointDouble(tileX, tileY), tile));
                }
            }
        }
    }
    fetchedTileLat = tileBox.getLatitude();
    fetchedTileLon = tileBox.getLongitude();
    this.tiles = new ArrayList<>(tiles.values());
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) HashMap(java.util.HashMap) ResourceManager(net.osmand.plus.resources.ResourceManager) QuadRect(net.osmand.data.QuadRect) Point(com.vividsolutions.jts.geom.Point) SuppressLint(android.annotation.SuppressLint) ITileSource(net.osmand.map.ITileSource) GeometryTile(net.osmand.data.GeometryTile) Pair(android.support.v4.util.Pair) QuadPointDouble(net.osmand.data.QuadPointDouble)

Example 10 with ResourceManager

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

the class MapillaryVectorLayer method drawTileMap.

@Override
public void drawTileMap(Canvas canvas, RotatedTileBox tileBox) {
    ITileSource map = this.map;
    if (map == null) {
        return;
    }
    int nzoom = tileBox.getZoom();
    if (nzoom < map.getMinimumZoomSupported()) {
        return;
    }
    ResourceManager mgr = resourceManager;
    final QuadRect tilesRect = tileBox.getTileBounds();
    // recalculate for ellipsoid coordinates
    float ellipticTileCorrection = 0;
    if (map.isEllipticYTile()) {
        ellipticTileCorrection = (float) (MapUtils.getTileEllipsoidNumberY(nzoom, tileBox.getLatitude()) - tileBox.getCenterTileY());
    }
    int left = (int) Math.floor(tilesRect.left);
    int top = (int) Math.floor(tilesRect.top + ellipticTileCorrection);
    int width = (int) Math.ceil(tilesRect.right - left);
    int height = (int) Math.ceil(tilesRect.bottom + ellipticTileCorrection - top);
    int dzoom = nzoom - TILE_ZOOM;
    int div = (int) Math.pow(2.0, dzoom);
    boolean useInternet = (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null || OsmandPlugin.getEnabledPlugin(MapillaryPlugin.class) != null) && settings.USE_INTERNET_TO_DOWNLOAD_TILES.get() && settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet();
    Map<String, GeometryTile> tiles = new HashMap<>();
    Map<QuadPointDouble, Map> visiblePoints = new HashMap<>();
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int tileX = (left + i) / div;
            int tileY = (top + j) / div;
            String tileId = mgr.calculateTileId(map, tileX, tileY, TILE_ZOOM);
            GeometryTile tile = tiles.get(tileId);
            if (tile == null) {
                // asking tile image async
                boolean imgExist = mgr.tileExistOnFileSystem(tileId, map, tileX, tileY, TILE_ZOOM);
                if (imgExist || useInternet) {
                    tile = mgr.getGeometryTilesCache().getTileForMapAsync(tileId, map, tileX, tileY, TILE_ZOOM, useInternet);
                }
                if (tile != null) {
                    tiles.put(tileId, tile);
                    if (tile.getData() != null) {
                        drawLines(canvas, tileBox, tileX, tileY, tile);
                        if (nzoom > 15) {
                            drawPoints(canvas, tileBox, tileX, tileY, tile, visiblePoints);
                        }
                    }
                }
            }
        }
    }
    this.visiblePoints = visiblePoints;
    drawSelectedPoint(canvas, tileBox);
}
Also used : HashMap(java.util.HashMap) ResourceManager(net.osmand.plus.resources.ResourceManager) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) QuadRect(net.osmand.data.QuadRect) Point(com.vividsolutions.jts.geom.Point) Paint(android.graphics.Paint) ITileSource(net.osmand.map.ITileSource) GeometryTile(net.osmand.data.GeometryTile) HashMap(java.util.HashMap) Map(java.util.Map) QuadPointDouble(net.osmand.data.QuadPointDouble)

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