commit
5f6f8fdfc6
15 changed files with 560 additions and 31 deletions
|
@ -31,6 +31,44 @@
|
|||
android:text="@string/osmo_start_service" />
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/osmo_log_off_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_marginTop="3dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/osmo_user_name_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/anonymous_user"
|
||||
android:textAppearance="?android:attr/textAppearance" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/osmo_login_logoff"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:focusable="false"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/osmo_login_hint_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@id/osmo_user_name_text_view"
|
||||
android:minHeight="0dp"
|
||||
android:minWidth="0dp"
|
||||
android:text="\?"
|
||||
android:textAppearance="?android:attr/textAppearance" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/enable_tracker"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
18
OsmAnd/res/layout/osmo_groups_list_footer.xml
Normal file
18
OsmAnd/res/layout/osmo_groups_list_footer.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/osmo_no_connection_msg"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:autoLink="web"
|
||||
android:linksClickable="true"
|
||||
android:padding="10dp"
|
||||
android:text="@string/osmo_no_connection_msg"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -31,6 +31,44 @@
|
|||
android:text="@string/osmo_start_service" />
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/osmo_log_off_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="3dp"
|
||||
android:layout_marginTop="3dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/osmo_user_name_text_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/anonymous_user"
|
||||
android:textAppearance="?android:attr/textAppearance" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/osmo_login_logoff"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:focusable="false"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/osmo_login_hint_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@id/osmo_user_name_text_view"
|
||||
android:minHeight="0dp"
|
||||
android:minWidth="0dp"
|
||||
android:text="\?"
|
||||
android:textAppearance="?android:attr/textAppearance" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/enable_tracker"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
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
|
||||
-->
|
||||
<string name="osmo_device_not_found">Device not found</string>
|
||||
<string name="osmo_no_connection_msg">OsMo service is not available:\n- check the connection;\n- check the settings;\n- check out our Twitter: https://twitter.com/OsMomobi</string>
|
||||
<string name="anonymous_user_hint">An anonymous user can not:\n- create groups;\n- synchronize groups and devices with the server;\n- manage groups and devices in a private office.</string>
|
||||
<string name="anonymous_user">Anonymous user</string>
|
||||
<string name="logged_as">Logged in as %1$s</string>
|
||||
<string name="speed_limit_exceed">Speed limit tolerance</string>
|
||||
<string name ="speed_limit_exceed_message">Select speed limit tolerance margin, above which you will receive a voice warning.</string>
|
||||
<string name="fav_point_emoticons_message">The favorite point name has been modified to %1$s to facilitate properly saving the string with emoticons to a file.</string>
|
||||
|
|
|
@ -49,6 +49,7 @@ import net.osmand.plus.activities.search.SearchActivity;
|
|||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
||||
import net.osmand.plus.helpers.WaypointDialogHelper;
|
||||
import net.osmand.plus.osmo.OsMoPositionLayer;
|
||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.BaseMapLayer;
|
||||
|
@ -873,6 +874,10 @@ public class MapActivityActions implements DialogProvider {
|
|||
@Override
|
||||
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||
stopNavigationActionConfirm(mapView);
|
||||
OsMoPositionLayer osMoPositionLayer = mapActivity.getMapView().getLayerByClass(OsMoPositionLayer.class);
|
||||
if (osMoPositionLayer != null) {
|
||||
OsMoPositionLayer.setFollowDestination(null);
|
||||
}
|
||||
}
|
||||
}).reg();
|
||||
}
|
||||
|
|
|
@ -132,7 +132,11 @@ public class OsMoControlDevice implements OsMoReactor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
public void onConnected() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(String msg) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@ package net.osmand.plus.osmo;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -19,6 +21,8 @@ import org.json.JSONArray;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
||||
|
||||
private static final String GROUP_NAME = "name";
|
||||
|
@ -34,6 +38,8 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
private static final String LAST_ONLINE = "last_online";
|
||||
private static final String TRACK = "track";
|
||||
private static final String POINT = "point";
|
||||
private static final String TRACKER_ID = "tracker_id";
|
||||
private static final String OK = "1";
|
||||
|
||||
private OsMoTracker tracker;
|
||||
private OsMoService service;
|
||||
|
@ -57,7 +63,11 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
service.registerReactor(this);
|
||||
tracker.setTrackerListener(this);
|
||||
storage = new OsMoGroupsStorage(this, app.getSettings().OSMO_GROUPS);
|
||||
storage.load();
|
||||
if (service.isLoggedIn()) {
|
||||
storage.loadOnlyMainGroup();
|
||||
} else {
|
||||
storage.load();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUiListener(OsMoGroupsUIListener uiListener) {
|
||||
|
@ -71,26 +81,31 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
private void connectDeviceImpl(OsMoDevice d) {
|
||||
d.enabled = true;
|
||||
d.active = true;
|
||||
String mid = service.getMyGroupTrackerId();
|
||||
if(mid == null || !mid.equals(d.getTrackerId())) {
|
||||
String mid = service.getMyTrackerId();
|
||||
String mgid = service.getMyGroupTrackerId();
|
||||
if ((mid == null || !mid.equals(d.getTrackerId()))
|
||||
&& (mgid == null || !mgid.equals(d.getTrackerId()))) {
|
||||
tracker.startTrackingId(d);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
public void onConnected() {
|
||||
for(OsMoDevice d : storage.getMainGroup().getGroupUsers(null)) {
|
||||
if(d.isEnabled()) {
|
||||
connectDeviceImpl(d);
|
||||
}
|
||||
}
|
||||
for(OsMoGroup g : storage.getGroups()) {
|
||||
if(!g.isMainGroup() && g.isEnabled()) {
|
||||
connectGroupImpl(g);
|
||||
}
|
||||
if (service.isLoggedIn()) {
|
||||
service.pushCommand("GROUP_GET_ALL");
|
||||
service.pushCommand("DEVICE_GET_ALL");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(String msg) {
|
||||
}
|
||||
|
||||
private String connectGroupImpl(OsMoGroup g) {
|
||||
g.enabled = true;
|
||||
String operation = "GROUP_CONNECT:" + g.groupId;
|
||||
|
@ -230,6 +245,109 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
}
|
||||
storage.save();
|
||||
processed = true;
|
||||
} else if (command.equals("GROUP_GET_ALL")) {
|
||||
try {
|
||||
JSONArray arr = new JSONArray(data);
|
||||
int arrLength = arr.length();
|
||||
if (arrLength > 0) {
|
||||
Map<String, OsMoGroup> resivedGroups = new HashMap<String, OsMoGroupsStorage.OsMoGroup>();
|
||||
for (int i = 0; i < arrLength; i++) {
|
||||
JSONObject o = arr.getJSONObject(i);
|
||||
OsMoGroup parsedGroup = parseGroup(o);
|
||||
resivedGroups.put(parsedGroup.getGroupId(), parsedGroup);
|
||||
}
|
||||
|
||||
storage.mergeGroups(resivedGroups);
|
||||
storage.save();
|
||||
}
|
||||
processed = true;
|
||||
for(OsMoGroup g : storage.getGroups()) {
|
||||
if(!g.isMainGroup() && g.isEnabled()) {
|
||||
connectGroupImpl(g);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
service.showErrorMessage(e.getMessage());
|
||||
return processed;
|
||||
}
|
||||
} else if (command.equals("DEVICE_GET_ALL")) {
|
||||
try {
|
||||
JSONArray arr = new JSONArray(data);
|
||||
int arrLength = arr.length();
|
||||
if (arrLength > 0) {
|
||||
OsMoGroup mainGroup = storage.getMainGroup();
|
||||
String mid = service.getMyTrackerId();
|
||||
Set<String> toDelete = new HashSet<String>(mainGroup.users.keySet());
|
||||
for (int i = 0; i < arrLength; i++) {
|
||||
JSONObject o = arr.getJSONObject(i);
|
||||
OsMoDevice device = parseDevice(o);
|
||||
device.group = mainGroup;
|
||||
String trackerId = device.getTrackerId();
|
||||
if (!mid.equals(trackerId)) {
|
||||
if (toDelete.contains(trackerId)) {
|
||||
toDelete.remove(trackerId);
|
||||
} else {
|
||||
mainGroup.users.put(trackerId, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String id : toDelete) {
|
||||
mainGroup.users.remove(id);
|
||||
}
|
||||
storage.save();
|
||||
for(OsMoDevice d : mainGroup.getGroupUsers(null)) {
|
||||
if(d.isEnabled() && !d.isActive()) {
|
||||
connectDeviceImpl(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
processed = true;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
service.showErrorMessage(e.getMessage());
|
||||
return processed;
|
||||
}
|
||||
} else if (command.equals("SUBSCRIBE")) {
|
||||
OsMoGroup mainGroup = storage.getMainGroup();
|
||||
OsMoDevice device = mainGroup.users.get(gid);
|
||||
if (device != null) {
|
||||
if (OK.equals(data)) {
|
||||
connectDeviceImpl(device);
|
||||
} else {
|
||||
mainGroup.users.remove(gid);
|
||||
storage.save();
|
||||
if (obj != null) {
|
||||
String errorDescription = obj
|
||||
.optString("error_description");
|
||||
if (!TextUtils.isEmpty(errorDescription)) {
|
||||
app.showToastMessage(errorDescription);
|
||||
}
|
||||
} else {
|
||||
app.showToastMessage(app.getString(R.string.osmo_device_not_found));
|
||||
}
|
||||
}
|
||||
}
|
||||
processed = true;
|
||||
} else if (command.equals("UNSUBSCRIBE")) {
|
||||
OsMoGroup mainGroup = storage.getMainGroup();
|
||||
OsMoDevice device = mainGroup.users.get(gid);
|
||||
if (device != null) {
|
||||
mainGroup.users.remove(gid);
|
||||
storage.save();
|
||||
}
|
||||
if (!OK.equals(data)) {
|
||||
if (obj != null) {
|
||||
String errorDescription = obj
|
||||
.optString("error_description");
|
||||
if (!TextUtils.isEmpty(errorDescription)) {
|
||||
app.showToastMessage(errorDescription);
|
||||
}
|
||||
} else {
|
||||
app.showToastMessage(app.getString(R.string.osmo_device_not_found));
|
||||
}
|
||||
}
|
||||
processed = true;
|
||||
}
|
||||
if(processed && uiListener != null) {
|
||||
uiListener.groupsListChange(operation, group);
|
||||
|
@ -237,6 +355,24 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
return processed;
|
||||
}
|
||||
|
||||
private OsMoGroup parseGroup(JSONObject obj) throws JSONException {
|
||||
OsMoGroup groupe = new OsMoGroup();
|
||||
groupe.enabled = true;
|
||||
groupe.name = obj.optString(GROUP_NAME);
|
||||
groupe.groupId = obj.getString(GROUP_ID);
|
||||
groupe.description = obj.optString(DESCRIPTION);
|
||||
groupe.policy = obj.optString(POLICY);
|
||||
return groupe;
|
||||
}
|
||||
|
||||
private OsMoDevice parseDevice(JSONObject obj) throws JSONException {
|
||||
OsMoDevice device = new OsMoDevice();
|
||||
device.enabled = true;
|
||||
device.userName = obj.optString(USER_NAME);
|
||||
device.trackerId = obj.getString(TRACKER_ID);
|
||||
return device;
|
||||
}
|
||||
|
||||
private void parseGroup(JSONObject obj, OsMoGroup gr) {
|
||||
try {
|
||||
if(obj.has(GROUP_NAME)) {
|
||||
|
@ -374,11 +510,13 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
|
||||
|
||||
public void deleteDevice(OsMoDevice device) {
|
||||
storage.getMainGroup().users.remove(device.trackerId);
|
||||
if(device.isEnabled()) {
|
||||
disconnectImpl(device);
|
||||
}
|
||||
storage.save();
|
||||
StringBuilder unsubscribeCmd = new StringBuilder();
|
||||
unsubscribeCmd.append("UNSUBSCRIBE:");
|
||||
unsubscribeCmd.append(device.trackerId);
|
||||
service.pushCommand(unsubscribeCmd.toString());
|
||||
}
|
||||
public void setGenColor(OsMoDevice device, int genColor) {
|
||||
device.genColor = genColor;
|
||||
|
@ -392,8 +530,13 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
us.userName = nameUser;
|
||||
us.genColor = genColor;
|
||||
us.group.users.put(trackerId, us);
|
||||
connectDeviceImpl(us);
|
||||
storage.save();
|
||||
StringBuilder subscribeCmd = new StringBuilder();
|
||||
subscribeCmd.append("SUBSCRIBE:");
|
||||
subscribeCmd.append(trackerId);
|
||||
subscribeCmd.append('|');
|
||||
subscribeCmd.append(nameUser);
|
||||
service.pushCommand(subscribeCmd.toString());
|
||||
return us;
|
||||
}
|
||||
public String joinGroup(String groupId, String userName, String nick) {
|
||||
|
@ -433,5 +576,9 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void clearGroups() {
|
||||
storage.clearGroups();
|
||||
storage.save();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import android.app.AlertDialog;
|
|||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
@ -58,6 +59,7 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.DisplayMetrics;
|
||||
|
@ -72,6 +74,7 @@ import android.webkit.WebViewClient;
|
|||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ImageView;
|
||||
|
@ -106,7 +109,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
protected static final int SETTINGS_DEV_ID = 10;
|
||||
protected static final int TRACK_DEV_ID = 11;
|
||||
private static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30;
|
||||
private static final long RECENT_THRESHOLD = 60000;
|
||||
public static final long RECENT_THRESHOLD = 60000;
|
||||
private boolean joinGroup;
|
||||
|
||||
private OsMoPlugin osMoPlugin;
|
||||
|
@ -124,6 +127,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
private String operation;
|
||||
private Paint white;
|
||||
private View header;
|
||||
private View footer;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -144,12 +148,13 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
getSupportActionBar().setTitle(R.string.osmo_activity);
|
||||
setSupportProgressBarIndeterminateVisibility(false);
|
||||
setupHeader();
|
||||
setupFooter();
|
||||
// getSupportActionBar().setIcon(R.drawable.tab_search_favorites_icon);
|
||||
|
||||
|
||||
adapter = new OsMoGroupsAdapter(osMoPlugin.getGroups(), osMoPlugin.getTracker(),
|
||||
osMoPlugin.getService());
|
||||
getExpandableListView().setAdapter(adapter);
|
||||
setListAdapter(adapter);
|
||||
|
||||
|
||||
uiHandler = new Handler();
|
||||
|
@ -207,6 +212,9 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
if (app.getNavigationService() != null) {
|
||||
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_LIVE);
|
||||
}
|
||||
if (getExpandableListView().getFooterViewsCount() > 0) {
|
||||
getExpandableListView().removeFooterView(footer);
|
||||
}
|
||||
}
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
header.postDelayed(new Runnable() {
|
||||
|
@ -234,8 +242,27 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
if(visible) {
|
||||
mtd.setText(si.motd);
|
||||
}
|
||||
|
||||
CompoundButton login = (CompoundButton) header.findViewById(R.id.osmo_login_logoff);
|
||||
login.setChecked(osMoPlugin.getService().isLoggedIn());
|
||||
login.setOnCheckedChangeListener(new LoginOnCheckedChangeListener());
|
||||
|
||||
Button hintBtn = (Button) header.findViewById(R.id.osmo_login_hint_button);
|
||||
hintBtn.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showHint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupFooter() {
|
||||
footer = getLayoutInflater().inflate(R.layout.osmo_groups_list_footer, null);
|
||||
TextView noConnectionTextView = (TextView) footer.findViewById(R.id.osmo_no_connection_msg);
|
||||
noConnectionTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
long lastUpdateTime;
|
||||
private Drawable blinkImg;
|
||||
private void blink(final ImageView status, Drawable bigger, final Drawable smaller ) {
|
||||
|
@ -276,12 +303,37 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
lastUpdateTime = last;
|
||||
blink(status, big, small);
|
||||
}
|
||||
View logOffLayout = header.findViewById(R.id.osmo_log_off_layout);
|
||||
CompoundButton login = (CompoundButton) header.findViewById(R.id.osmo_login_logoff);
|
||||
if(service.isConnected()) {
|
||||
header.findViewById(R.id.motd).setVisibility(View.VISIBLE);
|
||||
header.findViewById(R.id.enable_tracker).setVisibility(View.VISIBLE);
|
||||
|
||||
logOffLayout.setVisibility(View.VISIBLE);
|
||||
TextView userNameTextView = (TextView) header.findViewById(R.id.osmo_user_name_text_view);
|
||||
Button hintBtn = (Button) header.findViewById(R.id.osmo_login_hint_button);
|
||||
if (service.isLoggedIn()) {
|
||||
String text = getString(R.string.logged_as, app.getSettings().OSMO_USER_NAME.get());
|
||||
userNameTextView.setText(text);
|
||||
hintBtn.setVisibility(View.GONE);
|
||||
if (!login.isChecked()) {
|
||||
login.setOnCheckedChangeListener(null);
|
||||
login.setChecked(true);
|
||||
login.setOnCheckedChangeListener(new LoginOnCheckedChangeListener());
|
||||
}
|
||||
} else {
|
||||
userNameTextView.setText(R.string.anonymous_user);
|
||||
hintBtn.setVisibility(View.VISIBLE);
|
||||
if (login.isChecked()) {
|
||||
login.setOnCheckedChangeListener(null);
|
||||
login.setChecked(false);
|
||||
login.setOnCheckedChangeListener(new LoginOnCheckedChangeListener());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
header.findViewById(R.id.motd).setVisibility(View.GONE);
|
||||
header.findViewById(R.id.enable_tracker).setVisibility(View.GONE);
|
||||
logOffLayout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -656,6 +708,10 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
|
||||
private void signinPost() {
|
||||
signinPost(true);
|
||||
}
|
||||
|
||||
private void signinPost(final boolean createGroup) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.osmo_sign_in);
|
||||
LinearLayout ll = new LinearLayout(this);
|
||||
|
@ -689,6 +745,17 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
});
|
||||
|
||||
builder.setCancelable(true);
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
if (!createGroup) {
|
||||
updateStatus();
|
||||
setSupportProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
final AlertDialog dlg = builder.show();
|
||||
|
||||
wv.setWebViewClient(new WebViewClient() {
|
||||
|
@ -706,7 +773,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
app.getSettings().OSMO_USER_NAME.set(user);
|
||||
app.getSettings().OSMO_USER_PWD.set(pwd);
|
||||
osMoPlugin.getService().reconnectToServer();
|
||||
createGroupWithDelay(3000);
|
||||
if (createGroup) {
|
||||
createGroupWithDelay(3000);
|
||||
} else {
|
||||
updateStatus();
|
||||
}
|
||||
dlg.dismiss();
|
||||
return true;
|
||||
}
|
||||
|
@ -930,8 +1001,13 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
if(group != null) {
|
||||
adapter.update(group);
|
||||
adapter.notifyDataSetChanged();
|
||||
} else if (operation.startsWith("GROUP_GET_ALL")
|
||||
|| operation.startsWith("DEVICE_GET_ALL")
|
||||
|| operation.startsWith("SUBSCRIBE")
|
||||
|| operation.startsWith("UNSUBSCRIBE")) {
|
||||
adapter.synchronizeGroups();
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
|
@ -1373,7 +1449,72 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
private void logoff() {
|
||||
if (osMoPlugin.getService().isLoggedIn()) {
|
||||
app.getSettings().OSMO_USER_NAME.set("");
|
||||
app.getSettings().OSMO_USER_PWD.set("");
|
||||
osMoPlugin.getService().reconnectToServer();
|
||||
updateStatus();
|
||||
osMoPlugin.getGroups().clearGroups();
|
||||
adapter.synchronizeGroups();
|
||||
}
|
||||
}
|
||||
|
||||
private void showHint() {
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.anonymous_user);
|
||||
String message = getString(R.string.anonymous_user_hint);
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private class LoginOnCheckedChangeListener implements OnCheckedChangeListener {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
if (!osMoPlugin.getService().isLoggedIn()) {
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
signinPost(false);
|
||||
}
|
||||
} else {
|
||||
logoff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleConnect() {
|
||||
app.runInUIThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (getExpandableListView().getFooterViewsCount() > 0) {
|
||||
getExpandableListView().removeFooterView(footer);
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleDisconnect(final String msg) {
|
||||
app.runInUIThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!TextUtils.isEmpty(msg)) {
|
||||
CompoundButton srvc = (CompoundButton) header.findViewById(R.id.enable_service);
|
||||
if (srvc.isChecked()) {
|
||||
if (getExpandableListView().getFooterViewsCount() == 0) {
|
||||
getExpandableListView().addFooterView(footer);
|
||||
}
|
||||
adapter.clear();
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package net.osmand.plus.osmo;
|
||||
|
||||
import java.security.acl.Group;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
|
@ -18,6 +22,7 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
||||
public class OsMoGroupsStorage {
|
||||
private static final String GROUPS = "groups";
|
||||
|
@ -56,6 +61,17 @@ public class OsMoGroupsStorage {
|
|||
return groups.values();
|
||||
}
|
||||
|
||||
public void loadOnlyMainGroup() {
|
||||
String grp = pref.get();
|
||||
try {
|
||||
JSONObject obj = new JSONObject(grp);
|
||||
parseGroupUsers(mainGroup, obj);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
service.showErrorMessage(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
String grp = pref.get();
|
||||
try {
|
||||
|
@ -396,7 +412,16 @@ public class OsMoGroupsStorage {
|
|||
}
|
||||
return genColor;
|
||||
}
|
||||
|
||||
|
||||
public int getNonActiveColor() {
|
||||
int color = getColor();
|
||||
int alpha = Math.round(Color.alpha(color) * 0.3f);
|
||||
int red = Color.red(color);
|
||||
int green = Color.green(color);
|
||||
int blue = Color.blue(color);
|
||||
return Color.argb(alpha, red, green, blue);
|
||||
}
|
||||
|
||||
public String getVisibleName(){
|
||||
if(userName != null && userName.length() > 0) {
|
||||
return userName;
|
||||
|
@ -423,5 +448,29 @@ public class OsMoGroupsStorage {
|
|||
|
||||
}
|
||||
|
||||
|
||||
public void mergeGroups(Map<String, OsMoGroup> groupsToMerge) {
|
||||
Set<String> toDelete = new HashSet<String>(groups.keySet());
|
||||
if (groupsToMerge != null) {
|
||||
Set<String> toMerge = groupsToMerge.keySet();
|
||||
for (String id: toMerge) {
|
||||
if (toDelete.contains(id)) {
|
||||
toDelete.remove(id);
|
||||
} else {
|
||||
addGroup(groupsToMerge.get(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String id: toDelete) {
|
||||
OsMoGroup group = getGroup(id);
|
||||
if ((group != null) && (!group.equals(mainGroup))) {
|
||||
deleteGroup(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearGroups() {
|
||||
groups.clear();
|
||||
groups.put("", mainGroup);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ import android.preference.Preference.OnPreferenceClickListener;
|
|||
import android.preference.PreferenceScreen;
|
||||
import android.view.View;
|
||||
|
||||
public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlServices {
|
||||
public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlServices, OsMoReactor {
|
||||
|
||||
private OsmandApplication app;
|
||||
public static final String ID = "osmand.osmo";
|
||||
|
@ -497,5 +497,28 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptCommand(String command, String id, String data, JSONObject obj, OsMoThread tread) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextSendCommand(OsMoThread tracker) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected() {
|
||||
if (groupsActivity != null) {
|
||||
groupsActivity.handleConnect();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(String msg) {
|
||||
if (groupsActivity != null) {
|
||||
groupsActivity.handleDisconnect(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.core.jni.ColorARGB;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
|
@ -46,6 +47,9 @@ import android.widget.Toast;
|
|||
public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, OsMoGroupsUIListener,
|
||||
ContextMenuLayer.IContextMenuProviderSelection{
|
||||
|
||||
private static int POINT_OUTER_COLOR = 0x88555555;
|
||||
private static int PAINT_TEXT_ICON_COLOR = Color.BLACK;
|
||||
|
||||
private DisplayMetrics dm;
|
||||
private final MapActivity map;
|
||||
private OsmandMapTileView view;
|
||||
|
@ -87,13 +91,13 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
paintTextIcon.setTextSize(10 * view.getDensity());
|
||||
paintTextIcon.setTextAlign(Align.CENTER);
|
||||
paintTextIcon.setFakeBoldText(true);
|
||||
paintTextIcon.setColor(Color.BLACK);
|
||||
paintTextIcon.setColor(PAINT_TEXT_ICON_COLOR);
|
||||
paintTextIcon.setAntiAlias(true);
|
||||
|
||||
pth = new Path();
|
||||
|
||||
pointOuter = new Paint();
|
||||
pointOuter.setColor(0x88555555);
|
||||
pointOuter.setColor(POINT_OUTER_COLOR);
|
||||
pointOuter.setAntiAlias(true);
|
||||
pointOuter.setStyle(Style.FILL_AND_STROKE);
|
||||
}
|
||||
|
@ -153,6 +157,32 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
int x = (int) tileBox.getPixXFromLatLon(l.getLatitude(), l.getLongitude());
|
||||
int y = (int) tileBox.getPixYFromLatLon(l.getLatitude(), l.getLongitude());
|
||||
pointInnerCircle.setColor(t.getColor());
|
||||
pointOuter.setColor(POINT_OUTER_COLOR);
|
||||
paintTextIcon.setColor(PAINT_TEXT_ICON_COLOR);
|
||||
Location lastLocation = t.getLastLocation();
|
||||
if (lastLocation != null) {
|
||||
long now = System.currentTimeMillis();
|
||||
boolean recent = Math.abs( now - lastLocation.getTime() ) < OsMoGroupsActivity.RECENT_THRESHOLD;
|
||||
if (!recent) {
|
||||
int color = t.getNonActiveColor();
|
||||
pointInnerCircle.setColor(color);
|
||||
pointOuter.setColor(Color.argb(Color.alpha(color),
|
||||
Color.red(POINT_OUTER_COLOR), Color.green(POINT_OUTER_COLOR),
|
||||
Color.blue(POINT_OUTER_COLOR)));
|
||||
paintTextIcon.setColor(Color.argb(Color.alpha(color),
|
||||
Color.red(PAINT_TEXT_ICON_COLOR), Color.green(PAINT_TEXT_ICON_COLOR),
|
||||
Color.blue(PAINT_TEXT_ICON_COLOR)));
|
||||
}
|
||||
} else {
|
||||
int color = t.getNonActiveColor();
|
||||
pointInnerCircle.setColor(color);
|
||||
pointOuter.setColor(Color.argb(Color.alpha(color),
|
||||
Color.red(POINT_OUTER_COLOR), Color.green(POINT_OUTER_COLOR),
|
||||
Color.blue(POINT_OUTER_COLOR)));
|
||||
paintTextIcon.setColor(Color.argb(Color.alpha(color),
|
||||
Color.red(PAINT_TEXT_ICON_COLOR), Color.green(PAINT_TEXT_ICON_COLOR),
|
||||
Color.blue(PAINT_TEXT_ICON_COLOR)));
|
||||
}
|
||||
canvas.drawCircle(x, y, r + (float)Math.ceil(tileBox.getDensity()), pointOuter);
|
||||
canvas.drawCircle(x, y, r - (float)Math.ceil(tileBox.getDensity()), pointInnerCircle);
|
||||
paintTextIcon.setTextSize(r * 3 / 2);
|
||||
|
|
|
@ -8,6 +8,8 @@ public interface OsMoReactor {
|
|||
|
||||
public String nextSendCommand(OsMoThread tracker);
|
||||
|
||||
public void reconnect();
|
||||
public void onConnected();
|
||||
|
||||
public void onDisconnected(String msg);
|
||||
|
||||
}
|
|
@ -42,6 +42,7 @@ import android.os.AsyncTask;
|
|||
import android.os.Build;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class OsMoService implements OsMoReactor {
|
||||
public static final String REGENERATE_CMD = "TRACKER_REGENERATE_ID";
|
||||
|
@ -62,13 +63,14 @@ public class OsMoService implements OsMoReactor {
|
|||
private Notification notification;
|
||||
public final static String OSMO_REGISTER_AGAIN = "OSMO_REGISTER_AGAIN"; //$NON-NLS-1$
|
||||
private final static int SIMPLE_NOTFICATION_ID = 5;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public OsMoService(final OsmandApplication app, OsMoPlugin plugin) {
|
||||
this.app = app;
|
||||
this.plugin = plugin;
|
||||
listReactors.add(this);
|
||||
listReactors.add(plugin);
|
||||
broadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -89,7 +91,7 @@ public class OsMoService implements OsMoReactor {
|
|||
public Void doInBackground(Void... voids ) {
|
||||
try {
|
||||
registerOsmoDeviceKey();
|
||||
reconnect();
|
||||
onConnected();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -241,6 +243,14 @@ public class OsMoService implements OsMoReactor {
|
|||
return myGroupTrackerId;
|
||||
}
|
||||
|
||||
public String getMyTrackerId() {
|
||||
String myGroupTrackerId = "";
|
||||
SessionInfo currentSessionInfo = getCurrentSessionInfo();
|
||||
if (currentSessionInfo != null) {
|
||||
myGroupTrackerId = currentSessionInfo.trackerId;
|
||||
}
|
||||
return myGroupTrackerId;
|
||||
}
|
||||
|
||||
public SessionInfo prepareSessionToken() throws IOException {
|
||||
String deviceKey = app.getSettings().OSMO_DEVICE_KEY.get();
|
||||
|
@ -407,14 +417,23 @@ public class OsMoService implements OsMoReactor {
|
|||
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
public void onConnected() {
|
||||
pushCommand("TRACK_GET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(String msg) {
|
||||
}
|
||||
|
||||
public void reconnectToServer() {
|
||||
if(thread != null) {
|
||||
thread.reconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isLoggedIn() {
|
||||
String psswd = app.getSettings().OSMO_USER_PWD.get();
|
||||
String userName = app.getSettings().OSMO_USER_NAME.get();
|
||||
return ((!TextUtils.isEmpty(psswd) && !TextUtils.isEmpty(userName)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class OsMoThread {
|
|||
this.activeChannel = activeChannel;
|
||||
key.attach(new Integer(++activeConnectionId));
|
||||
for(OsMoReactor sender : listReactors) {
|
||||
sender.reconnect();
|
||||
sender.onConnected();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -171,6 +171,10 @@ public class OsMoThread {
|
|||
if (activeChannel != null && !activeChannel.isConnected()) {
|
||||
activeChannel = null;
|
||||
}
|
||||
String msg = e.getMessage();
|
||||
for(OsMoReactor sender : listReactors) {
|
||||
sender.onDisconnected(msg);
|
||||
}
|
||||
delay = HEARTBEAT_FAILED_DELAY;
|
||||
if(lastSendCommand != 0 && System.currentTimeMillis() - lastSendCommand > TIMEOUT_TO_RECONNECT ) {
|
||||
reconnect = true;
|
||||
|
@ -180,6 +184,9 @@ public class OsMoThread {
|
|||
}
|
||||
if (stopThread) {
|
||||
stopChannel();
|
||||
for(OsMoReactor sender : listReactors) {
|
||||
sender.onDisconnected(null);
|
||||
}
|
||||
serviceThread.getLooper().quit();
|
||||
} else {
|
||||
scheduleHeartbeat(delay);
|
||||
|
|
|
@ -213,12 +213,15 @@ public class OsMoTracker implements OsMoReactor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void reconnect() {
|
||||
public void onConnected() {
|
||||
if(autoStart.get() || startSendingLocations) {
|
||||
enableTracker();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisconnected(String msg) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue