Show status in activity
This commit is contained in:
parent
c8012c6431
commit
941dc8b522
10 changed files with 372 additions and 118 deletions
|
@ -7,6 +7,13 @@
|
|||
android:layout_marginRight="5dp"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/osmo_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingLeft="6dp"
|
||||
android:src="@drawable/mon_osmo_conn_small" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/motd"
|
||||
|
|
|
@ -1,17 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="3dp"
|
||||
android:paddingRight="3dp" android:stretchColumns="1">
|
||||
<TableRow >
|
||||
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:text="@string/osmo_connect_to_device_tracker_id"/>
|
||||
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="3dp"
|
||||
android:id="@+id/TrackerId" android:inputType="textCapCharacters" android:selectAllOnFocus="true"/>
|
||||
</TableRow>
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="3dp"
|
||||
android:paddingRight="3dp"
|
||||
android:stretchColumns="1" >
|
||||
|
||||
<TableRow>
|
||||
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:text="@string/osmo_connect_to_device_name"/>
|
||||
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="3dp"
|
||||
android:id="@+id/Name" android:inputType="textCapWords" />
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_span="2" >
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/ConnectToDevice"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/osmo_connect_to_device" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/ConnectToGroup"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/osmo_connect_to_group" />
|
||||
</RadioGroup>
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/LabelTrackerId"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/osmo_connect_to_device_tracker_id" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/TrackerId"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textCapCharacters"
|
||||
android:paddingLeft="3dp"
|
||||
android:selectAllOnFocus="true" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/LabelName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/osmo_connect_to_device_name" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/Name"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textCapWords"
|
||||
android:paddingLeft="3dp" />
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
|
@ -7,6 +7,14 @@
|
|||
android:layout_marginRight="5dp"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/osmo_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingLeft="6dp"
|
||||
android:src="@drawable/mon_osmo_conn_small" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/motd"
|
||||
android:layout_marginBottom="8dip"
|
||||
|
|
|
@ -9,17 +9,22 @@
|
|||
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_connect_to_device_tracker_id">Tracker id</string>
|
||||
<string name="osmo_connect_to_device_name">Device name</string>
|
||||
<string name="osmo_connect_to_group_id">Group id</string>
|
||||
<string name="osmo_connect_to_group_name">Group name</string>
|
||||
<string name="osmo_connect_to_device">Device</string>
|
||||
<string name="osmo_connect_to_group">Group</string>
|
||||
<string name="osmo_connect">Connect to</string>
|
||||
<string name="osmo_create_group">Create group</string>
|
||||
<string name="osmo_server_operation_failed">OsMo Server operation failed</string>
|
||||
<string name="osmo_activity">Osm Monitoring</string>
|
||||
<string name="osmo_enable_tracker">Send my locations</string>
|
||||
<string name="osmo_control">OsMo quick access</string>
|
||||
<string name="hours_ago">hours ago</string>
|
||||
<string name="minutes_ago">min ago</string>
|
||||
<string name="seconds_ago">sec ago</string>
|
||||
<string name="osmo_connect_to_device_name">Name of device</string>
|
||||
<string name="osmo_connect_to_device_tracker_id">Tracker id</string>
|
||||
<string name="osmo_connect_to_device">Link with device</string>
|
||||
<string name="osmo_join_group">Join group</string>
|
||||
<string name="osmo_new_device">Connect to device</string>
|
||||
<string name="osmo_connected_devices">Connected devices</string>
|
||||
<string name="osmo_groups">OsMo Groups/Devices</string>
|
||||
<string name="osmo_auto_send_locations_descr">Automatically start tracker session and send locations after application startup</string>
|
||||
|
|
|
@ -36,7 +36,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
|
||||
public interface OsMoGroupsUIListener {
|
||||
|
||||
public void groupsListChange(String operation);
|
||||
public void groupsListChange(String operation, OsMoGroup group);
|
||||
}
|
||||
|
||||
public OsMoGroups(OsMoService service, OsMoTracker tracker, OsmandSettings settings) {
|
||||
|
@ -135,11 +135,12 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
public boolean acceptCommand(String command, String data, JSONObject obj, OsMoThread thread) {
|
||||
boolean processed = false;
|
||||
String operation = command;
|
||||
OsMoGroup group = null;
|
||||
if(command.startsWith("GROUP_CHANGE:")) {
|
||||
String gid = command.substring(command.indexOf(':') + 1);
|
||||
OsMoGroup gr = storage.getGroup(gid);
|
||||
if(gr != null) {
|
||||
List<OsMoDevice> delta = mergeGroup(gr, obj, false);
|
||||
group = storage.getGroup(gid);
|
||||
if(group != null) {
|
||||
List<OsMoDevice> delta = mergeGroup(group, obj, false);
|
||||
for(OsMoDevice d :delta) {
|
||||
if(d.getDeletedTimestamp() != 0 && d.isEnabled()) {
|
||||
disconnectImpl(d);
|
||||
|
@ -152,17 +153,17 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
processed = true;
|
||||
} else if(command.startsWith("GROUP_DISCONNECT:")) {
|
||||
String gid = command.substring(command.indexOf(':') + 1);
|
||||
OsMoGroup gr = storage.getGroup(gid);
|
||||
if(gr != null) {
|
||||
disconnectAllGroupUsers(gr);
|
||||
group = storage.getGroup(gid);
|
||||
if(group != null) {
|
||||
disconnectAllGroupUsers(group);
|
||||
}
|
||||
processed = true;
|
||||
} else if(command.startsWith("GROUP_CONNECT:")) {
|
||||
String gid = command.substring(command.indexOf(':') + 1);
|
||||
OsMoGroup gr = storage.getGroup(gid);
|
||||
if(gr != null) {
|
||||
mergeGroup(gr, obj, true);
|
||||
gr.active = true;
|
||||
group = storage.getGroup(gid);
|
||||
if(group != null) {
|
||||
mergeGroup(group, obj, true);
|
||||
group.active = true;
|
||||
// connect to all devices in group
|
||||
for(OsMoDevice d : storage.getMainGroup().getGroupUsers()) {
|
||||
connectDeviceImpl(d);
|
||||
|
@ -170,32 +171,32 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
storage.save();
|
||||
}
|
||||
processed = true;
|
||||
} else if(command.startsWith("GROUP_CREATE:") || command.startsWith("GROUP_JOIN:") ) {
|
||||
if(command.startsWith("GROUP_CREATE:")) {
|
||||
operation = "GROUP_CREATE";
|
||||
} else if(command.startsWith("AGROUP_CREATE:") || command.startsWith("GROUP_JOIN:") ) {
|
||||
if(command.startsWith("AGROUP_CREATE:")) {
|
||||
operation = "AGROUP_CREATE";
|
||||
}
|
||||
String gid = command.substring(command.indexOf(':') + 1);
|
||||
OsMoGroup gr = storage.getGroup(gid);
|
||||
if(gr == null) {
|
||||
gr = new OsMoGroup();
|
||||
gr.groupId = gid;
|
||||
group = storage.getGroup(gid);
|
||||
if(group == null) {
|
||||
group = new OsMoGroup();
|
||||
group.groupId = gid;
|
||||
}
|
||||
parseGroup(obj, gr);
|
||||
connectGroupImpl(gr);
|
||||
parseGroup(obj, group);
|
||||
connectGroupImpl(group);
|
||||
storage.save();
|
||||
processed = true;
|
||||
} else if(command.startsWith("LEAVE_GROUP:")) {
|
||||
String gid = command.substring(command.indexOf(':') + 1);
|
||||
OsMoGroup gr = storage.getGroup(gid);
|
||||
if(gr != null) {
|
||||
disconnectAllGroupUsers(gr);
|
||||
storage.deleteGroup(gr);
|
||||
group = storage.getGroup(gid);
|
||||
if(group != null) {
|
||||
disconnectAllGroupUsers(group);
|
||||
storage.deleteGroup(group);
|
||||
storage.save();
|
||||
}
|
||||
processed = true;
|
||||
}
|
||||
if(processed && uiListener != null) {
|
||||
uiListener.groupsListChange(operation);
|
||||
uiListener.groupsListChange(operation, group);
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
@ -284,14 +285,21 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
|
|||
obj.put("expireTime", expireTime);
|
||||
obj.put("description", description);
|
||||
obj.put("policy", policy);
|
||||
service.pushCommand("GROUP_CREATE|" + obj.toString());
|
||||
return "GROUP_CREATE";
|
||||
service.pushCommand("AGROUP_CREATE|" + obj.toString());
|
||||
return "AGROUP_CREATE";
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteDevice(OsMoDevice device) {
|
||||
storage.getMainGroup().users.remove(device.trackerId);
|
||||
if(device.isEnabled()) {
|
||||
disconnectImpl(device);
|
||||
}
|
||||
storage.save();
|
||||
}
|
||||
|
||||
public OsMoDevice addConnectedDevice(String trackerId, String nameUser, int userColor) {
|
||||
OsMoDevice us = new OsMoDevice();
|
||||
|
|
|
@ -7,12 +7,9 @@ import java.text.Collator;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -25,10 +22,12 @@ import net.osmand.plus.OsmandPlugin;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.OsmandExpandableListActivity;
|
||||
import net.osmand.plus.osmo.OsMoGroups.OsMoGroup;
|
||||
import net.osmand.plus.osmo.OsMoGroups.OsMoUser;
|
||||
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 net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
|
@ -38,9 +37,9 @@ import android.graphics.Canvas;
|
|||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -52,30 +51,30 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.actionbarsherlock.view.ActionMode;
|
||||
import com.actionbarsherlock.view.ActionMode.Callback;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.actionbarsherlock.view.Window;
|
||||
import com.actionbarsherlock.view.ActionMode.Callback;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class OsMoGroupsActivity extends OsmandExpandableListActivity implements OsmAndCompassListener,
|
||||
OsmAndLocationListener, OsmoTrackerListener {
|
||||
OsmAndLocationListener, OsmoTrackerListener, OsMoGroupsUIListener {
|
||||
|
||||
public static final int CONNECT_TO_DEVICE = 1;
|
||||
public static final int CONNECT_TO = 1;
|
||||
protected static final int DELETE_ACTION_ID = 2;
|
||||
public static final int CREATE_GROUP = 3;
|
||||
public static final int JOIN_GROUP = 4;
|
||||
private static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30;
|
||||
private static final long RECENT_THRESHOLD = 60000;
|
||||
|
||||
|
@ -91,8 +90,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
private Location lastLocation;
|
||||
private float lastCompass;
|
||||
private ActionMode actionMode;
|
||||
private boolean selectionMode;
|
||||
private Set<OsMoDevice> selectedObjects = new HashSet<OsMoGroups.OsMoDevice>();
|
||||
private Object selectedObject = null;
|
||||
private String operation;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
@ -124,6 +123,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
} else {
|
||||
osMoPlugin.getTracker().disableTracker();
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
TextView mtd = (TextView) findViewById(R.id.motd);
|
||||
|
@ -133,6 +133,49 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
if(visible) {
|
||||
mtd.setText(si.motd);
|
||||
}
|
||||
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
long lastUpdateTime;
|
||||
private Drawable blinkImg;
|
||||
private void blink(final ImageView status, Drawable bigger, final Drawable smaller ) {
|
||||
blinkImg = smaller;
|
||||
status.setImageDrawable(bigger);
|
||||
status.invalidate();
|
||||
uiHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
blinkImg = null;
|
||||
status.setImageDrawable(smaller);
|
||||
status.invalidate();
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
private void updateStatus() {
|
||||
ImageView status = (ImageView) findViewById(R.id.osmo_status);
|
||||
final Drawable srcSmall = getResources().getDrawable(R.drawable.mon_osmo_conn_small);
|
||||
final Drawable srcSignalSmall = getResources().getDrawable(R.drawable.mon_osmo_conn_signal_small);
|
||||
final Drawable srcBig = getResources().getDrawable(R.drawable.mon_osmo_conn_big);
|
||||
final Drawable srcSignalBig = getResources().getDrawable(R.drawable.mon_osmo_conn_signal_big);
|
||||
final Drawable srcinactive = getResources().getDrawable(R.drawable.monitoring_rec_inactive);
|
||||
Drawable small = srcinactive;
|
||||
Drawable big = srcinactive;
|
||||
OsMoService service = osMoPlugin.getService();
|
||||
OsMoTracker tracker = osMoPlugin.getTracker();
|
||||
long last = service.getLastCommandTime();
|
||||
if (service.isActive()) {
|
||||
small = tracker.isEnabledTracker() ? srcSignalSmall : srcSmall;
|
||||
big = tracker.isEnabledTracker() ? srcSignalBig : srcBig;
|
||||
}
|
||||
if (blinkImg != small) {
|
||||
status.setImageDrawable(small);
|
||||
}
|
||||
if (last != lastUpdateTime) {
|
||||
lastUpdateTime = last;
|
||||
blink(status, big, small);
|
||||
}
|
||||
}
|
||||
|
||||
private Path createDirectionPath() {
|
||||
|
@ -183,11 +226,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
osMoPlugin.getTracker().setUITrackerListener(null);
|
||||
}
|
||||
|
||||
private void enterSelectionMode() {
|
||||
private void enterSelectionMode(final Object o) {
|
||||
actionMode = startActionMode(new Callback() {
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
selectionMode = true;
|
||||
selectedObject = o;
|
||||
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);
|
||||
return true;
|
||||
|
@ -200,12 +243,27 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
selectionMode = false;
|
||||
selectedObject = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
if(item.getItemId() == DELETE_ACTION_ID) {
|
||||
if(item.getItemId() == DELETE_ACTION_ID ) {
|
||||
Builder bld = new AlertDialog.Builder(OsMoGroupsActivity.this);
|
||||
String name = (selectedObject instanceof OsMoDevice)? ((OsMoDevice) selectedObject).getVisibleName() :
|
||||
((OsMoGroup) selectedObject).getVisibleName(OsMoGroupsActivity.this);
|
||||
bld.setTitle(getString(R.string.delete_confirmation_msg, name));
|
||||
bld.setPositiveButton(R.string .default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Object obj = selectedObject;
|
||||
quitSelectionMode();
|
||||
deleteObject(obj);
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.default_buttons_no, null);
|
||||
bld.show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -213,42 +271,99 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
|
||||
}
|
||||
|
||||
protected void deleteObject(Object selectedObject) {
|
||||
if(selectedObject instanceof OsMoDevice) {
|
||||
OsMoDevice d = (OsMoDevice)selectedObject;
|
||||
osMoPlugin.getGroups().deleteDevice(d);
|
||||
adapter.update(d.getGroup());
|
||||
adapter.notifyDataSetChanged();
|
||||
} else {
|
||||
if (checkOperationIsNotRunning()) {
|
||||
String operation = osMoPlugin.getGroups().leaveGroup((OsMoGroup) selectedObject);
|
||||
startLongRunningOperation(operation);
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
if (!selectionMode) {
|
||||
enterSelectionMode();
|
||||
}
|
||||
OsMoDevice user = adapter.getChild(groupPosition, childPosition);
|
||||
selectedObjects.add(user);
|
||||
if (user != selectedObject) {
|
||||
enterSelectionMode(user);
|
||||
} else {
|
||||
quitSelectionMode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void quitSelectionMode() {
|
||||
selectedObject = null;
|
||||
actionMode.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
|
||||
if (item.getItemId() == CONNECT_TO_DEVICE) {
|
||||
if (item.getItemId() == CONNECT_TO) {
|
||||
connectToDevice();
|
||||
return true;
|
||||
} else if (item.getItemId() == JOIN_GROUP) {
|
||||
// shareFavourites();
|
||||
} else if (item.getItemId() == CREATE_GROUP) {
|
||||
createGroup();
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void createGroup() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private void connectToDevice() {
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.osmo_connect_to_device);
|
||||
final View v = getLayoutInflater().inflate(R.layout.osmo_connect_to_device, getExpandableListView(), false);
|
||||
final RadioButton device = (RadioButton) v.findViewById(R.id.ConnectToDevice);
|
||||
//final RadioButton group = (RadioButton) v.findViewById(R.id.ConnectToGroup);
|
||||
final TextView labelTracker = (TextView ) v.findViewById(R.id.LabelTrackerId);
|
||||
final TextView labelName = (TextView ) v.findViewById(R.id.LabelName);
|
||||
final EditText tracker = (EditText) v.findViewById(R.id.TrackerId);
|
||||
final EditText name = (EditText) v.findViewById(R.id.Name);
|
||||
device.setChecked(true);
|
||||
device.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if(isChecked) {
|
||||
labelTracker.setText(R.string.osmo_connect_to_device_tracker_id);
|
||||
labelName.setText(R.string.osmo_connect_to_device_name);
|
||||
} else {
|
||||
labelTracker.setText(R.string.osmo_connect_to_group_id);
|
||||
labelName.setText(R.string.osmo_connect_to_group_name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
builder.setView(v);
|
||||
builder.setNegativeButton(R.string.default_buttons_cancel, null);
|
||||
builder.setPositiveButton(R.string.default_buttons_apply, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String nameUser = name.getText().toString();
|
||||
adapter.registerUser(tracker.getText().toString(), nameUser);
|
||||
final String nameUser = name.getText().toString();
|
||||
final String id = tracker.getText().toString();
|
||||
if(device.isChecked()) {
|
||||
OsMoDevice dev = osMoPlugin.getGroups().addConnectedDevice(id, nameUser, 0);
|
||||
adapter.update(dev.group);
|
||||
adapter.notifyDataSetChanged();
|
||||
} else {
|
||||
if(!checkOperationIsNotRunning()) {
|
||||
return;
|
||||
}
|
||||
String op = osMoPlugin.getGroups().joinGroup(id, nameUser);
|
||||
startLongRunningOperation(op);
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
|
@ -257,25 +372,62 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
|
||||
createMenuItem(menu, CONNECT_TO_DEVICE, R.string.osmo_new_device, R.drawable.ic_action_marker_light,
|
||||
R.drawable.ic_action_marker_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
createMenuItem(menu, JOIN_GROUP, R.string.osmo_join_group, R.drawable.ic_action_markers_light,
|
||||
R.drawable.ic_action_markers_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
createMenuItem(menu, CONNECT_TO, R.string.osmo_connect,
|
||||
0, 0,/*R.drawable.ic_action_marker_light,*/
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
createMenuItem(menu, CREATE_GROUP, R.string.osmo_create_group,
|
||||
0, 0,/*R.drawable.ic_action_marker_light,*/
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
public void showProgressBar() {
|
||||
public void startLongRunningOperation(String operation) {
|
||||
this.operation = operation;
|
||||
setSupportProgressBarIndeterminateVisibility(true);
|
||||
uiHandler.postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(OsMoGroupsActivity.this, R.string.osmo_server_operation_failed, Toast.LENGTH_LONG).show();
|
||||
hideProgressBar();
|
||||
}
|
||||
}, 15000);
|
||||
}
|
||||
|
||||
public void hideProgressBar() {
|
||||
OsMoGroupsActivity.this.operation = null;
|
||||
setSupportProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void groupsListChange(final String operation, final OsMoGroup group) {
|
||||
uiHandler.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String top = OsMoGroupsActivity.this.operation;
|
||||
if(operation == top || (operation != null && operation.equals(top))) {
|
||||
hideProgressBar();
|
||||
}
|
||||
adapter.update(group);
|
||||
adapter.notifyDataSetChanged();
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean checkOperationIsNotRunning() {
|
||||
if(operation != null) {
|
||||
Toast.makeText(this, R.string.wait_current_task_finished, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
class OsMoGroupsAdapter extends OsmandBaseExpandableListAdapter {
|
||||
|
||||
private List<OsMoGroup> sortedGroups = new ArrayList<OsMoGroups.OsMoGroup>();
|
||||
private Map<OsMoGroup, List<OsMoDevice>> users = new LinkedHashMap<OsMoGroups.OsMoGroup, List<OsMoDevice>>();
|
||||
private List<OsMoGroup> sortedGroups = new ArrayList<OsMoGroup>();
|
||||
private Map<OsMoGroup, List<OsMoDevice>> users = new LinkedHashMap<OsMoGroup, List<OsMoDevice>>();
|
||||
private OsMoGroups grs;
|
||||
private OsMoTracker tracker;
|
||||
|
||||
|
@ -285,43 +437,38 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
synchronizeGroups();
|
||||
}
|
||||
|
||||
public void registerUser(String trackerId, String nameUser) {
|
||||
addUser(grs.registerUser(trackerId, nameUser));
|
||||
}
|
||||
public void update(OsMoGroup group) {
|
||||
if(group.isDeleted()) {
|
||||
sortedGroups.remove(group);
|
||||
users.remove(group);
|
||||
} else {
|
||||
List<OsMoDevice> us = !group.isEnabled() && !group.isMainGroup() ? new ArrayList<OsMoDevice>(0) : group.getGroupUsers();
|
||||
final Collator ci = Collator.getInstance();
|
||||
Collections.sort(us, new Comparator<OsMoDevice>() {
|
||||
|
||||
public void sort(Comparator<OsMoDevice> comparator) {
|
||||
for (List<OsMoDevice> ps : users.values()) {
|
||||
Collections.sort(ps, comparator);
|
||||
@Override
|
||||
public int compare(OsMoDevice lhs, OsMoDevice rhs) {
|
||||
return ci.compare(lhs.getVisibleName(), rhs.getVisibleName());
|
||||
}
|
||||
});
|
||||
users.put(group, us);
|
||||
if(!sortedGroups.contains(group)) {
|
||||
sortedGroups.add(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addUser(OsMoDevice p) {
|
||||
if (!users.containsKey(p.getGroup())) {
|
||||
users.put(p.getGroup(), new ArrayList<OsMoDevice>());
|
||||
sortedGroups.add(p.getGroup());
|
||||
}
|
||||
users.get(p.getGroup()).add(p);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
public void synchronizeGroups() {
|
||||
users.clear();
|
||||
sortedGroups.clear();
|
||||
final Collator clt = Collator.getInstance();
|
||||
for (OsMoGroup key : grs.getGroups().values()) {
|
||||
for (OsMoGroup key : grs.getGroups()) {
|
||||
sortedGroups.add(key);
|
||||
final ArrayList<OsMoDevice> list = new ArrayList<OsMoDevice>(key.users.values());
|
||||
Collections.sort(list, new Comparator<OsMoGroups.OsMoDevice>() {
|
||||
|
||||
@Override
|
||||
public int compare(OsMoDevice lhs, OsMoDevice rhs) {
|
||||
return clt.compare(lhs.getVisibleName(), rhs.getVisibleName());
|
||||
update(key);
|
||||
}
|
||||
});
|
||||
users.put(key, list);
|
||||
}
|
||||
Collections.sort(sortedGroups, new Comparator<OsMoGroups.OsMoGroup>() {
|
||||
|
||||
Collections.sort(sortedGroups, new Comparator<OsMoGroup>() {
|
||||
@Override
|
||||
public int compare(OsMoGroup lhs, OsMoGroup rhs) {
|
||||
if (lhs.isMainGroup()) {
|
||||
|
@ -398,13 +545,24 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
ch.setVisibility(model.isMainGroup() ? View.INVISIBLE : View.VISIBLE);
|
||||
ch.setChecked(model.enabled);
|
||||
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
boolean revert = false;
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if(revert) {
|
||||
revert = false;
|
||||
return;
|
||||
}
|
||||
if(checkOperationIsNotRunning()) {
|
||||
revert = true;
|
||||
ch.setChecked(!isChecked);
|
||||
return;
|
||||
}
|
||||
if(isChecked) {
|
||||
osMoPlugin.getGroups().connectGroup(model);
|
||||
String operation = osMoPlugin.getGroups().connectGroup(model);
|
||||
startLongRunningOperation(operation);
|
||||
} else {
|
||||
osMoPlugin.getGroups().disconnectGroup(model);
|
||||
String operation = osMoPlugin.getGroups().disconnectGroup(model);
|
||||
startLongRunningOperation(operation);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -446,7 +604,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
|
||||
|
||||
LatLon lnLocation = mapLocation;
|
||||
Location location = tracker.getLastLocation(model.trackerId);
|
||||
Location location = model.getLastLocation();
|
||||
if(model.getTrackerId().equals(osMoPlugin.getService().getMyGroupTrackerId())) {
|
||||
location = tracker.getLastSendLocation();
|
||||
}
|
||||
//Location location = tracker.getLastLocation(model.trackerId);
|
||||
if (location == null || lnLocation == null) {
|
||||
icon.setImageResource(R.drawable.list_favorite);
|
||||
label.setText(model.getVisibleName());
|
||||
|
@ -505,6 +667,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
@Override
|
||||
public void run() {
|
||||
adapter.notifyDataSetChanged();
|
||||
updateStatus();
|
||||
}
|
||||
});
|
||||
msg.what = LIST_REFRESH_MSG_ID;
|
||||
|
@ -564,4 +727,5 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -203,6 +203,7 @@ public class OsMoGroupsStorage {
|
|||
protected boolean enabled;
|
||||
protected long expireTime;
|
||||
protected boolean active;
|
||||
protected boolean deleted;
|
||||
|
||||
protected Map<String, OsMoDevice> users = new ConcurrentHashMap<String, OsMoDevice>();
|
||||
|
||||
|
@ -217,6 +218,10 @@ public class OsMoGroupsStorage {
|
|||
return dvs;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
@ -370,10 +375,12 @@ public class OsMoGroupsStorage {
|
|||
|
||||
public void deleteGroup(OsMoGroup gr) {
|
||||
groups.remove(gr.groupId);
|
||||
gr.deleted = true;
|
||||
}
|
||||
|
||||
public void addGroup(OsMoGroup g) {
|
||||
groups.put(g.groupId, g);
|
||||
g.deleted = false;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -37,10 +37,6 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
public OsMoPlugin(final OsmandApplication app) {
|
||||
service = new OsMoService(app);
|
||||
tracker = new OsMoTracker(service);
|
||||
if(app.getSettings().OSMO_AUTO_SEND_LOCATIONS.get()) {
|
||||
tracker.enableTracker();
|
||||
}
|
||||
groups = new OsMoGroups(service, tracker, app.getSettings());
|
||||
this.app = app;
|
||||
ApplicationMode.regWidget("osmo_control", (ApplicationMode[])null);
|
||||
}
|
||||
|
@ -48,6 +44,10 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
@Override
|
||||
public boolean init(final OsmandApplication app) {
|
||||
service.connect(true);
|
||||
if(app.getSettings().OSMO_AUTO_SEND_LOCATIONS.get()) {
|
||||
tracker.enableTracker();
|
||||
}
|
||||
groups = new OsMoGroups(service, tracker, app.getSettings());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -243,6 +244,13 @@ public class OsMoService implements OsMoSender, OsMoReactor {
|
|||
if(command.equals("MOTD")) {
|
||||
SessionInfo si = getCurrentSessionInfo();
|
||||
if(si != null) {
|
||||
if(data.startsWith("[")){
|
||||
try {
|
||||
data = new JSONArray(data).getString(0);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
si.motd = data;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.osmand.PlatformUtil;
|
|||
import net.osmand.plus.osmo.OsMoService.SessionInfo;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
|
Loading…
Reference in a new issue