-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.gradle | ||
/app | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.2.0' | ||
classpath 'com.google.gms:google-services:3.0.0' | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 24 | ||
buildToolsVersion "24.0.1" | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 24 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:24.2.1' | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.google.android.gms:play-services:9.6.1' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/tarGz/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ahmadrosid.lib.drawroutemap; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumentation test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.ahmadrosid.lib.drawroutemap.test", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.ahmadrosid.lib.drawroutemap"> | ||
|
||
<application android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
> | ||
|
||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.ahmadrosid.lib.drawroutemap; | ||
|
||
import com.google.android.gms.maps.model.LatLng; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by ocittwo on 11/14/16. | ||
* | ||
* @Author Ahmad Rosid | ||
* @Email [email protected] | ||
* @Github https://github.com/ar-android | ||
* @Web http://ahmadrosid.com | ||
*/ | ||
public class DataRouteParser { | ||
|
||
/** | ||
* Receives a JSONObject and returns a list of lists containing latitude and longitude | ||
*/ | ||
public List<List<HashMap<String, String>>> parse(JSONObject jObject) { | ||
|
||
List<List<HashMap<String, String>>> routes = new ArrayList<>(); | ||
JSONArray jRoutes; | ||
JSONArray jLegs; | ||
JSONArray jSteps; | ||
|
||
try { | ||
|
||
jRoutes = jObject.getJSONArray("routes"); | ||
|
||
/** Traversing all routes */ | ||
for (int i = 0; i < jRoutes.length(); i++) { | ||
jLegs = ((JSONObject) jRoutes.get(i)).getJSONArray("legs"); | ||
List path = new ArrayList<>(); | ||
|
||
/** Traversing all legs */ | ||
for (int j = 0; j < jLegs.length(); j++) { | ||
jSteps = ((JSONObject) jLegs.get(j)).getJSONArray("steps"); | ||
|
||
/** Traversing all steps */ | ||
for (int k = 0; k < jSteps.length(); k++) { | ||
String polyline = ""; | ||
polyline = (String) ((JSONObject) ((JSONObject) jSteps.get(k)).get("polyline")).get("points"); | ||
List<LatLng> list = decodePoly(polyline); | ||
|
||
/** Traversing all points */ | ||
for (int l = 0; l < list.size(); l++) { | ||
HashMap<String, String> hm = new HashMap<>(); | ||
hm.put("lat", Double.toString((list.get(l)).latitude)); | ||
hm.put("lng", Double.toString((list.get(l)).longitude)); | ||
path.add(hm); | ||
} | ||
} | ||
routes.add(path); | ||
} | ||
} | ||
|
||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return routes; | ||
} | ||
|
||
/** | ||
* Method to decode polyline points | ||
* Courtesy : http://jeffreysambells.com/2010/05/27/decoding-polylines-from-google-maps-direction-api-with-java | ||
*/ | ||
private List<LatLng> decodePoly(String encoded) { | ||
|
||
List<LatLng> poly = new ArrayList<>(); | ||
int index = 0, len = encoded.length(); | ||
int lat = 0, lng = 0; | ||
|
||
while (index < len) { | ||
int b, shift = 0, result = 0; | ||
do { | ||
b = encoded.charAt(index++) - 63; | ||
result |= (b & 0x1f) << shift; | ||
shift += 5; | ||
} while (b >= 0x20); | ||
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); | ||
lat += dlat; | ||
|
||
shift = 0; | ||
result = 0; | ||
do { | ||
b = encoded.charAt(index++) - 63; | ||
result |= (b & 0x1f) << shift; | ||
shift += 5; | ||
} while (b >= 0x20); | ||
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); | ||
lng += dlng; | ||
|
||
LatLng p = new LatLng((((double) lat / 1E5)), | ||
(((double) lng / 1E5))); | ||
poly.add(p); | ||
} | ||
|
||
return poly; | ||
} | ||
} |