Fix small issues (colors, center on map)

This commit is contained in:
Victor Shcherb 2014-06-01 17:32:30 +02:00
parent dca616d349
commit 6aef562893
10 changed files with 123 additions and 30 deletions

View file

@ -9,6 +9,10 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 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 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_user_joined">User %1$s joined group %2$s</string>
<string name="osmo_user_left">User %1$s left group %2$s</string>
<string name="osmo_show_group_notifications">Show group notifications</string>
<string name="osmo_show_group_notifications_descr">Show toast messages when user joins or leavs the group</string>
<string name="osmo_follow">Follow</string> <string name="osmo_follow">Follow</string>
<string name="osmo_sign_in">Sign in</string> <string name="osmo_sign_in">Sign in</string>
<string name="osmo_create_groups_confirm">In order to create groups you need to be a registered user of OsMo.</string> <string name="osmo_create_groups_confirm">In order to create groups you need to be a registered user of OsMo.</string>

View file

@ -834,6 +834,8 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> OSMO_AUTO_SEND_LOCATIONS = new BooleanPreference("osmo_automatically_send_locations", false).makeGlobal(); public final OsmandPreference<Boolean> OSMO_AUTO_SEND_LOCATIONS = new BooleanPreference("osmo_automatically_send_locations", false).makeGlobal();
public final OsmandPreference<Boolean> OSMO_SHOW_GROUP_NOTIFICATIONS = new BooleanPreference("osmo_show_toast_notifications", true).makeGlobal();
public final CommonPreference<Integer> OSMO_SAVE_TRACK_INTERVAL = new IntPreference("osmo_save_track_interval", 5000).makeGlobal().cache(); public final CommonPreference<Integer> OSMO_SAVE_TRACK_INTERVAL = new IntPreference("osmo_save_track_interval", 5000).makeGlobal().cache();
public final OsmandPreference<String> OSMO_GROUPS = new StringPreference("osmo_groups", "{}").makeGlobal(); public final OsmandPreference<String> OSMO_GROUPS = new StringPreference("osmo_groups", "{}").makeGlobal();

View file

@ -7,8 +7,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.R;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice; import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup; import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup;
import net.osmand.plus.osmo.OsMoTracker.OsmoTrackerListener; import net.osmand.plus.osmo.OsMoTracker.OsmoTrackerListener;
@ -39,6 +41,8 @@ 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;
public interface OsMoGroupsUIListener { public interface OsMoGroupsUIListener {
@ -47,13 +51,14 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
public void deviceLocationChanged(OsMoDevice device); public void deviceLocationChanged(OsMoDevice device);
} }
public OsMoGroups(OsMoPlugin plugin, OsMoService service, OsMoTracker tracker, OsmandSettings settings) { public OsMoGroups(OsMoPlugin plugin, OsMoService service, OsMoTracker tracker, OsmandApplication app) {
this.plugin = plugin; this.plugin = plugin;
this.service = service; this.service = service;
this.tracker = tracker; this.tracker = tracker;
this.app = app;
service.registerReactor(this); service.registerReactor(this);
tracker.setTrackerListener(this); tracker.setTrackerListener(this);
storage = new OsMoGroupsStorage(this, settings.OSMO_GROUPS); storage = new OsMoGroupsStorage(this, app.getSettings().OSMO_GROUPS);
storage.load(); storage.load();
} }
@ -158,13 +163,19 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
group = storage.getGroup(gid); group = storage.getGroup(gid);
if(group != null) { if(group != null) {
List<OsMoDevice> delta = mergeGroup(group, obj, false); List<OsMoDevice> delta = mergeGroup(group, obj, false);
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");
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");
connectDeviceImpl(d); connectDeviceImpl(d);
} }
} }
if(b.length() > 0 && settings.OSMO_SHOW_GROUP_NOTIFICATIONS.get()){
app.showToastMessage(b.toString().trim());
}
storage.save(); storage.save();
} }
processed = true; processed = true;

View file

