Search in sources :

Example 11 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class OnlineRoutingEngineFragment method showExitDialog.

public void showExitDialog() {
    View focus = view.findFocus();
    AndroidUtils.hideSoftKeyboard(mapActivity, focus);
    if (hasNameDuplicate(initEngine)) {
        List<OnlineRoutingEngine> cachedEngines = helper.getEnginesExceptMentionedKeys(editedEngineKey);
        OnlineRoutingUtils.generateUniqueName(app, initEngine, cachedEngines);
    }
    if (!engine.equals(initEngine)) {
        AlertDialog.Builder dismissDialog = createWarningDialog(mapActivity, R.string.shared_string_dismiss, R.string.exit_without_saving, R.string.shared_string_cancel);
        dismissDialog.setPositiveButton(R.string.shared_string_exit, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dismiss();
            }
        });
        dismissDialog.show();
    } else {
        dismiss();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) DialogInterface(android.content.DialogInterface) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint)

Example 12 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class OnlineRoutingEngineFragment method changeEngineType.

private void changeEngineType(OnlineRoutingEngine type) {
    OnlineRoutingEngine tmp = (OnlineRoutingEngine) engine.clone();
    engine = type.newInstance(tmp.getParams());
    // after changing the type, select the vehicle
    // with the same name that was selected before
    VehicleType previous = tmp.getSelectedVehicleType();
    VehicleType next = null;
    for (VehicleType vt : engine.getAllowedVehicles()) {
        if (Algorithms.objectEquals(previous.getTitle(app), vt.getTitle(app))) {
            next = vt;
            break;
        }
    }
    String vehicleKey;
    if (next != null) {
        vehicleKey = next.equals(CUSTOM_VEHICLE) ? customVehicleKey : next.getKey();
    } else {
        vehicleKey = engine.getAllowedVehicles().get(0).getKey();
    }
    engine.put(EngineParameter.VEHICLE_KEY, vehicleKey);
    setupVehicleTypes();
    generateUniqueNameIfNeeded();
    updateCardViews(nameCard, typeCard, vehicleCard, exampleCard);
}
Also used : OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) VehicleType(net.osmand.plus.onlinerouting.VehicleType)

Example 13 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class OnlineRoutingEngineFragment method testEngineWork.

private void testEngineWork() {
    final OnlineRoutingEngine requestedEngine = (OnlineRoutingEngine) engine.clone();
    final ExampleLocation location = selectedLocation;
    new Thread(new Runnable() {

        @Override
        public void run() {
            StringBuilder errorMessage = new StringBuilder();
            boolean resultOk = false;
            try {
                String method = engine.getHTTPMethod();
                List<LatLon> path = Arrays.asList(location.getCityAirportLatLon(), location.getCityCenterLatLon());
                String body = engine.getRequestBody(path, null);
                Map<String, String> headers = engine.getRequestHeaders();
                String response = helper.makeRequest(exampleCard.getEditedText(), method, body, headers);
                resultOk = requestedEngine.isResultOk(errorMessage, response);
            } catch (IOException | JSONException e) {
                errorMessage.append(e.toString());
            }
            showTestResults(resultOk, errorMessage.toString(), location);
        }
    }).start();
}
Also used : JSONException(org.json.JSONException) IOException(java.io.IOException) LatLon(net.osmand.data.LatLon) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)

Example 14 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class OnlineRoutingEngineFragment method setupTypeCard.

private void setupTypeCard() {
    typeCard = new OnlineRoutingCard(mapActivity, isNightMode(), appMode);
    typeCard.build(mapActivity);
    typeCard.setHeaderTitle(getString(R.string.shared_string_type));
    List<net.osmand.plus.widgets.chips.ChipItem> typeItems = new ArrayList<>();
    for (OnlineRoutingEngine type : EngineType.values()) {
        String title = type.getTitle();
        ChipItem item = new ChipItem(title);
        item.title = title;
        item.tag = type;
        typeItems.add(item);
    }
    typeCard.setSelectionMenu(typeItems, engine.getType().getTitle(), result -> {
        OnlineRoutingEngine type = (OnlineRoutingEngine) result.tag;
        if (engine.getType() != type) {
            changeEngineType(type);
            return true;
        }
        return false;
    });
    typeCard.setOnTextChangedListener(new OnTextChangedListener() {

        @Override
        public void onTextChanged(boolean editedByUser, @NonNull String text) {
            if (editedByUser) {
                engine.put(EngineParameter.CUSTOM_URL, text);
                updateCardViews(exampleCard);
            }
        }
    });
    typeCard.setFieldBoxLabelText(getString(R.string.shared_string_server_url));
    typeCard.showDivider();
    segmentsContainer.addView(typeCard.getView());
}
Also used : OnTextChangedListener(net.osmand.plus.onlinerouting.ui.OnlineRoutingCard.OnTextChangedListener) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) ArrayList(java.util.ArrayList) ChipItem(net.osmand.plus.widgets.chips.ChipItem)

Example 15 with OnlineRoutingEngine

use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.

the class OnlineRoutingHelper method readFromSettings.

@NonNull
private List<OnlineRoutingEngine> readFromSettings() {
    List<OnlineRoutingEngine> engines = new ArrayList<>();
    String jsonString = settings.ONLINE_ROUTING_ENGINES.get();
    if (!isEmpty(jsonString)) {
        try {
            JSONObject json = new JSONObject(jsonString);
            OnlineRoutingUtils.readFromJson(json, engines);
        } catch (JSONException | IllegalArgumentException e) {
            LOG.debug("Error when reading engines from JSON ", e);
        }
    }
    return engines;
}
Also used : OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) NonNull(androidx.annotation.NonNull)

Aggregations

OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)22 ArrayList (java.util.ArrayList)8 File (java.io.File)6 ITileSource (net.osmand.map.ITileSource)6 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)5 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)5 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)5 FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)5 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 QuickAction (net.osmand.plus.quickaction.QuickAction)5 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)5 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)4 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)4 ApplicationModeBean (net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean)4 NonNull (androidx.annotation.NonNull)3 MapMarker (net.osmand.plus.mapmarkers.MapMarker)3 OnlineRoutingHelper (net.osmand.plus.onlinerouting.OnlineRoutingHelper)3 SQLiteTileSource (net.osmand.plus.resources.SQLiteTileSource)3 FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)3 GlobalSettingsItem (net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem)3