Search in sources :

Example 16 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class WikipediaPlugin method getSuggestedMaps.

@Override
public List<IndexItem> getSuggestedMaps() {
    DownloadIndexesThread downloadThread = app.getDownloadThread();
    OsmandSettings settings = app.getSettings();
    if (!downloadThread.getIndexes().isDownloadedFromInternet && settings.isInternetConnectionAvailable()) {
        downloadThread.runReloadIndexFiles();
    }
    if (!downloadThread.shouldDownloadIndexes()) {
        LatLon latLon = app.getMapViewTrackingUtilities().getMapLocation();
        return getMapsForType(latLon, DownloadActivityType.WIKIPEDIA_FILE);
    }
    return Collections.emptyList();
}
Also used : LatLon(net.osmand.data.LatLon) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) DownloadIndexesThread(net.osmand.plus.download.DownloadIndexesThread)

Example 17 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class ArticleWebViewClient method shouldOverrideUrlLoading.

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    boolean isWebPage = url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS);
    if (url.contains(WIKIVOYAGE_DOMAIN) && isWebPage) {
        WikivoyageUtils.processWikivoyageDomain(activity, url, isNightMode());
        fragment.dismiss();
    } else if (url.contains(WIKI_DOMAIN) && isWebPage) {
        QuadRect rect = gpxFile.getRect();
        LatLon defaultCoordinates = new LatLon(rect.centerY(), rect.centerX());
        WikivoyageUtils.processWikipediaDomain(wikiArticleHelper, defaultCoordinates, url);
    } else if (url.contains(PREFIX_TEL)) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse(url));
        return AndroidUtils.startActivityIfSafe(activity, intent);
    } else if (url.contains(PREFIX_GEO)) {
        fragment.closeAll();
        String coordinates = url.replace(PREFIX_GEO, "");
        WptPt gpxPoint = WikivoyageUtils.findNearestPoint(gpxFile.getPoints(), coordinates);
        if (gpxPoint != null) {
            OsmandSettings settings = app.getSettings();
            settings.setMapLocationToShow(gpxPoint.getLatitude(), gpxPoint.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, gpxPoint.name), false, gpxPoint);
            MapActivity.launchMapActivityMoveToTop(activity);
        }
    } else if (isWebPage) {
        WikiArticleHelper.warnAboutExternalLoad(url, activity, isNightMode());
    } else {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        return AndroidUtils.startActivityIfSafe(activity, intent);
    }
    return true;
}
Also used : LatLon(net.osmand.data.LatLon) WptPt(net.osmand.GPXUtilities.WptPt) PointDescription(net.osmand.data.PointDescription) Intent(android.content.Intent) QuadRect(net.osmand.data.QuadRect) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings)

Example 18 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class FailSafeFuntions method restoreRoutingMode.

