forked from upstream-mirrors/OpenTracks
Fix displaying a marker on the map view.
This commit is contained in:
@@ -51,7 +51,6 @@ import android.os.Bundle;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -74,7 +73,6 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
|||||||
public static final String EXTRA_TRACK_ID = "track_id";
|
public static final String EXTRA_TRACK_ID = "track_id";
|
||||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||||
|
|
||||||
private static final String TAG = TrackDetailActivity.class.getSimpleName();
|
|
||||||
private static final String CURRENT_TAB_TAG_KEY = "current_tab_tag_key";
|
private static final String CURRENT_TAB_TAG_KEY = "current_tab_tag_key";
|
||||||
|
|
||||||
// The following are set in onCreate
|
// The following are set in onCreate
|
||||||
@@ -218,7 +216,6 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
|||||||
}
|
}
|
||||||
trackController = new TrackController(
|
trackController = new TrackController(
|
||||||
this, trackRecordingServiceConnection, false, recordListener, stopListener);
|
this, trackRecordingServiceConnection, false, recordListener, stopListener);
|
||||||
showMarker();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -292,7 +289,6 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
|||||||
public void onNewIntent(Intent intent) {
|
public void onNewIntent(Intent intent) {
|
||||||
setIntent(intent);
|
setIntent(intent);
|
||||||
handleIntent(intent);
|
handleIntent(intent);
|
||||||
showMarker();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -474,6 +470,13 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
|||||||
return trackDataHub;
|
return trackDataHub;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the marker id.
|
||||||
|
*/
|
||||||
|
public long getMarkerId() {
|
||||||
|
return markerId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the data in the intent.
|
* Handles the data in the intent.
|
||||||
*/
|
*/
|
||||||
@@ -508,22 +511,6 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows marker.
|
|
||||||
*/
|
|
||||||
private void showMarker() {
|
|
||||||
if (markerId != -1L) {
|
|
||||||
MyTracksMapFragment mapFragmet = (MyTracksMapFragment) getSupportFragmentManager()
|
|
||||||
.findFragmentByTag(MyTracksMapFragment.MAP_FRAGMENT_TAG);
|
|
||||||
if (mapFragmet != null) {
|
|
||||||
tabHost.setCurrentTabByTag(MyTracksMapFragment.MAP_FRAGMENT_TAG);
|
|
||||||
mapFragmet.showMarker(trackId, markerId);
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "MapFragment is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the menu items.
|
* Updates the menu items.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -93,8 +93,10 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
|
|
||||||
private static final int MAP_VIEW_PADDING = 32;
|
private static final int MAP_VIEW_PADDING = 32;
|
||||||
|
|
||||||
|
// States from TrackDetailActivity, set in onResume
|
||||||
private TrackDataHub trackDataHub;
|
private TrackDataHub trackDataHub;
|
||||||
|
private long markerId;
|
||||||
|
|
||||||
// Current location
|
// Current location
|
||||||
private Location currentLocation;
|
private Location currentLocation;
|
||||||
private Location lastTrackPoint;
|
private Location lastTrackPoint;
|
||||||
@@ -130,10 +132,6 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
|
|
||||||
private OnLocationChangedListener onLocationChangedListener;
|
private OnLocationChangedListener onLocationChangedListener;
|
||||||
|
|
||||||
// For showing a marker
|
|
||||||
private long markerTrackId = -1L;
|
|
||||||
private long markerId = -1L;
|
|
||||||
|
|
||||||
// Current track
|
// Current track
|
||||||
private Track currentTrack;
|
private Track currentTrack;
|
||||||
|
|
||||||
@@ -274,6 +272,9 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
// First obtain the states from TrackDetailActivity
|
||||||
|
markerId = ((TrackDetailActivity) getActivity()).getMarkerId();
|
||||||
resumeTrackDataHub();
|
resumeTrackDataHub();
|
||||||
|
|
||||||
MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
|
MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(
|
||||||
@@ -319,29 +320,6 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
pauseTrackDataHub();
|
pauseTrackDataHub();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows the marker on the map.
|
|
||||||
*
|
|
||||||
* @param trackId the track id
|
|
||||||
* @param id the marker id
|
|
||||||
*/
|
|
||||||
public void showMarker(long trackId, long id) {
|
|
||||||
/*
|
|
||||||
* Synchronize to prevent race condition in changing markerTrackId and
|
|
||||||
* markerId variables.
|
|
||||||
*/
|
|
||||||
synchronized (this) {
|
|
||||||
if (currentTrack != null && currentTrack.getId() == trackId) {
|
|
||||||
showMarker(id);
|
|
||||||
markerTrackId = -1L;
|
|
||||||
markerId = -1L;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
markerTrackId = trackId;
|
|
||||||
markerId = id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflator) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflator) {
|
||||||
menuInflator.inflate(R.menu.map, menu);
|
menuInflator.inflate(R.menu.map, menu);
|
||||||
@@ -409,21 +387,12 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
boolean hasTrack = track != null;
|
boolean hasTrack = track != null;
|
||||||
if (hasTrack) {
|
if (hasTrack) {
|
||||||
mapOverlay.setShowEndMarker(!isSelectedTrackRecording());
|
mapOverlay.setShowEndMarker(!isSelectedTrackRecording());
|
||||||
synchronized (this) {
|
if (markerId != -1L) {
|
||||||
/*
|
// Show the marker
|
||||||
* Synchronize to prevent race condition in changing markerTrackId and
|
showMarker(markerId);
|
||||||
* markerId variables.
|
} else {
|
||||||
*/
|
// Show the track
|
||||||
if (track.getId() == markerTrackId) {
|
showTrack();
|
||||||
// Show the marker
|
|
||||||
showMarker(markerId);
|
|
||||||
|
|
||||||
markerTrackId = -1L;
|
|
||||||
markerId = -1L;
|
|
||||||
} else {
|
|
||||||
// Show the track
|
|
||||||
showTrack();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -648,9 +617,9 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
|||||||
.include(southWest).include(northEast).build();
|
.include(southWest).include(northEast).build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note cannot call CameraUpdate.newLatLngBounds(LatLngBounds bounds,
|
* Note cannot call CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds,
|
||||||
* int padding) if the map view has not undergone layout. Thus calling
|
* int padding) if the map view has not undergone layout. Thus calling
|
||||||
* CameraUpdate.newLatLngBounds(LatLngBounds bounds, int width, int
|
* CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds, int width, int
|
||||||
* height, int padding) after making sure that mapView is valid in the
|
* height, int padding) after making sure that mapView is valid in the
|
||||||
* above code.
|
* above code.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user