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.Intent;
|
||||
import android.net.Uri;
|
||||
|
||||
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.net.URLEncoder;
|
||||
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 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();
|
||||
|
||||
if (locations.size() == 0) {
|
||||
|
@ -26,20 +25,21 @@ public class NavigateToLocationsDialog {
|
|||
startIntentForLocation(activity, locations.get(0));
|
||||
done(activity, finishOnDone);
|
||||
} else if (locations.size() > 1) {
|
||||
String[] locationDescriptions = new String[locations.size()];
|
||||
final String[] locationDescriptions = new String[locations.size()];
|
||||
|
||||
int i = 0;
|
||||
for (PassLocation loc : locations) {
|
||||
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))
|
||||
.setItems(locationDescriptions, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
startIntentForLocation(activity, locations.get(which));
|
||||
done(activity, finishOnDone);
|
||||
}
|
||||
}).show();
|
||||
})
|
||||
.show();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -51,18 +51,12 @@ public class NavigateToLocationsDialog {
|
|||
}
|
||||
|
||||
private static void startIntentForLocation(Activity activity, PassLocation location) {
|
||||
Intent i = new Intent();
|
||||
i.setAction(Intent.ACTION_VIEW);
|
||||
final Intent i = new Intent(Intent.ACTION_VIEW);
|
||||
|
||||
String description = "";
|
||||
try {
|
||||
description = URLEncoder.encode(location.getDescription(), "UTF-8");
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
// OK - no descripion
|
||||
}
|
||||
final String description = getEncodedDescription(location);
|
||||
|
||||
PassLocation.LatLng latlng = location.latlng;
|
||||
String latAndLonStr = latlng.lat + "," + latlng.lon;
|
||||
final PassLocation.LatLng latlng = location.latlng;
|
||||
final String latAndLonStr = latlng.lat + "," + latlng.lon;
|
||||
i.setData(Uri.parse("geo:" + latAndLonStr + "?q=" + latAndLonStr + "(" + description + ")"));
|
||||
try {
|
||||
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