forked from upstream-mirrors/OpenTracks
Some string corrections + getDefaultCategory moved to TrackRecordingService.
This commit is contained in:
@@ -880,14 +880,14 @@ limitations under the License.
|
|||||||
Use a number as the default track name
|
Use a number as the default track name
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_default_category"
|
<string name="settings_default_category"
|
||||||
translation_description="In the Recording settings, the option to set the default
|
translation_description="In the Recording settings, the option to specify a new track's default
|
||||||
type of the recorded activity.">
|
activity type.">
|
||||||
Default activity type
|
Default activity type
|
||||||
</string>
|
</string>
|
||||||
<string name="settings_default_category_summary"
|
<string name="settings_default_category_summary"
|
||||||
translation_description="In the Recording settings, the summary for the 'Default activity type'
|
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.">
|
option explaining that it sets the default activity type for a new track.">
|
||||||
Default type of the recorded activity
|
Default activity type for a new track.
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<!-- Sensor settings -->
|
<!-- Sensor settings -->
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import android.widget.AutoCompleteTextView;
|
|||||||
*/
|
*/
|
||||||
public class AutoCompleteTextPreference extends EditTextPreference {
|
public class AutoCompleteTextPreference extends EditTextPreference {
|
||||||
|
|
||||||
private static AutoCompleteTextView mEditText = null;
|
private AutoCompleteTextView mEditText = null;
|
||||||
|
|
||||||
public AutoCompleteTextPreference(Context context, AttributeSet attrs) {
|
public AutoCompleteTextPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, 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,
|
Log.d(TAG,
|
||||||
"Location listener now unregistered w/ TrackRecordingService.");
|
"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.
|
* Recording lifecycle.
|
||||||
@@ -582,7 +587,7 @@ public class TrackRecordingService extends Service {
|
|||||||
track.setId(recordingTrackId);
|
track.setId(recordingTrackId);
|
||||||
track.setName(new DefaultTrackNameFactory(this).newTrackName(
|
track.setName(new DefaultTrackNameFactory(this).newTrackName(
|
||||||
recordingTrackId, startTime));
|
recordingTrackId, startTime));
|
||||||
track.setCategory(new DefaultCategoryFactory(this).newTrackCategory());
|
track.setCategory(getDefaultActivityType(this));
|
||||||
isRecording = true;
|
isRecording = true;
|
||||||
isMoving = true;
|
isMoving = true;
|
||||||
|
|
||||||
|
|||||||
-54
@@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
@@ -382,6 +382,8 @@ public class TrackRecordingServiceTest
|
|||||||
Track track = providerUtils.getTrack(id);
|
Track track = providerUtils.getTrack(id);
|
||||||
assertNotNull(track);
|
assertNotNull(track);
|
||||||
assertEquals(id, track.getId());
|
assertEquals(id, track.getId());
|
||||||
|
assertEquals(sharedPreferences.getString(context.getString(R.string.default_category_key), ""),
|
||||||
|
track.getCategory());
|
||||||
assertEquals(id, sharedPreferences.getLong(
|
assertEquals(id, sharedPreferences.getLong(
|
||||||
context.getString(R.string.recording_track_key), -1));
|
context.getString(R.string.recording_track_key), -1));
|
||||||
assertEquals(id, service.getRecordingTrackId());
|
assertEquals(id, service.getRecordingTrackId());
|
||||||
|
|||||||
Reference in New Issue
Block a user