@ -6,6 +6,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -26,6 +27,7 @@ public class OsMoGroupsStorage {
private static final String TRACKER_ID = "trackerId"; private static final String TRACKER_ID = "trackerId";
private static final String USER_NAME = "userName"; private static final String USER_NAME = "userName";
private static final String USER_COLOR = "userSetColor"; private static final String USER_COLOR = "userSetColor";
private static final String GEN_COLOR = "genColor";
private static final String SERVER_COLOR = "serverColor"; private static final String SERVER_COLOR = "serverColor";
private static final String DESCRIPTION = "description"; private static final String DESCRIPTION = "description";
private static final String POLICY = "policy"; private static final String POLICY = "policy";
@ -146,6 +148,9 @@ public class OsMoGroupsStorage {
if (u.userColor != 0) { if (u.userColor != 0) {
obj.put(USER_COLOR, u.userColor); obj.put(USER_COLOR, u.userColor);
} }
if (u.genColor != 0) {
obj.put(GEN_COLOR, u.genColor);
}
if (u.serverColor != 0) { if (u.serverColor != 0) {
obj.put(SERVER_COLOR, u.serverColor); obj.put(SERVER_COLOR, u.serverColor);
} }
@ -183,6 +188,9 @@ public class OsMoGroupsStorage {
if(o.has(USER_COLOR)) { if(o.has(USER_COLOR)) {
user.userColor = o.getInt(USER_COLOR); user.userColor = o.getInt(USER_COLOR);
} }
if(o.has(GEN_COLOR)) {
user.genColor = o.getInt(GEN_COLOR);
}
if(o.has(DELETED)) { if(o.has(DELETED)) {
user.deleted = o.getLong(DELETED); user.deleted = o.getLong(DELETED);
} }
@ -274,9 +282,6 @@ public class OsMoGroupsStorage {
OsMoDevice d = users.get(trackerId); OsMoDevice d = users.get(trackerId);
if(d != null) { if(d != null) {
d.setLastLocation(location); d.setLastLocation(location);
if(location != null) {
d.setLastOnline(location.getTime());
}
} }
return d; return d;
} }
@ -317,6 +322,7 @@ public class OsMoGroupsStorage {
protected long deleted; protected long deleted;
protected OsMoGroup group ; protected OsMoGroup group ;
protected ConcurrentLinkedQueue<Location> previousLocations = new java.util.concurrent.ConcurrentLinkedQueue<Location>();
protected List<OsMoMessage> messages = new ArrayList<OsMoMessage>(); protected List<OsMoMessage> messages = new ArrayList<OsMoMessage>();
protected long lastOnline; protected long lastOnline;
protected Location lastLocation; protected Location lastLocation;
@ -326,8 +332,21 @@ public class OsMoGroupsStorage {
return messages; return messages;
} }
public ConcurrentLinkedQueue<Location> getPreviousLocations(long threshold) {
while(!previousLocations.isEmpty() && previousLocations.peek().getTime() < threshold) {
previousLocations.poll();
}
return previousLocations;
}
public void setLastLocation(Location lastLocation) { public void setLastLocation(Location lastLocation) {
if(this.lastLocation != null) {
previousLocations.add(this.lastLocation);
}
this.lastLocation = lastLocation; this.lastLocation = lastLocation;
if (lastLocation != null) {
setLastOnline(lastLocation.getTime());
}
} }
public Location getLastLocation() { public Location getLastLocation() {

View file

@ -64,7 +64,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
tracker = new OsMoTracker(service, app.getSettings().OSMO_SAVE_TRACK_INTERVAL, tracker = new OsMoTracker(service, app.getSettings().OSMO_SAVE_TRACK_INTERVAL,
app.getSettings().OSMO_AUTO_SEND_LOCATIONS); app.getSettings().OSMO_AUTO_SEND_LOCATIONS);
new OsMoControlDevice(app, this, service, tracker); new OsMoControlDevice(app, this, service, tracker);
groups = new OsMoGroups(this, service, tracker, app.getSettings()); groups = new OsMoGroups(this, service, tracker, app);
this.app = app; this.app = app;
ApplicationMode.regWidget("osmo_control", (ApplicationMode[])null); ApplicationMode.regWidget("osmo_control", (ApplicationMode[])null);
} }

View file

@ -36,7 +36,8 @@ import android.widget.Toast;
* Class represents a layer for osmo positions * Class represents a layer for osmo positions
* *
*/ */
public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, OsMoGroupsUIListener { public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, OsMoGroupsUIListener,
ContextMenuLayer.IContextMenuProviderSelection{
private DisplayMetrics dm; private DisplayMetrics dm;
private final MapActivity map; private final MapActivity map;
@ -163,10 +164,10 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
@Override @Override
public String getObjectName(Object o) { public String getObjectName(Object o) {
if(o instanceof OsMoDevice) { // if(o instanceof OsMoDevice) {
return map.getString(R.string.osmo_user_name) + " " + ((OsMoDevice) o).getVisibleName(); // return map.getString(R.string.osmo_user_name) + " " + ((OsMoDevice) o).getVisibleName();
} // }
return null; return getObjectDescription(o);
} }
public void refresh() { public void refresh() {
@ -298,5 +299,21 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
} }
} }
@Override
public void setSelectedObject(Object o) {
if(o instanceof OsMoDevice) {
followTrackerId = ((OsMoDevice) o).getTrackerId();
}
}
@Override
public void clearSelectedObjects() {
LatLon mapLoc = new LatLon(map.getMapView().getLatitude(), map.getMapView().getLongitude());
final boolean centered = Algorithms.objectEquals(followMapLocation, mapLoc);
if(!centered && followTrackerId != null) {
followTrackerId = null;
}
}
} }

