use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class QuickSearchCoordinatesFragment method updateLocationCell.
private void updateLocationCell(final LatLon latLon) {
final OsmandApplication app = getMyApplication();
if (latLon == null) {
coordsView.setVisibility(View.GONE);
errorView.setVisibility(View.VISIBLE);
} else {
final TextView titleView = (TextView) coordsView.findViewById(R.id.title);
final TextView subtitleView = (TextView) coordsView.findViewById(R.id.subtitle);
titleView.setText(PointDescription.getLocationNamePlain(app, latLon.getLatitude(), latLon.getLongitude()));
new AsyncTask<LatLon, Void, String>() {
@Override
protected String doInBackground(LatLon... params) {
return app.getRegions().getCountryName(latLon);
}
@Override
protected void onPostExecute(String country) {
if (!paused) {
subtitleView.setText(country == null ? "" : country);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, latLon);
updateLocationUI(latLon, heading);
errorView.setVisibility(View.GONE);
coordsView.setVisibility(View.VISIBLE);
}
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class QuickSearchPoiFilterFragment method getListItems.
private List<PoiFilterListItem> getListItems() {
OsmandApplication app = getMyApplication();
MapPoiTypes poiTypes = app.getPoiTypes();
int groupId = 0;
List<PoiFilterListItem> items = new ArrayList<>();
Map<String, PoiType> poiAdditionals = filter.getPoiAdditionals();
Set<String> excludedPoiAdditionalCategories = getExcludedPoiAdditionalCategories();
List<PoiType> otherAdditionalCategories = poiTypes.getOtherMapCategory().getPoiAdditionalsCategorized();
if (!excludedPoiAdditionalCategories.contains("opening_hours")) {
items.add(new PoiFilterListItem(PoiFilterListItemType.DIVIDER, 0, null, -1, false, false, false, null, null));
String keyNameOpen = app.getString(R.string.shared_string_is_open).replace(' ', '_').toLowerCase();
items.add(new PoiFilterListItem(PoiFilterListItemType.SWITCH_ITEM, R.drawable.ic_action_time, app.getString(R.string.shared_string_is_open), ++groupId, false, false, selectedPoiAdditionals.contains(keyNameOpen), null, keyNameOpen));
String keyNameOpen24 = app.getString(R.string.shared_string_is_open_24_7).replace(' ', '_').toLowerCase();
items.add(new PoiFilterListItem(PoiFilterListItemType.SWITCH_ITEM, 0, app.getString(R.string.shared_string_is_open_24_7), groupId, false, false, selectedPoiAdditionals.contains(keyNameOpen24), null, keyNameOpen24));
}
if (poiAdditionals != null) {
Map<String, List<PoiType>> additionalsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
extractPoiAdditionals(poiAdditionals.values(), additionalsMap, excludedPoiAdditionalCategories, false);
extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, false);
if (additionalsMap.size() > 0) {
for (Entry<String, List<PoiType>> entry : additionalsMap.entrySet()) {
String category = entry.getKey();
String categoryLocalizedName = poiTypes.getPoiTranslation(category);
boolean expanded = !collapsedCategories.contains(category);
boolean showAll = showAllCategories.contains(category);
items.add(new PoiFilterListItem(PoiFilterListItemType.DIVIDER, 0, null, -1, false, false, false, null, null));
String categoryIconStr = poiTypes.getPoiAdditionalCategoryIconName(category);
int categoryIconId = 0;
if (!Algorithms.isEmpty(categoryIconStr)) {
categoryIconId = RenderingIcons.getBigIconResourceId(categoryIconStr);
}
if (categoryIconId == 0) {
categoryIconId = getResources().getIdentifier("mx_" + category, "drawable", app.getPackageName());
}
if (categoryIconId == 0) {
categoryIconId = R.drawable.ic_action_folder_stroke;
}
items.add(new PoiFilterListItem(PoiFilterListItemType.GROUP_HEADER, categoryIconId, categoryLocalizedName, ++groupId, true, expanded, false, category, null));
List<PoiType> categoryPoiAdditionals = new ArrayList<>(entry.getValue());
Collections.sort(categoryPoiAdditionals, new Comparator<PoiType>() {
@Override
public int compare(PoiType p1, PoiType p2) {
String firstPoiTypeTranslation = poiAdditionalsTranslations.get(p1);
String secondPoiTypeTranslation = poiAdditionalsTranslations.get(p2);
if (firstPoiTypeTranslation != null && secondPoiTypeTranslation != null) {
return firstPoiTypeTranslation.compareTo(secondPoiTypeTranslation);
} else {
return 0;
}
}
});
for (PoiType poiType : categoryPoiAdditionals) {
String keyName = poiType.getKeyName().replace('_', ':').toLowerCase();
String translation = poiAdditionalsTranslations.get(poiType);
items.add(new PoiFilterListItem(PoiFilterListItemType.CHECKBOX_ITEM, 0, translation, groupId, false, false, selectedPoiAdditionals.contains(keyName), category, keyName));
}
if (!showAll && categoryPoiAdditionals.size() > 0) {
items.add(new PoiFilterListItem(PoiFilterListItemType.BUTTON_ITEM, 0, app.getString(R.string.shared_string_show_all).toUpperCase(), groupId, false, false, false, category, null));
}
}
}
}
return items;
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class QuickSearchPoiFilterFragment method deleteFilter.
private void deleteFilter() {
final OsmandApplication app = getMyApplication();
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(R.string.edit_filter_delete_dialog_title);
builder.setNegativeButton(R.string.shared_string_no, null);
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (app.getPoiFilters().removePoiFilter(filter)) {
Toast.makeText(getContext(), MessageFormat.format(getContext().getText(R.string.edit_filter_delete_message).toString(), filter.getName()), Toast.LENGTH_SHORT).show();
app.getSearchUICore().refreshCustomPoiFilters();
QuickSearchDialogFragment quickSearchDialogFragment = (QuickSearchDialogFragment) getParentFragment();
quickSearchDialogFragment.reloadCategories();
quickSearchDialogFragment.clearLastWord();
QuickSearchPoiFilterFragment.this.dismiss();
}
}
});
builder.create().show();
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class ShowHidePoiAction method getIconRes.
@Override
public int getIconRes(Context context) {
if (getParams().get(KEY_FILTERS) == null || getParams().get(KEY_FILTERS).isEmpty()) {
return super.getIconRes();
} else {
OsmandApplication app = (OsmandApplication) context.getApplicationContext();
List<String> filters = new ArrayList<>();
String filtersId = getParams().get(KEY_FILTERS);
Collections.addAll(filters, filtersId.split(","));
if (app.getPoiFilters() == null)
return super.getIconRes();
PoiUIFilter filter = app.getPoiFilters().getFilterById(filters.get(0));
if (filter == null)
return super.getIconRes();
Object res = filter.getIconResource();
if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) {
return RenderingIcons.getBigIconResourceId(res.toString());
} else
return super.getIconRes();
}
}
use of net.osmand.plus.OsmandApplication 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