Fix small issues and add lock device to position
This commit is contained in:
parent
ebee46c5d8
commit
376c267348
9 changed files with 138 additions and 52 deletions
|
@ -1297,7 +1297,7 @@
|
|||
</string>
|
||||
<string name="available_downloads_left">Доступно %1$d файлов для скачивания</string>
|
||||
<string name="files_limit">осталось %1$d файлов</string>
|
||||
<string name="wait_current_task_finished">Пожалуйста, подождите, пока завершится текущий трек</string>
|
||||
<string name="wait_current_task_finished">Пожалуйста, подождите, пока завершится текущая операция</string>
|
||||
<string name="distance_measurement_load_gpx">Открыть существующий GPX</string>
|
||||
<string name="distance_measurement_finish_subtrack">Начать новый подтрек</string>
|
||||
<string name="gpx_file_name">Имя файла GPX</string>
|
||||
|
|
|
@ -3,14 +3,14 @@ package net.osmand.plus;
|
|||
public interface OsmAndConstants {
|
||||
|
||||
|
||||
public int UI_HANDLER_MAP_VIEW = 300;
|
||||
public int UI_HANDLER_MAP_VIEW = 3000;
|
||||
|
||||
public int UI_HANDLER_MAP_CONTROLS = 400;
|
||||
public int UI_HANDLER_MAP_CONTROLS = 4000;
|
||||
|
||||
public int UI_HANDLER_LOCATION_SERVICE = 500;
|
||||
public int UI_HANDLER_LOCATION_SERVICE = 5000;
|
||||
|
||||
public int UI_HANDLER_PROGRESS = 600;
|
||||
public int UI_HANDLER_PROGRESS = 6000;
|
||||
|
||||
public int UI_HANDLER_SEARCH = 700;
|
||||
public int UI_HANDLER_SEARCH = 7000;
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
public interface OsMoGroupsUIListener {
|
||||
|
||||
public void groupsListChange(String operation, OsMoGroup group);
|
||||
|
||||
public void deviceLocationChanged(OsMoDevice device);
|
||||
}
|
||||
|
||||
public OsMoGroups(OsMoService service, OsMoTracker tracker, OsmandSettings settings) {
|
||||
|
@ -132,8 +134,11 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
|
||||
@Override
|
||||
public void locationChange(String trackerId, Location location) {
|
||||
for(OsMoGroup g: getGroups()) {
|
||||
g.updateLastLocation(trackerId, location);
|
||||
for (OsMoGroup g : getGroups()) {
|
||||
OsMoDevice d = g.updateLastLocation(trackerId, location);
|
||||
if (d != null && uiListener != null) {
|
||||
uiListener.deviceLocationChanged(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ import net.osmand.plus.osmo.OsMoGroups.OsMoGroupsUIListener;
|
|||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
|
||||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup;
|
||||
import net.osmand.plus.osmo.OsMoService.SessionInfo;
|
||||
import net.osmand.plus.osmo.OsMoTracker.OsmoTrackerListener;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
|
@ -89,7 +88,7 @@ import com.actionbarsherlock.view.Window;
|
|||
*
|
||||
*/
|
||||
public class OsMoGroupsActivity extends OsmandExpandableListActivity implements OsmAndCompassListener,
|
||||
OsmAndLocationListener, OsmoTrackerListener, OsMoGroupsUIListener {
|
||||
OsmAndLocationListener, OsMoGroupsUIListener {
|
||||
|
||||
public static final int CONNECT_TO = 1;
|
||||
protected static final int DELETE_ACTION_ID = 2;
|
||||
|
@ -303,7 +302,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
app.getLocationProvider().registerOrUnregisterCompassListener(true);
|
||||
app.getLocationProvider().addLocationListener(this);
|
||||
app.getLocationProvider().resumeAllUpdates();
|
||||
osMoPlugin.getTracker().setUITrackerListener(this);
|
||||
osMoPlugin.getGroups().setUiListener(this);
|
||||
adapter.synchronizeGroups();
|
||||
}
|
||||
|
@ -314,7 +312,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
app.getLocationProvider().pauseAllUpdates();
|
||||
app.getLocationProvider().removeCompassListener(this);
|
||||
app.getLocationProvider().removeLocationListener(this);
|
||||
osMoPlugin.getTracker().setUITrackerListener(null);
|
||||
osMoPlugin.getGroups().setUiListener(null);
|
||||
}
|
||||
|
||||
|
@ -339,9 +336,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
if(device != null && device.getLastLocation() != null) {
|
||||
createMenuItem(menu, SHOW_ON_MAP_ID, R.string.show_poi_on_map, R.drawable.ic_action_marker_light, R.drawable.ic_action_marker_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
} else if(group != null) {
|
||||
createMenuItem(menu, SHOW_ON_MAP_ID, R.string.show_poi_on_map, R.drawable.ic_action_marker_light, R.drawable.ic_action_marker_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
}
|
||||
createMenuItem(menu, SHARE_ID, R.string.share_fav, R.drawable.ic_action_gshare_light, R.drawable.ic_action_gshare_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
@ -354,8 +348,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
createMenuItem(menu, GROUP_INFO, R.string.osmo_group_info, R.drawable.ic_action_info_light, R.drawable.ic_action_info_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
}
|
||||
createMenuItem(menu, DELETE_ACTION_ID, R.string.default_buttons_delete, R.drawable.ic_action_delete_light, R.drawable.ic_action_delete_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
if (device == null || device.getGroup().isMainGroup()) {
|
||||
createMenuItem(menu, DELETE_ACTION_ID, R.string.default_buttons_delete,
|
||||
R.drawable.ic_action_delete_light, R.drawable.ic_action_delete_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
}
|
||||
|
||||
|
||||
if (mi != null) {
|
||||
|
@ -417,7 +414,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
if(device != null) {
|
||||
Location location = device.getLastLocation();
|
||||
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), app.getSettings().getMapZoomToShow(),
|
||||
null, device.getVisibleName(), device);
|
||||
null, device.getVisibleName(), device);
|
||||
osMoPlugin.setMapFollowTrackerId(device);
|
||||
MapActivity.launchMapActivityMoveToTop(OsMoGroupsActivity.this);
|
||||
}
|
||||
} else if(item.getItemId() == ON_OFF_ACTION_ID) {
|
||||
|
@ -1003,7 +1001,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void locationChange(String trackerId, Location loc) {
|
||||
public void deviceLocationChanged(OsMoDevice device) {
|
||||
refreshList();
|
||||
}
|
||||
public static String colorToString(int color) {
|
||||
|
@ -1169,5 +1167,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ public class OsMoGroupsStorage {
|
|||
return name;
|
||||
}
|
||||
|
||||
public void updateLastLocation(String trackerId, Location location) {
|
||||
public OsMoDevice updateLastLocation(String trackerId, Location location) {
|
||||
OsMoDevice d = users.get(trackerId);
|
||||
if(d != null) {
|
||||
d.setLastLocation(location);
|
||||
|
@ -278,6 +278,7 @@ public class OsMoGroupsStorage {
|
|||
d.setLastOnline(location.getTime());
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ import net.osmand.plus.OsmandPlugin;
|
|||
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.osmo.OsMoService.SessionInfo;
|
||||
import net.osmand.plus.osmo.OsMoTracker.OsmoTrackerListener;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.MonitoringInfoControl;
|
||||
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
|
||||
|
@ -38,10 +38,10 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
private OsMoGroups groups;
|
||||
private BaseMapWidget osmoControl;
|
||||
private OsMoPositionLayer olayer;
|
||||
private Object followTrackerId;
|
||||
|
||||
// 2014-05-27 23:11:40
|
||||
public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private OsmandMapTileView mv;
|
||||
|
||||
public OsMoPlugin(final OsmandApplication app) {
|
||||
service = new OsMoService(app);
|
||||
|
@ -109,23 +109,14 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
|
||||
@Override
|
||||
public void mapActivityPause(MapActivity activity) {
|
||||
mv = null;
|
||||
tracker.setUITrackerListener(new OsmoTrackerListener() {
|
||||
|
||||
@Override
|
||||
public void locationChange(String trackerId, Location location) {
|
||||
if(mv != null) {
|
||||
mv.refreshMap();
|
||||
}
|
||||
}
|
||||
});
|
||||
groups.setUiListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapActivityResume(MapActivity activity) {
|
||||
mv = activity.getMapView();
|
||||
tracker.setUITrackerListener(null);
|
||||
|
||||
if(olayer != null) {
|
||||
groups.setUiListener(olayer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -249,6 +240,15 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
}).reg();
|
||||
}
|
||||
|
||||
public Object getFollowTrackerId() {
|
||||
return followTrackerId;
|
||||
}
|
||||
|
||||
public void setMapFollowTrackerId(OsMoDevice d) {
|
||||
if(olayer != null) {
|
||||
olayer.setFollowTrackerId(d);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
|
@ -267,4 +267,6 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
return service;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,18 +8,23 @@ import net.osmand.Location;
|
|||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.osmo.OsMoGroups.OsMoGroupsUIListener;
|
||||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
|
||||
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup;
|
||||
import net.osmand.plus.views.ContextMenuLayer;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.util.Algorithms;
|
||||
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.os.Handler;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
@ -28,7 +33,7 @@ import android.widget.Toast;
|
|||
* Class represents a layer for osmo positions
|
||||
*
|
||||
*/
|
||||
public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
|
||||
public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, OsMoGroupsUIListener {
|
||||
|
||||
private DisplayMetrics dm;
|
||||
private final MapActivity map;
|
||||
|
@ -37,6 +42,7 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
private Paint point;
|
||||
private OsMoPlugin plugin;
|
||||
private final static float startZoom = 7;
|
||||
private Handler uiHandler;
|
||||
|
||||
public OsMoPositionLayer(MapActivity map, OsMoPlugin plugin) {
|
||||
this.map = map;
|
||||
|
@ -46,6 +52,7 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
uiHandler = new Handler();
|
||||
dm = new DisplayMetrics();
|
||||
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
|
||||
wmgr.getDefaultDisplay().getMetrics(dm);
|
||||
|
@ -140,14 +147,22 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
@Override
|
||||
public String getObjectDescription(Object o) {
|
||||
if (o instanceof OsMoDevice) {
|
||||
return map.getString(R.string.osmo_user_name) + " " + ((OsMoDevice) o).getVisibleName();
|
||||
String d = map.getString(R.string.osmo_user_name) + " " + ((OsMoDevice) o).getVisibleName();
|
||||
final Location l = ((OsMoDevice) o).getLastLocation();
|
||||
if(l != null && l.hasSpeed()) {
|
||||
d += "\n"+ OsmAndFormatter.getFormattedSpeed(l.getSpeed(), map.getMyApplication());
|
||||
}
|
||||
return d;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getObjectName(Object o) {
|
||||
return ((OsMoDevice) o).getVisibleName();
|
||||
if(o instanceof OsMoDevice) {
|
||||
return map.getString(R.string.osmo_user_name) + " " + ((OsMoDevice) o).getVisibleName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
|
@ -180,6 +195,70 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void groupsListChange(String operation, OsMoGroup group) {
|
||||
}
|
||||
|
||||
private volatile boolean schedule = false;
|
||||
// store between rotations
|
||||
private static String followTrackerId;
|
||||
private static LatLon followMapLocation;
|
||||
|
||||
public void setFollowTrackerId(OsMoDevice d) {
|
||||
if(d != null) {
|
||||
followTrackerId = d.trackerId;
|
||||
Location l = d.getLastLocation();
|
||||
if(l != null) {
|
||||
followMapLocation = new LatLon(l.getLatitude(), l.getLongitude());
|
||||
}
|
||||
} else {
|
||||
followTrackerId = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deviceLocationChanged(final OsMoDevice device) {
|
||||
boolean sameId = Algorithms.objectEquals(followTrackerId, device.trackerId);
|
||||
Location l = device.getLastLocation();
|
||||
if(sameId && !schedule && l != null) {
|
||||
schedule = true;
|
||||
ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer();
|
||||
final boolean sameObject = Algorithms.objectEquals(device, cl.getFirstSelectedObject());
|
||||
LatLon mapLoc = new LatLon(map.getMapView().getLatitude(), map.getMapView().getLongitude());
|
||||
final boolean centered = Algorithms.objectEquals(followMapLocation, mapLoc);
|
||||
if(sameObject || centered) {
|
||||
if(centered ) {
|
||||
followMapLocation = new LatLon(l.getLatitude(), l.getLongitude());
|
||||
} else if(!map.getMapView().getAnimatedDraggingThread().isAnimating()) {
|
||||
// disable tracking
|
||||
followMapLocation = null;
|
||||
}
|
||||
uiHandler.postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
schedule = false;
|
||||
if (sameObject) {
|
||||
ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer();
|
||||
Location l = device.getLastLocation();
|
||||
cl.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), getObjectDescription(device));
|
||||
cl.setSelectedObject(device);
|
||||
}
|
||||
if (centered) {
|
||||
map.getMapView().setLatLon(followMapLocation.getLatitude(),
|
||||
followMapLocation.getLongitude());
|
||||
}
|
||||
map.getMapView().refreshMap();
|
||||
}
|
||||
|
||||
}, 150);
|
||||
} else {
|
||||
followTrackerId = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ public class OsMoTracker implements OsMoReactor {
|
|||
private boolean startSendingLocations;
|
||||
private OsMoService service;
|
||||
private int locationsSent = 0;
|
||||
private OsmoTrackerListener uiTrackerListener = null;
|
||||
private OsmoTrackerListener trackerListener = null;
|
||||
private Location lastSendLocation;
|
||||
private Location lastBufferLocation;
|
||||
|
@ -29,6 +28,7 @@ public class OsMoTracker implements OsMoReactor {
|
|||
|
||||
public void locationChange(String trackerId, Location location);
|
||||
}
|
||||
|
||||
|
||||
public OsMoTracker(OsMoService service, OsmandPreference<Integer> interval,
|
||||
OsmandPreference<Boolean> autoStart) {
|
||||
|
@ -112,8 +112,10 @@ public class OsMoTracker implements OsMoReactor {
|
|||
if (location.getTime() - ltime > pref.get()) {
|
||||
if(lastBufferLocation != null && (!lastBufferLocation.hasSpeed() || lastBufferLocation.getSpeed() < 1) &&
|
||||
lastBufferLocation.distanceTo(location) < 20){
|
||||
// ignores
|
||||
return;
|
||||
if(lastBufferLocation != null && location.getTime() - ltime < 60000) {
|
||||
// ignores
|
||||
return;
|
||||
}
|
||||
}
|
||||
lastBufferLocation = location;
|
||||
bufferOfLocations.add(location);
|
||||
|
@ -187,9 +189,6 @@ public class OsMoTracker implements OsMoReactor {
|
|||
if(trackerListener != null) {
|
||||
trackerListener.locationChange(tid, loc);
|
||||
}
|
||||
if(uiTrackerListener != null){
|
||||
uiTrackerListener.locationChange(tid, loc);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -204,13 +203,6 @@ public class OsMoTracker implements OsMoReactor {
|
|||
return trackerListener;
|
||||
}
|
||||
|
||||
public OsmoTrackerListener getUITrackerListener() {
|
||||
return uiTrackerListener;
|
||||
}
|
||||
|
||||
public void setUITrackerListener(OsmoTrackerListener trackerListener) {
|
||||
this.uiTrackerListener = trackerListener;
|
||||
}
|
||||
|
||||
public Collection<OsMoDevice> getTrackingDevices() {
|
||||
return trackingDevices.values();
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
|
@ -46,7 +47,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
private static final String KEY_SELECTED_OBJECTS = "context_menu_selected_objects";
|
||||
private LatLon latLon;
|
||||
private String description;
|
||||
private Map<Object, IContextMenuProvider> selectedObjects = new LinkedHashMap<Object, IContextMenuProvider>();
|
||||
private Map<Object, IContextMenuProvider> selectedObjects = new ConcurrentHashMap<Object, IContextMenuProvider>();
|
||||
|
||||
private TextView textView;
|
||||
private ImageView closeButton;
|
||||
|
@ -74,6 +75,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
@Override
|
||||
public void destroyLayer() {
|
||||
}
|
||||
|
||||
public Object getFirstSelectedObject() {
|
||||
if(!selectedObjects.isEmpty()) {
|
||||
return selectedObjects.keySet().iterator().next();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
|
|
Loading…
Reference in a new issue