Skip to content

Commit

Permalink
Route navigation support
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov committed Oct 24, 2023
1 parent 89ed9c1 commit 8acbc3d
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions app/src/main/java/mobi/maptrek/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import android.content.pm.PermissionInfo;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
Expand Down Expand Up @@ -626,12 +625,8 @@ public void onChildViewRemoved(View parent, View child) {
layers.addGroup(MAP_POSITIONAL);
layers.addGroup(MAP_OVERLAYS);

try {
if (Configuration.getHillshadesEnabled())
showHillShade();
} catch (SQLiteCantOpenDatabaseException ignore) {
// temporary, until data will be moved to application folder
}
if (Configuration.getHillshadesEnabled())
showHillShade();

mGridLayer = new TileGridLayer(mMap, MapTrek.density * .75f);
if (Configuration.getGridLayerEnabled())
Expand Down Expand Up @@ -670,18 +665,15 @@ public void onChildViewRemoved(View parent, View child) {
layers.add(mMarkerLayer, MAP_3D_DATA);

// Load waypoints
try {
mWaypointDbDataSource = application.getWaypointDbDataSource();
mWaypointDbDataSource.open();
for (Waypoint waypoint : mWaypointDbDataSource.getWaypoints()) {
if (mEditedWaypoint != null && mEditedWaypoint._id == waypoint._id)
mEditedWaypoint = waypoint;
addWaypointMarker(waypoint);
mTotalDataItems++;
}
} catch (SQLiteCantOpenDatabaseException ignore) {
// temporary, until data will be moved to application folder
mWaypointDbDataSource = application.getWaypointDbDataSource();
mWaypointDbDataSource.open();
for (Waypoint waypoint : mWaypointDbDataSource.getWaypoints()) {
if (mEditedWaypoint != null && mEditedWaypoint._id == waypoint._id)
mEditedWaypoint = waypoint;
addWaypointMarker(waypoint);
mTotalDataItems++;
}

mWaypointBroadcastReceiver = new WaypointBroadcastReceiver();
registerReceiver(mWaypointBroadcastReceiver, new IntentFilter(WaypointDbDataSource.BROADCAST_WAYPOINTS_MODIFIED));
registerReceiver(mWaypointBroadcastReceiver, new IntentFilter(WaypointDbDataSource.BROADCAST_WAYPOINTS_RESTORED));
Expand All @@ -692,11 +684,7 @@ public void onChildViewRemoved(View parent, View child) {
for (MapFile bitmapLayerMap : mBitmapLayerMaps)
showBitmapMap(bitmapLayerMap, false);

try {
setMapTheme();
} catch (IllegalStateException ignore) {
// temporary, until data will be moved to application folder
}
setMapTheme();

//if (BuildConfig.DEBUG)
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
Expand Down Expand Up @@ -750,9 +738,9 @@ public void onChildViewRemoved(View parent, View child) {
mViews.coordinatorLayout.findViewById(R.id.mapZoomHolder).setVisibility(visible ? View.VISIBLE : View.GONE);

// Resume navigation
MapObject mapObject = Configuration.getNavigationPoint();
if (mapObject != null)
startNavigation(mapObject);
//MapObject mapObject = Configuration.getNavigationPoint();
//if (mapObject != null)
// startNavigation(mapObject, Configuration.getNavigationViaRoute());

// Initialize data loader
getLoaderManager();
Expand Down Expand Up @@ -1440,7 +1428,7 @@ public void onDismissed(Snackbar transientBottomBar, int event) {
removeMarker();
MapObject mapObject = new MapObject(mSelectedPoint.getLatitude(), mSelectedPoint.getLongitude());
mapObject.name = getString(R.string.selectedLocation);
startNavigation(mapObject);
startNavigation(mapObject, false);
return true;
} else if (action == R.id.actionFindRouteHere) {
removeMarker();
Expand Down Expand Up @@ -2001,13 +1989,14 @@ public void onServiceDisconnected(ComponentName className) {
}
};

private void startNavigation(MapObject mapObject) {
private void startNavigation(MapObject mapObject, boolean viaRoute) {
enableNavigation();
Intent i = new Intent(this, NavigationService.class).setAction(NavigationService.NAVIGATE_TO_POINT);
i.putExtra(NavigationService.EXTRA_NAME, mapObject.name);
i.putExtra(NavigationService.EXTRA_LATITUDE, mapObject.coordinates.getLatitude());
i.putExtra(NavigationService.EXTRA_LONGITUDE, mapObject.coordinates.getLongitude());
i.putExtra(NavigationService.EXTRA_PROXIMITY, mapObject.proximity);
i.putExtra(NavigationService.EXTRA_ROUTE, viaRoute);
startService(i);
if (mLocationState == LocationState.DISABLED)
askForPermission();
Expand Down Expand Up @@ -2082,7 +2071,7 @@ public void disableTracking() {

@Override
public void navigateTo(@NonNull GeoPoint coordinates, @Nullable String name) {
startNavigation(new MapObject(name, coordinates));
startNavigation(new MapObject(name, coordinates), false);
}

@Override
Expand Down Expand Up @@ -2625,7 +2614,7 @@ public void onWaypointDetails(Waypoint waypoint, boolean fromList) {

@Override
public void onWaypointNavigate(Waypoint waypoint) {
startNavigation(waypoint);
startNavigation(waypoint, false);
}

@Override
Expand Down Expand Up @@ -3985,7 +3974,7 @@ public void onLoaderReset(Loader<List<FileDataSource>> loader) {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
logger.error("Broadcast: {}", action);
logger.debug("Broadcast: {}", action);
if (MapService.BROADCAST_MAP_ADDED.equals(action) || MapService.BROADCAST_MAP_REMOVED.equals(action)) {
mMap.clearMap();
}
Expand Down Expand Up @@ -4029,8 +4018,11 @@ public void onDismissed(Snackbar transientBottomBar, int event) {
enableNavigation();
updateNavigationUI();
}
if (state == BaseNavigationService.STATE_NEXT_WPT)
if (state == BaseNavigationService.STATE_NEXT_WPT) {
updateNavigationGauges(true);
if (mNavigationLayer != null && mNavigationService != null)
mNavigationLayer.setDestination(mNavigationService.getWaypoint().coordinates);
}
updatePanels();
}
if (BaseNavigationService.BROADCAST_NAVIGATION_STATUS.equals(action)) {
Expand Down

0 comments on commit 8acbc3d

Please sign in to comment.