Alexey Kulish 2016-03-11 16:23:11 +03:00
parent 274fee4fbe
commit eaddc809c6
6 changed files with 392 additions and 123 deletions

View file

@ -15,6 +15,7 @@ import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.voice.MediaCommandPlayerImpl;
import net.osmand.plus.voice.TTSCommandPlayerImpl;
import net.osmand.util.Algorithms;
import java.io.File;
import java.text.ParseException;
@ -27,15 +28,15 @@ import java.util.TimeZone;
public class LocalIndexHelper {
private final OsmandApplication app;
public LocalIndexHelper(OsmandApplication app){
public LocalIndexHelper(OsmandApplication app) {
this.app = app;
}
public String getInstalledDate(File f){
public String getInstalledDate(File f) {
return android.text.format.DateFormat.getMediumDateFormat(app).format(getInstalationDate(f));
}
@ -44,15 +45,15 @@ public class LocalIndexHelper {
return new Date(t);
}
public String getInstalledDate(long t, TimeZone timeZone){
public String getInstalledDate(long t, TimeZone timeZone) {
return android.text.format.DateFormat.getMediumDateFormat(app).format(new Date(t));
}
public void updateDescription(LocalIndexInfo info){
public void updateDescription(LocalIndexInfo info) {
File f = new File(info.getPathToData());
if(info.getType() == LocalIndexType.MAP_DATA){
if (info.getType() == LocalIndexType.MAP_DATA) {
Map<String, String> ifns = app.getResourceManager().getIndexFileNames();
if(ifns.containsKey(info.getFileName())) {
if (ifns.containsKey(info.getFileName())) {
try {
Date dt = app.getResourceManager().getDateFormat().parse(ifns.get(info.getFileName()));
info.setDescription(getInstalledDate(dt.getTime(), null));
@ -62,39 +63,145 @@ public class LocalIndexHelper {
} else {
info.setDescription(getInstalledDate(f));
}
} else if(info.getType() == LocalIndexType.TILES_DATA){
ITileSource template ;
if(f.isDirectory() && TileSourceManager.isTileSourceMetaInfoExist(f)){
} else if (info.getType() == LocalIndexType.TILES_DATA) {
ITileSource template;
if (f.isDirectory() && TileSourceManager.isTileSourceMetaInfoExist(f)) {
template = TileSourceManager.createTileSourceTemplate(new File(info.getPathToData()));
} else if(f.isFile() && f.getName().endsWith(SQLiteTileSource.EXT)){
} else if (f.isFile() && f.getName().endsWith(SQLiteTileSource.EXT)) {
template = new SQLiteTileSource(app, f, TileSourceManager.getKnownSourceTemplates());
} else {
return;
}
String descr = "";
descr += app.getString(R.string.local_index_tile_data_name, template.getName());
if(template.getExpirationTimeMinutes() >= 0) {
if (template.getExpirationTimeMinutes() >= 0) {
descr += "\n" + app.getString(R.string.local_index_tile_data_expire, template.getExpirationTimeMinutes());
}
info.setDescription(descr);
} else if(info.getType() == LocalIndexType.SRTM_DATA){
} else if (info.getType() == LocalIndexType.SRTM_DATA) {
info.setDescription(app.getString(R.string.download_srtm_maps));
} else if(info.getType() == LocalIndexType.WIKI_DATA){
} else if (info.getType() == LocalIndexType.WIKI_DATA) {
info.setDescription(getInstalledDate(f));
} else if(info.getType() == LocalIndexType.TTS_VOICE_DATA){
} else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) {
info.setDescription(getInstalledDate(f));
} else if(info.getType() == LocalIndexType.DEACTIVATED){
} else if (info.getType() == LocalIndexType.DEACTIVATED) {
info.setDescription(getInstalledDate(f));
} else if(info.getType() == LocalIndexType.VOICE_DATA){
} else if (info.getType() == LocalIndexType.VOICE_DATA) {
info.setDescription(getInstalledDate(f));
}
}
private LocalIndexInfo getLocalIndexInfo(LocalIndexType type, String downloadName, boolean roadMap, boolean backuped) {
public List<LocalIndexInfo> getLocalIndexData(AbstractLoadLocalIndexTask loadTask){
File fileDir = null;
String fileName = null;
if (type == LocalIndexType.MAP_DATA) {
if (!roadMap) {
fileDir = app.getAppPath(IndexConstants.MAPS_PATH);
fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_MAP_INDEX_EXT;
} else {
fileDir = app.getAppPath(IndexConstants.ROADS_INDEX_DIR);
fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_ROAD_MAP_INDEX_EXT;
}
} else if (type == LocalIndexType.SRTM_DATA) {
fileDir = app.getAppPath(IndexConstants.SRTM_INDEX_DIR);
fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
} else if (type == LocalIndexType.WIKI_DATA) {
fileDir = app.getAppPath(IndexConstants.WIKI_INDEX_DIR);
fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_WIKI_MAP_INDEX_EXT;
}
if (backuped) {
fileDir = app.getAppPath(IndexConstants.BACKUP_INDEX_DIR);
}
if (fileDir != null && fileName != null) {
File f = new File(fileDir, fileName);
if (f.exists()) {
LocalIndexInfo info = new LocalIndexInfo(type, f, backuped, app);
updateDescription(info);
return info;
}
}
return null;
}
public LocalIndexInfo getLocalIndexInfo(String downloadName) {
LocalIndexInfo info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, false);
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, true, false);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.SRTM_DATA, downloadName, false, false);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.WIKI_DATA, downloadName, false, false);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, true);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, true, true);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.SRTM_DATA, downloadName, false, true);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.WIKI_DATA, downloadName, false, true);
}
return info;
}
public List<LocalIndexInfo> getLocalIndexInfos(String downloadName) {
List<LocalIndexInfo> list = new ArrayList<>();
LocalIndexInfo info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, false);
if (info != null) {
list.add(info);
}
info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, true, false);
if (info != null) {
list.add(info);
}
info = getLocalIndexInfo(LocalIndexType.SRTM_DATA, downloadName, false, false);
if (info != null) {
list.add(info);
}
info = getLocalIndexInfo(LocalIndexType.WIKI_DATA, downloadName, false, false);
if (info != null) {
list.add(info);
}
info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, true);
if (info != null) {
list.add(info);
}
info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, true, true);
if (info != null) {
list.add(info);
}
info = getLocalIndexInfo(LocalIndexType.SRTM_DATA, downloadName, false, true);
if (info != null) {
list.add(info);
}
info = getLocalIndexInfo(LocalIndexType.WIKI_DATA, downloadName, false, true);
if (info != null) {
list.add(info);
}
return list;
}
public List<LocalIndexInfo> getLocalIndexData(AbstractLoadLocalIndexTask loadTask) {
Map<String, String> loadedMaps = app.getResourceManager().getIndexFileNames();
List<LocalIndexInfo> result = new ArrayList<>();
loadObfData(app.getAppPath(IndexConstants.MAPS_PATH), result, false, loadTask, loadedMaps);
loadObfData(app.getAppPath(IndexConstants.ROADS_INDEX_DIR), result, false, loadTask, loadedMaps);
loadTilesData(app.getAppPath(IndexConstants.TILES_INDEX_DIR), result, false, loadTask);
@ -103,7 +210,7 @@ public class LocalIndexHelper {
//loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask);
loadVoiceData(app.getAppPath(IndexConstants.VOICE_INDEX_DIR), result, false, loadTask);
loadObfData(app.getAppPath(IndexConstants.BACKUP_INDEX_DIR), result, true, loadTask, loadedMaps);
return result;
}
@ -124,7 +231,7 @@ public class LocalIndexHelper {
if (TTSCommandPlayerImpl.isMyData(voiceF)) {
info = new LocalIndexInfo(LocalIndexType.TTS_VOICE_DATA, voiceF, backup, app);
}
if(info != null) {
if (info != null) {
updateDescription(info);
result.add(info);
loadTask.loadFile(info);
@ -137,7 +244,7 @@ public class LocalIndexHelper {
if (voiceF.isDirectory() && MediaCommandPlayerImpl.isMyData(voiceF)) {
LocalIndexInfo info = null;
info = new LocalIndexInfo(LocalIndexType.VOICE_DATA, voiceF, backup, app);
if(info != null){
if (info != null) {
updateDescription(info);
result.add(info);
loadTask.loadFile(info);
@ -146,7 +253,7 @@ public class LocalIndexHelper {
}
}
}
private void loadTilesData(File tilesPath, List<LocalIndexInfo> result, boolean backup, AbstractLoadLocalIndexTask loadTask) {
if (tilesPath.canRead()) {
for (File tileFile : listFilesSorted(tilesPath)) {
@ -158,7 +265,7 @@ public class LocalIndexHelper {
} else if (tileFile.isDirectory()) {
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.TILES_DATA, tileFile, backup, app);
if(!TileSourceManager.isTileSourceMetaInfoExist(tileFile)){
if (!TileSourceManager.isTileSourceMetaInfoExist(tileFile)) {
info.setCorrupted(true);
}
updateDescription(info);
@ -168,17 +275,17 @@ public class LocalIndexHelper {
}
}
}
private File[] listFilesSorted(File dir){
private File[] listFilesSorted(File dir) {
File[] listFiles = dir.listFiles();
if(listFiles == null) {
if (listFiles == null) {
return new File[0];
}
Arrays.sort(listFiles);
return listFiles;
}
private void loadSrtmData(File mapPath, List<LocalIndexInfo> result, AbstractLoadLocalIndexTask loadTask) {
if (mapPath.canRead()) {
for (File mapFile : listFilesSorted(mapPath)) {
@ -191,7 +298,7 @@ public class LocalIndexHelper {
}
}
}
private void loadWikiData(File mapPath, List<LocalIndexInfo> result, AbstractLoadLocalIndexTask loadTask) {
if (mapPath.canRead()) {
for (File mapFile : listFilesSorted(mapPath)) {
@ -204,19 +311,19 @@ public class LocalIndexHelper {
}
}
}
private void loadObfData(File mapPath, List<LocalIndexInfo> result, boolean backup, AbstractLoadLocalIndexTask loadTask, Map<String, String> loadedMaps) {
if (mapPath.canRead()) {
for (File mapFile : listFilesSorted(mapPath)) {
if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
LocalIndexType lt = LocalIndexType.MAP_DATA;
if(mapFile.getName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)) {
if (mapFile.getName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)) {
lt = LocalIndexType.SRTM_DATA;
} else if(mapFile.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
} else if (mapFile.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
lt = LocalIndexType.WIKI_DATA;
}
LocalIndexInfo info = new LocalIndexInfo(lt, mapFile, backup, app);
if(loadedMaps.containsKey(mapFile.getName()) && !backup){
if (loadedMaps.containsKey(mapFile.getName()) && !backup) {
info.setLoaded(true);
}
updateDescription(info);
@ -228,53 +335,47 @@ public class LocalIndexHelper {
}
public enum LocalIndexType {
MAP_DATA(R.string.local_indexes_cat_map),
TILES_DATA(R.string.local_indexes_cat_tile),
SRTM_DATA(R.string.local_indexes_cat_srtm, R.drawable.ic_plugin_srtm),
WIKI_DATA(R.string.local_indexes_cat_wiki, R.drawable.ic_plugin_wikipedia),
TTS_VOICE_DATA(R.string.local_indexes_cat_tts, R.drawable.ic_action_volume_up),
VOICE_DATA(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up),
DEACTIVATED(R.string.local_indexes_cat_backup, R.drawable.ic_type_archive);
MAP_DATA(R.string.local_indexes_cat_map, R.drawable.ic_map, 10),
TILES_DATA(R.string.local_indexes_cat_tile, R.drawable.ic_map, 60),
SRTM_DATA(R.string.local_indexes_cat_srtm, R.drawable.ic_plugin_srtm, 40),
WIKI_DATA(R.string.local_indexes_cat_wiki, R.drawable.ic_plugin_wikipedia, 50),
TTS_VOICE_DATA(R.string.local_indexes_cat_tts, R.drawable.ic_action_volume_up, 20),
VOICE_DATA(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up, 30),
DEACTIVATED(R.string.local_indexes_cat_backup, R.drawable.ic_type_archive, 1000);
// AV_DATA(R.string.local_indexes_cat_av);;
@StringRes
private final int resId;
@DrawableRes
private int iconResource;
private final int orderIndex;
LocalIndexType(@StringRes int resId, @DrawableRes int iconResource){
LocalIndexType(@StringRes int resId, @DrawableRes int iconResource, int orderIndex) {
this.resId = resId;
this.iconResource = iconResource;
this.orderIndex = orderIndex;
}
LocalIndexType(@StringRes int resId){
this.resId = resId;
this.iconResource = R.drawable.ic_map;
//TODO: Adjust icon of backed up files to original type
//if (getString(resId) == R.string.local_indexes_cat_backup) {
// if (i.getOriginalType() == LocalIndexType.MAP_DATA) {
// this.iconResource = R.drawable.ic_map;
// } else if (i.getOriginalType() == LocalIndexType.TILES_DATA) {
// this.iconResource = R.drawable.ic_map;
// } else if (i.getOriginalType() == LocalIndexType.SRTM_DATA) {
// this.iconResource = R.drawable.ic_plugin_srtm;
// } else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) {
// this.iconResource = R.drawable.ic_plugin_wikipedia;
// } else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA) {
// this.iconResource = R.drawable.ic_action_volume_up;
// } else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) {
// this.iconResource = R.drawable.ic_action_volume_up;
// } else if (i.getOriginalType() == LocalIndexType.AV_DATA) {
// this.iconResource = R.drawable.ic_action_volume_up;
// }
}
public String getHumanString(Context ctx){
public String getHumanString(Context ctx) {
return ctx.getString(resId);
}
public int getIconResource() {
return iconResource;
}
public int getOrderIndex(LocalIndexInfo info) {
String fileName = info.getFileName();
int index = info.getOriginalType().orderIndex;
if (info.getType() == DEACTIVATED) {
index += DEACTIVATED.orderIndex;
}
if (fileName.endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) {
index++;
}
return index;
}
public String getBasename(LocalIndexInfo localIndexInfo) {
String fileName = localIndexInfo.getFileName();
if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) {
@ -293,7 +394,7 @@ public class LocalIndexHelper {
int ls = fileName.lastIndexOf('_');
if (ls >= 0) {
return fileName.substring(0, ls);
} else if(fileName.indexOf('.') > 0){
} else if (fileName.indexOf('.') > 0) {
return fileName.substring(0, fileName.indexOf('.'));
}
return fileName;

View file

@ -102,33 +102,33 @@ public class DownloadResources extends DownloadResourceGroup {
public boolean checkIfItemOutdated(IndexItem item, java.text.DateFormat format) {
boolean outdated = false;
String sfName = item.getTargetFileName();
String indexactivateddate = indexActivatedFileNames.get(sfName);
String indexfilesdate = indexFileNames.get(sfName);
String indexActivatedDate = indexActivatedFileNames.get(sfName);
String indexFilesDate = indexFileNames.get(sfName);
item.setDownloaded(false);
item.setOutdated(false);
if(indexactivateddate == null && indexfilesdate == null) {
return outdated;
if (indexActivatedDate == null && indexFilesDate == null) {
return false;
}
item.setDownloaded(true);
String date = item.getDate(format);
boolean parsed = false;
if(indexactivateddate != null) {
if (indexActivatedDate != null) {
try {
item.setLocalTimestamp(format.parse(indexactivateddate).getTime());
item.setLocalTimestamp(format.parse(indexActivatedDate).getTime());
parsed = true;
} catch (ParseException e) {
e.printStackTrace();
}
}
if (!parsed && indexfilesdate != null) {
if (!parsed && indexFilesDate != null) {
try {
item.setLocalTimestamp(format.parse(indexfilesdate).getTime());
item.setLocalTimestamp(format.parse(indexFilesDate).getTime());
parsed = true;
} catch (ParseException e) {
e.printStackTrace();
}
}
if (date != null && !date.equals(indexactivateddate) && !date.equals(indexfilesdate)) {
if (date != null && !date.equals(indexActivatedDate) && !date.equals(indexFilesDate)) {
if ((item.getType() == DownloadActivityType.NORMAL_FILE && !item.extra)
|| item.getType() == DownloadActivityType.ROADS_FILE
|| item.getType() == DownloadActivityType.WIKIPEDIA_FILE

View file

@ -571,7 +571,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
final TextView titleButtonRightText = (TextView) view.findViewById(R.id.title_button_right_text);
if (leftTitleButtonController != null) {
leftTitleButton.setText(leftTitleButtonController.caption);
leftTitleButton.setVisibility(leftTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
leftTitleButton.setVisibility(leftTitleButtonController.visible ? View.VISIBLE : View.GONE);
Drawable leftIcon = leftTitleButtonController.getLeftIcon();
if (leftIcon != null) {
@ -594,7 +594,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
final Button rightTitleButton = (Button) view.findViewById(R.id.title_button_right);
if (rightTitleButtonController != null) {
rightTitleButton.setText(rightTitleButtonController.caption);
rightTitleButton.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE);
rightTitleButton.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.GONE);
Drawable leftIcon = rightTitleButtonController.getLeftIcon();
rightTitleButton.setCompoundDrawablesWithIntrinsicBounds(leftIcon, null, null, null);

View file

@ -8,6 +8,7 @@ import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.widget.Toast;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon;
@ -15,7 +16,11 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadValidationManager;
@ -23,7 +28,6 @@ import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject;
@ -31,6 +35,7 @@ import net.osmand.util.Algorithms;
import java.io.File;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@ -41,25 +46,38 @@ public class MapDataMenuController extends MenuController {
private DownloadMapObject mapObject;
private IndexItem indexItem;
private List<IndexItem> otherIndexItems;
private LocalIndexInfo localIndexInfo;
private List<LocalIndexInfo> otherLocalIndexInfos;
private boolean srtmDisabled;
private boolean srtmNeedsInstallation;
boolean downloaded;
private boolean downloaded;
private boolean backuped;
private DownloadIndexesThread downloadThread;
private ResourceManager rm;
public MapDataMenuController(OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, final DownloadMapObject mapObject) {
public MapDataMenuController(final OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, final DownloadMapObject mapObject) {
super(new MenuBuilder(app), pointDescription, mapActivity);
this.mapObject = mapObject;
rm = app.getResourceManager();
indexItem = mapObject.getIndexItem();
localIndexInfo = mapObject.getLocalIndexInfo();
downloadThread = app.getDownloadThread();
if (indexItem != null) {
downloaded = indexItem.isDownloaded();
backuped = indexItem.getBackupFile(getMapActivity().getMyApplication()).exists();
otherIndexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(mapObject.getWorldRegion()));
otherIndexItems.remove(indexItem);
} else {
downloaded = checkIfObjectDownloaded(rm.getOsmandRegions().getDownloadName(mapObject.getDataObject()));
} else if (localIndexInfo != null) {
downloaded = true;
backuped = localIndexInfo.isBackupedData();
LocalIndexHelper helper = new LocalIndexHelper(app);
otherLocalIndexInfos = helper.getLocalIndexInfos(mapObject.getWorldRegion().getRegionDownloadName());
for (Iterator<LocalIndexInfo> iterator = otherLocalIndexInfos.iterator(); iterator.hasNext(); ) {
LocalIndexInfo info = iterator.next();
if (info.getPathToData().equals(localIndexInfo.getPathToData())) {
iterator.remove();
break;
}
}
}
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
@ -69,7 +87,9 @@ public class MapDataMenuController extends MenuController {
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
if (indexItem != null) {
if (backuped) {
restoreFromBackup();
} else if (indexItem != null) {
if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
|| indexItem.getType() == DownloadActivityType.HILLSHADE_FILE)
&& srtmDisabled) {
@ -100,15 +120,13 @@ public class MapDataMenuController extends MenuController {
@Override
public void buttonPressed() {
if (indexItem != null) {
deleteItem();
} else if (downloaded) {
/*
File f = new File(info.getPathToData());
boolean successfull = Algorithms.removeAllFiles(f);
if (successfull) {
getMapActivity().getMyApplication().getResourceManager().closeFile(info.getFileName());
if (backuped) {
deleteItem(indexItem.getBackupFile(app));
} else {
deleteItem(indexItem.getTargetFile(app));
}
*/
} else if (localIndexInfo != null) {
deleteItem(new File(localIndexInfo.getPathToData()));
}
}
};
@ -122,10 +140,18 @@ public class MapDataMenuController extends MenuController {
Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>();
IContextMenuProvider provider = mapActivity.getMapLayers().getDownloadedRegionsLayer();
for (IndexItem item : otherIndexItems) {
selectedObjects.put(
new DownloadMapObject(mapObject.getDataObject(), mapObject.getWorldRegion(), item),
provider);
if (otherIndexItems != null && otherIndexItems.size() > 0) {
for (IndexItem item : otherIndexItems) {
selectedObjects.put(
new DownloadMapObject(mapObject.getDataObject(), mapObject.getWorldRegion(), item, null),
provider);
}
} else if (otherLocalIndexInfos != null && otherLocalIndexInfos.size() > 0) {
for (LocalIndexInfo info : otherLocalIndexInfos) {
selectedObjects.put(
new DownloadMapObject(mapObject.getDataObject(), mapObject.getWorldRegion(), null, info),
provider);
}
}
mapActivity.getContextMenu().getMultiSelectionMenu().show(
mapActivity.getContextMenu().getLatLon(), selectedObjects);
@ -167,12 +193,16 @@ public class MapDataMenuController extends MenuController {
@Override
public Drawable getLeftIcon() {
int iconResId;
if (indexItem != null) {
iconResId = indexItem.getType().getIconResource();
if (getDownloadActivityType() != null) {
iconResId = getDownloadActivityType().getIconResource();
} else {
iconResId = R.drawable.ic_map;
}
return getIcon(iconResId, R.color.osmand_orange);
if (backuped) {
return getIcon(iconResId);
} else {
return getIcon(iconResId, R.color.osmand_orange);
}
}
@Override
@ -198,7 +228,32 @@ public class MapDataMenuController extends MenuController {
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
if (indexItem != null) {
addPlainMenuItem(R.drawable.ic_action_info_dark, indexItem.getType().getString(getMapActivity()), false, false);
addPlainMenuItem(R.drawable.ic_action_info_dark, indexItem.getSizeDescription(getMapActivity()), false, false);
StringBuilder sizeStr = new StringBuilder();
sizeStr.append(indexItem.getSizeDescription(getMapActivity()));
if (backuped) {
sizeStr.append("").append(LocalIndexType.DEACTIVATED.getHumanString(getMapActivity()));
}
addPlainMenuItem(R.drawable.ic_action_info_dark, sizeStr.toString(), false, false);
} else if (localIndexInfo != null) {
if (getDownloadActivityType() != null) {
addPlainMenuItem(R.drawable.ic_action_info_dark, getDownloadActivityType().getString(getMapActivity()), false, false);
}
StringBuilder sizeStr = new StringBuilder();
if (localIndexInfo.getSize() >= 0) {
if (localIndexInfo.getSize() > 100) {
sizeStr.append(DownloadActivity.formatMb.format(new Object[]{(float) localIndexInfo.getSize() / (1 << 10)}));
} else {
sizeStr.append(localIndexInfo.getSize()).append(" KB");
}
}
if (backuped) {
if (sizeStr.length() > 0) {
sizeStr.append("").append(LocalIndexType.DEACTIVATED.getHumanString(getMapActivity()));
} else {
sizeStr.append(LocalIndexType.DEACTIVATED.getHumanString(getMapActivity()));
}
}
addPlainMenuItem(R.drawable.ic_action_info_dark, sizeStr.toString(), false, false);
}
if (!Algorithms.isEmpty(mapObject.getWorldRegion().getParams().getWikiLink())) {
String[] items = mapObject.getWorldRegion().getParams().getWikiLink().split(":");
@ -228,6 +283,8 @@ public class MapDataMenuController extends MenuController {
if (indexItem != null) {
DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(getMapActivity());
addPlainMenuItem(R.drawable.ic_action_data, indexItem.getRemoteDate(dateFormat), false, false);
} else if (localIndexInfo != null) {
addPlainMenuItem(R.drawable.ic_action_data, localIndexInfo.getDescription(), false, false);
}
}
@ -261,8 +318,12 @@ public class MapDataMenuController extends MenuController {
}
}
leftTitleButtonController.visible = false;
leftTitleButtonController.leftIconId = R.drawable.ic_action_import;
if (indexItem != null) {
if (backuped) {
leftTitleButtonController.caption = getMapActivity().getString(R.string.local_index_mi_restore);
leftTitleButtonController.visible = true;
} else if (indexItem != null) {
if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
|| indexItem.getType() == DownloadActivityType.HILLSHADE_FILE)
&& srtmDisabled) {
@ -273,10 +334,12 @@ public class MapDataMenuController extends MenuController {
} else {
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_download);
}
leftTitleButtonController.visible = true;
}
rightTitleButtonController.visible = downloaded;
topRightTitleButtonController.visible = otherIndexItems.size() > 0;
topRightTitleButtonController.visible = (otherIndexItems != null && otherIndexItems.size() > 0)
|| (otherLocalIndexInfos != null && otherLocalIndexInfos.size() > 0);
boolean downloadIndexes = getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable()
&& !downloadThread.getIndexes().isDownloadedFromInternet
@ -293,13 +356,13 @@ public class MapDataMenuController extends MenuController {
titleProgressController.progress = 0;
}
double mb = indexItem.getArchiveSizeMB();
String v ;
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) {
if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
titleProgressController.caption = indexItem.getType().getString(getMapActivity()) + "" + v;
} else {
titleProgressController.caption = v;
@ -313,9 +376,8 @@ public class MapDataMenuController extends MenuController {
}
}
public void deleteItem() {
public void deleteItem(final File fl) {
final OsmandApplication app = getMapActivity().getMyApplication();
final File fl = indexItem.getTargetFile(app);
if (fl.exists()) {
AlertDialog.Builder confirm = new AlertDialog.Builder(getMapActivity());
confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@ -347,18 +409,105 @@ public class MapDataMenuController extends MenuController {
}
});
confirm.setNegativeButton(R.string.shared_string_no, null);
String fn = FileNameTranslationHelper.getFileName(getMapActivity(), app.getRegions(),
indexItem.getVisibleName(getMapActivity(), app.getRegions()));
String fn;
if (indexItem != null) {
fn = FileNameTranslationHelper.getFileName(getMapActivity(), app.getRegions(),
indexItem.getVisibleName(getMapActivity(), app.getRegions()));
} else {
fn = getPointDescription().getName();
}
confirm.setMessage(getMapActivity().getString(R.string.delete_confirmation_msg, fn));
confirm.show();
}
}
private boolean checkIfObjectDownloaded(String downloadName) {
final String regionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_MAP_INDEX_EXT;
final String roadsRegionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + ".road"
+ IndexConstants.BINARY_MAP_INDEX_EXT;
return rm.getIndexFileNames().containsKey(regionName) || rm.getIndexFileNames().containsKey(roadsRegionName);
public void restoreFromBackup() {
final OsmandApplication app = getMapActivity().getMyApplication();
new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
getMapActivity().getContextMenu().close();
}
@Override
protected Void doInBackground(Void... params) {
if (localIndexInfo != null) {
LocalIndexInfo info = localIndexInfo;
move(new File(info.getPathToData()), getFileToRestore(info));
app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList<String>());
app.getDownloadThread().updateLoadedFiles();
} else if (indexItem != null) {
move(indexItem.getBackupFile(app), indexItem.getTargetFile(app));
app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList<String>());
app.getDownloadThread().updateLoadedFiles();
}
return null;
}
protected void onPostExecute(Void result) {
getMapActivity().getMapLayers().getDownloadedRegionsLayer().updateObjects();
getMapActivity().refreshMap();
}
}.execute((Void) null);
}
private boolean move(File from, File to) {
if (!to.getParentFile().exists()) {
to.getParentFile().mkdirs();
}
return from.renameTo(to);
}
private File getFileToRestore(LocalIndexInfo i) {
if (i.isBackupedData()) {
final OsmandApplication app = getMapActivity().getMyApplication();
File parent = new File(i.getPathToData()).getParentFile();
if (i.getOriginalType() == LocalIndexType.MAP_DATA) {
if (i.getFileName().endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) {
parent = app.getAppPath(IndexConstants.ROADS_INDEX_DIR);
} else {
parent = app.getAppPath(IndexConstants.MAPS_PATH);
}
} else if (i.getOriginalType() == LocalIndexType.TILES_DATA) {
parent = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.SRTM_DATA) {
parent = app.getAppPath(IndexConstants.SRTM_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) {
parent = app.getAppPath(IndexConstants.WIKI_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA) {
parent = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) {
parent = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
}
return new File(parent, i.getFileName());
}
return new File(i.getPathToData());
}
public DownloadActivityType getDownloadActivityType() {
if (indexItem != null) {
return indexItem.getType();
} else if (localIndexInfo != null) {
if (localIndexInfo.getOriginalType() == LocalIndexType.MAP_DATA) {
if (localIndexInfo.getFileName().endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) {
return DownloadActivityType.ROADS_FILE;
} else {
return DownloadActivityType.NORMAL_FILE;
}
} else if (localIndexInfo.getOriginalType() == LocalIndexType.SRTM_DATA) {
return DownloadActivityType.SRTM_COUNTRY_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.WIKI_DATA) {
return DownloadActivityType.WIKIPEDIA_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.TTS_VOICE_DATA
|| localIndexInfo.getOriginalType() == LocalIndexType.VOICE_DATA) {
return DownloadActivityType.VOICE_FILE;
} else {
return null;
}
} else {
return null;
}
}
}

View file

@ -21,6 +21,8 @@ import net.osmand.map.OsmandRegions;
import net.osmand.map.WorldRegion;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
@ -55,6 +57,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
private Paint paintOutdated;
private Path pathOutdated;
private OsmandRegions osmandRegions;
private LocalIndexHelper helper;
private TextPaint textPaint;
private ResourceManager rm;
@ -76,6 +79,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
private BinaryMapDataObject dataObject;
private WorldRegion worldRegion;
private IndexItem indexItem;
private LocalIndexInfo localIndexInfo;
public BinaryMapDataObject getDataObject() {
return dataObject;
@ -89,10 +93,16 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
return indexItem;
}
public DownloadMapObject(BinaryMapDataObject dataObject, WorldRegion worldRegion, IndexItem indexItem) {
public LocalIndexInfo getLocalIndexInfo() {
return localIndexInfo;
}
public DownloadMapObject(BinaryMapDataObject dataObject, WorldRegion worldRegion,
IndexItem indexItem, LocalIndexInfo localIndexInfo) {
this.dataObject = dataObject;
this.worldRegion = worldRegion;
this.indexItem = indexItem;
this.localIndexInfo = localIndexInfo;
}
}
@ -102,6 +112,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
app = view.getApplication();
rm = app.getResourceManager();
osmandRegions = rm.getOsmandRegions();
helper = new LocalIndexHelper(app);
paintDownloaded = getPaint(view.getResources().getColor(R.color.region_uptodate));
paintSelected = getPaint(view.getResources().getColor(R.color.region_selected));
@ -251,8 +262,6 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
return rm.getIndexFileNames().containsKey(regionName) || rm.getIndexFileNames().containsKey(roadsRegionName);
}
private List<BinaryMapDataObject> queryData(RotatedTileBox tileBox) {
if (tileBox.getZoom() >= ZOOM_AFTER_BASEMAP) {
if(!checkIfMapEmpty(tileBox)) {
@ -391,7 +400,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
Set<String> set = new TreeSet<String>();
int cx = view.getCurrentRotatedTileBox().getCenter31X();
int cy = view.getCurrentRotatedTileBox().getCenter31Y();
if ((currentObjects != null && currentObjects.size() > 0)) {
if ((currentObjects.size() > 0)) {
for (int i = 0; i < currentObjects.size(); i++) {
final BinaryMapDataObject o = currentObjects.get(i);
if (!osmandRegions.contain(o, cx, cy)) {
@ -537,10 +546,18 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
if (!dataItems.isEmpty()) {
for (IndexItem item : dataItems) {
dataObjects.add(new DownloadMapObject(o, region, item));
dataObjects.add(new DownloadMapObject(o, region, item, null));
}
} else {
dataObjects.add(new DownloadMapObject(o, region, null));
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));
}
}
}
}
}
@ -555,6 +572,8 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
order = mapObject.worldRegion.getLevel() * 1000 - 100000;
if (mapObject.indexItem != null) {
order += mapObject.indexItem.getType().getOrderIndex();
} else if (mapObject.localIndexInfo != null) {
order += mapObject.localIndexInfo.getType().getOrderIndex(mapObject.localIndexInfo);
}
}
return order;

View file

@ -119,7 +119,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override
protected List<Amenity> calculateResult(RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds();
if (filter == null) {
if (filter == null || latLonBounds == null) {
return new ArrayList<Amenity>();
}
int z = (int) Math.floor(tileBox.getZoom() + Math.log(view.getSettings().MAP_DENSITY.get()) / Math.log(2));