use of net.osmand.map.WorldRegion in project Osmand by osmandapp.
the class DownloadResources method prepareData.
protected boolean prepareData(List<IndexItem> resources) {
this.rawResources = resources;
DownloadResourceGroup otherMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.OTHER_MAPS_GROUP);
DownloadResourceGroup otherMapsScreen = new DownloadResourceGroup(otherMapsGroup, DownloadResourceGroupType.OTHER_MAPS);
DownloadResourceGroup otherMaps = new DownloadResourceGroup(otherMapsGroup, DownloadResourceGroupType.OTHER_MAPS_HEADER);
otherMapsScreen.addGroup(otherMaps);
otherMapsGroup.addGroup(otherMapsScreen);
DownloadResourceGroup otherGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.OTHER_GROUP);
DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_TTS);
DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_REC);
DownloadResourceGroup fontScreen = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS);
DownloadResourceGroup voiceTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_TTS);
DownloadResourceGroup voiceRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_REC);
DownloadResourceGroup fonts = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS_HEADER);
DownloadResourceGroup worldMaps = new DownloadResourceGroup(this, DownloadResourceGroupType.WORLD_MAPS);
DownloadResourceGroup nauticalMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.NAUTICAL_MAPS_GROUP);
DownloadResourceGroup nauticalMapsScreen = new DownloadResourceGroup(nauticalMapsGroup, DownloadResourceGroupType.NAUTICAL_MAPS);
DownloadResourceGroup nauticalMaps = new DownloadResourceGroup(nauticalMapsGroup, DownloadResourceGroupType.NAUTICAL_MAPS_HEADER);
Map<WorldRegion, List<IndexItem>> groupByRegion = new LinkedHashMap<WorldRegion, List<IndexItem>>();
OsmandRegions regs = app.getRegions();
for (IndexItem ii : resources) {
if (ii.getType() == DownloadActivityType.VOICE_FILE) {
if (ii.getFileName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
voiceTTS.addItem(ii);
} else {
voiceRec.addItem(ii);
}
continue;
}
if (ii.getType() == DownloadActivityType.FONT_FILE) {
fonts.addItem(ii);
continue;
}
if (ii.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE) {
if (app.getSettings().DEPTH_CONTOURS_PURCHASED.get() || nauticalMaps.size() == 0) {
nauticalMaps.addItem(ii);
}
continue;
}
String basename = ii.getBasename().toLowerCase();
WorldRegion wg = regs.getRegionDataByDownloadName(basename);
if (wg != null) {
if (!groupByRegion.containsKey(wg)) {
groupByRegion.put(wg, new ArrayList<IndexItem>());
}
groupByRegion.get(wg).add(ii);
} else {
if (ii.getFileName().startsWith("World_")) {
if (ii.getFileName().toLowerCase().startsWith(WORLD_SEAMARKS_KEY) || ii.getFileName().toLowerCase().startsWith(WORLD_SEAMARKS_OLD_KEY)) {
nauticalMaps.addItem(ii);
} else {
worldMaps.addItem(ii);
}
} else {
otherMaps.addItem(ii);
}
}
}
this.groupByRegion = groupByRegion;
LinkedList<WorldRegion> queue = new LinkedList<WorldRegion>();
LinkedList<DownloadResourceGroup> parent = new LinkedList<DownloadResourceGroup>();
DownloadResourceGroup worldSubregions = new DownloadResourceGroup(this, DownloadResourceGroupType.SUBREGIONS);
addGroup(worldSubregions);
for (WorldRegion rg : region.getSubregions()) {
queue.add(rg);
parent.add(worldSubregions);
}
while (!queue.isEmpty()) {
WorldRegion reg = queue.pollFirst();
DownloadResourceGroup parentGroup = parent.pollFirst();
List<WorldRegion> subregions = reg.getSubregions();
DownloadResourceGroup mainGrp = new DownloadResourceGroup(parentGroup, DownloadResourceGroupType.REGION, reg.getRegionId());
mainGrp.region = reg;
parentGroup.addGroup(mainGrp);
List<IndexItem> list = groupByRegion.get(reg);
if (list != null) {
DownloadResourceGroup flatFiles = new DownloadResourceGroup(mainGrp, DownloadResourceGroupType.REGION_MAPS);
for (IndexItem ii : list) {
flatFiles.addItem(ii);
}
mainGrp.addGroup(flatFiles);
}
DownloadResourceGroup subRegions = new DownloadResourceGroup(mainGrp, DownloadResourceGroupType.SUBREGIONS);
mainGrp.addGroup(subRegions);
// add to processing queue
for (WorldRegion rg : subregions) {
queue.add(rg);
parent.add(subRegions);
}
}
// Possible improvements
// 1. if there is no subregions no need to create resource group REGIONS_MAPS - objection raise diversity and there is no value
// 2. if there is no subregions and there only 1 index item it could be merged to the level up - objection there is no such maps
// 3. if hillshade/srtm is disabled, all maps from inner level could be combined into 1
addGroup(worldMaps);
nauticalMapsScreen.addGroup(nauticalMaps);
nauticalMapsGroup.addGroup(nauticalMapsScreen);
addGroup(nauticalMapsGroup);
if (otherMaps.size() > 0) {
addGroup(otherMapsGroup);
}
voiceScreenTTS.addGroup(voiceTTS);
voiceScreenRec.addGroup(voiceRec);
if (fonts.getIndividualResources() != null) {
fontScreen.addGroup(fonts);
}
otherGroup.addGroup(voiceScreenTTS);
otherGroup.addGroup(voiceScreenRec);
if (fonts.getIndividualResources() != null) {
otherGroup.addGroup(fontScreen);
}
addGroup(otherGroup);
createHillshadeSRTMGroups();
trimEmptyGroups();
updateLoadedFiles();
return true;
}
use of net.osmand.map.WorldRegion in project Osmand by osmandapp.
the class DownloadResources method findIndexItemsAt.
public static List<IndexItem> findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type) throws IOException {
List<IndexItem> res = new ArrayList<>();
OsmandRegions regions = app.getRegions();
DownloadIndexesThread downloadThread = app.getDownloadThread();
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
List<BinaryMapDataObject> mapDataObjects;
try {
mapDataObjects = regions.queryBbox(point31x, point31x, point31y, point31y);
} catch (IOException e) {
throw new IOException("Error while calling queryBbox");
}
if (mapDataObjects != null) {
Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (o.getTypes() != null) {
boolean isRegion = true;
for (int i = 0; i < o.getTypes().length; i++) {
BinaryMapIndexReader.TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
if ("boundary".equals(tp.value)) {
isRegion = false;
break;
}
}
WorldRegion downloadRegion = regions.getRegionData(regions.getFullName(o));
if (downloadRegion != null && isRegion && regions.contain(o, point31x, point31y)) {
if (!isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) {
addIndexItem(downloadThread, type, downloadRegion, res);
}
}
}
}
}
return res;
}
use of net.osmand.map.WorldRegion in project Osmand by osmandapp.
the class DownloadedRegionsLayer method getWorldRegionFromPoint.
private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List<? super DownloadMapObject> dataObjects) {
int zoom = tb.getZoom();
if (zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION && data.results != null && osmandRegions.isInitialized()) {
LatLon pointLatLon = tb.getLatLonFromPixel(point.x, point.y);
int point31x = MapUtils.get31TileNumberX(pointLatLon.getLongitude());
int point31y = MapUtils.get31TileNumberY(pointLatLon.getLatitude());
List<BinaryMapDataObject> result = new LinkedList<>(data.results);
Iterator<BinaryMapDataObject> it = result.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
boolean isRegion = true;
for (int i = 0; i < o.getTypes().length; i++) {
TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
if ("boundary".equals(tp.value)) {
isRegion = false;
break;
}
}
if (!isRegion || !osmandRegions.contain(o, point31x, point31y)) {
it.remove();
}
}
OsmandRegions osmandRegions = app.getRegions();
for (BinaryMapDataObject o : result) {
String fullName = osmandRegions.getFullName(o);
WorldRegion region = osmandRegions.getRegionData(fullName);
if (region != null && region.isRegionMapDownload()) {
List<IndexItem> indexItems = app.getDownloadThread().getIndexes().getIndexItems(region);
List<IndexItem> dataItems = new LinkedList<>();
IndexItem regularMapItem = null;
for (IndexItem item : indexItems) {
if (item.isDownloaded() || app.getDownloadThread().isDownloading(item)) {
dataItems.add(item);
if (item.getType() == DownloadActivityType.NORMAL_FILE) {
regularMapItem = item;
}
}
}
if (dataItems.isEmpty() && regularMapItem != null) {
dataItems.add(regularMapItem);
}
if (!dataItems.isEmpty()) {
for (IndexItem item : dataItems) {
dataObjects.add(new DownloadMapObject(o, region, item, null));
}
} else {
String downloadName = osmandRegions.getDownloadName(o);
List<LocalIndexInfo> infos = helper.getLocalIndexInfos(downloadName);
if (infos.size() == 0) {
dataObjects.add(new DownloadMapObject(o, region, null, null));
} else {
for (LocalIndexInfo info : infos) {
dataObjects.add(new DownloadMapObject(o, region, null, info));
}
}
}
}
}
}
}
use of net.osmand.map.WorldRegion in project Osmand by osmandapp.
the class MenuController method buildMapDownloadButtonAndSizeInfo.
public void buildMapDownloadButtonAndSizeInfo(final LatLon latLon) {
new AsyncTask<Void, Void, BinaryMapDataObject>() {
ResourceManager rm;
OsmandRegions osmandRegions;
String selectedFullName = "";
@Override
protected void onPreExecute() {
rm = getMapActivity().getMyApplication().getResourceManager();
osmandRegions = rm.getOsmandRegions();
}
@Override
protected BinaryMapDataObject doInBackground(Void... voids) {
int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
List<BinaryMapDataObject> mapDataObjects = null;
try {
mapDataObjects = osmandRegions.queryBbox(point31x, point31x, point31y, point31y);
} catch (IOException e) {
e.printStackTrace();
}
BinaryMapDataObject binaryMapDataObject = null;
if (mapDataObjects != null) {
Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (o.getTypes() != null) {
boolean isRegion = true;
for (int i = 0; i < o.getTypes().length; i++) {
TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
if ("boundary".equals(tp.value)) {
isRegion = false;
break;
}
}
if (!isRegion || !osmandRegions.contain(o, point31x, point31y)) {
it.remove();
}
}
}
double smallestArea = -1;
for (BinaryMapDataObject o : mapDataObjects) {
String downloadName = osmandRegions.getDownloadName(o);
if (!Algorithms.isEmpty(downloadName)) {
boolean downloaded = checkIfObjectDownloaded(rm, downloadName);
if (downloaded) {
binaryMapDataObject = null;
break;
} else {
String fullName = osmandRegions.getFullName(o);
WorldRegion region = osmandRegions.getRegionData(fullName);
if (region != null && region.isRegionMapDownload()) {
double area = OsmandRegions.getArea(o);
if (smallestArea == -1) {
smallestArea = area;
selectedFullName = fullName;
binaryMapDataObject = o;
} else if (area < smallestArea) {
smallestArea = area;
selectedFullName = fullName;
binaryMapDataObject = o;
}
}
}
}
}
}
return binaryMapDataObject;
}
@Override
protected void onPostExecute(BinaryMapDataObject binaryMapDataObject) {
downloadMapDataObject = binaryMapDataObject;
downloaded = downloadMapDataObject == null;
if (!downloaded) {
downloadThread = getMapActivity().getMyApplication().getDownloadThread();
downloadRegion = osmandRegions.getRegionData(selectedFullName);
if (downloadRegion != null && downloadRegion.isRegionMapDownload()) {
List<IndexItem> indexItems = downloadThread.getIndexes().getIndexItems(downloadRegion);
for (IndexItem item : indexItems) {
if (item.getType() == DownloadActivityType.NORMAL_FILE && (item.isDownloaded() || downloadThread.isDownloading(item))) {
indexItem = item;
}
}
}
leftDownloadButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
if (indexItem != null) {
if (indexItem.getType() == DownloadActivityType.NORMAL_FILE) {
new DownloadValidationManager(getMapActivity().getMyApplication()).startDownload(getMapActivity(), indexItem);
}
}
}
};
leftDownloadButtonController.caption = downloadRegion != null ? downloadRegion.getLocaleName() : getMapActivity().getString(R.string.shared_string_download);
leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
titleProgressController = new TitleProgressController() {
@Override
public void buttonPressed() {
if (indexItem != null) {
downloadThread.cancelDownload(indexItem);
}
}
};
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
if (getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable()) {
downloadThread.runReloadIndexFiles();
}
}
if (mapContextMenu != null) {
mapContextMenu.updateMenuUI();
}
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of net.osmand.map.WorldRegion in project Osmand by osmandapp.
the class LiveUpdatesFragment method updateSubscriptionHeader.
public void updateSubscriptionHeader() {
if (getActivity() instanceof OsmLiveActivity) {
View subscriptionBanner = subscriptionHeader.findViewById(R.id.subscription_banner);
View subscriptionInfo = subscriptionHeader.findViewById(R.id.subscription_info);
if (getSettings().LIVE_UPDATES_PURCHASED.get()) {
ImageView statusIcon = (ImageView) subscriptionHeader.findViewById(R.id.statusIcon);
TextView statusTextView = (TextView) subscriptionHeader.findViewById(R.id.statusTextView);
TextView regionNameTextView = (TextView) subscriptionHeader.findViewById(R.id.regionTextView);
statusTextView.setText(getString(R.string.osm_live_active));
statusIcon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_done));
String countryName = getSettings().BILLING_USER_COUNTRY.get();
if (Algorithms.isEmpty(countryName)) {
WorldRegion world = getMyApplication().getRegions().getWorldRegion();
countryName = world.getLocaleName();
}
regionNameTextView.setText(countryName);
subscriptionBanner.setVisibility(View.GONE);
subscriptionInfo.setVisibility(View.VISIBLE);
} else {
Button readMoreBtn = (Button) subscriptionHeader.findViewById(R.id.read_more_button);
readMoreBtn.setEnabled(!processing);
readMoreBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("https://osmand.net/osm_live.php");
Intent goToOsmLive = new Intent(Intent.ACTION_VIEW, uri);
startActivity(goToOsmLive);
}
});
Button subscriptionButton = (Button) subscriptionHeader.findViewById(R.id.subscription_button);
subscriptionButton.setEnabled(!processing);
subscriptionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SubscriptionFragment subscriptionFragment = new SubscriptionFragment();
subscriptionFragment.show(getChildFragmentManager(), SubscriptionFragment.TAG);
}
});
subscriptionBanner.setVisibility(View.VISIBLE);
subscriptionInfo.setVisibility(View.GONE);
}
}
}
Aggregations