Cleanup
This commit is contained in:
parent
c4de64c63f
commit
92682f4d1d
1 changed files with 28 additions and 25 deletions
|
@ -5,19 +5,18 @@ import android.content.ActivityNotFoundException;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import org.ligi.passandroid.R;
|
|
||||||
import org.ligi.passandroid.model.PassLocation;
|
|
||||||
import org.ligi.passandroid.model.Pass;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import org.ligi.passandroid.R;
|
||||||
|
import org.ligi.passandroid.model.Pass;
|
||||||
|
import org.ligi.passandroid.model.PassLocation;
|
||||||
|
|
||||||
public class NavigateToLocationsDialog {
|
public class NavigateToLocationsDialog {
|
||||||
|
|
||||||
public static void perform(final Activity activity, final Pass pass, final boolean finishOnDone) {
|
public static void perform(@Nonnull final Activity activity, @Nonnull final Pass pass, final boolean finishOnDone) {
|
||||||
final List<PassLocation> locations = pass.getLocations();
|
final List<PassLocation> locations = pass.getLocations();
|
||||||
|
|
||||||
if (locations.size() == 0) {
|
if (locations.size() == 0) {
|
||||||
|
@ -26,20 +25,21 @@ public class NavigateToLocationsDialog {
|
||||||
startIntentForLocation(activity, locations.get(0));
|
startIntentForLocation(activity, locations.get(0));
|
||||||
done(activity, finishOnDone);
|
done(activity, finishOnDone);
|
||||||
} else if (locations.size() > 1) {
|
} else if (locations.size() > 1) {
|
||||||
String[] locationDescriptions = new String[locations.size()];
|
final String[] locationDescriptions = new String[locations.size()];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (PassLocation loc : locations) {
|
for (PassLocation loc : locations) {
|
||||||
locationDescriptions[i++] = loc.getDescription();
|
locationDescriptions[i++] = loc.getDescription();
|
||||||
}
|
}
|
||||||
new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.choose_location)).setItems(locationDescriptions, new DialogInterface.OnClickListener() {
|
new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.choose_location))
|
||||||
@Override
|
.setItems(locationDescriptions, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
startIntentForLocation(activity, locations.get(which));
|
startIntentForLocation(activity, locations.get(which));
|
||||||
done(activity, finishOnDone);
|
done(activity, finishOnDone);
|
||||||
}
|
}
|
||||||
}).show();
|
})
|
||||||
|
.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,18 +51,12 @@ public class NavigateToLocationsDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startIntentForLocation(Activity activity, PassLocation location) {
|
private static void startIntentForLocation(Activity activity, PassLocation location) {
|
||||||
Intent i = new Intent();
|
final Intent i = new Intent(Intent.ACTION_VIEW);
|
||||||
i.setAction(Intent.ACTION_VIEW);
|
|
||||||
|
|
||||||
String description = "";
|
final String description = getEncodedDescription(location);
|
||||||
try {
|
|
||||||
description = URLEncoder.encode(location.getDescription(), "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e1) {
|
|
||||||
// OK - no descripion
|
|
||||||
}
|
|
||||||
|
|
||||||
PassLocation.LatLng latlng = location.latlng;
|
final PassLocation.LatLng latlng = location.latlng;
|
||||||
String latAndLonStr = latlng.lat + "," + latlng.lon;
|
final String latAndLonStr = latlng.lat + "," + latlng.lon;
|
||||||
i.setData(Uri.parse("geo:" + latAndLonStr + "?q=" + latAndLonStr + "(" + description + ")"));
|
i.setData(Uri.parse("geo:" + latAndLonStr + "?q=" + latAndLonStr + "(" + description + ")"));
|
||||||
try {
|
try {
|
||||||
activity.startActivity(i);
|
activity.startActivity(i);
|
||||||
|
@ -73,4 +67,13 @@ public class NavigateToLocationsDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getEncodedDescription(final PassLocation location) {
|
||||||
|
try {
|
||||||
|
return URLEncoder.encode(location.getDescription(), "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e1) {
|
||||||
|
// OK - no description
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue