From 8c7b21e7fc4b2be45ef7d5de786f3149e939d65d Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 15 Dec 2012 00:20:44 +0100 Subject: [PATCH] Fix download --- OsmAnd/res/values/strings.xml | 3 + .../src/net/osmand/plus/ResourceManager.java | 1 + .../audionotes/AudioVideoNotesPlugin.java | 147 +++++++++++++++++- .../src/net/osmand/plus/render/QuadTree.java | 96 ------------ .../net/osmand/plus/render/TextRenderer.java | 22 +-- 5 files changed, 162 insertions(+), 107 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/render/QuadTree.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 39a024c4eb..bf8cdd4be2 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,9 @@ 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 --> + Location is not defined yet to take with audio notes + stop + Audio notes Audio notes plugin description Audio notes plugin parts diff --git a/OsmAnd/src/net/osmand/plus/ResourceManager.java b/OsmAnd/src/net/osmand/plus/ResourceManager.java index abf6cdb8d6..b7ea4f8bf6 100644 --- a/OsmAnd/src/net/osmand/plus/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/ResourceManager.java @@ -69,6 +69,7 @@ public class ResourceManager { public static final String APP_DIR = "osmand/"; //$NON-NLS-1$ 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 VOICE_PATH = APP_DIR + IndexConstants.VOICE_INDEX_DIR; public static final String GPX_PATH = APP_DIR + "tracks"; diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 93c638721b..c4d3b1bfb1 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -1,18 +1,54 @@ package net.osmand.plus.audionotes; +import java.io.File; +import java.io.IOException; +import java.util.EnumSet; + 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.OsmandPlugin; 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.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 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 static final String ID = "osmand.audionotes"; private static final Log log = LogUtil.getLog(AudioVideoNotesPlugin.class); private OsmandApplication app; + private TextInfoControl recordControl; + private MapActivity mapActivity; + + private DataTileManager indexedFiles = new DataTileManager(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 public String getId() { @@ -41,11 +77,120 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { @Override 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 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; + } + + } } diff --git a/OsmAnd/src/net/osmand/plus/render/QuadTree.java b/OsmAnd/src/net/osmand/plus/render/QuadTree.java deleted file mode 100644 index a13ed2cb6e..0000000000 --- a/OsmAnd/src/net/osmand/plus/render/QuadTree.java +++ /dev/null @@ -1,96 +0,0 @@ -package net.osmand.plus.render; - -import java.util.ArrayList; -import java.util.List; - -import android.graphics.RectF; - -public class QuadTree { - private static class Node { - List data = null; - Node[] 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 root; - - public QuadTree(RectF r, int depth/* =8 */, float ratio /* = 0.55 */) { - this.ratio = ratio; - this.root = new Node(r); - this.maxDepth = depth; - } - - void insert(T data, RectF box) { - int depth = 0; - doInsertData(data, box, root, depth); - } - - void queryInBox(RectF box, List result) { - result.clear(); - queryNode(box, result, root); - } - - private void queryNode(RectF box, List result, Node 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 n, int depth) { - if (++depth >= maxDepth) { - if (n.data == null) { - n.data = new ArrayList(); - } - 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(ext[i]); - } - doInsertData(data, box, n.children[i], depth); - return; - } - } - if (n.data == null) { - n.data = new ArrayList(); - } - 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); - } - -} diff --git a/OsmAnd/src/net/osmand/plus/render/TextRenderer.java b/OsmAnd/src/net/osmand/plus/render/TextRenderer.java index f1507e8ee1..23e6f84ac5 100644 --- a/OsmAnd/src/net/osmand/plus/render/TextRenderer.java +++ b/OsmAnd/src/net/osmand/plus/render/TextRenderer.java @@ -10,6 +10,8 @@ import java.util.List; import net.osmand.binary.BinaryMapDataObject; 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.render.RenderingRuleSearchRequest; import net.osmand.render.RenderingRulesStorage; @@ -42,7 +44,7 @@ public class TextRenderer { String text = null; Path drawOnPath = null; - RectF bounds = null; + QuadRect bounds = null; float vOffset = 0; float centerX = 0; float pathRotate = 0; @@ -99,9 +101,9 @@ public class TextRenderer { 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) { - return RectF.intersects(tRect, sRect); + return QuadRect.intersects(tRect, sRect); } float dist = FloatMath.sqrt(sqr(tRect.centerX() - sRect.centerX()) + sqr(tRect.centerY() - sRect.centerY())); if (dist < 3) { @@ -114,7 +116,7 @@ public class TextRenderer { tRot += Math.PI / 2; float l = tRect.centerX() - tRect.height() / 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 @@ -125,12 +127,12 @@ public class TextRenderer { diff -= sRot; float left = sRect.centerX() + dist * FloatMath.cos(diff) - tRect.width() / 2; float top = sRect.centerY() - dist * FloatMath.sin(diff) - tRect.height() / 2; - RectF nRect = new RectF(left, top, left + tRect.width(), top + tRect.height()); - return RectF.intersects(nRect, sRect); + QuadRect nRect = new QuadRect(left, top, left + tRect.width(), top + tRect.height()); + return QuadRect.intersects(nRect, sRect); } // 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) { @@ -160,7 +162,7 @@ public class TextRenderer { } } 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)); boundIntersections.queryInBox(boundsSearch, tempSearch); // drawTestBox(cv, &boundsSearch, text.pathRotate, paintIcon, text.text, NULL/*paintText*/); @@ -201,7 +203,7 @@ public class TextRenderer { 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); QuadTree nonIntersectedBounds = new QuadTree(r, 4, 0.6f); @@ -313,7 +315,7 @@ public class TextRenderer { paintText.setTextSize(rc.getDensityValue(text.textSize)); Rect bs = new Rect(); 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)); boolean display = true; if(path != null) {