include uncertainty into shared geo uri
This commit is contained in:
parent
a508a81553
commit
5d526a77e3
|
@ -856,9 +856,15 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
||||||
toggleInputMethod();
|
toggleInputMethod();
|
||||||
break;
|
break;
|
||||||
case ATTACHMENT_CHOICE_LOCATION:
|
case ATTACHMENT_CHOICE_LOCATION:
|
||||||
double latitude = data.getDoubleExtra("latitude", 0);
|
final double latitude = data.getDoubleExtra("latitude", 0);
|
||||||
double longitude = data.getDoubleExtra("longitude", 0);
|
final double longitude = data.getDoubleExtra("longitude", 0);
|
||||||
Uri geo = Uri.parse("geo:" + latitude + "," + longitude);
|
final int accuracy = data.getIntExtra("accuracy", 0);
|
||||||
|
final Uri geo;
|
||||||
|
if (accuracy > 0) {
|
||||||
|
geo = Uri.parse(String.format("geo:%s,%s;u=%s", latitude, longitude, accuracy));
|
||||||
|
} else {
|
||||||
|
geo = Uri.parse(String.format("geo:%s,%s", latitude, longitude));
|
||||||
|
}
|
||||||
mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), geo, Attachment.Type.LOCATION));
|
mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), geo, Attachment.Type.LOCATION));
|
||||||
toggleInputMethod();
|
toggleInputMethod();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -13,10 +13,13 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.databinding.DataBindingUtil;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
import com.google.common.math.DoubleMath;
|
||||||
|
|
||||||
import org.osmdroid.api.IGeoPoint;
|
import org.osmdroid.api.IGeoPoint;
|
||||||
import org.osmdroid.util.GeoPoint;
|
import org.osmdroid.util.GeoPoint;
|
||||||
|
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.databinding.ActivityShareLocationBinding;
|
import eu.siacs.conversations.databinding.ActivityShareLocationBinding;
|
||||||
|
@ -28,213 +31,213 @@ import eu.siacs.conversations.utils.ThemeHelper;
|
||||||
|
|
||||||
public class ShareLocationActivity extends LocationActivity implements LocationListener {
|
public class ShareLocationActivity extends LocationActivity implements LocationListener {
|
||||||
|
|
||||||
private Snackbar snackBar;
|
private Snackbar snackBar;
|
||||||
private ActivityShareLocationBinding binding;
|
private ActivityShareLocationBinding binding;
|
||||||
private boolean marker_fixed_to_loc = false;
|
private boolean marker_fixed_to_loc = false;
|
||||||
private static final String KEY_FIXED_TO_LOC = "fixed_to_loc";
|
private static final String KEY_FIXED_TO_LOC = "fixed_to_loc";
|
||||||
private Boolean noAskAgain = false;
|
private Boolean noAskAgain = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull final Bundle outState) {
|
protected void onSaveInstanceState(@NonNull final Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
outState.putBoolean(KEY_FIXED_TO_LOC, marker_fixed_to_loc);
|
outState.putBoolean(KEY_FIXED_TO_LOC, marker_fixed_to_loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
|
protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
|
||||||
super.onRestoreInstanceState(savedInstanceState);
|
super.onRestoreInstanceState(savedInstanceState);
|
||||||
|
|
||||||
if (savedInstanceState.containsKey(KEY_FIXED_TO_LOC)) {
|
if (savedInstanceState.containsKey(KEY_FIXED_TO_LOC)) {
|
||||||
this.marker_fixed_to_loc = savedInstanceState.getBoolean(KEY_FIXED_TO_LOC);
|
this.marker_fixed_to_loc = savedInstanceState.getBoolean(KEY_FIXED_TO_LOC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
this.binding = DataBindingUtil.setContentView(this,R.layout.activity_share_location);
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_share_location);
|
||||||
setSupportActionBar(binding.toolbar);
|
setSupportActionBar(binding.toolbar);
|
||||||
configureActionBar(getSupportActionBar());
|
configureActionBar(getSupportActionBar());
|
||||||
setupMapView(binding.map, LocationProvider.getGeoPoint(this));
|
setupMapView(binding.map, LocationProvider.getGeoPoint(this));
|
||||||
|
|
||||||
this.binding.cancelButton.setOnClickListener(view -> {
|
this.binding.cancelButton.setOnClickListener(view -> {
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.snackBar = Snackbar.make(this.binding.snackbarCoordinator, R.string.location_disabled, Snackbar.LENGTH_INDEFINITE);
|
this.snackBar = Snackbar.make(this.binding.snackbarCoordinator, R.string.location_disabled, Snackbar.LENGTH_INDEFINITE);
|
||||||
this.snackBar.setAction(R.string.enable, view -> {
|
this.snackBar.setAction(R.string.enable, view -> {
|
||||||
if (isLocationEnabledAndAllowed()) {
|
if (isLocationEnabledAndAllowed()) {
|
||||||
updateUi();
|
updateUi();
|
||||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasLocationPermissions()) {
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !hasLocationPermissions()) {
|
||||||
requestPermissions(REQUEST_CODE_SNACKBAR_PRESSED);
|
requestPermissions(REQUEST_CODE_SNACKBAR_PRESSED);
|
||||||
} else if (!isLocationEnabled()) {
|
} else if (!isLocationEnabled()) {
|
||||||
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ThemeHelper.fix(this.snackBar);
|
ThemeHelper.fix(this.snackBar);
|
||||||
|
|
||||||
this.binding.shareButton.setOnClickListener(view -> {
|
this.binding.shareButton.setOnClickListener(this::shareLocation);
|
||||||
final Intent result = new Intent();
|
|
||||||
|
|
||||||
if (marker_fixed_to_loc && myLoc != null) {
|
this.marker_fixed_to_loc = isLocationEnabledAndAllowed();
|
||||||
result.putExtra("latitude", myLoc.getLatitude());
|
|
||||||
result.putExtra("longitude", myLoc.getLongitude());
|
|
||||||
result.putExtra("altitude", myLoc.getAltitude());
|
|
||||||
result.putExtra("accuracy", (int) myLoc.getAccuracy());
|
|
||||||
} else {
|
|
||||||
final IGeoPoint markerPoint = this.binding.map.getMapCenter();
|
|
||||||
result.putExtra("latitude", markerPoint.getLatitude());
|
|
||||||
result.putExtra("longitude", markerPoint.getLongitude());
|
|
||||||
}
|
|
||||||
|
|
||||||
setResult(RESULT_OK, result);
|
this.binding.fab.setOnClickListener(view -> {
|
||||||
finish();
|
if (!marker_fixed_to_loc) {
|
||||||
});
|
if (!isLocationEnabled()) {
|
||||||
|
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
||||||
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
requestPermissions(REQUEST_CODE_FAB_PRESSED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toggleFixedLocation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.marker_fixed_to_loc = isLocationEnabledAndAllowed();
|
private void shareLocation(final View view) {
|
||||||
|
final Intent result = new Intent();
|
||||||
|
if (marker_fixed_to_loc && myLoc != null) {
|
||||||
|
result.putExtra("latitude", myLoc.getLatitude());
|
||||||
|
result.putExtra("longitude", myLoc.getLongitude());
|
||||||
|
result.putExtra("altitude", myLoc.getAltitude());
|
||||||
|
result.putExtra("accuracy", DoubleMath.roundToInt(myLoc.getAccuracy(), RoundingMode.HALF_UP));
|
||||||
|
} else {
|
||||||
|
final IGeoPoint markerPoint = this.binding.map.getMapCenter();
|
||||||
|
result.putExtra("latitude", markerPoint.getLatitude());
|
||||||
|
result.putExtra("longitude", markerPoint.getLongitude());
|
||||||
|
}
|
||||||
|
setResult(RESULT_OK, result);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
this.binding.fab.setOnClickListener(view -> {
|
@Override
|
||||||
if (!marker_fixed_to_loc) {
|
public void onRequestPermissionsResult(final int requestCode,
|
||||||
if (!isLocationEnabled()) {
|
@NonNull final String[] permissions,
|
||||||
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
@NonNull final int[] grantResults) {
|
||||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
requestPermissions(REQUEST_CODE_FAB_PRESSED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
toggleFixedLocation();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (grantResults.length > 0 &&
|
||||||
public void onRequestPermissionsResult(final int requestCode,
|
grantResults[0] != PackageManager.PERMISSION_GRANTED &&
|
||||||
@NonNull final String[] permissions,
|
Build.VERSION.SDK_INT >= 23 &&
|
||||||
@NonNull final int[] grantResults) {
|
permissions.length > 0 &&
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
(
|
||||||
|
Manifest.permission.LOCATION_HARDWARE.equals(permissions[0]) ||
|
||||||
|
Manifest.permission.ACCESS_FINE_LOCATION.equals(permissions[0]) ||
|
||||||
|
Manifest.permission.ACCESS_COARSE_LOCATION.equals(permissions[0])
|
||||||
|
) &&
|
||||||
|
!shouldShowRequestPermissionRationale(permissions[0])) {
|
||||||
|
noAskAgain = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (grantResults.length > 0 &&
|
if (!noAskAgain && requestCode == REQUEST_CODE_SNACKBAR_PRESSED && !isLocationEnabled() && hasLocationPermissions()) {
|
||||||
grantResults[0] != PackageManager.PERMISSION_GRANTED &&
|
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
||||||
Build.VERSION.SDK_INT >= 23 &&
|
}
|
||||||
permissions.length > 0 &&
|
updateUi();
|
||||||
(
|
}
|
||||||
Manifest.permission.LOCATION_HARDWARE.equals(permissions[0]) ||
|
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION.equals(permissions[0]) ||
|
|
||||||
Manifest.permission.ACCESS_COARSE_LOCATION.equals(permissions[0])
|
|
||||||
) &&
|
|
||||||
!shouldShowRequestPermissionRationale(permissions[0])) {
|
|
||||||
noAskAgain = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!noAskAgain && requestCode == REQUEST_CODE_SNACKBAR_PRESSED && !isLocationEnabled() && hasLocationPermissions()) {
|
@Override
|
||||||
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
|
protected void gotoLoc(final boolean setZoomLevel) {
|
||||||
}
|
if (this.myLoc != null && mapController != null) {
|
||||||
updateUi();
|
if (setZoomLevel) {
|
||||||
}
|
mapController.setZoom(Config.Map.FINAL_ZOOM_LEVEL);
|
||||||
|
}
|
||||||
|
mapController.animateTo(new GeoPoint(this.myLoc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void gotoLoc(final boolean setZoomLevel) {
|
protected void setMyLoc(final Location location) {
|
||||||
if (this.myLoc != null && mapController != null) {
|
this.myLoc = location;
|
||||||
if (setZoomLevel) {
|
}
|
||||||
mapController.setZoom(Config.Map.FINAL_ZOOM_LEVEL);
|
|
||||||
}
|
|
||||||
mapController.animateTo(new GeoPoint(this.myLoc));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setMyLoc(final Location location) {
|
protected void onPause() {
|
||||||
this.myLoc = location;
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void updateLocationMarkers() {
|
||||||
super.onPause();
|
super.updateLocationMarkers();
|
||||||
}
|
if (this.myLoc != null) {
|
||||||
|
this.binding.map.getOverlays().add(new MyLocation(this, null, this.myLoc));
|
||||||
|
if (this.marker_fixed_to_loc) {
|
||||||
|
this.binding.map.getOverlays().add(new Marker(marker_icon, new GeoPoint(this.myLoc)));
|
||||||
|
} else {
|
||||||
|
this.binding.map.getOverlays().add(new Marker(marker_icon));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.binding.map.getOverlays().add(new Marker(marker_icon));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateLocationMarkers() {
|
public void onLocationChanged(final Location location) {
|
||||||
super.updateLocationMarkers();
|
if (this.myLoc == null) {
|
||||||
if (this.myLoc != null) {
|
this.marker_fixed_to_loc = true;
|
||||||
this.binding.map.getOverlays().add(new MyLocation(this, null, this.myLoc));
|
}
|
||||||
if (this.marker_fixed_to_loc) {
|
updateUi();
|
||||||
this.binding.map.getOverlays().add(new Marker(marker_icon, new GeoPoint(this.myLoc)));
|
if (LocationHelper.isBetterLocation(location, this.myLoc)) {
|
||||||
} else {
|
final Location oldLoc = this.myLoc;
|
||||||
this.binding.map.getOverlays().add(new Marker(marker_icon));
|
this.myLoc = location;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.binding.map.getOverlays().add(new Marker(marker_icon));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// Don't jump back to the users location if they're not moving (more or less).
|
||||||
public void onLocationChanged(final Location location) {
|
if (oldLoc == null || (this.marker_fixed_to_loc && this.myLoc.distanceTo(oldLoc) > 1)) {
|
||||||
if (this.myLoc == null) {
|
gotoLoc();
|
||||||
this.marker_fixed_to_loc = true;
|
}
|
||||||
}
|
|
||||||
updateUi();
|
|
||||||
if (LocationHelper.isBetterLocation(location, this.myLoc)) {
|
|
||||||
final Location oldLoc = this.myLoc;
|
|
||||||
this.myLoc = location;
|
|
||||||
|
|
||||||
// Don't jump back to the users location if they're not moving (more or less).
|
updateLocationMarkers();
|
||||||
if (oldLoc == null || (this.marker_fixed_to_loc && this.myLoc.distanceTo(oldLoc) > 1)) {
|
}
|
||||||
gotoLoc();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
updateLocationMarkers();
|
@Override
|
||||||
}
|
public void onStatusChanged(final String provider, final int status, final Bundle extras) {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void onStatusChanged(final String provider, final int status, final Bundle extras) {
|
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public void onProviderEnabled(final String provider) {
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void onProviderEnabled(final String provider) {
|
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public void onProviderDisabled(final String provider) {
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void onProviderDisabled(final String provider) {
|
|
||||||
|
|
||||||
}
|
private boolean isLocationEnabledAndAllowed() {
|
||||||
|
return this.hasLocationFeature && (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || this.hasLocationPermissions()) && this.isLocationEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isLocationEnabledAndAllowed() {
|
private void toggleFixedLocation() {
|
||||||
return this.hasLocationFeature && (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || this.hasLocationPermissions()) && this.isLocationEnabled();
|
this.marker_fixed_to_loc = isLocationEnabledAndAllowed() && !this.marker_fixed_to_loc;
|
||||||
}
|
if (this.marker_fixed_to_loc) {
|
||||||
|
gotoLoc(false);
|
||||||
|
}
|
||||||
|
updateLocationMarkers();
|
||||||
|
updateUi();
|
||||||
|
}
|
||||||
|
|
||||||
private void toggleFixedLocation() {
|
@Override
|
||||||
this.marker_fixed_to_loc = isLocationEnabledAndAllowed() && !this.marker_fixed_to_loc;
|
protected void updateUi() {
|
||||||
if (this.marker_fixed_to_loc) {
|
if (!hasLocationFeature || noAskAgain || isLocationEnabledAndAllowed()) {
|
||||||
gotoLoc(false);
|
this.snackBar.dismiss();
|
||||||
}
|
} else {
|
||||||
updateLocationMarkers();
|
this.snackBar.show();
|
||||||
updateUi();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (isLocationEnabledAndAllowed()) {
|
||||||
protected void updateUi() {
|
this.binding.fab.setVisibility(View.VISIBLE);
|
||||||
if (!hasLocationFeature || noAskAgain || isLocationEnabledAndAllowed()) {
|
runOnUiThread(() -> {
|
||||||
this.snackBar.dismiss();
|
this.binding.fab.setImageResource(marker_fixed_to_loc ? R.drawable.ic_gps_fixed_white_24dp :
|
||||||
} else {
|
R.drawable.ic_gps_not_fixed_white_24dp);
|
||||||
this.snackBar.show();
|
this.binding.fab.setContentDescription(getResources().getString(
|
||||||
}
|
marker_fixed_to_loc ? R.string.action_unfix_from_location : R.string.action_fix_to_location
|
||||||
|
));
|
||||||
if (isLocationEnabledAndAllowed()) {
|
this.binding.fab.invalidate();
|
||||||
this.binding.fab.setVisibility(View.VISIBLE);
|
});
|
||||||
runOnUiThread(() -> {
|
} else {
|
||||||
this.binding.fab.setImageResource(marker_fixed_to_loc ? R.drawable.ic_gps_fixed_white_24dp :
|
this.binding.fab.setVisibility(View.GONE);
|
||||||
R.drawable.ic_gps_not_fixed_white_24dp);
|
}
|
||||||
this.binding.fab.setContentDescription(getResources().getString(
|
}
|
||||||
marker_fixed_to_loc ? R.string.action_unfix_from_location : R.string.action_fix_to_location
|
|
||||||
));
|
|
||||||
this.binding.fab.invalidate();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.binding.fab.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue