use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class SelectCategoryDialogFragment method getIcon.
private static Drawable getIcon(final Activity activity, int resId, int color) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
Drawable d = app.getResources().getDrawable(resId).mutate();
d.clearColorFilter();
d.setColorFilter(color, PorterDuff.Mode.SRC_IN);
return d;
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class FavouritesAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof FavouritesViewHolder) {
OsmandApplication app = (OsmandApplication) ((Activity) context).getApplication();
IconsCache iconsCache = app.getIconsCache();
FavouritesViewHolder favouritesViewHolder = (FavouritesViewHolder) holder;
FavouritePoint favouritePoint = getItem(position);
favouritesViewHolder.title.setText(favouritePoint.getName());
if (favouritePoint.getCategory().equals("")) {
favouritesViewHolder.description.setText(R.string.shared_string_favorites);
} else {
favouritesViewHolder.description.setText(favouritePoint.getCategory());
}
Location myloc = app.getLocationProvider().getLastKnownLocation();
favouritesViewHolder.favouriteImage.setImageDrawable(FavoriteImageDrawable.getOrCreate(context, favouritePoint.getColor(), false));
if (myloc == null) {
return;
}
float dist = (float) MapUtils.getDistance(favouritePoint.getLatitude(), favouritePoint.getLongitude(), myloc.getLatitude(), myloc.getLongitude());
favouritesViewHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
favouritesViewHolder.arrowImage.setImageDrawable(iconsCache.getIcon(R.drawable.ic_direction_arrow));
DashLocationFragment.updateLocationView(useCenter, location, heading, favouritesViewHolder.arrowImage, favouritesViewHolder.distance, favouritePoint.getLatitude(), favouritePoint.getLongitude(), screenOrientation, app, context);
}
}
use of net.osmand.plus.OsmandApplication 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.OsmandApplication 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.OsmandApplication in project Osmand by osmandapp.
the class DashTrackFragment method setupGpxFiles.
private void setupGpxFiles() {
View mainView = getView();
final File dir = getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
final OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
final List<String> list = new ArrayList<String>();
for (SelectedGpxFile sg : app.getSelectedGpxHelper().getSelectedGPXFiles()) {
if (!sg.isShowCurrentTrack()) {
GPXFile gpxFile = sg.getGpxFile();
if (gpxFile != null) {
list.add(gpxFile.path);
}
}
}
int totalCount = 3 + list.size() / 2;
if (app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
totalCount--;
}
if (list.size() < totalCount) {
final List<GPXInfo> res = GpxUiHelper.getSortedGPXFilesInfoByDate(dir, true);
for (GPXInfo r : res) {
String name = r.getFileName();
if (!list.contains(name)) {
list.add(name);
if (list.size() >= totalCount) {
break;
}
}
}
}
if (list.size() == 0 && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) == null) {
(mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
return;
} else {
(mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
DashboardOnMap.handleNumberOfRows(list, getMyApplication().getSettings(), ROW_NUMBER_TAG);
}
LinearLayout tracks = (LinearLayout) mainView.findViewById(R.id.items);
tracks.removeAllViews();
LayoutInflater inflater = getActivity().getLayoutInflater();
if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
View view = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
createCurrentTrackView(view, app);
((TextView) view.findViewById(R.id.name)).setText(R.string.shared_string_currently_recording_track);
updateCurrentTrack(view, getActivity(), app);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AvailableGPXFragment.openTrack(getActivity(), null);
}
});
view.findViewById(R.id.divider_dash).setVisibility(View.VISIBLE);
tracks.addView(view);
startHandler(view);
}
for (String filename : list) {
final File f = new File(filename);
AvailableGPXFragment.GpxInfo info = new AvailableGPXFragment.GpxInfo();
info.subfolder = "";
info.file = f;
View v = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
AvailableGPXFragment.updateGpxInfoView(v, info, app, true);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AvailableGPXFragment.openTrack(getActivity(), f);
}
});
ImageButton showOnMap = ((ImageButton) v.findViewById(R.id.show_on_map));
showOnMap.setVisibility(View.VISIBLE);
showOnMap.setContentDescription(getString(R.string.shared_string_show_on_map));
updateShowOnMap(app, f, v, showOnMap);
tracks.addView(v);
}
}
Aggregations