View file

@ -74,7 +74,7 @@ public class OsMoService implements OsMoReactor {
if(thread == null) { if(thread == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return new ArrayList<String>(thread.getLast100Commands()); return new ArrayList<String>(thread.getLastCommands());
} }
@ -246,6 +246,7 @@ public class OsMoService implements OsMoReactor {
app.showToastMessage(app.getString(R.string.osmo_io_error) + string); app.showToastMessage(app.getString(R.string.osmo_io_error) + string);
} }
public void pushCommand(String cmd) { public void pushCommand(String cmd) {
commands.add(cmd); commands.add(cmd);
} }

View file

@ -66,7 +66,8 @@ public class OsMoThread {
private SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); private SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
private ConcurrentLinkedQueue<String> last100Commands = new ConcurrentLinkedQueue<String>(); private ConcurrentLinkedQueue<String> lastCommands = new ConcurrentLinkedQueue<String>();
private final static int STACK_CMD = 30;
@ -91,6 +92,7 @@ public class OsMoThread {
this.activeChannel = null; this.activeChannel = null;
authorized = 0; authorized = 0;
reconnect = false; reconnect = false;
pingSent = 0;
failures = 0; failures = 0;
lastSendCommand = 0; lastSendCommand = 0;
selector = Selector.open(); selector = Selector.open();
@ -382,25 +384,29 @@ public class OsMoThread {
return ByteBuffer.wrap(prepareCommand(l).toString().getBytes("UTF-8")); return ByteBuffer.wrap(prepareCommand(l).toString().getBytes("UTF-8"));
} }
} }
if(System.currentTimeMillis() - lastSendCommand > TIMEOUT_TO_PING) { final long interval = System.currentTimeMillis() - lastSendCommand;
if(pingSent == 0) { if(interval > TIMEOUT_TO_PING) {
final long pingInterval = System.currentTimeMillis() - pingSent;
if(pingSent == 0 || pingInterval > TIMEOUT_TO_PING) {
pingSent = System.currentTimeMillis(); pingSent = System.currentTimeMillis();
cmd(PING_CMD, true); cmd(PING_CMD, true);
return ByteBuffer.wrap(prepareCommand(PING_CMD).toString().getBytes("UTF-8")); return ByteBuffer.wrap(prepareCommand(PING_CMD).toString().getBytes("UTF-8"));
} }
} else if(pingSent != 0) {
pingSent = 0;
} }
return null; return null;
} }
public ConcurrentLinkedQueue<String> getLast100Commands() { public ConcurrentLinkedQueue<String> getLastCommands() {
return last100Commands; return lastCommands;
} }
private void cmd(String cmd, boolean send) { private void cmd(String cmd, boolean send) {
log.info("OsMO" + (send ? "> " : ">> ") + cmd); log.info("OsMO" + (send ? "> " : ">> ") + cmd);
last100Commands.add((send ? "> " : ">> ") + df.format(new Date()) + " " + cmd); lastCommands.add((send ? "> " : ">> ") + df.format(new Date()) + " " + cmd);
while(last100Commands.size() > 100) { while(lastCommands.size() > STACK_CMD) {
last100Commands.poll(); lastCommands.poll();
} }
} }

