use of net.osmand.plus.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(app, new File(gpxPath));
if (f.warning != 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_CALCULATE_RTEPT.get()) {
gpxRoute.setUseIntermediatePointsRTE(true);
}
if (settings.GPX_ROUTE_CALC.get()) {
gpxRoute.setCalculateOsmAndRoute(true);
}
} 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();
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class QuickSearchDialogFragment method reloadCitiesInternal.
private void reloadCitiesInternal() {
if (SearchUICore.isDebugMode()) {
LOG.info("UI >> Start loading nearest cities");
}
startNearestCitySearch();
runCoreSearch("", false, false, new SearchResultListener() {
@Override
public void searchStarted(SearchPhrase phrase) {
}
@Override
public void publish(SearchResultCollection res, boolean append) {
}
@Override
public boolean searchFinished(SearchPhrase phrase) {
SearchResultCollection res = getResultCollection();
if (SearchUICore.isDebugMode()) {
LOG.info("UI >> Nearest cities found: " + (res != null ? res.getCurrentSearchResults().size() : 0));
}
final OsmandSettings settings = app.getSettings();
List<QuickSearchListItem> rows = new ArrayList<>();
if (SearchUICore.isDebugMode()) {
LOG.info("UI >> Start last city searching (within nearests)");
}
SearchResult lastCity = null;
if (res != null) {
citiesLoaded = res.getCurrentSearchResults().size() > 0;
final long lastCityId = settings.getLastSearchedCity();
for (SearchResult sr : res.getCurrentSearchResults()) {
if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
lastCity = sr;
break;
}
}
}
if (SearchUICore.isDebugMode()) {
LOG.info("UI >> Last city found: " + (lastCity != null ? lastCity.localeName : "-"));
}
final String lastCityName = lastCity == null ? settings.getLastSearchedCityName() : lastCity.localeName;
if (!Algorithms.isEmpty(lastCityName)) {
String selectStreets = app.getString(R.string.select_street);
String inCityName = app.getString(R.string.shared_string_in_name, lastCityName);
Spannable spannable = new SpannableString(selectStreets + " " + inCityName);
boolean light = settings.isLightContent();
spannable.setSpan(new ForegroundColorSpan(getResources().getColor(light ? R.color.icon_color : R.color.color_white)), selectStreets.length() + 1, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
final SearchResult lastCityFinal = lastCity;
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_street_name, spannable, new OnClickListener() {
@Override
public void onClick(View v) {
if (lastCityFinal == null) {
final long lastCityId = settings.getLastSearchedCity();
final LatLon lastCityPoint = settings.getLastSearchedPoint();
if (lastCityId != -1 && lastCityPoint != null) {
startLastCitySearch(lastCityPoint);
if (SearchUICore.isDebugMode()) {
LOG.info("UI >> Start last city searching (standalone)");
}
runCoreSearch("", false, false, new SearchResultListener() {
boolean cityFound = false;
@Override
public void publish(SearchResultCollection res, boolean append) {
if (res != null) {
for (SearchResult sr : res.getCurrentSearchResults()) {
if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
if (SearchUICore.isDebugMode()) {
LOG.info("UI >> Last city found: " + sr.localeName);
}
cityFound = true;
completeQueryWithObject(sr);
break;
}
}
}
}
@Override
public void searchStarted(SearchPhrase phrase) {
}
@Override
public boolean searchFinished(SearchPhrase phrase) {
if (!cityFound) {
replaceQueryWithText(lastCityName + " ");
}
return false;
}
});
restoreSearch();
} else {
replaceQueryWithText(lastCityName + " ");
}
} else {
completeQueryWithObject(lastCityFinal);
}
openKeyboard();
}
}));
}
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_building_number, app.getString(R.string.select_city), new OnClickListener() {
@Override
public void onClick(View v) {
searchEditText.setHint(R.string.type_city_town);
startCitySearch();
updateTabbarVisibility(false);
runCoreSearch("", false, false);
openKeyboard();
}
}));
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_postcode, app.getString(R.string.select_postcode), new OnClickListener() {
@Override
public void onClick(View v) {
searchEditText.setHint(R.string.type_postcode);
startPostcodeSearch();
mainSearchFragment.getAdapter().clear();
updateTabbarVisibility(false);
openKeyboard();
}
}));
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_marker_dark, app.getString(R.string.coords_search), new OnClickListener() {
@Override
public void onClick(View v) {
LatLon latLon = searchUICore.getSearchSettings().getOriginalLocation();
QuickSearchCoordinatesFragment.showDialog(QuickSearchDialogFragment.this, latLon.getLatitude(), latLon.getLongitude());
}
}));
if (res != null) {
rows.add(new QuickSearchHeaderListItem(app, app.getString(R.string.nearest_cities), true));
int limit = 15;
for (SearchResult sr : res.getCurrentSearchResults()) {
if (limit > 0) {
rows.add(new QuickSearchListItem(app, sr));
}
limit--;
}
}
addressSearchFragment.updateListAdapter(rows, false);
if (SearchUICore.isDebugMode()) {
LOG.info("UI >> Nearest cities loaded");
}
return true;
}
});
restoreSearch();
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method selectMapOverlayLayer.
public void selectMapOverlayLayer(@NonNull final OsmandMapTileView mapView, @NonNull final CommonPreference<String> mapPref, @NonNull final CommonPreference<String> exMapPref, boolean force, @NonNull final MapActivity activity, @Nullable final OnMapSelectedCallback callback) {
final MapActivityLayers layers = activity.getMapLayers();
if (!force && exMapPref.get() != null) {
mapPref.set(exMapPref.get());
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, mapPref, layers);
return;
}
final OsmandSettings settings = app.getSettings();
Map<String, String> entriesMap = settings.getTileSourceEntries();
final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final String[] items = new String[entriesMap.size() + 1];
int i = 0;
for (String it : entriesMap.values()) {
items[i++] = it;
}
items[i] = app.getString(R.string.install_more);
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == items.length - 1) {
installMapLayers(activity, new ResultMatcher<TileSourceTemplate>() {
TileSourceTemplate template = null;
int count = 0;
@Override
public boolean publish(TileSourceTemplate object) {
if (object == null) {
if (count == 1) {
mapPref.set(template.getName());
exMapPref.set(template.getName());
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, mapPref, layers);
} else {
selectMapOverlayLayer(mapView, mapPref, exMapPref, false, activity, null);
}
} else {
count++;
template = object;
}
return false;
}
@Override
public boolean isCancelled() {
return false;
}
});
} else {
mapPref.set(keys.get(which));
exMapPref.set(keys.get(which));
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, mapPref, layers);
}
dialog.dismiss();
}
}).setNegativeButton(R.string.shared_string_cancel, null).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (callback != null) {
callback.onMapSelected(true);
}
}
});
builder.show();
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method registerLayerContextMenuActions.
@Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
int[] viewCoordinates = AndroidUtils.getCenterViewCoordinates(view);
if (itemId == R.string.layer_overlay) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.OVERLAY_MAP, viewCoordinates);
return false;
} else if (itemId == R.string.layer_underlay) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.UNDERLAY_MAP, viewCoordinates);
return false;
}
return true;
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
switch(itemId) {
case R.string.layer_overlay:
toggleUnderlayState(mapActivity, RasterMapType.OVERLAY, new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
ContextMenuItem item = adapter.getItem(pos);
String overlayMapDescr = settings.MAP_OVERLAY.get();
boolean hasOverlayDescription = overlayMapDescr != null;
overlayMapDescr = hasOverlayDescription ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none);
item.setDescription(overlayMapDescr);
item.setSelected(hasOverlayDescription);
item.setColorRes(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
});
return false;
case R.string.layer_underlay:
toggleUnderlayState(mapActivity, RasterMapType.UNDERLAY, new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
ContextMenuItem item = adapter.getItem(pos);
String underlayMapDescr = settings.MAP_UNDERLAY.get();
boolean hasUnderlayDescription = underlayMapDescr != null;
underlayMapDescr = hasUnderlayDescription ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none);
item.setDescription(underlayMapDescr);
item.setSelected(hasUnderlayDescription);
item.setColorRes(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
hidePolygonsPref.set(hasUnderlayDescription);
RasterMapMenu.refreshMapComplete(mapActivity);
}
});
return false;
}
return true;
}
};
if (overlayLayer.getMap() == null) {
settings.MAP_OVERLAY.set(null);
settings.MAP_OVERLAY_PREVIOUS.set(null);
}
if (underlayLayer.getMap() == null) {
settings.MAP_UNDERLAY.set(null);
settings.MAP_UNDERLAY_PREVIOUS.set(null);
}
String overlayMapDescr = settings.MAP_OVERLAY.get();
boolean hasOverlayDescription = overlayMapDescr != null;
overlayMapDescr = hasOverlayDescription ? overlayMapDescr : mapActivity.getString(R.string.shared_string_none);
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_overlay, mapActivity).setDescription(overlayMapDescr).setSelected(hasOverlayDescription).setColor(hasOverlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_layer_top_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(14).createItem());
String underlayMapDescr = settings.MAP_UNDERLAY.get();
boolean hasUnderlayDescription = underlayMapDescr != null;
underlayMapDescr = hasUnderlayDescription ? underlayMapDescr : mapActivity.getString(R.string.shared_string_none);
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_underlay, mapActivity).setDescription(underlayMapDescr).setSelected(hasUnderlayDescription).setColor(hasUnderlayDescription ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_layer_bottom_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(15).createItem());
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method defineNewEditLayer.
public static void defineNewEditLayer(final Activity activity, final ResultMatcher<TileSourceTemplate> resultMatcher) {
final OsmandApplication app = (OsmandApplication) activity.getApplication();
final OsmandSettings settings = app.getSettings();
final Map<String, String> entriesMap = settings.getTileSourceEntries(false);
TileSourceTemplate ts = new TileSourceTemplate("NewMapnik", "http://mapnik.osmand.net/{0}/{1}/{2}.png", "png", 17, 5, 256, 16, 32000);
final TileSourceTemplate[] result = new TileSourceTemplate[] { ts };
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
View view = activity.getLayoutInflater().inflate(R.layout.editing_tile_source, null);
final EditText name = (EditText) view.findViewById(R.id.Name);
final Spinner existing = (Spinner) view.findViewById(R.id.TileSourceSpinner);
final EditText urlToLoad = (EditText) view.findViewById(R.id.URLToLoad);
final EditText minZoom = (EditText) view.findViewById(R.id.MinZoom);
final EditText maxZoom = (EditText) view.findViewById(R.id.MaxZoom);
final EditText expire = (EditText) view.findViewById(R.id.ExpirationTime);
final CheckBox elliptic = (CheckBox) view.findViewById(R.id.EllipticMercator);
updateTileSourceEditView(ts, name, urlToLoad, minZoom, maxZoom, expire, elliptic);
final ArrayList<String> templates = new ArrayList<>(entriesMap.keySet());
templates.add(0, "");
ArrayAdapter<String> adapter = new ArrayAdapter<>(view.getContext(), android.R.layout.simple_spinner_item, templates);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
existing.setAdapter(adapter);
existing.setSelection(0);
existing.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position > 0) {
File f = ((OsmandApplication) activity.getApplication()).getAppPath(IndexConstants.TILES_INDEX_DIR + templates.get(position));
TileSourceTemplate template = TileSourceManager.createTileSourceTemplate(f);
if (template != null) {
result[0] = template.copy();
updateTileSourceEditView(result[0], name, urlToLoad, minZoom, maxZoom, expire, elliptic);
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
bld.setView(view);
bld.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
TileSourceTemplate r = result[0];
try {
r.setName(name.getText().toString());
r.setExpirationTimeMinutes(expire.getText().length() == 0 ? -1 : Integer.parseInt(expire.getText().toString()));
r.setMinZoom(Integer.parseInt(minZoom.getText().toString()));
r.setMaxZoom(Integer.parseInt(maxZoom.getText().toString()));
r.setEllipticYTile(elliptic.isChecked());
r.setUrlToLoad(urlToLoad.getText().toString().equals("") ? null : urlToLoad.getText().toString().replace("{$x}", "{1}").replace("{$y}", "{2}").replace("{$z}", "{0}"));
if (r.getName().length() > 0) {
if (settings.installTileSource(r)) {
Toast.makeText(activity, activity.getString(R.string.edit_tilesource_successfully, r.getName()), Toast.LENGTH_SHORT).show();
resultMatcher.publish(r);
}
}
} catch (RuntimeException e) {
Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.show();
}
Aggregations