Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-11-07 17:51:35 +01:00
commit 2a9fbe2b81
7 changed files with 204 additions and 107 deletions

View file

@ -61,9 +61,11 @@ import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dialogs.WhatsNewDialogFragment;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.helpers.GpxImportHelper;
import net.osmand.plus.helpers.WakeLockHelper;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.MapContextMenuFragment;
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
import net.osmand.plus.mapcontextmenu.editors.PointEditor;
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
@ -91,7 +93,7 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MapActivity extends AccessibleActivity {
public class MapActivity extends AccessibleActivity implements DownloadEvents {
private static final int SHOW_POSITION_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 1;
private static final int LONG_KEYPRESS_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 2;
private static final int LONG_KEYPRESS_DELAY = 500;
@ -480,11 +482,16 @@ public class MapActivity extends AccessibleActivity {
app.getResourceManager().setBusyIndicator(new BusyIndicator(this, progress));
}
getMapLayers().getDownloadedRegionsLayer().updateObjects();
OsmandPlugin.onMapActivityResume(this);
mapView.refreshMap(true);
if (atlasMapRendererView != null) {
atlasMapRendererView.handleOnResume();
}
app.getDownloadThread().setUiActivity(this);
getMyApplication().getAppCustomization().resumeActivity(MapActivity.class, this);
if (System.currentTimeMillis() - tm > 50) {
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
@ -710,6 +717,7 @@ public class MapActivity extends AccessibleActivity {
@Override
protected void onPause() {
app.getDownloadThread().resetUiActivity(this);
if (atlasMapRendererView != null) {
atlasMapRendererView.handleOnPause();
}
@ -1021,4 +1029,38 @@ public class MapActivity extends AccessibleActivity {
openDrawer();
}
}
// DownloadEvents
@Override
public void newDownloadIndexes() {
MapContextMenuFragment contextMenuFragment = getContextMenu().findMenuFragment();
if (contextMenuFragment != null) {
contextMenuFragment.newDownloadIndexes();
}
if (getMapLayers().getDownloadedRegionsLayer().updateObjects()) {
refreshMap();
}
}
@Override
public void downloadInProgress() {
MapContextMenuFragment contextMenuFragment = getContextMenu().findMenuFragment();
if (contextMenuFragment != null) {
contextMenuFragment.downloadInProgress();
}
if (getMapLayers().getDownloadedRegionsLayer().updateObjects()) {
refreshMap();
}
}
@Override
public void downloadHasFinished() {
MapContextMenuFragment contextMenuFragment = getContextMenu().findMenuFragment();
if (contextMenuFragment != null) {
contextMenuFragment.downloadHasFinished();
}
if (getMapLayers().getDownloadedRegionsLayer().updateObjects()) {
refreshMap();
}
}
}

View file

@ -466,5 +466,8 @@ public class MapActivityLayers {
public TransportInfoLayer getTransportInfoLayer() {
return transportInfoLayer;
}
public DownloadedRegionsLayer getDownloadedRegionsLayer() {
return downloadedRegionsLayer;
}
}

View file

@ -233,11 +233,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
if (desc != null) {
return desc;
} else if (this.isAudio()) {
return ctx.getString(R.string.rec_audio_description, formatDateTime(ctx, file.lastModified()));
return formatDateTime(ctx, file.lastModified());
} else if (this.isVideo()) {
return ctx.getString(R.string.rec_video_description, formatDateTime(ctx, file.lastModified()));
return formatDateTime(ctx, file.lastModified());
} else if (this.isPhoto()) {
return ctx.getString(R.string.rec_photo_description, formatDateTime(ctx, file.lastModified()));
return formatDateTime(ctx, file.lastModified());
}
return "";
}

View file

@ -24,6 +24,7 @@ public class DownloadResources extends DownloadResourceGroup {
private Map<String, String> indexFileNames = new LinkedHashMap<>();
private Map<String, String> indexActivatedFileNames = new LinkedHashMap<>();
private List<IndexItem> rawResources;
private Map<WorldRegion, List<IndexItem> > groupByRegion;
private List<IndexItem> itemsToUpdate = new ArrayList<>();
public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap";
@ -67,17 +68,14 @@ public class DownloadResources extends DownloadResourceGroup {
return res;
}
public List<IndexItem> getIndexItems(String fileNamePrefix) {
List<IndexItem> res = new LinkedList<>();
if (rawResources == null) {
return res;
}
for (IndexItem item : rawResources) {
if (item.getFileName().toLowerCase().startsWith(fileNamePrefix)) {
res.add(item);
public List<IndexItem> getIndexItems(WorldRegion region) {
if (groupByRegion != null) {
List<IndexItem> res = groupByRegion.get(region);
if (res != null) {
return res;
}
}
return res;
return new LinkedList<>();
}
public void updateLoadedFiles() {
@ -276,6 +274,8 @@ public class DownloadResources extends DownloadResourceGroup {
}
}
}
this.groupByRegion = groupByRegion;
LinkedList<WorldRegion> queue = new LinkedList<WorldRegion>();
LinkedList<DownloadResourceGroup> parent = new LinkedList<DownloadResourceGroup>();
DownloadResourceGroup worldSubregions = new DownloadResourceGroup(this, DownloadResourceGroupType.SUBREGIONS);

View file

@ -550,18 +550,6 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
}
}
@Override
public void onResume() {
super.onResume();
getMyApplication().getDownloadThread().setUiActivity(this);
}
@Override
public void onPause() {
super.onPause();
getMyApplication().getDownloadThread().resetUiActivity(this);
}
@Override
public void onDestroyView() {
super.onDestroyView();

View file

@ -23,6 +23,8 @@ import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.util.Algorithms;
import java.io.File;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class MapDataMenuController extends MenuController {
@ -146,11 +148,13 @@ public class MapDataMenuController extends MenuController {
@Override
public void updateData() {
if (indexItem == null) {
otherIndexItems = downloadThread.getIndexes().getIndexItems(region.getRegionDownloadNameLC());
for (IndexItem i : otherIndexItems) {
otherIndexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(region));
Iterator<IndexItem> it = otherIndexItems.iterator();
while (it.hasNext()) {
IndexItem i = it.next();
if (i.getType() == DownloadActivityType.NORMAL_FILE) {
indexItem = i;
otherIndexItems.remove(i);
it.remove();
break;
}
}
@ -226,6 +230,7 @@ public class MapDataMenuController extends MenuController {
}
protected void onPostExecute(Void result) {
getMapActivity().getMapLayers().getDownloadedRegionsLayer().updateObjects();
getMapActivity().refreshMap();
}

View file

@ -20,7 +20,10 @@ import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.OsmandRegions;
import net.osmand.map.WorldRegion;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProviderSelection;
@ -39,44 +42,45 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
private static final int ZOOM_THRESHOLD = 2;
private OsmandApplication app;
private OsmandMapTileView view;
private Paint paint;
private Paint paintDownloaded;
private Path pathDownloaded;
private Paint paintSelected;
private Path path;
private Path pathSelected;
private Paint paintDownloading;
private Path pathDownloading;
private Paint paintOutdated;
private Path pathOutdated;
private OsmandRegions osmandRegions;
private TextPaint textPaint;
private ResourceManager rm;
private MapLayerData<List<BinaryMapDataObject>> data;
private List<BinaryMapDataObject> selectedObjects;
private List<BinaryMapDataObject> outdatedObjects = new LinkedList<>();
private List<BinaryMapDataObject> downloadingObjects = new LinkedList<>();
private List<BinaryMapDataObject> selectedObjects = new LinkedList<>();
private static int ZOOM_TO_SHOW_MAP_NAMES = 6;
private static int ZOOM_AFTER_BASEMAP = 12;
private static int ZOOM_TO_SHOW_BORDERS_ST = 5;
private static int ZOOM_TO_SHOW_BORDERS = 7;
private static int ZOOM_TO_SHOW_SELECTION_ST = 3;
private static int ZOOM_TO_SHOW_SELECTION = 10;
@Override
public void initLayer(final OsmandMapTileView view) {
this.view = view;
rm = view.getApplication().getResourceManager();
app = view.getApplication();
rm = app.getResourceManager();
osmandRegions = rm.getOsmandRegions();
paint = new Paint();
paint.setStyle(Style.FILL_AND_STROKE);
paint.setStrokeWidth(1);
paint.setColor(Color.argb(100, 50, 200, 50));
paint.setAntiAlias(true);
paint.setStrokeCap(Cap.ROUND);
paint.setStrokeJoin(Join.ROUND);
paintSelected = new Paint();
paintSelected.setStyle(Style.FILL_AND_STROKE);
paintSelected.setStrokeWidth(1);
paintSelected.setColor(Color.argb(100, 255, 143, 0));
paintSelected.setAntiAlias(true);
paintSelected.setStrokeCap(Cap.ROUND);
paintSelected.setStrokeJoin(Join.ROUND);
paintDownloaded = getPaint(Color.argb(100, 50, 200, 50));
paintSelected = getPaint(Color.argb(100, 255, 143, 0));
paintDownloading = getPaint(Color.argb(40, 50, 200, 50));
paintOutdated = getPaint(Color.argb(100, 0, 128, 255));
textPaint = new TextPaint();
final WindowManager wmgr = (WindowManager) view.getApplication().getSystemService(Context.WINDOW_SERVICE);
@ -86,8 +90,11 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
textPaint.setAntiAlias(true);
textPaint.setTextAlign(Paint.Align.CENTER);
path = new Path();
pathDownloaded = new Path();
pathSelected = new Path();
pathDownloading = new Path();
pathOutdated = new Path();
data = new MapLayerData<List<BinaryMapDataObject>>() {
@Override
@ -96,9 +103,9 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
}
public boolean queriedBoxContains(final RotatedTileBox queriedData, final RotatedTileBox newBox) {
if (newBox.getZoom() < ZOOM_TO_SHOW_BORDERS) {
if (queriedData != null && queriedData.getZoom() < ZOOM_TO_SHOW_BORDERS) {
return queriedData != null && queriedData.containsTileBox(newBox);
if (newBox.getZoom() < ZOOM_TO_SHOW_SELECTION) {
if (queriedData != null && queriedData.getZoom() < ZOOM_TO_SHOW_SELECTION) {
return queriedData.containsTileBox(newBox);
} else {
return false;
}
@ -121,10 +128,17 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
};
}
private static int ZOOM_TO_SHOW_BORDERS_ST = 5;
private static int ZOOM_TO_SHOW_BORDERS = 7;
private static int ZOOM_TO_SHOW_SELECTION_ST = 3;
private static int ZOOM_TO_SHOW_SELECTION = 10;
private Paint getPaint(int color) {
Paint paint = new Paint();
paint.setStyle(Style.FILL_AND_STROKE);
paint.setStrokeWidth(1);
paint.setColor(color);
paint.setAntiAlias(true);
paint.setStrokeCap(Cap.ROUND);
paint.setStrokeJoin(Join.ROUND);
return paint;
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
@ -133,47 +147,62 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
return;
}
// draw objects
final List<BinaryMapDataObject> currentObjects = data.results;
if (zoom >= ZOOM_TO_SHOW_BORDERS_ST && zoom < ZOOM_TO_SHOW_BORDERS && osmandRegions.isInitialized() &&
currentObjects != null) {
path.reset();
for (BinaryMapDataObject o : currentObjects) {
String downloadName = osmandRegions.getDownloadName(o);
boolean downloaded = checkIfObjectDownloaded(downloadName);
if (!downloaded) {
continue;
}
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
path.moveTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
for (int j = 1; j < o.getPointsLength(); j++) {
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
path.lineTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
}
if (osmandRegions.isInitialized() && zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION) {
final List<BinaryMapDataObject> currentObjects = new LinkedList<>();
if (data.results != null) {
currentObjects.addAll(data.results);
}
canvas.drawPath(path, paint);
}
final List<BinaryMapDataObject> downloadingObjects = new LinkedList<>(this.downloadingObjects);
final List<BinaryMapDataObject> outdatedObjects = new LinkedList<>(this.outdatedObjects);
final List<BinaryMapDataObject> selectedObjects = new LinkedList<>(this.selectedObjects);
final List<BinaryMapDataObject> selectedObjects = this.selectedObjects;
if (zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION && osmandRegions.isInitialized() &&
selectedObjects != null) {
pathSelected.reset();
for (BinaryMapDataObject o : selectedObjects) {
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
pathSelected.moveTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
for (int j = 1; j < o.getPointsLength(); j++) {
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
pathSelected.lineTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
if (selectedObjects.size() > 0) {
currentObjects.removeAll(selectedObjects);
drawBorders(canvas, tileBox, selectedObjects, pathSelected, paintSelected);
}
if (zoom >= ZOOM_TO_SHOW_BORDERS_ST && zoom < ZOOM_TO_SHOW_BORDERS) {
downloadingObjects.removeAll(selectedObjects);
if (downloadingObjects.size() > 0) {
currentObjects.removeAll(downloadingObjects);
drawBorders(canvas, tileBox, downloadingObjects, pathDownloading, paintDownloading);
}
outdatedObjects.removeAll(selectedObjects);
if (outdatedObjects.size() > 0) {
currentObjects.removeAll(outdatedObjects);
drawBorders(canvas, tileBox, outdatedObjects, pathOutdated, paintOutdated);
}
if (currentObjects.size() > 0) {
Iterator<BinaryMapDataObject> it = currentObjects.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
boolean downloaded = checkIfObjectDownloaded(osmandRegions.getDownloadName(o));
if (!downloaded) {
it.remove();
}
}
if (currentObjects.size() > 0) {
drawBorders(canvas, tileBox, currentObjects, pathDownloaded, paintDownloaded);
}
}
}
canvas.drawPath(pathSelected, paintSelected);
}
}
private void drawBorders(Canvas canvas, RotatedTileBox tileBox, final List<BinaryMapDataObject> objects, Path path, Paint paint) {
path.reset();
for (BinaryMapDataObject o : objects) {
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
path.moveTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
for (int j = 1; j < o.getPointsLength(); j++) {
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
path.lineTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
}
}
canvas.drawPath(path, paint);
}
private boolean checkIfObjectDownloaded(String downloadName) {
final String regionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
@ -208,21 +237,62 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
} catch (IOException e) {
return result;
}
Iterator<BinaryMapDataObject> it = result.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (tileBox.getZoom() < ZOOM_TO_SHOW_BORDERS) {
if (tileBox.getZoom() < ZOOM_TO_SHOW_SELECTION) {
//
} else {
if (!osmandRegions.contain(o, left / 2 + right / 2, top / 2 + bottom / 2)) {
it.remove();
continue;
}
}
}
updateObjects(result);
return result;
}
public boolean updateObjects() {
int zoom = view.getZoom();
if (osmandRegions.isInitialized() && data.results != null
&& zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION) {
return updateObjects(data.results);
}
return false;
}
private boolean updateObjects(List<BinaryMapDataObject> objects) {
List<BinaryMapDataObject> outdatedObjects = new LinkedList<>();
List<BinaryMapDataObject> downloadingObjects = new LinkedList<>();
for (BinaryMapDataObject o : objects) {
String fullName = osmandRegions.getFullName(o);
WorldRegion region = osmandRegions.getRegionData(fullName);
if (region != null && region.getRegionDownloadName() != null) {
List<IndexItem> indexItems = app.getDownloadThread().getIndexes().getIndexItems(region);
for (IndexItem item : indexItems) {
if (item.getType() == DownloadActivityType.NORMAL_FILE) {
if (app.getDownloadThread().isDownloading(item)) {
downloadingObjects.add(o);
} else if (item.isOutdated()) {
outdatedObjects.add(o);
}
}
}
}
}
boolean res = !this.downloadingObjects.equals(downloadingObjects)
|| !this.outdatedObjects.equals(outdatedObjects);
this.downloadingObjects = downloadingObjects;
this.outdatedObjects = outdatedObjects;
return res;
}
private boolean checkIfMapEmpty(RotatedTileBox tileBox) {
// RotatedTileBox cb = rm.getRenderer().getCheckedBox();
@ -388,18 +458,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
int point31x = MapUtils.get31TileNumberX(pointLatLon.getLongitude());
int point31y = MapUtils.get31TileNumberY(pointLatLon.getLatitude());
int left = MapUtils.get31TileNumberX(tb.getLeftTopLatLon().getLongitude());
int right = MapUtils.get31TileNumberX(tb.getRightBottomLatLon().getLongitude());
int top = MapUtils.get31TileNumberY(tb.getLeftTopLatLon().getLatitude());
int bottom = MapUtils.get31TileNumberY(tb.getRightBottomLatLon().getLatitude());
List<BinaryMapDataObject> result;
try {
result = osmandRegions.queryBbox(left, right, top, bottom);
} catch (IOException e) {
return;
}
List<BinaryMapDataObject> result = new LinkedList<>(data.results);
Iterator<BinaryMapDataObject> it = result.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
@ -422,7 +481,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
String fullName = osmandRegions.getFullName((BinaryMapDataObject) o);
final WorldRegion region = osmandRegions.getRegionData(fullName);
if (region != null) {
return region.getLevel();
return region.getLevel() - 1000;
}
}
return 0;
@ -432,7 +491,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
public void setSelectedObject(Object o) {
if (o instanceof BinaryMapDataObject) {
List<BinaryMapDataObject> list = new LinkedList<>();
if (selectedObjects != null) {
if (selectedObjects. size() > 0) {
list.addAll(selectedObjects);
}
list.add((BinaryMapDataObject) o);
@ -442,6 +501,6 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
@Override
public void clearSelectedObject() {
selectedObjects = null;
selectedObjects = new LinkedList<>();
}
}