Update selection & colors

This commit is contained in:
vshcherb 2014-05-24 20:04:43 +02:00
parent 941dc8b522
commit 3a28293fe1
14 changed files with 232 additions and 61 deletions

View file

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical" >
<Switch
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="fill_parent"
android:focusable="false"
android:gravity="center_vertical"
android:visibility="gone" />

View file

@ -7,29 +7,35 @@
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"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dip"
android:gravity="center"
android:textSize="18sp" />
<Switch
android:id="@+id/enable_tracker"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center_vertical"
android:text="@string/osmo_enable_tracker" />
android:orientation="horizontal" >
<ImageView
android:id="@+id/osmo_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:src="@drawable/mon_osmo_conn_small" />
<Switch
android:id="@+id/enable_tracker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center_vertical"
android:text="@string/osmo_enable_tracker" />
</LinearLayout>
</LinearLayout>

View file

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical" >
<CheckBox
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="fill_parent"
android:focusable="false"
android:gravity="center_vertical"
android:visibility="gone" />

View file

@ -0,0 +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_group_name" />
<EditText
android:id="@+id/Name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="3dp" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/osmo_group_description" />
<EditText
android:id="@+id/Description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="3"
android:paddingLeft="3dp" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/osmo_expire_group" />
<Spinner
android:id="@+id/ExpireGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="3dp" />
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/osmo_group_policy" />
<EditText
android:id="@+id/Policy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="2"
android:paddingLeft="3dp" />
</TableRow>
</TableRow>
</TableLayout>

View file

@ -6,29 +6,36 @@
android:layout_marginLeft="5dp"
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"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dip"
android:gravity="center"
android:textSize="18sp" />
<CheckBox
android:id="@+id/enable_tracker"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center_vertical"
android:text="@string/osmo_enable_tracker" />
android:orientation="horizontal" >
<ImageView
android:id="@+id/osmo_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:src="@drawable/mon_osmo_conn_small" />
<CheckBox
android:id="@+id/enable_tracker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center_vertical"
android:text="@string/osmo_enable_tracker" />
</LinearLayout>
</LinearLayout>

View file

@ -13,6 +13,8 @@
<color name="color_white">#FFFFFF</color>
<color name="color_black">#000000</color>
<color name="row_selection_color">#CC33BBE0</color>
<!-- Themed color list items -->
<!-- invalid -red, localindex not supported, -->
<color name="color_invalid">#EE3232</color>

View file

@ -9,10 +9,14 @@
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="int_days">days</string>
<string name="osmo_expire_group">Expires in</string>
<string name="osmo_group_description">Description</string>
<string name="osmo_group_policy">Policy</string>
<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_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>

View file

@ -830,6 +830,8 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> OSMO_AUTO_SEND_LOCATIONS = new BooleanPreference("osmo_automatically_send_locations", false).makeGlobal();
public final CommonPreference<Integer> OSMO_SAVE_TRACK_INTERVAL = new IntPreference("osmo_save_track_interval", 3000).makeGlobal().cache();
public final OsmandPreference<String> OSMO_GROUPS = new StringPreference("osmo_groups", "{}").makeGlobal();
// this value string is synchronized with settings_pref.xml preference name

View file

