Add share options/start offline thread

This commit is contained in:
vshcherb 2014-05-25 02:25:01 +02:00
parent f68a84b8f7
commit d8abb54eec
10 changed files with 358 additions and 119 deletions

View file

@ -9,6 +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="osmo_group">OsMo group</string>
<string name="osmo_group_share">In order to Connect to the group %2$s, specify group id (%1$s)</string>
<string name="osmo_share_connect_device">Let permanently follow this device</string>
<string name="osmo_share_current_session">Share current session in browser</string>
<string name="osmo_session_not_available">Session not available, please check that \'Send locations\' is on.</string>
<string name="osmo_share_session">Share session</string>
<string name="osmo_session_id_share">Session url to track device (%1$s)</string>
<string name="osmo_tracker_id_share">In order to Connect to the target device %2$s, specify tracker id (%1$s)</string>
<string name="osmo_track_interval">Logging interval</string>
<string name="osmo_track_interval_descr">Choose time interval to send location</string>
<string name="int_days">days</string>

View file

@ -36,7 +36,10 @@ public class NavigationService extends Service implements LocationListener {
// global id don't conflict with others
private final static int NOTIFICATION_SERVICE_ID = 5;
public final static String OSMAND_STOP_SERVICE_ACTION = "OSMAND_STOP_SERVICE_ACTION"; //$NON-NLS-1$
public final static String NAVIGATION_START_SERVICE_PARAM = "NAVIGATION_START_SERVICE_PARAM";
public static int USED_BY_NAVIGATION = 1;
public static int USED_BY_GPX = 2;
public static int USED_BY_LIVE = 4;
public final static String USAGE_INTENT = "SERVICE_USED_BY";
private NavigationServiceBinder binder = new NavigationServiceBinder();
@ -52,7 +55,8 @@ public class NavigationService extends Service implements LocationListener {
private static WakeLock lockStatic;
private PendingIntent pendingIntent;
private BroadcastReceiver broadcastReceiver;
private boolean startedForNavigation;
private int usedBy = 0;
private static Method mStartForeground;
private static Method mStopForeground;
@ -110,17 +114,29 @@ public class NavigationService extends Service implements LocationListener {
return serviceOffProvider;
}
public boolean startedForNavigation(){
return startedForNavigation;
public boolean isUsed() {
return usedBy != 0;
}
public void addUsageIntent(int usageIntent) {
usedBy |= usageIntent;
}
public void stopIfNeeded(Context ctx, int usageIntent) {
usedBy -= usageIntent;
if (usedBy == 0) {
final Intent serviceIntent = new Intent(ctx, NavigationService.class);
ctx.stopService(serviceIntent);
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
handler = new Handler();
OsmandApplication app = (OsmandApplication) getApplication();
settings = app.getSettings();
startedForNavigation = intent.getBooleanExtra(NAVIGATION_START_SERVICE_PARAM, false);
if (startedForNavigation) {
usedBy = intent.getIntExtra(USAGE_INTENT, 0);
if ((usedBy & USED_BY_NAVIGATION) != 0) {
serviceOffInterval = 0;
} else {
serviceOffInterval = settings.SERVICE_OFF_INTERVAL.get();
@ -217,7 +233,7 @@ public class NavigationService extends Service implements LocationListener {
public void onDestroy() {
super.onDestroy();
((OsmandApplication)getApplication()).setNavigationService(null);
usedBy = 0;
// remove updates
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.removeUpdates(this);

View file

@ -828,4 +828,15 @@ public class OsmandApplication extends Application {
return 0;
}
}
public void startNavigationService(int intent) {
final Intent serviceIntent = new Intent(this, NavigationService.class);
serviceIntent.putExtra(NavigationService.USAGE_INTENT, intent);
if (getNavigationService() == null) {
getSettings().SERVICE_OFF_INTERVAL.set(0);
startService(serviceIntent);
} else {
getNavigationService().addUsageIntent(intent);
}
}
}

View file

@ -659,7 +659,7 @@ public class MapActivity extends AccessibleActivity {
return mapView;
}
public MapViewTrackingUtilities getMapViewTrackingUtilities() {
public static MapViewTrackingUtilities getMapViewTrackingUtilities() {
return mapViewTrackingUtilities;
}

View file

@ -0,0 +1,192 @@
package net.osmand.plus.activities.actions;
import java.util.ArrayList;
import java.util.List;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.text.Html;
import android.widget.Toast;
public class ShareDialog {
private Activity a;
private String title;
private List<ShareType> share = new ArrayList<ShareType>();
private static final String ZXING_BARCODE_SCANNER_COMPONENT = "com.google.zxing.client.android"; //$NON-NLS-1$
private static final String ZXING_BARCODE_SCANNER_ACTIVITY = "com.google.zxing.client.android.ENCODE"; //$NON-NLS-1$
static final int VIEW = 0;
static final int EMAIL = 1;
static final int SMS = 2;
static final int CLIPBOARD = 3;
static final int QR = 4;
public ShareDialog(Activity a) {
this.a = a;
}
public ShareDialog setTitle(String title) {
this.title = title;
return this;
}
public ShareDialog viewContent(String content){
share.add(new ShareType(content, VIEW));
return this;
}
public ShareDialog shareURLOrText(String url, String shortExplanation, String longExplanation){
if(shortExplanation == null) {
shortExplanation = url;
}
if(longExplanation == null){
longExplanation = shortExplanation;
}
share.add(new ShareType(longExplanation, EMAIL));
share.add(new ShareType(shortExplanation, SMS));
share.add(new ShareType(shortExplanation, CLIPBOARD));
share.add(new ShareType(url, QR));
return this;
}
private static class ShareType {
public String content;
public int type;
public ShareType(String content, int type) {
this.content = content;
this.type = type;
}
public String getShareName(Context ctx) {
if(type == VIEW) {
return ctx.getString(R.string.show_details);
} else if(type == EMAIL) {
return "Email";
} else if(type == SMS) {
return "SMS";
} else if(type == CLIPBOARD) {
return "Clipboard";
} else if(type == QR) {
return "QR-code";
}
return "";
}
public void execute(Activity a, String title) {
if(type == VIEW) {
Builder bld = new AlertDialog.Builder(a);
bld.setTitle(title);
bld.setMessage(content);
bld.show();
} else if(type == EMAIL) {
sendEmail(a, content, title);
} else if(type == SMS) {
sendSms(a, content);
} else if(type == CLIPBOARD) {
sendToClipboard(a, content);
} else if(type == QR) {
sendQRCode(a, "TEXT_TYPE", null, content);
}
}
}
public void showDialog() {
AlertDialog.Builder builder = new Builder(a);
builder.setTitle(title);
String[] shareStrings = new String[share.size()];
for(int i = 0; i < shareStrings.length; i++) {
shareStrings[i] = share.get(i).getShareName(a);
}
builder.setItems(shareStrings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ShareType type = share.get(which);
try {
type.execute(a, title);
} catch (RuntimeException e) {
Toast.makeText(a, R.string.input_output_error, Toast.LENGTH_SHORT).show();
}
}
});
builder.show();
}
public static void sendSms(Activity a, String sms) {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", sms);
sendIntent.setType("vnd.android-dir/mms-sms");
a.startActivity(sendIntent);
}
public static void sendEmail(Activity a, String email, String title) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_SUBJECT, "Location"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(email));
intent.setType("text/html");
a.startActivity(Intent.createChooser(intent, a.getString(R.string.send_location)));
}
public static void sendQRCode(final Activity activity, String encodeType, Bundle encodeData, String strEncodeData) {
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setAction(ZXING_BARCODE_SCANNER_ACTIVITY);
ResolveInfo resolved = activity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolved != null) {
intent.putExtra("ENCODE_TYPE", encodeType);
if(strEncodeData != null ) {
intent.putExtra("ENCODE_DATA", strEncodeData);
} else {
intent.putExtra("ENCODE_DATA", encodeData);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
activity.startActivity(intent);
} else {
if (Version.isMarketEnabled((OsmandApplication) activity.getApplication())) {
AlertDialog.Builder builder = new AccessibleAlertBuilder(activity);
builder.setMessage(activity.getString(R.string.zxing_barcode_scanner_not_found));
builder.setPositiveButton(activity.getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix((OsmandApplication) activity.getApplication())
+ ZXING_BARCODE_SCANNER_COMPONENT));
try {
activity.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
builder.setNegativeButton(activity.getString(R.string.default_buttons_no), null);
builder.show();
} else {
Toast.makeText(activity, R.string.zxing_barcode_scanner_not_found, Toast.LENGTH_LONG).show();
}
}
}
public static void sendToClipboard(Activity activity, String text) {
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(text);
}
}

View file

@ -1,32 +1,21 @@
package net.osmand.plus.activities.actions;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.text.Html;
import android.widget.Toast;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;
public class ShareLocation extends OsmAndAction {
private static final String ZXING_BARCODE_SCANNER_COMPONENT = "com.google.zxing.client.android"; //$NON-NLS-1$
private static final String ZXING_BARCODE_SCANNER_ACTIVITY = "com.google.zxing.client.android.ENCODE"; //$NON-NLS-1$
public ShareLocation(MapActivity mapActivity) {
super(mapActivity);
}
@ -82,24 +71,16 @@ public class ShareLocation extends OsmAndAction {
private void sendEmail(final String shortOsmUrl, final String appLink) {
String email = mapActivity.getString(R.string.send_location_email_pattern, shortOsmUrl, appLink);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_SUBJECT, "Location"); //$NON-NLS-1$
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(email));
intent.setType("text/html");
mapActivity.startActivity(Intent.createChooser(intent, getString(R.string.send_location)));
ShareDialog.sendEmail(mapActivity, email, getString(R.string.send_location));
}
private void sendSms(String sms) {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", sms);
sendIntent.setType("vnd.android-dir/mms-sms");
mapActivity.startActivity(sendIntent);
ShareDialog.sendSms(mapActivity, sms);
}
private void sendToClipboard(String sms) {
ClipboardManager clipboard = (ClipboardManager) mapActivity.getSystemService(Activity.CLIPBOARD_SERVICE);
clipboard.setText(sms);
ShareDialog.sendToClipboard(mapActivity, sms);
}
private void sendGeoActivity(final double latitude, final double longitude, final int zoom) {
@ -113,38 +94,7 @@ public class ShareLocation extends OsmAndAction {
Bundle bundle = new Bundle();
bundle.putFloat("LAT", (float) latitude);
bundle.putFloat("LONG", (float) longitude);
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setAction(ZXING_BARCODE_SCANNER_ACTIVITY);
ResolveInfo resolved = mapActivity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolved != null) {
intent.putExtra("ENCODE_TYPE", "LOCATION_TYPE");
intent.putExtra("ENCODE_DATA", bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
mapActivity.startActivity(intent);
} else {
if (Version.isMarketEnabled(mapActivity.getMyApplication())) {
AlertDialog.Builder builder = new AccessibleAlertBuilder(mapActivity);
builder.setMessage(getString(R.string.zxing_barcode_scanner_not_found));
builder.setPositiveButton(getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(mapActivity.getMyApplication())
+ ZXING_BARCODE_SCANNER_COMPONENT));
try {
mapActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
builder.setNegativeButton(getString(R.string.default_buttons_no), null);
builder.show();
} else {
Toast.makeText(mapActivity, R.string.zxing_barcode_scanner_not_found, Toast.LENGTH_LONG).show();
}
}
ShareDialog.sendQRCode(mapActivity, "LOCATION_TYPE", bundle, null);
}

View file

@ -192,18 +192,14 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
app.getSavingTrackHelper().startNewSegment();
}
settings.SAVE_TRACK_TO_GPX.set(!wasTrackMonitored);
final Intent serviceIntent = new Intent(map, NavigationService.class);
if (wasTrackMonitored) {
if (app.getNavigationService() != null && !app.getNavigationService().startedForNavigation()) {
app.stopService(serviceIntent);
if (app.getNavigationService() != null) {
app.getNavigationService().stopIfNeeded(app,NavigationService.USED_BY_GPX);
}
} else {
if (app.getNavigationService() == null) {
app.getSettings().SERVICE_OFF_INTERVAL.set(0);
app.startService(serviceIntent);
app.startNavigationService(NavigationService.USED_BY_GPX);
}
}
monitoringControl.updateInfo(null);
}
});
@ -231,14 +227,14 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
view.getSettings().SAVE_TRACK_TO_GPX.set(true);
if (view.getApplication().getNavigationService() == null) {
view.getSettings().SERVICE_OFF_INTERVAL.set(0);
view.getContext().startService(serviceIntent);
}
app.startNavigationService(NavigationService.USED_BY_GPX);
}
});
} else {
view.getSettings().SAVE_TRACK_TO_GPX.set(false);
if (view.getApplication().getNavigationService() != null && !view.getApplication().getNavigationService().startedForNavigation()) {
view.getContext().stopService(serviceIntent);
if (app.getNavigationService() != null) {
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_GPX);
}
}
}

