Some string corrections + getDefaultCategory moved to TrackRecordingService.

This commit is contained in:
Rimas Trumpa
2011-11-09 22:03:59 +00:00
parent a76945deef
commit 7915202aaa
6 changed files with 13 additions and 114 deletions
+4 -4
View File
@@ -880,14 +880,14 @@ limitations under the License.
Use a number as the default track name
</string>
<string name="settings_default_category"
translation_description="In the Recording settings, the option to set the default
type of the recorded activity.">
translation_description="In the Recording settings, the option to specify a new track's default
activity type.">
Default activity type
</string>
<string name="settings_default_category_summary"
translation_description="In the Recording settings, the summary for the 'Default activity type'
option explaining that it sets the default type of the recorded activity.">
Default type of the recorded activity
option explaining that it sets the default activity type for a new track.">
Default activity type for a new track.
</string>
<!-- Sensor settings -->
@@ -23,7 +23,7 @@ import android.widget.AutoCompleteTextView;
*/
public class AutoCompleteTextPreference extends EditTextPreference {
private static AutoCompleteTextView mEditText = null;
private AutoCompleteTextView mEditText = null;
public AutoCompleteTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -1,54 +0,0 @@
/*
* Copyright 2010 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.services;
import com.google.android.apps.mytracks.Constants;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.content.SharedPreferences;
/**
* Creates a default track category (activity type) based on current default
* category settings.
*
* @author Rimas Trumpa
*/
class DefaultCategoryFactory {
private final Context context;
DefaultCategoryFactory(Context context) {
this.context = context;
}
/**
* Creates a new track category (activity type).
*
* @return The new track category.
*/
String newTrackCategory() {
if (getDefaultCategory() != null) {
return getDefaultCategory();
} else {
return "";
}
}
protected String getDefaultCategory() {
SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, 0);
return prefs.getString(context.getString(R.string.default_category_key), null);
}
}
@@ -559,6 +559,11 @@ public class TrackRecordingService extends Service {
Log.d(TAG,
"Location listener now unregistered w/ TrackRecordingService.");
}
private String getDefaultActivityType(Context context) {
SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, 0);
return prefs.getString(context.getString(R.string.default_category_key), "");
}
/*
* Recording lifecycle.
@@ -582,7 +587,7 @@ public class TrackRecordingService extends Service {
track.setId(recordingTrackId);
track.setName(new DefaultTrackNameFactory(this).newTrackName(
recordingTrackId, startTime));
track.setCategory(new DefaultCategoryFactory(this).newTrackCategory());
track.setCategory(getDefaultActivityType(this));
isRecording = true;
isMoving = true;
@@ -1,54 +0,0 @@
/*
* Copyright 2010 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.services;
import android.content.Context;
import android.test.AndroidTestCase;
/**
* Tests {@link DefaultCategoryFactory}
*
* @author Rimas Trumpa
*/
public class DefaultCategoryFactoryTest extends AndroidTestCase {
/**
* A version of the factory which allows us to supply our own default activity
* type.
*/
private static class MockDefaultCategoryFactory extends DefaultCategoryFactory {
private final String defaultCategory;
MockDefaultCategoryFactory(Context context, String defaultCategory) {
super(context);
this.defaultCategory = defaultCategory;
}
@Override
protected String getDefaultCategory() {
return defaultCategory;
}
}
public void testCategoryName() {
DefaultCategoryFactory factory = new MockDefaultCategoryFactory(getContext(), "foo");
assertEquals("foo", factory.newTrackCategory());
}
public void testNoDefaultCategoryName() {
DefaultCategoryFactory factory = new MockDefaultCategoryFactory(getContext(), null);
assertEquals("", factory.newTrackCategory());
}
}
@@ -382,6 +382,8 @@ public class TrackRecordingServiceTest
Track track = providerUtils.getTrack(id);
assertNotNull(track);
assertEquals(id, track.getId());
assertEquals(sharedPreferences.getString(context.getString(R.string.default_category_key), ""),
track.getCategory());
assertEquals(id, sharedPreferences.getLong(
context.getString(R.string.recording_track_key), -1));
assertEquals(id, service.getRecordingTrackId());