Improve download usability

This commit is contained in:
Victor Shcherb 2012-05-26 13:55:19 +02:00
parent bc9787e2e5
commit 1cfaf71c10
6 changed files with 110 additions and 30 deletions

View file

@ -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).
-->
<string name="confirm_interrupt_download">Do you want to interrupt file downloading?</string>
<string name="first_time_msg">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.</string>
<string name="basemap_was_selected_to_download">Basemap is required for proper application functioning and was selected to download.</string>
<string name="select_index_file_to_download">Nothing was found. If you can\'t find your region manually, you can make it yourself (see osmand.net).</string>
<string name="local_indexes_cat_tile">Online Map data</string>
<string name="local_indexes_cat_map">Offline Map data</string>
<string name="gpx_index_settings_descr"> (includes GPX analyzer)</string>
<string name="index_settings_descr">Download, view details and manage offline maps</string>
<string name="local_index_description">Download, (de-)activate, or delete offline data. \nTo see more details click on the item. \nCurrent data on device (%1$s free):</string>
<string name="local_index_description">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):</string>
<string name="map_online_plugin_is_not_installed">Enable online maps plugin to select different map sources</string>
<string name="map_online_data">Online maps</string>
<string name="map_online_data_descr">Use online maps (download and save them on sdcard)</string>
@ -722,7 +725,6 @@
<string name="route_head">Head</string>
<string name="first_time_continue">Later</string>
<string name="first_time_download">Download regions</string>
<string name="first_time_msg">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.</string>
<string name="search_poi_location">Searching for signal&#8230;</string>
<string name="search_near_map">Search near last map location</string>
<string name="search_nearby">Search nearby</string>

View file

@ -14,8 +14,8 @@ import net.osmand.plus.DownloadOsmandIndexesHelper.IndexItem;
public class IndexFileList implements Serializable {
private static final long serialVersionUID = 1L;
IndexItem basemap;
TreeMap<String, IndexItem> indexFiles = new TreeMap<String, IndexItem>(new Comparator<String>(){
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() {
@ -55,6 +58,10 @@ public class IndexFileList implements Serializable {
return indexFiles;
}
public IndexItem getBasemap() {
return basemap;
}
public boolean isIncreasedMapVersion() {
try {
int mapVersionInList = Integer.parseInt(mapversion);

View file

@ -64,8 +64,22 @@ public class ProgressDialogImplementation implements IProgress {
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

View file

@ -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<String, String> indexFileNames = new LinkedHashMap<String, String>();
protected final Set<String> basemapFileNames = new LinkedHashSet<String>();
protected final Map<String, BinaryMapIndexReader> routingMapFiles = new LinkedHashMap<String, BinaryMapIndexReader>();
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<String, String>(indexFileNames);
}
public boolean containsBasemap(){
return !basemapFileNames.isEmpty();
}
public Map<String, String> getBackupIndexes(Map<String, String> map) {
File file = context.getSettings().extendOsmandPath(BACKUP_PATH);
if (file != null && file.isDirectory()) {

View file

@ -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,11 +791,34 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
public DownloadIndexAdapter(Map<String, IndexItem> indexFiles) {
this.indexFiles = new LinkedHashMap<String, IndexItem>(indexFiles);
list.clear();
list.addAll(categorizeIndexItems(indexFiles.values()));
List<IndexItemCategory> 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<String, IndexItem> 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<IndexItemCategory> cats = categorizeIndexItems(indexFiles);
synchronized (this) {
list.clear();
list.addAll(cats);
}
notifyDataSetChanged();
}
@ -834,14 +882,17 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
list.clear();
Collection<IndexItem> items = (Collection<IndexItem>) 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<IndexItem> items = (Collection<IndexItem>) 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;
}

View file

@ -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();
}