use resolveActivityInfo to display nagivate to button
resolveActivity on the other hand only finds apps that are category_default fixes #4375
This commit is contained in:
parent
f7996a6c3c
commit
a95d0fa8d3
|
@ -64,6 +64,9 @@
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<data android:mimeType="resource/folder" />
|
<data android:mimeType="resource/folder" />
|
||||||
</intent>
|
</intent>
|
||||||
|
<intent>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ package eu.siacs.conversations.ui;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -17,6 +17,7 @@ import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.databinding.DataBindingUtil;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.osmdroid.util.GeoPoint;
|
import org.osmdroid.util.GeoPoint;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -32,198 +33,214 @@ import eu.siacs.conversations.ui.widget.Marker;
|
||||||
import eu.siacs.conversations.ui.widget.MyLocation;
|
import eu.siacs.conversations.ui.widget.MyLocation;
|
||||||
import eu.siacs.conversations.utils.LocationProvider;
|
import eu.siacs.conversations.utils.LocationProvider;
|
||||||
|
|
||||||
|
|
||||||
public class ShowLocationActivity extends LocationActivity implements LocationListener {
|
public class ShowLocationActivity extends LocationActivity implements LocationListener {
|
||||||
|
|
||||||
private GeoPoint loc = LocationProvider.FALLBACK;
|
private GeoPoint loc = LocationProvider.FALLBACK;
|
||||||
private ActivityShowLocationBinding binding;
|
private ActivityShowLocationBinding binding;
|
||||||
|
|
||||||
|
private Uri createGeoUri() {
|
||||||
|
return Uri.parse("geo:" + this.loc.getLatitude() + "," + this.loc.getLongitude());
|
||||||
|
}
|
||||||
|
|
||||||
private Uri createGeoUri() {
|
@Override
|
||||||
return Uri.parse("geo:" + this.loc.getLatitude() + "," + this.loc.getLongitude());
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
}
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
@Override
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_show_location);
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
setSupportActionBar(binding.toolbar);
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
this.binding = DataBindingUtil.setContentView(this,R.layout.activity_show_location);
|
configureActionBar(getSupportActionBar());
|
||||||
setSupportActionBar(binding.toolbar);
|
setupMapView(this.binding.map, this.loc);
|
||||||
|
|
||||||
configureActionBar(getSupportActionBar());
|
this.binding.fab.setOnClickListener(view -> startNavigation());
|
||||||
setupMapView(this.binding.map, this.loc);
|
|
||||||
|
|
||||||
this.binding.fab.setOnClickListener(view -> startNavigation());
|
final Intent intent = getIntent();
|
||||||
|
if (intent != null) {
|
||||||
|
final String action = intent.getAction();
|
||||||
|
if (action == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (action) {
|
||||||
|
case "eu.siacs.conversations.location.show":
|
||||||
|
if (intent.hasExtra("longitude") && intent.hasExtra("latitude")) {
|
||||||
|
final double longitude = intent.getDoubleExtra("longitude", 0);
|
||||||
|
final double latitude = intent.getDoubleExtra("latitude", 0);
|
||||||
|
this.loc = new GeoPoint(latitude, longitude);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Intent.ACTION_VIEW:
|
||||||
|
final Uri geoUri = intent.getData();
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
// Attempt to set zoom level if the geo URI specifies it
|
||||||
if (intent != null) {
|
if (geoUri != null) {
|
||||||
final String action = intent.getAction();
|
final HashMap<String, String> query =
|
||||||
if (action == null) {
|
UriHelper.parseQueryString(geoUri.getQuery());
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (action) {
|
|
||||||
case "eu.siacs.conversations.location.show":
|
|
||||||
if (intent.hasExtra("longitude") && intent.hasExtra("latitude")) {
|
|
||||||
final double longitude = intent.getDoubleExtra("longitude", 0);
|
|
||||||
final double latitude = intent.getDoubleExtra("latitude", 0);
|
|
||||||
this.loc = new GeoPoint(latitude, longitude);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Intent.ACTION_VIEW:
|
|
||||||
final Uri geoUri = intent.getData();
|
|
||||||
|
|
||||||
// Attempt to set zoom level if the geo URI specifies it
|
// Check for zoom level.
|
||||||
if (geoUri != null) {
|
final String z = query.get("z");
|
||||||
final HashMap<String, String> query = UriHelper.parseQueryString(geoUri.getQuery());
|
if (z != null) {
|
||||||
|
try {
|
||||||
|
mapController.setZoom(Double.valueOf(z));
|
||||||
|
} catch (final Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check for zoom level.
|
// Check for the actual geo query.
|
||||||
final String z = query.get("z");
|
boolean posInQuery = false;
|
||||||
if (z != null) {
|
final String q = query.get("q");
|
||||||
try {
|
if (q != null) {
|
||||||
mapController.setZoom(Double.valueOf(z));
|
final Pattern latlng =
|
||||||
} catch (final Exception ignored) {
|
Pattern.compile(
|
||||||
}
|
"/^([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)(\\(.*\\))?/");
|
||||||
}
|
final Matcher m = latlng.matcher(q);
|
||||||
|
if (m.matches()) {
|
||||||
|
try {
|
||||||
|
this.loc =
|
||||||
|
new GeoPoint(
|
||||||
|
Double.valueOf(m.group(1)),
|
||||||
|
Double.valueOf(m.group(3)));
|
||||||
|
posInQuery = true;
|
||||||
|
} catch (final Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check for the actual geo query.
|
final String schemeSpecificPart = geoUri.getSchemeSpecificPart();
|
||||||
boolean posInQuery = false;
|
if (schemeSpecificPart != null && !schemeSpecificPart.isEmpty()) {
|
||||||
final String q = query.get("q");
|
try {
|
||||||
if (q != null) {
|
final GeoPoint latlong =
|
||||||
final Pattern latlng = Pattern.compile("/^([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)(\\(.*\\))?/");
|
LocationHelper.parseLatLong(schemeSpecificPart);
|
||||||
final Matcher m = latlng.matcher(q);
|
if (latlong != null && !posInQuery) {
|
||||||
if (m.matches()) {
|
this.loc = latlong;
|
||||||
try {
|
}
|
||||||
this.loc = new GeoPoint(Double.valueOf(m.group(1)), Double.valueOf(m.group(3)));
|
} catch (final NumberFormatException ignored) {
|
||||||
posInQuery = true;
|
}
|
||||||
} catch (final Exception ignored) {
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final String schemeSpecificPart = geoUri.getSchemeSpecificPart();
|
break;
|
||||||
if (schemeSpecificPart != null && !schemeSpecificPart.isEmpty()) {
|
}
|
||||||
try {
|
updateLocationMarkers();
|
||||||
final GeoPoint latlong = LocationHelper.parseLatLong(schemeSpecificPart);
|
}
|
||||||
if (latlong != null && !posInQuery) {
|
}
|
||||||
this.loc = latlong;
|
|
||||||
}
|
|
||||||
} catch (final NumberFormatException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
@Override
|
||||||
}
|
protected void gotoLoc(final boolean setZoomLevel) {
|
||||||
updateLocationMarkers();
|
if (this.loc != null && mapController != null) {
|
||||||
}
|
if (setZoomLevel) {
|
||||||
}
|
mapController.setZoom(Config.Map.FINAL_ZOOM_LEVEL);
|
||||||
|
}
|
||||||
|
mapController.animateTo(new GeoPoint(this.loc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void gotoLoc(final boolean setZoomLevel) {
|
public void onRequestPermissionsResult(
|
||||||
if (this.loc != null && mapController != null) {
|
final int requestCode,
|
||||||
if (setZoomLevel) {
|
@NonNull final String[] permissions,
|
||||||
mapController.setZoom(Config.Map.FINAL_ZOOM_LEVEL);
|
@NonNull final int[] grantResults) {
|
||||||
}
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
mapController.animateTo(new GeoPoint(this.loc));
|
updateUi();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(final int requestCode,
|
protected void setMyLoc(final Location location) {
|
||||||
@NonNull final String[] permissions,
|
this.myLoc = location;
|
||||||
@NonNull final int[] grantResults) {
|
}
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
||||||
updateUi();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setMyLoc(final Location location) {
|
public boolean onCreateOptionsMenu(@NotNull final Menu menu) {
|
||||||
this.myLoc = location;
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
}
|
getMenuInflater().inflate(R.menu.menu_show_location, menu);
|
||||||
|
updateUi();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
protected void updateLocationMarkers() {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
super.updateLocationMarkers();
|
||||||
getMenuInflater().inflate(R.menu.menu_show_location, menu);
|
if (this.myLoc != null) {
|
||||||
updateUi();
|
this.binding.map.getOverlays().add(new MyLocation(this, null, this.myLoc));
|
||||||
return true;
|
}
|
||||||
}
|
this.binding.map.getOverlays().add(new Marker(this.marker_icon, this.loc));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateLocationMarkers() {
|
protected void onPause() {
|
||||||
super.updateLocationMarkers();
|
super.onPause();
|
||||||
if (this.myLoc != null) {
|
}
|
||||||
this.binding.map.getOverlays().add(new MyLocation(this, null, this.myLoc));
|
|
||||||
}
|
|
||||||
this.binding.map.getOverlays().add(new Marker(this.marker_icon, this.loc));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
super.onPause();
|
switch (item.getItemId()) {
|
||||||
}
|
case R.id.action_copy_location:
|
||||||
|
final ClipboardManager clipboard =
|
||||||
|
(ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
|
if (clipboard != null) {
|
||||||
|
final ClipData clip =
|
||||||
|
ClipData.newPlainText("location", createGeoUri().toString());
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
Toast.makeText(this, R.string.url_copied_to_clipboard, Toast.LENGTH_SHORT)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case R.id.action_share_location:
|
||||||
|
final Intent shareIntent = new Intent();
|
||||||
|
shareIntent.setAction(Intent.ACTION_SEND);
|
||||||
|
shareIntent.putExtra(Intent.EXTRA_TEXT, createGeoUri().toString());
|
||||||
|
shareIntent.setType("text/plain");
|
||||||
|
try {
|
||||||
|
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with)));
|
||||||
|
} catch (final ActivityNotFoundException e) {
|
||||||
|
// This should happen only on faulty androids because normally chooser is always
|
||||||
|
// available
|
||||||
|
Toast.makeText(
|
||||||
|
this,
|
||||||
|
R.string.no_application_found_to_open_file,
|
||||||
|
Toast.LENGTH_SHORT)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
private void startNavigation() {
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
final Intent intent = getStartNavigationIntent();
|
||||||
switch (item.getItemId()) {
|
startActivity(intent);
|
||||||
case R.id.action_copy_location:
|
}
|
||||||
final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
|
||||||
if (clipboard != null) {
|
|
||||||
final ClipData clip = ClipData.newPlainText("location", createGeoUri().toString());
|
|
||||||
clipboard.setPrimaryClip(clip);
|
|
||||||
Toast.makeText(this,R.string.url_copied_to_clipboard,Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case R.id.action_share_location:
|
|
||||||
final Intent shareIntent = new Intent();
|
|
||||||
shareIntent.setAction(Intent.ACTION_SEND);
|
|
||||||
shareIntent.putExtra(Intent.EXTRA_TEXT, createGeoUri().toString());
|
|
||||||
shareIntent.setType("text/plain");
|
|
||||||
try {
|
|
||||||
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with)));
|
|
||||||
} catch (final ActivityNotFoundException e) {
|
|
||||||
//This should happen only on faulty androids because normally chooser is always available
|
|
||||||
Toast.makeText(this, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startNavigation() {
|
private Intent getStartNavigationIntent() {
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
|
return new Intent(
|
||||||
"google.navigation:q=" +
|
Intent.ACTION_VIEW,
|
||||||
this.loc.getLatitude() + "," + this.loc.getLongitude()
|
Uri.parse(
|
||||||
)));
|
"google.navigation:q="
|
||||||
}
|
+ this.loc.getLatitude()
|
||||||
|
+ ","
|
||||||
|
+ this.loc.getLongitude()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateUi() {
|
protected void updateUi() {
|
||||||
final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=0,0"));
|
final Intent intent = getStartNavigationIntent();
|
||||||
final ComponentName component = i.resolveActivity(getPackageManager());
|
final ActivityInfo activityInfo = intent.resolveActivityInfo(getPackageManager(), 0);
|
||||||
this.binding.fab.setVisibility(component == null ? View.GONE : View.VISIBLE);
|
this.binding.fab.setVisibility(activityInfo == null ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(final Location location) {
|
public void onLocationChanged(@NotNull final Location location) {
|
||||||
if (LocationHelper.isBetterLocation(location, this.myLoc)) {
|
if (LocationHelper.isBetterLocation(location, this.myLoc)) {
|
||||||
this.myLoc = location;
|
this.myLoc = location;
|
||||||
updateLocationMarkers();
|
updateLocationMarkers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusChanged(final String provider, final int status, final Bundle extras) {
|
public void onStatusChanged(final String provider, final int status, final Bundle extras) {}
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public void onProviderEnabled(@NotNull final String provider) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(final String provider) {
|
public void onProviderDisabled(@NotNull final String provider) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProviderDisabled(final String provider) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue