diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 3cfecd6..5f4a8b6 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -9,15 +9,22 @@
-
+
+
+
+
+
+
+
+
-
+
@@ -159,7 +166,14 @@
1676537805415
-
+
+ 1676538610453
+
+
+
+ 1676538610453
+
+
@@ -181,6 +195,7 @@
-
+
+
\ No newline at end of file
diff --git a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/AbstractRouting.java b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/AbstractRouting.java
index adbea99..d0d4a7b 100644
--- a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/AbstractRouting.java
+++ b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/AbstractRouting.java
@@ -9,8 +9,7 @@
public abstract class AbstractRouting extends AsyncTask> {
protected ArrayList listenerArrayList = new ArrayList<>();
- protected static final String DIRECTIONS_API_URL = "https://maps.googleapis.com/maps/api/directions/json?";
- private Exceptions exceptions = null;
+ private ErrorHandling errorHandling = null;
protected AbstractRouting(RouteListener listener) {
this.registerListener(listener);
@@ -30,7 +29,7 @@ protected void dispatchOnStart() {
}
- protected void dispatchOnFailure(Exceptions exception) {
+ protected void dispatchOnFailure(ErrorHandling exception) {
for (RouteListener mListener : this.listenerArrayList) {
mListener.onRouteFailure(exception);
}
@@ -55,9 +54,9 @@ protected ArrayList doInBackground(Void... voids) {
ArrayList result = new ArrayList<>();
try {
- result = (new GoogleParser(this.constructURL())).parse();
- } catch (Exceptions var4) {
- this.exceptions = var4;
+ result = (new RouteJsonParser(this.constructURL())).parse();
+ } catch (ErrorHandling errorHandling) {
+ this.errorHandling = errorHandling;
}
return result;
@@ -75,7 +74,7 @@ protected void onPostExecute(ArrayList result) {
int minDistance = Integer.MAX_VALUE;
for(int i = 0; i < result.size(); ++i) {
- PolylineOptions mOptions = new PolylineOptions();
+ PolylineOptions polylineOptions = new PolylineOptions();
RouteInfoModel routeInfoModel = result.get(i);
if (routeInfoModel.getLength() < minDistance) {
shortestRouteIndex = i;
@@ -83,15 +82,15 @@ protected void onPostExecute(ArrayList result) {
}
for (LatLng point : routeInfoModel.getPoints()) {
- mOptions.add(point);
+ polylineOptions.add(point);
}
- result.get(i).setPolyOptions(mOptions);
+ result.get(i).setPolyOptions(polylineOptions);
}
this.dispatchOnSuccess(result, shortestRouteIndex);
} else {
- this.dispatchOnFailure(this.exceptions);
+ this.dispatchOnFailure(this.errorHandling);
}
}
@@ -105,16 +104,16 @@ public enum AvoidKind {
HIGHWAYS(2, "highways"),
FERRIES(4, "ferries");
- private final String _sRequestParam;
- private final int _sBitValue;
+ private final String param;
+ private final int bit;
AvoidKind(int bit, String param) {
- this._sBitValue = bit;
- this._sRequestParam = param;
+ this.bit = bit;
+ this.param = param;
}
int getBitValue() {
- return this._sBitValue;
+ return this.bit;
}
static String getRequestParam(int bit) {
@@ -122,8 +121,8 @@ static String getRequestParam(int bit) {
AvoidKind[] arr$ = values();
for (AvoidKind kind : arr$) {
- if ((bit & kind._sBitValue) == kind._sBitValue) {
- ret = ret + kind._sRequestParam;
+ if ((bit & kind.bit) == kind.bit) {
+ ret = ret + kind.param;
ret = ret + "|";
}
}
diff --git a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/Exceptions.java b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/ErrorHandling.java
similarity index 69%
rename from GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/Exceptions.java
rename to GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/ErrorHandling.java
index e6937c8..d814e39 100644
--- a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/Exceptions.java
+++ b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/ErrorHandling.java
@@ -5,11 +5,12 @@
import org.json.JSONException;
import org.json.JSONObject;
-public class Exceptions extends Exception {
+public class ErrorHandling extends Exception {
private String statusCode;
private String message;
+ private int status;
- public Exceptions(JSONObject json) {
+ public ErrorHandling(JSONObject json) {
if (json == null) {
this.statusCode = "";
this.message = "Cannot parse";
@@ -18,13 +19,17 @@ public Exceptions(JSONObject json) {
this.statusCode = json.getString("status");
this.message = json.getString("error_message");
} catch (JSONException e) {
- Log.e("RouteInfoModel json error" , "JSON parsing error : " + e.getMessage());
+ Log.e("route json error" , "JSON parsing error : " + e.getMessage());
}
}
}
- public Exceptions(String msg) {
+ public ErrorHandling(int status){
+ this.status = status;
+ }
+
+ public ErrorHandling(String msg) {
this.message = msg;
}
diff --git a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/KeyConstants.java b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/KeyConstants.java
new file mode 100644
index 0000000..5673fb9
--- /dev/null
+++ b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/KeyConstants.java
@@ -0,0 +1,11 @@
+package com.codebyashish.googledirectionapi;
+
+public class KeyConstants {
+
+ public static String DIRECTION_BASE_URL = "https://maps.googleapis.com/maps/api/directions/json?";
+ public static String START_LOCATION = "start_location";
+ public static String START_ADDRESS = "start_address";
+ public static String END_ADDRESS = "end_address";
+ public static String OK = "OK";
+
+}
diff --git a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteDrawing.java b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteDrawing.java
index 185f768..d1ec1c1 100644
--- a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteDrawing.java
+++ b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteDrawing.java
@@ -27,7 +27,7 @@ private RouteDrawing(Builder builder) {
}
protected String constructURL() {
- StringBuilder stringBuilder = new StringBuilder("https://maps.googleapis.com/maps/api/directions/json?");
+ StringBuilder stringBuilder = new StringBuilder(KeyConstants.DIRECTION_BASE_URL);
LatLng origin = this.waypoints.get(0);
stringBuilder.append("origin=");
stringBuilder.append(origin.latitude);
diff --git a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteInfoModel.java b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteInfoModel.java
index 24f8cce..b168c9b 100644
--- a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteInfoModel.java
+++ b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteInfoModel.java
@@ -10,7 +10,7 @@
public class RouteInfoModel {
private String name;
private final List points = new ArrayList<>();
- private List segments = new ArrayList<>();
+ private List stepsModels = new ArrayList<>();
private String copyright;
private String warning;
private String country;
@@ -72,8 +72,8 @@ public void setDistanceValue(int distanceValue) {
this.distanceValue = distanceValue;
}
- public void setSegments(List segments) {
- this.segments = segments;
+ public void setSegments(List stepsModels) {
+ this.stepsModels = stepsModels;
}
public RouteInfoModel() {
@@ -91,12 +91,12 @@ public List getPoints() {
return this.points;
}
- public void addSegment(Segment s) {
- this.segments.add(s);
+ public void addSegment(StepsModel s) {
+ this.stepsModels.add(s);
}
- public List getSegments() {
- return this.segments;
+ public List getSegments() {
+ return this.stepsModels;
}
public void setName(String name) {
diff --git a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/GoogleParser.java b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteJsonParser.java
similarity index 81%
rename from GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/GoogleParser.java
rename to GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteJsonParser.java
index 84fb097..9e23692 100644
--- a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/GoogleParser.java
+++ b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteJsonParser.java
@@ -1,11 +1,5 @@
package com.codebyashish.googledirectionapi;
-//
-// Source code recreated from a .class file by IntelliJ IDEA
-// (powered by FernFlower decompiler)
-//
-
-
import android.util.Log;
import com.google.android.gms.maps.model.LatLng;
@@ -21,29 +15,29 @@
import java.util.ArrayList;
import java.util.List;
-public class GoogleParser extends XMLParser {
+public class RouteJsonParser extends XMLParser {
private int distance;
- private String OK = "OK";
- public GoogleParser(String feedUrl) {
+
+ public RouteJsonParser(String feedUrl) {
super(feedUrl);
}
- public ArrayList parse() throws Exceptions {
+ public ArrayList parse() throws ErrorHandling {
ArrayList routeInfoModels = new ArrayList<>();
String result = convertStreamToString(this.getInputStream());
if (result == null) {
- throw new Exceptions("Result is null");
+ throw new ErrorHandling("No result found");
} else {
try {
JSONObject json = new JSONObject(result);
- if (!json.getString("status").equals(this.OK)) {
- throw new Exceptions(json);
+ if (!json.getString("status").equals(KeyConstants.OK)) {
+ throw new ErrorHandling(json);
} else {
JSONArray jsonRoutes = json.getJSONArray("routes");
for(int i = 0; i < jsonRoutes.length(); ++i) {
RouteInfoModel routeInfoModel = new RouteInfoModel();
- Segment segment = new Segment();
+ StepsModel stepsModel = new StepsModel();
JSONObject jsonRoute = jsonRoutes.getJSONObject(i);
JSONObject jsonBounds = jsonRoute.getJSONObject("bounds");
JSONObject jsonNortheast = jsonBounds.getJSONObject("northeast");
@@ -51,8 +45,8 @@ public ArrayList parse() throws Exceptions {
routeInfoModel.setLatLgnBounds(new LatLng(jsonNortheast.getDouble("lat"), jsonNortheast.getDouble("lng")), new LatLng(jsonSouthwest.getDouble("lat"), jsonSouthwest.getDouble("lng")));
JSONObject leg = jsonRoute.getJSONArray("legs").getJSONObject(0);
JSONArray steps = leg.getJSONArray("steps");
- int numSteps = steps.length();
- routeInfoModel.setName(leg.getString("start_address") + " to " + leg.getString("end_address"));
+
+ routeInfoModel.setName(leg.getString(KeyConstants.START_ADDRESS) + " to " + leg.getString(KeyConstants.END_ADDRESS));
routeInfoModel.setCopyright(jsonRoute.getString("copyrights"));
routeInfoModel.setDurationText(leg.getJSONObject("duration").getString("text"));
routeInfoModel.setDurationValue(leg.getJSONObject("duration").getInt("value"));
@@ -64,18 +58,18 @@ public ArrayList parse() throws Exceptions {
routeInfoModel.setWarning(jsonRoute.getJSONArray("warnings").getString(0));
}
- for(int y = 0; y < numSteps; ++y) {
+ for(int y = 0; y < steps.length(); ++y) {
JSONObject step = steps.getJSONObject(y);
- JSONObject start = step.getJSONObject("start_location");
+ JSONObject start = step.getJSONObject(KeyConstants.START_LOCATION);
LatLng position = new LatLng(start.getDouble("lat"), start.getDouble("lng"));
- segment.setPoint(position);
+ stepsModel.setPoint(position);
int length = step.getJSONObject("distance").getInt("value");
this.distance += length;
- segment.setLength(length);
- segment.setDistance((double)this.distance / 1000.0);
- segment.setInstruction(step.getString("html_instructions").replaceAll("<(.*?)*>", ""));
+ stepsModel.setLength(length);
+ stepsModel.setDistance((double)this.distance / 1000.0);
+ stepsModel.setInstruction(step.getString("html_instructions").replaceAll("<(.*?)*>", ""));
routeInfoModel.addPoints(this.decodePolyLine(step.getJSONObject("polyline").getString("points")));
- routeInfoModel.addSegment(segment.copy());
+ routeInfoModel.addSegment(stepsModel.copy());
}
routeInfoModels.add(routeInfoModel);
@@ -84,7 +78,7 @@ public ArrayList parse() throws Exceptions {
return routeInfoModels;
}
} catch (JSONException var20) {
- throw new Exceptions("JSONException. Msg: " + var20.getMessage());
+ throw new ErrorHandling("JSONException. Msg: " + var20.getMessage());
}
}
}
diff --git a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteListener.java b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteListener.java
index 8449345..8c21a92 100644
--- a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteListener.java
+++ b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/RouteListener.java
@@ -3,7 +3,7 @@
import java.util.ArrayList;
public interface RouteListener {
- void onRouteFailure(Exceptions e);
+ void onRouteFailure(ErrorHandling e);
void onRouteStart();
diff --git a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/Segment.java b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/StepsModel.java
similarity index 88%
rename from GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/Segment.java
rename to GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/StepsModel.java
index a944a53..842cd79 100644
--- a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/Segment.java
+++ b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/StepsModel.java
@@ -3,13 +3,13 @@
import com.google.android.gms.maps.model.LatLng;
-public class Segment {
+public class StepsModel {
private LatLng start;
private String instruction;
private int length;
private double distance;
- public Segment() {
+ public StepsModel() {
}
public void setInstruction(String turn) {
@@ -28,8 +28,8 @@ public LatLng startPoint() {
return this.start;
}
- public Segment copy() {
- Segment copy = new Segment();
+ public StepsModel copy() {
+ StepsModel copy = new StepsModel();
copy.start = this.start;
copy.instruction = this.instruction;
copy.length = this.length;
diff --git a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/XMLParser.java b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/XMLParser.java
index 2966a8e..87418ba 100644
--- a/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/XMLParser.java
+++ b/GoogleDirectionApi/src/main/java/com/codebyashish/googledirectionapi/XMLParser.java
@@ -13,8 +13,8 @@ public class XMLParser {
protected XMLParser(String feedUrl) {
try {
this.feedUrl = new URL(feedUrl);
- } catch (MalformedURLException var3) {
- Log.e("RouteDrawing Error", var3.getMessage());
+ } catch (MalformedURLException e) {
+ Log.e("RouteDrawing Error", e.getMessage());
}
}
@@ -22,8 +22,8 @@ protected XMLParser(String feedUrl) {
protected InputStream getInputStream() {
try {
return this.feedUrl.openConnection().getInputStream();
- } catch (IOException var2) {
- Log.e("RouteDrawing Error", var2.getMessage());
+ } catch (IOException e) {
+ Log.e("RouteDrawing Error", e.getMessage());
return null;
}
}