forked from upstream-mirrors/OpenTracks
Merge heads
This commit is contained in:
@@ -485,9 +485,9 @@ public class ChartView extends View {
|
||||
}
|
||||
}
|
||||
if (nearestWaypoint != null && dmin < 100) {
|
||||
Intent intent =
|
||||
new Intent(getContext(), WaypointDetails.class);
|
||||
intent.putExtra(WaypointDetails.WAYPOINT_ID_EXTRA, nearestWaypoint.getId());
|
||||
Intent intent = new Intent(getContext(), MarkerDetailActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, nearestWaypoint.getId());
|
||||
getContext().startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,18 +33,6 @@ public abstract class Constants {
|
||||
*/
|
||||
public static final String SDCARD_TOP_DIR = "MyTracks";
|
||||
|
||||
/*
|
||||
* onActivityResult request codes:
|
||||
*/
|
||||
public static final int SHOW_WAYPOINT = 0;
|
||||
|
||||
/*
|
||||
* Context menu ids. Sorted alphabetically.
|
||||
*/
|
||||
public static final int MENU_DELETE = 100;
|
||||
public static final int MENU_EDIT = 101;
|
||||
public static final int MENU_SHOW = 102;
|
||||
|
||||
/*
|
||||
* Main screen tab tags:
|
||||
*/
|
||||
|
||||
@@ -444,8 +444,9 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe
|
||||
|
||||
if (waypoint != null &&
|
||||
dmin < 15000000 / Math.pow(2, mapView.getZoomLevel())) {
|
||||
Intent intent = new Intent(context, WaypointDetails.class);
|
||||
intent.putExtra(WaypointDetails.WAYPOINT_ID_EXTRA, waypoint.getId());
|
||||
Intent intent = new Intent(context, MarkerDetailActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, waypoint.getId());
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright 2009 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;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.StatsUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* An activity to display marker detail info.
|
||||
*
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public class MarkerDetailActivity extends FragmentActivity {
|
||||
|
||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||
private static final String TAG = MarkerDetailActivity.class.getSimpleName();
|
||||
|
||||
private long markerId;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
|
||||
ApiAdapterFactory.getApiAdapter().configureActionBarHomeAsUp(this);
|
||||
setContentView(R.layout.marker_detail);
|
||||
|
||||
markerId = getIntent().getLongExtra(EXTRA_MARKER_ID, -1L);
|
||||
if (markerId == -1L) {
|
||||
Log.d(TAG, "invalid marker id");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
Waypoint 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_marker_type);
|
||||
markerType.setText(getString(R.string.marker_detail_marker_type, waypoint.getCategory()));
|
||||
TextView description = (TextView) findViewById(R.id.marker_detail_description);
|
||||
description.setText(getString(R.string.marker_detail_description, waypoint.getDescription()));
|
||||
|
||||
} else {
|
||||
waypointSection.setVisibility(View.GONE);
|
||||
statisticsSection.setVisibility(View.VISIBLE);
|
||||
|
||||
SharedPreferences preferences = getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
boolean metricUnits = preferences.getBoolean(getString(R.string.metric_units_key), true);
|
||||
boolean reportSpeed = preferences.getBoolean(getString(R.string.report_speed_key), true);
|
||||
|
||||
StatsUtils.setSpeedLabel(this, R.id.marker_detail_max_speed_label, R.string.stat_max_speed,
|
||||
R.string.stat_fastest_pace, reportSpeed);
|
||||
StatsUtils.setSpeedLabel(this, R.id.marker_detail_average_speed_label,
|
||||
R.string.stat_average_speed, R.string.stat_average_pace, reportSpeed);
|
||||
StatsUtils.setSpeedLabel(this, R.id.marker_detail_average_moving_speed_label,
|
||||
R.string.stat_average_moving_speed, R.string.stat_average_moving_pace, reportSpeed);
|
||||
|
||||
TripStatistics tripStatistics = waypoint.getStatistics();
|
||||
|
||||
StatsUtils.setDistanceValue(this, R.id.marker_detail_total_distance_value,
|
||||
tripStatistics.getTotalDistance(), metricUnits);
|
||||
StatsUtils.setSpeedValue(this, R.id.marker_detail_max_speed_value,
|
||||
tripStatistics.getMaxSpeed(), reportSpeed, metricUnits);
|
||||
|
||||
StatsUtils.setTimeValue(
|
||||
this, R.id.marker_detail_total_time_value, tripStatistics.getTotalTime());
|
||||
StatsUtils.setSpeedValue(this, R.id.marker_detail_average_speed_value,
|
||||
tripStatistics.getAverageSpeed(), reportSpeed, metricUnits);
|
||||
|
||||
StatsUtils.setTimeValue(
|
||||
this, R.id.marker_detail_moving_time_value, tripStatistics.getMovingTime());
|
||||
StatsUtils.setSpeedValue(this, R.id.marker_detail_average_moving_speed_value,
|
||||
tripStatistics.getAverageMovingSpeed(), reportSpeed, metricUnits);
|
||||
|
||||
StatsUtils.setAltitudeValue(this, R.id.marker_detail_elevation_value,
|
||||
waypoint.getLocation().getAltitude(), metricUnits);
|
||||
StatsUtils.setAltitudeValue(this, R.id.marker_detail_elevation_gain_value,
|
||||
tripStatistics.getTotalElevationGain(), metricUnits);
|
||||
|
||||
StatsUtils.setAltitudeValue(this, R.id.marker_detail_min_elevation_value,
|
||||
tripStatistics.getMinElevation(), metricUnits);
|
||||
StatsUtils.setAltitudeValue(this, R.id.marker_detail_max_elevation_value,
|
||||
tripStatistics.getMaxElevation(), metricUnits);
|
||||
|
||||
StatsUtils.setGradeValue(
|
||||
this, R.id.marker_detail_min_grade_value, tripStatistics.getMinGrade());
|
||||
StatsUtils.setGradeValue(
|
||||
this, R.id.marker_detail_max_grade_value, tripStatistics.getMaxGrade());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.marker_detail, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.marker_detail_show_on_map:
|
||||
startActivity(new Intent(this, TrackDetailActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId));
|
||||
return true;
|
||||
case R.id.marker_detail_edit:
|
||||
startActivity(new Intent(this, MarkerEditActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId));
|
||||
return true;
|
||||
case R.id.marker_detail_delete:
|
||||
DeleteOneMarkerDialogFragment.newInstance(markerId).show(getSupportFragmentManager(),
|
||||
DeleteOneMarkerDialogFragment.DELETE_ONE_MARKER_DIALOG_TAG);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
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.ITrackRecordingService;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* An activity to add/edit a marker.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class MarkerEditActivity extends Activity {
|
||||
|
||||
private static final String TAG = MarkerEditActivity.class.getSimpleName();
|
||||
|
||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||
|
||||
private long markerId;
|
||||
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
||||
private Waypoint waypoint;
|
||||
|
||||
// UI elements
|
||||
private View typeSection;
|
||||
private RadioGroup type;
|
||||
private EditText name;
|
||||
private View waypointSection;
|
||||
private AutoCompleteTextView markerType;
|
||||
private EditText description;
|
||||
private Button done;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
|
||||
ApiAdapterFactory.getApiAdapter().configureActionBarHomeAsUp(this);
|
||||
setContentView(R.layout.marker_edit);
|
||||
|
||||
markerId = getIntent().getLongExtra(EXTRA_MARKER_ID, -1L);
|
||||
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_type_statistics;
|
||||
name.setText(
|
||||
statistics ? R.string.marker_edit_type_statistics : R.string.marker_edit_type_waypoint);
|
||||
updateUiByMarkerType(statistics);
|
||||
}
|
||||
});
|
||||
name = (EditText) findViewById(R.id.marker_edit_name);
|
||||
waypointSection = findViewById(R.id.marker_edit_waypoint_section);
|
||||
markerType = (AutoCompleteTextView) findViewById(R.id.marker_edit_marker_type);
|
||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
|
||||
this, R.array.waypoint_types, android.R.layout.simple_dropdown_item_1line);
|
||||
markerType.setAdapter(adapter);
|
||||
description = (EditText) findViewById(R.id.marker_edit_description);
|
||||
|
||||
Button cancel = (Button) findViewById(R.id.marker_edit_cancel);
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
done = (Button) findViewById(R.id.marker_edit_done);
|
||||
updateUiByMarkerId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI based on the marker id.
|
||||
*/
|
||||
private void updateUiByMarkerId() {
|
||||
final boolean newMarker = markerId == -1L;
|
||||
|
||||
setTitle(newMarker ? R.string.marker_edit_add_title : R.string.menu_edit);
|
||||
typeSection.setVisibility(newMarker ? View.VISIBLE : View.GONE);
|
||||
done.setText(newMarker ? R.string.marker_edit_add : R.string.generic_save);
|
||||
done.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (newMarker) {
|
||||
addMarker();
|
||||
} else {
|
||||
saveMarker();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
if (newMarker) {
|
||||
type.check(R.id.marker_edit_type_statistics);
|
||||
} else {
|
||||
waypoint = MyTracksProviderUtils.Factory.get(this).getWaypoint(markerId);
|
||||
if (waypoint == null) {
|
||||
Log.d(TAG, "waypoint is null");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
name.setText(waypoint.getName());
|
||||
boolean statistics = waypoint.getType() == Waypoint.TYPE_STATISTICS;
|
||||
updateUiByMarkerType(statistics);
|
||||
if (!statistics) {
|
||||
markerType.setText(waypoint.getCategory());
|
||||
description.setText(waypoint.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI by marker type.
|
||||
*
|
||||
* @param statistics true for a statistics marker
|
||||
*/
|
||||
private void updateUiByMarkerType(boolean statistics) {
|
||||
name.setCompoundDrawablesWithIntrinsicBounds(
|
||||
statistics ? R.drawable.ylw_pushpin : R.drawable.blue_pushpin, 0, 0, 0);
|
||||
name.setImeOptions(statistics ? EditorInfo.IME_ACTION_DONE : EditorInfo.IME_ACTION_NEXT);
|
||||
waypointSection.setVisibility(statistics ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
TrackRecordingServiceConnectionUtils.resume(this, trackRecordingServiceConnection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
trackRecordingServiceConnection.unbind();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() != android.R.id.home) {
|
||||
return false;
|
||||
}
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a marker.
|
||||
*/
|
||||
private void addMarker() {
|
||||
boolean statistics = type.getCheckedRadioButtonId() == R.id.marker_edit_type_statistics;
|
||||
WaypointType waypointType = statistics ? WaypointType.STATISTICS : WaypointType.MARKER;
|
||||
String markerCategory = statistics ? null : markerType.getText().toString();
|
||||
String markerDescription = statistics ? null : description.getText().toString();
|
||||
String markerIconUrl = getString(
|
||||
statistics ? R.string.marker_statistics_icon_url : R.string.marker_waypoint_icon_url);
|
||||
WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(
|
||||
waypointType, name.getText().toString(), markerCategory, markerDescription, markerIconUrl);
|
||||
ITrackRecordingService trackRecordingService =
|
||||
trackRecordingServiceConnection.getServiceIfBound();
|
||||
if (trackRecordingService == null) {
|
||||
Log.d(TAG, "Unable to add marker, no track recording service");
|
||||
} else {
|
||||
try {
|
||||
if (trackRecordingService.insertWaypoint(waypointCreationRequest) != -1L) {
|
||||
Toast.makeText(this, R.string.marker_edit_add_success, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Unable to add marker", e);
|
||||
} catch (IllegalStateException e) {
|
||||
Log.e(TAG, "Unable to add marker.", e);
|
||||
}
|
||||
}
|
||||
Toast.makeText(this, R.string.marker_edit_add_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a marker.
|
||||
*/
|
||||
private void saveMarker() {
|
||||
waypoint.setName(name.getText().toString());
|
||||
if (waypoint.getType() == Waypoint.TYPE_WAYPOINT) {
|
||||
waypoint.setCategory(markerType.getText().toString());
|
||||
waypoint.setDescription(description.getText().toString());
|
||||
}
|
||||
MyTracksProviderUtils.Factory.get(this).updateWaypoint(waypoint);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
* Copyright 2009 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;
|
||||
|
||||
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.util.ApiAdapterFactory;
|
||||
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;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.widget.ResourceCursorAdapter;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Activity to show a list of markers in a track.
|
||||
*
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public class MarkerListActivity extends FragmentActivity {
|
||||
|
||||
public static final String EXTRA_TRACK_ID = "track_id";
|
||||
|
||||
private static final String TAG = MarkerListActivity.class.getSimpleName();
|
||||
|
||||
private static final String[] PROJECTION = new String[] { WaypointsColumns._ID,
|
||||
WaypointsColumns.TYPE,
|
||||
WaypointsColumns.NAME,
|
||||
WaypointsColumns.CATEGORY,
|
||||
WaypointsColumns.TIME,
|
||||
WaypointsColumns.DESCRIPTION };
|
||||
|
||||
// Callback when an item is selected in the contextual action mode
|
||||
private ContextualActionModeCallback contextualActionModeCallback =
|
||||
new ContextualActionModeCallback() {
|
||||
@Override
|
||||
public boolean onClick(int itemId, long id) {
|
||||
return handleContextItem(itemId, id);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Note that sharedPreferenceChangeListener cannot be an anonymous inner
|
||||
* class. Anonymous inner class will get garbage collected.
|
||||
*/
|
||||
private final OnSharedPreferenceChangeListener sharedPreferenceChangeListener =
|
||||
new OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
// Note that key can be null
|
||||
if (PreferencesUtils.getRecordingTrackIdKey(MarkerListActivity.this).equals(key)) {
|
||||
updateMenu();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private long trackId = -1;
|
||||
private ResourceCursorAdapter resourceCursorAdapter;
|
||||
|
||||
// UI elements
|
||||
private MenuItem insertMarkerMenuItem;
|
||||
private MenuItem searchMenuItem;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||
if (trackId == -1L) {
|
||||
Log.d(TAG, "invalid track id");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
ApiAdapterFactory.getApiAdapter().configureActionBarHomeAsUp(this);
|
||||
setContentView(R.layout.marker_list);
|
||||
|
||||
SharedPreferences sharedPreferences = getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
|
||||
ListView listView = (ListView) findViewById(R.id.marker_list);
|
||||
listView.setEmptyView(findViewById(R.id.marker_list_empty));
|
||||
listView.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
startActivity(new Intent(MarkerListActivity.this, MarkerDetailActivity.class).addFlags(
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, id));
|
||||
}
|
||||
});
|
||||
resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.marker_list_item, null, 0) {
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE);
|
||||
int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME);
|
||||
int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY);
|
||||
int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME);
|
||||
int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION);
|
||||
|
||||
boolean statistics = cursor.getInt(typeIndex) == Waypoint.TYPE_STATISTICS;
|
||||
TextView name = (TextView) view.findViewById(R.id.marker_list_item_name);
|
||||
name.setText(cursor.getString(nameIndex));
|
||||
name.setCompoundDrawablesWithIntrinsicBounds(statistics ? R.drawable.ylw_pushpin
|
||||
: R.drawable.blue_pushpin, 0, 0, 0);
|
||||
|
||||
TextView category = (TextView) view.findViewById(R.id.marker_list_item_category);
|
||||
if (!statistics) {
|
||||
category.setText(cursor.getString(categoryIndex));
|
||||
}
|
||||
category.setVisibility(statistics || category.getText().length() == 0 ? View.GONE : View.VISIBLE);
|
||||
|
||||
TextView time = (TextView) view.findViewById(R.id.marker_list_item_time);
|
||||
long timeValue = cursor.getLong(timeIndex);
|
||||
if (timeValue == 0) {
|
||||
time.setVisibility(View.GONE);
|
||||
} else {
|
||||
time.setText(StringUtils.formatDateTime(MarkerListActivity.this, timeValue));
|
||||
time.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
TextView description = (TextView) view.findViewById(R.id.marker_list_item_description);
|
||||
if (!statistics) {
|
||||
description.setText(cursor.getString(descriptionIndex));
|
||||
}
|
||||
description.setVisibility(statistics || description.getText().length() == 0 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
};
|
||||
listView.setAdapter(resourceCursorAdapter);
|
||||
ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(
|
||||
this, listView, R.menu.marker_list_context_menu, R.id.marker_list_item_name,
|
||||
contextualActionModeCallback);
|
||||
|
||||
|
||||
final long firstWaypointId = MyTracksProviderUtils.Factory.get(this).getFirstWaypointId(trackId);
|
||||
getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() {
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
return new CursorLoader(MarkerListActivity.this,
|
||||
WaypointsColumns.CONTENT_URI,
|
||||
PROJECTION,
|
||||
WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + "!=?",
|
||||
new String[] { String.valueOf(trackId), String.valueOf(firstWaypointId) },
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||
resourceCursorAdapter.swapCursor(cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
resourceCursorAdapter.swapCursor(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.marker_list, menu);
|
||||
insertMarkerMenuItem = menu.findItem(R.id.marker_list_insert_marker);
|
||||
searchMenuItem = menu.findItem(R.id.marker_list_search);
|
||||
ApiAdapterFactory.getApiAdapter().configureSearchWidget(this, searchMenuItem);
|
||||
updateMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateMenu() {
|
||||
if (insertMarkerMenuItem != null) {
|
||||
insertMarkerMenuItem.setVisible(trackId == PreferencesUtils.getRecordingTrackId(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.marker_list_insert_marker:
|
||||
startActivity(new Intent(this, MarkerEditActivity.class).addFlags(
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
return true;
|
||||
case R.id.marker_list_search:
|
||||
return ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(this);
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
getMenuInflater().inflate(R.menu.marker_list_context_menu, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
if (handleContextItem(
|
||||
item.getItemId(), ((AdapterContextMenuInfo) item.getMenuInfo()).id)) {
|
||||
return true;
|
||||
}
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a context item selection.
|
||||
*
|
||||
* @param itemId the menu item id
|
||||
* @param markerId the marker id
|
||||
* @return true if handled.
|
||||
*/
|
||||
private boolean handleContextItem(int itemId, long markerId) {
|
||||
switch (itemId) {
|
||||
case R.id.marker_list_context_menu_show_on_map:
|
||||
startActivity(new Intent(this, TrackDetailActivity.class).addFlags(
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId));
|
||||
return true;
|
||||
case R.id.marker_list_context_menu_edit:
|
||||
startActivity(new Intent(this, MarkerEditActivity.class).addFlags(
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId));
|
||||
return true;
|
||||
case R.id.marker_list_context_menu_delete:
|
||||
DeleteOneMarkerDialogFragment.newInstance(markerId).show(getSupportFragmentManager(),
|
||||
DeleteOneMarkerDialogFragment.DELETE_ONE_MARKER_DIALOG_TAG);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
||||
if (ApiAdapterFactory.getApiAdapter().handleSearchKey(searchMenuItem)) { return true; }
|
||||
}
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
}
|
||||
@@ -248,10 +248,12 @@ public class SearchActivity extends ListActivity {
|
||||
|
||||
private Intent createViewDataIntent(Map<String, Object> clickedData) {
|
||||
Intent intent = new Intent(this, TrackDetailActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, (Long) clickedData.get(TRACK_ID_FIELD));
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
if (clickedData.containsKey(WAYPOINT_ID_FIELD)) {
|
||||
intent.putExtra(TrackDetailActivity.EXTRA_WAYPOINT_ID, (Long) clickedData.get(WAYPOINT_ID_FIELD));
|
||||
intent.putExtra(
|
||||
TrackDetailActivity.EXTRA_MARKER_ID, (Long) clickedData.get(WAYPOINT_ID_FIELD));
|
||||
} else {
|
||||
intent.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, (Long) clickedData.get(TRACK_ID_FIELD));
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ public class SensorStateActivity extends Activity {
|
||||
String value;
|
||||
if (sds.hasBatteryLevel() && sds.getBatteryLevel().hasValue()
|
||||
&& sds.getBatteryLevel().getState() == Sensor.SensorState.SENDING) {
|
||||
String format = getString(R.string.sensor_state_battery_value);
|
||||
String format = getString(R.string.value_integer_percent);
|
||||
value = String.format(format, sds.getBatteryLevel().getValue());
|
||||
} else {
|
||||
value = SensorUtils.getStateAsString(
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.google.android.apps.mytracks;
|
||||
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.StatsUtils;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
@@ -29,6 +30,8 @@ import java.text.NumberFormat;
|
||||
/**
|
||||
* Various utility functions for views that display statistics information.
|
||||
*
|
||||
* @deprecated use {@link StatsUtils}.
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public class StatsUtilities {
|
||||
|
||||
@@ -20,7 +20,9 @@ import static com.google.android.apps.mytracks.Constants.CHART_TAB_TAG;
|
||||
import static com.google.android.apps.mytracks.Constants.MAP_TAB_TAG;
|
||||
import static com.google.android.apps.mytracks.Constants.STATS_TAB_TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.TrackDataHub;
|
||||
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.ChartSettingsDialogFragment;
|
||||
@@ -71,7 +73,7 @@ import java.util.List;
|
||||
public class TrackDetailActivity extends FragmentActivity {
|
||||
|
||||
public static final String EXTRA_TRACK_ID = "track_id";
|
||||
public static final String EXTRA_WAYPOINT_ID = "waypoint_id";
|
||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||
|
||||
private static final String TAG = TrackDetailActivity.class.getSimpleName();
|
||||
private static final String CURRENT_TAG_KEY = "tab";
|
||||
@@ -264,7 +266,8 @@ public class TrackDetailActivity extends FragmentActivity {
|
||||
TrackRecordingServiceConnectionUtils.stop(this, trackRecordingServiceConnection);
|
||||
return true;
|
||||
case R.id.track_detail_insert_marker:
|
||||
// TODO: Add insert marker when updating WaypointList to ICS
|
||||
startActivity(new Intent(this, MarkerEditActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
return true;
|
||||
case R.id.track_detail_play:
|
||||
if (isEarthInstalled()) {
|
||||
@@ -302,9 +305,10 @@ public class TrackDetailActivity extends FragmentActivity {
|
||||
startSaveActivity(TrackFileFormat.TCX, true);
|
||||
return true;
|
||||
case R.id.track_detail_markers:
|
||||
intent = new Intent(this, WaypointsList.class)
|
||||
.putExtra("trackid", trackDataHub.getSelectedTrackId());
|
||||
startActivityForResult(intent, Constants.SHOW_WAYPOINT);
|
||||
intent = new Intent(this, MarkerListActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(MarkerListActivity.EXTRA_TRACK_ID, trackId);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.track_detail_send_google:
|
||||
intent = new Intent(this, UploadServiceChooserActivity.class)
|
||||
@@ -361,25 +365,6 @@ public class TrackDetailActivity extends FragmentActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, final Intent results) {
|
||||
if (requestCode != Constants.SHOW_WAYPOINT) {
|
||||
Log.d(TAG, "Invalid request code: " + requestCode);
|
||||
return;
|
||||
}
|
||||
if (results != null) {
|
||||
long waypointId = results.getLongExtra(WaypointDetails.WAYPOINT_ID_EXTRA, -1L);
|
||||
if (waypointId != -1L) {
|
||||
MapFragment mapFragment = (MapFragment) getSupportFragmentManager()
|
||||
.findFragmentByTag(MAP_TAB_TAG);
|
||||
if (mapFragment != null) {
|
||||
tabHost.setCurrentTab(0);
|
||||
mapFragment.showWaypoint(waypointId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTrackballEvent(MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
@@ -401,9 +386,8 @@ public class TrackDetailActivity extends FragmentActivity {
|
||||
Log.e(TAG, "Unable to insert waypoint", e);
|
||||
}
|
||||
Toast.makeText(this,
|
||||
success ? R.string.marker_insert_success : R.string.marker_insert_error,
|
||||
success ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG)
|
||||
.show();
|
||||
success ? R.string.marker_edit_add_success : R.string.marker_edit_add_error,
|
||||
success ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG).show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -421,22 +405,30 @@ public class TrackDetailActivity extends FragmentActivity {
|
||||
* Handles the data in the intent.
|
||||
*/
|
||||
private void handleIntent(Intent intent) {
|
||||
// Get the trackid
|
||||
trackId = intent.getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||
trackId = intent.getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||
long markerId = intent.getLongExtra(EXTRA_MARKER_ID, -1L);
|
||||
if (markerId != -1L) {
|
||||
Waypoint waypoint = MyTracksProviderUtils.Factory.get(this).getWaypoint(markerId);
|
||||
if (waypoint == null) {
|
||||
startTrackListActivity();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
trackId = waypoint.getTrackId();
|
||||
}
|
||||
if (trackId == -1L) {
|
||||
startTrackListActivity();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
trackDataHub.loadTrack(trackId);
|
||||
|
||||
// Get the waypointId
|
||||
long waypointId = intent.getLongExtra(EXTRA_WAYPOINT_ID, -1L);
|
||||
if (waypointId != -1L) {
|
||||
if (markerId != -1L) {
|
||||
MapFragment mapFragmet = (MapFragment) getSupportFragmentManager()
|
||||
.findFragmentByTag(MAP_TAB_TAG);
|
||||
if (mapFragmet != null) {
|
||||
tabHost.setCurrentTab(0);
|
||||
mapFragmet.showWaypoint(trackId, waypointId);
|
||||
tabHost.setCurrentTabByTag(MAP_TAB_TAG);
|
||||
mapFragmet.showMarker(trackId, markerId);
|
||||
} else {
|
||||
Log.e(TAG, "MapFragment is null");
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public class TrackListActivity extends FragmentActivity {
|
||||
}
|
||||
updateMenu();
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
resourceCursorAdapter.notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -142,17 +142,17 @@ public class TrackListActivity extends FragmentActivity {
|
||||
private boolean metricUnits;
|
||||
private long recordingTrackId;
|
||||
private ListView listView;
|
||||
private ResourceCursorAdapter adapter;
|
||||
private ResourceCursorAdapter resourceCursorAdapter;
|
||||
|
||||
// True to start a new recording.
|
||||
private boolean startNewRecording = false;
|
||||
|
||||
private MenuItem recordTrack;
|
||||
private MenuItem stopRecording;
|
||||
private MenuItem search;
|
||||
private MenuItem importAll;
|
||||
private MenuItem exportAll;
|
||||
private MenuItem deleteAll;
|
||||
private MenuItem recordTrackMenuItem;
|
||||
private MenuItem stopRecordingMenuItem;
|
||||
private MenuItem searchMenuItem;
|
||||
private MenuItem importAllMenuItem;
|
||||
private MenuItem exportAllMenuItem;
|
||||
private MenuItem deleteAllMenuItem;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -187,7 +187,7 @@ public class TrackListActivity extends FragmentActivity {
|
||||
startTrackDetailActivity(id);
|
||||
}
|
||||
});
|
||||
adapter = new ResourceCursorAdapter(this, R.layout.track_list_item, null, 0) {
|
||||
resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.track_list_item, null, 0) {
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
int idIndex = cursor.getColumnIndex(TracksColumns._ID);
|
||||
@@ -227,7 +227,7 @@ public class TrackListActivity extends FragmentActivity {
|
||||
description.setVisibility(description.getText().length() == 0 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
};
|
||||
listView.setAdapter(adapter);
|
||||
listView.setAdapter(resourceCursorAdapter);
|
||||
ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(
|
||||
this, listView, R.menu.track_list_context_menu, R.id.track_list_item_name,
|
||||
contextualActionModeCallback);
|
||||
@@ -245,12 +245,12 @@ public class TrackListActivity extends FragmentActivity {
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||
adapter.swapCursor(cursor);
|
||||
resourceCursorAdapter.swapCursor(cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
adapter.swapCursor(null);
|
||||
resourceCursorAdapter.swapCursor(null);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -289,14 +289,14 @@ public class TrackListActivity extends FragmentActivity {
|
||||
menu.findItem(R.id.track_list_export_tcx)
|
||||
.setTitle(getString(R.string.menu_export_all_format, fileTypes[3]));
|
||||
|
||||
recordTrack = menu.findItem(R.id.track_list_record_track);
|
||||
stopRecording = menu.findItem(R.id.track_list_stop_recording);
|
||||
search = menu.findItem(R.id.track_list_search);
|
||||
importAll = menu.findItem(R.id.track_list_import_all);
|
||||
exportAll = menu.findItem(R.id.track_list_export_all);
|
||||
deleteAll = menu.findItem(R.id.track_list_delete_all);
|
||||
recordTrackMenuItem = menu.findItem(R.id.track_list_record_track);
|
||||
stopRecordingMenuItem = menu.findItem(R.id.track_list_stop_recording);
|
||||
searchMenuItem = menu.findItem(R.id.track_list_search);
|
||||
importAllMenuItem = menu.findItem(R.id.track_list_import_all);
|
||||
exportAllMenuItem = menu.findItem(R.id.track_list_export_all);
|
||||
deleteAllMenuItem = menu.findItem(R.id.track_list_delete_all);
|
||||
|
||||
ApiAdapterFactory.getApiAdapter().configureSearchWidget(this, search);
|
||||
ApiAdapterFactory.getApiAdapter().configureSearchWidget(this, searchMenuItem);
|
||||
updateMenu();
|
||||
return true;
|
||||
}
|
||||
@@ -315,20 +315,20 @@ public class TrackListActivity extends FragmentActivity {
|
||||
* @param isRecording true if recording
|
||||
*/
|
||||
private void updateMenuItems(boolean isRecording) {
|
||||
if (recordTrack != null) {
|
||||
recordTrack.setVisible(!isRecording);
|
||||
if (recordTrackMenuItem != null) {
|
||||
recordTrackMenuItem.setVisible(!isRecording);
|
||||
}
|
||||
if (stopRecording != null) {
|
||||
stopRecording.setVisible(isRecording);
|
||||
if (stopRecordingMenuItem != null) {
|
||||
stopRecordingMenuItem.setVisible(isRecording);
|
||||
}
|
||||
if (importAll != null) {
|
||||
importAll.setVisible(!isRecording);
|
||||
if (importAllMenuItem != null) {
|
||||
importAllMenuItem.setVisible(!isRecording);
|
||||
}
|
||||
if (exportAll != null) {
|
||||
exportAll.setVisible(!isRecording);
|
||||
if (exportAllMenuItem != null) {
|
||||
exportAllMenuItem.setVisible(!isRecording);
|
||||
}
|
||||
if (deleteAll != null) {
|
||||
deleteAll.setVisible(!isRecording);
|
||||
if (deleteAllMenuItem != null) {
|
||||
deleteAllMenuItem.setVisible(!isRecording);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,7 +450,7 @@ public class TrackListActivity extends FragmentActivity {
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
||||
if (ApiAdapterFactory.getApiAdapter().handleSearchKey(search)) {
|
||||
if (ApiAdapterFactory.getApiAdapter().handleSearchKey(searchMenuItem)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 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;
|
||||
|
||||
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.stats.TripStatistics;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
||||
/**
|
||||
* Screen in which the user enters details about a waypoint.
|
||||
*
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public class WaypointDetails extends Activity
|
||||
implements OnClickListener {
|
||||
|
||||
public static final String WAYPOINT_ID_EXTRA = "com.google.android.apps.mytracks.WAYPOINT_ID";
|
||||
|
||||
/**
|
||||
* The id of the way point being edited (taken from bundle with the above name).
|
||||
*/
|
||||
private Long waypointId;
|
||||
|
||||
private EditText name;
|
||||
private EditText description;
|
||||
private AutoCompleteTextView category;
|
||||
private View detailsView;
|
||||
private View statsView;
|
||||
|
||||
private StatsUtilities utils;
|
||||
private Waypoint waypoint;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setContentView(R.layout.mytracks_waypoint_details);
|
||||
|
||||
utils = new StatsUtilities(this);
|
||||
SharedPreferences preferences = getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
if (preferences != null) {
|
||||
boolean useMetric =
|
||||
preferences.getBoolean(getString(R.string.metric_units_key), true);
|
||||
utils.setMetricUnits(useMetric);
|
||||
|
||||
boolean displaySpeed =
|
||||
preferences.getBoolean(getString(R.string.report_speed_key), true);
|
||||
utils.setReportSpeed(displaySpeed);
|
||||
|
||||
utils.updateWaypointUnits();
|
||||
utils.setSpeedLabels();
|
||||
}
|
||||
|
||||
// Required extra when launching this intent:
|
||||
waypointId = getIntent().getLongExtra(WAYPOINT_ID_EXTRA, -1);
|
||||
if (waypointId < 0) {
|
||||
Log.d(Constants.TAG,
|
||||
"MyTracksWaypointsDetails intent was launched w/o waypoint id.");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// Optional extra that can be used to suppress the cancel button:
|
||||
boolean hasCancelButton =
|
||||
getIntent().getBooleanExtra("hasCancelButton", true);
|
||||
|
||||
name = (EditText) findViewById(R.id.waypointdetails_name);
|
||||
description = (EditText) findViewById(R.id.waypointdetails_description);
|
||||
category =
|
||||
(AutoCompleteTextView) findViewById(R.id.waypointdetails_category);
|
||||
statsView = findViewById(R.id.waypoint_stats);
|
||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
|
||||
this,
|
||||
R.array.waypoint_types,
|
||||
android.R.layout.simple_dropdown_item_1line);
|
||||
category.setAdapter(adapter);
|
||||
detailsView = findViewById(R.id.waypointdetails_description_layout);
|
||||
|
||||
Button cancel = (Button) findViewById(R.id.waypointdetails_cancel);
|
||||
if (hasCancelButton) {
|
||||
cancel.setOnClickListener(this);
|
||||
cancel.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
cancel.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
Button save = (Button) findViewById(R.id.waypointdetails_save);
|
||||
save.setOnClickListener(this);
|
||||
|
||||
fillDialog();
|
||||
}
|
||||
|
||||
private void fillDialog() {
|
||||
waypoint = MyTracksProviderUtils.Factory.get(this).getWaypoint(waypointId);
|
||||
if (waypoint != null) {
|
||||
name.setText(waypoint.getName());
|
||||
ImageView icon = (ImageView) findViewById(R.id.waypointdetails_icon);
|
||||
int iconId = -1;
|
||||
switch(waypoint.getType()) {
|
||||
case Waypoint.TYPE_WAYPOINT:
|
||||
description.setText(waypoint.getDescription());
|
||||
detailsView.setVisibility(View.VISIBLE);
|
||||
category.setText(waypoint.getCategory());
|
||||
statsView.setVisibility(View.GONE);
|
||||
iconId = R.drawable.blue_pushpin;
|
||||
break;
|
||||
case Waypoint.TYPE_STATISTICS:
|
||||
detailsView.setVisibility(View.GONE);
|
||||
statsView.setVisibility(View.VISIBLE);
|
||||
iconId = R.drawable.ylw_pushpin;
|
||||
TripStatistics waypointStats = waypoint.getStatistics();
|
||||
utils.setAllStats(waypointStats);
|
||||
utils.setAltitude(
|
||||
R.id.elevation_register, waypoint.getLocation().getAltitude());
|
||||
name.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||
break;
|
||||
}
|
||||
icon.setImageDrawable(getResources().getDrawable(iconId));
|
||||
}
|
||||
}
|
||||
|
||||
private void saveDialog() {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(WaypointsColumns.NAME, name.getText().toString());
|
||||
if (waypoint != null && waypoint.getType() == Waypoint.TYPE_WAYPOINT) {
|
||||
values.put(WaypointsColumns.DESCRIPTION,
|
||||
description.getText().toString());
|
||||
values.put(WaypointsColumns.CATEGORY, category.getText().toString());
|
||||
}
|
||||
getContentResolver().update(
|
||||
WaypointsColumns.CONTENT_URI,
|
||||
values,
|
||||
"_id = " + waypointId,
|
||||
null /*selectionArgs*/);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.waypointdetails_cancel:
|
||||
finish();
|
||||
break;
|
||||
case R.id.waypointdetails_save:
|
||||
saveDialog();
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 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;
|
||||
|
||||
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
import com.google.android.apps.mytracks.content.WaypointsColumns;
|
||||
import com.google.android.apps.mytracks.services.ITrackRecordingService;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||
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.app.Dialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnCreateContextMenuListener;
|
||||
import android.view.Window;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* Activity which shows the list of waypoints in a track.
|
||||
*
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public class WaypointsList extends ListActivity implements View.OnClickListener {
|
||||
|
||||
private static final int DIALOG_DELETE_CURRENT_ID = 0;
|
||||
|
||||
private int contextPosition = -1;
|
||||
private long trackId = -1;
|
||||
private long selectedWaypointId = -1;
|
||||
private ListView listView = null;
|
||||
private Button insertWaypointButton = null;
|
||||
private Button insertStatisticsButton = null;
|
||||
private long recordingTrackId = -1;
|
||||
private MyTracksProviderUtils providerUtils;
|
||||
private TrackRecordingServiceConnection serviceConnection;
|
||||
|
||||
private Cursor waypointsCursor = null;
|
||||
|
||||
private final OnCreateContextMenuListener contextMenuListener =
|
||||
new OnCreateContextMenuListener() {
|
||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||
ContextMenuInfo menuInfo) {
|
||||
menu.setHeaderTitle(R.string.marker_list_context_menu_title);
|
||||
AdapterView.AdapterContextMenuInfo info =
|
||||
(AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
contextPosition = info.position;
|
||||
selectedWaypointId = WaypointsList.this.listView.getAdapter()
|
||||
.getItemId(contextPosition);
|
||||
Waypoint waypoint = providerUtils.getWaypoint(info.id);
|
||||
if (waypoint != null) {
|
||||
int type = waypoint.getType();
|
||||
menu.add(Menu.NONE, Constants.MENU_SHOW, Menu.NONE, R.string.marker_list_show_on_map);
|
||||
menu.add(Menu.NONE, Constants.MENU_EDIT, Menu.NONE, R.string.marker_list_edit_marker);
|
||||
MenuItem deleteMenu = menu.add(
|
||||
Menu.NONE, Constants.MENU_DELETE, Menu.NONE, R.string.marker_list_delete_marker);
|
||||
deleteMenu.setEnabled(recordingTrackId < 0
|
||||
|| type == Waypoint.TYPE_WAYPOINT
|
||||
|| type == Waypoint.TYPE_STATISTICS
|
||||
|| info.id != providerUtils.getLastWaypointId(recordingTrackId));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
editWaypoint(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||
if (!super.onMenuItemSelected(featureId, item)) {
|
||||
switch (item.getItemId()) {
|
||||
case Constants.MENU_SHOW: {
|
||||
Intent result = new Intent();
|
||||
result.putExtra("trackid", trackId);
|
||||
result.putExtra(WaypointDetails.WAYPOINT_ID_EXTRA, selectedWaypointId);
|
||||
setResult(RESULT_OK, result);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
case Constants.MENU_EDIT: {
|
||||
editWaypoint(selectedWaypointId);
|
||||
return true;
|
||||
}
|
||||
case Constants.MENU_DELETE: {
|
||||
showDialog(DIALOG_DELETE_CURRENT_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void editWaypoint(long waypointId) {
|
||||
Intent intent = new Intent(this, WaypointDetails.class);
|
||||
intent.putExtra("trackid", trackId);
|
||||
intent.putExtra(WaypointDetails.WAYPOINT_ID_EXTRA, waypointId);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
providerUtils = MyTracksProviderUtils.Factory.get(this);
|
||||
serviceConnection = new TrackRecordingServiceConnection(this, null);
|
||||
|
||||
// We don't need a window title bar:
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
setContentView(R.layout.mytracks_waypoints_list);
|
||||
|
||||
listView = getListView();
|
||||
listView.setOnCreateContextMenuListener(contextMenuListener);
|
||||
|
||||
insertWaypointButton =
|
||||
(Button) findViewById(R.id.waypointslist_btn_insert_waypoint);
|
||||
insertWaypointButton.setOnClickListener(this);
|
||||
insertStatisticsButton =
|
||||
(Button) findViewById(R.id.waypointslist_btn_insert_statistics);
|
||||
insertStatisticsButton.setOnClickListener(this);
|
||||
|
||||
recordingTrackId = PreferencesUtils.getRecordingTrackId(this);
|
||||
|
||||
long selectedTrackId = PreferencesUtils.getSelectedTrackId(this);
|
||||
boolean selectedRecording = selectedTrackId != -1L && selectedTrackId == recordingTrackId;
|
||||
insertWaypointButton.setEnabled(selectedRecording);
|
||||
insertStatisticsButton.setEnabled(selectedRecording);
|
||||
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
trackId = getIntent().getExtras().getLong("trackid", -1);
|
||||
} else {
|
||||
trackId = -1;
|
||||
}
|
||||
|
||||
final long firstWaypointId = providerUtils.getFirstWaypointId(trackId);
|
||||
waypointsCursor = getContentResolver().query(
|
||||
WaypointsColumns.CONTENT_URI, null,
|
||||
WaypointsColumns.TRACKID + "=" + trackId + " AND "
|
||||
+ WaypointsColumns._ID + "!=" + firstWaypointId, null, null);
|
||||
startManagingCursor(waypointsCursor);
|
||||
setListAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
serviceConnection.bindIfRunning();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
serviceConnection.unbind();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
if (id != DIALOG_DELETE_CURRENT_ID) {
|
||||
return null;
|
||||
}
|
||||
return DialogUtils.createConfirmationDialog(this,
|
||||
R.string.marker_list_delete_marker_confirm_message, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
providerUtils.deleteWaypoint(
|
||||
selectedWaypointId, new DescriptionGeneratorImpl(WaypointsList.this));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.search_only, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_search:
|
||||
onSearchRequested();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
WaypointCreationRequest request;
|
||||
switch (v.getId()) {
|
||||
case R.id.waypointslist_btn_insert_waypoint:
|
||||
request = WaypointCreationRequest.DEFAULT_MARKER;
|
||||
break;
|
||||
case R.id.waypointslist_btn_insert_statistics:
|
||||
request = WaypointCreationRequest.DEFAULT_STATISTICS;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
long id = insertWaypoint(request);
|
||||
if (id < 0) {
|
||||
Toast.makeText(this, R.string.marker_insert_error, Toast.LENGTH_LONG).show();
|
||||
Log.e(Constants.TAG, "Failed to insert marker.");
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent(this, WaypointDetails.class);
|
||||
intent.putExtra(WaypointDetails.WAYPOINT_ID_EXTRA, id);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private long insertWaypoint(WaypointCreationRequest request) {
|
||||
try {
|
||||
ITrackRecordingService trackRecordingService = serviceConnection.getServiceIfBound();
|
||||
if (trackRecordingService != null) {
|
||||
long waypointId = trackRecordingService.insertWaypoint(request);
|
||||
if (waypointId >= 0) {
|
||||
Toast.makeText(this, R.string.marker_insert_success, Toast.LENGTH_LONG).show();
|
||||
return waypointId;
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Not connected to service, not inserting waypoint");
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "Cannot insert marker.", e);
|
||||
} catch (IllegalStateException e) {
|
||||
Log.e(Constants.TAG, "Cannot insert marker.", e);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void setListAdapter() {
|
||||
// Get a cursor with all tracks
|
||||
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
|
||||
this,
|
||||
R.layout.mytracks_marker_item,
|
||||
waypointsCursor,
|
||||
new String[] { WaypointsColumns.NAME, WaypointsColumns.TIME,
|
||||
WaypointsColumns.CATEGORY, WaypointsColumns.TYPE },
|
||||
new int[] { R.id.waypointslist_item_name,
|
||||
R.id.waypointslist_item_time,
|
||||
R.id.waypointslist_item_category,
|
||||
R.id.waypointslist_item_icon });
|
||||
|
||||
final int timeIdx =
|
||||
waypointsCursor.getColumnIndexOrThrow(WaypointsColumns.TIME);
|
||||
final int typeIdx =
|
||||
waypointsCursor.getColumnIndexOrThrow(WaypointsColumns.TYPE);
|
||||
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
|
||||
@Override
|
||||
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
|
||||
if (columnIndex == timeIdx) {
|
||||
long time = cursor.getLong(timeIdx);
|
||||
TextView textView = (TextView) view;
|
||||
|
||||
if (time == 0) {
|
||||
textView.setVisibility(View.GONE);
|
||||
} else {
|
||||
textView.setText(StringUtils.formatDateTime(WaypointsList.this, time));
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else if (columnIndex == typeIdx) {
|
||||
int type = cursor.getInt(typeIdx);
|
||||
ImageView imageView = (ImageView) view;
|
||||
imageView.setImageDrawable(getResources().getDrawable(
|
||||
type == Waypoint.TYPE_STATISTICS
|
||||
? R.drawable.ylw_pushpin
|
||||
: R.drawable.blue_pushpin));
|
||||
} else {
|
||||
TextView textView = (TextView) view;
|
||||
textView.setText(cursor.getString(columnIndex));
|
||||
textView.setVisibility(
|
||||
textView.getText().length() < 1 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
setListAdapter(adapter);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.MarkerListActivity;
|
||||
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
/**
|
||||
* A DialogFragment to delete one marker.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class DeleteOneMarkerDialogFragment extends DialogFragment {
|
||||
|
||||
public static final String DELETE_ONE_MARKER_DIALOG_TAG = "deleteOneMarkerDialog";
|
||||
private static final String KEY_MARKER_ID = "markerId";
|
||||
|
||||
public static DeleteOneMarkerDialogFragment newInstance(long markerId) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(KEY_MARKER_ID, markerId);
|
||||
|
||||
DeleteOneMarkerDialogFragment deleteOneMarkerDialogFragment = new DeleteOneMarkerDialogFragment();
|
||||
deleteOneMarkerDialogFragment.setArguments(bundle);
|
||||
return deleteOneMarkerDialogFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return DialogUtils.createConfirmationDialog(getActivity(),
|
||||
R.string.marker_delete_one_marker_confirm_message, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MyTracksProviderUtils.Factory.get(getActivity()).deleteWaypoint(
|
||||
getArguments().getLong(KEY_MARKER_ID), new DescriptionGeneratorImpl(getActivity()));
|
||||
startActivity(new Intent(getActivity(), MarkerListActivity.class).addFlags(
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -41,9 +41,9 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(KEY_TRACK_ID, trackId);
|
||||
|
||||
DeleteOneTrackDialogFragment deleteTrackDialogFragment = new DeleteOneTrackDialogFragment();
|
||||
deleteTrackDialogFragment.setArguments(bundle);
|
||||
return deleteTrackDialogFragment;
|
||||
DeleteOneTrackDialogFragment deleteOneTrackDialogFragment = new DeleteOneTrackDialogFragment();
|
||||
deleteOneTrackDialogFragment.setArguments(bundle);
|
||||
return deleteOneTrackDialogFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -70,11 +70,11 @@ public class MapFragment extends Fragment
|
||||
// True to zoom to my location. Only apply when keepMyLocationVisible is true.
|
||||
private boolean zoomToMyLocation;
|
||||
|
||||
// The track id of the waypoint to show.
|
||||
private long waypointTrackId;
|
||||
// The track id of the marker to show.
|
||||
private long markerTrackId;
|
||||
|
||||
// The waypoint id to show
|
||||
private long waypointId;
|
||||
// The marker id to show
|
||||
private long markerId;
|
||||
|
||||
// The current selected track id. Set in onSelectedTrackChanged.
|
||||
private long currentSelectedTrackId;
|
||||
@@ -166,11 +166,11 @@ public class MapFragment extends Fragment
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the waypoint.
|
||||
* Shows the marker.
|
||||
*
|
||||
* @param id the waypoint id
|
||||
* @param id the marker id
|
||||
*/
|
||||
public void showWaypoint(long id) {
|
||||
private void showMarker(long id) {
|
||||
MyTracksProviderUtils MyTracksProviderUtils = Factory.get(getActivity());
|
||||
Waypoint waypoint = MyTracksProviderUtils.getWaypoint(id);
|
||||
if (waypoint != null && waypoint.getLocation() != null) {
|
||||
@@ -184,25 +184,25 @@ public class MapFragment extends Fragment
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the waypoint.
|
||||
* Shows the marker.
|
||||
*
|
||||
* @param trackId the track id
|
||||
* @param id the waypoint id
|
||||
* @param id the marker id
|
||||
*/
|
||||
public void showWaypoint(long trackId, long id) {
|
||||
public void showMarker(long trackId, long id) {
|
||||
/*
|
||||
* Synchronize to prevent race condition in changing waypointTrackId and
|
||||
* waypointId variables.
|
||||
* Synchronize to prevent race condition in changing markerTrackId and
|
||||
* markerId variables.
|
||||
*/
|
||||
synchronized (this) {
|
||||
if (trackId == currentSelectedTrackId) {
|
||||
showWaypoint(id);
|
||||
waypointTrackId = -1L;
|
||||
waypointId = -1L;
|
||||
showMarker(id);
|
||||
markerTrackId = -1L;
|
||||
markerId = -1L;
|
||||
return;
|
||||
}
|
||||
waypointTrackId = trackId;
|
||||
waypointId = id;
|
||||
markerTrackId = trackId;
|
||||
markerId = id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,8 +314,8 @@ public class MapFragment extends Fragment
|
||||
|
||||
synchronized (this) {
|
||||
/*
|
||||
* Synchronize to prevent race condition in changing waypointTrackId
|
||||
* and waypointId variables.
|
||||
* Synchronize to prevent race condition in changing markerTrackId
|
||||
* and markerId variables.
|
||||
*/
|
||||
currentSelectedTrackId = track.getId();
|
||||
updateMap(track);
|
||||
@@ -424,17 +424,17 @@ public class MapFragment extends Fragment
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the map by either zooming to the requested waypoint or showing the track.
|
||||
* Updates the map by either zooming to the requested marker or showing the track.
|
||||
*
|
||||
* @param track the track
|
||||
*/
|
||||
private void updateMap(Track track) {
|
||||
if (track.getId() == waypointTrackId) {
|
||||
// Show the waypoint
|
||||
showWaypoint(waypointId);
|
||||
if (track.getId() == markerTrackId) {
|
||||
// Show the marker
|
||||
showMarker(markerId);
|
||||
|
||||
waypointTrackId = -1L;
|
||||
waypointId = -1L;
|
||||
markerTrackId = -1L;
|
||||
markerId = -1L;
|
||||
} else {
|
||||
// Show the track
|
||||
showTrack(track);
|
||||
|
||||
@@ -57,6 +57,7 @@ public class RestoreActivity extends Activity {
|
||||
if (date == -1L) {
|
||||
Log.d(TAG, "Invalid date");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
restoreAsyncTask = new RestoreAsyncTask(this, new Date(date));
|
||||
restoreAsyncTask.execute();
|
||||
|
||||
@@ -87,9 +87,9 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
||||
|
||||
@Override
|
||||
public void writeHeader() {
|
||||
writeCommaSeparatedLine(context.getString(R.string.track_edit_name),
|
||||
writeCommaSeparatedLine(context.getString(R.string.generic_name),
|
||||
context.getString(R.string.track_edit_activity_type_hint),
|
||||
context.getString(R.string.track_edit_description));
|
||||
context.getString(R.string.generic_description));
|
||||
writeCommaSeparatedLine(track.getName(), track.getCategory(), track.getDescription());
|
||||
writeCommaSeparatedLine();
|
||||
}
|
||||
@@ -101,9 +101,9 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
||||
|
||||
@Override
|
||||
public void writeBeginWaypoints() {
|
||||
writeCommaSeparatedLine(context.getString(R.string.marker_detail_marker_name),
|
||||
context.getString(R.string.marker_detail_marker_type_hint),
|
||||
context.getString(R.string.marker_detail_marker_description),
|
||||
writeCommaSeparatedLine(context.getString(R.string.generic_name),
|
||||
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),
|
||||
context.getString(R.string.description_location_altitude),
|
||||
|
||||
@@ -972,10 +972,13 @@ public class TrackRecordingService extends Service {
|
||||
wpt.setIcon(request.getIconUrl());
|
||||
}
|
||||
if (request.getName() == null) {
|
||||
wpt.setName(getString(R.string.marker_type_waypoint));
|
||||
wpt.setName(getString(R.string.marker_edit_type_waypoint));
|
||||
} else {
|
||||
wpt.setName(request.getName());
|
||||
}
|
||||
if (request.getCategory() != null) {
|
||||
wpt.setCategory(request.getCategory());
|
||||
}
|
||||
if (request.getDescription() != null) {
|
||||
wpt.setDescription(request.getDescription());
|
||||
}
|
||||
@@ -1000,7 +1003,7 @@ public class TrackRecordingService extends Service {
|
||||
|
||||
// Set the rest of the waypoint data
|
||||
waypoint.setType(Waypoint.TYPE_STATISTICS);
|
||||
waypoint.setName(getString(R.string.marker_type_statistics));
|
||||
waypoint.setName(getString(R.string.marker_edit_type_statistics));
|
||||
waypoint.setStatistics(waypointStatsBuilder.getStatistics());
|
||||
waypoint.setDescription(descriptionGenerator.generateWaypointDescription(waypoint));
|
||||
waypoint.setIcon(getString(R.string.marker_statistics_icon_url));
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Utilities for updating the statistics UI labels and values.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class StatsUtils {
|
||||
|
||||
private StatsUtils() {}
|
||||
|
||||
/**
|
||||
* Sets a speed label.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param id the speed label resource id
|
||||
* @param speedId the speed string id
|
||||
* @param paceId the pace string id
|
||||
* @param reportSpeed true to report speed
|
||||
*/
|
||||
public static void setSpeedLabel(
|
||||
Activity activity, int id, int speedId, int paceId, boolean reportSpeed) {
|
||||
TextView textView = (TextView) activity.findViewById(id);
|
||||
textView.setText(reportSpeed ? speedId : paceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a speed value.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param id the speed value resource id
|
||||
* @param speed the speed in meters per second
|
||||
* @param reportSpeed true to report speed
|
||||
* @param metricUnits true to display in metric units
|
||||
*/
|
||||
public static void setSpeedValue(
|
||||
Activity activity, int id, double speed, boolean reportSpeed, boolean metricUnits) {
|
||||
TextView textView = (TextView) activity.findViewById(id);
|
||||
speed *= UnitConversions.MS_TO_KMH;
|
||||
String value;
|
||||
if (metricUnits) {
|
||||
if (reportSpeed) {
|
||||
value = activity.getString(R.string.value_float_kilometer_hour, speed);
|
||||
} else {
|
||||
// convert from hours to minutes
|
||||
double pace = speed == 0 ? 0.0 : 60.0 / speed;
|
||||
value = activity.getString(R.string.value_float_minute_kilometer, pace);
|
||||
}
|
||||
} else {
|
||||
speed *= UnitConversions.KM_TO_MI;
|
||||
if (reportSpeed) {
|
||||
value = activity.getString(R.string.value_float_mile_hour, speed);
|
||||
} else {
|
||||
// convert from hours to minutes
|
||||
double pace = speed == 0 ? 0.0 : 60.0 / speed;
|
||||
value = activity.getString(R.string.value_float_minute_mile, pace);
|
||||
}
|
||||
}
|
||||
textView.setText(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a distance value.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param id the distance value resource id
|
||||
* @param distance the distance in meters
|
||||
* @param metricUnits true to display in metric units
|
||||
*/
|
||||
public static void setDistanceValue(
|
||||
Activity activity, int id, double distance, boolean metricUnits) {
|
||||
TextView textView = (TextView) activity.findViewById(id);
|
||||
distance *= UnitConversions.M_TO_KM;
|
||||
String value;
|
||||
if (metricUnits) {
|
||||
value = activity.getString(R.string.value_float_kilometer, distance);
|
||||
} else {
|
||||
distance *= UnitConversions.KM_TO_MI;
|
||||
value = activity.getString(R.string.value_float_mile, distance);
|
||||
}
|
||||
textView.setText(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a time value.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param id the time value resource id
|
||||
* @param time the time
|
||||
*/
|
||||
public static void setTimeValue(Activity activity, int id, long time) {
|
||||
TextView textView = (TextView) activity.findViewById(id);
|
||||
textView.setText(StringUtils.formatElapsedTime(time));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an altitude value.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param id the altitude value resource id
|
||||
* @param altitude the altitude in meters
|
||||
* @param metricUnits true to display in metric units
|
||||
*/
|
||||
public static void setAltitudeValue(
|
||||
Activity activity, int id, double altitude, boolean metricUnits) {
|
||||
TextView textView = (TextView) activity.findViewById(id);
|
||||
String value;
|
||||
if (Double.isNaN(altitude) || Double.isInfinite(altitude)) {
|
||||
value = activity.getString(R.string.value_unknown);
|
||||
} else {
|
||||
if (metricUnits) {
|
||||
value = activity.getString(R.string.value_float_meter, altitude);
|
||||
} else {
|
||||
altitude *= UnitConversions.M_TO_FT;
|
||||
value = activity.getString(R.string.value_float_feet, altitude);
|
||||
}
|
||||
}
|
||||
textView.setText(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a grade value.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param id the grade value resource id
|
||||
* @param grade the grade in fraction between 0 and 1
|
||||
*/
|
||||
public static void setGradeValue(Activity activity, int id, double grade) {
|
||||
TextView textView = (TextView) activity.findViewById(id);
|
||||
String value;
|
||||
if (Double.isNaN(grade) || Double.isInfinite(grade)) {
|
||||
value = activity.getString(R.string.value_unknown);
|
||||
} else {
|
||||
value = activity.getString(R.string.value_integer_percent, Math.round(grade * 100));
|
||||
}
|
||||
textView.setText(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user