Skip to content

Commit

Permalink
Bump 1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
pluscubed committed Dec 12, 2017
1 parent 0f9e680 commit 0bf5d64
Show file tree
Hide file tree
Showing 34 changed files with 444 additions and 314 deletions.
44 changes: 22 additions & 22 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'io.fabric.tools:gradle:1.24.5'
classpath 'io.fabric.tools:gradle:1.25.1'
classpath 'com.squareup.sqldelight:gradle-plugin:0.6.1'
classpath 'com.google.gms:oss-licenses:0.9.1'
}
Expand All @@ -19,7 +19,7 @@ apply plugin: 'com.google.gms.oss.licenses.plugin'

android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
buildToolsVersion "27.0.2"

if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfigs {
Expand All @@ -41,9 +41,9 @@ android {
defaultConfig {
applicationId "com.pluscubed.velociraptor"
minSdkVersion 16
targetSdkVersion 25
versionCode 38
versionName "1.6.1"
targetSdkVersion 27
versionCode 39
versionName "1.6.2"
vectorDrawables.useSupportLibrary = true
manifestPlaceholders = [appName: "@string/app_name"]
multiDexEnabled true
Expand Down Expand Up @@ -117,23 +117,23 @@ dependencies {

compile 'com.squareup.sqlbrite:sqlbrite:1.1.2'

compile 'com.android.support:appcompat-v7:27.0.1'
compile 'com.android.support:support-v4:27.0.1'
compile 'com.android.support:support-v13:27.0.1'
compile 'com.android.support:support-annotations:27.0.1'
compile 'com.android.support:cardview-v7:27.0.1'
compile 'com.android.support:design:27.0.1'
compile 'com.android.support:customtabs:27.0.1'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:support-v4:27.0.2'
compile 'com.android.support:support-v13:27.0.2'
compile 'com.android.support:support-annotations:27.0.2'
compile 'com.android.support:cardview-v7:27.0.2'
compile 'com.android.support:design:27.0.2'
compile 'com.android.support:customtabs:27.0.2'

compile 'com.google.firebase:firebase-core:11.6.0'
compile 'com.google.firebase:firebase-messaging:11.6.0'
compile 'com.google.firebase:firebase-config:11.6.0'
compile 'com.google.firebase:firebase-core:11.6.2'
compile 'com.google.firebase:firebase-messaging:11.6.2'
compile 'com.google.firebase:firebase-config:11.6.2'

compile 'com.android.billingclient:billing:1.0'

compile 'com.google.android.gms:play-services-location:11.6.0'
compile 'com.google.android.gms:play-services-oss-licenses:11.6.0'
compile 'com.google.android.gms:play-services-maps:11.6.0'
compile 'com.google.android.gms:play-services-location:11.6.2'
compile 'com.google.android.gms:play-services-oss-licenses:11.6.2'
compile 'com.google.android.gms:play-services-maps:11.6.2'
compile 'com.google.maps.android:android-maps-utils:0.5'

compile 'com.stepstone.stepper:material-stepper:4.3.1'
Expand All @@ -151,9 +151,9 @@ dependencies {
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.squareup.okio:okio:1.13.0'

compile 'com.fasterxml.jackson.core:jackson-databind:2.9.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.3'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.3'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.3'

compile 'com.github.gigamole.arcprogressstackview:library:1.0.3'
compile 'com.github.pluscubed:recycler-fast-scroll:0.3.2'
Expand All @@ -170,7 +170,7 @@ dependencies {
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'

compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
compile('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
transitive = true;
}
compile 'com.android.support.constraint:constraint-layout:1.0.2'
Expand Down
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public LimitFetcher(Context context) {

OkHttpClient client = buildOkHttpClient();

this.osmLimitProvider = new OsmLimitProvider(context, client);
this.raptorLimitProvider = new RaptorLimitProvider(context, client, LimitCache.getInstance(context));
LimitCache cache = LimitCache.getInstance(context);
this.osmLimitProvider = new OsmLimitProvider(context, client, cache);
this.raptorLimitProvider = new RaptorLimitProvider(context, client, cache);
}

public static Retrofit buildRetrofit(OkHttpClient client, String baseUrl) {
Expand Down Expand Up @@ -64,8 +65,6 @@ public void verifyRaptorService(Purchase purchase) {
}

public Single<LimitResponse> getSpeedLimit(Location location) {
//TODO: Restructure as stream of error/missing/completed responses

String lastRoadName = lastResponse == null ? null : lastResponse.roadName();
Observable<LimitResponse> cacheQuery = LimitCache.getInstance(context)
.get(lastRoadName, new Coord(location));
Expand All @@ -91,6 +90,7 @@ public Single<LimitResponse> getSpeedLimit(Location location) {
.defaultIfEmpty(LimitResponse.builder().build());
}

//If it's from OSM & there's no valid speed limit
if (limitResponse.origin() == LimitResponse.ORIGIN_OSM
&& limitResponse.speedLimit() == -1) {
return finalRaptorQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@AutoValue
public abstract class LimitResponse {

// Higher origin = higher priority in cache
public static final int ORIGIN_HERE = 2;
public static final int ORIGIN_TOMTOM = 1;
public static final int ORIGIN_OSM = 0;
Expand All @@ -28,8 +27,7 @@ public static Builder builder() {
public abstract int origin();

/**
* In mph or km/h depending on setting
* -1 if limit does not exist
* In km/h, -1 if limit does not exist
*/
public abstract int speedLimit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.pluscubed.velociraptor.api.osm.data.OsmResponse;
import com.pluscubed.velociraptor.api.osm.data.Tags;
import com.pluscubed.velociraptor.cache.LimitCache;
import com.pluscubed.velociraptor.utils.PrefUtils;
import com.pluscubed.velociraptor.utils.Utils;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -39,12 +39,14 @@ public class OsmLimitProvider implements LimitProvider {
public static final int OSM_RADIUS = 15;
private Context context;
private OkHttpClient client;
private LimitCache cache;

private List<OsmApiEndpoint> osmOverpassApis;

public OsmLimitProvider(Context context, OkHttpClient client) {
public OsmLimitProvider(Context context, OkHttpClient client, LimitCache osmCache) {
this.context = context;
this.client = client;
this.cache = osmCache;

osmOverpassApis = new ArrayList<>();

Expand Down Expand Up @@ -138,8 +140,6 @@ public Observable<LimitResponse> getSpeedLimit(final Location location, LimitRes
return Observable.error(new Exception("OSM null response"));
}

boolean useMetric = PrefUtils.getUseMetric(context);

List<Element> elements = osmApi.getElements();

if (elements.isEmpty()) {
Expand Down Expand Up @@ -172,13 +172,13 @@ public Observable<LimitResponse> getSpeedLimit(final Location location, LimitRes
//Get speed limit
String maxspeed = tags.getMaxspeed();
if (maxspeed != null) {
responseBuilder.setSpeedLimit(parseOsmSpeedLimit(useMetric, maxspeed));
responseBuilder.setSpeedLimit(parseOsmSpeedLimit(maxspeed));
}

LimitResponse response = responseBuilder.build();

//Cache
LimitCache.getInstance(context).put(response);
cache.put(response);

if (element == bestMatch) {
bestResponse = response;
Expand All @@ -197,20 +197,15 @@ private String parseOsmRoadName(Tags tags) {
return tags.getRef() + ":" + tags.getName();
}

private int parseOsmSpeedLimit(boolean useMetric, String maxspeed) {
private int parseOsmSpeedLimit(String maxspeed) {
int speedLimit = -1;
if (maxspeed.matches("^-?\\d+$")) {
//is integer -> km/h
//If it is an integer, it is in km/h
speedLimit = Integer.valueOf(maxspeed);
if (!useMetric) {
speedLimit = (int) (speedLimit / 1.609344 + 0.5d);
}
} else if (maxspeed.contains("mph")) {
String[] split = maxspeed.split(" ");
speedLimit = Integer.valueOf(split[0]);
if (useMetric) {
speedLimit = (int) (speedLimit * 1.609344 + 0.5d);
}
speedLimit = Utils.convertMphToKmh(speedLimit);
}

return speedLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import rx.Observable
import rx.schedulers.Schedulers
import java.util.*

class RaptorLimitProvider(context: Context, client: OkHttpClient, limitCache: LimitCache) : LimitProvider {
class RaptorLimitProvider(context: Context, client: OkHttpClient, val limitCache: LimitCache) : LimitProvider {

private val raptorService: RaptorService
private val limitCache: LimitCache

private var id: String

Expand All @@ -28,7 +27,7 @@ class RaptorLimitProvider(context: Context, client: OkHttpClient, limitCache: Li

companion object {
@JvmField
val USE_DEBUG_ID = BuildConfig.BUILD_TYPE.equals("debug")
val USE_DEBUG_ID = BuildConfig.BUILD_TYPE == "debug"
}

init {
Expand All @@ -39,11 +38,9 @@ class RaptorLimitProvider(context: Context, client: OkHttpClient, limitCache: Li
val raptorRest = LimitFetcher.buildRetrofit(raptorClient, SERVER_URL)
raptorService = raptorRest.create(RaptorService::class.java)

this.limitCache = limitCache;

id = UUID.randomUUID().toString()
if (USE_DEBUG_ID) {
val resId = context.getResources().getIdentifier("debug_id", "string", context.getPackageName())
val resId = context.resources.getIdentifier("debug_id", "string", context.getPackageName())
if (resId != 0) {
id = context.getString(resId);
}
Expand Down Expand Up @@ -89,9 +86,9 @@ class RaptorLimitProvider(context: Context, client: OkHttpClient, limitCache: Li

private fun queryRaptorApi(here: Boolean, latitude: String, longitude: String, location: Location): Observable<LimitResponse>? {
val raptorQuery = if (here) {
raptorService.getHere("Bearer " + hereToken, id, latitude, longitude, location.bearing.toInt())
raptorService.getHere("Bearer " + hereToken, id, latitude, longitude, location.bearing.toInt(), "Metric")
} else {
raptorService.getTomtom("Bearer " + tomtomToken, id, latitude, longitude, location.bearing.toInt())
raptorService.getTomtom("Bearer " + tomtomToken, id, latitude, longitude, location.bearing.toInt(), "Metric")
}

return raptorQuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public interface RaptorService {

@GET("tomtom")
Single<RaptorResponse> getTomtom(@Header("Authorization") String authorization, @Query("id") String id,
@Query("lat") String lat, @Query("lng") String lng, @Query("vehicle_heading") int heading);
@Query("lat") String lat, @Query("lng") String lng, @Query("vehicle_heading") int heading, @Query("units") String units);

@GET("here")
Single<RaptorResponse> getHere(@Header("Authorization") String authorization, @Query("id") String id,
@Query("lat") String lat, @Query("lng") String lng, @Query("vehicle_heading") int heading);
@Query("lat") String lat, @Query("lng") String lng, @Query("vehicle_heading") int heading, @Query("units") String units);
}
31 changes: 17 additions & 14 deletions app/src/main/java/com/pluscubed/velociraptor/cache/LimitCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,24 @@ public Observable<LimitResponse> get(final String previousName, final Coord coor
return Observable.empty();
}

Collections.sort(ways, (way1, way2) -> {
if (way1.maxspeed() == -1 && way2.maxspeed() != -1) {
return 1;
} else if (way1.maxspeed() != -1 && way2.maxspeed() == -1) {
return -1;
} else {
return 0;
}
});
LimitResponse.Builder response = ways.get(0).toResponse();
for (LimitCacheWay way : ways) {
if (way.road() != null && way.road().equals(previousName)) {
response = way.toResponse();
break;
Collections.sort(ways, (way1, way2) -> Integer.compare((int) way2.origin(), (int) way1.origin()));

List<LimitCacheWay> validWays = Observable.from(ways)
.filter(way -> way.maxspeed() != 0)
.toList()
.toBlocking().first();

LimitResponse.Builder response;
if (!validWays.isEmpty()) {
response = validWays.get(0).toResponse();
for (LimitCacheWay way : validWays) {
if (way.road() != null && way.road().equals(previousName)) {
response = way.toResponse();
break;
}
}
} else {
response = ways.get(0).toResponse();
}

response.setFromCache(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
Expand Down Expand Up @@ -70,12 +71,14 @@ public FloatingView(LimitService service) {
private void inflateDebugging() {
mDebuggingText = (TextView) LayoutInflater.from(new ContextThemeWrapper(mService, R.style.Theme_Velociraptor))
.inflate(R.layout.floating_stats, null, false);

WindowManager.LayoutParams debuggingParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
getWindowType(),
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT);

debuggingParams.gravity = Gravity.BOTTOM;
try {
mWindowManager.addView(mDebuggingText, debuggingParams);
Expand All @@ -84,6 +87,12 @@ private void inflateDebugging() {
}
}

private int getWindowType() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY :
WindowManager.LayoutParams.TYPE_PHONE;
}

private void inflateMonitor() {
int layout;
switch (mStyle = PrefUtils.getSignStyle(mService)) {
Expand All @@ -104,7 +113,7 @@ private void inflateMonitor() {
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
getWindowType(),
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.START;
Expand Down
Loading

0 comments on commit 0bf5d64

Please sign in to comment.