forked from upstream-mirrors/OpenTracks
Fix an nullpointexception issue when run ChartFragmentTest.
This commit is contained in:
@@ -34,6 +34,7 @@ import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -188,7 +189,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
public void onSampledInTrackPoint(Location location) {
|
||||
if (isResumed()) {
|
||||
double[] data = new double[ChartView.NUM_SERIES + 1];
|
||||
fillDataPoint(location, data);
|
||||
fillDataPoint(location, data, getActivity());
|
||||
pendingPoints.add(data);
|
||||
}
|
||||
}
|
||||
@@ -196,14 +197,14 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
@Override
|
||||
public void onSampledOutTrackPoint(Location location) {
|
||||
if (isResumed()) {
|
||||
fillDataPoint(location, null);
|
||||
fillDataPoint(location, null, getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSegmentSplit(Location location) {
|
||||
if (isResumed()) {
|
||||
fillDataPoint(location, null);
|
||||
fillDataPoint(location, null, getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,9 +440,10 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
*
|
||||
* @param location the location
|
||||
* @param data the data point to fill in, can be null
|
||||
* @param context the context
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void fillDataPoint(Location location, double data[]) {
|
||||
void fillDataPoint(Location location, double data[], Context context) {
|
||||
double timeOrDistance = Double.NaN;
|
||||
double elevation = Double.NaN;
|
||||
double speed = Double.NaN;
|
||||
@@ -451,7 +453,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
double power = Double.NaN;
|
||||
|
||||
if (tripStatisticsUpdater != null) {
|
||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, getActivity());
|
||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context);
|
||||
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||
if (chartByDistance) {
|
||||
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
||||
|
||||
@@ -358,7 +358,7 @@ public class ChartFragmentTest extends AndroidTestCase {
|
||||
*/
|
||||
private double[] fillDataPointTestHelper(Location location) {
|
||||
double[] point = new double[ChartView.NUM_SERIES + 1];
|
||||
chartFragment.fillDataPoint(location, point);
|
||||
chartFragment.fillDataPoint(location, point, getContext());
|
||||
return point;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user