Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
- chg: updated GH library to v. 0.9.0
Browse files Browse the repository at this point in the history
- chg: updated Locus API to v. 0.2.10
  • Loading branch information
menion committed Jul 25, 2017
1 parent 15a9d60 commit fb151c0
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 53 deletions.
17 changes: 9 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
versionCode 10
versionName '0.3'
versionCode 11
versionName '0.4'

minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
Expand Down Expand Up @@ -65,17 +65,18 @@ android {

dependencies {
// get locus API
compile 'com.asamm:locus-api-android:0.2.6'
compile 'com.asamm:locus-api-android:0.2.10'

// add current GraphHopper
// https://mvnrepository.com/artifact/com.graphhopper/graphhopper-web
compile(group: 'com.graphhopper', name: 'graphhopper', version: '0.7.0') {
// add GraphHopper dependency
// https://github.com/graphhopper/graphhopper/tree/master/android
compile(group: 'com.graphhopper', name: 'graphhopper-core', version: '0.9.0') {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'org.openstreetmap.osmosis', module: 'osmosis-osm-binary'
exclude group: 'org.apache.xmlgraphics', module: 'xmlgraphics-commons'
}
compile 'org.slf4j:slf4j-simple:1.7.12'
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'org.slf4j:slf4j-android:1.7.25'

// Android support libraries
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:appcompat-v7:25.3.1'
}
130 changes: 91 additions & 39 deletions src/main/java/com/asamm/locus/addon/graphhopper/RoutingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.routing.util.FlagEncoderFactory;
import com.graphhopper.routing.weighting.FastestWeighting;
import com.graphhopper.routing.weighting.ShortestWeighting;
import com.graphhopper.routing.weighting.Weighting;
import com.graphhopper.util.Instruction;
import com.graphhopper.util.Parameters;
import com.graphhopper.util.PointList;
Expand All @@ -27,7 +30,8 @@
import locus.api.android.features.computeTrack.ComputeTrackParameters;
import locus.api.android.features.computeTrack.ComputeTrackService;
import locus.api.android.utils.LocusUtils;
import locus.api.objects.extra.ExtraData;
import locus.api.objects.enums.PointRteAction;
import locus.api.objects.extra.GeoDataExtra;
import locus.api.objects.extra.Location;
import locus.api.objects.extra.Track;
import locus.api.objects.extra.Waypoint;
Expand Down Expand Up @@ -68,6 +72,7 @@ public int[] getTrackTypes() {

// load encoders
EncodingManager em = getGraphHooper().getEncodingManager();
List<Weighting> weightings = getGraphHooper().getCHFactoryDecorator().getWeightings();
List<Integer> types = new ArrayList<>();

// get all encoders
Expand All @@ -77,24 +82,50 @@ public int[] getTrackTypes() {
// add car
switch (encType) {
case FlagEncoderFactory.CAR:
types.add(ExtraData.VALUE_RTE_TYPE_CAR_FAST);
types.add(ExtraData.VALUE_RTE_TYPE_CAR_SHORT);
boolean carAdded = false;
for (Weighting weighting : weightings) {
if (weighting instanceof FastestWeighting) {
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_CAR_FAST, types);
carAdded = true;
} else if (weighting instanceof ShortestWeighting) {
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_CAR_SHORT, types);
carAdded = true;
}
}

// add basic "car" if no car type exists
if (!carAdded) {
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_CAR, types);
}
break;
case FlagEncoderFactory.MOTORCYCLE:
types.add(ExtraData.VALUE_RTE_TYPE_MOTORCYCLE);
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_MOTORCYCLE, types);
break;
case FlagEncoderFactory.BIKE:
types.add(ExtraData.VALUE_RTE_TYPE_CYCLE_FAST);
types.add(ExtraData.VALUE_RTE_TYPE_CYCLE_SHORT);
boolean bikeAdded = false;
for (Weighting weighting : weightings) {
if (weighting instanceof FastestWeighting) {
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_CYCLE_FAST, types);
bikeAdded = true;
} else if (weighting instanceof ShortestWeighting) {
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_CYCLE_SHORT, types);
bikeAdded = true;
}
}

