-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 08f9c4f
Showing
46 changed files
with
1,568 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.sarcobjects.a500mts" | ||
minSdkVersion 24 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
implementation 'com.google.android.gms:play-services-maps:17.0.0' | ||
testImplementation 'junit:junit:4.13' | ||
testImplementation("org.assertj:assertj-core:3.15.0") | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
implementation 'com.google.android.gms:play-services-location:17.0.0' | ||
implementation 'com.google.android.libraries.places:places:2.2.0' | ||
implementation 'com.google.android.material:material:1.2.0-alpha06' | ||
implementation 'com.google.dagger:dagger:2.27' | ||
annotationProcessor 'com.google.dagger:dagger-compiler:2.27' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# 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 *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
27 changes: 27 additions & 0 deletions
27
app/src/androidTest/java/com/sarcobjects/a500mts/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.sarcobjects.a500mts; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Instrumented 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() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
|
||
assertEquals("com.sarcobjects.a500mts", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<resources> | ||
<!-- | ||
TODO: Before you run your application, you need a Google Maps API key. | ||
To get one, follow this link, follow the directions and press "Create" at the end: | ||
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=B3:C9:74:50:63:23:D2:82:39:80:E4:77:3C:D0:20:2F:2F:53:94:A7%3Bcom.sarcobjects.a500mts | ||
You can also add your credentials to an existing key, using these values: | ||
Package name: | ||
com.sarcobjects.a500mts | ||
SHA-1 certificate fingerprint: | ||
B3:C9:74:50:63:23:D2:82:39:80:E4:77:3C:D0:20:2F:2F:53:94:A7 | ||
Alternatively, follow the directions here: | ||
https://developers.google.com/maps/documentation/android/start#get-key | ||
Once you have your key (it starts with "AIza"), replace the "google_maps_key" | ||
string in this file. | ||
--> | ||
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyC6FjODLjcmW--MHjP4bE8UiI59l_FjMuY</string> | ||
<string name="bing_maps_key" templateMergeStrategy="preserve" translatable="false">ArgsggbF5gTrtoKqnQlE4TNy-aESLqhiVhbOIGDpfI8N3fPPD1e-F5REQqAhyuoa</string> | ||
<string name="here_maps_key" templateMergeStrategy="preserve" translatable="false">pH_tHAZNvmyxcvanHSGxYhwJT_zyuAUgLQxU0VrlQCw</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.sarcobjects.a500mts"> | ||
|
||
<!-- | ||
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use | ||
Google Maps Android API v2, but you must specify either coarse or fine | ||
location permissions for the 'MyLocation' functionality. | ||
--> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
<uses-permission android:name="android.permission.INTERNET " /> | ||
|
||
<application | ||
android:name=".android.MapApplication" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
|
||
<!-- | ||
The API key for Google Maps-based APIs is defined as a string resource. | ||
(See the file "res/values/google_maps_api.xml"). | ||
Note that the API key is linked to the encryption key used to sign the APK. | ||
You need a different API key for each encryption key, including the release key that is used to | ||
sign the APK for publishing. | ||
You can define the keys for the debug and release targets in src/debug/ and src/release/. | ||
--> | ||
<meta-data | ||
android:name="com.google.android.geo.API_KEY" | ||
android:value="@string/google_maps_key" /> | ||
|
||
<activity | ||
android:name=".MapsActivity" | ||
android:label="@string/title_activity_maps"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions
88
app/src/main/java/com/sarcobjects/a500mts/BingSnapToRoad.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.sarcobjects.a500mts; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import com.android.volley.Request; | ||
import com.android.volley.RequestQueue; | ||
import com.android.volley.Response; | ||
import com.android.volley.VolleyError; | ||
import com.android.volley.toolbox.JsonObjectRequest; | ||
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.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class BingSnapToRoad extends SnapToRoad { | ||
|
||
private static final String TAG = BingSnapToRoad.class.getSimpleName(); | ||
private static final String SNAP_URL = | ||
"https://dev.virtualearth.net/REST/v1/Routes/SnapToRoad?interpolate=true&includeSpeedLimit=false&includeTruckSpeedLimit=false&travelMode=walking&key=%s&points=%s"; | ||
private final Context context; | ||
|
||
public BingSnapToRoad(Context context) { | ||
this.angles = findAngles(16); | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
void snapToRoad(List<LatLng> coords, RequestQueue requestQueue, VolleyCallback<List<LatLng>> callback) { | ||
|
||
String key = context.getString(R.string.bing_maps_key); | ||
|
||
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, format(SNAP_URL, key, formatPaths(coords)), null, | ||
new Response.Listener<JSONObject>() { | ||
|
||
@Override | ||
public void onResponse(JSONObject response) { | ||
Log.i(TAG, response.toString()); | ||
List<LatLng> latLngs = new ArrayList<>(); | ||
try { | ||
JSONArray snapped = response.getJSONArray("resourceSets"); | ||
for (int i = 0; i < snapped.length(); i++) { | ||
JSONObject set = snapped.getJSONObject(i); | ||
JSONArray resources = set.getJSONArray("resources"); | ||
for (int j = 0; j < resources.length(); j++) { | ||
JSONObject snappedPoints = resources.getJSONObject(j); | ||
JSONArray points = snappedPoints.getJSONArray("snappedPoints"); | ||
for (int k = 0; k < points.length(); k++) { | ||
JSONObject point = points.getJSONObject(k); | ||
JSONObject coordinate = point.getJSONObject("coordinate"); | ||
latLngs.add(new LatLng(coordinate.getDouble("latitude"), coordinate.getDouble("longitude"))); | ||
Log.i(TAG, "Received point: " + coordinate); | ||
} | ||
} | ||
} | ||
} catch (JSONException e) { | ||
handleError(callback, e.getMessage(), R.string.error_json_parse); | ||
} | ||
callback.onSuccessResponse(latLngs); | ||
} | ||
}, | ||
new Response.ErrorListener() { | ||
|
||
@Override | ||
public void onErrorResponse(VolleyError error) { | ||
Log.e(TAG, "HTTP call didn't work: " + error.toString()); | ||
handleError(callback, "HTTP call didn't work: " + error.toString(), R.string.error_http_call); | ||
} | ||
}); | ||
|
||
requestQueue.add(request); | ||
} | ||
|
||
|
||
String formatPaths(List<LatLng> latLngs) { | ||
return latLngs.stream() | ||
.map(l -> l.latitude + "," + l.longitude) | ||
.collect(Collectors.joining(";")); | ||
|
||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/sarcobjects/a500mts/GoogleSnapToRoad.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.sarcobjects.a500mts; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import com.android.volley.Request; | ||
import com.android.volley.RequestQueue; | ||
import com.android.volley.Response; | ||
import com.android.volley.VolleyError; | ||
import com.android.volley.toolbox.JsonObjectRequest; | ||
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.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class GoogleSnapToRoad extends SnapToRoad { | ||
|
||
private static final String TAG = GoogleSnapToRoad.class.getSimpleName(); | ||
private static final String SNAP_URL = "https://roads.googleapis.com/v1/snapToRoads?interpolate=true&key=%s&path=%s"; | ||
|
||
private Context context; | ||
|
||
@Inject | ||
public GoogleSnapToRoad(Context context) { | ||
this.angles = findAngles(12); | ||
this.context = context; | ||
} | ||
|
||
//for test | ||
public GoogleSnapToRoad(int slices) { | ||
this.angles = findAngles(slices); | ||
} | ||
|
||
@Override | ||
public void snapToRoad(List<LatLng> coords, RequestQueue requestQueue, VolleyCallback<List<LatLng>> callback) { | ||
|
||
String key = context.getString(R.string.google_maps_key); | ||
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, format(SNAP_URL, key, formatPaths(coords)), null, | ||
new Response.Listener<JSONObject>() { | ||
|
||
@Override | ||
public void onResponse(JSONObject response) { | ||
List<LatLng> latLngs = new ArrayList<>(); | ||
try { | ||
JSONArray snapped = response.getJSONArray("snappedPoints"); | ||
for (int i = 0; i < snapped.length(); i++) { | ||
JSONObject point = snapped.getJSONObject(i); | ||
JSONObject location = point.getJSONObject("location"); | ||
latLngs.add(new LatLng(location.getDouble("latitude"), location.getDouble("longitude"))); | ||
Log.i(TAG, "Received point: " + location); | ||
} | ||
} catch (JSONException e) { | ||
handleError(callback, e.getMessage(), R.string.error_json_parse); | ||
} | ||
callback.onSuccessResponse(latLngs); | ||
} | ||
}, | ||
new Response.ErrorListener() { | ||
|
||
@Override | ||
public void onErrorResponse(VolleyError error) { | ||
Log.e(TAG, "HTTP call didn't work: " + error.toString()); | ||
handleError(callback, "HTTP call didn't work: " + error.toString(), R.string.error_http_call); | ||
} | ||
}); | ||
|
||
requestQueue.add(request); | ||
} | ||
|
||
|
||
String formatPaths(List<LatLng> latLngs) { | ||
return latLngs.stream() | ||
.map(l -> l.latitude + "," + l.longitude) | ||
.collect(Collectors.joining("|")); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.