From 878a87278d75d757004c2c837bb343635bbbb848 Mon Sep 17 00:00:00 2001 From: Sandor Dornbush Date: Fri, 17 Dec 2010 06:59:43 -0800 Subject: [PATCH] Address comments. --- .../android/apps/mytracks/MyTracks.java | 2 +- .../mytracks/MyTracksWaypointDetails.java | 2 +- .../apps/mytracks/MyTracksWaypointsList.java | 10 ++-- .../services/TrackRecordingService.java | 4 +- .../content/WaypointCreationRequest.java | 50 ++++++++++++------- SignalStrengthSampler/AndroidManifest.xml | 1 - .../signalstrength/SignalStrengthService.java | 6 +-- 7 files changed, 43 insertions(+), 32 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/MyTracks.java b/MyTracks/src/com/google/android/apps/mytracks/MyTracks.java index 886d9e75e..c7ade2cdc 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MyTracks.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MyTracks.java @@ -891,7 +891,7 @@ public class MyTracks extends TabActivity implements OnTouchListener, * Inserts a waypoint marker. * * @return Id of the inserted statistics marker. - * @throws RemoteException + * @throws RemoteException If the call on the service failed. */ public long insertWaypoint(WaypointCreationRequest request) throws RemoteException { if (trackRecordingService == null) { diff --git a/MyTracks/src/com/google/android/apps/mytracks/MyTracksWaypointDetails.java b/MyTracks/src/com/google/android/apps/mytracks/MyTracksWaypointDetails.java index 34e952577..5e9f110b7 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MyTracksWaypointDetails.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MyTracksWaypointDetails.java @@ -42,7 +42,7 @@ import android.widget.ImageView; public class MyTracksWaypointDetails extends Activity implements OnClickListener { - public static final String WAYPOINT_ID_EXTRA = "waypointid"; + 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, "waypointid") diff --git a/MyTracks/src/com/google/android/apps/mytracks/MyTracksWaypointsList.java b/MyTracks/src/com/google/android/apps/mytracks/MyTracksWaypointsList.java index 2bbc25cc9..f3c151169 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MyTracksWaypointsList.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MyTracksWaypointsList.java @@ -189,11 +189,13 @@ public class MyTracksWaypointsList extends ListActivity Log.e(MyTracksConstants.TAG, "Cannot insert marker.", e); return; } - if (id >= 0) { - Intent intent = new Intent(this, MyTracksWaypointDetails.class); - intent.putExtra(MyTracksWaypointDetails.WAYPOINT_ID_EXTRA, id); - startActivity(intent); + if (id < 0) { + Log.e(MyTracksConstants.TAG, "Failed to insert marker."); + return; } + Intent intent = new Intent(this, MyTracksWaypointDetails.class); + intent.putExtra(MyTracksWaypointDetails.WAYPOINT_ID_EXTRA, id); + startActivity(intent); } private void setListAdapter() { diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java index 84b180ddf..55147ebd3 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -889,10 +889,10 @@ public class TrackRecordingService extends Service implements LocationListener { private void buildMarker(Waypoint wpt, WaypointCreationRequest request) { wpt.setType(Waypoint.TYPE_WAYPOINT); - if (request.getIcon() == null) { + if (request.getIconUrl() == null) { wpt.setIcon(getString(R.string.waypoint_icon_url)); } else { - wpt.setIcon(request.getIcon()); + wpt.setIcon(request.getIconUrl()); } if (request.getName() == null) { wpt.setName(getString(R.string.waypoint)); diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java index 417700328..66c3692ac 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java @@ -33,7 +33,7 @@ public class WaypointCreationRequest implements Parcelable { private WaypointType type; private String name; private String description; - private String icon; + private String iconUrl; public final static WaypointCreationRequest DEFAULT_MARKER = new WaypointCreationRequest(WaypointType.MARKER); @@ -44,6 +44,15 @@ public class WaypointCreationRequest implements Parcelable { this.type = type; } + public WaypointCreationRequest(WaypointType type, String name, + String description, String iconUrl) { + super(); + this.type = type; + this.name = name; + this.description = description; + this.iconUrl = iconUrl; + } + public static class Creator implements Parcelable.Creator { public WaypointCreationRequest createFromParcel(Parcel source) { @@ -52,9 +61,17 @@ public class WaypointCreationRequest implements Parcelable { throw new IllegalArgumentException("Could not find waypoint type: " + i); } WaypointCreationRequest request = new WaypointCreationRequest(WaypointType.values()[i]); + request.description = maybeReadStringToParcel(source); + request.iconUrl = maybeReadStringToParcel(source); + request.name = maybeReadStringToParcel(source); return request; } + private String maybeReadStringToParcel(Parcel parcel) { + return parcel.readByte() > 0 ? parcel.readString() : null; + } + + public WaypointCreationRequest[] newArray(int size) { return new WaypointCreationRequest[size]; } @@ -70,37 +87,32 @@ public class WaypointCreationRequest implements Parcelable { @Override public void writeToParcel(Parcel parcel, int arg1) { parcel.writeInt(type.ordinal()); + // TODO: Pack all of available bits into one byte. + maybeWriteStringToParcel(parcel, description); + maybeWriteStringToParcel(parcel, iconUrl); + maybeWriteStringToParcel(parcel, name); + } + + private void maybeWriteStringToParcel(Parcel parcel, String s) { + parcel.writeByte(s == null ? (byte) 0 : (byte) 1); + if (s != null) { + parcel.writeString(s); + } } public WaypointType getType() { return type; } - public void setType(WaypointType type) { - this.type = type; - } - public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - public String getDescription() { return description; } - public void setDescription(String description) { - this.description = description; - } - - public String getIcon() { - return icon; - } - - public void setIcon(String icon) { - this.icon = icon; + public String getIconUrl() { + return iconUrl; } } \ No newline at end of file diff --git a/SignalStrengthSampler/AndroidManifest.xml b/SignalStrengthSampler/AndroidManifest.xml index ea09d0894..03d216a34 100644 --- a/SignalStrengthSampler/AndroidManifest.xml +++ b/SignalStrengthSampler/AndroidManifest.xml @@ -50,7 +50,6 @@ limitations under the License. - diff --git a/SignalStrengthSampler/src/com/google/android/apps/mytracks/signalstrength/SignalStrengthService.java b/SignalStrengthSampler/src/com/google/android/apps/mytracks/signalstrength/SignalStrengthService.java index c6fc847fb..210fefe02 100644 --- a/SignalStrengthSampler/src/com/google/android/apps/mytracks/signalstrength/SignalStrengthService.java +++ b/SignalStrengthSampler/src/com/google/android/apps/mytracks/signalstrength/SignalStrengthService.java @@ -169,10 +169,8 @@ public class SignalStrengthService extends Service // Create a waypoint. WaypointCreationRequest request = - new WaypointCreationRequest(WaypointCreationRequest.WaypointType.MARKER); - request.setName("Signal Strength"); - request.setIcon(icon); - request.setDescription(description); + new WaypointCreationRequest(WaypointCreationRequest.WaypointType.MARKER, + "Signal Strength", icon, description); waypointId = mytracksService.insertWaypoint(request); }