View file

@ -28,7 +28,6 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
private Preference debugPref; private Preference debugPref;
private Preference trackerId; private Preference trackerId;
private CheckBoxPreference sendLocationsref;
public static final int[] SECONDS = new int[] {0, 1, 2, 3, 5, 10, 15, 30, 60, 90}; public static final int[] SECONDS = new int[] {0, 1, 2, 3, 5, 10, 15, 30, 60, 90};
public static final int[] MINUTES = new int[] {2, 3, 5}; public static final int[] MINUTES = new int[] {2, 3, 5};
@ -48,7 +47,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
trackerId.setOnPreferenceClickListener(this); trackerId.setOnPreferenceClickListener(this);
grp.addPreference(trackerId); grp.addPreference(trackerId);
sendLocationsref = createCheckBoxPreference(settings.OSMO_AUTO_SEND_LOCATIONS); CheckBoxPreference sendLocationsref = createCheckBoxPreference(settings.OSMO_AUTO_SEND_LOCATIONS);
sendLocationsref.setTitle(R.string.osmo_auto_send_locations); sendLocationsref.setTitle(R.string.osmo_auto_send_locations);
sendLocationsref.setSummary(R.string.osmo_auto_send_locations_descr); sendLocationsref.setSummary(R.string.osmo_auto_send_locations_descr);
grp.addPreference(sendLocationsref); grp.addPreference(sendLocationsref);
@ -56,6 +55,11 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
grp.addPreference(createTimeListPreference(settings.OSMO_SAVE_TRACK_INTERVAL, SECONDS, grp.addPreference(createTimeListPreference(settings.OSMO_SAVE_TRACK_INTERVAL, SECONDS,
MINUTES, 1000, R.string.osmo_track_interval, R.string.osmo_track_interval_descr)); MINUTES, 1000, R.string.osmo_track_interval, R.string.osmo_track_interval_descr));
CheckBoxPreference showGroupNotifiations = createCheckBoxPreference(settings.OSMO_SHOW_GROUP_NOTIFICATIONS);
sendLocationsref.setTitle(R.string.osmo_show_group_notifications);
sendLocationsref.setSummary(R.string.osmo_show_group_notifications_descr);
grp.addPreference(sendLocationsref);
debugPref = new Preference(this); debugPref = new Preference(this);
debugPref.setTitle(R.string.osmo_settings_debug); debugPref.setTitle(R.string.osmo_settings_debug);
debugPref.setOnPreferenceClickListener(this); debugPref.setOnPreferenceClickListener(this);

View file

