use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class GpxUiHelper method setupGPXChart.
public static void setupGPXChart(OsmandApplication ctx, LineChart mChart, int yLabelsCount) {
OsmandSettings settings = ctx.getSettings();
boolean light = settings.isLightContent();
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
mChart.setHardwareAccelerationEnabled(false);
} else {
mChart.setHardwareAccelerationEnabled(true);
}
mChart.setTouchEnabled(true);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setPinchZoom(true);
mChart.setScaleYEnabled(false);
mChart.setAutoScaleMinMaxEnabled(true);
mChart.setDrawBorders(false);
mChart.getDescription().setEnabled(false);
mChart.setMaxVisibleValueCount(10);
mChart.setMinOffset(0f);
mChart.setDragDecelerationEnabled(false);
mChart.setExtraTopOffset(24f);
mChart.setExtraBottomOffset(16f);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
GPXMarkerView mv = new GPXMarkerView(mChart.getContext());
// For bounds control
mv.setChartView(mChart);
// Set the marker to the chart
mChart.setMarker(mv);
mChart.setDrawMarkers(true);
XAxis xAxis = mChart.getXAxis();
xAxis.setDrawAxisLine(false);
xAxis.setDrawGridLines(true);
xAxis.setGridLineWidth(1.5f);
xAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_black_grid));
xAxis.enableGridDashedLine(25f, Float.MAX_VALUE, 0f);
xAxis.setPosition(BOTTOM);
xAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
YAxis yAxis = mChart.getAxisLeft();
yAxis.enableGridDashedLine(10f, 5f, 0f);
yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.divider_color));
yAxis.setDrawAxisLine(false);
yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
yAxis.setXOffset(16f);
yAxis.setYOffset(-6f);
yAxis.setLabelCount(yLabelsCount);
yAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
yAxis = mChart.getAxisRight();
yAxis.enableGridDashedLine(10f, 5f, 0f);
yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.divider_color));
yAxis.setDrawAxisLine(false);
yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
yAxis.setXOffset(16f);
yAxis.setYOffset(-6f);
yAxis.setLabelCount(yLabelsCount);
yAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
yAxis.setEnabled(false);
Legend legend = mChart.getLegend();
legend.setEnabled(false);
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class GpxUiHelper method createGPXSlopeDataSet.
public static OrderedLineDataSet createGPXSlopeDataSet(OsmandApplication ctx, LineChart mChart, GPXTrackAnalysis analysis, GPXDataSetAxisType axisType, List<Entry> eleValues, boolean useRightAxis, boolean drawFilled) {
if (axisType == GPXDataSetAxisType.TIME) {
return null;
}
OsmandSettings settings = ctx.getSettings();
boolean light = settings.isLightContent();
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
final float convEle = useFeet ? 3.28084f : 1.0f;
final float totalDistance = analysis.totalDistance;
XAxis xAxis = mChart.getXAxis();
float divX = setupXAxisDistance(ctx, xAxis, analysis.totalDistance);
final String mainUnitY = "%";
YAxis yAxis;
if (useRightAxis) {
yAxis = mChart.getAxisRight();
yAxis.setEnabled(true);
} else {
yAxis = mChart.getAxisLeft();
}
yAxis.setTextColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_green_label));
yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_green_grid));
yAxis.setGranularity(1f);
yAxis.resetAxisMinimum();
yAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return (int) value + " " + mainUnitY;
}
});
List<Entry> values;
if (eleValues == null) {
values = calculateElevationArray(analysis, GPXDataSetAxisType.DISTANCE, 1f, 1f);
} else {
values = new ArrayList<>(eleValues.size());
for (Entry e : eleValues) {
values.add(new Entry(e.getX() * divX, e.getY() / convEle));
}
}
if (values == null || values.size() == 0) {
if (useRightAxis) {
yAxis.setEnabled(false);
}
return null;
}
int lastIndex = values.size() - 1;
double STEP = 5;
double[] calculatedDist = new double[(int) (totalDistance / STEP) + 1];
double[] calculatedH = new double[(int) (totalDistance / STEP) + 1];
int nextW = 0;
for (int k = 0; k < calculatedDist.length; k++) {
if (k > 0) {
calculatedDist[k] = calculatedDist[k - 1] + STEP;
}
while (nextW < lastIndex && calculatedDist[k] > values.get(nextW).getX()) {
nextW++;
}
double pd = nextW == 0 ? 0 : values.get(nextW - 1).getX();
double ph = nextW == 0 ? values.get(0).getY() : values.get(nextW - 1).getY();
calculatedH[k] = ph + (values.get(nextW).getY() - ph) / (values.get(nextW).getX() - pd) * (calculatedDist[k] - pd);
}
double SLOPE_PROXIMITY = 100;
if (totalDistance - SLOPE_PROXIMITY < 0) {
if (useRightAxis) {
yAxis.setEnabled(false);
}
return null;
}
double[] calculatedSlopeDist = new double[(int) ((totalDistance - SLOPE_PROXIMITY) / STEP) + 1];
double[] calculatedSlope = new double[(int) ((totalDistance - SLOPE_PROXIMITY) / STEP) + 1];
int index = (int) ((SLOPE_PROXIMITY / STEP) / 2);
for (int k = 0; k < calculatedSlopeDist.length; k++) {
calculatedSlopeDist[k] = calculatedDist[index + k];
calculatedSlope[k] = (calculatedH[2 * index + k] - calculatedH[k]) * 100 / SLOPE_PROXIMITY;
if (Double.isNaN(calculatedSlope[k])) {
calculatedSlope[k] = 0;
}
}
List<Entry> slopeValues = new ArrayList<>(calculatedSlopeDist.length);
float prevSlope = -80000;
float slope;
float x;
float lastXSameY = 0;
boolean hasSameY = false;
Entry lastEntry = null;
lastIndex = calculatedSlopeDist.length - 1;
for (int i = 0; i < calculatedSlopeDist.length; i++) {
x = (float) calculatedSlopeDist[i] / divX;
slope = (float) calculatedSlope[i];
if (prevSlope != -80000) {
if (prevSlope == slope && i < lastIndex) {
hasSameY = true;
lastXSameY = x;
continue;
}
if (hasSameY) {
slopeValues.add(new Entry(lastXSameY, lastEntry.getY()));
}
hasSameY = false;
}
prevSlope = slope;
lastEntry = new Entry(x, slope);
slopeValues.add(lastEntry);
}
OrderedLineDataSet dataSet = new OrderedLineDataSet(slopeValues, "", GPXDataSetType.SLOPE, axisType);
dataSet.divX = divX;
dataSet.units = mainUnitY;
dataSet.setColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_green));
dataSet.setLineWidth(1f);
if (drawFilled) {
dataSet.setFillAlpha(128);
dataSet.setFillColor(ContextCompat.getColor(mChart.getContext(), R.color.gpx_chart_green));
dataSet.setDrawFilled(true);
} else {
dataSet.setDrawFilled(false);
}
dataSet.setDrawValues(false);
dataSet.setValueTextSize(9f);
dataSet.setFormLineWidth(1f);
dataSet.setFormSize(15.f);
dataSet.setDrawCircles(false);
dataSet.setDrawCircleHole(false);
dataSet.setHighlightEnabled(true);
dataSet.setDrawVerticalHighlightIndicator(true);
dataSet.setDrawHorizontalHighlightIndicator(false);
dataSet.setHighLightColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
/*
dataSet.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
return dataProvider.getYChartMin();
}
});
*/
if (useRightAxis) {
dataSet.setAxisDependency(YAxis.AxisDependency.RIGHT);
}
return dataSet;
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class AmenityMenuBuilder method buildInternal.
@Override
public void buildInternal(View view) {
boolean hasWiki = false;
MapPoiTypes poiTypes = app.getPoiTypes();
String preferredLang = getPreferredMapAppLang();
List<AmenityInfoRow> infoRows = new LinkedList<>();
List<AmenityInfoRow> descriptions = new LinkedList<>();
Map<String, List<PoiType>> poiAdditionalCategories = new HashMap<>();
AmenityInfoRow cuisineRow = null;
for (Map.Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
int iconId = 0;
Drawable icon = null;
int textColor = 0;
String key = e.getKey();
String vl = e.getValue();
if (key.equals("image") || key.equals("mapillary") || key.equals("subway_region")) {
continue;
}
String textPrefix = "";
CollapsableView collapsableView = null;
boolean collapsable = false;
boolean isWiki = false;
boolean isText = false;
boolean isDescription = false;
boolean needLinks = !"population".equals(key);
boolean isPhoneNumber = false;
boolean isUrl = false;
boolean isCuisine = false;
int poiTypeOrder = 0;
String poiTypeKeyName = "";
AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(key);
if (pt == null && !Algorithms.isEmpty(vl) && vl.length() < 50) {
pt = poiTypes.getAnyPoiAdditionalTypeByKey(key + "_" + vl);
}
PoiType pType = null;
if (pt != null) {
pType = (PoiType) pt;
if (pType.isFilterOnly()) {
continue;
}
poiTypeOrder = pType.getOrder();
poiTypeKeyName = pType.getKeyName();
}
if (pType != null && !pType.isText()) {
String categoryName = pType.getPoiAdditionalCategory();
if (!Algorithms.isEmpty(categoryName)) {
List<PoiType> poiAdditionalCategoryTypes = poiAdditionalCategories.get(categoryName);
if (poiAdditionalCategoryTypes == null) {
poiAdditionalCategoryTypes = new ArrayList<>();
poiAdditionalCategories.put(categoryName, poiAdditionalCategoryTypes);
}
poiAdditionalCategoryTypes.add(pType);
continue;
}
}
if (amenity.getType().isWiki()) {
if (!hasWiki) {
String lng = amenity.getContentLanguage("content", preferredLang, "en");
if (Algorithms.isEmpty(lng)) {
lng = "en";
}
final String langSelected = lng;
String content = amenity.getDescription(langSelected);
vl = (content != null) ? Html.fromHtml(content).toString() : "";
if (vl.length() > 300) {
vl = vl.substring(0, 300);
}
hasWiki = true;
isWiki = true;
needLinks = false;
} else {
continue;
}
} else if (key.startsWith("name:")) {
continue;
} else if (Amenity.OPENING_HOURS.equals(key)) {
iconId = R.drawable.ic_action_time;
collapsableView = getCollapsableTextView(view.getContext(), true, amenity.getOpeningHours());
collapsable = true;
OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
if (rs != null) {
vl = rs.toLocalString();
Calendar inst = Calendar.getInstance();
inst.setTimeInMillis(System.currentTimeMillis());
boolean opened = rs.isOpenedForTime(inst);
if (opened) {
textColor = R.color.color_ok;
} else {
textColor = R.color.color_invalid;
}
}
needLinks = false;
} else if (Amenity.PHONE.equals(key)) {
iconId = R.drawable.ic_action_call_dark;
isPhoneNumber = true;
} else if (Amenity.WEBSITE.equals(key)) {
iconId = R.drawable.ic_world_globe_dark;
isUrl = true;
} else if (Amenity.CUISINE.equals(key)) {
isCuisine = true;
iconId = R.drawable.ic_action_cuisine;
StringBuilder sb = new StringBuilder();
for (String c : e.getValue().split(";")) {
if (sb.length() > 0) {
sb.append(", ");
sb.append(poiTypes.getPoiTranslation("cuisine_" + c).toLowerCase());
} else {
sb.append(poiTypes.getPoiTranslation("cuisine_" + c));
}
}
textPrefix = app.getString(R.string.poi_cuisine);
vl = sb.toString();
} else if (key.contains(Amenity.ROUTE)) {
continue;
} else {
if (key.contains(Amenity.DESCRIPTION)) {
iconId = R.drawable.ic_action_note_dark;
} else {
iconId = R.drawable.ic_action_info_dark;
}
if (pType != null) {
poiTypeOrder = pType.getOrder();
poiTypeKeyName = pType.getKeyName();
if (pType.getParentType() != null && pType.getParentType() instanceof PoiType) {
icon = getRowIcon(view.getContext(), ((PoiType) pType.getParentType()).getOsmTag() + "_" + pType.getOsmTag().replace(':', '_') + "_" + pType.getOsmValue());
}
if (!pType.isText()) {
vl = pType.getTranslation();
} else {
isText = true;
isDescription = iconId == R.drawable.ic_action_note_dark;
textPrefix = pType.getTranslation();
vl = amenity.unzipContent(e.getValue());
}
if (!isDescription && icon == null) {
icon = getRowIcon(view.getContext(), pType.getIconKeyName());
if (isText && icon != null) {
textPrefix = "";
}
}
if (icon == null && isText) {
iconId = R.drawable.ic_action_note_dark;
}
} else {
textPrefix = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey());
vl = amenity.unzipContent(e.getValue());
}
}
if (vl.startsWith("http://") || vl.startsWith("https://") || vl.startsWith("HTTP://") || vl.startsWith("HTTPS://")) {
isUrl = true;
}
boolean matchWidthDivider = !isDescription && isWiki;
AmenityInfoRow row;
if (isDescription) {
row = new AmenityInfoRow(key, R.drawable.ic_action_note_dark, textPrefix, vl, collapsable, collapsableView, 0, false, true, true, 0, "", false, false, matchWidthDivider, 0);
} else if (icon != null) {
row = new AmenityInfoRow(key, icon, textPrefix, vl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0);
} else {
row = new AmenityInfoRow(key, iconId, textPrefix, vl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0);
}
if (isDescription) {
descriptions.add(row);
} else {
if (!isCuisine) {
infoRows.add(row);
} else {
cuisineRow = row;
}
}
}
if (cuisineRow != null) {
boolean hasCuisineOrDish = poiAdditionalCategories.get(Amenity.CUISINE) != null || poiAdditionalCategories.get(Amenity.DISH) != null;
if (!hasCuisineOrDish) {
infoRows.add(cuisineRow);
}
}
for (Map.Entry<String, List<PoiType>> e : poiAdditionalCategories.entrySet()) {
String categoryName = e.getKey();
List<PoiType> categoryTypes = e.getValue();
if (categoryTypes.size() > 0) {
Drawable icon;
PoiType pType = categoryTypes.get(0);
String poiAdditionalCategoryName = pType.getPoiAdditionalCategory();
String poiAddidionalIconName = poiTypes.getPoiAdditionalCategoryIconName(poiAdditionalCategoryName);
icon = getRowIcon(view.getContext(), poiAddidionalIconName);
if (icon == null) {
icon = getRowIcon(view.getContext(), poiAdditionalCategoryName);
}
if (icon == null) {
icon = getRowIcon(view.getContext(), pType.getIconKeyName());
}
if (icon == null) {
icon = getRowIcon(R.drawable.ic_action_note_dark);
}
StringBuilder sb = new StringBuilder();
for (PoiType pt : categoryTypes) {
if (sb.length() > 0) {
sb.append(" • ");
}
sb.append(pt.getTranslation());
}
boolean cuisineOrDish = categoryName.equals(Amenity.CUISINE) || categoryName.equals(Amenity.DISH);
CollapsableView collapsableView = getPoiAdditionalCollapsableView(view.getContext(), true, categoryTypes, cuisineOrDish ? cuisineRow : null);
infoRows.add(new AmenityInfoRow(poiAdditionalCategoryName, icon, pType.getPoiAdditionalCategoryTranslation(), sb.toString(), true, collapsableView, 0, false, false, false, pType.getOrder(), pType.getKeyName(), false, false, false, 1));
}
}
Collections.sort(infoRows, new Comparator<AmenityInfoRow>() {
@Override
public int compare(AmenityInfoRow row1, AmenityInfoRow row2) {
if (row1.order < row2.order) {
return -1;
} else if (row1.order == row2.order) {
return row1.name.compareTo(row2.name);
} else {
return 1;
}
}
});
for (AmenityInfoRow info : infoRows) {
buildAmenityRow(view, info);
}
String langSuffix = ":" + preferredLang;
AmenityInfoRow descInPrefLang = null;
for (AmenityInfoRow desc : descriptions) {
if (desc.key.length() > langSuffix.length() && desc.key.substring(desc.key.length() - langSuffix.length(), desc.key.length()).equals(langSuffix)) {
descInPrefLang = desc;
break;
}
}
if (descInPrefLang != null) {
descriptions.remove(descInPrefLang);
descriptions.add(0, descInPrefLang);
}
for (AmenityInfoRow info : descriptions) {
buildAmenityRow(view, info);
}
if (processNearstWiki() && nearestWiki.size() > 0) {
AmenityInfoRow wikiInfo = new AmenityInfoRow("nearest_wiki", R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", true, getCollapsableWikiView(view.getContext(), true), 0, false, false, false, 1000, null, false, false, false, 0);
buildAmenityRow(view, wikiInfo);
}
OsmandSettings st = ((OsmandApplication) mapActivity.getApplicationContext()).getSettings();
boolean osmEditingEnabled = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null;
if (osmEditingEnabled && amenity.getId() != null && amenity.getId() > 0 && (amenity.getId() % 2 == 0 || (amenity.getId() >> 1) < Integer.MAX_VALUE)) {
String link;
if (amenity.getId() % 2 == 0) {
link = "https://www.openstreetmap.org/node/";
} else {
link = "https://www.openstreetmap.org/way/";
}
buildRow(view, R.drawable.ic_action_info_dark, null, link + (amenity.getId() >> 1), 0, false, null, true, 0, true, null, false);
}
buildRow(view, R.drawable.ic_action_get_my_location, null, PointDescription.getLocationName(app, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), true).replaceAll("\n", " "), 0, false, null, false, 0, false, null, false);
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class PerformLiveUpdateAsyncTask method onPostExecute.
@Override
protected void onPostExecute(IncrementalChangesManager.IncrementalUpdateList result) {
LOG.debug("onPostExecute");
if (context instanceof AbstractDownloadActivity) {
AbstractDownloadActivity activity = (AbstractDownloadActivity) context;
activity.setSupportProgressBarIndeterminateVisibility(false);
}
final OsmandApplication application = getMyApplication();
final OsmandSettings settings = application.getSettings();
if (result.errorMessage != null) {
LOG.info(result.errorMessage);
tryRescheduleDownload(context, settings, localIndexFileName);
} else {
settings.LIVE_UPDATES_RETRIES.resetToDefault();
List<IncrementalChangesManager.IncrementalUpdate> ll = result.getItemsForUpdate();
if (ll != null && !ll.isEmpty()) {
ArrayList<IndexItem> itemsToDownload = new ArrayList<>(ll.size());
for (IncrementalChangesManager.IncrementalUpdate iu : ll) {
IndexItem indexItem = new IndexItem(iu.fileName, "Incremental update", iu.timestamp, iu.sizeText, iu.contentSize, iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE);
itemsToDownload.add(indexItem);
}
DownloadIndexesThread downloadThread = application.getDownloadThread();
if (context instanceof DownloadIndexesThread.DownloadEvents) {
downloadThread.setUiActivity((DownloadIndexesThread.DownloadEvents) context);
}
boolean downloadViaWiFi = LiveUpdatesHelper.preferenceDownloadViaWiFi(localIndexFileName, settings).get();
if (getMyApplication().getSettings().isInternetConnectionAvailable()) {
if (forceUpdate || settings.isWifiConnected() || !downloadViaWiFi) {
long szLong = 0;
int i = 0;
for (IndexItem es : downloadThread.getCurrentDownloadingItems()) {
szLong += es.getContentSize();
i++;
}
for (IndexItem es : itemsToDownload) {
szLong += es.getContentSize();
i++;
}
double sz = ((double) szLong) / (1 << 20);
// get availabile space
double asz = downloadThread.getAvailableSpace();
if (asz == -1 || asz <= 0 || sz / asz <= 0.4) {
IndexItem[] itemsArray = new IndexItem[itemsToDownload.size()];
itemsArray = itemsToDownload.toArray(itemsArray);
downloadThread.runDownloadFiles(itemsArray);
if (context instanceof DownloadIndexesThread.DownloadEvents) {
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
}
}
}
}
} else {
if (context instanceof DownloadIndexesThread.DownloadEvents) {
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
}
}
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class UpdatesIndexFragment method invalidateListView.
public void invalidateListView(Activity a) {
DownloadResources indexes = getMyApplication().getDownloadThread().getIndexes();
List<IndexItem> indexItems = indexes.getItemsToUpdate();
final OsmandRegions osmandRegions = getMyApplication().getResourceManager().getOsmandRegions();
OsmandSettings settings = getMyApplication().getSettings();
listAdapter = new UpdateIndexAdapter(a, R.layout.download_index_list_item, indexItems, !settings.LIVE_UPDATES_PURCHASED.get() || settings.SHOULD_SHOW_FREE_VERSION_BANNER.get());
listAdapter.sort(new Comparator<IndexItem>() {
@Override
public int compare(IndexItem indexItem, IndexItem indexItem2) {
return indexItem.getVisibleName(getMyApplication(), osmandRegions).compareTo(indexItem2.getVisibleName(getMyApplication(), osmandRegions));
}
});
setListAdapter(listAdapter);
updateErrorMessage();
}
Aggregations