From 336827fc67a702661b1ca0ae19120759d5151db2 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 1 Jun 2014 18:17:22 +0200 Subject: [PATCH] Add 15 seconds --- .../src/net/osmand/plus/osmo/OsMoGroups.java | 17 +++-- .../osmand/plus/osmo/OsMoGroupsActivity.java | 2 +- .../osmand/plus/osmo/OsMoGroupsStorage.java | 4 -- .../osmand/plus/osmo/OsMoPositionLayer.java | 64 +++++++++++++++---- 4 files changed, 63 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java index 82d92048cf..3c4acb4613 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java @@ -41,7 +41,6 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { private OsMoGroupsStorage storage; private OsMoGroupsUIListener uiListener; private OsMoPlugin plugin; - private OsmandSettings settings; private OsmandApplication app; public interface OsMoGroupsUIListener { @@ -166,14 +165,18 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { StringBuilder b = new StringBuilder(); for(OsMoDevice d : delta) { if(d.getDeletedTimestamp() != 0 && d.isEnabled()) { - b.append(app.getString(R.string.osmo_user_joined, d.getVisibleName(), group.getVisibleName(app))).append("\n"); + if(group.name != null) { + b.append(app.getString(R.string.osmo_user_left, d.getVisibleName(), group.getVisibleName(app))).append("\n"); + } disconnectImpl(d); } else if(!d.isActive()) { - b.append(app.getString(R.string.osmo_user_left, d.getVisibleName(), group.getVisibleName(app))).append("\n"); + if(group.name != null) { + b.append(app.getString(R.string.osmo_user_joined, d.getVisibleName(), group.getVisibleName(app))).append("\n"); + } connectDeviceImpl(d); } } - if(b.length() > 0 && settings.OSMO_SHOW_GROUP_NOTIFICATIONS.get()){ + if(b.length() > 0 && app.getSettings().OSMO_SHOW_GROUP_NOTIFICATIONS.get()){ app.showToastMessage(b.toString().trim()); } storage.save(); @@ -343,6 +346,10 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { } storage.save(); } + public void setGenColor(OsMoDevice device, int genColor) { + device.genColor = genColor; + storage.save(); + } public OsMoDevice addConnectedDevice(String trackerId, String nameUser, int genColor) { OsMoDevice us = new OsMoDevice(); @@ -365,7 +372,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { } g.userName = userName; service.pushCommand(op); - return op; + return "GROUP_JOIN:"+groupId; } public String leaveGroup(OsMoGroup group) { diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java index e63d404cf2..7db76fb355 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java @@ -958,7 +958,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements int activeColor = model.getColor(); if (activeColor == 0) { activeColor = getRandomColor(); - model.setGenColor(activeColor); + osMoPlugin.getGroups().setGenColor(model, activeColor); } //Location location = tracker.getLastLocation(model.trackerId); if (location == null || mapLocation == null) { diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsStorage.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsStorage.java index 7da0bb4a56..a4362021bd 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsStorage.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsStorage.java @@ -357,10 +357,6 @@ public class OsMoGroupsStorage { this.lastOnline = lastOnline; } - public void setGenColor(int genColor) { - this.genColor = genColor; - } - public long getLastOnline() { return lastOnline; } diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java index 246c661cd4..486c9a0e67 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java @@ -2,7 +2,9 @@ package net.osmand.plus.osmo; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; import net.osmand.Location; import net.osmand.access.AccessibleToast; @@ -25,7 +27,10 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Paint.Cap; +import android.graphics.Paint.Join; import android.graphics.Paint.Style; +import android.graphics.Path; import android.graphics.PointF; import android.os.Handler; import android.util.DisplayMetrics; @@ -42,11 +47,13 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye private DisplayMetrics dm; private final MapActivity map; private OsmandMapTileView view; - private Paint pointAltUI; - private Paint point; + private Paint pointInnerCircle; + private Paint pointOuter; private OsMoPlugin plugin; private final static float startZoom = 7; private Handler uiHandler; + private Paint paintPath; + private Path pth; public OsMoPositionLayer(MapActivity map, OsMoPlugin plugin) { this.map = map; @@ -61,15 +68,24 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye 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); - pointAltUI.setAntiAlias(true); + pointInnerCircle = new Paint(); + pointInnerCircle.setColor(view.getApplication().getResources().getColor(R.color.poi_background)); + pointInnerCircle.setStyle(Style.FILL); + pointInnerCircle.setAntiAlias(true); - point = new Paint(); - point.setColor(Color.GRAY); - point.setAntiAlias(true); - point.setStyle(Style.FILL_AND_STROKE); + paintPath = new Paint(); + paintPath.setStyle(Style.STROKE); + paintPath.setStrokeWidth(14); + paintPath.setAntiAlias(true); + paintPath.setStrokeCap(Cap.ROUND); + paintPath.setStrokeJoin(Join.ROUND); + + pth = new Path(); + + pointOuter = new Paint(); + pointOuter.setColor(Color.GRAY); + pointOuter.setAntiAlias(true); + pointOuter.setStyle(Style.FILL_AND_STROKE); } public Collection getTrackingDevices() { @@ -94,15 +110,35 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye @Override public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) { final int r = getRadiusPoi(tb); + long treshold = System.currentTimeMillis() - 15000; for (OsMoDevice t : getTrackingDevices()) { Location l = t.getLastLocation(); if (l != null) { + ConcurrentLinkedQueue plocations = t.getPreviousLocations(treshold); 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 + 2, point); - canvas.drawCircle(x, y, r - 2, pointAltUI); + if (plocations.size() > 0) { + pth.rewind(); + Iterator it = plocations.iterator(); + boolean f= true; + while (it.hasNext()) { + Location lo = it.next(); + int xt = (int) tb.getPixXFromLatLon(lo.getLatitude(), lo.getLongitude()); + int yt = (int) tb.getPixYFromLatLon(lo.getLatitude(), lo.getLongitude()); + if(f) { + f = false; + pth.moveTo(xt, yt); + } else{ + pth.lineTo(xt, yt); + } + } + pth.lineTo(x, y); + paintPath.setColor(t.getColor()); + canvas.drawPath(pth, paintPath); + } + pointInnerCircle.setColor(t.getColor()); + canvas.drawCircle(x, y, r + 2, pointOuter); + canvas.drawCircle(x, y, r - 2, pointInnerCircle); } } }