Add points on map

This commit is contained in:
vshcherb 2014-05-28 02:09:23 +02:00
parent 4529c0f346
commit cee2c99356
6 changed files with 211 additions and 15 deletions

View file

@ -9,6 +9,7 @@
3. 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
-->
<string name="osmo_device_map_description">User : %1$s</string>
<string name="color_red">red</string>
<string name="color_pink">pink</string>
<string name="color_orange">orange</string>

View file

@ -71,7 +71,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
d.enabled = true;
d.active = true;
if(!service.getMyGroupTrackerId().equals(d.getTrackerId())) {
tracker.startTrackingId(d.trackerId);
tracker.startTrackingId(d);
}
}
@ -100,7 +100,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
String operation = "GROUP_DISCONNECT:"+model.groupId;
service.pushCommand(operation);
for(OsMoDevice d : model.getGroupUsers()) {
tracker.startTrackingId(d.trackerId);
tracker.startTrackingId(d);
}
storage.save();
return operation;
@ -113,7 +113,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
private void disconnectImpl(OsMoDevice model) {
model.enabled = false;
tracker.stopTrackingId(model.trackerId);
tracker.stopTrackingId(model);
}

View file

@ -12,6 +12,8 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import net.osmand.plus.osmodroid.OsMoDroidLayer;
import net.osmand.plus.parkingpoint.ParkingPositionLayer;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.MonitoringInfoControl;
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
@ -36,6 +38,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
private OsMoTracker tracker;
private OsMoGroups groups;
private BaseMapWidget osmoControl;
private OsMoPositionLayer olayer;
// 2014-05-27 23:11:40
public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@ -98,6 +101,12 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
layer.getMapInfoControls().registerSideWidget(osmoControl,
R.drawable.mon_osmo_conn_big, R.string.osmo_control, "osmo_control", false, 18);
layer.recreateControls();
if(olayer != null) {
activity.getMapView().removeLayer(olayer);
}
olayer = new OsMoPositionLayer(activity, this);
activity.getMapView().addLayer(olayer, 5.5f);
}
/**

View file

@ -0,0 +1,184 @@
package net.osmand.plus.osmo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.osmand.Location;
import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PointF;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.Toast;
/**
* Class represents a layer for osmo positions
*
*/
public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private DisplayMetrics dm;
private final MapActivity map;
private OsmandMapTileView view;
private Paint pointAltUI;
private Paint point;
private OsMoPlugin plugin;
private final static float startZoom = 10;
public OsMoPositionLayer(MapActivity map, OsMoPlugin plugin) {
this.map = map;
this.plugin = plugin;
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
pointAltUI = new Paint();
pointAltUI.setColor(view.getApplication().getResources().getColor(R.color.poi_background));
pointAltUI.setStyle(Style.FILL);
point = new Paint();
point.setColor(Color.GRAY);
point.setAntiAlias(true);
point.setStyle(Style.STROKE);
}
public Collection<OsMoDevice> getTrackingDevices() {
return plugin.getTracker().getTrackingDevices();
}
public int getRadiusPoi(RotatedTileBox tb){
int r = 0;
final float zoom = tb.getZoom() + tb.getZoomScale();
if(zoom < startZoom){
r = 0;
} else if(zoom <= 15){
r = 10;
} else if(zoom <= 16){
r = 14;
} else if(zoom <= 17){
r = 16;
} else {
r = 18;
}
return (int) (r * tb.getDensity());
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
final int r = getRadiusPoi(tb);
for (OsMoDevice t : getTrackingDevices()) {
Location l = t.getLastLocation();
if (t != null) {
int x = (int) tb.getPixXFromLatLon(l.getLatitude(), l.getLongitude());
int y = (int) tb.getPixYFromLatLon(l.getLatitude(), l.getLongitude());
pointAltUI.setColor(t.getColor());
canvas.drawCircle(x, y, r, pointAltUI);
canvas.drawCircle(x, y, r, point);
}
}
}
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
List<OsMoDevice> pos = new ArrayList<OsMoDevice>();
getOsmoFromPoint(tileBox, point, pos);
if (!pos.isEmpty()) {
StringBuilder res = new StringBuilder();
for (OsMoDevice d : pos) {
res.append(getObjectDescription(d));
}
AccessibleToast.makeText(view.getContext(), res.toString(), Toast.LENGTH_LONG).show();
return true;
}
return false;
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
getOsmoFromPoint(tileBox, point, o);
}
@Override
public LatLon getObjectLocation(Object o) {
if(o instanceof OsMoDevice) {
Location loc = ((OsMoDevice) o).getLastLocation();
if(loc != null) {
return new LatLon(loc.getLatitude(), loc.getLongitude());
}
}
return null;
}
@Override
public String getObjectDescription(Object o) {
if (o instanceof OsMoDevice) {
return map.getString(R.string.osmo_device_map_description, ((OsMoDevice) o).getVisibleName());
}
return null;
}
@Override
public String getObjectName(Object o) {
return ((OsMoDevice) o).getVisibleName();
}
public void refresh() {
if (view != null) {
view.refreshMap();
}
}
private void getOsmoFromPoint(RotatedTileBox tb, PointF point, List<? super OsMoDevice> points) {
if (view != null) {
int ex = (int) point.x;
int ey = (int) point.y;
final int rp = getRadiusPoi(tb);
int compare = rp;
int radius = rp * 3 / 2;
for (OsMoDevice d : getTrackingDevices()) {
Location position = d.getLastLocation();
if (position != null) {
int x = (int) tb.getPixXFromLatLon(position.getLatitude(), position.getLongitude());
int y = (int) tb.getPixYFromLatLon(position.getLatitude(), position.getLongitude());
// the width of an image is 40 px, the height is 60 px -> radius = 20,
// the position of a parking point relatively to the icon is at the center of the bottom line of the
// image
if (Math.abs(x - ex) <= compare && Math.abs(y - ey) <= compare) {
compare = radius;
points.add(d);
}
}
}
}
}
}