@ -40,7 +40,17 @@ public class ContextMenuLayer extends OsmandMapLayer {
public String getObjectName(Object o); public String getObjectName(Object o);
} }
public interface IContextMenuProviderSelection {
public void setSelectedObject(Object o);
public void clearSelectedObjects();
}
private static final String KEY_LAT_LAN = "context_menu_lat_lon"; private static final String KEY_LAT_LAN = "context_menu_lat_lon";
private static final String KEY_DESCRIPTION = "context_menu_description"; private static final String KEY_DESCRIPTION = "context_menu_description";
private static final String KEY_SELECTED_OBJECTS = "context_menu_selected_objects"; private static final String KEY_SELECTED_OBJECTS = "context_menu_selected_objects";
@ -189,16 +199,28 @@ public class ContextMenuLayer extends OsmandMapLayer {
public void setSelections(Map<Object, IContextMenuProvider> selections) { public void setSelections(Map<Object, IContextMenuProvider> selections) {
clearSelectedObjects();
if (selections != null) { if (selections != null) {
selectedObjects = selections; selectedObjects = selections;
} else {
selectedObjects.clear();
} }
if (!selectedObjects.isEmpty()) { if (!selectedObjects.isEmpty()) {
Entry<Object, IContextMenuProvider> e = selectedObjects.entrySet().iterator().next(); Entry<Object, IContextMenuProvider> e = selectedObjects.entrySet().iterator().next();
latLon = e.getValue().getObjectLocation(e.getKey()); latLon = e.getValue().getObjectLocation(e.getKey());
if(e.getValue() instanceof IContextMenuProviderSelection){
((IContextMenuProviderSelection) e.getValue()).setSelectedObject(e.getKey());
} }
} }
}
private void clearSelectedObjects() {
for(IContextMenuProvider p : this.selectedObjects.values()) {
if(p instanceof IContextMenuProviderSelection){
((IContextMenuProviderSelection) p).clearSelectedObjects();
}
}
selectedObjects.clear();
}
@Override @Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) { public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
@ -223,15 +245,19 @@ public class ContextMenuLayer extends OsmandMapLayer {
public LatLon selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point) { public LatLon selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point) {
final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y); final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y);
final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y); final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y);
selectedObjects.clear(); clearSelectedObjects();
List<Object> s = new ArrayList<Object>(); List<Object> s = new ArrayList<Object>();
LatLon latLon = null; LatLon latLon = null;
for(OsmandMapLayer l : view.getLayers()){ for(OsmandMapLayer lt : view.getLayers()){
if(l instanceof ContextMenuLayer.IContextMenuProvider){ if(lt instanceof ContextMenuLayer.IContextMenuProvider){
s.clear(); s.clear();
((ContextMenuLayer.IContextMenuProvider) l).collectObjectsFromPoint(point, tileBox, s); final IContextMenuProvider l = (ContextMenuLayer.IContextMenuProvider) lt;
l.collectObjectsFromPoint(point, tileBox, s);
for(Object o : s) { for(Object o : s) {
selectedObjects.put(o, ((ContextMenuLayer.IContextMenuProvider) l)); selectedObjects.put(o, l);
if(l instanceof IContextMenuProviderSelection){
((IContextMenuProviderSelection) l).setSelectedObject(o);
}
if(latLon == null) { if(latLon == null) {
latLon = ((ContextMenuLayer.IContextMenuProvider) l).getObjectLocation(o); latLon = ((ContextMenuLayer.IContextMenuProvider) l).getObjectLocation(o);
} }
@ -382,13 +408,16 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
public void setSelectedObject(Object toShow) { public void setSelectedObject(Object toShow) {
selectedObjects.clear(); clearSelectedObjects();
if(toShow != null){ if(toShow != null){
for(OsmandMapLayer l : view.getLayers()){ for(OsmandMapLayer l : view.getLayers()){
if(l instanceof ContextMenuLayer.IContextMenuProvider){ if(l instanceof ContextMenuLayer.IContextMenuProvider){
String des = ((ContextMenuLayer.IContextMenuProvider) l).getObjectDescription(toShow); String des = ((ContextMenuLayer.IContextMenuProvider) l).getObjectDescription(toShow);
if(des != null) { if(des != null) {
selectedObjects.put(toShow, (IContextMenuProvider) l); selectedObjects.put(toShow, (IContextMenuProvider) l);
if(l instanceof IContextMenuProviderSelection){
((IContextMenuProviderSelection) l).setSelectedObject(toShow);
}
} }
} }
} }