Add 15 seconds

This commit is contained in:
Victor Shcherb 2014-06-01 18:17:22 +02:00
parent 6aef562893
commit 336827fc67
4 changed files with 63 additions and 24 deletions

View file

@ -41,7 +41,6 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
private OsMoGroupsStorage storage; private OsMoGroupsStorage storage;
private OsMoGroupsUIListener uiListener; private OsMoGroupsUIListener uiListener;
private OsMoPlugin plugin; private OsMoPlugin plugin;
private OsmandSettings settings;
private OsmandApplication app; private OsmandApplication app;
public interface OsMoGroupsUIListener { public interface OsMoGroupsUIListener {
@ -166,14 +165,18 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
for(OsMoDevice d : delta) { for(OsMoDevice d : delta) {
if(d.getDeletedTimestamp() != 0 && d.isEnabled()) { 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); disconnectImpl(d);
} else if(!d.isActive()) { } 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); 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()); app.showToastMessage(b.toString().trim());
} }
storage.save(); storage.save();
@ -343,6 +346,10 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
} }
storage.save(); storage.save();
} }
public void setGenColor(OsMoDevice device, int genColor) {
device.genColor = genColor;
storage.save();
}
public OsMoDevice addConnectedDevice(String trackerId, String nameUser, int genColor) { public OsMoDevice addConnectedDevice(String trackerId, String nameUser, int genColor) {
OsMoDevice us = new OsMoDevice(); OsMoDevice us = new OsMoDevice();
@ -365,7 +372,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
} }
g.userName = userName; g.userName = userName;
service.pushCommand(op); service.pushCommand(op);
return op; return "GROUP_JOIN:"+groupId;
} }
public String leaveGroup(OsMoGroup group) { public String leaveGroup(OsMoGroup group) {

View file

@ -958,7 +958,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
int activeColor = model.getColor(); int activeColor = model.getColor();
if (activeColor == 0) { if (activeColor == 0) {
activeColor = getRandomColor(); activeColor = getRandomColor();
model.setGenColor(activeColor); osMoPlugin.getGroups().setGenColor(model, activeColor);
} }
//Location location = tracker.getLastLocation(model.trackerId); //Location location = tracker.getLastLocation(model.trackerId);
if (location == null || mapLocation == null) { if (location == null || mapLocation == null) {

View file

@ -357,10 +357,6 @@ public class OsMoGroupsStorage {
this.lastOnline = lastOnline; this.lastOnline = lastOnline;
} }
public void setGenColor(int genColor) {
this.genColor = genColor;
}
public long getLastOnline() { public long getLastOnline() {
return lastOnline; return lastOnline;
} }

View file

@ -2,7 +2,9 @@ package net.osmand.plus.osmo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
@ -25,7 +27,10 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF; import android.graphics.PointF;
import android.os.Handler; import android.os.Handler;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@ -42,11 +47,13 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
private DisplayMetrics dm; private DisplayMetrics dm;
private final MapActivity map; private final MapActivity map;
private OsmandMapTileView view; private OsmandMapTileView view;
private Paint pointAltUI; private Paint pointInnerCircle;
private Paint point; private Paint pointOuter;
private OsMoPlugin plugin; private OsMoPlugin plugin;
private final static float startZoom = 7; private final static float startZoom = 7;
private Handler uiHandler; private Handler uiHandler;
private Paint paintPath;
private Path pth;
public OsMoPositionLayer(MapActivity map, OsMoPlugin plugin) { public OsMoPositionLayer(MapActivity map, OsMoPlugin plugin) {
this.map = map; this.map = map;
@ -61,15 +68,24 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE); WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm); wmgr.getDefaultDisplay().getMetrics(dm);
pointAltUI = new Paint(); pointInnerCircle = new Paint();
pointAltUI.setColor(view.getApplication().getResources().getColor(R.color.poi_background)); pointInnerCircle.setColor(view.getApplication().getResources().getColor(R.color.poi_background));
pointAltUI.setStyle(Style.FILL); pointInnerCircle.setStyle(Style.FILL);
pointAltUI.setAntiAlias(true); pointInnerCircle.setAntiAlias(true);
point = new Paint(); paintPath = new Paint();
point.setColor(Color.GRAY); paintPath.setStyle(Style.STROKE);
point.setAntiAlias(true); paintPath.setStrokeWidth(14);
point.setStyle(Style.FILL_AND_STROKE); 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<OsMoDevice> getTrackingDevices() { public Collection<OsMoDevice> getTrackingDevices() {
@ -94,15 +110,35 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
@Override @Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) { public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
final int r = getRadiusPoi(tb); final int r = getRadiusPoi(tb);
long treshold = System.currentTimeMillis() - 15000;
for (OsMoDevice t : getTrackingDevices()) { for (OsMoDevice t : getTrackingDevices()) {
Location l = t.getLastLocation(); Location l = t.getLastLocation();
if (l != null) { if (l != null) {
ConcurrentLinkedQueue<Location> plocations = t.getPreviousLocations(treshold);
int x = (int) tb.getPixXFromLatLon(l.getLatitude(), l.getLongitude()); int x = (int) tb.getPixXFromLatLon(l.getLatitude(), l.getLongitude());
int y = (int) tb.getPixYFromLatLon(l.getLatitude(), l.getLongitude()); int y = (int) tb.getPixYFromLatLon(l.getLatitude(), l.getLongitude());
if (plocations.size() > 0) {
pointAltUI.setColor(t.getColor()); pth.rewind();
canvas.drawCircle(x, y, r + 2, point); Iterator<Location> it = plocations.iterator();
canvas.drawCircle(x, y, r - 2, pointAltUI); 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);
} }
} }
} }