diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index cfa71d3987..4b90e58cb3 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -8,12 +8,15 @@ If you are making/correcting english translations make sure : 1. All your modified/created strings are in the top of the file (to make easier find what's translated). --> + Do you want to interrupt file downloading? + To use the major features of this application, you need some regional offline data, which you can download (use Settings, Offline Data). Afterwards, you will be able to search by address, look up POIs and find public transportation. + Basemap is required for proper application functioning and was selected to download. Nothing was found. If you can\'t find your region manually, you can make it yourself (see osmand.net). Online Map data Offline Map data (includes GPX analyzer) Download, view details and manage offline maps - Download, (de-)activate, or delete offline data. \nTo see more details click on the item. \nCurrent data on device (%1$s free): + Download or update offline data. \nTo see more details click on the item, to deactivate or delete offline data press and hold. \nCurrent data on device (%1$s free): Enable online maps plugin to select different map sources Online maps Use online maps (download and save them on sdcard) @@ -722,7 +725,6 @@ Head Later Download regions - Thank you for choosing OsmAnd. \nTo use the major features of this application, you will need some regional offline data, which you can download (use Settings, Offline Data). Afterwards, you will be able to search by address, look up POIs and find public transportation. Searching for signal… Search near last map location Search nearby diff --git a/OsmAnd/src/net/osmand/plus/IndexFileList.java b/OsmAnd/src/net/osmand/plus/IndexFileList.java index a561c42229..790dd4b48d 100644 --- a/OsmAnd/src/net/osmand/plus/IndexFileList.java +++ b/OsmAnd/src/net/osmand/plus/IndexFileList.java @@ -14,8 +14,8 @@ import net.osmand.plus.DownloadOsmandIndexesHelper.IndexItem; public class IndexFileList implements Serializable { private static final long serialVersionUID = 1L; + IndexItem basemap; TreeMap indexFiles = new TreeMap(new Comparator(){ - private static final long serialVersionUID = 1L; @Override public int compare(String object1, String object2) { @@ -45,6 +45,9 @@ public class IndexFileList implements Serializable { if (indexItem.isAccepted()) { indexFiles.put(name, indexItem); } + if(name.toLowerCase().startsWith("world_basemap")) { + basemap = indexItem; + } } public boolean isAcceptable() { @@ -54,6 +57,10 @@ public class IndexFileList implements Serializable { public Map getIndexFiles() { return indexFiles; } + + public IndexItem getBasemap() { + return basemap; + } public boolean isIncreasedMapVersion() { try { diff --git a/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java b/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java index 0172a3777d..fbb26a9ca6 100644 --- a/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java +++ b/OsmAnd/src/net/osmand/plus/ProgressDialogImplementation.java @@ -63,9 +63,23 @@ public class ProgressDialogImplementation implements IProgress { public ProgressDialogImplementation(final ProgressDialog dlg){ this(dlg, false); } + public static ProgressDialogImplementation createProgressDialog(Context ctx, String title, String message, int style) { - ProgressDialog dlg = new ProgressDialog(ctx); + return createProgressDialog(ctx, title, message, style, null); + } + + public static ProgressDialogImplementation createProgressDialog(Context ctx, String title, String message, int style, final DialogInterface.OnCancelListener listener) { + ProgressDialog dlg = new ProgressDialog(ctx) { + @Override + public void cancel() { + if(listener != null) { + listener.onCancel(this); + } else { + super.cancel(); + } + } + }; dlg.setTitle(title); dlg.setMessage(message); dlg.setIndeterminate(style == ProgressDialog.STYLE_HORIZONTAL); // re-set in mViewUpdateHandler.handleMessage above diff --git a/OsmAnd/src/net/osmand/plus/ResourceManager.java b/OsmAnd/src/net/osmand/plus/ResourceManager.java index 970d90428c..6f1e6bbdf8 100644 --- a/OsmAnd/src/net/osmand/plus/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/ResourceManager.java @@ -12,8 +12,10 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import net.osmand.Algoritms; @@ -102,6 +104,8 @@ public class ResourceManager { protected final Map indexFileNames = new LinkedHashMap(); + protected final Set basemapFileNames = new LinkedHashSet(); + protected final Map routingMapFiles = new LinkedHashMap(); protected final MapRenderRepositories renderer; @@ -507,6 +511,9 @@ public class ResourceManager { if (index == null) { warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$ } else { + if(index.isBasemap()) { + basemapFileNames.add(f.getName()); + } indexFileNames.put(f.getName(), MessageFormat.format("{0,date,dd.MM.yyyy}", new Date(f.lastModified()))); //$NON-NLS-1$ for(String rName : index.getRegionNames()) { // skip duplicate names (don't make collision between getName() and name in the map) @@ -810,6 +817,7 @@ public class ResourceManager { public synchronized void close(){ imagesOnFS.clear(); indexFileNames.clear(); + basemapFileNames.clear(); renderer.clearAllResources(); closeAmenities(); closeRouteFiles(); @@ -841,6 +849,10 @@ public class ResourceManager { return new LinkedHashMap(indexFileNames); } + public boolean containsBasemap(){ + return !basemapFileNames.isEmpty(); + } + public Map getBackupIndexes(Map map) { File file = context.getSettings().extendOsmandPath(BACKUP_PATH); if (file != null && file.isDirectory()) { diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index 3bb91d9d18..32e5b100fd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -44,6 +44,7 @@ import android.app.ProgressDialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.res.AssetManager; import android.graphics.Color; @@ -264,6 +265,14 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { @Override public void run() { if (indexFiles != null) { + boolean basemapExists = ((OsmandApplication) uiActivity.getApplication()).getResourceManager().containsBasemap(); + if(!basemapExists && indexFiles.getBasemap() != null) { + uiActivity.entriesToDownload.put(indexFiles.getBasemap().getFileName(), + indexFiles.getBasemap().createDownloadEntry(ctx)); + AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download, + Toast.LENGTH_LONG).show(); + uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE); + } uiActivity.setListAdapter(uiActivity.new DownloadIndexAdapter(indexFiles.getIndexFiles())); if (indexFiles.isIncreasedMapVersion()) { uiActivity.showDialog(DownloadIndexActivity.DIALOG_MAP_VERSION_UPDATE); @@ -311,19 +320,18 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { DownloadIndexActivity.this, getString(R.string.downloading), getString(R.string.downloading_file), - ProgressDialog.STYLE_HORIZONTAL); + ProgressDialog.STYLE_HORIZONTAL, + new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + makeSureUserCancelDownload(dialog); + } + }); progressFileDlg = progress.getDialog(); - progressFileDlg.setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - downloadFileHelper.setInterruptDownloading(true); - } - }); progressFileDlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { downloadFileHelper.setInterruptDownloading(true); - } }); return progress.getDialog(); @@ -361,6 +369,20 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { return super.getExpandableListAdapter(); } + private void makeSureUserCancelDownload(final DialogInterface dlg) { + Builder bld = new AlertDialog.Builder(this); + bld.setTitle(getString(R.string.default_buttons_cancel)); + bld.setMessage(R.string.confirm_interrupt_download); + bld.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dlg.dismiss(); + } + }); + bld.setNegativeButton(R.string.default_buttons_no, null); + bld.show(); + } + @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { @@ -769,10 +791,33 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { public DownloadIndexAdapter(Map indexFiles) { this.indexFiles = new LinkedHashMap(indexFiles); - list.clear(); - list.addAll(categorizeIndexItems(indexFiles.values())); + List cats = categorizeIndexItems(indexFiles.values()); + synchronized (this) { + list.clear(); + list.addAll(cats); + } getFilter().filter(filterText.getText()); } + + public void collapseTrees(final CharSequence constraint){ + runOnUiThread(new Runnable() { + @Override + public void run() { + synchronized (DownloadIndexAdapter.this) { + final ExpandableListView expandableListView = getExpandableListView(); + for (int i = 0; i < getGroupCount(); i++) { + int cp = getChildrenCount(i); + if (cp < 7) { + expandableListView.expandGroup(i); + } else { + expandableListView.collapseGroup(i); + } + } + } + } + }); + + } public Map getIndexFiles() { return indexFiles; @@ -783,8 +828,11 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { for(IndexItem i : indexFiles) { this.indexFiles.put(i.getFileName(), i); } - list.clear(); - list.addAll(categorizeIndexItems(indexFiles)); + List cats = categorizeIndexItems(indexFiles); + synchronized (this) { + list.clear(); + list.addAll(cats); + } notifyDataSetChanged(); } @@ -830,18 +878,21 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { } return results; } - + @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) { - list.clear(); - Collection items = (Collection) results.values; - if (items != null && !items.isEmpty()) { - list.addAll(categorizeIndexItems(items)); - } else { - list.add(new IndexItemCategory(getResources().getString(R.string.select_index_file_to_download),1)); + synchronized (DownloadIndexAdapter.this) { + list.clear(); + Collection items = (Collection) results.values; + if (items != null && !items.isEmpty()) { + list.addAll(categorizeIndexItems(items)); + } else { + list.add(new IndexItemCategory(getResources().getString(R.string.select_index_file_to_download), 1)); + } } notifyDataSetChanged(); + collapseTrees(constraint); } } @@ -893,12 +944,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { item.setText(group.name); item.setLinkTextColor(Color.YELLOW); adjustIndicator(groupPosition, isExpanded, v); - int cp = getChildrenCount(groupPosition); - if(cp < 10 && !isExpanded) { - getExpandableListView().expandGroup(groupPosition); - } else if(cp > 50 && isExpanded){ - getExpandableListView().collapseGroup(groupPosition); - } return row; } diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java index 3f3f911f6f..ee6aad1faf 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java @@ -678,7 +678,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity { } TextView ds = (TextView) findViewById(R.id.DescriptionText); String text = getString(R.string.local_index_description, size); - int l = text.indexOf(','); + int l = text.indexOf('.'); if(l == -1) { l = text.length(); }