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();
}
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;
}
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();
}
}
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();
}
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();
}
Aggregations