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,13 +33,11 @@ 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() {
|
private Uri createGeoUri() {
|
||||||
return Uri.parse("geo:" + this.loc.getLatitude() + "," + this.loc.getLongitude());
|
return Uri.parse("geo:" + this.loc.getLatitude() + "," + this.loc.getLongitude());
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,8 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
|
||||||
|
|
||||||
// Attempt to set zoom level if the geo URI specifies it
|
// Attempt to set zoom level if the geo URI specifies it
|
||||||
if (geoUri != null) {
|
if (geoUri != null) {
|
||||||
final HashMap<String, String> query = UriHelper.parseQueryString(geoUri.getQuery());
|
final HashMap<String, String> query =
|
||||||
|
UriHelper.parseQueryString(geoUri.getQuery());
|
||||||
|
|
||||||
// Check for zoom level.
|
// Check for zoom level.
|
||||||
final String z = query.get("z");
|
final String z = query.get("z");
|
||||||
|
@ -89,11 +89,16 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
|
||||||
boolean posInQuery = false;
|
boolean posInQuery = false;
|
||||||
final String q = query.get("q");
|
final String q = query.get("q");
|
||||||
if (q != null) {
|
if (q != null) {
|
||||||
final Pattern latlng = Pattern.compile("/^([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)(\\(.*\\))?/");
|
final Pattern latlng =
|
||||||
|
Pattern.compile(
|
||||||
|
"/^([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)(\\(.*\\))?/");
|
||||||
final Matcher m = latlng.matcher(q);
|
final Matcher m = latlng.matcher(q);
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
try {
|
try {
|
||||||
this.loc = new GeoPoint(Double.valueOf(m.group(1)), Double.valueOf(m.group(3)));
|
this.loc =
|
||||||
|
new GeoPoint(
|
||||||
|
Double.valueOf(m.group(1)),
|
||||||
|
Double.valueOf(m.group(3)));
|
||||||
posInQuery = true;
|
posInQuery = true;
|
||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
}
|
}
|
||||||
|
@ -103,7 +108,8 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
|
||||||
final String schemeSpecificPart = geoUri.getSchemeSpecificPart();
|
final String schemeSpecificPart = geoUri.getSchemeSpecificPart();
|
||||||
if (schemeSpecificPart != null && !schemeSpecificPart.isEmpty()) {
|
if (schemeSpecificPart != null && !schemeSpecificPart.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
final GeoPoint latlong = LocationHelper.parseLatLong(schemeSpecificPart);
|
final GeoPoint latlong =
|
||||||
|
LocationHelper.parseLatLong(schemeSpecificPart);
|
||||||
if (latlong != null && !posInQuery) {
|
if (latlong != null && !posInQuery) {
|
||||||
this.loc = latlong;
|
this.loc = latlong;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +135,8 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(final int requestCode,
|
public void onRequestPermissionsResult(
|
||||||
|
final int requestCode,
|
||||||
@NonNull final String[] permissions,
|
@NonNull final String[] permissions,
|
||||||
@NonNull final int[] grantResults) {
|
@NonNull final int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
@ -142,7 +149,7 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
public boolean onCreateOptionsMenu(@NotNull final Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
getMenuInflater().inflate(R.menu.menu_show_location, menu);
|
getMenuInflater().inflate(R.menu.menu_show_location, menu);
|
||||||
updateUi();
|
updateUi();
|
||||||
|
@ -167,11 +174,14 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_copy_location:
|
case R.id.action_copy_location:
|
||||||
final ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
final ClipboardManager clipboard =
|
||||||
|
(ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
if (clipboard != null) {
|
if (clipboard != null) {
|
||||||
final ClipData clip = ClipData.newPlainText("location", createGeoUri().toString());
|
final ClipData clip =
|
||||||
|
ClipData.newPlainText("location", createGeoUri().toString());
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
Toast.makeText(this,R.string.url_copied_to_clipboard,Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.url_copied_to_clipboard, Toast.LENGTH_SHORT)
|
||||||
|
.show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_share_location:
|
case R.id.action_share_location:
|
||||||
|
@ -182,8 +192,13 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
|
||||||
try {
|
try {
|
||||||
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with)));
|
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with)));
|
||||||
} catch (final ActivityNotFoundException e) {
|
} catch (final ActivityNotFoundException e) {
|
||||||
//This should happen only on faulty androids because normally chooser is always available
|
// This should happen only on faulty androids because normally chooser is always
|
||||||
Toast.makeText(this, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show();
|
// available
|
||||||
|
Toast.makeText(
|
||||||
|
this,
|
||||||
|
R.string.no_application_found_to_open_file,
|
||||||
|
Toast.LENGTH_SHORT)
|
||||||
|
.show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -191,21 +206,29 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startNavigation() {
|
private void startNavigation() {
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
|
final Intent intent = getStartNavigationIntent();
|
||||||
"google.navigation:q=" +
|
startActivity(intent);
|
||||||
this.loc.getLatitude() + "," + this.loc.getLongitude()
|
}
|
||||||
)));
|
|
||||||
|
private Intent getStartNavigationIntent() {
|
||||||
|
return new Intent(
|
||||||
|
Intent.ACTION_VIEW,
|
||||||
|
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();
|
||||||
|
@ -213,17 +236,11 @@ public class ShowLocationActivity extends LocationActivity implements LocationLi
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public void onProviderEnabled(final String provider) {
|
public void onProviderEnabled(@NotNull final String provider) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(final String provider) {
|
public void onProviderDisabled(@NotNull final String provider) {}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue