Fix download
This commit is contained in:
parent
a045b20580
commit
8c7b21e7fc
5 changed files with 162 additions and 107 deletions
|
@ -9,6 +9,9 @@
|
||||||
1. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
1. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="audionotes_location_not_defined">Location is not defined yet to take with audio notes</string>
|
||||||
|
<string name="monitoring_control_stop">stop</string>
|
||||||
|
<string name="map_widget_audionotes">Audio notes</string>
|
||||||
<string name="audionotes_plugin_description">Audio notes plugin description</string>
|
<string name="audionotes_plugin_description">Audio notes plugin description</string>
|
||||||
<string name="audionotes_plugin_name">Audio notes plugin</string>
|
<string name="audionotes_plugin_name">Audio notes plugin</string>
|
||||||
<string name="index_srtm_parts">parts</string>
|
<string name="index_srtm_parts">parts</string>
|
||||||
|
|
|
@ -69,6 +69,7 @@ public class ResourceManager {
|
||||||
|
|
||||||
public static final String APP_DIR = "osmand/"; //$NON-NLS-1$
|
public static final String APP_DIR = "osmand/"; //$NON-NLS-1$
|
||||||
public static final String ROUTING_XML = APP_DIR + "routing.xml";
|
public static final String ROUTING_XML = APP_DIR + "routing.xml";
|
||||||
|
public static final String AV_PATH = APP_DIR + IndexConstants.AV_INDEX_DIR;
|
||||||
public static final String SRTM_PATH = APP_DIR + IndexConstants.SRTM_INDEX_DIR;
|
public static final String SRTM_PATH = APP_DIR + IndexConstants.SRTM_INDEX_DIR;
|
||||||
public static final String VOICE_PATH = APP_DIR + IndexConstants.VOICE_INDEX_DIR;
|
public static final String VOICE_PATH = APP_DIR + IndexConstants.VOICE_INDEX_DIR;
|
||||||
public static final String GPX_PATH = APP_DIR + "tracks";
|
public static final String GPX_PATH = APP_DIR + "tracks";
|
||||||
|
|
|
@ -1,18 +1,54 @@
|
||||||
package net.osmand.plus.audionotes;
|
package net.osmand.plus.audionotes;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import net.osmand.LogUtil;
|
import net.osmand.LogUtil;
|
||||||
|
import net.osmand.access.AccessibleToast;
|
||||||
|
import net.osmand.data.DataTileManager;
|
||||||
|
import net.osmand.osm.MapUtils;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.ResourceManager;
|
||||||
|
import net.osmand.plus.activities.ApplicationMode;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.parkingpoint.ParkingPositionLayer;
|
||||||
|
import net.osmand.plus.views.MapInfoLayer;
|
||||||
|
import net.osmand.plus.views.OsmandMapLayer;
|
||||||
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
|
import net.osmand.plus.views.TextInfoControl;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.media.MediaRecorder;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class AudioVideoNotesPlugin extends OsmandPlugin {
|
public class AudioVideoNotesPlugin extends OsmandPlugin {
|
||||||
|
|
||||||
public static final String ID = "osmand.audionotes";
|
public static final String ID = "osmand.audionotes";
|
||||||
private static final Log log = LogUtil.getLog(AudioVideoNotesPlugin.class);
|
private static final Log log = LogUtil.getLog(AudioVideoNotesPlugin.class);
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
private TextInfoControl recordControl;
|
||||||
|
private MapActivity mapActivity;
|
||||||
|
|
||||||
|
private DataTileManager<Recording> indexedFiles = new DataTileManager<AudioVideoNotesPlugin.Recording>(14);
|
||||||
|
private AudioNotesLayer audioNotesLayer;
|
||||||
|
|
||||||
|
public static class Recording {
|
||||||
|
public Recording(File f) {
|
||||||
|
this.file = f;
|
||||||
|
}
|
||||||
|
public File file;
|
||||||
|
public int x31;
|
||||||
|
public int y31;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -41,11 +77,120 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerLayers(MapActivity activity) {
|
public void registerLayers(MapActivity activity) {
|
||||||
|
if(audioNotesLayer != null) {
|
||||||
|
activity.getMapView().removeLayer(audioNotesLayer);
|
||||||
|
}
|
||||||
|
audioNotesLayer = new AudioNotesLayer(activity);
|
||||||
|
registerWidget(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void registerWidget(MapActivity activity) {
|
||||||
|
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
|
||||||
|
mapActivity = activity;
|
||||||
|
if (mapInfoLayer != null ) {
|
||||||
|
recordControl = createRecordControl(activity, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText());
|
||||||
|
mapInfoLayer.getMapInfoControls().registerSideWidget(recordControl,
|
||||||
|
-1/*R.drawable.widget_parking*/, R.string.map_widget_appearance, "audionotes", false,
|
||||||
|
EnumSet.allOf(ApplicationMode.class),
|
||||||
|
EnumSet.noneOf(ApplicationMode.class), 22);
|
||||||
|
mapInfoLayer.recreateControls();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private TextInfoControl createRecordControl(MapActivity activity, Paint paintText, Paint paintSubText) {
|
||||||
|
TextInfoControl recordPlaceControl = new TextInfoControl(activity, 0, paintText, paintSubText);
|
||||||
|
setRecordListener(recordPlaceControl);
|
||||||
|
return recordPlaceControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRecordListener(final TextInfoControl recordPlaceControl) {
|
||||||
|
recordPlaceControl.setText("", app.getString(R.string.monitoring_control_start));
|
||||||
|
recordPlaceControl.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
recordAudioVideo(recordPlaceControl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void recordAudioVideo(final TextInfoControl recordPlaceControl) {
|
||||||
|
Location loc = mapActivity.getLastKnownLocation();
|
||||||
|
if(loc == null) {
|
||||||
|
AccessibleToast.makeText(app, R.string.audionotes_location_not_defined, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
String basename = MapUtils.createShortLocString(loc.getLatitude(), loc.getLongitude(), 15);
|
||||||
|
File f = app.getSettings().extendOsmandPath(ResourceManager.AV_PATH);
|
||||||
|
f.mkdirs();
|
||||||
|
final MediaRecorder mr = new MediaRecorder();
|
||||||
|
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
|
||||||
|
int k = 1;
|
||||||
|
File fl;
|
||||||
|
do {
|
||||||
|
fl = new File(f, basename + "_" + (k++) + ".3gpp");
|
||||||
|
} while(fl.exists());
|
||||||
|
mr.setOutputFile(fl.getAbsolutePath());
|
||||||
|
mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
||||||
|
recordPlaceControl.setText("", app.getString(R.string.monitoring_control_stop));
|
||||||
|
try {
|
||||||
|
mr.prepare();
|
||||||
|
mr.start();
|
||||||
|
recordPlaceControl.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
mr.stop();
|
||||||
|
mr.release();
|
||||||
|
setRecordListener(recordPlaceControl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
AccessibleToast.makeText(app, app.getString(R.string.error_io_error) + " : " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void indexFile(File f){
|
||||||
|
Recording r = new Recording(f);
|
||||||
|
indexedFiles.registerObject(r.x31, r.y31, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable(OsmandApplication app) {
|
public void disable(OsmandApplication app) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class AudioNotesLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
|
private MapActivity activity;
|
||||||
|
|
||||||
|
public AudioNotesLayer(MapActivity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initLayer(OsmandMapTileView view) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDraw(Canvas canvas, RectF latlonRect, RectF tilesRect, DrawSettings settings) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyLayer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean drawInScreenPixels() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
package net.osmand.plus.render;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.graphics.RectF;
|
|
||||||
|
|
||||||
public class QuadTree<T> {
|
|
||||||
private static class Node<T> {
|
|
||||||
List<T> data = null;
|
|
||||||
Node<T>[] children = null;
|
|
||||||
RectF bounds;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private Node(RectF b) {
|
|
||||||
bounds = new RectF(b);
|
|
||||||
children = new Node[4];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private float ratio;
|
|
||||||
private int maxDepth;
|
|
||||||
private Node<T> root;
|
|
||||||
|
|
||||||
public QuadTree(RectF r, int depth/* =8 */, float ratio /* = 0.55 */) {
|
|
||||||
this.ratio = ratio;
|
|
||||||
this.root = new Node<T>(r);
|
|
||||||
this.maxDepth = depth;
|
|
||||||
}
|
|
||||||
|
|
||||||
void insert(T data, RectF box) {
|
|
||||||
int depth = 0;
|
|
||||||
doInsertData(data, box, root, depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
void queryInBox(RectF box, List<T> result) {
|
|
||||||
result.clear();
|
|
||||||
queryNode(box, result, root);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void queryNode(RectF box, List<T> result, Node<T> node) {
|
|
||||||
if (node != null) {
|
|
||||||
if (RectF.intersects(box, node.bounds)) {
|
|
||||||
if (node.data != null) {
|
|
||||||
result.addAll(node.data);
|
|
||||||
}
|
|
||||||
for (int k = 0; k < 4; ++k) {
|
|
||||||
queryNode(box, result, node.children[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doInsertData(T data, RectF box, Node<T> n, int depth) {
|
|
||||||
if (++depth >= maxDepth) {
|
|
||||||
if (n.data == null) {
|
|
||||||
n.data = new ArrayList<T>();
|
|
||||||
}
|
|
||||||
n.data.add(data);
|
|
||||||
} else {
|
|
||||||
RectF[] ext = new RectF[4];
|
|
||||||
splitBox(n.bounds, ext);
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
if (ext[i].contains(box)) {
|
|
||||||
if (n.children[i] == null) {
|
|
||||||
n.children[i] = new Node<T>(ext[i]);
|
|
||||||
}
|
|
||||||
doInsertData(data, box, n.children[i], depth);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (n.data == null) {
|
|
||||||
n.data = new ArrayList<T>();
|
|
||||||
}
|
|
||||||
n.data.add(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void splitBox(RectF node_extent, RectF[] n) {
|
|
||||||
// coord2d c=node_extent.center();
|
|
||||||
|
|
||||||
float width = node_extent.width();
|
|
||||||
float height = node_extent.height();
|
|
||||||
|
|
||||||
float lox = node_extent.left;
|
|
||||||
float loy = node_extent.top;
|
|
||||||
float hix = node_extent.right;
|
|
||||||
float hiy = node_extent.bottom;
|
|
||||||
|
|
||||||
n[0] = new RectF(lox, loy, lox + width * ratio, loy + height * ratio);
|
|
||||||
n[1] = new RectF(hix - width * ratio, loy, hix, loy + height * ratio);
|
|
||||||
n[2] = new RectF(lox, hiy - height * ratio, lox + width * ratio, hiy);
|
|
||||||
n[3] = new RectF(hix - width * ratio, hiy - height * ratio, hix, hiy);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -10,6 +10,8 @@ import java.util.List;
|
||||||
|
|
||||||
import net.osmand.binary.BinaryMapDataObject;
|
import net.osmand.binary.BinaryMapDataObject;
|
||||||
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
||||||
|
import net.osmand.data.QuadTree;
|
||||||
|
import net.osmand.data.QuadTree.QuadRect;
|
||||||
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
|
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
|
||||||
import net.osmand.render.RenderingRuleSearchRequest;
|
import net.osmand.render.RenderingRuleSearchRequest;
|
||||||
import net.osmand.render.RenderingRulesStorage;
|
import net.osmand.render.RenderingRulesStorage;
|
||||||
|
@ -42,7 +44,7 @@ public class TextRenderer {
|
||||||
|
|
||||||
String text = null;
|
String text = null;
|
||||||
Path drawOnPath = null;
|
Path drawOnPath = null;
|
||||||
RectF bounds = null;
|
QuadRect bounds = null;
|
||||||
float vOffset = 0;
|
float vOffset = 0;
|
||||||
float centerX = 0;
|
float centerX = 0;
|
||||||
float pathRotate = 0;
|
float pathRotate = 0;
|
||||||
|
@ -99,9 +101,9 @@ public class TextRenderer {
|
||||||
return a * a;
|
return a * a;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean intersects(RectF tRect, float tRot, RectF sRect, float sRot) {
|
boolean intersects(QuadRect tRect, float tRot, QuadRect sRect, float sRot) {
|
||||||
if (Math.abs(tRot) < Math.PI / 15 && Math.abs(sRot) < Math.PI / 15) {
|
if (Math.abs(tRot) < Math.PI / 15 && Math.abs(sRot) < Math.PI / 15) {
|
||||||
return RectF.intersects(tRect, sRect);
|
return QuadRect.intersects(tRect, sRect);
|
||||||
}
|
}
|
||||||
float dist = FloatMath.sqrt(sqr(tRect.centerX() - sRect.centerX()) + sqr(tRect.centerY() - sRect.centerY()));
|
float dist = FloatMath.sqrt(sqr(tRect.centerX() - sRect.centerX()) + sqr(tRect.centerY() - sRect.centerY()));
|
||||||
if (dist < 3) {
|
if (dist < 3) {
|
||||||
|
@ -114,7 +116,7 @@ public class TextRenderer {
|
||||||
tRot += Math.PI / 2;
|
tRot += Math.PI / 2;
|
||||||
float l = tRect.centerX() - tRect.height() / 2;
|
float l = tRect.centerX() - tRect.height() / 2;
|
||||||
float t = tRect.centerY() - tRect.width() / 2;
|
float t = tRect.centerY() - tRect.width() / 2;
|
||||||
tRect = new RectF(l, t, l + tRect.height(), t + tRect.width());
|
tRect = new QuadRect(l, t, l + tRect.height(), t + tRect.width());
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine difference close to 180/0 degrees
|
// determine difference close to 180/0 degrees
|
||||||
|
@ -125,12 +127,12 @@ public class TextRenderer {
|
||||||
diff -= sRot;
|
diff -= sRot;
|
||||||
float left = sRect.centerX() + dist * FloatMath.cos(diff) - tRect.width() / 2;
|
float left = sRect.centerX() + dist * FloatMath.cos(diff) - tRect.width() / 2;
|
||||||
float top = sRect.centerY() - dist * FloatMath.sin(diff) - tRect.height() / 2;
|
float top = sRect.centerY() - dist * FloatMath.sin(diff) - tRect.height() / 2;
|
||||||
RectF nRect = new RectF(left, top, left + tRect.width(), top + tRect.height());
|
QuadRect nRect = new QuadRect(left, top, left + tRect.width(), top + tRect.height());
|
||||||
return RectF.intersects(nRect, sRect);
|
return QuadRect.intersects(nRect, sRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO other cases not covered
|
// TODO other cases not covered
|
||||||
return RectF.intersects(tRect, sRect);
|
return QuadRect.intersects(tRect, sRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawTestBox(Canvas cv, RectF r, float rot, String text) {
|
void drawTestBox(Canvas cv, RectF r, float rot, String text) {
|
||||||
|
@ -160,7 +162,7 @@ public class TextRenderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (text.minDistance > 0) {
|
if (text.minDistance > 0) {
|
||||||
RectF boundsSearch = new RectF(text.bounds);
|
QuadRect boundsSearch = new QuadRect(text.bounds);
|
||||||
boundsSearch.inset(-rc.getDensityValue(Math.max(5.0f, text.minDistance)), -rc.getDensityValue(15));
|
boundsSearch.inset(-rc.getDensityValue(Math.max(5.0f, text.minDistance)), -rc.getDensityValue(15));
|
||||||
boundIntersections.queryInBox(boundsSearch, tempSearch);
|
boundIntersections.queryInBox(boundsSearch, tempSearch);
|
||||||
// drawTestBox(cv, &boundsSearch, text.pathRotate, paintIcon, text.text, NULL/*paintText*/);
|
// drawTestBox(cv, &boundsSearch, text.pathRotate, paintIcon, text.text, NULL/*paintText*/);
|
||||||
|
@ -201,7 +203,7 @@ public class TextRenderer {
|
||||||
return object1.textOrder - object2.textOrder;
|
return object1.textOrder - object2.textOrder;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
RectF r = new RectF(0, 0, rc.width, rc.height);
|
QuadRect r = new QuadRect(0, 0, rc.width, rc.height);
|
||||||
r.inset(-100, -100);
|
r.inset(-100, -100);
|
||||||
QuadTree<TextDrawInfo> nonIntersectedBounds = new QuadTree<TextDrawInfo>(r, 4, 0.6f);
|
QuadTree<TextDrawInfo> nonIntersectedBounds = new QuadTree<TextDrawInfo>(r, 4, 0.6f);
|
||||||
|
|
||||||
|
@ -313,7 +315,7 @@ public class TextRenderer {
|
||||||
paintText.setTextSize(rc.getDensityValue(text.textSize));
|
paintText.setTextSize(rc.getDensityValue(text.textSize));
|
||||||
Rect bs = new Rect();
|
Rect bs = new Rect();
|
||||||
paintText.getTextBounds(name, 0, name.length(), bs);
|
paintText.getTextBounds(name, 0, name.length(), bs);
|
||||||
text.bounds = new RectF(bs);
|
text.bounds = new QuadRect(bs.left, bs.top, bs.right, bs.bottom);
|
||||||
text.bounds.inset(-rc.getDensityValue(3), -rc.getDensityValue(10));
|
text.bounds.inset(-rc.getDensityValue(3), -rc.getDensityValue(10));
|
||||||
boolean display = true;
|
boolean display = true;
|
||||||
if(path != null) {
|
if(path != null) {
|
||||||
|
|
Loading…
Reference in a new issue