Review issues corrected

This commit is contained in:
ase69s
2011-09-13 20:26:28 +02:00
parent 057c2d69a9
commit 3c4c215931
8 changed files with 134 additions and 121 deletions
@@ -189,49 +189,7 @@ public class SettingsActivity extends PreferenceActivity {
}); });
updateTrackColorModeSettings(trackColorModePreference.getValue()); updateTrackColorModeSettings(trackColorModePreference.getValue());
EditTextPreference trackColorModeFixedSlowPreference = setTrackColorModePreferenceListeners();
(EditTextPreference) findPreference(getString(R.string.track_color_mode_fixed_speed_slow_display_key));
trackColorModeFixedSlowPreference.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
validateTrackColorModeSettings((EditTextPreference) preference, (String) newValue,
R.string.track_color_mode_fixed_speed_slow_key);
return true;
}
});
trackColorModeFixedSlowPreference.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
viewTrackColorModeSettings((EditTextPreference) preference,
R.string.track_color_mode_fixed_speed_slow_key);
return true;
}
});
EditTextPreference trackColorModeFixedMediumPreference =
(EditTextPreference) findPreference(getString(R.string.track_color_mode_fixed_speed_medium_display_key));
trackColorModeFixedMediumPreference.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
validateTrackColorModeSettings((EditTextPreference) preference, (String) newValue,
R.string.track_color_mode_fixed_speed_slow_key);
return true;
}
});
trackColorModeFixedMediumPreference.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
viewTrackColorModeSettings((EditTextPreference) preference,
R.string.track_color_mode_fixed_speed_medium_key);
return true;
}
});
PreferenceCategory speedOptionsCategory = PreferenceCategory speedOptionsCategory =
(PreferenceCategory) findPreference(getString(R.string.track_color_mode_fixed_speed_options_key)); (PreferenceCategory) findPreference(getString(R.string.track_color_mode_fixed_speed_options_key));
@@ -461,8 +419,10 @@ public class SettingsActivity extends PreferenceActivity {
}.start(); }.start();
} }
/** Set the given edit text preference text. /**
If the units are not metric convert the value before displaying. */ * Set the given edit text preference text.
* If the units are not metric convert the value before displaying.
*/
private void viewTrackColorModeSettings(EditTextPreference preference, int id) { private void viewTrackColorModeSettings(EditTextPreference preference, int id) {
CheckBoxPreference metricUnitsPreference = (CheckBoxPreference) findPreference( CheckBoxPreference metricUnitsPreference = (CheckBoxPreference) findPreference(
getString(R.string.metric_units_key)); getString(R.string.metric_units_key));
@@ -481,8 +441,10 @@ public class SettingsActivity extends PreferenceActivity {
preference.getEditText().setText(String.valueOf(englishspeed)); preference.getEditText().setText(String.valueOf(englishspeed));
} }
/** Saves the given edit text preference value. /**
If the units are not metric convert the value before saving. */ * Saves the given edit text preference value.
* If the units are not metric convert the value before saving.
*/
private void validateTrackColorModeSettings(EditTextPreference preference, private void validateTrackColorModeSettings(EditTextPreference preference,
String newValue, int id) { String newValue, int id) {
CheckBoxPreference metricUnitsPreference = (CheckBoxPreference) findPreference( CheckBoxPreference metricUnitsPreference = (CheckBoxPreference) findPreference(
@@ -501,4 +463,53 @@ public class SettingsActivity extends PreferenceActivity {
SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
prefs.edit().putString(getString(id), metricspeed).commit(); prefs.edit().putString(getString(id), metricspeed).commit();
} }
/**
* Sets the TrackColorMode preference listeners.
*/
private void setTrackColorModePreferenceListeners() {
EditTextPreference trackColorModeFixedSlowPreference =
(EditTextPreference) findPreference(getString(R.string.track_color_mode_fixed_speed_slow_display_key));
trackColorModeFixedSlowPreference.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
validateTrackColorModeSettings((EditTextPreference) preference, (String) newValue,
R.string.track_color_mode_fixed_speed_slow_key);
return true;
}
});
trackColorModeFixedSlowPreference.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
viewTrackColorModeSettings((EditTextPreference) preference,
R.string.track_color_mode_fixed_speed_slow_key);
return true;
}
});
EditTextPreference trackColorModeFixedMediumPreference =
(EditTextPreference) findPreference(getString(R.string.track_color_mode_fixed_speed_medium_display_key));
trackColorModeFixedMediumPreference.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
validateTrackColorModeSettings((EditTextPreference) preference, (String) newValue,
R.string.track_color_mode_fixed_speed_slow_key);
return true;
}
});
trackColorModeFixedMediumPreference.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
viewTrackColorModeSettings((EditTextPreference) preference,
R.string.track_color_mode_fixed_speed_medium_key);
return true;
}
});
}
} }
@@ -99,7 +99,7 @@ public class DynamicSpeedTrackPathDescriptor
SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, 0); SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, 0);
long currentTrackId = prefs.getLong(context.getString(R.string.selected_track_key), -1); long currentTrackId = prefs.getLong(context.getString(R.string.selected_track_key), -1);
if(currentTrackId == -1) { if(currentTrackId == -1) {
// in reality this means something went awry, additional logic to exit or so? // Could not find track.
return false; return false;
} }
Track track = MyTracksProviderUtils.Factory.get(context).getTrack(currentTrackId); Track track = MyTracksProviderUtils.Factory.get(context).getTrack(currentTrackId);
@@ -56,7 +56,7 @@ public class TrackPathPainterFactory {
return new DynamicSpeedTrackPathPainter(context, return new DynamicSpeedTrackPathPainter(context,
new DynamicSpeedTrackPathDescriptor(context)); new DynamicSpeedTrackPathDescriptor(context));
} else { } else {
Log.i(Constants.TAG, "Unknow colorMode: " + colorMode); Log.w(Constants.TAG, "Using default track path painter. Unrecognized painter: " + colorMode);
return new SingleColorTrackPathPainter(context); return new SingleColorTrackPathPainter(context);
} }
} }
@@ -24,6 +24,7 @@ import android.graphics.Paint;
* @author Vangelis S. * @author Vangelis S.
*/ */
public class TrackPathUtilities { public class TrackPathUtilities {
public static Paint getPaint(int id, Context context) { public static Paint getPaint(int id, Context context) {
Paint paint = new Paint(); Paint paint = new Paint();
paint.setColor(context.getResources().getColor(id)); paint.setColor(context.getResources().getColor(id));
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2011 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
@@ -27,29 +27,31 @@ import android.graphics.Rect;
* *
* @author Bartlomiej Niechwiej * @author Bartlomiej Niechwiej
* @author Vangelis S. * @author Vangelis S.
*/ *
/**
* A mock version of {@code MapOverlay} that does not use * A mock version of {@code MapOverlay} that does not use
* {@class MapView}. * {@class MapView}.
*/ */
public class MockMyTracksOverlay extends MapOverlay { public class MockMyTracksOverlay extends MapOverlay {
private Projection mockProjection; private Projection mockProjection;
public MockMyTracksOverlay(Context context) { public MockMyTracksOverlay(Context context) {
super(context); super(context);
mockProjection = new MockProjection(); mockProjection = new MockProjection();
} }
@Override @Override
public Projection getMapProjection(MapView mapView) { public Projection getMapProjection(MapView mapView) {
return mockProjection; return mockProjection;
} }
@Override @Override
public Rect getMapViewRect(MapView mapView) { public Rect getMapViewRect(MapView mapView) {
return new Rect(0, 0, 100, 100); return new Rect(0, 0, 100, 100);
} }
@Override @Override
public Path newPath() { public Path newPath() {
return new MockPath(); return new MockPath();
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2011 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
@@ -30,28 +30,26 @@ import junit.framework.Assert;
* *
* @author Bartlomiej Niechwiej * @author Bartlomiej Niechwiej
* @author Vangelis S. * @author Vangelis S.
*/ *
/**
* A mock class that intercepts {@code Path}'s and records calls to * A mock class that intercepts {@code Path}'s and records calls to
* {@code #moveTo()} and {@code #lineTo()}. * {@code #moveTo()} and {@code #lineTo()}.
*/ */
public class MockPath extends Path { public class MockPath extends Path {
/** A list of disjoined path segments. */ /** A list of disjoined path segments. */
public final List<List<PointF>> segments = new LinkedList<List<PointF>>(); public final List<List<PointF>> segments = new LinkedList<List<PointF>>();
/** The total number of points in this path. */ /** The total number of points in this path. */
public int totalPoints; public int totalPoints;
private List<PointF> currentSegment; private List<PointF> currentSegment;
@Override @Override
public void lineTo(float x, float y) { public void lineTo(float x, float y) {
super.lineTo(x, y); super.lineTo(x, y);
Assert.assertNotNull(currentSegment); Assert.assertNotNull(currentSegment);
currentSegment.add(new PointF(x, y)); currentSegment.add(new PointF(x, y));
totalPoints++; totalPoints++;
} }
@Override @Override
public void moveTo(float x, float y) { public void moveTo(float x, float y) {
super.moveTo(x, y); super.moveTo(x, y);
@@ -59,4 +57,4 @@ import junit.framework.Assert;
new ArrayList<PointF>(Arrays.asList(new PointF(x, y)))); new ArrayList<PointF>(Arrays.asList(new PointF(x, y))));
totalPoints++; totalPoints++;
} }
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2011 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of * use this file except in compliance with the License. You may obtain a copy of
@@ -25,22 +25,23 @@ import android.graphics.Point;
* *
* @author Bartlomiej Niechwiej * @author Bartlomiej Niechwiej
* @author Vangelis S. * @author Vangelis S.
*/ *
/**
* A mock {@code Projection} that acts as the identity matrix. * A mock {@code Projection} that acts as the identity matrix.
*/ */
public class MockProjection implements Projection { public class MockProjection implements Projection {
@Override @Override
public Point toPixels(GeoPoint in, Point out) { public Point toPixels(GeoPoint in, Point out) {
return out; return out;
} }
@Override @Override
public float metersToEquatorPixels(float meters) { public float metersToEquatorPixels(float meters) {
return meters; return meters;
} }
@Override @Override
public GeoPoint fromPixels(int x, int y) { public GeoPoint fromPixels(int x, int y) {
return new GeoPoint(y, x); return new GeoPoint(y, x);
} }
} }