public static void restoreRoutingMode(final MapActivity ma) {
    final OsmandApplication app = ma.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final Handler uiHandler = new Handler();
    final String gpxPath = settings.FOLLOW_THE_GPX_ROUTE.get();
    final TargetPointsHelper targetPoints = app.getTargetPointsHelper();
    final TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
    if (pointToNavigate == null && gpxPath == null) {
        notRestoreRoutingMode(ma, app);
    } else {
        quitRouteRestoreDialog = false;
        Runnable encapsulate = new Runnable() {

            int delay = 7;

            Runnable delayDisplay = null;

            @Override
            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(ma);
                final TextView tv = new TextView(ma);
                tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                tv.setPadding(7, 5, 7, 5);
                builder.setView(tv);
                builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        restoreRoutingModeInner();
                    }
                });
                builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        notRestoreRoutingMode(ma, app);
                    }
                });
                final AlertDialog dlg = builder.show();
                dlg.setOnDismissListener(new OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                dlg.setOnCancelListener(new OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                delayDisplay = new Runnable() {

                    @Override
                    public void run() {
                        if (!quitRouteRestoreDialog) {
                            delay--;
                            tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                            if (delay <= 0) {
                                try {
                                    if (dlg.isShowing() && !quitRouteRestoreDialog) {
                                        dlg.dismiss();
                                    }
                                    quitRouteRestoreDialog = true;
                                    restoreRoutingModeInner();
                                } catch (Exception e) {
                                    // swalow view not attached exception
                                    log.error(e.getMessage() + "", e);
                                }
                            } else {
                                uiHandler.postDelayed(delayDisplay, 1000);
                            }
                        }
                    }
                };
                delayDisplay.run();
            }

            private void restoreRoutingModeInner() {
                AsyncTask<String, Void, GPXFile> task = new AsyncTask<String, Void, GPXFile>() {

                    @Override
                    protected GPXFile doInBackground(String... params) {
                        if (gpxPath != null) {
                            // Reverse also should be stored ?
                            GPXFile f = GPXUtilities.loadGPXFile(new File(gpxPath));
                            if (f.error != null) {
                                return null;
                            }
                            return f;
                        } else {
                            return null;
                        }
                    }

                    @Override
                    protected void onPostExecute(GPXFile result) {
                        final GPXRouteParamsBuilder gpxRoute;
                        if (result != null) {
                            gpxRoute = new GPXRouteParamsBuilder(result, settings);
                            if (settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
                                gpxRoute.setCalculateOsmAndRouteParts(true);
                            }
                            if (settings.GPX_ROUTE_CALC.get()) {
                                gpxRoute.setCalculateOsmAndRoute(true);
                            }
                            if (settings.GPX_ROUTE_SEGMENT.get() != -1) {
                                gpxRoute.setSelectedSegment(settings.GPX_ROUTE_SEGMENT.get());
                            }
                        } else {
                            gpxRoute = null;
                        }
                        TargetPoint endPoint = pointToNavigate;
                        if (endPoint == null) {
                            notRestoreRoutingMode(ma, app);
                        } else {
                            enterRoutingMode(ma, gpxRoute);
                        }
                    }
                };
                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxPath);
            }
        };
        encapsulate.run();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) OnDismissListener(android.content.DialogInterface.OnDismissListener) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TextView(android.widget.TextView) GPXFile(net.osmand.GPXUtilities.GPXFile) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 19 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class SelectMapViewQuickActionsBottomSheet method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    Bundle args = getArguments();
    if (args == null) {
        return;
    }
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return;
    }
    long id = args.getLong(SwitchableAction.KEY_ID);
    OsmandApplication app = mapActivity.getMyApplication();
    QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry();
    action = quickActionRegistry.getQuickAction(id);
    action = QuickActionRegistry.produceAction(action);
    if (action == null) {
        return;
    }
    OsmandSettings settings = app.getSettings();
    if (savedInstanceState != null) {
        selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY);
    } else {
        selectedItem = ((SwitchableAction<?>) action).getSelectedItem(app);
    }
    rbColorList = AndroidUtils.createCheckedColorStateList(app, R.color.icon_color_default_light, getActiveColorId());
    items.add(new TitleItem(action.getName(app)));
    NestedScrollView nestedScrollView = new NestedScrollView(app);
    itemsContainer = new LinearLayout(app);
    itemsContainer.setLayoutParams((new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)));
    itemsContainer.setOrientation(LinearLayout.VERTICAL);
    int padding = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small);
    itemsContainer.setPadding(0, padding, 0, padding);
    int itemsSize = 0;
    if (action instanceof SwitchableAction) {
        SwitchableAction switchableAction = (SwitchableAction) action;
        List sources = switchableAction.loadListFromParams();
        itemsSize = sources.size();
    }
    for (int i = 0; i < itemsSize; i++) {
        LayoutInflater.from(new ContextThemeWrapper(app, themeRes)).inflate(R.layout.bottom_sheet_item_with_radio_btn, itemsContainer, true);
    }
    nestedScrollView.addView(itemsContainer);
    items.add(new BaseBottomSheetItem.Builder().setCustomView(nestedScrollView).create());
    populateItemsList();
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) LayoutParams(android.widget.LinearLayout.LayoutParams) OsmandApplication(net.osmand.plus.OsmandApplication) Bundle(android.os.Bundle) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) SwitchableAction(net.osmand.plus.quickaction.SwitchableAction) ContextThemeWrapper(android.view.ContextThemeWrapper) ColorStateList(android.content.res.ColorStateList) List(java.util.List) NestedScrollView(androidx.core.widget.NestedScrollView) QuickActionRegistry(net.osmand.plus.quickaction.QuickActionRegistry) LinearLayout(android.widget.LinearLayout) MapActivity(net.osmand.plus.activities.MapActivity)

Example 20 with OsmandSettings

use of net.osmand.plus.settings.backend.OsmandSettings in project Osmand by osmandapp.

the class ConfigureMapMenu method createTravelRoutesItem.

private ContextMenuItem createTravelRoutesItem(@NonNull MapActivity activity, boolean nightMode) {
    OsmandSettings settings = activity.getMyApplication().getSettings();
    boolean selected = settings.SHOW_TRAVEL.get();
    return new ContextMenuItem.ItemBuilder().setId(ROUTES_ID + TRAVEL_ROUTES).setTitle(activity.getString(R.string.travel_routes)).setIcon(getIconIdForAttr(TRAVEL_ROUTES)).setSecondaryIcon(R.drawable.ic_action_additional_option).setSelected(selected).setColor(selected ? settings.APPLICATION_MODE.get().getProfileColor(nightMode) : null).setDescription(activity.getString(selected ? R.string.shared_string_enabled : R.string.shared_string_disabled)).setListener(new OnRowItemClick() {

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
            activity.getDashboard().setDashboardVisibility(true, DashboardType.TRAVEL_ROUTES, AndroidUtils.getCenterViewCoordinates(view));
            return false;
        }

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
            settings.SHOW_TRAVEL.set(isChecked);
            ContextMenuItem item = adapter.getItem(position);
            if (item != null) {
                item.setSelected(isChecked);
                item.setColor(activity, isChecked ? R.color.osmand_orange : INVALID_ID);
                item.setDescription(activity.getString(isChecked ? R.string.shared_string_enabled : R.string.shared_string_disabled));
                adapter.notifyDataSetChanged();
            }
            activity.refreshMap();
            activity.updateLayers();
            return false;
        }
    }).createItem();
}
Also used : ContextMenuItem(net.osmand.plus.ContextMenuItem) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) View(android.view.View) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)154 OsmandApplication (net.osmand.plus.OsmandApplication)52 View (android.view.View)25 ArrayList (java.util.ArrayList)23 LatLon (net.osmand.data.LatLon)17 MapActivity (net.osmand.plus.activities.MapActivity)17 TextView (android.widget.TextView)16 NonNull (androidx.annotation.NonNull)16 AlertDialog (androidx.appcompat.app.AlertDialog)15 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)15 ArrayAdapter (android.widget.ArrayAdapter)13 ContextMenuItem (net.osmand.plus.ContextMenuItem)13 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)12 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)12 Context (android.content.Context)11 ImageView (android.widget.ImageView)11 Intent (android.content.Intent)8 List (java.util.List)8 PointDescription (net.osmand.data.PointDescription)8 DialogInterface (android.content.DialogInterface)7