Merge heads

This commit is contained in:
youtaol
2012-05-15 16:58:38 +08:00
parent f1573a550a
commit 37bfefaa3d
29 changed files with 379 additions and 499 deletions
@@ -44,6 +44,10 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity {
private long markerId;
private Waypoint waypoint;
private TextView name;
private View waypointSection;
private View statisticsSection;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
@@ -55,29 +59,29 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity {
finish();
return;
}
name = (TextView) findViewById(R.id.marker_detail_name);
waypointSection = findViewById(R.id.marker_detail_waypoint_section);
statisticsSection = findViewById(R.id.marker_detail_statistics_section);
}
@Override
protected void onResume() {
super.onResume();
waypoint = MyTracksProviderUtils.Factory.get(this).getWaypoint(markerId);
if (waypoint == null) {
Log.d(TAG, "waypoint is null");
finish();
return;
}
TextView name = (TextView) findViewById(R.id.marker_detail_name);
name.setText(getString(R.string.marker_detail_name, waypoint.getName()));
View waypointSection = findViewById(R.id.marker_detail_waypoint_section);
View statisticsSection = findViewById(R.id.marker_detail_statistics_section);
if (waypoint.getType() == Waypoint.TYPE_WAYPOINT) {
waypointSection.setVisibility(View.VISIBLE);
statisticsSection.setVisibility(View.GONE);
TextView markerType = (TextView) findViewById(R.id.marker_detail_waypoint_marker_type);
markerType.setText(getString(
R.string.marker_detail_waypoint_marker_type, waypoint.getCategory()));
markerType.setText(getString(R.string.marker_detail_marker_type, waypoint.getCategory()));
TextView description = (TextView) findViewById(R.id.marker_detail_waypoint_description);
description.setText(getString(
R.string.marker_detail_waypoint_description, waypoint.getDescription()));
description.setText(getString(R.string.marker_detail_description, waypoint.getDescription()));
} else {
waypointSection.setVisibility(View.GONE);
statisticsSection.setVisibility(View.VISIBLE);
@@ -85,7 +89,7 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity {
StatsUtils.setLocationValues(this, waypoint.getLocation(), false);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.marker_detail, menu);
@@ -21,7 +21,6 @@ import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
import com.google.android.apps.mytracks.content.WaypointCreationRequest.WaypointType;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
import com.google.android.maps.mytracks.R;
@@ -33,7 +32,6 @@ import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
/**
* An activity to add/edit a marker.
@@ -46,17 +44,13 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
public static final String EXTRA_TRACK_ID = "track_id";
public static final String EXTRA_MARKER_ID = "marker_id";
public static final String EXTRA_STATISTICS_MARKER = "statistics_marker";
private long trackId;
private long markerId;
private boolean statisticsMarker;
private TrackRecordingServiceConnection trackRecordingServiceConnection;
private Waypoint waypoint;
// UI elements
private View typeSection;
private RadioGroup type;
private View statisticsSection;
private EditText statisticsName;
private View waypointSection;
@@ -72,36 +66,9 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
markerId = getIntent().getLongExtra(EXTRA_MARKER_ID, -1L);
statisticsMarker = getIntent().getBooleanExtra(EXTRA_STATISTICS_MARKER, true);
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
// Setup UI elements
typeSection = findViewById(R.id.marker_edit_type_section);
type = (RadioGroup) findViewById(R.id.marker_edit_type);
type.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
boolean statistics = checkedId == R.id.marker_edit_statistics;
statisticsSection.setVisibility(statistics ? View.VISIBLE : View.GONE);
waypointSection.setVisibility(statistics ? View.GONE : View.VISIBLE);
int nextMarkerNumber = trackId == -1L ? -1
: MyTracksProviderUtils.Factory.get(MarkerEditActivity.this)
.getNextMarkerNumber(trackId, statistics);
if (statistics) {
String name = nextMarkerNumber == -1 ? getString(R.string.marker_type_statistics)
: getString(R.string.marker_statistics_name_format, nextMarkerNumber);
statisticsName.setText(name);
statisticsName.selectAll();
} else {
String name = nextMarkerNumber == -1 ? getString(R.string.marker_type_waypoint)
: getString(R.string.marker_waypoint_name_format, nextMarkerNumber);
waypointName.setText(name);
waypointName.selectAll();
waypointMarkerType.setText("");
waypointDescription.setText("");
}
}
});
statisticsSection = findViewById(R.id.marker_edit_statistics_section);
statisticsName = (EditText) findViewById(R.id.marker_edit_statistics_name);
@@ -131,7 +98,6 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
final boolean newMarker = markerId == -1L;
setTitle(newMarker ? R.string.menu_insert_marker : R.string.menu_edit);
typeSection.setVisibility(newMarker ? View.VISIBLE : View.GONE);
done.setText(newMarker ? R.string.generic_add : R.string.generic_save);
done.setOnClickListener(new View.OnClickListener() {
@Override
@@ -146,7 +112,16 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
});
if (newMarker) {
type.check(statisticsMarker ? R.id.marker_edit_statistics : R.id.marker_edit_waypoint);
statisticsSection.setVisibility(View.GONE);
waypointSection.setVisibility(View.VISIBLE);
int nextMarkerNumber = trackId == -1L ? -1
: MyTracksProviderUtils.Factory.get(this).getNextMarkerNumber(trackId, false);
String name = nextMarkerNumber == -1 ? getString(R.string.marker_type_waypoint)
: getString(R.string.marker_name_format, nextMarkerNumber);
waypointName.setText(name);
waypointName.selectAll();
waypointMarkerType.setText("");
waypointDescription.setText("");
} else {
waypoint = MyTracksProviderUtils.Factory.get(this).getWaypoint(markerId);
if (waypoint == null) {
@@ -183,18 +158,13 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
* Adds a marker.
*/
private void addMarker() {
boolean statistics = type.getCheckedRadioButtonId() == R.id.marker_edit_statistics;
PreferencesUtils.setBoolean(this, R.string.pick_statistics_marker_key, statistics);
WaypointType waypointType = statistics ? WaypointType.STATISTICS : WaypointType.WAYPOINT;
String markerName = statistics ? statisticsName.getText().toString()
: waypointName.getText().toString();
String markerCategory = statistics ? null : waypointMarkerType.getText().toString();
String markerDescription = statistics ? null : waypointDescription.getText().toString();
String markerIconUrl = getString(statistics ? R.string.marker_statistics_icon_url
: R.string.marker_waypoint_icon_url);
WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(
waypointType, markerName, markerCategory, markerDescription, markerIconUrl);
WaypointType.WAYPOINT,
false,
waypointName.getText().toString(),
waypointMarkerType.getText().toString(),
waypointDescription.getText().toString(),
getString(R.string.marker_waypoint_icon_url));
TrackRecordingServiceConnectionUtils.addMarker(
this, trackRecordingServiceConnection, waypointCreationRequest);
}
@@ -20,12 +20,10 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointsColumns;
import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment;
import com.google.android.apps.mytracks.fragments.MarkerAddDialogFragment;
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.ListItemUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R;
import android.content.Context;
@@ -139,12 +137,12 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
boolean statistics = cursor.getInt(typeIndex) == Waypoint.TYPE_STATISTICS;
String name = cursor.getString(nameIndex);
int iconId = statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin;
String contentDescription = getString(R.string.icon_marker);
String category = statistics ? null : cursor.getString(categoryIndex);
long time = cursor.getLong(timeIndex);
String startTime = time == 0
? null : StringUtils.formatDateTime(MarkerListActivity.this, time);
String description = statistics ? null : cursor.getString(descriptionIndex);
ListItemUtils.setListItem(view, name, iconId, category, null, null, startTime, description);
ListItemUtils.setListItem(MarkerListActivity.this,
view, name, iconId, contentDescription, category, null, null, time, description);
}
};
listView.setAdapter(resourceCursorAdapter);
@@ -197,8 +195,9 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.marker_list_insert_marker:
MarkerAddDialogFragment.newInstance(trackId)
.show(getSupportFragmentManager(), MarkerAddDialogFragment.MARKER_ADD_DIALOG_TAG);
Intent intent = IntentUtils.newIntent(this, MarkerEditActivity.class)
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId);
startActivity(intent);
return true;
case R.id.marker_list_search:
return ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(this);
@@ -25,12 +25,15 @@ import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.ListItemUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
import com.google.android.maps.mytracks.R;
import android.app.SearchManager;
@@ -67,12 +70,13 @@ import java.util.SortedSet;
*
* @author Rodrigo Damazio
*/
public class SearchListActivity extends AbstractMyTracksActivity {
public class SearchListActivity extends AbstractMyTracksActivity implements DeleteOneTrackCaller {
private static final String TAG = SearchListActivity.class.getSimpleName();
private static final String NAME_FIELD = "name";
private static final String ICON_FIELD = "icon";
private static final String ICON_CONTENT_DESCRIPTION_FIELD = "iconContentDescription";
private static final String CATEGORY_FIELD = "category";
private static final String TOTAL_TIME_FIELD = "totalTime";
private static final String TOTAL_DISTANCE_FIELD = "totalDistance";
@@ -103,6 +107,7 @@ public class SearchListActivity extends AbstractMyTracksActivity {
}
};
private TrackRecordingServiceConnection trackRecordingServiceConnection;
private MyTracksProviderUtils myTracksProviderUtils;
private SearchEngine searchEngine;
private SearchRecentSuggestions searchRecentSuggestions;
@@ -121,6 +126,7 @@ public class SearchListActivity extends AbstractMyTracksActivity {
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
setContentView(R.layout.search_list);
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
searchEngine = new SearchEngine(myTracksProviderUtils);
searchRecentSuggestions = SearchEngineProvider.newHelper(this);
@@ -161,14 +167,17 @@ public class SearchListActivity extends AbstractMyTracksActivity {
Map<String, Object> resultMap = getItem(position);
String name = (String) resultMap.get(NAME_FIELD);
int iconId = (Integer) resultMap.get(ICON_FIELD);
String iconContentDescription = (String) resultMap.get(ICON_CONTENT_DESCRIPTION_FIELD);
String category = (String) resultMap.get(CATEGORY_FIELD);
String totalTime = (String) resultMap.get(TOTAL_TIME_FIELD);
String totalDistance = (String) resultMap.get(TOTAL_DISTANCE_FIELD);
String startTime = (String) resultMap.get(START_TIME_FIELD);
long startTime = (Long) resultMap.get(START_TIME_FIELD);
String description = (String) resultMap.get(DESCRIPTION_FIELD);
ListItemUtils.setListItem(view,
ListItemUtils.setListItem(SearchListActivity.this,
view,
name,
iconId,
iconContentDescription,
category,
totalTime,
totalDistance,
@@ -186,10 +195,17 @@ public class SearchListActivity extends AbstractMyTracksActivity {
@Override
protected void onResume() {
super.onResume();
TrackRecordingServiceConnectionUtils.resume(this, trackRecordingServiceConnection);
metricUnits = PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
}
@Override
protected void onDestroy() {
super.onDestroy();
trackRecordingServiceConnection.unbind();
}
@Override
public void onNewIntent(Intent intent) {
setIntent(intent);
@@ -382,11 +398,9 @@ public class SearchListActivity extends AbstractMyTracksActivity {
boolean statistics = waypoint.getType() == Waypoint.TYPE_STATISTICS;
resultMap.put(NAME_FIELD, waypoint.getName());
resultMap.put(ICON_FIELD, statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin);
resultMap.put(ICON_CONTENT_DESCRIPTION_FIELD, getString(R.string.icon_marker));
resultMap.put(CATEGORY_FIELD, statistics ? null : waypoint.getCategory());
long time = waypoint.getLocation().getTime();
String startTime = StringUtils.formatDateTime(this, time);
resultMap.put(START_TIME_FIELD, time == 0 || startTime.equals(trackName) ? null : startTime);
resultMap.put(START_TIME_FIELD, waypoint.getLocation().getTime());
// Display the marker's track name in the total time field
resultMap.put(TOTAL_TIME_FIELD, trackName == null ? null
@@ -408,18 +422,21 @@ public class SearchListActivity extends AbstractMyTracksActivity {
TripStatistics tripStatitics = track.getStatistics();
resultMap.put(NAME_FIELD, track.getName());
resultMap.put(ICON_FIELD, isRecording ? R.drawable.menu_record_track : R.drawable.track);
resultMap.put(ICON_CONTENT_DESCRIPTION_FIELD, getString(isRecording ? R.string.icon_recording
: R.string.icon_track));
resultMap.put(CATEGORY_FIELD, track.getCategory());
resultMap.put(TOTAL_TIME_FIELD, isRecording ? null : StringUtils.formatElapsedTime(
tripStatitics.getTotalTime()));
resultMap.put(TOTAL_DISTANCE_FIELD, isRecording ? null : StringUtils.formatDistance(
this, tripStatitics.getTotalDistance(), metricUnits));
String startTime = StringUtils.formatDateTime(this, tripStatitics.getStartTime());
if (startTime.equals(track.getName())) {
startTime = null;
}
resultMap.put(START_TIME_FIELD, startTime);
resultMap.put(START_TIME_FIELD, tripStatitics.getStartTime());
resultMap.put(DESCRIPTION_FIELD, track.getDescription());
resultMap.put(TRACK_ID_FIELD, track.getId());
resultMap.put(MARKER_ID_FIELD, null);
}
@Override
public TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
return trackRecordingServiceConnection;
}
}
@@ -22,13 +22,13 @@ import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection
import com.google.android.apps.mytracks.services.sensors.SensorManager;
import com.google.android.apps.mytracks.services.sensors.SensorManagerFactory;
import com.google.android.apps.mytracks.services.sensors.SensorUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
import com.google.android.maps.mytracks.R;
import com.google.protobuf.InvalidProtocolBufferException;
import android.os.Bundle;
import android.os.RemoteException;
import android.text.format.DateFormat;
import android.util.Log;
import android.widget.TextView;
@@ -221,7 +221,7 @@ public class SensorStateActivity extends AbstractMyTracksActivity {
* @param sensorDataSet sensor data set
*/
private String getLastSensorTime(Sensor.SensorDataSet sensorDataSet) {
return StringUtils.formatTime(this, sensorDataSet.getCreationTime());
return DateFormat.format("h:mm:ss aa", sensorDataSet.getCreationTime()).toString();
}
/**
@@ -23,9 +23,9 @@ import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
import com.google.android.apps.mytracks.fragments.ChartFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment;
import com.google.android.apps.mytracks.fragments.MapFragment;
import com.google.android.apps.mytracks.fragments.MarkerAddDialogFragment;
import com.google.android.apps.mytracks.fragments.StatsFragment;
import com.google.android.apps.mytracks.io.file.SaveActivity;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
@@ -64,7 +64,7 @@ import java.util.List;
* @author Leif Hendrik Wilden
* @author Rodrigo Damazio
*/
public class TrackDetailActivity extends AbstractMyTracksActivity {
public class TrackDetailActivity extends AbstractMyTracksActivity implements DeleteOneTrackCaller {
public static final String EXTRA_TRACK_ID = "track_id";
public static final String EXTRA_MARKER_ID = "marker_id";
@@ -85,8 +85,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
private MenuItem shareMenuItem;
private MenuItem sendGoogleMenuItem;
private MenuItem saveMenuItem;
private MenuItem editMenuItem;
private MenuItem deleteMenuItem;
private View mapViewContainer;
@@ -226,8 +224,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
shareMenuItem = menu.findItem(R.id.track_detail_share);
sendGoogleMenuItem = menu.findItem(R.id.track_detail_send_google);
saveMenuItem = menu.findItem(R.id.track_detail_save);
editMenuItem = menu.findItem(R.id.track_detail_edit);
deleteMenuItem = menu.findItem(R.id.track_detail_delete);
updateMenu();
return true;
@@ -255,11 +251,12 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
case R.id.track_detail_stop_recording:
updateMenuItems(false);
setTitle(false);
TrackRecordingServiceConnectionUtils.stop(this, trackRecordingServiceConnection);
TrackRecordingServiceConnectionUtils.stop(this, trackRecordingServiceConnection, true);
return true;
case R.id.track_detail_insert_marker:
MarkerAddDialogFragment.newInstance(trackId)
.show(getSupportFragmentManager(), MarkerAddDialogFragment.MARKER_ADD_DIALOG_TAG);
intent = IntentUtils.newIntent(this, MarkerEditActivity.class)
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId);
startActivity(intent);
return true;
case R.id.track_detail_play:
if (isEarthInstalled()) {
@@ -349,7 +346,7 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (TrackRecordingServiceConnectionUtils.isRecording(this, trackRecordingServiceConnection)) {
TrackRecordingServiceConnectionUtils.addMarker(
this, trackRecordingServiceConnection, WaypointCreationRequest.DEFAULT_STATISTICS);
this, trackRecordingServiceConnection, WaypointCreationRequest.DEFAULT_WAYPOINT);
return true;
}
}
@@ -455,12 +452,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
if (saveMenuItem != null) {
saveMenuItem.setVisible(!isRecording);
}
if (editMenuItem != null) {
editMenuItem.setVisible(!isRecording);
}
if (deleteMenuItem != null) {
deleteMenuItem.setVisible(!isRecording);
}
}
/**
@@ -492,4 +483,9 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
}
return false;
}
@Override
public TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
return trackRecordingServiceConnection;
}
}
@@ -89,7 +89,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity {
track.setCategory(activityType.getText().toString());
track.setDescription(description.getText().toString());
myTracksProviderUtils.updateTrack(track);
finish();
finish();
}
});
@@ -102,7 +102,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity {
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
finish();
}
});
cancel.setVisibility(View.VISIBLE);
@@ -20,6 +20,7 @@ import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.fragments.CheckUnitsDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteAllTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
import com.google.android.apps.mytracks.fragments.WelcomeDialogFragment;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
@@ -68,7 +69,7 @@ import android.widget.Toast;
*
* @author Leif Hendrik Wilden
*/
public class TrackListActivity extends FragmentActivity {
public class TrackListActivity extends FragmentActivity implements DeleteOneTrackCaller {
private static final String TAG = TrackListActivity.class.getSimpleName();
@@ -217,20 +218,20 @@ public class TrackListActivity extends FragmentActivity {
boolean isRecording = cursor.getLong(idIndex) == recordingTrackId;
String name = cursor.getString(nameIndex);
int iconId = isRecording ? R.drawable.menu_record_track : R.drawable.track;
String iconContentDescription = getString(isRecording ? R.string.icon_recording
: R.string.icon_track);
String category = cursor.getString(categoryIndex);
String totalTime = isRecording
? null : StringUtils.formatElapsedTime(cursor.getLong(timeIndex));
String totalDistance = isRecording ? null : StringUtils.formatDistance(
TrackListActivity.this, cursor.getDouble(distanceIndex), metricUnits);
String startTime =
StringUtils.formatDateTime(TrackListActivity.this, cursor.getLong(startIndex));
if (startTime.equals(name)) {
startTime = null;
}
long startTime = cursor.getLong(startIndex);
String description = cursor.getString(descriptionIndex);
ListItemUtils.setListItem(view,
ListItemUtils.setListItem(TrackListActivity.this,
view,
name,
iconId,
iconContentDescription,
category,
totalTime,
totalDistance,
@@ -388,7 +389,7 @@ public class TrackListActivity extends FragmentActivity {
return true;
case R.id.track_list_stop_recording:
updateMenuItems(false);
TrackRecordingServiceConnectionUtils.stop(this, trackRecordingServiceConnection);
TrackRecordingServiceConnectionUtils.stop(this, trackRecordingServiceConnection, true);
return true;
case R.id.track_list_search:
return ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(this);
@@ -506,4 +507,9 @@ public class TrackListActivity extends FragmentActivity {
}
return super.onKeyUp(keyCode, event);
}
@Override
public TrackRecordingServiceConnection getTrackRecordingServiceConnection() {
return trackRecordingServiceConnection;
}
}
@@ -18,11 +18,16 @@ package com.google.android.apps.mytracks.fragments;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
@@ -30,7 +35,7 @@ import android.support.v4.app.DialogFragment;
/**
* A DialogFragment to delete one track.
*
*
* @author Jimmy Shih
*/
public class DeleteOneTrackDialogFragment extends DialogFragment {
@@ -38,6 +43,17 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
public static final String DELETE_ONE_TRACK_DIALOG_TAG = "deleteOneTrackDialog";
private static final String KEY_TRACK_ID = "trackId";
/**
* Interface for caller of this dialog fragment.
*
* @author Jimmy Shih
*/
public interface DeleteOneTrackCaller {
public TrackRecordingServiceConnection getTrackRecordingServiceConnection();
}
private DeleteOneTrackCaller caller;
public static DeleteOneTrackDialogFragment newInstance(long trackId) {
Bundle bundle = new Bundle();
bundle.putLong(KEY_TRACK_ID, trackId);
@@ -47,17 +63,32 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
return deleteOneTrackDialogFragment;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
caller = (DeleteOneTrackCaller) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement DeleteOneTrackCaller");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return DialogUtils.createConfirmationDialog(getActivity(),
R.string.track_detail_delete_confirm_message, new DialogInterface.OnClickListener() {
@Override
@Override
public void onClick(DialogInterface dialog, int which) {
MyTracksProviderUtils.Factory.get(getActivity())
.deleteTrack(getArguments().getLong(KEY_TRACK_ID));
Intent intent = IntentUtils.newIntent(getActivity(), TrackListActivity.class);
long trackId = getArguments().getLong(KEY_TRACK_ID);
Context context = getActivity();
if (trackId == PreferencesUtils.getLong(context, R.string.recording_track_id_key)) {
TrackRecordingServiceConnectionUtils.stop(
context, caller.getTrackRecordingServiceConnection(), false);
}
MyTracksProviderUtils.Factory.get(context).deleteTrack(trackId);
Intent intent = IntentUtils.newIntent(context, TrackListActivity.class);
startActivity(intent);
// Close the activity since its content can change after delete.
// Close the activity since its content can change after delete
getActivity().finish();
}
});
@@ -1,122 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.fragments;
import com.google.android.apps.mytracks.MarkerEditActivity;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
import com.google.android.maps.mytracks.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
/**
* A DialogFragment to add a marker.
*
* @author Jimmy Shih
*/
public class MarkerAddDialogFragment extends DialogFragment {
public static final String MARKER_ADD_DIALOG_TAG = "markerAddDialog";
private static final String KEY_TRACK_ID = "trackId";
private TrackRecordingServiceConnection trackRecordingServiceConnection;
private RadioGroup radioGroup;
private Button moreOptions;
/**
* Creates a new instance of {@link MarkerAddDialogFragment}.
*
* @param trackId the track id
*/
public static MarkerAddDialogFragment newInstance(long trackId) {
Bundle bundle = new Bundle();
bundle.putLong(KEY_TRACK_ID, trackId);
MarkerAddDialogFragment markerAddDialogFragment = new MarkerAddDialogFragment();
markerAddDialogFragment.setArguments(bundle);
return markerAddDialogFragment;
}
@Override
public void onCreate(Bundle arg0) {
super.onCreate(arg0);
trackRecordingServiceConnection = new TrackRecordingServiceConnection(getActivity(), null);
}
@Override
public void onResume() {
super.onResume();
TrackRecordingServiceConnectionUtils.resume(getActivity(), trackRecordingServiceConnection);
}
@Override
public void onDestroy() {
super.onDestroy();
trackRecordingServiceConnection.unbind();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.marker_add, null);
radioGroup = (RadioGroup) view.findViewById(R.id.marker_add_type);
moreOptions = (Button) view.findViewById(R.id.marker_add_more_options);
moreOptions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean statisticsMarker = radioGroup.getCheckedRadioButtonId()
== R.id.marker_add_statistics;
Intent intent = IntentUtils.newIntent(getActivity(), MarkerEditActivity.class);
intent.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, getArguments().getLong(KEY_TRACK_ID));
intent.putExtra(MarkerEditActivity.EXTRA_STATISTICS_MARKER, statisticsMarker);
startActivity(intent);
dismiss();
}
});
boolean pickStatisticsMarker = PreferencesUtils.getBoolean(getActivity(),
R.string.pick_statistics_marker_key, PreferencesUtils.PICK_STATISTICS_MARKER_DEFAULT);
radioGroup.check(pickStatisticsMarker ? R.id.marker_add_statistics : R.id.marker_add_waypoint);
return new AlertDialog.Builder(getActivity())
.setNegativeButton(R.string.generic_cancel, null)
.setPositiveButton(R.string.generic_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
boolean statisticsMarker = radioGroup.getCheckedRadioButtonId()
== R.id.marker_add_statistics;
PreferencesUtils.setBoolean(
getActivity(), R.string.pick_statistics_marker_key, statisticsMarker);
TrackRecordingServiceConnectionUtils.addMarker(getActivity(),
trackRecordingServiceConnection,
statisticsMarker ? WaypointCreationRequest.DEFAULT_STATISTICS
: WaypointCreationRequest.DEFAULT_WAYPOINT);
}
})
.setTitle(R.string.menu_insert_marker)
.setView(view)
.create();
}
}
@@ -102,7 +102,7 @@ public class CsvTrackWriter implements TrackFormatWriter {
@Override
public void writeBeginWaypoints() {
writeCommaSeparatedLine(context.getString(R.string.generic_name),
context.getString(R.string.marker_edit_waypoint_marker_type_hint),
context.getString(R.string.marker_edit_marker_type_hint),
context.getString(R.string.generic_description),
context.getString(R.string.description_location_latitude),
context.getString(R.string.description_location_longitude),
@@ -30,6 +30,7 @@ import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
import com.google.android.apps.mytracks.content.WaypointCreationRequest.WaypointType;
import com.google.android.apps.mytracks.content.WaypointsColumns;
import com.google.android.apps.mytracks.services.sensors.SensorManager;
import com.google.android.apps.mytracks.services.sensors.SensorManagerFactory;
@@ -589,7 +590,7 @@ public class TrackRecordingService extends Service {
statsBuilder.setMinRecordingDistance(minRecordingDistance);
waypointStatsBuilder = new TripStatisticsBuilder(startTime);
waypointStatsBuilder.setMinRecordingDistance(minRecordingDistance);
currentWaypointId = insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
currentWaypointId = insertWaypoint(WaypointCreationRequest.DEFAULT_START_TRACK);
length = 0;
showNotification();
registerLocationListener();
@@ -916,37 +917,33 @@ public class TrackRecordingService extends Service {
public long insertWaypoint(WaypointCreationRequest request) {
if (!isRecording()) {
throw new IllegalStateException(
"Unable to insert waypoint marker while not recording!");
throw new IllegalStateException("Unable to insert marker while not recording!");
}
if (request == null) {
request = WaypointCreationRequest.DEFAULT_WAYPOINT;
}
Waypoint wpt = new Waypoint();
switch (request.getType()) {
case WAYPOINT:
buildWaypointMarker(wpt, request);
break;
case STATISTICS:
buildStatisticsMarker(wpt, request);
break;
}
wpt.setTrackId(recordingTrackId);
wpt.setLength(length);
if (lastLocation == null
|| statsBuilder == null || statsBuilder.getStatistics() == null) {
// A null location is ok, and expected on track start.
// Make it an impossible location.
Location l = new Location("");
l.setLatitude(100);
l.setLongitude(180);
wpt.setLocation(l);
Waypoint waypoint = new Waypoint();
if (request.getType() == WaypointType.WAYPOINT) {
buildWaypointMarker(waypoint, request);
} else {
wpt.setLocation(lastLocation);
wpt.setDuration(lastLocation.getTime()
- statsBuilder.getStatistics().getStartTime());
buildStatisticsMarker(waypoint, request);
}
Uri uri = providerUtils.insertWaypoint(wpt);
waypoint.setTrackId(recordingTrackId);
waypoint.setLength(length);
if (lastLocation == null || statsBuilder == null || statsBuilder.getStatistics() == null) {
if (!request.isTrackStatistics()) {
return -1L;
}
/*
* For track statistics, a null location is OK. Make it an impossible
* location.
*/
Location location = new Location("");
location.setLatitude(100);
location.setLongitude(180);
waypoint.setLocation(location);
} else {
waypoint.setLocation(lastLocation);
waypoint.setDuration(lastLocation.getTime() - statsBuilder.getStatistics().getStartTime());
}
Uri uri = providerUtils.insertWaypoint(waypoint);
return Long.parseLong(uri.getLastPathSegment());
}
@@ -963,7 +960,7 @@ public class TrackRecordingService extends Service {
} else {
int nextMarkerNumber = providerUtils.getNextMarkerNumber(recordingTrackId, false);
name = nextMarkerNumber == -1 ? getString(R.string.marker_type_waypoint)
: getString(R.string.marker_waypoint_name_format, nextMarkerNumber);
: getString(R.string.marker_name_format, nextMarkerNumber);
}
wpt.setName(name);
if (request.getCategory() != null) {
@@ -18,7 +18,9 @@ package com.google.android.apps.mytracks.util;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
/**
@@ -33,26 +35,32 @@ public class ListItemUtils {
/**
* Sets a list item.
*
* @param context the context
* @param view the list item view
* @param name the name value
* @param iconId the icon id
* @param iconContentDescription the icon content description
* @param category the category value
* @param totalTime the total time value
* @param totalDistance the total distance value
* @param startTime the start time value
* @param description the description value
*/
public static void setListItem(View view,
public static void setListItem(Context context, View view,
String name,
int iconId,
String iconContentDescription,
String category,
String totalTime,
String totalDistance,
String startTime,
long startTime,
String description) {
ImageView iconImageView = (ImageView) view.findViewById(R.id.list_item_icon);
iconImageView.setImageResource(iconId);
iconImageView.setContentDescription(iconContentDescription);
TextView nameTextView = (TextView) view.findViewById(R.id.list_item_name);
nameTextView.setText(name);
nameTextView.setCompoundDrawablesWithIntrinsicBounds(iconId, 0, 0, 0);
TextView categoryTextView = (TextView) view.findViewById(R.id.list_item_category);
setTextView(categoryTextView, category);
@@ -63,8 +71,11 @@ public class ListItemUtils {
TextView totalDistanceTextView = (TextView) view.findViewById(R.id.list_item_total_distance);
setTextView(totalDistanceTextView, totalDistance);
String startTimeDisplay = startTime == 0L
|| StringUtils.formatDateTime(context, startTime).equals(name) ? null
: StringUtils.formatRelativeDateTime(context, startTime);
TextView startTimeTextView = (TextView) view.findViewById(R.id.list_item_start_time);
setTextView(startTimeTextView, startTime);
setTextView(startTimeTextView, startTimeDisplay);
TextView descriptionTextView = (TextView) view.findViewById(R.id.list_item_description);
setTextView(descriptionTextView, description);
@@ -66,7 +66,6 @@ public class PreferencesUtils {
public static final int PERIODIC_TASK_OFF = 0;
public static final boolean PICK_EXISTING_MAP_DEFAULT = false;
public static final boolean PICK_STATISTICS_MARKER_DEFAULT = true;
public static final String PREFERRED_ACCOUNT_DEFAULT = "";
public static final long RECORDING_TRACK_ID_DEFAULT = -1L;
public static final boolean REPORT_SPEED_DEFAULT = true;
@@ -23,6 +23,7 @@ import android.text.format.DateUtils;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.regex.Matcher;
@@ -42,7 +43,6 @@ public class StringUtils {
"yyyy-MM-dd'T'HH:mm:ss");
private static final Pattern ISO_8601_EXTRAS = Pattern.compile(
"^(\\.\\d+)?(?:Z|([+-])(\\d{2}):(\\d{2}))?$");
static {
ISO_8601_DATE_TIME_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
ISO_8601_BASE.setTimeZone(TimeZone.getTimeZone("UTC"));
@@ -50,25 +50,31 @@ public class StringUtils {
private StringUtils() {}
/**
* Formats the time based on user's phone date/time preferences.
*
* @param context the context
* @param time the time in milliseconds
*/
public static String formatTime(Context context, long time) {
return android.text.format.DateFormat.getTimeFormat(context).format(time);
}
/**
* Formats the date and time based on user's phone date/time preferences.
*
*
* @param context the context
* @param time the time in milliseconds
*/
public static String formatDateTime(Context context, long time) {
return android.text.format.DateFormat.getDateFormat(context).format(time) + " "
+ formatTime(context, time);
+ DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_TIME).toString();
}
/**
* Formats the relative date and time based on user's phone date/time preferences.
*
* @param context the context
* @param time the time in milliseconds
*/
public static String formatRelativeDateTime(Context context, long time) {
long now = Calendar.getInstance().getTimeInMillis();
if (now - time > DateUtils.WEEK_IN_MILLIS) {
return formatDateTime(context, time);
} else {
return DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE).toString();
}
}
/**
@@ -96,24 +96,30 @@ public class TrackRecordingServiceConnectionUtils {
* @param context the context
* @param trackRecordingServiceConnection the track recording service
* connection
* @param showEditor true to show the editor
*/
public static void stop(
Context context, TrackRecordingServiceConnection trackRecordingServiceConnection) {
public static void stop(Context context,
TrackRecordingServiceConnection trackRecordingServiceConnection, boolean showEditor) {
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection
.getServiceIfBound();
if (trackRecordingService != null) {
try {
/*
* Need to remember the recordingTrackId before calling endCurrentTrack.
* endCurrentTrack sets the value to -1L.
*/
long recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key);
trackRecordingService.endCurrentTrack();
if (recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
Intent intent = IntentUtils.newIntent(context, TrackEditActivity.class)
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, recordingTrackId)
.putExtra(TrackEditActivity.EXTRA_NEW_TRACK, true);
context.startActivity(intent);
if (showEditor) {
/*
* Need to remember the recordingTrackId before calling
* endCurrentTrack. endCurrentTrack sets the value to -1L.
*/
long recordingTrackId = PreferencesUtils.getLong(
context, R.string.recording_track_id_key);
trackRecordingService.endCurrentTrack();
if (recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
Intent intent = IntentUtils.newIntent(context, TrackEditActivity.class)
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, recordingTrackId)
.putExtra(TrackEditActivity.EXTRA_NEW_TRACK, true);
context.startActivity(intent);
}
} else {
trackRecordingService.endCurrentTrack();
}
} catch (Exception e) {
Log.e(TAG, "Unable to stop recording.", e);