Skip to content

Commit

Permalink
Upgrade Navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Jul 22, 2020
1 parent a397bc2 commit deb4d88
Showing 1 changed file with 24 additions and 27 deletions.
Expand Up @@ -13,6 +13,7 @@
import android.util.Log;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.Options;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
Expand All @@ -21,6 +22,7 @@
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.common.TransportMethod;
import com.google.appinventor.components.common.YaVersion;
import com.google.appinventor.components.runtime.util.AsynchUtil;
import com.google.appinventor.components.runtime.util.ErrorMessages;
Expand Down Expand Up @@ -65,24 +67,6 @@ public class Navigation extends AndroidNonvisibleComponent implements Component
private String language = "en";
private YailDictionary lastResponse = YailDictionary.makeDictionary();

enum TransportMethod {
DEFAULT ("foot-walking"),
DRIVING ("driving-car"),
CYCLING ("cycling-regular"),
WALKING ("foot-walking"),
WHEELCHAIR ("wheelchair");

private final String method;

TransportMethod(String method) {
this.method = method;
}

private String method() {
return method;
}
}

/**
* Creates a Navigation component.
*
Expand All @@ -93,7 +77,7 @@ public Navigation(ComponentContainer container) {
apiKey = "";
startLocation = new GeoPoint(0.0, 0.0);
endLocation = new GeoPoint(0.0, 0.0);
method = TransportMethod.DEFAULT;
method = TransportMethod.Foot;
}

/**
Expand Down Expand Up @@ -238,8 +222,15 @@ public double EndLongitude() {
}

@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public String TransportationMethod() {
return method.method();
public @Options(TransportMethod.class) String TransportationMethod() {
return method.getValue();
}

/**
* Returns the current transportation method.
*/
public TransportMethod TransportationMethodAbstract() {
return method;
}

/**
Expand All @@ -255,14 +246,20 @@ public String TransportationMethod() {
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NAVIGATION_METHOD,
defaultValue = "foot-walking")
@SimpleProperty(description = "The transportation method used for determining the route.")
public void TransportationMethod(String method) {
for (TransportMethod t : TransportMethod.values()) {
if (method.equals(t.method())) {
this.method = t;
}
public void TransportationMethod(@Options(TransportMethod.class) String method) {
TransportMethod t = TransportMethod.get(method);
if (t != null) {
TransportationMethodAbstract(t);
}
}

/**
* Sets the current transportation method.
*/
public void TransportationMethodAbstract(TransportMethod method) {
this.method = method;
}

@SimpleProperty(description = "Set the end location.")
public void EndLocation(MapFeature feature) {
GeoPoint point = feature.getCentroid();
Expand Down Expand Up @@ -332,7 +329,7 @@ public void GotDirections(YailList directions, YailList points, double distance,

private void performRequest(GeoPoint start, GeoPoint end, TransportMethod method)
throws IOException, JSONException {
final String finalURL = serviceUrl + method.method() + "/geojson/";
final String finalURL = serviceUrl + method.getValue() + "/geojson/";
URL url = new URL(finalURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
Expand Down

0 comments on commit deb4d88

Please sign in to comment.