Address comments.

This commit is contained in:
Sandor Dornbush
2011-02-04 15:13:33 -08:00
parent 4a47c096f7
commit e7ec021da8
@@ -101,7 +101,7 @@ public class ChartActivity extends Activity implements
/* /*
* UI elements: * UI elements:
*/ */
private ChartView cv; private ChartView chartView;
private MenuItem chartSettingsMenuItem; private MenuItem chartSettingsMenuItem;
private LinearLayout busyPane; private LinearLayout busyPane;
private ZoomControls zoomControls; private ZoomControls zoomControls;
@@ -118,10 +118,10 @@ public class ChartActivity extends Activity implements
@Override @Override
public void run() { public void run() {
busyPane.setVisibility(View.GONE); busyPane.setVisibility(View.GONE);
zoomControls.setIsZoomInEnabled(cv.canZoomIn()); zoomControls.setIsZoomInEnabled(chartView.canZoomIn());
zoomControls.setIsZoomOutEnabled(cv.canZoomOut()); zoomControls.setIsZoomOutEnabled(chartView.canZoomOut());
cv.setShowPointer(selectedTrackIsRecording()); chartView.setShowPointer(selectedTrackIsRecording());
cv.invalidate(); chartView.invalidate();
} }
}; };
@@ -158,12 +158,12 @@ public class ChartActivity extends Activity implements
private Handler updateTrackHandler; private Handler updateTrackHandler;
/** /**
* A runnable that update the profile from the provider. * A runnable that updates the profile from the provider.
*/ */
private final Runnable updateTrackRunnable = new Runnable() { private final Runnable updateTrackRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
updateTrackPoints(); readNewTrackPoints();
} }
}; };
@@ -180,13 +180,13 @@ public class ChartActivity extends Activity implements
metricUnits = metricUnits =
sharedPreferences.getBoolean(getString(R.string.metric_units_key), sharedPreferences.getBoolean(getString(R.string.metric_units_key),
true); true);
cv.setMetricUnits(metricUnits); chartView.setMetricUnits(metricUnits);
readProfileAsync(); readProfileAsync();
} else if (key.equals(getString(R.string.report_speed_key))) { } else if (key.equals(getString(R.string.report_speed_key))) {
reportSpeed = reportSpeed =
sharedPreferences.getBoolean(getString(R.string.report_speed_key), sharedPreferences.getBoolean(getString(R.string.report_speed_key),
true); true);
cv.setReportSpeed(reportSpeed, this); chartView.setReportSpeed(reportSpeed, this);
readProfileAsync(); readProfileAsync();
} else if (key.equals(getString(R.string.recording_track_key))) { } else if (key.equals(getString(R.string.recording_track_key))) {
recordingTrackId = recordingTrackId =
@@ -212,11 +212,11 @@ public class ChartActivity extends Activity implements
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mytracks_charts); setContentView(R.layout.mytracks_charts);
ViewGroup layout = (ViewGroup) findViewById(R.id.elevation_chart); ViewGroup layout = (ViewGroup) findViewById(R.id.elevation_chart);
cv = new ChartView(this); chartView = new ChartView(this);
cv.setMode(this.mode); chartView.setMode(this.mode);
LayoutParams params = LayoutParams params =
new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
layout.addView(cv, params); layout.addView(chartView, params);
SharedPreferences preferences = SharedPreferences preferences =
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0); getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
@@ -227,10 +227,10 @@ public class ChartActivity extends Activity implements
preferences.getLong(getString(R.string.recording_track_key), -1); preferences.getLong(getString(R.string.recording_track_key), -1);
metricUnits = preferences.getBoolean(getString(R.string.metric_units_key), metricUnits = preferences.getBoolean(getString(R.string.metric_units_key),
true); true);
cv.setMetricUnits(metricUnits); chartView.setMetricUnits(metricUnits);
reportSpeed = preferences.getBoolean(getString(R.string.report_speed_key), reportSpeed = preferences.getBoolean(getString(R.string.report_speed_key),
true); true);
cv.setReportSpeed(reportSpeed, this); chartView.setReportSpeed(reportSpeed, this);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
} }
@@ -290,7 +290,7 @@ public class ChartActivity extends Activity implements
ChartActivity.this.runOnUiThread(new Runnable() { ChartActivity.this.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
cv.invalidate(); chartView.invalidate();
} }
}); });
} }
@@ -342,21 +342,21 @@ public class ChartActivity extends Activity implements
} }
private void zoomIn() { private void zoomIn() {
cv.zoomIn(); chartView.zoomIn();
zoomControls.setIsZoomInEnabled(cv.canZoomIn()); zoomControls.setIsZoomInEnabled(chartView.canZoomIn());
zoomControls.setIsZoomOutEnabled(cv.canZoomOut()); zoomControls.setIsZoomOutEnabled(chartView.canZoomOut());
} }
private void zoomOut() { private void zoomOut() {
cv.zoomOut(); chartView.zoomOut();
zoomControls.setIsZoomInEnabled(cv.canZoomIn()); zoomControls.setIsZoomInEnabled(chartView.canZoomIn());
zoomControls.setIsZoomOutEnabled(cv.canZoomOut()); zoomControls.setIsZoomOutEnabled(chartView.canZoomOut());
} }
public void setMode(Mode newMode) { public void setMode(Mode newMode) {
if (this.mode != newMode) { if (this.mode != newMode) {
this.mode = newMode; this.mode = newMode;
cv.setMode(this.mode); chartView.setMode(this.mode);
readProfileAsync(); readProfileAsync();
} }
} }
@@ -366,12 +366,12 @@ public class ChartActivity extends Activity implements
} }
public void setSeriesEnabled(int index, boolean enabled) { public void setSeriesEnabled(int index, boolean enabled) {
cv.getChartValueSeries(index).setEnabled(enabled); chartView.getChartValueSeries(index).setEnabled(enabled);
runOnUiThread(updateChart); runOnUiThread(updateChart);
} }
public boolean isSeriesEnabled(int index) { public boolean isSeriesEnabled(int index) {
return cv.getChartValueSeries(index).isEnabled(); return chartView.getChartValueSeries(index).isEnabled();
} }
private void readWaypoints() { private void readWaypoints() {
@@ -379,7 +379,7 @@ public class ChartActivity extends Activity implements
return; return;
} }
Cursor cursor = null; Cursor cursor = null;
cv.clearWaypoints(); chartView.clearWaypoints();
try { try {
// We will silently drop extra waypoints to make the app responsive. // We will silently drop extra waypoints to make the app responsive.
cursor = cursor =
@@ -389,7 +389,7 @@ public class ChartActivity extends Activity implements
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
do { do {
Waypoint wpt = providerUtils.createWaypoint(cursor); Waypoint wpt = providerUtils.createWaypoint(cursor);
cv.addWaypoint(wpt); chartView.addWaypoint(wpt);
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} }
} }
@@ -533,7 +533,7 @@ public class ChartActivity extends Activity implements
* Sets the chart data points reading from the provider. This is non-blocking. * Sets the chart data points reading from the provider. This is non-blocking.
*/ */
private void readProfileAsync() { private void readProfileAsync() {
cv.reset(); chartView.reset();
updateTrackHandler.post(new Runnable() { updateTrackHandler.post(new Runnable() {
public void run() { public void run() {
runOnUiThread(showSpinner); runOnUiThread(showSpinner);
@@ -606,7 +606,7 @@ public class ChartActivity extends Activity implements
} }
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
cv.setDataPoints(theData); chartView.setDataPoints(theData);
} }
}); });
} catch (RuntimeException e) { } catch (RuntimeException e) {
@@ -619,9 +619,11 @@ public class ChartActivity extends Activity implements
} }
/** /**
* Read all new track points.
*
* The reading methods are synchronized so that we don't read points multiple times. * The reading methods are synchronized so that we don't read points multiple times.
*/ */
private synchronized void updateTrackPoints() { private synchronized void readNewTrackPoints() {
Log.i(MyTracksConstants.TAG, "MyTracks: Updating chart last seen: " + lastSeenLocationId); Log.i(MyTracksConstants.TAG, "MyTracks: Updating chart last seen: " + lastSeenLocationId);
Track track = providerUtils.getTrack(recordingTrackId); Track track = providerUtils.getTrack(recordingTrackId);
if (track == null) { if (track == null) {
@@ -632,7 +634,7 @@ public class ChartActivity extends Activity implements
try { try {
cursor = providerUtils.getLocationsCursor(recordingTrackId, cursor = providerUtils.getLocationsCursor(recordingTrackId,
lastSeenLocationId + 1, lastSeenLocationId + 1,
MyTracksConstants.MAX_DISPLAYED_TRACK_POINTS - cv.getData().size(), MyTracksConstants.MAX_DISPLAYED_TRACK_POINTS - chartView.getData().size(),
true); true);
if (cursor != null) { if (cursor != null) {
if (cursor.moveToLast()) { if (cursor.moveToLast()) {
@@ -650,7 +652,7 @@ public class ChartActivity extends Activity implements
data.add(point); data.add(point);
} }
} while (cursor.moveToPrevious()); } while (cursor.moveToPrevious());
cv.addDataPoints(data); chartView.addDataPoints(data);
} }
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
@@ -661,7 +663,7 @@ public class ChartActivity extends Activity implements
} }
uiHandler.post(new Runnable() { uiHandler.post(new Runnable() {
public void run() { public void run() {
cv.invalidate(); chartView.invalidate();
} }
}); });
} }