From 0497f21b1a1440b8c6e2219a7186582dd99bba18 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 24 May 2014 23:08:19 +0200 Subject: [PATCH] Show on map location --- OsmAnd/res/layout/osmo_group_list_item.xml | 8 ++ OsmAnd/res/values/strings.xml | 2 + .../src/net/osmand/plus/osmo/OsMoGroups.java | 8 +- .../osmand/plus/osmo/OsMoGroupsActivity.java | 75 ++++++++++--------- .../src/net/osmand/plus/osmo/OsMoTracker.java | 34 +++++++-- .../plus/osmo/SettingsOsMoActivity.java | 2 +- 6 files changed, 85 insertions(+), 44 deletions(-) diff --git a/OsmAnd/res/layout/osmo_group_list_item.xml b/OsmAnd/res/layout/osmo_group_list_item.xml index ed651a138c..5745aa1bb5 100644 --- a/OsmAnd/res/layout/osmo_group_list_item.xml +++ b/OsmAnd/res/layout/osmo_group_list_item.xml @@ -23,6 +23,14 @@ android:layout_marginLeft="10dp" android:maxLines="7" android:layout_weight="1" /> + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a43c75873a..c2368fd9f1 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 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 --> + Logging interval + Choose time interval to send location days Connect Expires in diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java index 050260c379..6e89f97fb8 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java @@ -195,14 +195,13 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { connectGroupImpl(group); storage.save(); processed = true; - } else if(command.startsWith("LEAVE_GROUP:")) { + } else if(command.startsWith("GROUP_LEAVE:")) { String gid = command.substring(command.indexOf(':') + 1); group = storage.getGroup(gid); if(group != null) { - disconnectAllGroupUsers(group); storage.deleteGroup(group); - storage.save(); } + storage.save(); processed = true; } if(processed && uiListener != null) { @@ -339,6 +338,9 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { final String op = "GROUP_LEAVE:"+group.groupId; storage.deleteGroup(group); service.pushCommand(op); + if(group.isEnabled()) { + disconnectAllGroupUsers(group); + } return op; } diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java index 52bfc14e7c..4e348925e5 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java @@ -21,6 +21,7 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandExpandableListActivity; import net.osmand.plus.osmo.OsMoGroups.OsMoGroupsUIListener; @@ -28,7 +29,6 @@ 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 net.osmand.plus.views.OsmandMapLayer.DrawSettings; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.Context; @@ -53,10 +53,9 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.ArrayAdapter; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; -import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.EditText; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnGroupClickListener; @@ -82,6 +81,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements protected static final int DELETE_ACTION_ID = 2; public static final int CREATE_GROUP = 3; protected static final int ON_OFF_ACTION_ID = 4; + protected static final int SHARE_ID = 5; + protected static final int SHOW_ON_MAP_ID = 6; private static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30; private static final long RECENT_THRESHOLD = 60000; @@ -268,19 +269,32 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements return; } actionMode = startActionMode(new Callback() { + private OsMoDevice device; + private OsMoGroup group; + @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { selectedObject = o; + device = (OsMoDevice) (o instanceof OsMoDevice ?o : null); + group = (OsMoGroup) (o instanceof OsMoGroup ?o : null); 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.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); MenuItem mi = createMenuItem(menu, ON_OFF_ACTION_ID, R.string.default_buttons_ok, 0, 0, MenuItem.SHOW_AS_ACTION_ALWAYS); final LayoutInflater inflater = LayoutInflater.from(OsMoGroupsActivity.this); View view = inflater.inflate(R.layout.check_item_rel, null); final CompoundButton check = (CompoundButton) view.findViewById(R.id.check_item); - check.setChecked(o instanceof OsMoDevice ? - ((OsMoDevice) o).isEnabled() : ((OsMoGroup) o).isEnabled()); + check.setChecked((device != null && device.isEnabled()) || (group != null && group.isEnabled())); check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override @@ -320,6 +334,14 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements }); bld.setNegativeButton(R.string.default_buttons_no, null); bld.show(); + } else if(item.getItemId() == SHARE_ID) { + } else if(item.getItemId() == SHOW_ON_MAP_ID) { + if(device != null) { + Location location = device.getLastLocation(); + app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), app.getSettings().getMapZoomToShow(), + null, device.getVisibleName(), device); + MapActivity.launchMapActivityMoveToTop(OsMoGroupsActivity.this); + } } else if(item.getItemId() == ON_OFF_ACTION_ID) { CompoundButton bt = ((CompoundButton) item.getActionView().findViewById(R.id.check_item)); onOffAction(bt); @@ -363,7 +385,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements } String operation = osMoPlugin.getGroups().leaveGroup((OsMoGroup) selectedObject); startLongRunningOperation(operation); - + adapter.update((OsMoGroup) selectedObject); adapter.notifyDataSetChanged(); } @@ -680,27 +702,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements row.setBackgroundColor(Color.TRANSPARENT); } TextView label = (TextView) row.findViewById(R.id.osmo_label); + TextView labelTime = (TextView) row.findViewById(R.id.osmo_label_time); ImageView icon = (ImageView) row.findViewById(R.id.osmo_user_icon); -// final CompoundButton ch = (CompoundButton) row.findViewById(R.id.check_item); -// if(model.getGroup().isMainGroup()) { -// ch.setVisibility(View.VISIBLE); -// ch.setOnCheckedChangeListener(null); -// ch.setChecked(model.enabled); -// ch.setOnCheckedChangeListener(new OnCheckedChangeListener() { -// -// @Override -// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { -// if(isChecked) { -// osMoPlugin.getGroups().connectDevice(model); -// } else { -// osMoPlugin.getGroups().disconnectDevice(model); -// } -// } -// }); -// } else { -// ch.setVisibility(View.GONE); -// } - LatLon lnLocation = mapLocation; Location location = model.getLastLocation(); if(model.getTrackerId().equals(osMoPlugin.getService().getMyGroupTrackerId())) { @@ -725,29 +728,31 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements draw.setAngle(mes[1] - lastCompass + 180); draw.setRecent(Math.abs(location.getTime() - System.currentTimeMillis()) < RECENT_THRESHOLD); icon.setImageDrawable(draw); - icon.setImageResource(R.drawable.list_favorite); int dist = (int) mes[0]; long seconds = Math.max(0, (System.currentTimeMillis() - location.getTime()) / 1000); - String time = "\n ("; - if (seconds < 100) { + String time = ""; + if (seconds < 60) { + if(seconds > 15) { + seconds = (seconds / 5) * 5; + } time = seconds + " " + getString(R.string.seconds_ago); + } else if (seconds / 60 < 100) { time = (seconds / 60) + " " + getString(R.string.minutes_ago); } else { time = (seconds / (60 * 60)) + " " + getString(R.string.hours_ago); } - time += ")"; String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " "; String visibleName = model.getVisibleName(); String firstPart = distance + visibleName; - final String fullText = firstPart + time; - label.setText(fullText, TextView.BufferType.SPANNABLE); + label.setText(firstPart, TextView.BufferType.SPANNABLE); ((Spannable) label.getText()).setSpan( new ForegroundColorSpan(getResources().getColor(R.color.color_distance)), 0, distance.length() - 1, 0); - ((Spannable) label.getText()).setSpan( - new ForegroundColorSpan(getResources().getColor(R.color.color_unknown)), firstPart.length(), - fullText.length() - 1, 0); + labelTime.setText(time); + ((Spannable) labelTime.getText()).setSpan( + new ForegroundColorSpan(getResources().getColor(seconds < 60 ? R.color.color_ok : R.color.color_unknown)), 0, + time.length() -1, 0); } return row; diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoTracker.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoTracker.java index 96ec21ad6b..598567dd0b 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoTracker.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoTracker.java @@ -7,6 +7,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; import net.osmand.Location; import net.osmand.plus.OsmandSettings.CommonPreference; +import org.json.JSONException; import org.json.JSONObject; public class OsMoTracker implements OsMoSender, OsMoReactor { @@ -20,6 +21,7 @@ public class OsMoTracker implements OsMoSender, OsMoReactor { private Location lastSendLocation; private Location lastBufferLocation; private CommonPreference pref; + private String sessionURL; public interface OsmoTrackerListener { @@ -33,6 +35,13 @@ public class OsMoTracker implements OsMoSender, OsMoReactor { service.registerReactor(this); } + public String getSessionURL() { + if (!isEnabledTracker()) { + return null; + } + return "http://test1342.osmo.mobi/u/" + sessionURL; + } + public boolean isEnabledTracker() { return startSendingLocations; } @@ -130,15 +139,30 @@ public class OsMoTracker implements OsMoSender, OsMoReactor { @Override public boolean acceptCommand(String command, String data, JSONObject obj, OsMoThread thread) { - if(command.startsWith("LT:")) { + if(command.equals("LISTEN")) { + return true; + } else if(command.equals("UNLISTEN")) { + return true; + } else if(command.equals("TRACKER_SESSION_CLOSE")) { + return true; + } else if(command.equals("TRACKER_SESSION_OPEN")) { + try { + sessionURL = obj.getString("url"); + } catch (JSONException e) { + service.showErrorMessage(e.getMessage()); + e.printStackTrace(); + } + return true; + } else if(command.startsWith("LT:")) { String tid = command.substring(command.indexOf(':') + 1); float lat = 0; float lon = 0; float speed = 0; - int k = 1; - for (int i = 0; i <= data.length(); i++) { - boolean separator = i == data.length() || Character.isDigit(data.charAt(i)) || data.charAt(i) == ':' - || data.charAt(i) == '.'; + int k = 0; + for (int i = 1; i <= data.length(); i++) { + boolean separator = i == data.length() || + !(Character.isDigit(data.charAt(i)) || + data.charAt(i) == ':' || data.charAt(i) == '.'); if (separator) { char ch = data.charAt(k); String vl = data.substring(k + 1, i); diff --git a/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java b/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java index 5c0f3efe40..36e309d6e4 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/SettingsOsMoActivity.java @@ -51,7 +51,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity { grp.addPreference(sendLocationsref); grp.addPreference(createTimeListPreference(settings.OSMO_SAVE_TRACK_INTERVAL, SECONDS, - MINUTES, 1000, R.string.save_track_interval, R.string.save_track_interval_descr)); + MINUTES, 1000, R.string.osmo_track_interval, R.string.osmo_track_interval_descr)); debugPref = new Preference(this); debugPref.setTitle(R.string.osmo_settings_debug);