SearchListActivity: show on map for individual markers.

This commit is contained in:
Dennis Guse
2019-07-18 22:48:07 +02:00
parent ef7db315d3
commit 15155aa394
5 changed files with 67 additions and 98 deletions
@@ -65,7 +65,8 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
private static final String[] PROJECTION = new String[] { WaypointsColumns._ID, private static final String[] PROJECTION = new String[] { WaypointsColumns._ID,
WaypointsColumns.NAME, WaypointsColumns.DESCRIPTION, WaypointsColumns.CATEGORY, WaypointsColumns.NAME, WaypointsColumns.DESCRIPTION, WaypointsColumns.CATEGORY,
WaypointsColumns.TYPE, WaypointsColumns.TIME, WaypointsColumns.PHOTOURL }; WaypointsColumns.TYPE, WaypointsColumns.TIME, WaypointsColumns.PHOTOURL,
WaypointsColumns.LATITUDE, WaypointsColumns.LONGITUDE};
// Callback when an item is selected in the contextual action mode // Callback when an item is selected in the contextual action mode
private ContextualActionModeCallback contextualActionModeCallback = new ContextualActionModeCallback() { private ContextualActionModeCallback contextualActionModeCallback = new ContextualActionModeCallback() {
@@ -165,16 +166,18 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY); int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY);
int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION); int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION);
int photoUrlIndex = cursor.getColumnIndex(WaypointsColumns.PHOTOURL); int photoUrlIndex = cursor.getColumnIndex(WaypointsColumns.PHOTOURL);
int latitudeIndex = cursor.getColumnIndex(WaypointsColumns.LATITUDE);
int longitudeIndex = cursor.getColumnIndex(WaypointsColumns.LONGITUDE);
boolean statistics = WaypointType.values()[cursor.getInt(typeIndex)] boolean statistics = WaypointType.values()[cursor.getInt(typeIndex)] == WaypointType.STATISTICS;
== WaypointType.STATISTICS; int iconId = statistics ? R.drawable.ic_marker_yellow_pushpin : R.drawable.ic_marker_blue_pushpin;
int iconId = statistics ? R.drawable.ic_marker_yellow_pushpin
: R.drawable.ic_marker_blue_pushpin;
String name = cursor.getString(nameIndex); String name = cursor.getString(nameIndex);
long time = cursor.getLong(timeIndex); long time = cursor.getLong(timeIndex);
String category = statistics ? null : cursor.getString(categoryIndex); String category = statistics ? null : cursor.getString(categoryIndex);
String description = statistics ? null : cursor.getString(descriptionIndex); String description = statistics ? null : cursor.getString(descriptionIndex);
String photoUrl = cursor.getString(photoUrlIndex); String photoUrl = cursor.getString(photoUrlIndex);
double latitude = cursor.getDouble(latitudeIndex);
double longitude = cursor.getDouble(longitudeIndex);
ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId, R.string.image_marker, name, null, null, 0, time, false, category, description, photoUrl); ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId, R.string.image_marker, name, null, null, 0, time, false, category, description, photoUrl);
} }
@@ -263,8 +266,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
getMenuInflater().inflate(R.menu.list_context_menu, menu); getMenuInflater().inflate(R.menu.list_context_menu, menu);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
contextualActionModeCallback.onPrepare( contextualActionModeCallback.onPrepare(menu, new int[] { info.position }, new long[] { info.id }, false);
menu, new int[] { info.position }, new long[] { info.id }, false);
} }
@Override @Override
@@ -290,6 +292,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
if (markerIds.length == 1) { if (markerIds.length == 1) {
intent = IntentUtils.newIntent(this, TrackDetailActivity.class) intent = IntentUtils.newIntent(this, TrackDetailActivity.class)
.putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerIds[0]); .putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerIds[0]);
//TODO Use IntentUtils.newShowOnMapIntent()
startActivity(intent); startActivity(intent);
} }
return true; return true;
@@ -70,6 +70,8 @@ import java.util.SortedSet;
* An activity to display a list of search results. * An activity to display a list of search results.
* *
* @author Rodrigo Damazio * @author Rodrigo Damazio
*
* TODO: allow to refine search (present search in context menu)
*/ */
public class SearchListActivity extends AbstractTrackActivity implements DeleteMarkerCaller, ConfirmDeleteDialogFragment.ConfirmDeleteCaller { public class SearchListActivity extends AbstractTrackActivity implements DeleteMarkerCaller, ConfirmDeleteDialogFragment.ConfirmDeleteCaller {
@@ -87,6 +89,8 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
private static final String CATEGORY_FIELD = "category"; private static final String CATEGORY_FIELD = "category";
private static final String DESCRIPTION_FIELD = "description"; private static final String DESCRIPTION_FIELD = "description";
private static final String PHOTO_URL_FIELD = "photoUrl"; private static final String PHOTO_URL_FIELD = "photoUrl";
private static final String MARKER_LATITUDE_FIELD = "latitude";
private static final String MARKER_LONGITUDE_FIELD = "longitude";
private static final String TRACK_ID_FIELD = "trackId"; private static final String TRACK_ID_FIELD = "trackId";
private static final String MARKER_ID_FIELD = "markerId"; private static final String MARKER_ID_FIELD = "markerId";
@@ -95,20 +99,14 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() { sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (key == null || key.equals( if (key == null || key.equals(PreferencesUtils.getKey(SearchListActivity.this, R.string.stats_units_key))) {
PreferencesUtils.getKey(SearchListActivity.this, R.string.stats_units_key))) {
metricUnits = PreferencesUtils.isMetricUnits(SearchListActivity.this); metricUnits = PreferencesUtils.isMetricUnits(SearchListActivity.this);
} }
if (key == null || key.equals( if (key == null || key.equals(PreferencesUtils.getKey(SearchListActivity.this, R.string.recording_track_id_key))) {
PreferencesUtils.getKey(SearchListActivity.this, R.string.recording_track_id_key))) { recordingTrackId = PreferencesUtils.getLong(SearchListActivity.this, R.string.recording_track_id_key);
recordingTrackId = PreferencesUtils.getLong(
SearchListActivity.this, R.string.recording_track_id_key);
} }
if (key == null || key.equals(PreferencesUtils.getKey( if (key == null || key.equals(PreferencesUtils.getKey(SearchListActivity.this, R.string.recording_track_paused_key))) {
SearchListActivity.this, R.string.recording_track_paused_key))) { recordingTrackPaused = PreferencesUtils.getBoolean(SearchListActivity.this, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
recordingTrackPaused = PreferencesUtils.getBoolean(SearchListActivity.this,
R.string.recording_track_paused_key,
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
} }
if (key != null) { if (key != null) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@@ -122,8 +120,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
}; };
// Callback when an item is selected in the contextual action mode // Callback when an item is selected in the contextual action mode
private ContextualActionModeCallback private ContextualActionModeCallback contextualActionModeCallback = new ContextualActionModeCallback() {
contextualActionModeCallback = new ContextualActionModeCallback() {
@Override @Override
public boolean onClick(int itemId, int[] positions, long[] ids) { public boolean onClick(int itemId, int[] positions, long[] ids) {
return handleContextItem(itemId, positions); return handleContextItem(itemId, positions);
@@ -147,8 +144,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
//TODO Setup shareIntent. //TODO Setup shareIntent.
// One item, item is a marker // One item, item is a marker
menu.findItem(R.id.list_context_menu_show_on_map) menu.findItem(R.id.list_context_menu_show_on_map).setVisible(isSingleSelection && !isSingleSelectionTrack);
.setVisible(isSingleSelection && !isSingleSelectionTrack);
// One item, can be a track or a marker // One item, can be a track or a marker
menu.findItem(R.id.list_context_menu_edit).setVisible(isSingleSelection); menu.findItem(R.id.list_context_menu_edit).setVisible(isSingleSelection);
// One item. If track, no restriction. // One item. If track, no restriction.
@@ -191,15 +187,15 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
view = convertView; view = convertView;
} }
Map<String, Object> resultMap = getItem(position); Map<String, Object> resultMap = getItem(position);
boolean isRecording = (Boolean) resultMap.get(IS_RECORDING_FIELD); boolean isRecording = (boolean) resultMap.get(IS_RECORDING_FIELD);
boolean isPaused = (Boolean) resultMap.get(IS_PAUSED_FIELD); boolean isPaused = (boolean) resultMap.get(IS_PAUSED_FIELD);
int iconId = (Integer) resultMap.get(ICON_ID_FIELD); int iconId = (int) resultMap.get(ICON_ID_FIELD);
int iconContentDescriptionId = (Integer) resultMap.get(ICON_CONTENT_DESCRIPTION_ID_FIELD); int iconContentDescriptionId = (int) resultMap.get(ICON_CONTENT_DESCRIPTION_ID_FIELD);
String name = (String) resultMap.get(NAME_FIELD); String name = (String) resultMap.get(NAME_FIELD);
String totalTime = (String) resultMap.get(TOTAL_TIME_FIELD); String totalTime = (String) resultMap.get(TOTAL_TIME_FIELD);
String totalDistance = (String) resultMap.get(TOTAL_DISTANCE_FIELD); String totalDistance = (String) resultMap.get(TOTAL_DISTANCE_FIELD);
int markerCount = (Integer) resultMap.get(MARKER_COUNT_FIELD); int markerCount = (int) resultMap.get(MARKER_COUNT_FIELD);
Long startTime = (Long) resultMap.get(START_TIME_FIELD); long startTime = (long) resultMap.get(START_TIME_FIELD);
String category = (String) resultMap.get(CATEGORY_FIELD); String category = (String) resultMap.get(CATEGORY_FIELD);
String description = (String) resultMap.get(DESCRIPTION_FIELD); String description = (String) resultMap.get(DESCRIPTION_FIELD);
String photoUrl = (String) resultMap.get(PHOTO_URL_FIELD); String photoUrl = (String) resultMap.get(PHOTO_URL_FIELD);
@@ -288,8 +284,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
getMenuInflater().inflate(R.menu.list_context_menu, menu); getMenuInflater().inflate(R.menu.list_context_menu, menu);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
contextualActionModeCallback.onPrepare( contextualActionModeCallback.onPrepare(menu, new int[] { info.position }, new long[] { info.id }, false);
menu, new int[] { info.position }, new long[] { info.id }, false);
} }
@Override @Override
@@ -330,8 +325,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
Log.e(TAG, "Not implemented"); Log.e(TAG, "Not implemented");
return true; return true;
case R.id.list_context_menu_show_on_map: case R.id.list_context_menu_show_on_map:
intent = IntentUtils.newIntent(this, TrackDetailActivity.class) intent = IntentUtils.newShowOnMapIntent((double)item.get(MARKER_LATITUDE_FIELD), (double)item.get(MARKER_LONGITUDE_FIELD), item.get(NAME_FIELD) + "");
.putExtra(TrackDetailActivity.EXTRA_MARKER_ID, markerId);
startActivity(intent); startActivity(intent);
return true; return true;
case R.id.list_context_menu_edit: case R.id.list_context_menu_edit:
@@ -349,8 +343,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
return true; return true;
case R.id.list_context_menu_delete: case R.id.list_context_menu_delete:
if (markerId != null) { if (markerId != null) {
DeleteMarkerDialogFragment.newInstance(new long[] { markerId }).show( DeleteMarkerDialogFragment.newInstance(new long[] { markerId }).show(getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
} else { } else {
deleteTracks(new long[] { trackId }); deleteTracks(new long[] { trackId });
} }
@@ -375,50 +368,16 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
final String textQuery = intent.getStringExtra(SearchManager.QUERY); final String textQuery = intent.getStringExtra(SearchManager.QUERY);
setTitle(textQuery); setTitle(textQuery);
SearchQuery query = new SearchQuery(textQuery, null, -1L, System.currentTimeMillis()); doSearch(textQuery);
doSearch(query);
// // TODO Why was this done? Somehow we searched by last location?
// @Deprecated
// final MyTracksLocationManager myTracksLocationManager = new MyTracksLocationManager(this, Looper.myLooper(), true);
// LocationListener locationListener = new LocationListener() {
// @Override
// public void onLocationChanged(final Location location) {
// myTracksLocationManager.close();
// new Thread() {
// @Override
// public void run() {
// SearchQuery query = new SearchQuery(
// textQuery, location, -1L, System.currentTimeMillis());
// doSearch(query);
// }
// }.start();
// }
//
// @Override
// public void onStatusChanged(String provider, int status, Bundle extras) {
// Log.w(TAG, "LocationListener.onStatusChanged(): is not implemented.");
// }
//
// @Override
// public void onProviderEnabled(String provider) {
// Log.w(TAG, "LocationListener.onProviderEnabled(): is not implemented.");
// }
//
// @Override
// public void onProviderDisabled(String provider) {
// Log.w(TAG, "LocationListener.onProviderDisabled(): is not implemented.");
// }
// };
// myTracksLocationManager.requestLastLocation(locationListener);
} }
/** /**
* Do the search. * Do the search.
* *
* @param query the query * @param textQuery the query
*/ */
private void doSearch(SearchQuery query) { private void doSearch(String textQuery) {
SearchQuery query = new SearchQuery(textQuery, null, -1L, System.currentTimeMillis());
SortedSet<ScoredResult> scoredResults = searchEngine.search(query); SortedSet<ScoredResult> scoredResults = searchEngine.search(query);
final List<Map<String, Object>> displayResults = prepareResultsforDisplay(scoredResults); final List<Map<String, Object>> displayResults = prepareResultsforDisplay(scoredResults);
@@ -441,10 +400,9 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
* @param scoredResults a list of score results * @param scoredResults a list of score results
* @return a list of result maps * @return a list of result maps
*/ */
private List<Map<String, Object>> prepareResultsforDisplay( private List<Map<String, Object>> prepareResultsforDisplay(Collection<ScoredResult> scoredResults) {
Collection<ScoredResult> scoredResults) { //TODO Replace use of map<string, object>, but rather provide Track or Waypoint directly.
ArrayList<Map<String, Object>> output = new ArrayList<>( ArrayList<Map<String, Object>> output = new ArrayList<>(scoredResults.size());
scoredResults.size());
for (ScoredResult result : scoredResults) { for (ScoredResult result : scoredResults) {
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
if (result.track != null) { if (result.track != null) {
@@ -463,6 +421,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
* @param waypoint the marker * @param waypoint the marker
* @param resultMap the result map * @param resultMap the result map
*/ */
@Deprecated
private void prepareMarkerForDisplay(Waypoint waypoint, Map<String, Object> resultMap) { private void prepareMarkerForDisplay(Waypoint waypoint, Map<String, Object> resultMap) {
/* /*
* TODO: It may be more appropriate to obtain the track name as a join in * TODO: It may be more appropriate to obtain the track name as a join in
@@ -481,13 +440,11 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
resultMap.put(IS_RECORDING_FIELD, false); resultMap.put(IS_RECORDING_FIELD, false);
resultMap.put(IS_PAUSED_FIELD, true); resultMap.put(IS_PAUSED_FIELD, true);
resultMap.put(ICON_ID_FIELD, resultMap.put(ICON_ID_FIELD, statistics ? R.drawable.ic_marker_yellow_pushpin : R.drawable.ic_marker_blue_pushpin);
statistics ? R.drawable.ic_marker_yellow_pushpin : R.drawable.ic_marker_blue_pushpin);
resultMap.put(ICON_CONTENT_DESCRIPTION_ID_FIELD, R.string.image_marker); resultMap.put(ICON_CONTENT_DESCRIPTION_ID_FIELD, R.string.image_marker);
resultMap.put(NAME_FIELD, waypoint.getName()); resultMap.put(NAME_FIELD, waypoint.getName());
// Display the marker's track name in the total time field // Display the marker's track name in the total time field
resultMap.put(TOTAL_TIME_FIELD, trackName == null ? null resultMap.put(TOTAL_TIME_FIELD, trackName == null ? null : getString(R.string.search_list_marker_track_location, trackName));
: getString(R.string.search_list_marker_track_location, trackName));
resultMap.put(TOTAL_DISTANCE_FIELD, null); resultMap.put(TOTAL_DISTANCE_FIELD, null);
resultMap.put(MARKER_COUNT_FIELD, 0); resultMap.put(MARKER_COUNT_FIELD, 0);
resultMap.put(START_TIME_FIELD, waypoint.getLocation().getTime()); resultMap.put(START_TIME_FIELD, waypoint.getLocation().getTime());
@@ -496,6 +453,9 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
resultMap.put(PHOTO_URL_FIELD, waypoint.getPhotoUrl()); resultMap.put(PHOTO_URL_FIELD, waypoint.getPhotoUrl());
resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId()); resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId());
resultMap.put(MARKER_ID_FIELD, waypoint.getId()); resultMap.put(MARKER_ID_FIELD, waypoint.getId());
resultMap.put(MARKER_LATITUDE_FIELD, waypoint.getLocation().getLatitude());
resultMap.put(MARKER_LONGITUDE_FIELD, waypoint.getLocation().getLongitude());
} }
/** /**
@@ -504,6 +464,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
* @param track the track * @param track the track
* @param resultMap the result map * @param resultMap the result map
*/ */
@Deprecated
private void prepareTrackForDisplay(Track track, Map<String, Object> resultMap) { private void prepareTrackForDisplay(Track track, Map<String, Object> resultMap) {
TripStatistics tripStatitics = track.getTripStatistics(); TripStatistics tripStatitics = track.getTripStatistics();
String icon = track.getIcon(); String icon = track.getIcon();
@@ -515,8 +476,7 @@ public class SearchListActivity extends AbstractTrackActivity implements DeleteM
resultMap.put(ICON_CONTENT_DESCRIPTION_ID_FIELD, R.string.image_track); resultMap.put(ICON_CONTENT_DESCRIPTION_ID_FIELD, R.string.image_track);
resultMap.put(NAME_FIELD, track.getName()); resultMap.put(NAME_FIELD, track.getName());
resultMap.put(TOTAL_TIME_FIELD, StringUtils.formatElapsedTime(tripStatitics.getTotalTime())); resultMap.put(TOTAL_TIME_FIELD, StringUtils.formatElapsedTime(tripStatitics.getTotalTime()));
resultMap.put(TOTAL_DISTANCE_FIELD, resultMap.put(TOTAL_DISTANCE_FIELD, StringUtils.formatDistance(this, tripStatitics.getTotalDistance(), metricUnits));
StringUtils.formatDistance(this, tripStatitics.getTotalDistance(), metricUnits));
resultMap.put(MARKER_COUNT_FIELD, myTracksProviderUtils.getWaypointCount(track.getId())); resultMap.put(MARKER_COUNT_FIELD, myTracksProviderUtils.getWaypointCount(track.getId()));
resultMap.put(START_TIME_FIELD, tripStatitics.getStartTime()); resultMap.put(START_TIME_FIELD, tripStatitics.getStartTime());
resultMap.put(CATEGORY_FIELD, category); resultMap.put(CATEGORY_FIELD, category);
@@ -187,13 +187,14 @@ public class MarkerDetailFragment extends Fragment {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
long markerId = getArguments().getLong(KEY_MARKER_ID); long markerId = getArguments().getLong(KEY_MARKER_ID);
FragmentActivity fragmentActivity = getActivity(); FragmentActivity fragmentActivity = getActivity();
Intent intent;
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.marker_detail_show_on_map: case R.id.marker_detail_show_on_map:
startActivity(IntentUtils.newShowOnMapIntent(waypoint.getLocation().getLatitude(), waypoint.getLocation().getLongitude())); intent = IntentUtils.newShowOnMapIntent(waypoint);
startActivity(intent);
return true; return true;
case R.id.marker_detail_edit: case R.id.marker_detail_edit:
Intent intent = IntentUtils.newIntent(fragmentActivity, MarkerEditActivity.class) intent = IntentUtils.newIntent(fragmentActivity, MarkerEditActivity.class)
.putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId); .putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerId);
startActivity(intent); startActivity(intent);
return true; return true;
@@ -23,6 +23,7 @@ import android.net.Uri;
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.io.file.TrackFileFormat; import com.google.android.apps.mytracks.io.file.TrackFileFormat;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
@@ -47,8 +48,7 @@ public class IntentUtils {
* @param cls the class * @param cls the class
*/ */
public static Intent newIntent(Context context, Class<?> cls) { public static Intent newIntent(Context context, Class<?> cls) {
return new Intent(context, cls).addFlags( return new Intent(context, cls).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
} }
/** /**
@@ -59,24 +59,30 @@ public class IntentUtils {
* @param filePath the file path * @param filePath the file path
* @param trackFileFormat the track file format * @param trackFileFormat the track file format
*/ */
public static Intent newShareFileIntent( public static Intent newShareFileIntent(Context context, long trackId, String filePath, TrackFileFormat trackFileFormat) {
Context context, long trackId, String filePath, TrackFileFormat trackFileFormat) {
Track track = MyTracksProviderUtils.Factory.get(context).getTrack(trackId); Track track = MyTracksProviderUtils.Factory.get(context).getTrack(trackId);
String trackDescription = track == null ? "" String trackDescription = track == null ? "" : new DescriptionGeneratorImpl(context).generateTrackDescription(track, null, null, false);
: new DescriptionGeneratorImpl(context).generateTrackDescription(track, null, null, false);
return new Intent(Intent.ACTION_SEND) return new Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath))) .putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)))
.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.share_track_subject)) .putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.share_track_subject))
.putExtra(Intent.EXTRA_TEXT, .putExtra(Intent.EXTRA_TEXT, context.getString(R.string.share_track_share_file_body, trackDescription))
context.getString(R.string.share_track_share_file_body, trackDescription))
.putExtra(context.getString(R.string.track_id_broadcast_extra), trackId) .putExtra(context.getString(R.string.track_id_broadcast_extra), trackId)
.setType(trackFileFormat.getMimeType()); .setType(trackFileFormat.getMimeType());
} }
public static Intent newShowOnMapIntent(double latitude, double longitude) { public static Intent newShowOnMapIntent(Waypoint waypoint) {
return newShowOnMapIntent(waypoint.getLocation().getLatitude(), waypoint.getLocation().getLongitude(), waypoint.getName());
}
public static Intent newShowOnMapIntent(double latitude, double longitude, String label) {
//SEE https://developer.android.com/guide/components/intents-common.html#Maps
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:" + latitude + "," + longitude)); String uri = "geo:0,0?q=" + latitude + "," + longitude;
if (label != null && label.length() > 0) {
uri += "(" + label + ")";
}
intent.setData(Uri.parse(uri));
return intent; return intent;
} }
} }
+2 -3
View File
@@ -13,11 +13,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/search_list_search" android:id="@+id/search_list_search"
android:title="@string/menu_search" android:title="@string/menu_search"
android:actionViewClass="android.widget.SearchView" android:actionViewClass="android.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" /> android:showAsAction="ifRoom" />
</menu> </menu>