View file

@ -13,17 +13,21 @@ import java.util.Map;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListActivity;
import net.osmand.plus.activities.actions.ShareDialog;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.osmo.OsMoGroups.OsMoGroupsUIListener;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoGroup;
@ -83,19 +87,19 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
protected static final int ON_OFF_ACTION_ID = 4;
protected static final int SHARE_ID = 5;
protected static final int SHOW_ON_MAP_ID = 6;
public static final int SHARE_SESSION = 7;
private static final int LIST_REFRESH_MSG_ID = OsmAndConstants.UI_HANDLER_SEARCH + 30;
private static final long RECENT_THRESHOLD = 60000;
private OsMoPlugin osMoPlugin;
private OsMoGroupsAdapter adapter;
private LatLon mapLocation;
private Location mapLocation;
private OsmandApplication app;
private Handler uiHandler;
private float width = 24;
private float height = 24;
private Path directionPath = new Path();
private Location lastLocation;
private float lastCompass;
private ActionMode actionMode;
private Object selectedObject = null;
@ -128,8 +132,13 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
osMoPlugin.getTracker().enableTracker();
app.startNavigationService(NavigationService.USED_BY_LIVE);
app.getSettings().SERVICE_OFF_INTERVAL.set(0);
} else {
osMoPlugin.getTracker().disableTracker();
if (app.getNavigationService() != null) {
app.getNavigationService().stopIfNeeded(app,NavigationService.USED_BY_LIVE);
}
}
updateStatus();
}
@ -244,7 +253,10 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
@Override
protected void onResume() {
super.onResume();
mapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
LatLon ml = getMyApplication().getSettings().getLastKnownMapLocation();
mapLocation = new Location("map");
mapLocation.setLatitude(ml.getLatitude());
mapLocation.setLongitude(ml.getLongitude());
app.getLocationProvider().addCompassListener(this);
app.getLocationProvider().registerOrUnregisterCompassListener(true);
app.getLocationProvider().addLocationListener(this);
@ -335,6 +347,11 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
bld.setNegativeButton(R.string.default_buttons_no, null);
bld.show();
} else if(item.getItemId() == SHARE_ID) {
if(device != null) {
shareTrackerId(device.getVisibleName(), device.getTrackerId());
} else {
shareOsMoGroup(group.getVisibleName(app), group.getGroupId());
}
} else if(item.getItemId() == SHOW_ON_MAP_ID) {
if(device != null) {
Location location = device.getLastLocation();
@ -412,6 +429,9 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
if (item.getItemId() == CONNECT_TO) {
connectToDevice();
return true;
} else if (item.getItemId() == SHARE_SESSION) {
shareSession();
return true;
} else if (item.getItemId() == CREATE_GROUP) {
createGroup();
return true;
@ -420,6 +440,60 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
}
}
private void shareSession() {
Builder bld = new AlertDialog.Builder(this);
bld.setItems(new String[] {
getString(R.string.osmo_share_current_session),
getString(R.string.osmo_share_connect_device)
}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
shareSessionUrl();
} else {
OsMoService service = osMoPlugin.getService();
SessionInfo ci = service.getCurrentSessionInfo();
shareTrackerId("", ci == null ? null : ci.trackerId);
}
}
});
bld.setNegativeButton(R.string.default_buttons_cancel, null);
bld.show();
}
private void shareSessionUrl() {
String sessionURL = osMoPlugin.getTracker().getSessionURL();
if(sessionURL == null ) {
AccessibleToast.makeText(this, R.string.osmo_session_not_available, Toast.LENGTH_SHORT).show();
} else {
ShareDialog dlg = new ShareDialog(this);
dlg.setTitle(getString(R.string.osmo_share_session));
dlg.viewContent(sessionURL);
dlg.shareURLOrText(sessionURL, getString(R.string.osmo_session_id_share, sessionURL), null);
dlg.showDialog();
}
}
private void shareTrackerId(String name, String trackerId) {
if(trackerId == null) {
AccessibleToast.makeText(this, R.string.osmo_auth_pending, Toast.LENGTH_SHORT).show();
} else {
ShareDialog dlg = new ShareDialog(this);
dlg.setTitle(getString(R.string.osmo_tracker_id));
dlg.viewContent(trackerId);
dlg.shareURLOrText(trackerId, getString(R.string.osmo_tracker_id_share, trackerId, name), null);
dlg.showDialog();
}
}
private void shareOsMoGroup(String name, String groupId) {
ShareDialog dlg = new ShareDialog(this);
dlg.setTitle(getString(R.string.osmo_group));
dlg.viewContent(groupId);
dlg.shareURLOrText(groupId, getString(R.string.osmo_group_share, groupId, name), null);
dlg.showDialog();
}
private void createGroup() {
Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.osmo_create_group);
@ -511,6 +585,9 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
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, SHARE_SESSION, R.string.osmo_share_session,
R.drawable.ic_action_gshare_light, R.drawable.ic_action_gshare_dark,
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);
@ -704,27 +781,25 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
TextView label = (TextView) row.findViewById(R.id.osmo_label);
TextView labelTime = (TextView) row.findViewById(R.id.osmo_label_time);
ImageView icon = (ImageView) row.findViewById(R.id.osmo_user_icon);
LatLon lnLocation = mapLocation;
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) {
if (location == null || mapLocation == null) {
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();
float[] mes = new float[2];
net.osmand.Location.distanceBetween(location.getLatitude(), location.getLongitude(),
lnLocation.getLatitude(), lnLocation.getLongitude(), mes);
mapLocation.getLatitude(), mapLocation.getLongitude(), mes);
draw.setAngle(mes[1] - lastCompass + 180);
draw.setRecent(Math.abs(location.getTime() - System.currentTimeMillis()) < RECENT_THRESHOLD);
icon.setImageDrawable(draw);
@ -761,9 +836,12 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements
@Override
public void updateLocation(Location location) {
lastLocation = location;
MapViewTrackingUtilities mv = MapActivity.getMapViewTrackingUtilities();
if(mv != null && mv.isMapLinkedToLocation() && location != null) {
mapLocation = location;
adapter.notifyDataSetInvalidated();
}
}
@Override
public void updateCompassValue(float value) {

View file

@ -2,23 +2,15 @@ package net.osmand.plus.osmo;
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.activities.actions.ShareDialog;
import net.osmand.plus.osmo.OsMoService.SessionInfo;
import net.osmand.util.Algorithms;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.text.format.DateFormat;
import android.util.TimeUtils;
import android.widget.ProgressBar;
import android.widget.Toast;
public class SettingsOsMoActivity extends SettingsBaseActivity {
@ -101,10 +93,11 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
if(ci == null || ci.trackerId == null) {
AccessibleToast.makeText(this, R.string.osmo_auth_pending, Toast.LENGTH_SHORT).show();
} else {
Builder bld = new AlertDialog.Builder(this);
bld.setTitle(R.string.osmo_tracker_id);
bld.setMessage(ci.trackerId);
bld.show();
ShareDialog dlg = new ShareDialog(this);
dlg.setTitle(getString(R.string.osmo_tracker_id));
dlg.viewContent(ci.trackerId);
dlg.shareURLOrText(ci.trackerId, getString(R.string.osmo_tracker_id_share, ci.trackerId), null);
dlg.showDialog();
}
}
return super.onPreferenceClick(preference);

View file

@ -98,17 +98,12 @@ public class RoutingHelper {
public void setFollowingMode(boolean follow) {
isFollowingMode = follow;
if(follow) {
if (!follow) {
if (app.getNavigationService() != null) {
Intent serviceIntent = new Intent(app, NavigationService.class);
serviceIntent.putExtra(NavigationService.NAVIGATION_START_SERVICE_PARAM, true);
app.startService(serviceIntent);
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_NAVIGATION);
}
} else {
if(app.getNavigationService() != null && app.getNavigationService().startedForNavigation()) {
Intent serviceIntent = new Intent(app, NavigationService.class);
app.stopService(serviceIntent);
}
app.startNavigationService(NavigationService.USED_BY_NAVIGATION);
}
}