Skip to content

Commit

Permalink
Compilation issue on class Routing / Lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fcduarte authored and Felipe Duarte committed Oct 19, 2015
1 parent 3a60f76 commit fff771b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum TravelMode {

protected String _sValue;

private TravelMode(String sValue) {
TravelMode(String sValue) {
this._sValue = sValue;
}

Expand All @@ -47,7 +47,7 @@ public enum AvoidKind {
private final String _sRequestParam;
private final int _sBitValue;

private AvoidKind (int bit, String param) {
AvoidKind(int bit, String param) {
this._sBitValue = bit;
this._sRequestParam = param;
}
Expand Down Expand Up @@ -107,8 +107,7 @@ private void dispatchOnCancelled() {
* Performs the call to the google maps API to acquire routing data and
* deserializes it to a format the map can display.
*
* @param
* @return
* @return an array list containing the routes
*/
@Override
protected ArrayList<Route> doInBackground(Void... voids) {
Expand Down
3 changes: 2 additions & 1 deletion library/src/main/java/com/directions/route/GoogleParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static String convertStreamToString(final InputStream input) {
final BufferedReader reader = new BufferedReader(new InputStreamReader(input));
final StringBuilder sBuf = new StringBuilder();

String line = null;
String line;
try {
while ((line = reader.readLine()) != null) {
sBuf.append(line);
Expand All @@ -140,6 +140,7 @@ private static String convertStreamToString(final InputStream input) {
} finally {
try {
input.close();
reader.close();
} catch (IOException e) {
Log.e("Routing Error", e.getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/directions/route/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

//. by Haseem Saheed
public interface Parser {
public List<Route> parse();
List<Route> parse();
}
56 changes: 28 additions & 28 deletions library/src/main/java/com/directions/route/Routing.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.android.gms.maps.model.LatLng;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -25,63 +26,64 @@ private Routing(Builder builder) {
this.avoidKinds = builder.avoidKinds;
this.optimize = builder.optimize;
this.alternativeRoutes = builder.alternativeRoutes;
this.language = builder.language;
}

protected String constructURL () {
final StringBuffer stringBuffer = new StringBuffer(AbstractRouting.DIRECTIONS_API_URL);
final StringBuilder stringBuilder = new StringBuilder(AbstractRouting.DIRECTIONS_API_URL);

// origin
final LatLng origin = waypoints.get(0);
stringBuffer.append("origin=");
stringBuffer.append(origin.latitude);
stringBuffer.append(',');
stringBuffer.append(origin.longitude);
stringBuilder.append("origin=");
stringBuilder.append(origin.latitude);
stringBuilder.append(',');
stringBuilder.append(origin.longitude);

// destination
final LatLng destination = waypoints.get(waypoints.size() - 1);
stringBuffer.append("&destination=");
stringBuffer.append(destination.latitude);
stringBuffer.append(',');
stringBuffer.append(destination.longitude);
stringBuilder.append("&destination=");
stringBuilder.append(destination.latitude);
stringBuilder.append(',');
stringBuilder.append(destination.longitude);

// travel
stringBuffer.append("&mode=");
stringBuffer.append(travelMode.getValue());
stringBuilder.append("&mode=");
stringBuilder.append(travelMode.getValue());

// waypoints
if (waypoints.size() > 2) {
stringBuffer.append("&waypoints=");
stringBuilder.append("&waypoints=");
if(optimize)
stringBuffer.append("optimize:true|");
stringBuilder.append("optimize:true|");
for (int i = 1; i < waypoints.size() - 1; i++) {
final LatLng p = waypoints.get(i);
stringBuffer.append("via:"); // we don't want to parse the resulting JSON for 'legs'.
stringBuffer.append(p.latitude);
stringBuffer.append(",");
stringBuffer.append(p.longitude);
stringBuffer.append("|");
stringBuilder.append("via:"); // we don't want to parse the resulting JSON for 'legs'.
stringBuilder.append(p.latitude);
stringBuilder.append(",");
stringBuilder.append(p.longitude);
stringBuilder.append("|");
}
}

// avoid
if (avoidKinds > 0) {
stringBuffer.append("&avoid=");
stringBuffer.append(AvoidKind.getRequestParam(avoidKinds));
stringBuilder.append("&avoid=");
stringBuilder.append(AvoidKind.getRequestParam(avoidKinds));
}

if (alternativeRoutes == true) {
stringBuffer.append("&alternatives=true");
if (alternativeRoutes) {
stringBuilder.append("&alternatives=true");
}

// sensor
stringBuffer.append("&sensor=true");
stringBuilder.append("&sensor=true");

// language
if (language != null) {
stringBuffer.append("&language=").append(language);
stringBuilder.append("&language=").append(language);
}

return stringBuffer.toString();
return stringBuilder.toString();
}

public static class Builder {
Expand Down Expand Up @@ -116,9 +118,7 @@ public Builder alternativeRoutes (boolean alternativeRoutes) {

public Builder waypoints (LatLng... points) {
waypoints.clear();
for (LatLng p : points) {
waypoints.add(p);
}
Collections.addAll(waypoints, points);
return this;
}

Expand Down
10 changes: 4 additions & 6 deletions library/src/main/java/com/directions/route/RoutingListener.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.directions.route;

import com.google.android.gms.maps.model.PolylineOptions;

import java.util.ArrayList;

public interface RoutingListener {
public void onRoutingFailure();
void onRoutingFailure();

public void onRoutingStart();
void onRoutingStart();

public void onRoutingSuccess(ArrayList<Route> route,int shortestRouteIndex);
void onRoutingSuccess(ArrayList<Route> route, int shortestRouteIndex);

public void onRoutingCancelled();
void onRoutingCancelled();
}

0 comments on commit fff771b

Please sign in to comment.