Update ui to have selection and select individual users to track

This commit is contained in:
Victor Shcherb 2014-06-01 23:45:17 +02:00
parent 6857b98523
commit 92f3624d29
4 changed files with 76 additions and 51 deletions

View file

@ -8,6 +8,8 @@
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:focusable="false"
android:gravity="center_vertical"/>

View file

@ -9,6 +9,10 @@
android:text="@string/osmo_connect_menu"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:focusable="false"
android:gravity="center_vertical" />

View file

@ -4,7 +4,7 @@
android:layout_height="wrap_content"
android:background="?attr/expandable_category_color"
android:paddingBottom="5dp"
android:paddingLeft="4dp"
android:paddingLeft="3dp"
android:paddingRight="4dp"
android:paddingTop="5dp" >
@ -14,7 +14,8 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="6dp"
android:src="@drawable/expandable_category_unpushed" />
android:src="@drawable/expandable_category_unpushed" />
<TextView
android:id="@+id/category_name"
@ -23,25 +24,18 @@
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:textSize="18sp" >
</TextView>
<!--
<RelativeLayout
<include layout="@layout/check_item_rel"/>
<ImageButton
android:src="@drawable/ic_action_settings_dark" android:id="@+id/settings"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical" >
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:focusable="false"
/>
<CheckBox
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:focusable="false"
android:gravity="center_vertical" />
</RelativeLayout>
-->
</LinearLayout>

View file

@ -36,6 +36,8 @@ 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.util.MapAlgorithms;
import net.osmand.util.MapUtils;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
@ -203,34 +205,6 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
white.setAntiAlias(true);
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;
@ -339,7 +313,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
device = (OsMoDevice) (o instanceof OsMoDevice ?o : null);
group = (OsMoGroup) (o instanceof OsMoGroup ?o : null);
MenuItem mi = null;
if(device == null || device.getGroup().isMainGroup()) {
if(device != null) {
mi = createMenuItem(menu, ON_OFF_ACTION_ID, R.string.default_buttons_ok, 0, 0,
MenuItem.SHOW_AS_ACTION_ALWAYS);
}
@ -929,6 +903,40 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
} else {
label.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
}
View v = row.findViewById(R.id.settings);
if(model.isMainGroup()) {
v.setVisibility(View.GONE);
} else {
v.setVisibility(View.VISIBLE);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
enterSelectionMode(model);
}
});
}
CompoundButton ci = (CompoundButton) row.findViewById(R.id.check_item);
if(model.isMainGroup()) {
ci.setVisibility(View.GONE);
} else {
ci.setVisibility(View.VISIBLE);
ci.setOnCheckedChangeListener(null);
ci.setChecked(model.isEnabled() && model.isActive());
ci.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
String operation = osMoPlugin.getGroups().connectGroup(model);
startLongRunningOperation(operation);
} else {
String operation = osMoPlugin.getGroups().disconnectGroup(model);
startLongRunningOperation(operation);
}
}
});
}
return row;
}
@ -961,17 +969,25 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
osMoPlugin.getGroups().setGenColor(model, activeColor);
}
//Location location = tracker.getLastLocation(model.trackerId);
if (location == null || mapLocation == null) {
if(model.isEnabled()) {
icon.setVisibility(View.INVISIBLE);
label.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
label.setText(model.getVisibleName());
} else if (location == null || mapLocation == null) {
label.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
icon.setVisibility(View.VISIBLE);
NonDirectionDrawable draw ;
if(icon.getDrawable() instanceof NonDirectionDrawable) {
draw = (NonDirectionDrawable) icon.getDrawable();
} else {
draw = new NonDirectionDrawable();
}
draw.setColor(model.isEnabled()?activeColor : color);
draw.setColor(model.isEnabled() ? activeColor : color);
icon.setImageDrawable(draw);
label.setText(model.getVisibleName());
} else {
label.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
icon.setVisibility(View.VISIBLE);
DirectionDrawable draw;
if (icon.getDrawable() instanceof DirectionDrawable) {
draw = (DirectionDrawable) icon.getDrawable();
@ -1022,8 +1038,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
public void updateLocation(Location location) {
MapViewTrackingUtilities mv = MapActivity.getMapViewTrackingUtilities();
if(mv != null && mv.isMapLinkedToLocation() && location != null) {
Location lt = mapLocation;
mapLocation = location;
adapter.notifyDataSetInvalidated();
if(lt == null || location.distanceTo(lt) > 8) {
refreshList();
}
}
}
@ -1033,8 +1052,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
@Override
public void updateCompassValue(float value) {
float vl = lastCompass;
lastCompass = value;
refreshList();
if(Math.abs(MapUtils.degreesDiff(vl, value)) > 15) {
refreshList();
}
}
private void refreshList() {
@ -1042,7 +1064,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
Message msg = Message.obtain(uiHandler, new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
adapter.notifyDataSetInvalidated();
updateStatus();
}
});
@ -1051,10 +1073,13 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
}
@Override
public void deviceLocationChanged(OsMoDevice device) {
refreshList();
}
public static String colorToString(int color) {
if ((0xFF000000 & color) == 0xFF000000) {
return "#" + Integer.toHexString(color & 0x00FFFFFF); //$NON-NLS-1$