@ -19,6 +19,7 @@ import org.json.JSONObject;
public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
private static final String GROUP_NAME = "name";
private static final String GROUP_ID = "group_id";
private static final String EXPIRE_TIME = "expireTime";
private static final String DESCRIPTION = "description";
private static final String POLICY = "policy";
@ -171,11 +172,19 @@ public class OsMoGroups implements OsMoReactor, OsmoTrackerListener {
storage.save();
}
processed = true;
} else if(command.startsWith("AGROUP_CREATE:") || command.startsWith("GROUP_JOIN:") ) {
if(command.startsWith("AGROUP_CREATE:")) {
operation = "AGROUP_CREATE";
} else if(command.startsWith("AGROUP_CREATE") || command.startsWith("GROUP_JOIN:") ) {
String gid ;
if(command.startsWith("AGROUP_CREATE")) {
try {
gid = obj.getString(GROUP_ID);
} catch (JSONException e) {
e.printStackTrace();
service.showErrorMessage(e.getMessage());
return true;
}
} else {
gid = command.substring(command.indexOf(':') + 1);
}
String gid = command.substring(command.indexOf(':') + 1);
group = storage.getGroup(gid);
if(group == null) {
group = new OsMoGroup();

View file

@ -11,6 +11,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmAndConstants;
@ -34,6 +35,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
@ -53,10 +55,12 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@ -278,10 +282,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
adapter.update(d.getGroup());
adapter.notifyDataSetChanged();
} else {
if (checkOperationIsNotRunning()) {
String operation = osMoPlugin.getGroups().leaveGroup((OsMoGroup) selectedObject);
startLongRunningOperation(operation);
if (!checkOperationIsNotRunning()) {
return;
}
String operation = osMoPlugin.getGroups().leaveGroup((OsMoGroup) selectedObject);
startLongRunningOperation(operation);
adapter.notifyDataSetChanged();
}
@ -317,7 +322,39 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
private void createGroup() {
// TODO Auto-generated method stub
Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.osmo_create_group);
final View v = getLayoutInflater().inflate(R.layout.osmo_create_group, getExpandableListView(), false);
final EditText policy = (EditText) v.findViewById(R.id.Policy);
final EditText description = (EditText) v.findViewById(R.id.Description);
final EditText name = (EditText) v.findViewById(R.id.Name);
final Spinner expire = (Spinner) v.findViewById(R.id.ExpireGroup);
final int[] days = new int[]{1,2,3,7,14};
String[] ds = new String[days.length];
for(int k = 0; k < days.length; k++) {
ds[k] = days[k] + " " + getString(R.string.int_days);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ds);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
expire.setAdapter(adapter);
expire.setSelection(3);
builder.setView(v);
builder.setNegativeButton(R.string.default_buttons_cancel, null);
builder.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(!checkOperationIsNotRunning()) {
return ;
}
long eTime = days[expire.getSelectedItemPosition()] * 60 * 60 * 24 * 1000 + System.currentTimeMillis();
String op = osMoPlugin.getGroups().createGroup(name.getText().toString(), eTime,
description.getText().toString(), policy.getText().toString());
startLongRunningOperation(op);
}
});
builder.create().show();
AndroidUtils.softKeyboardDelayed(name);
}
@ -341,7 +378,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
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);
labelName.setText(R.string.osmo_group_name);
}
}
});
@ -367,7 +404,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
});
builder.create().show();
tracker.requestFocus();
AndroidUtils.softKeyboardDelayed(tracker);
}
@Override
@ -532,17 +569,24 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
row = inflater.inflate(R.layout.osmo_group_item, parent, false);
//fixBackgroundRepeat(row);
}
adjustIndicator(groupPosition, isExpanded, row);
TextView label = (TextView) row.findViewById(R.id.category_name);
final OsMoGroup model = getGroup(groupPosition);
if(selectedObject == model) {
row.setBackgroundColor(getResources().getColor(R.color.row_selection_color));
} else {
row.setBackgroundColor(Color.TRANSPARENT);
}
label.setText(model.getVisibleName(OsMoGroupsActivity.this));
if(model.isMainGroup() || model.active) {
if(model.isMainGroup() || model.isActive()) {
label.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} 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;
@ -552,7 +596,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
revert = false;
return;
}
if(checkOperationIsNotRunning()) {
if(!checkOperationIsNotRunning()) {
revert = true;
ch.setChecked(!isChecked);
return;
@ -580,11 +624,17 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
final OsMoDevice model = (OsMoDevice) getChild(groupPosition, childPosition);
row.setTag(model);
if(selectedObject == model) {
row.setBackgroundColor(getResources().getColor(R.color.row_selection_color));
} else {
row.setBackgroundColor(Color.TRANSPARENT);
}
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() {
@ -610,7 +660,14 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
//Location location = tracker.getLastLocation(model.trackerId);
if (location == null || lnLocation == null) {
icon.setImageResource(R.drawable.list_favorite);
if(model.isEnabled()) {
icon.setImageResource(
//model.isActive() ? R.drawable.mon_osmo_conn_signal_small :
R.drawable.mon_osmo_conn_small);
} else {
icon.setImageResource(R.drawable.monitoring_rec_inactive);
}
label.setText(model.getVisibleName());
} else {
DirectionDrawable draw = new DirectionDrawable();
@ -623,7 +680,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
icon.setImageResource(R.drawable.list_favorite);
int dist = (int) mes[0];
long seconds = Math.max(0, (System.currentTimeMillis() - location.getTime()) / 1000);
String time = " (";
String time = "\n (";
if (seconds < 100) {
time = seconds + " " + getString(R.string.seconds_ago);
} else if (seconds / 60 < 100) {

View file

@ -36,7 +36,7 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
public OsMoPlugin(final OsmandApplication app) {
service = new OsMoService(app);
tracker = new OsMoTracker(service);
tracker = new OsMoTracker(service, app.getSettings().OSMO_SAVE_TRACK_INTERVAL);
this.app = app;
ApplicationMode.regWidget("osmo_control", (ApplicationMode[])null);
}

View file

@ -34,7 +34,7 @@ public class OsMoThread {
protected final static Log log = PlatformUtil.getLog(OsMoThread.class);
private static final long HEARTBEAT_DELAY = 100;
private static final long HEARTBEAT_FAILED_DELAY = 10000;
private static final long TIMEOUT_TO_RECONNECT = 10 * 60 * 1000;
private static final long TIMEOUT_TO_RECONNECT = 60 * 1000;
private static final long TIMEOUT_TO_PING = 2 * 60 * 1000;
private static final long LIMIT_OF_FAILURES_RECONNECT = 10;
private static final long SELECT_TIMEOUT = 500;
@ -84,6 +84,7 @@ public class OsMoThread {
if (sessionInfo == null) {
sessionInfo = service.prepareSessionToken();
}
this.activeChannel = null;
authorized = 0;
reconnect = false;
failures = 0;
@ -150,10 +151,10 @@ public class OsMoThread {
} catch (Exception e) {
log.info("Exception selecting socket", e);
e.printStackTrace();
delay = HEARTBEAT_FAILED_DELAY;
if (activeChannel != null && !activeChannel.isConnected()) {
activeChannel = null;
}
delay = HEARTBEAT_FAILED_DELAY;
if(lastSendCommand != 0 && System.currentTimeMillis() - lastSendCommand > TIMEOUT_TO_RECONNECT ) {
reconnect = true;
} else if (failures++ > LIMIT_OF_FAILURES_RECONNECT) {
@ -279,6 +280,7 @@ public class OsMoThread {
continue;
} else if(header.equalsIgnoreCase(PING_CMD)) {
pingSent = 0;
continue;
// lastSendCommand = System.currentTimeMillis(); // not needed handled by send
}
boolean processed = false;

View file

@ -5,6 +5,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import net.osmand.Location;
import net.osmand.plus.OsmandSettings.CommonPreference;
import org.json.JSONObject;
@ -17,14 +18,17 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
private OsmoTrackerListener uiTrackerListener = null;
private OsmoTrackerListener trackerListener = null;
private Location lastSendLocation;
private Location lastBufferLocation;
private CommonPreference<Integer> pref;
public interface OsmoTrackerListener {
public void locationChange(String trackerId, Location location);
}
public OsMoTracker(OsMoService service) {
public OsMoTracker(OsMoService service, CommonPreference<Integer> pref) {
this.service = service;
this.pref = pref;
service.registerSender(this);
service.registerReactor(this);
}
@ -93,8 +97,18 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
}
public void sendCoordinate(Location location) {
if(startSendingLocations) {
bufferOfLocations.add(location);
if(startSendingLocations && location != null) {
long ltime = lastBufferLocation == null ? 0 : lastBufferLocation.getTime();
if (location.getTime() - ltime > pref.get()) {
if(lastBufferLocation != null && (!lastBufferLocation.hasSpeed() || lastBufferLocation.getSpeed() < 1) &&
lastBufferLocation.distanceTo(location) < 40){
// ignores
return;
}
lastBufferLocation = location;
bufferOfLocations.add(location);
}
}
}

View file

@ -5,6 +5,7 @@ import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmo.OsMoService.SessionInfo;
import net.osmand.util.Algorithms;
import android.app.AlertDialog;
@ -22,12 +23,13 @@ import android.widget.Toast;
public class SettingsOsMoActivity extends SettingsBaseActivity {
public static final String MORE_VALUE = "MORE_VALUE";
public static final String DEFINE_EDIT = "DEFINE_EDIT";
private Preference debugPref;
private Preference trackerId;
private CheckBoxPreference sendLocationsref;
public static final int[] SECONDS = new int[] {1, 2, 3, 5, 10, 15, 30, 60, 90};
public static final int[] MINUTES = new int[] {2, 3, 5};
@Override
public void onCreate(Bundle savedInstanceState) {
@ -48,6 +50,9 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
sendLocationsref.setSummary(R.string.osmo_auto_send_locations_descr);
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));
debugPref = new Preference(this);
debugPref.setTitle(R.string.osmo_settings_debug);
debugPref.setOnPreferenceClickListener(this);