Skip to content

Commit

Permalink
445: upgrade target SDK to 30 (Android 11) (cyclestreets#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlockwood authored and HilaryN committed Mar 4, 2021
1 parent 45a040d commit 846d2e0
Show file tree
Hide file tree
Showing 22 changed files with 508 additions and 54 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ext {
// Remember to keep these values in sync with .travis.yml
compileSdkVersion=30
minSdkVersion=23
targetSdkVersion=29
targetSdkVersion=30
buildToolsVersion='30.0.2'

// centrally manage some other dependencies
Expand Down
4 changes: 4 additions & 0 deletions cyclestreets.app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="net.cyclestreets.views.CircularRouteActivity"
android:parentActivityName="net.cyclestreets.CycleStreets">
</activity>

<!-- Allows CycleStreets-created files to be written into by the camera app -->
<provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class RoutePlans {
public final static String PLAN_FASTEST = "fastest";
public final static String PLAN_QUIETEST = "quietest";
public final static String PLAN_SHORTEST = "shortest";
public final static String PLAN_LEISURE = "leisure";

private final static String[] Plans = new String[] {
PLAN_QUIETEST, PLAN_BALANCED, PLAN_FASTEST, PLAN_SHORTEST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package net.cyclestreets.api

import android.content.Context
import android.content.pm.PackageManager
import net.cyclestreets.RoutePlans.PLAN_LEISURE

import net.cyclestreets.api.client.RetrofitApiClient
import net.cyclestreets.core.R

interface CycleStreetsApi {
fun getJourneyJson(plan: String, leaving: String?, arriving: String?, speed: Int, lonLat: DoubleArray): String
fun getJourneyJson(plan: String, itineraryId: Long): String
fun getCircularJourneyJson(lonLat: DoubleArray, distance: Int?, duration: Int?, poiTypes: String?): String
fun getPhotomapCategories(): PhotomapCategories
fun getPhoto(photoId: Long): Photos
fun getPhotos(lonW: Double, latS: Double, lonE: Double, latN: Double): Photos
Expand Down Expand Up @@ -91,6 +93,9 @@ object ApiClient : CycleStreetsApi {
override fun getJourneyJson(plan: String, itineraryId: Long): String {
return delegate.getJourneyJson(plan, itineraryId)
}
override fun getCircularJourneyJson(lonLat: DoubleArray, distance: Int?, duration: Int?, poiTypes: String?): String {
return delegate.getCircularJourneyJson(lonLat, distance, duration, poiTypes)
}
override fun getPhotomapCategories(): PhotomapCategories {
return delegate.getPhotomapCategories()
}
Expand Down Expand Up @@ -148,6 +153,14 @@ class ApiClientImpl(private val retrofitApiClient: RetrofitApiClient): CycleStre
return retrofitApiClient.retrievePreviousJourneyJson(plan, itineraryId)
}

override fun getCircularJourneyJson(lonLat: DoubleArray,
distance: Int?,
duration: Int?,
poiTypes: String?): String {
val point = itineraryPoints(*lonLat)
return retrofitApiClient.getCircularJourneyJson(PLAN_LEISURE, point, distance, duration, poiTypes)
}

override fun getPhotomapCategories(): PhotomapCategories {
return retrofitApiClient.photomapCategories
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,34 @@ public class JourneyPlanner {
public static String getJourneyJson(final String plan,
final int speed,
final Waypoints waypoints) {
final double[] lonLat = new double[waypoints.count() * 2];
for (int i = 0; i != waypoints.count(); ++i) {
int l = i * 2;
lonLat[l] = waypoints.get(i).getLongitude();
lonLat[l + 1] = waypoints.get(i).getLatitude();
}
return ApiClient.INSTANCE.getJourneyJson(plan,
null,
null,
speed,
lonLat);
lonLat(waypoints));
}

public static String getJourneyJson(final String plan,
final long itinerary) {
return ApiClient.INSTANCE.getJourneyJson(plan, itinerary);
}

public static String getCircularJourneyJson(final Waypoints waypoints,
Integer distance,
Integer duration,
String pois) {
return ApiClient.INSTANCE.getCircularJourneyJson(lonLat(waypoints), distance, duration, pois);
}

private static double[] lonLat(Waypoints waypoints) {
final double[] lonLat = new double[waypoints.count() * 2];
for (int i = 0; i != waypoints.count(); ++i) {
int l = i * 2;
lonLat[l] = waypoints.get(i).getLongitude();
lonLat[l + 1] = waypoints.get(i).getLatitude();
}
return lonLat;
}

private JourneyPlanner() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private const val V1API_JSON_JOLT_SPEC = """[{
}
}
}
}
},
"error": "Error"
}
}]"""
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class RetrofitApiClient {
private final BlogApi blogApi;
private final Context context;

private static final String REPORT_ERRORS = "1";

// ~30KB covers /news/feed/, /v2/pois.types and /v2/photomap.categories - allow 200KB for headroom
private static final int CACHE_MAX_SIZE_BYTES = 200 * 1024;
private static final String CACHE_DIR_NAME = "RetrofitApiClientCache";
Expand Down Expand Up @@ -146,13 +148,22 @@ public String getJourneyJson(final String plan,
final String leaving,
final String arriving,
final int speed) throws IOException {
Response<String> response = v1Api.getJourneyJson(plan, itineraryPoints, leaving, arriving, speed).execute();
Response<String> response = v1Api.getJourneyJson(plan, itineraryPoints, leaving, arriving, speed, REPORT_ERRORS).execute();
return JourneyStringTransformerKt.fromV1ApiJson(response.body());
}

public String getCircularJourneyJson(final String plan,
final String itineraryPoints,
final Integer distance,
final Integer duration,
final String poitypes) throws IOException {
Response<String> response = v1Api.getCircularJourneyJson(plan, itineraryPoints, distance, duration, poitypes, REPORT_ERRORS).execute();
return JourneyStringTransformerKt.fromV1ApiJson(response.body());
}

public String retrievePreviousJourneyJson(final String plan,
final long itineraryId) throws IOException {
Response<String> response = v1Api.retrievePreviousJourneyJson(plan, itineraryId).execute();
Response<String> response = v1Api.retrievePreviousJourneyJson(plan, itineraryId, REPORT_ERRORS).execute();
return JourneyStringTransformerKt.fromV1ApiJson(response.body());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ Call<String> getJourneyJson(@Query("plan") String plan,
@Query("itinerarypoints") String itineraryPoints,
@Query("leaving") String leaving,
@Query("arriving") String arriving,
@Query("speed") int speed);
@Query("speed") int speed,
@Query("reporterrors") String reportErrors);

@GET("/api/journey.json")
Call<String> retrievePreviousJourneyJson(@Query("plan") String plan,
@Query("itinerary") long itineraryId);
@Query("itinerary") long itineraryId,
@Query("reporterrors") String reportErrors);

@GET("/api/journey.json")
Call<String> getCircularJourneyJson(@Query("plan") String plan,
@Query("itinerarypoints") String itineraryPoints,
@Query("distance") Integer distance,
@Query("duration") Integer duration,
@Query("poitypes") String poitypes,
@Query("reporterrors") String reportErrors);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import net.cyclestreets.routing.Route
import net.cyclestreets.routing.Waypoints

import android.Manifest
import android.app.Activity
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
Expand Down Expand Up @@ -40,7 +42,7 @@ class RouteMapFragment : CycleMapFragment(), Route.Listener {
overlayPushBottom(POIOverlay(mapView()))
overlayPushBottom(RouteOverlay())

routeSetter = TapToRouteOverlay(mapView())
routeSetter = TapToRouteOverlay(mapView(), this)
overlayPushTop(routeSetter)

hasGps = GPS.deviceHasGPS(requireContext())
Expand Down Expand Up @@ -99,6 +101,19 @@ class RouteMapFragment : CycleMapFragment(), Route.Listener {

}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if ((requestCode == TapToRouteOverlay.CIRCULAR_ROUTE_ACTIVITY_REQUEST_CODE) && (resultCode == Activity.RESULT_OK)) {
if (data != null) {
Route.plotCircularRoute(RoutePlans.PLAN_LEISURE,
data.getIntExtra("circular_route_distance", 0),
data.getIntExtra("circular_route_duration", 0),
null,
requireContext())
}
}
}

private fun startLiveRide() {
doOrRequestPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) {
LiveRideActivity.launch(requireContext())
Expand Down
35 changes: 22 additions & 13 deletions libraries/cyclestreets-view/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application android:supportsRtl="false">
<activity android:name="net.cyclestreets.AccountDetailsActivity"
android:label="Account Details"
android:windowSoftInputMode="stateVisible|adjustResize" />
<activity android:name="net.cyclestreets.FeedbackActivity"
android:label="Route Comments"
android:windowSoftInputMode="stateVisible|adjustResize" />
<activity android:name="net.cyclestreets.LiveRideActivity"
android:label="LiveRide"
android:launchMode="singleTop"
android:screenOrientation="portrait" />
<activity
android:name="net.cyclestreets.views.CircularRouteActivity"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
</activity>
<activity
android:name="net.cyclestreets.AccountDetailsActivity"
android:label="Account Details"
android:windowSoftInputMode="stateVisible|adjustResize" />
<activity
android:name="net.cyclestreets.FeedbackActivity"
android:label="Route Comments"
android:windowSoftInputMode="stateVisible|adjustResize" />
<activity
android:name="net.cyclestreets.LiveRideActivity"
android:label="LiveRide"
android:launchMode="singleTop"
android:screenOrientation="portrait" />

<service android:name="net.cyclestreets.liveride.LiveRideService"
android:foregroundServiceType="location"/>
<service
android:name="net.cyclestreets.liveride.LiveRideService"
android:foregroundServiceType="location" />
</application>
</manifest>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ internal class ReplanFromHere(previous: LiveRideState, whereIam: GeoPoint) : Liv
next = this

val activeSegment = Route.journey().activeSegment()
// if waypoints size is 1, it's a circular route, so need to get waypoints from Segment.Waymark's
if (Route.waypoints().count() == 1) {
for (waymark in Route.journey().segments) {
if (waymark is Segment.Waymark) {
Log.d(TAG, "Waymark points " + waymark.points().toString())
Route.waypoints().add(waymark.start().latitude, waymark.start().longitude)
}
}
// Add final waypoint (which is same as starting point):
Route.waypoints().first()?.let { Route.waypoints().add(it) }
}
val remainingWaypoints: Waypoints = when (activeSegment) {
is Segment.Start -> Route.waypoints().startingWith(whereIam)
is Segment.End -> Waypoints.fromTo(whereIam, Route.waypoints().last())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import net.cyclestreets.view.R

internal open class CycleStreetsRoutingTask(private val routeType: String,
private val speed: Int,
context: Context) : RoutingTask<Waypoints>(R.string.route_finding_new, context) {
context: Context,
private val distance: Int? = null,
private val duration: Int? = null,
private val pois: String? = null) : RoutingTask<Waypoints>(R.string.route_finding_new, context) {
override fun doInBackground(vararg waypoints: Waypoints): RouteData? {
val wp = waypoints[0]
return fetchRoute(routeType, speed, wp)
return fetchRoute(routeType, -1, speed, wp, distance, duration, pois)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Journey private constructor(wp: Waypoints? = null) {
fun speed(): Int { return start().speed() }
fun totalDistance(): Int { return end().totalDistance() }
fun totalTime(): Int { return end().totalTime() }
fun otherRoutes(): String {return start().otherRoutes()}

fun remainingDistance(distanceUntilTurn: Int): Int {
val actSeg = activeSegment()
Expand Down Expand Up @@ -158,11 +159,19 @@ class Journey private constructor(wp: Waypoints? = null) {
}

private fun populateWaypoints(jdo: JourneyDomainObject) {
// waypoints will have the points tapped on the screen. But if we are retrieving an existing route
// (e.g. by number) then it will be empty, so needs to be populated from the json - the route
// retrieved from the server.
if (journey.waypoints.count() == 0) {
for (gp in jdo.waypoints) {
journey.waypoints.add(gp)
}
}
// For leisure / circular routes there is no waypoint in the json.
// Put the start point into waypoints so it can be displayed on the screen.
if (journey.waypoints.count() == 0) {
journey.waypoints.add(jdo.route.start_latitude, jdo.route.start_longitude)
}
}

private fun populateSegments(jdo: JourneyDomainObject) {
Expand Down Expand Up @@ -205,7 +214,7 @@ class Journey private constructor(wp: Waypoints? = null) {

private fun generateStartAndFinishSegments(jdo: JourneyDomainObject) {
val from = journey.waypoints.first()
val to = journey.waypoints.last()
val to = if (journey.waypoints.isEmpty()) null else journey.waypoints.last()

val pStart = journey.segments.startPoint()
val pEnd = journey.segments.finishPoint()
Expand All @@ -219,6 +228,7 @@ class Journey private constructor(wp: Waypoints? = null) {
totalDistance,
jdo.route.calories,
jdo.route.grammesCO2saved,
jdo.route.otherRoutes,
listOf(pD(from, pStart), pStart)
)
val endSeg = Segment.End(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ object Route {
query.execute(waypoints)
}

@JvmStatic
fun plotCircularRoute(plan: String,
distance: Int?,
duration: Int?,
pois: String?,
context: Context) {
val query = CycleStreetsRoutingTask(plan, 0, context, distance, duration, pois)
query.execute(waypoints_)
}

fun LiveReplanRoute(plan: String,
speed: Int,
context: Context,
Expand Down
Loading

0 comments on commit 846d2e0

Please sign in to comment.