crash fix: GSON and Parcelable did not play well with Location Extras
This commit is contained in:
parent
a6dd91b348
commit
c9e1f1c750
5 changed files with 35 additions and 20 deletions
|
@ -140,6 +140,9 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
|||
mCurrentBestLocation.setLongitude(DEFAULT_LONGITUDE);
|
||||
}
|
||||
|
||||
LogHelper.v(LOG_TAG, "!!! TRACK:" + mCurrentBestLocation.getExtras());
|
||||
|
||||
|
||||
// get state of location system setting
|
||||
mLocationSystemSetting = LocationHelper.checkLocationSystemSetting(mActivity);
|
||||
|
||||
|
@ -394,8 +397,8 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
|||
}
|
||||
|
||||
// save track object
|
||||
// SaveTrackAsyncHelper saveTrackAsyncHelper = new SaveTrackAsyncHelper();
|
||||
// saveTrackAsyncHelper.execute();
|
||||
SaveTrackAsyncHelper saveTrackAsyncHelper = new SaveTrackAsyncHelper();
|
||||
saveTrackAsyncHelper.execute();
|
||||
// TODO add toast indicating track save
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ import org.y20k.trackbook.helpers.MapHelper;
|
|||
import org.y20k.trackbook.helpers.StorageHelper;
|
||||
import org.y20k.trackbook.helpers.TrackbookKeys;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
||||
|
||||
/**
|
||||
* MainActivityTrackFragment class
|
||||
|
@ -126,7 +128,18 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
|
|||
mRecordingStopView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_stop);
|
||||
mStatisticsSheet = mRootView.findViewById(R.id.statistic_sheet);
|
||||
|
||||
if (mTrack == null) {
|
||||
// load track and display map and statistics
|
||||
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
|
||||
loadTrackAsyncHelper.execute();
|
||||
} else {
|
||||
// display map and statistics
|
||||
displayTrack();
|
||||
}
|
||||
|
||||
// show statistics sheet
|
||||
mStatisticsSheetBehavior = BottomSheetBehavior.from(mStatisticsSheet);
|
||||
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
|
||||
return mRootView;
|
||||
}
|
||||
|
@ -137,12 +150,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
|
|||
super.onResume();
|
||||
LogHelper.v(LOG_TAG, "TrackFragment: onResume called.");
|
||||
|
||||
// load track and display map and statistics
|
||||
LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
|
||||
loadTrackAsyncHelper.execute();
|
||||
|
||||
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -181,13 +188,18 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
|
|||
Location lastLocation = mTrack.getWayPointLocation(mTrack.getSize() -1);
|
||||
position = new GeoPoint(lastLocation.getLatitude(), lastLocation.getLongitude());
|
||||
|
||||
String recordingStart = DateFormat.getDateInstance(DateFormat.SHORT).format(mTrack.getRecordingStart()) + " " +
|
||||
DateFormat.getTimeInstance(DateFormat.SHORT).format(mTrack.getRecordingStart());
|
||||
String recordingStop = DateFormat.getDateInstance(DateFormat.SHORT).format(mTrack.getRecordingStop()) + " " +
|
||||
DateFormat.getTimeInstance(DateFormat.SHORT).format(mTrack.getRecordingStop());
|
||||
|
||||
// populate views
|
||||
mDistanceView.setText(mTrack.getTrackDistance());
|
||||
mStepsView.setText(String.valueOf(Math.round(mTrack.getStepCount())));
|
||||
mWaypointsView.setText(String.valueOf(mTrack.getWayPoints().size()));
|
||||
mDurationView.setText(mTrack.getTrackDuration());
|
||||
mRecordingStartView.setText(mTrack.getRecordingStart().toString());
|
||||
mRecordingStopView.setText(mTrack.getRecordingStop().toString());
|
||||
mRecordingStartView.setText(recordingStart);
|
||||
mRecordingStopView.setText(recordingStop);
|
||||
|
||||
// draw track on map
|
||||
drawTrackOverlay(mTrack);
|
||||
|
@ -228,6 +240,7 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
|
|||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
// clear track object
|
||||
// LogHelper.v(LOG_TAG, "!!! TRACK:" + mTrack.getWayPoints().get(0).getLocation().getExtras());
|
||||
LogHelper.v(LOG_TAG, "Display map and statistics of track.");
|
||||
displayTrack();
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ public class Track implements TrackbookKeys, Parcelable {
|
|||
private float mTrackLength;
|
||||
private long mDuration;
|
||||
private float mStepCount;
|
||||
private int mUnitSystem;
|
||||
private Date mRecordingStart;
|
||||
private Date mRecordingStop;
|
||||
|
||||
|
@ -56,7 +55,6 @@ public class Track implements TrackbookKeys, Parcelable {
|
|||
mWayPoints = new ArrayList<WayPoint>();
|
||||
mTrackLength = 0;
|
||||
mStepCount = 0;
|
||||
mUnitSystem = getUnitSystem(Locale.getDefault());
|
||||
mRecordingStart = GregorianCalendar.getInstance().getTime();
|
||||
mRecordingStop = mRecordingStart;
|
||||
}
|
||||
|
@ -67,7 +65,6 @@ public class Track implements TrackbookKeys, Parcelable {
|
|||
mWayPoints = in.createTypedArrayList(WayPoint.CREATOR);
|
||||
mTrackLength = in.readFloat();
|
||||
mStepCount = in.readFloat();
|
||||
mUnitSystem = in.readInt();
|
||||
mRecordingStart = new Date(in.readLong());
|
||||
mRecordingStop = new Date(in.readLong());
|
||||
}
|
||||
|
@ -174,7 +171,7 @@ public class Track implements TrackbookKeys, Parcelable {
|
|||
float trackDistance;
|
||||
String unit;
|
||||
|
||||
if (mUnitSystem == IMPERIAL) {
|
||||
if (getUnitSystem(Locale.getDefault()) == IMPERIAL) {
|
||||
// get track distance and convert to feet
|
||||
trackDistance = mWayPoints.get(mWayPoints.size()-1).getDistanceToStartingPoint() * 3.28084f;
|
||||
unit = "ft";
|
||||
|
@ -216,11 +213,10 @@ public class Track implements TrackbookKeys, Parcelable {
|
|||
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
public void writeToParcel(Parcel parcel, int flags) {
|
||||
parcel.writeTypedList(mWayPoints);
|
||||
parcel.writeFloat(mTrackLength);
|
||||
parcel.writeFloat(mStepCount);
|
||||
parcel.writeInt(mUnitSystem);
|
||||
parcel.writeLong(mRecordingStart.getTime());
|
||||
parcel.writeLong(mRecordingStop.getTime());
|
||||
}
|
||||
|
|
|
@ -39,7 +39,8 @@ public class WayPoint implements Parcelable {
|
|||
|
||||
/* Constructor used by CREATOR */
|
||||
protected WayPoint(Parcel in) {
|
||||
mLocation = in.readParcelable(Location.class.getClassLoader());
|
||||
// mLocation = in.readParcelable(Location.class.getClassLoader());
|
||||
mLocation = Location.CREATOR.createFromParcel(in);
|
||||
mIsStopOver = in.readByte() != 0;
|
||||
mDistanceToStartingPoint = in.readFloat();
|
||||
}
|
||||
|
@ -101,8 +102,10 @@ public class WayPoint implements Parcelable {
|
|||
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeParcelable(mLocation, i);
|
||||
public void writeToParcel(Parcel parcel, int flags) {
|
||||
// parcel.writeParcelable(mLocation, flags);
|
||||
mLocation.setExtras(null); // necessary because: Location Extras cause cannot be serialized properly by GSON
|
||||
mLocation.writeToParcel(parcel, flags);
|
||||
parcel.writeByte((byte) (mIsStopOver ? 1 : 0));
|
||||
parcel.writeFloat(mDistanceToStartingPoint);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import android.util.Log;
|
|||
*/
|
||||
public final class LogHelper {
|
||||
|
||||
private final static boolean mTesting = false;
|
||||
private final static boolean mTesting = true;
|
||||
|
||||
public static void d(final String tag, String message) {
|
||||
// include logging only in debug versions
|
||||
|
|
Loading…
Reference in a new issue