use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class SnapToRoadBottomSheetDialogFragment method setupDialog.
@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
if (getMyApplication().getSettings().DO_NOT_USE_ANIMATIONS.get()) {
dialog.getWindow().setWindowAnimations(R.style.Animations_NoAnimation);
}
nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
final OsmandSettings settings = getMyApplication().getSettings();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_snap_to_road_bottom_sheet_dialog, null);
AndroidUtils.setBackground(getActivity(), mainView, nightMode, portrait ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_sheet_topsides_landscape_light, portrait ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_sheet_topsides_landscape_dark);
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
if (nightMode) {
((TextView) mainView.findViewById(R.id.choose_navigation_title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark));
}
LinearLayout container = (LinearLayout) mainView.findViewById(R.id.navigation_types_container);
final List<ApplicationMode> modes = new ArrayList<>(ApplicationMode.values(settings));
if (removeDefaultMode) {
modes.remove(ApplicationMode.DEFAULT);
}
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
snapToRoadEnabled = true;
if (listener != null) {
listener.onApplicationModeItemClick(modes.get((int) view.getTag()));
}
dismiss();
}
};
for (int i = 0; i < modes.size(); i++) {
ApplicationMode mode = modes.get(i);
View row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.list_item_icon_and_title, null);
((ImageView) row.findViewById(R.id.icon)).setImageDrawable(getContentIcon(mode.getSmallIconDark()));
((TextView) row.findViewById(R.id.title)).setText(mode.toHumanString(getContext()));
row.setOnClickListener(onClickListener);
row.setTag(i);
container.addView(row);
}
if (!portrait) {
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
BottomSheetDialog dialog = (BottomSheetDialog) dialogInterface;
FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
}
dialog.setContentView(mainView);
((View) mainView.getParent()).setBackgroundResource(0);
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class PointDescription method getLocationNamePlain.
public static String getLocationNamePlain(Context ctx, double lat, double lon) {
OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
int f = st.COORDINATES_FORMAT.get();
if (f == PointDescription.UTM_FORMAT) {
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " " + ((long) pnt.northing);
} else if (f == PointDescription.OLC_FORMAT) {
try {
return getLocationOlcName(lat, lon);
} catch (RuntimeException e) {
e.printStackTrace();
return "0, 0";
}
} else {
try {
return LocationConvert.convert(lat, f) + ", " + LocationConvert.convert(lon, f);
} catch (RuntimeException e) {
e.printStackTrace();
return "0, 0";
}
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class PointDescription method getLocationName.
public static String getLocationName(Context ctx, double lat, double lon, boolean sh) {
OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
int f = st.COORDINATES_FORMAT.get();
if (f == PointDescription.UTM_FORMAT) {
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " " + ((long) pnt.northing);
} else if (f == PointDescription.OLC_FORMAT) {
try {
return getLocationOlcName(lat, lon);
} catch (RuntimeException e) {
e.printStackTrace();
return "0, 0";
}
} else {
try {
return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, LocationConvert.convert(lat, f), LocationConvert.convert(lon, f));
} catch (RuntimeException e) {
e.printStackTrace();
return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, 0, 0);
}
}
}
use of net.osmand.plus.OsmandSettings 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);
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class EditPoiDialogFragment method showEditInstance.
public static void showEditInstance(final Amenity amenity, final AppCompatActivity activity) {
final OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
final OpenstreetmapUtil openstreetmapUtilToLoad;
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (// settings.OFFLINE_EDITION.get() ||
!settings.isInternetConnectionAvailable(true)) {
openstreetmapUtilToLoad = plugin.getPoiModificationLocalUtil();
} else {
openstreetmapUtilToLoad = plugin.getPoiModificationRemoteUtil();
}
new AsyncTask<Void, Void, Node>() {
@Override
protected Node doInBackground(Void... params) {
return openstreetmapUtilToLoad.loadNode(amenity);
}
protected void onPostExecute(Node n) {
if (n != null) {
EditPoiDialogFragment fragment = EditPoiDialogFragment.createInstance(n, false);
fragment.show(activity.getSupportFragmentManager(), TAG);
} else {
Toast.makeText(activity, activity.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Aggregations