View file

@ -1,18 +1,20 @@
package net.osmand.plus.osmo;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import net.osmand.Location;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import org.json.JSONException;
import org.json.JSONObject;
public class OsMoTracker implements OsMoSender, OsMoReactor {
private ConcurrentLinkedQueue<Location> bufferOfLocations = new ConcurrentLinkedQueue<Location>();
private Map<String, Location> otherLocations = new ConcurrentHashMap<String, Location>();
private boolean startSendingLocations;
private OsMoService service;
private int locationsSent = 0;
@ -22,6 +24,7 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
private Location lastBufferLocation;
private CommonPreference<Integer> pref;
private String sessionURL;
private Map<String, OsMoDevice> trackingDevices = new java.util.concurrent.ConcurrentHashMap<String, OsMoGroupsStorage.OsMoDevice>();
public interface OsmoTrackerListener {
@ -60,17 +63,14 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
}
}
public Location getLastLocation(String trackerId) {
return otherLocations.get(trackerId);
public void startTrackingId(OsMoDevice d) {
service.pushCommand("LISTEN:"+d.getTrackerId());
trackingDevices.put(d.getTrackerId(), d);
}
public void startTrackingId(String id) {
service.pushCommand("LISTEN:"+id);
}
public void stopTrackingId(String id) {
service.pushCommand("UNLISTEN:"+id);
otherLocations.remove(id);
public void stopTrackingId(OsMoDevice d) {
service.pushCommand("UNLISTEN:"+d.getTrackerId());
trackingDevices.remove(d.getTrackerId());
}
@Override
@ -184,7 +184,6 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
if(speed > 0) {
loc.setSpeed(speed);
}
otherLocations.put(tid, loc);
if(trackerListener != null) {
trackerListener.locationChange(tid, loc);
}
@ -213,6 +212,10 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
this.uiTrackerListener = trackerListener;
}
public Collection<OsMoDevice> getTrackingDevices() {
return trackingDevices.values();
}
}

View file

@ -110,7 +110,6 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 19);
tv.setMovementMethod(LinkMovementMethod.getInstance());
bld.setView(sv);
bld.setMessage(bs.toString());
bld.setPositiveButton(R.string.default_buttons_ok, null);
bld.show();
return true;