diff --git a/OsmAnd/res/drawable-large/mon_osmo_conn_big.png b/OsmAnd/res/drawable-large/mon_osmo_conn_big.png new file mode 100644 index 0000000000..ab803bd6df Binary files /dev/null and b/OsmAnd/res/drawable-large/mon_osmo_conn_big.png differ diff --git a/OsmAnd/res/drawable-large/mon_osmo_conn_signal_big.png b/OsmAnd/res/drawable-large/mon_osmo_conn_signal_big.png new file mode 100644 index 0000000000..86dff7a709 Binary files /dev/null and b/OsmAnd/res/drawable-large/mon_osmo_conn_signal_big.png differ diff --git a/OsmAnd/res/drawable-large/mon_osmo_conn_signal_small.png b/OsmAnd/res/drawable-large/mon_osmo_conn_signal_small.png new file mode 100644 index 0000000000..0a4e057d5f Binary files /dev/null and b/OsmAnd/res/drawable-large/mon_osmo_conn_signal_small.png differ diff --git a/OsmAnd/res/drawable-large/mon_osmo_conn_small.png b/OsmAnd/res/drawable-large/mon_osmo_conn_small.png new file mode 100644 index 0000000000..bd037422c4 Binary files /dev/null and b/OsmAnd/res/drawable-large/mon_osmo_conn_small.png differ diff --git a/OsmAnd/res/layout-v14/check_item.xml b/OsmAnd/res/layout-v14/check_item_rel.xml similarity index 66% rename from OsmAnd/res/layout-v14/check_item.xml rename to OsmAnd/res/layout-v14/check_item_rel.xml index e07aefbd7a..fafd584d05 100644 --- a/OsmAnd/res/layout-v14/check_item.xml +++ b/OsmAnd/res/layout-v14/check_item_rel.xml @@ -1,5 +1,5 @@ - @@ -9,7 +9,6 @@ android:layout_width="wrap_content" android:layout_height="fill_parent" android:focusable="false" - android:gravity="center_vertical" - android:visibility="gone" /> + android:gravity="center_vertical"/> - \ No newline at end of file + \ No newline at end of file diff --git a/OsmAnd/res/layout/check_item.xml b/OsmAnd/res/layout/check_item_rel.xml similarity index 63% rename from OsmAnd/res/layout/check_item.xml rename to OsmAnd/res/layout/check_item_rel.xml index 03db7ddbb4..f3b515724f 100644 --- a/OsmAnd/res/layout/check_item.xml +++ b/OsmAnd/res/layout/check_item_rel.xml @@ -1,15 +1,15 @@ - + android:gravity="center_vertical" /> - \ No newline at end of file + \ No newline at end of file diff --git a/OsmAnd/res/layout/osmo_create_group.xml b/OsmAnd/res/layout/osmo_create_group.xml index 832cd52579..d51a96a2ea 100644 --- a/OsmAnd/res/layout/osmo_create_group.xml +++ b/OsmAnd/res/layout/osmo_create_group.xml @@ -44,6 +44,7 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="3dp" /> + - + \ No newline at end of file diff --git a/OsmAnd/res/layout/osmo_group_item.xml b/OsmAnd/res/layout/osmo_group_item.xml index e60a3f607b..d78af32bc3 100644 --- a/OsmAnd/res/layout/osmo_group_item.xml +++ b/OsmAnd/res/layout/osmo_group_item.xml @@ -8,7 +8,6 @@ android:paddingRight="4dp" android:paddingTop="5dp" > - + android:layout_weight="1" + android:textSize="18sp" > - - + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/osmo_group_list_item.xml b/OsmAnd/res/layout/osmo_group_list_item.xml index 4ed8fa032a..ed651a138c 100644 --- a/OsmAnd/res/layout/osmo_group_list_item.xml +++ b/OsmAnd/res/layout/osmo_group_list_item.xml @@ -24,6 +24,6 @@ android:maxLines="7" android:layout_weight="1" /> - + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 43f88beba7..a43c75873a 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -10,6 +10,7 @@ PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> days + Connect Expires in Description Policy @@ -17,8 +18,8 @@ Device name Group id Group name - Device - Group + Link with device + Link with group Connect to Create group OsMo Server operation failed @@ -28,7 +29,6 @@ hours ago min ago sec ago - Link with device Connected devices OsMo Groups/Devices Automatically start tracker session and send locations after application startup diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java index 36334336d1..050260c379 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroups.java @@ -189,6 +189,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { if(group == null) { group = new OsMoGroup(); group.groupId = gid; + storage.addGroup(group); } parseGroup(obj, group); connectGroupImpl(group); @@ -336,6 +337,7 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener { public String leaveGroup(OsMoGroup group) { final String op = "GROUP_LEAVE:"+group.groupId; + storage.deleteGroup(group); service.pushCommand(op); return op; } diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java index 112242912c..52bfc14e7c 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java @@ -56,8 +56,10 @@ import android.view.WindowManager; 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; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.Spinner; @@ -79,6 +81,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements public static final int CONNECT_TO = 1; protected static final int DELETE_ACTION_ID = 2; public static final int CREATE_GROUP = 3; + protected static final int ON_OFF_ACTION_ID = 4; private static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30; private static final long RECENT_THRESHOLD = 60000; @@ -139,6 +142,34 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements } updateStatus(); + getExpandableListView().setOnGroupClickListener(new OnGroupClickListener() { + @Override + public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { + OsMoGroup gr = adapter.getGroup(groupPosition); + if(gr.isMainGroup()) { + if(parent.isGroupExpanded(groupPosition)) { + parent.collapseGroup(groupPosition); + } else { + parent.expandGroup(groupPosition); + } + } else { + if(selectedObject == gr) { + quitSelectionMode(); + if(parent.isGroupExpanded(groupPosition)) { + parent.collapseGroup(groupPosition); + } else { + parent.expandGroup(groupPosition); + } + } else { + enterSelectionMode(gr); + } + } + if(groupPosition == 0) { + return true; + } + return false; + } + }); } long lastUpdateTime; @@ -218,6 +249,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements app.getLocationProvider().addLocationListener(this); app.getLocationProvider().resumeAllUpdates(); osMoPlugin.getTracker().setUITrackerListener(this); + osMoPlugin.getGroups().setUiListener(this); adapter.synchronizeGroups(); } @@ -228,15 +260,35 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements app.getLocationProvider().removeCompassListener(this); app.getLocationProvider().removeLocationListener(this); osMoPlugin.getTracker().setUITrackerListener(null); + osMoPlugin.getGroups().setUiListener(null); } private void enterSelectionMode(final Object o) { + if(!checkOperationIsNotRunning()) { + return; + } actionMode = startActionMode(new Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { 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); + 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.setOnCheckedChangeListener(new OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + onOffAction(check); + } + }); + mi.setActionView(view); return true; } @@ -268,9 +320,33 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements }); bld.setNegativeButton(R.string.default_buttons_no, null); bld.show(); + } else if(item.getItemId() == ON_OFF_ACTION_ID) { + CompoundButton bt = ((CompoundButton) item.getActionView().findViewById(R.id.check_item)); + onOffAction(bt); } return true; } + + private void onOffAction(CompoundButton bt) { + if((selectedObject instanceof OsMoDevice)) { + OsMoDevice d = (OsMoDevice) selectedObject; + if(bt.isChecked()) { + osMoPlugin.getGroups().connectDevice(d); + } else { + osMoPlugin.getGroups().disconnectDevice(d); + } + } else { + OsMoGroup g = (OsMoGroup) selectedObject; + if(bt.isChecked()) { + String operation = osMoPlugin.getGroups().connectGroup(g); + startLongRunningOperation(operation); + } else { + String operation = osMoPlugin.getGroups().disconnectGroup(g); + startLongRunningOperation(operation); + } + } + quitSelectionMode(); + } }); } @@ -287,6 +363,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements } String operation = osMoPlugin.getGroups().leaveGroup((OsMoGroup) selectedObject); startLongRunningOperation(operation); + adapter.notifyDataSetChanged(); } @@ -294,9 +371,9 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - OsMoDevice user = adapter.getChild(groupPosition, childPosition); - if (user != selectedObject) { - enterSelectionMode(user); + OsMoDevice model = adapter.getChild(groupPosition, childPosition); + if (model != selectedObject) { + enterSelectionMode(model); } else { quitSelectionMode(); } @@ -509,10 +586,10 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements @Override public int compare(OsMoGroup lhs, OsMoGroup rhs) { if (lhs.isMainGroup()) { - return 1; + return -1; } if (rhs.isMainGroup()) { - return -1; + return 1; } return clt.compare(lhs.getVisibleName(OsMoGroupsActivity.this), rhs.getVisibleName(OsMoGroupsActivity.this)); @@ -562,7 +639,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements } @Override - public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { + public View getGroupView(final int groupPosition, final boolean isExpanded, View convertView, ViewGroup parent) { View row = convertView; if (row == null) { LayoutInflater inflater = getLayoutInflater(); @@ -584,33 +661,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements } else { label.setTypeface(Typeface.DEFAULT, Typeface.ITALIC); } - final CompoundButton ch = (CompoundButton) row.findViewById(R.id.check_item); - ch.setVisibility(model.isMainGroup() ? View.INVISIBLE : View.VISIBLE); - ch.setOnCheckedChangeListener(null); - 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) { - String operation = osMoPlugin.getGroups().connectGroup(model); - startLongRunningOperation(operation); - } else { - String operation = osMoPlugin.getGroups().disconnectGroup(model); - startLongRunningOperation(operation); - } - } - }); - return row; } @@ -631,27 +681,25 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements } TextView label = (TextView) row.findViewById(R.id.osmo_label); 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); - } - - +// 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(); @@ -704,6 +752,8 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements return row; } + + } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoTracker.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoTracker.java index 69486f247a..96ec21ad6b 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoTracker.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoTracker.java @@ -135,7 +135,7 @@ public class OsMoTracker implements OsMoSender, OsMoReactor { float lat = 0; float lon = 0; float speed = 0; - int k = 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) == '.';