forked from upstream-mirrors/OpenTracks
Set the title in TrackDetailActivity.
Fix a bug when recording, the TrackDetailActivity is not displaying the correct menu items.
This commit is contained in:
@@ -2123,6 +2123,10 @@ limitations under the License.
|
|||||||
translation_description="In the track detail page, the title of the tab showing the stats.">
|
translation_description="In the track detail page, the title of the tab showing the stats.">
|
||||||
Stats
|
Stats
|
||||||
</string>
|
</string>
|
||||||
|
<string name="track_detail_title_recording"
|
||||||
|
translation_description="In the track detail page, the title when recording.">
|
||||||
|
Recording...
|
||||||
|
</string>
|
||||||
<string name="track_icon_description"
|
<string name="track_icon_description"
|
||||||
translation_description="The accessibility description for the track icon.">
|
translation_description="The accessibility description for the track icon.">
|
||||||
Track
|
Track
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.google.android.apps.mytracks;
|
package com.google.android.apps.mytracks;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.content.TrackDataHub;
|
import com.google.android.apps.mytracks.content.TrackDataHub;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||||
@@ -76,6 +77,7 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
|||||||
private TabHost tabHost;
|
private TabHost tabHost;
|
||||||
private TabManager tabManager;
|
private TabManager tabManager;
|
||||||
private long trackId;
|
private long trackId;
|
||||||
|
private long markerId;
|
||||||
|
|
||||||
private MenuItem stopRecordingMenuItem;
|
private MenuItem stopRecordingMenuItem;
|
||||||
private MenuItem insertMarkerMenuItem;
|
private MenuItem insertMarkerMenuItem;
|
||||||
@@ -126,13 +128,15 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
handleIntent(getIntent());
|
||||||
ApiAdapterFactory.getApiAdapter().hideTitle(this);
|
ApiAdapterFactory.getApiAdapter().hideTitle(this);
|
||||||
setContentView(R.layout.track_detail);
|
setContentView(R.layout.track_detail);
|
||||||
|
|
||||||
getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE)
|
getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE)
|
||||||
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||||
trackDataHub = ((MyTracksApplication) getApplication()).getTrackDataHub();
|
|
||||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
||||||
|
trackDataHub = ((MyTracksApplication) getApplication()).getTrackDataHub();
|
||||||
|
trackDataHub.loadTrack(trackId);
|
||||||
|
|
||||||
mapViewContainer = getLayoutInflater().inflate(R.layout.map, null);
|
mapViewContainer = getLayoutInflater().inflate(R.layout.map, null);
|
||||||
tabHost = (TabHost) findViewById(android.R.id.tabhost);
|
tabHost = (TabHost) findViewById(android.R.id.tabhost);
|
||||||
@@ -152,14 +156,15 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
|||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
tabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAG_KEY));
|
tabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAG_KEY));
|
||||||
}
|
}
|
||||||
|
showMarker();
|
||||||
handleIntent(getIntent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewIntent(Intent intent) {
|
public void onNewIntent(Intent intent) {
|
||||||
setIntent(intent);
|
setIntent(intent);
|
||||||
handleIntent(intent);
|
handleIntent(intent);
|
||||||
|
trackDataHub.loadTrack(trackId);
|
||||||
|
showMarker();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -172,6 +177,7 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
TrackRecordingServiceConnectionUtils.resume(this, trackRecordingServiceConnection);
|
TrackRecordingServiceConnectionUtils.resume(this, trackRecordingServiceConnection);
|
||||||
|
setTitle(trackId == PreferencesUtils.getLong(this, R.string.recording_track_id_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -248,6 +254,7 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.track_detail_stop_recording:
|
case R.id.track_detail_stop_recording:
|
||||||
updateMenuItems(false);
|
updateMenuItems(false);
|
||||||
|
setTitle(false);
|
||||||
TrackRecordingServiceConnectionUtils.stop(this, trackRecordingServiceConnection);
|
TrackRecordingServiceConnectionUtils.stop(this, trackRecordingServiceConnection);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_insert_marker:
|
case R.id.track_detail_insert_marker:
|
||||||
@@ -361,25 +368,34 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
|||||||
*/
|
*/
|
||||||
private void handleIntent(Intent intent) {
|
private void handleIntent(Intent intent) {
|
||||||
trackId = intent.getLongExtra(EXTRA_TRACK_ID, -1L);
|
trackId = intent.getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||||
long markerId = intent.getLongExtra(EXTRA_MARKER_ID, -1L);
|
markerId = intent.getLongExtra(EXTRA_MARKER_ID, -1L);
|
||||||
if (markerId != -1L) {
|
if (markerId != -1L) {
|
||||||
Waypoint waypoint = MyTracksProviderUtils.Factory.get(this).getWaypoint(markerId);
|
Waypoint waypoint = MyTracksProviderUtils.Factory.get(this).getWaypoint(markerId);
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
Intent newIntent = IntentUtils.newIntent(this, TrackListActivity.class);
|
exit();
|
||||||
startActivity(newIntent);
|
|
||||||
finish();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
trackId = waypoint.getTrackId();
|
trackId = waypoint.getTrackId();
|
||||||
}
|
}
|
||||||
if (trackId == -1L) {
|
if (trackId == -1L) {
|
||||||
Intent newIntent = IntentUtils.newIntent(this, TrackListActivity.class);
|
exit();
|
||||||
startActivity(newIntent);
|
|
||||||
finish();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
trackDataHub.loadTrack(trackId);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exists and returns to {@link TrackListActivity}.
|
||||||
|
*/
|
||||||
|
private void exit() {
|
||||||
|
Intent newIntent = IntentUtils.newIntent(this, TrackListActivity.class);
|
||||||
|
startActivity(newIntent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows marker.
|
||||||
|
*/
|
||||||
|
private void showMarker() {
|
||||||
if (markerId != -1L) {
|
if (markerId != -1L) {
|
||||||
MapFragment mapFragmet = (MapFragment) getSupportFragmentManager()
|
MapFragment mapFragmet = (MapFragment) getSupportFragmentManager()
|
||||||
.findFragmentByTag(MapFragment.MAP_FRAGMENT_TAG);
|
.findFragmentByTag(MapFragment.MAP_FRAGMENT_TAG);
|
||||||
@@ -392,6 +408,22 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the title.
|
||||||
|
*
|
||||||
|
* @param isRecording true if recording
|
||||||
|
*/
|
||||||
|
private void setTitle(boolean isRecording) {
|
||||||
|
String title;
|
||||||
|
if (isRecording) {
|
||||||
|
title = getString(R.string.track_detail_title_recording);
|
||||||
|
} else {
|
||||||
|
Track track = MyTracksProviderUtils.Factory.get(this).getTrack(trackId);
|
||||||
|
title = track != null ? track.getName() : getString(R.string.my_tracks_app_name);
|
||||||
|
}
|
||||||
|
setTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the menu.
|
* Updates the menu.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user