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);
|
mCurrentBestLocation.setLongitude(DEFAULT_LONGITUDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogHelper.v(LOG_TAG, "!!! TRACK:" + mCurrentBestLocation.getExtras());
|
||||||
|
|
||||||
|
|
||||||
// get state of location system setting
|
// get state of location system setting
|
||||||
mLocationSystemSetting = LocationHelper.checkLocationSystemSetting(mActivity);
|
mLocationSystemSetting = LocationHelper.checkLocationSystemSetting(mActivity);
|
||||||
|
|
||||||
|
@ -394,8 +397,8 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
}
|
}
|
||||||
|
|
||||||
// save track object
|
// save track object
|
||||||
// SaveTrackAsyncHelper saveTrackAsyncHelper = new SaveTrackAsyncHelper();
|
SaveTrackAsyncHelper saveTrackAsyncHelper = new SaveTrackAsyncHelper();
|
||||||
// saveTrackAsyncHelper.execute();
|
saveTrackAsyncHelper.execute();
|
||||||
// TODO add toast indicating track save
|
// 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.StorageHelper;
|
||||||
import org.y20k.trackbook.helpers.TrackbookKeys;
|
import org.y20k.trackbook.helpers.TrackbookKeys;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MainActivityTrackFragment class
|
* MainActivityTrackFragment class
|
||||||
|
@ -126,7 +128,18 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
|
||||||
mRecordingStopView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_stop);
|
mRecordingStopView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_stop);
|
||||||
mStatisticsSheet = mRootView.findViewById(R.id.statistic_sheet);
|
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 = BottomSheetBehavior.from(mStatisticsSheet);
|
||||||
|
mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||||
|
|
||||||
return mRootView;
|
return mRootView;
|
||||||
}
|
}
|
||||||
|
@ -137,12 +150,6 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
|
||||||
super.onResume();
|
super.onResume();
|
||||||
LogHelper.v(LOG_TAG, "TrackFragment: onResume called.");
|
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);
|
Location lastLocation = mTrack.getWayPointLocation(mTrack.getSize() -1);
|
||||||
position = new GeoPoint(lastLocation.getLatitude(), lastLocation.getLongitude());
|
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
|
// populate views
|
||||||
mDistanceView.setText(mTrack.getTrackDistance());
|
mDistanceView.setText(mTrack.getTrackDistance());
|
||||||
mStepsView.setText(String.valueOf(Math.round(mTrack.getStepCount())));
|
mStepsView.setText(String.valueOf(Math.round(mTrack.getStepCount())));
|
||||||
mWaypointsView.setText(String.valueOf(mTrack.getWayPoints().size()));
|
mWaypointsView.setText(String.valueOf(mTrack.getWayPoints().size()));
|
||||||
mDurationView.setText(mTrack.getTrackDuration());
|
mDurationView.setText(mTrack.getTrackDuration());
|
||||||
mRecordingStartView.setText(mTrack.getRecordingStart().toString());
|
mRecordingStartView.setText(recordingStart);
|
||||||
mRecordingStopView.setText(mTrack.getRecordingStop().toString());
|
mRecordingStopView.setText(recordingStop);
|
||||||
|
|
||||||
// draw track on map
|
// draw track on map
|
||||||
drawTrackOverlay(mTrack);
|
drawTrackOverlay(mTrack);
|
||||||
|
@ -228,6 +240,7 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
|
||||||
protected void onPostExecute(Void aVoid) {
|
protected void onPostExecute(Void aVoid) {
|
||||||
super.onPostExecute(aVoid);
|
super.onPostExecute(aVoid);
|
||||||
// clear track object
|
// clear track object
|
||||||
|
// LogHelper.v(LOG_TAG, "!!! TRACK:" + mTrack.getWayPoints().get(0).getLocation().getExtras());
|
||||||
LogHelper.v(LOG_TAG, "Display map and statistics of track.");
|
LogHelper.v(LOG_TAG, "Display map and statistics of track.");
|
||||||
displayTrack();
|
displayTrack();
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ public class Track implements TrackbookKeys, Parcelable {
|
||||||
private float mTrackLength;
|
private float mTrackLength;
|
||||||
private long mDuration;
|
private long mDuration;
|
||||||
private float mStepCount;
|
private float mStepCount;
|
||||||
private int mUnitSystem;
|
|
||||||
private Date mRecordingStart;
|
private Date mRecordingStart;
|
||||||
private Date mRecordingStop;
|
private Date mRecordingStop;
|
||||||
|
|
||||||
|
@ -56,7 +55,6 @@ public class Track implements TrackbookKeys, Parcelable {
|
||||||
mWayPoints = new ArrayList<WayPoint>();
|
mWayPoints = new ArrayList<WayPoint>();
|
||||||
mTrackLength = 0;
|
mTrackLength = 0;
|
||||||
mStepCount = 0;
|
mStepCount = 0;
|
||||||
mUnitSystem = getUnitSystem(Locale.getDefault());
|
|
||||||
mRecordingStart = GregorianCalendar.getInstance().getTime();
|
mRecordingStart = GregorianCalendar.getInstance().getTime();
|
||||||
mRecordingStop = mRecordingStart;
|
mRecordingStop = mRecordingStart;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +65,6 @@ public class Track implements TrackbookKeys, Parcelable {
|
||||||
mWayPoints = in.createTypedArrayList(WayPoint.CREATOR);
|
mWayPoints = in.createTypedArrayList(WayPoint.CREATOR);
|
||||||
mTrackLength = in.readFloat();
|
mTrackLength = in.readFloat();
|
||||||
mStepCount = in.readFloat();
|
mStepCount = in.readFloat();
|
||||||
mUnitSystem = in.readInt();
|
|
||||||
mRecordingStart = new Date(in.readLong());
|
mRecordingStart = new Date(in.readLong());
|
||||||
mRecordingStop = new Date(in.readLong());
|
mRecordingStop = new Date(in.readLong());
|
||||||
}
|
}
|
||||||
|
@ -174,7 +171,7 @@ public class Track implements TrackbookKeys, Parcelable {
|
||||||
float trackDistance;
|
float trackDistance;
|
||||||
String unit;
|
String unit;
|
||||||
|
|
||||||
if (mUnitSystem == IMPERIAL) {
|
if (getUnitSystem(Locale.getDefault()) == IMPERIAL) {
|
||||||
// get track distance and convert to feet
|
// get track distance and convert to feet
|
||||||
trackDistance = mWayPoints.get(mWayPoints.size()-1).getDistanceToStartingPoint() * 3.28084f;
|
trackDistance = mWayPoints.get(mWayPoints.size()-1).getDistanceToStartingPoint() * 3.28084f;
|
||||||
unit = "ft";
|
unit = "ft";
|
||||||
|
@ -216,11 +213,10 @@ public class Track implements TrackbookKeys, Parcelable {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel parcel, int i) {
|
public void writeToParcel(Parcel parcel, int flags) {
|
||||||
parcel.writeTypedList(mWayPoints);
|
parcel.writeTypedList(mWayPoints);
|
||||||
parcel.writeFloat(mTrackLength);
|
parcel.writeFloat(mTrackLength);
|
||||||
parcel.writeFloat(mStepCount);
|
parcel.writeFloat(mStepCount);
|
||||||
parcel.writeInt(mUnitSystem);
|
|
||||||
parcel.writeLong(mRecordingStart.getTime());
|
parcel.writeLong(mRecordingStart.getTime());
|
||||||
parcel.writeLong(mRecordingStop.getTime());
|
parcel.writeLong(mRecordingStop.getTime());
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,8 @@ public class WayPoint implements Parcelable {
|
||||||
|
|
||||||
/* Constructor used by CREATOR */
|
/* Constructor used by CREATOR */
|
||||||
protected WayPoint(Parcel in) {
|
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;
|
mIsStopOver = in.readByte() != 0;
|
||||||
mDistanceToStartingPoint = in.readFloat();
|
mDistanceToStartingPoint = in.readFloat();
|
||||||
}
|
}
|
||||||
|
@ -101,8 +102,10 @@ public class WayPoint implements Parcelable {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel parcel, int i) {
|
public void writeToParcel(Parcel parcel, int flags) {
|
||||||
parcel.writeParcelable(mLocation, i);
|
// 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.writeByte((byte) (mIsStopOver ? 1 : 0));
|
||||||
parcel.writeFloat(mDistanceToStartingPoint);
|
parcel.writeFloat(mDistanceToStartingPoint);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import android.util.Log;
|
||||||
*/
|
*/
|
||||||
public final class LogHelper {
|
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) {
|
public static void d(final String tag, String message) {
|
||||||
// include logging only in debug versions
|
// include logging only in debug versions
|
||||||
|
|
Loading…
Reference in a new issue