use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class FirstUsageWizardFragment method startDownload.
private boolean startDownload(int itemIndex) {
boolean downloadStarted = false;
if (itemIndex == 0 && indexItems.size() > 0) {
IndexItem indexItem = indexItems.get(0);
if (!downloadThread.isDownloading(indexItem) && !indexItem.isDownloaded() && !firstMapDownloadCancelled) {
validationManager.startDownload(getActivity(), indexItem);
downloadStarted = true;
}
} else if (itemIndex == 1 && indexItems.size() > 1) {
IndexItem indexItem = indexItems.get(1);
if (!downloadThread.isDownloading(indexItem) && !indexItem.isDownloaded() && !secondMapDownloadCancelled) {
validationManager.startDownload(getActivity(), indexItem);
downloadStarted = true;
}
}
return downloadStarted;
}
use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class FirstUsageWizardFragment method downloadInProgress.
@Override
public void downloadInProgress() {
IndexItem indexItem = downloadThread.getCurrentDownloadingItem();
if (indexItem != null && !indexItem.isDownloaded()) {
int progress = downloadThread.getCurrentDownloadingItemProgress();
double mb = indexItem.getArchiveSizeMB();
String v;
if (progress != -1) {
v = getString(R.string.value_downloaded_of_max, mb * progress / 100, mb);
} else {
v = getString(R.string.file_size_in_mb, mb);
}
int index = indexItems.indexOf(indexItem);
if (index == 0) {
if (!firstMapDownloadCancelled) {
final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map_downloading_desc);
ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.map_download_progress_bar);
mapDescriptionTextView.setText(v);
progressBar.setProgress(progress < 0 ? 0 : progress);
}
} else if (index == 1) {
if (!secondMapDownloadCancelled) {
final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map2_downloading_desc);
ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.map2_download_progress_bar);
mapDescriptionTextView.setText(v);
progressBar.setProgress(progress < 0 ? 0 : progress);
}
}
}
updateDownloadedItems();
}
use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class FirstUsageWizardFragment method updateDownloadedItems.
private void updateDownloadedItems() {
int i = 0;
final View firstRowLayout = view.findViewById(R.id.map_downloading_layout);
final View secondRowLayout = view.findViewById(R.id.map2_downloading_layout);
final View progressLayout = view.findViewById(R.id.map_download_progress_layout);
final View progressLayout2 = view.findViewById(R.id.map2_download_progress_layout);
final ImageButton redownloadButton = (ImageButton) view.findViewById(R.id.map_redownload_button);
final ImageButton redownloadButton2 = (ImageButton) view.findViewById(R.id.map2_redownload_button);
for (IndexItem indexItem : indexItems) {
if (indexItem.isDownloaded()) {
if (i == 0 && progressLayout.getVisibility() == View.VISIBLE) {
final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map_downloading_desc);
mapDescriptionTextView.setText(indexItem.getSizeDescription(getContext()));
view.findViewById(R.id.map_download_padding).setVisibility(View.VISIBLE);
progressLayout.setVisibility(View.GONE);
firstRowLayout.setClickable(true);
final LatLon mapCenter = getMapCenter(indexItem);
final int mapZoom = getMapZoom(indexItem);
firstRowLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showOnMap(mapCenter, mapZoom);
}
});
} else if (i == 1 && progressLayout2.getVisibility() == View.VISIBLE) {
final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map2_downloading_desc);
mapDescriptionTextView.setText(indexItem.getSizeDescription(getContext()));
view.findViewById(R.id.map2_download_padding).setVisibility(View.VISIBLE);
progressLayout2.setVisibility(View.GONE);
secondRowLayout.setClickable(true);
final LatLon mapCenter = getMapCenter(indexItem);
final int mapZoom = getMapZoom(indexItem);
secondRowLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showOnMap(mapCenter, mapZoom);
}
});
}
} else {
if (downloadThread.isDownloading(indexItem)) {
if (i == 0 && !firstMapDownloadCancelled) {
if (progressLayout.getVisibility() == View.GONE) {
progressLayout.setVisibility(View.VISIBLE);
}
if (redownloadButton.getVisibility() == View.VISIBLE) {
redownloadButton.setVisibility(View.GONE);
}
}
if (i == 1 && !secondMapDownloadCancelled) {
if (progressLayout2.getVisibility() == View.GONE) {
progressLayout2.setVisibility(View.VISIBLE);
}
if (redownloadButton2.getVisibility() == View.VISIBLE) {
redownloadButton2.setVisibility(View.GONE);
}
}
}
}
i++;
}
}
use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class FirstUsageWizardFragment method searchMap.
private void searchMap() {
if (location != null) {
int point31x = MapUtils.get31TileNumberX(location.getLongitude());
int point31y = MapUtils.get31TileNumberY(location.getLatitude());
ResourceManager rm = getMyApplication().getResourceManager();
OsmandRegions osmandRegions = rm.getOsmandRegions();
List<BinaryMapDataObject> mapDataObjects = null;
try {
mapDataObjects = osmandRegions.queryBbox(point31x, point31x, point31y, point31y);
} catch (IOException e) {
e.printStackTrace();
}
String selectedFullName = "";
if (mapDataObjects != null) {
Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (!osmandRegions.contain(o, point31x, point31y)) {
it.remove();
}
}
for (BinaryMapDataObject o : mapDataObjects) {
String fullName = osmandRegions.getFullName(o);
if (fullName.length() > selectedFullName.length()) {
selectedFullName = fullName;
}
}
}
if (!Algorithms.isEmpty(selectedFullName)) {
WorldRegion downloadRegion = osmandRegions.getRegionData(selectedFullName);
if (downloadRegion != null && downloadRegion.isRegionMapDownload()) {
localDownloadRegion = downloadRegion;
List<IndexItem> indexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
for (IndexItem item : indexItems) {
if (item.getType() == DownloadActivityType.NORMAL_FILE) {
localMapIndexItem = item;
break;
}
}
}
}
baseMapIndexItem = downloadThread.getIndexes().getWorldBaseMapItem();
if (localMapIndexItem != null || baseMapIndexItem != null) {
showMapFoundFragment(getActivity());
} else {
closeWizard();
}
} else {
showNoLocationFragment(getActivity());
}
}
use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.
the class MenuController method updateData.
public void updateData() {
if (downloadMapDataObject != null) {
if (indexItem == null) {
List<IndexItem> indexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
for (IndexItem item : indexItems) {
if (item.getType() == DownloadActivityType.NORMAL_FILE) {
indexItem = item;
break;
}
}
}
if (indexItem != null) {
downloaded = indexItem.isDownloaded();
}
leftDownloadButtonController.visible = !downloaded;
leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
boolean internetConnectionAvailable = getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable();
boolean downloadIndexes = internetConnectionAvailable && !downloadThread.getIndexes().isDownloadedFromInternet && !downloadThread.getIndexes().downloadFromInternetFailed;
boolean isDownloading = indexItem != null && downloadThread.isDownloading(indexItem);
if (isDownloading) {
titleProgressController.setMapDownloadMode();
if (downloadThread.getCurrentDownloadingItem() == indexItem) {
titleProgressController.indeterminate = false;
titleProgressController.progress = downloadThread.getCurrentDownloadingItemProgress();
} else {
titleProgressController.indeterminate = true;
titleProgressController.progress = 0;
}
double mb = indexItem.getArchiveSizeMB();
String v;
if (titleProgressController.progress != -1) {
v = getMapActivity().getString(R.string.value_downloaded_of_max, mb * titleProgressController.progress / 100, mb);
} else {
v = getMapActivity().getString(R.string.file_size_in_mb, mb);
}
if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
titleProgressController.caption = indexItem.getType().getString(getMapActivity()) + " • " + v;
} else {
titleProgressController.caption = v;
}
titleProgressController.visible = true;
} else if (downloadIndexes) {
titleProgressController.setIndexesDownloadMode();
titleProgressController.visible = true;
} else if (!internetConnectionAvailable) {
titleProgressController.setNoInternetConnectionMode();
titleProgressController.visible = true;
} else {
titleProgressController.visible = false;
}
}
}
Aggregations