Skip to content

Commit

Permalink
- New start tab: Contains the closest address for the users coordinat…
Browse files Browse the repository at this point in the history
…es and frequently used tasks

- More compact layout for the track tab (#4)
- Precise bearing value was added to the distance and bearing label in the point details
  (see the already existing menu item with the same name in the navigate tab for details)
- New presets for way class weights. Makes it easier to calculate routes for
  different use cases like hiking or walking in urban areas.
- Talkback actions have been added to the bearing and location buttons in the
  tool bar: Enable / disable simulation and select bearing source (compass or GPS).
- Point context menu:
    - New entry: Navigate directly to this point
    - Rename and annotation entries were moved into the edit sub menu
- Fixed: Route calculation failed if one or more via points were included.
  • Loading branch information
Eric Scheibler committed Nov 6, 2024
1 parent ca495a7 commit 77fe465
Show file tree
Hide file tree
Showing 48 changed files with 1,484 additions and 417 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ android {
// WalkersGuide server url
buildConfigField 'String', 'SERVER_URL', '"https://api.walkersguide.org/"'
buildConfigField 'String', 'SERVER_URL_DEV', '"https://api.test.walkersguide.org/"'
// public-transport-enabler library
buildConfigField 'String', 'PTE_LINK_MAIN_WEBSITE', '"https://github.com/schildbach/public-transport-enabler"'
buildConfigField 'String', 'PTE_LINK_PROVIDER_LIST', '"https://github.com/schildbach/public-transport-enabler/tree/master/src/de/schildbach/pte"'
}

signingConfigs {
Expand Down Expand Up @@ -143,3 +146,4 @@ repositories {
dirs 'libs'
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ public Builder setReversed(final boolean reversed) throws JSONException {

public Builder setViaPoints(final Point via1, final Point via2, final Point via3) throws JSONException {
if (via1 != null) {
inputData.put(KEY_VIA_POINT_1, via1);
inputData.put(KEY_VIA_POINT_1, via1.toJson());
}
if (via2 != null) {
inputData.put(KEY_VIA_POINT_2, via2);
inputData.put(KEY_VIA_POINT_2, via2.toJson());
}
if (via3 != null) {
inputData.put(KEY_VIA_POINT_3, via3);
inputData.put(KEY_VIA_POINT_3, via3.toJson());
}
return this;
}
Expand Down Expand Up @@ -366,6 +366,10 @@ public Point getViaPoint3() {
return this.viaPoint3;
}

public boolean hasViaPoint() {
return getViaPoint1() != null || getViaPoint2() != null || getViaPoint3() != null;
}


/**
* super class methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class AnnouncementRadius implements Serializable {
private static final long serialVersionUID = 1l;
private static final int[] values = new int[]{ 25, 50, 100, 250, 500, 1000 };
private static final int[] values = new int[]{ 25, 50, 75, 100, 150, 200, 250, 500, 750, 1000 };

public static ArrayList<AnnouncementRadius> values() {
ArrayList<AnnouncementRadius> announcementRadiusList = new ArrayList<AnnouncementRadius>();
Expand All @@ -38,10 +38,18 @@ private AnnouncementRadius(int meter) throws IllegalArgumentException {
this.meter = meter;
}

@Override public String toString() {
public String longFormat() {
return GlobalInstance.getPluralResource(R.plurals.meter, this.meter);
}

public String shortFormat() {
return GlobalInstance.getPluralResource(R.plurals.meterShort, this.meter);
}

@Override public String toString() {
return longFormat();
}

@Override public int hashCode() {
return this.meter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ public BearingSensor getSelectedBearingSensor() {
public void setSelectedBearingSensor(BearingSensor newBearingSensor) {
if (newBearingSensor != null) {
settingsManagerInstance.setSelectedBearingSensor(newBearingSensor);
LocalBroadcastManager.getInstance(GlobalInstance.getContext()).sendBroadcast(new Intent(ACTION_BEARING_SENSOR_CHANGED));
broadcastBearingSensorChanged();
broadcastCurrentBearing(true);
}
}

public void broadcastBearingSensorChanged() {
LocalBroadcastManager.getInstance(GlobalInstance.getContext())
.sendBroadcast(new Intent(ACTION_BEARING_SENSOR_CHANGED));
}

public boolean isDeviceUpright() {
return this.deviceUpright;
}
Expand Down Expand Up @@ -517,26 +522,39 @@ && getSelectedBearingSensor() == BearingSensor.SATELLITE) {
* simulated bearing
*/

// enable / disable simulation
public static final String ACTION_SIMULATION_STATUS_CHANGED = "bearingSimulationStatusChanged";
public static final String EXTRA_SIMULATION_ENABLED = "bearingSimulationEnabled";

private boolean simulationEnabled = false;

public boolean getSimulationEnabled() {
return this.simulationEnabled;
}

public void setSimulationEnabled(boolean enabled) {
this.simulationEnabled = enabled;
broadcastCurrentBearing(true);
if (getSimulationEnabled() != enabled) {
this.simulationEnabled = enabled;
broadcastSimulationStatusChanged();
broadcastCurrentBearing(true);
}
}

private void broadcastSimulationStatusChanged() {
Intent intent = new Intent(ACTION_SIMULATION_STATUS_CHANGED);
intent.putExtra(EXTRA_SIMULATION_ENABLED, getSimulationEnabled());
LocalBroadcastManager.getInstance(GlobalInstance.getContext()).sendBroadcast(intent);
}

// change simulated bearing
public static final String ACTION_NEW_SIMULATED_BEARING = "new_simulated_bearing";
public static final String ACTION_NEW_BEARING_VALUE_FROM_SIMULATION = "new_bearing_value_from_simulation";

public void requestSimulatedBearing() {
broadcastSimulatedBearing();
}

private void broadcastSimulatedBearing() {
Intent intent = new Intent(ACTION_NEW_SIMULATED_BEARING);
Intent intent = new Intent(ACTION_NEW_BEARING_VALUE_FROM_SIMULATION);
intent.putExtra(EXTRA_BEARING, getSimulatedBearing());
LocalBroadcastManager.getInstance(GlobalInstance.getContext()).sendBroadcast(intent);
}
Expand All @@ -546,14 +564,19 @@ public Bearing getSimulatedBearing() {
}

public void setSimulatedBearing(Bearing newBearing) {
settingsManagerInstance.setSimulatedBearing(newBearing);

if (newBearing != null) {
settingsManagerInstance.setSimulatedBearing(newBearing);
// broadcast new simulated bearing action
broadcastSimulatedBearing();
// broadcast new bearing action
if (this.simulationEnabled) {
if (getSimulationEnabled()) {
broadcastCurrentBearing(true);
} else {
setSimulationEnabled(true);
}
// broadcast new simulated bearing action
broadcastSimulatedBearing();

} else if (getSimulationEnabled()) {
setSimulationEnabled(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ private BearingSensorAccuracyRating extractBearingSensorAccuracyRating(Location
*/

// enable / disable simulation
public static final String ACTION_SIMULATION_STATUS_CHANGED = "locationSimulationStatusChanged";
public static final String EXTRA_SIMULATION_ENABLED = "locationSimulationEnabled";

private boolean simulationEnabled = false;

Expand All @@ -371,8 +373,18 @@ public boolean getSimulationEnabled() {
}

public void setSimulationEnabled(boolean enabled) {
this.simulationEnabled = enabled;
broadcastCurrentLocation(true);
if (getSimulationEnabled() != enabled) {
this.simulationEnabled = enabled;
broadcastSimulationStatusChanged();
broadcastCurrentLocation(true);
}
}

private void broadcastSimulationStatusChanged() {
Timber.d("broadcastSimulationStatusChanged");
Intent intent = new Intent(ACTION_SIMULATION_STATUS_CHANGED);
intent.putExtra(EXTRA_SIMULATION_ENABLED, getSimulationEnabled());
LocalBroadcastManager.getInstance(GlobalInstance.getContext()).sendBroadcast(intent);
}

// change simulated location
Expand All @@ -397,16 +409,21 @@ public Point getSimulatedLocation() {
}

public void setSimulatedLocation(Point newPoint) {
settingsManagerInstance.setSimulatedPoint(newPoint);

if (newPoint != null) {
settingsManagerInstance.setSimulatedPoint(newPoint);
// add to history
HistoryProfile.simulatedPoints().addObject(newPoint);
// broadcast new simulated location action
broadcastSimulatedLocation();
// broadcast new location action
if (this.simulationEnabled) {
if (getSimulationEnabled()) {
broadcastCurrentLocation(true);
} else {
setSimulationEnabled(true);
}
// broadcast new simulated location action
broadcastSimulatedLocation();
// add to history
HistoryProfile.simulatedPoints().addObject(newPoint);

} else if (getSimulationEnabled()) {
setSimulationEnabled(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,8 @@ public P2pRouteTask(P2pRouteRequest request, WayClassWeightSettings wayClassWeig
}

// allowed way classes
JSONObject jsonWayClassTypeAndWeightMappings = new JSONObject();
for (WayClassType type : WayClassType.values()) {
jsonWayClassTypeAndWeightMappings.put(
type.id,
wayClassWeightSettings.getWeightFor(type).weight);
}
jsonServerParams.put(
"allowed_way_classes", jsonWayClassTypeAndWeightMappings);
"allowed_way_classes", this.wayClassWeightSettings.toJson());

} catch (JSONException e) {
throw new WgException(WgException.RC_BAD_REQUEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,100 @@
import org.walkersguide.android.server.wg.p2p.wayclass.WayClassWeight;

import java.io.Serializable;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Map;
import java.util.Locale;
import java.util.LinkedHashMap;
import java.lang.Comparable;
import org.walkersguide.android.util.GlobalInstance;


public class WayClassWeightSettings implements Serializable {
private static final long serialVersionUID = 1l;

public static WayClassWeightSettings getDefault() {
HashMap<WayClassType,WayClassWeight> map = new HashMap<WayClassType,WayClassWeight>();
for (WayClassType type : WayClassType.values()) {
map.put(type, type.defaultWeight);
public enum Preset {
URBAN_ON_FOOT(
1,
GlobalInstance.getStringResource(R.string.wcwsPresetUrbanOnFoot),
presetUrbanOnFoot()),
URBAN_BY_CAR(
2,
GlobalInstance.getStringResource(R.string.wcwsPresetUrbanByCar),
presetUrbanByCar()),
HIKING(
3,
GlobalInstance.getStringResource(R.string.wcwsPresetHiking),
presetHiking());

public static Preset matches(WayClassWeightSettings settings) {
for (Preset preset : values()) {
if (preset.settings.equals(settings)) {
return preset;
}
}
return null;
}

public int id;
public String label;
public WayClassWeightSettings settings;

private Preset(int id, String label, WayClassWeightSettings settings) {
this.id = id;
this.label = label;
this.settings = settings;
}

@Override public String toString() {
return this.label.replace(" ", "\u00A0");
}

private static WayClassWeightSettings presetUrbanOnFoot() {
LinkedHashMap<WayClassType,WayClassWeight> map = new LinkedHashMap<WayClassType,WayClassWeight>();
map.put(WayClassType.BIG_STREETS, WayClassWeight.SLIGHTLY_PREFER);
map.put(WayClassType.SMALL_STREETS, WayClassWeight.STRONGLY_PREFER);
map.put(WayClassType.PAVED_WAYS, WayClassWeight.NEUTRAL);
map.put(WayClassType.UNPAVED_WAYS, WayClassWeight.AVOID);
map.put(WayClassType.STEPS, WayClassWeight.SLIGHTLY_AVOID);
map.put(WayClassType.UNCLASSIFIED_WAYS, WayClassWeight.AVOID);
return new WayClassWeightSettings(map);
}

private static WayClassWeightSettings presetUrbanByCar() {
LinkedHashMap<WayClassType,WayClassWeight> map = new LinkedHashMap<WayClassType,WayClassWeight>();
map.put(WayClassType.BIG_STREETS, WayClassWeight.STRONGLY_PREFER);
map.put(WayClassType.SMALL_STREETS, WayClassWeight.NEUTRAL);
map.put(WayClassType.PAVED_WAYS, WayClassWeight.EXCLUDE);
map.put(WayClassType.UNPAVED_WAYS, WayClassWeight.EXCLUDE);
map.put(WayClassType.STEPS, WayClassWeight.EXCLUDE);
map.put(WayClassType.UNCLASSIFIED_WAYS, WayClassWeight.EXCLUDE);
return new WayClassWeightSettings(map);
}

private static WayClassWeightSettings presetHiking() {
LinkedHashMap<WayClassType,WayClassWeight> map = new LinkedHashMap<WayClassType,WayClassWeight>();
map.put(WayClassType.BIG_STREETS, WayClassWeight.EXCLUDE);
map.put(WayClassType.SMALL_STREETS, WayClassWeight.AVOID);
map.put(WayClassType.PAVED_WAYS, WayClassWeight.STRONGLY_PREFER);
map.put(WayClassType.UNPAVED_WAYS, WayClassWeight.NEUTRAL);
map.put(WayClassType.STEPS, WayClassWeight.AVOID);
map.put(WayClassType.UNCLASSIFIED_WAYS, WayClassWeight.AVOID);
return new WayClassWeightSettings(map);
}
return new WayClassWeightSettings(map);
}


private HashMap<WayClassType,WayClassWeight> typeWeightMap;
private LinkedHashMap<WayClassType,WayClassWeight> typeWeightMap;

public WayClassWeightSettings(HashMap<WayClassType,WayClassWeight> typeWeightMap) {
public WayClassWeightSettings(LinkedHashMap<WayClassType,WayClassWeight> typeWeightMap) {
this.typeWeightMap = typeWeightMap;
}

public int getNumberOfEntries() {
return this.typeWeightMap.size();
}

public WayClassWeight getWeightFor(WayClassType type) {
return this.typeWeightMap.get(type);
}
Expand All @@ -36,4 +109,41 @@ public void setWeightFor(WayClassType type, WayClassWeight newWeight) {
}
}

@Override public int hashCode() {
int result = 1;
for (Map.Entry<WayClassType,WayClassWeight> entry : typeWeightMap.entrySet()) {
result += Double.valueOf(entry.getValue().weight).hashCode();
}
return result;
}

@Override public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj == null) {
return false;
} else if (! (obj instanceof WayClassWeightSettings)) {
return false;
}
WayClassWeightSettings other = (WayClassWeightSettings) obj;
if (this.typeWeightMap.size() != other.getNumberOfEntries()) {
return false;
}
for (Map.Entry<WayClassType,WayClassWeight> entry : this.typeWeightMap.entrySet()) {
if (entry.getValue() != other.getWeightFor(entry.getKey())) {
return false;
}
}
return true;
}

public JSONObject toJson() throws JSONException {
JSONObject jsonWayClassTypeAndWeightMappings = new JSONObject();
for (Map.Entry<WayClassType,WayClassWeight> entry : typeWeightMap.entrySet()) {
jsonWayClassTypeAndWeightMappings.put(
entry.getKey().name().toLowerCase(Locale.ROOT), entry.getValue().weight);
}
return jsonWayClassTypeAndWeightMappings;
}

}
Loading

0 comments on commit 77fe465

Please sign in to comment.