// add basic "bike" if no bike type exists
if (!bikeAdded) {
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_CYCLE, types);
}
break;
case FlagEncoderFactory.MOUNTAINBIKE:
types.add(ExtraData.VALUE_RTE_TYPE_CYCLE_MTB);
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_CYCLE_MTB, types);
break;
case FlagEncoderFactory.RACINGBIKE:
types.add(ExtraData.VALUE_RTE_TYPE_CYCLE_RACING);
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_CYCLE_RACING, types);
break;
case FlagEncoderFactory.FOOT:
types.add(ExtraData.VALUE_RTE_TYPE_FOOT);
addTrackType(GeoDataExtra.VALUE_RTE_TYPE_FOOT_01, types);
break;
default:
Logger.logW(TAG, "getTrackTypes()," +
Expand All @@ -111,6 +142,17 @@ public int[] getTrackTypes() {
return typesA;
}

/**
* Add certain type into possible routing types.
* @param type type to add
* @param types types container
*/
private void addTrackType(int type, List<Integer> types) {
if (!types.contains(type)) {
types.add(type);
}
}

@Override
public Intent getIntentForSettings() {
Intent intent = new Intent();
Expand All @@ -135,32 +177,38 @@ public Track computeTrack(LocusUtils.LocusVersion lv, ComputeTrackParameters par
String vehicle = FlagEncoderFactory.CAR;
String weighting = "";
switch (params.getType()) {
case ExtraData.VALUE_RTE_TYPE_CAR_FAST:
case GeoDataExtra.VALUE_RTE_TYPE_CAR:
vehicle = FlagEncoderFactory.CAR;
break;
case GeoDataExtra.VALUE_RTE_TYPE_CAR_FAST:
vehicle = FlagEncoderFactory.CAR;
weighting = "fastest";
break;
case ExtraData.VALUE_RTE_TYPE_CAR_SHORT:
case GeoDataExtra.VALUE_RTE_TYPE_CAR_SHORT:
vehicle = FlagEncoderFactory.CAR;
weighting = "shortest";
break;
case ExtraData.VALUE_RTE_TYPE_MOTORCYCLE:
case GeoDataExtra.VALUE_RTE_TYPE_MOTORCYCLE:
vehicle = FlagEncoderFactory.MOTORCYCLE;
break;
case ExtraData.VALUE_RTE_TYPE_CYCLE_FAST:
case GeoDataExtra.VALUE_RTE_TYPE_CYCLE:
vehicle = FlagEncoderFactory.BIKE;
break;
case GeoDataExtra.VALUE_RTE_TYPE_CYCLE_FAST:
vehicle = FlagEncoderFactory.BIKE;
weighting = "fastest";
break;
case ExtraData.VALUE_RTE_TYPE_CYCLE_SHORT:
case GeoDataExtra.VALUE_RTE_TYPE_CYCLE_SHORT:
vehicle = FlagEncoderFactory.BIKE;
weighting = "shortest";
break;
case ExtraData.VALUE_RTE_TYPE_CYCLE_MTB:
case GeoDataExtra.VALUE_RTE_TYPE_CYCLE_MTB:
vehicle = FlagEncoderFactory.MOUNTAINBIKE;
break;
case ExtraData.VALUE_RTE_TYPE_CYCLE_RACING:
case GeoDataExtra.VALUE_RTE_TYPE_CYCLE_RACING:
vehicle = FlagEncoderFactory.RACINGBIKE;
break;
case ExtraData.VALUE_RTE_TYPE_FOOT:
case GeoDataExtra.VALUE_RTE_TYPE_FOOT_01:
vehicle = FlagEncoderFactory.FOOT;
break;
}
Expand Down Expand Up @@ -290,25 +338,25 @@ private Track createTrackFromResult(GHResponse resp, boolean instructions) {
// create instruction waypoint
Waypoint wpt = new Waypoint();
wpt.setLocation(firstLoc);
wpt.addParameter(ExtraData.PAR_RTE_POINT_ACTION,
graphHopperActionToLocus(inst));
wpt.addParameter(GeoDataExtra.PAR_RTE_POINT_ACTION,
graphHopperActionToLocus(inst).getId());

// set name
if (inst.getName().length() > 0) {
wpt.addParameter(ExtraData.PAR_RTE_STREET, inst.getName());
wpt.addParameter(GeoDataExtra.PAR_RTE_STREET, inst.getName());
}

// set speed and distance parameters
wpt.addParameter(ExtraData.PAR_RTE_DISTANCE_F,
wpt.addParameter(GeoDataExtra.PAR_RTE_DISTANCE_F,
Float.toString((float) inst.getDistance()));
wpt.addParameter(ExtraData.PAR_RTE_TIME_I,
wpt.addParameter(GeoDataExtra.PAR_RTE_TIME_I,
(int) (inst.getTime() / 1000.0));
track.getWaypoints().add(wpt);

// use "Via instruction"
if (viaInstruction != null) {
wpt.addParameter(ExtraData.PAR_RTE_POINT_ACTION,
ExtraData.VALUE_RTE_ACTION_PASS_PLACE);
wpt.addParameter(GeoDataExtra.PAR_RTE_POINT_ACTION,
PointRteAction.PASS_PLACE.getId());
viaInstruction = null;
}

Expand Down Expand Up @@ -355,20 +403,19 @@ private Location createLocation(PointList points, int index) {
* @param inst instruction on certain place
* @return code of action in Locus system
*/
private int graphHopperActionToLocus(Instruction inst) {
private PointRteAction graphHopperActionToLocus(Instruction inst) {
// get roundabout
if (inst.getSign() == Instruction.USE_ROUNDABOUT) {

// handle special instruction. If roundabout is not defined by it, rather ignore it,
// then notify incorrect exit
if (inst instanceof RoundaboutInstruction) {
RoundaboutInstruction instRb = (RoundaboutInstruction) inst;
return ExtraData.VALUE_RTE_ACTION_ROUNDABOUT_EXIT_1 +
(instRb.getExitNumber() - 1);
return PointRteAction.getActionRoundabout(instRb.getExitNumber());
} else {
Logger.logW(TAG, "graphHopperActionToLocus(" + inst + "), " +
"invalid Roundabout instruction");
return ExtraData.VALUE_RTE_ACTION_NO_MANEUVER;
return PointRteAction.NO_MANEUVER;
}
}

Expand All @@ -378,36 +425,41 @@ private int graphHopperActionToLocus(Instruction inst) {
// TURN RIGHT

case Instruction.TURN_SLIGHT_RIGHT:
return ExtraData.VALUE_RTE_ACTION_RIGHT_SLIGHT;
return PointRteAction.RIGHT_SLIGHT;
case Instruction.TURN_RIGHT:
return ExtraData.VALUE_RTE_ACTION_RIGHT;
return PointRteAction.RIGHT;
case Instruction.TURN_SHARP_RIGHT:
return ExtraData.VALUE_RTE_ACTION_RIGHT_SHARP;
return PointRteAction.RIGHT_SHARP;

// TURN LEFT

case Instruction.TURN_SLIGHT_LEFT:
return ExtraData.VALUE_RTE_ACTION_LEFT_SLIGHT;
return PointRteAction.LEFT_SLIGHT;
case Instruction.TURN_LEFT:
return ExtraData.VALUE_RTE_ACTION_LEFT;
return PointRteAction.LEFT;
case Instruction.TURN_SHARP_LEFT:
return ExtraData.VALUE_RTE_ACTION_LEFT_SHARP;
return PointRteAction.LEFT_SHARP;

// VARIOUS

case Instruction.CONTINUE_ON_STREET:
return ExtraData.VALUE_RTE_ACTION_CONTINUE_STRAIGHT;
return PointRteAction.CONTINUE_STRAIGHT;
case Instruction.KEEP_RIGHT:
return PointRteAction.STAY_RIGHT;
case Instruction.KEEP_LEFT:
return PointRteAction.STAY_LEFT;

case Instruction.FINISH:
return ExtraData.VALUE_RTE_ACTION_ARRIVE_DEST;
return PointRteAction.ARRIVE_DEST;
case Instruction.REACHED_VIA:
return ExtraData.VALUE_RTE_ACTION_PASS_PLACE;
return PointRteAction.PASS_PLACE;

// IGNORED

case Instruction.LEAVE_ROUNDABOUT:
return ExtraData.VALUE_RTE_ACTION_NO_MANEUVER;
return PointRteAction.NO_MANEUVER;
default:
return ExtraData.VALUE_RTE_ACTION_NO_MANEUVER;
return PointRteAction.NO_MANEUVER;
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/asamm/locus/addon/graphhopper/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Utils {
* @param ctx current context
* @return <code>true</code> if Locus is available
*/
public static boolean existsValidLocus(Context ctx) {
static boolean existsValidLocus(Context ctx) {
return LocusUtils.isLocusAvailable(ctx, LocusUtils.VersionCode.UPDATE_11);
}

Expand All @@ -41,7 +41,7 @@ public static boolean existsValidLocus(Context ctx) {
* @param ctx current context
* @return File as root GH directory or null if not defined or any problem happen
*/
public static File getRootDirectory(Context ctx) {
static File getRootDirectory(Context ctx) {
// check Locus version
if (!existsValidLocus(ctx)) {
Logger.logW(TAG, "getAvailableData(" + ctx + "), " +
Expand Down Expand Up @@ -76,7 +76,7 @@ public static File getRootDirectory(Context ctx) {
* @return list of all available routing items
* @throws locus.api.android.utils.exceptions.RequiredVersionMissingException
*/
public static List<File> getAvailableData(Context ctx) throws RequiredVersionMissingException {
static List<File> getAvailableData(Context ctx) throws RequiredVersionMissingException {
// container for data
List<File> res = new ArrayList<>();

Expand Down Expand Up @@ -137,7 +137,7 @@ private static void getAvailableData(File item, List<File> container) {
* @param ctx current context
* @return defined path to routing item
*/
public static File getCurrentRoutingItem(Context ctx) {
static File getCurrentRoutingItem(Context ctx) {
// get and check dir
String dir = PreferenceManager.getDefaultSharedPreferences(ctx).
getString(KEY_S_DATA_ITEM_PATH, "");
Expand All @@ -158,10 +158,10 @@ public static File getCurrentRoutingItem(Context ctx) {
* @param ctx current context
* @param file selected item
*/
public static void setCurrentRoutingItem(Context ctx, File file) {
static void setCurrentRoutingItem(Context ctx, File file) {
PreferenceManager.getDefaultSharedPreferences(ctx).
edit().
putString(KEY_S_DATA_ITEM_PATH, file.getAbsolutePath()).
commit();
apply();
}
}

0 comments on commit fb151c0

Please sign in to comment.