From a17fc3efd2e4679c25a6bb9b472f86a886ff1485 Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Wed, 21 Dec 2011 10:55:07 -0800 Subject: [PATCH] Fix the display unit (metric or imperial) on ChartView both on first app launch and when changing the display unit. In ChartActivity, set the default to true to match the default in ChartView. When display unit changes, on the UI thread, request a layout so the axises can be redrawn. --- .../android/apps/mytracks/ChartActivity.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/ChartActivity.java b/MyTracks/src/com/google/android/apps/mytracks/ChartActivity.java index 49f4c7114..dbe0e37a1 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/ChartActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/ChartActivity.java @@ -77,7 +77,7 @@ public class ChartActivity extends Activity implements TrackDataListener { private double trackMaxSpeed; // Modes of operation - private boolean metricUnits; + private boolean metricUnits = true; private boolean reportSpeed; /* @@ -452,14 +452,19 @@ public class ChartActivity extends Activity implements TrackDataListener { @Override public boolean onUnitsChanged(boolean metric) { - boolean changed = metric != this.metricUnits; - if (!changed) return false; - - this.metricUnits = metric; - - chartView.setMetricUnits(metric); - - return true; // Reload data + if (this.metricUnits == metric) { + return false; + } else { + this.metricUnits = metric; + chartView.setMetricUnits(metric); + runOnUiThread(new Runnable() { + @Override + public void run() { + chartView.requestLayout(); + } + }); + return true; + } } @SuppressWarnings("hiding")