forked from upstream-mirrors/OpenTracks
Review issues corrected, added test case for remaining class TrackPathPainterFactory
This commit is contained in:
@@ -462,7 +462,7 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
Log.d(Constants.TAG, "MapOverlay: onSharedPreferences changed " + key);
|
||||
Log.d(TAG, "MapOverlay: onSharedPreferences changed " + key);
|
||||
if (key != null) {
|
||||
if (key.equals(context.getString(R.string.track_color_mode_key))) {
|
||||
trackPathPainter = TrackPathPainterFactory.getTrackPathPainter(context);
|
||||
|
||||
@@ -468,46 +468,32 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
* 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(
|
||||
setTrackColorModePreferenceListener(R.string.track_color_mode_fixed_speed_slow_display_key,
|
||||
R.string.track_color_mode_fixed_speed_slow_key);
|
||||
setTrackColorModePreferenceListener(R.string.track_color_mode_fixed_speed_medium_display_key,
|
||||
R.string.track_color_mode_fixed_speed_medium_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a TrackColorMode preference listener.
|
||||
*/
|
||||
private void setTrackColorModePreferenceListener(int displayKey, final int metricKey) {
|
||||
EditTextPreference trackColorModePreference =
|
||||
(EditTextPreference) findPreference(getString(displayKey));
|
||||
trackColorModePreference.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);
|
||||
validateTrackColorModeSettings((EditTextPreference) preference, (String) newValue, metricKey);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
trackColorModeFixedSlowPreference.setOnPreferenceClickListener(
|
||||
trackColorModePreference.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);
|
||||
viewTrackColorModeSettings((EditTextPreference) preference, metricKey);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
+3
-1
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
@@ -76,7 +78,7 @@ public class DynamicSpeedTrackPathDescriptor
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
Log.d(Constants.TAG, "DynamicSpeedTrackPathDescriptor: onSharedPreferences changed " + key);
|
||||
Log.d(TAG, "DynamicSpeedTrackPathDescriptor: onSharedPreferences changed " + key);
|
||||
if (key == null
|
||||
|| !key.equals(context.getString(R.string.track_color_mode_dynamic_speed_variation_key))) {
|
||||
return;
|
||||
|
||||
+7
-7
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -34,7 +36,7 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSha
|
||||
private int normalSpeed;
|
||||
private final Context context;
|
||||
|
||||
public FixedSpeedTrackPathDescriptor(Context context){
|
||||
public FixedSpeedTrackPathDescriptor(Context context) {
|
||||
|
||||
this.context = context;
|
||||
context.getSharedPreferences(Constants.SETTINGS_NAME, 0)
|
||||
@@ -65,8 +67,7 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSha
|
||||
* Gets the slow speed for reference.
|
||||
* @return The speed limit considered as slow.
|
||||
*/
|
||||
public int getSlowSpeed()
|
||||
{
|
||||
public int getSlowSpeed() {
|
||||
return slowSpeed;
|
||||
}
|
||||
|
||||
@@ -74,14 +75,13 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSha
|
||||
* Gets the normal speed for reference.
|
||||
* @return The speed limit considered as normal.
|
||||
*/
|
||||
public int getNormalSpeed()
|
||||
{
|
||||
public int getNormalSpeed() {
|
||||
return normalSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
Log.d(Constants.TAG, "FixedSpeedTrackPathDescriptor: onSharedPreferences changed " + key);
|
||||
Log.d(TAG, "FixedSpeedTrackPathDescriptor: onSharedPreferences changed " + key);
|
||||
if (key == null
|
||||
|| (!key.equals(context.getString(R.string.track_color_mode_fixed_speed_slow_key))
|
||||
&& !key.equals(context.getString(R.string.track_color_mode_fixed_speed_medium_key)))) {
|
||||
@@ -104,7 +104,7 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSha
|
||||
normalSpeed = Integer.parseInt(prefs.getString(context.getString(
|
||||
R.string.track_color_mode_fixed_speed_medium_key), "17"));
|
||||
} catch (NumberFormatException e) {
|
||||
normalSpeed = 17;
|
||||
normalSpeed = 17;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -45,7 +47,7 @@ public class TrackPathPainterFactory {
|
||||
}
|
||||
|
||||
String colorMode = prefs.getString(context.getString(R.string.track_color_mode_key), null);
|
||||
Log.i(Constants.TAG, "Creating track path painter of type: " + colorMode);
|
||||
Log.i(TAG, "Creating track path painter of type: " + colorMode);
|
||||
|
||||
if (colorMode == null || colorMode.equals(context.getString(R.string.track_color_mode_none))) {
|
||||
return new SingleColorTrackPathPainter(context);
|
||||
@@ -56,7 +58,7 @@ public class TrackPathPainterFactory {
|
||||
return new DynamicSpeedTrackPathPainter(context,
|
||||
new DynamicSpeedTrackPathDescriptor(context));
|
||||
} else {
|
||||
Log.w(Constants.TAG, "Using default track path painter. Unrecognized painter: " + colorMode);
|
||||
Log.w(TAG, "Using default track path painter. Unrecognized painter: " + colorMode);
|
||||
return new SingleColorTrackPathPainter(context);
|
||||
}
|
||||
}
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* 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
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
/**
|
||||
* Tests for the MyTracks track path descriptors and painters.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*/
|
||||
public class TrackPathDescriptorDynamicSpeedTest extends TrackPathPainterTestCase {
|
||||
|
||||
public void testDynamicSpeedTrackPathDescriptor() throws Exception {
|
||||
Location location = new Location("gps");
|
||||
location.setLatitude(10);
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
location = new Location("gps");
|
||||
location.setLatitude(20 + i / 2);
|
||||
location.setLongitude(150 - i);
|
||||
myTracksOverlay.addLocation(location);
|
||||
}
|
||||
|
||||
TrackPathPainter painter = new DynamicSpeedTrackPathPainter(getContext(), new DynamicSpeedTrackPathDescriptor(getContext()));
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getPoints());
|
||||
painter.drawTrack(canvas);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* 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
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
/**
|
||||
* Tests for the MyTracks track path descriptors and painters.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*/
|
||||
public class TrackPathDescriptorFixedSpeedTest extends TrackPathPainterTestCase {
|
||||
|
||||
public void testFixedSpeedTrackPathDescriptor() throws Exception {
|
||||
Location location = new Location("gps");
|
||||
location.setLatitude(10);
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
location = new Location("gps");
|
||||
location.setLatitude(20 + i / 2);
|
||||
location.setLongitude(150 - i);
|
||||
myTracksOverlay.addLocation(location);
|
||||
}
|
||||
|
||||
TrackPathPainter painter = new DynamicSpeedTrackPathPainter(getContext(), new FixedSpeedTrackPathDescriptor(getContext()));
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getPoints());
|
||||
painter.drawTrack(canvas);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* 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
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
|
||||
/**
|
||||
* Tests for the MyTracks track path painter factory.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*/
|
||||
public class TrackPathPainterFactoryTest extends TrackPathPainterTestCase {
|
||||
|
||||
public void testTrackPathPainterFactory() throws Exception {
|
||||
Location location = new Location("gps");
|
||||
location.setLatitude(10);
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
location = new Location("gps");
|
||||
location.setLatitude(20 + i / 2);
|
||||
location.setLongitude(150 - i);
|
||||
myTracksOverlay.addLocation(location);
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, 0);
|
||||
if (prefs == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
testTrackPathPainterFactorySpecific(context, prefs, R.string.track_color_mode_none);
|
||||
testTrackPathPainterFactorySpecific(context, prefs, R.string.track_color_mode_fixed);
|
||||
testTrackPathPainterFactorySpecific(context, prefs, R.string.track_color_mode_dynamic);
|
||||
}
|
||||
|
||||
private void testTrackPathPainterFactorySpecific(Context context, SharedPreferences prefs, int track_color_mode) {
|
||||
prefs.edit().putString(context.getString(track_color_mode),
|
||||
context.getString(R.string.track_color_mode_key)).commit();
|
||||
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
TrackPathPainter painter = TrackPathPainterFactory.getTrackPathPainter(context);
|
||||
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getPoints());
|
||||
painter.drawTrack(canvas);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* 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
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
/**
|
||||
* Tests for the MyTracks track path descriptors and painters.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*/
|
||||
public class TrackPathPainterSingleColorTest extends TrackPathPainterTestCase {
|
||||
|
||||
public void testSimpeColorTrackPathPainter() throws Exception {
|
||||
Location location = new Location("gps");
|
||||
location.setLatitude(10);
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
location = new Location("gps");
|
||||
location.setLatitude(20 + i / 2);
|
||||
location.setLongitude(150 - i);
|
||||
myTracksOverlay.addLocation(location);
|
||||
}
|
||||
|
||||
TrackPathPainter painter = new SingleColorTrackPathPainter(getContext());
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getPoints());
|
||||
painter.drawTrack(canvas);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* 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
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.MockMyTracksOverlay;
|
||||
import com.google.android.maps.MapView;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests for the MyTracks track path descriptors and painters.
|
||||
*
|
||||
* @author Vangelis S.
|
||||
*/
|
||||
public class TrackPathPainterTestCase extends AndroidTestCase {
|
||||
protected Canvas canvas;
|
||||
protected MockMyTracksOverlay myTracksOverlay;
|
||||
protected MapView mockView;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
canvas = new Canvas();
|
||||
myTracksOverlay = new MockMyTracksOverlay(getContext());
|
||||
// Enable drawing.
|
||||
myTracksOverlay.setTrackDrawingEnabled(true);
|
||||
mockView = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user