forked from upstream-mirrors/OpenTracks
Rename files in the "tasks" package.
This commit is contained in:
@@ -32,9 +32,9 @@ import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest.WaypointType;
|
||||
import com.google.android.apps.mytracks.services.sensors.SensorManager;
|
||||
import com.google.android.apps.mytracks.services.sensors.SensorManagerFactory;
|
||||
import com.google.android.apps.mytracks.services.tasks.AnnouncementPeriodicTaskFactory;
|
||||
import com.google.android.apps.mytracks.services.tasks.PeriodicTaskExecutor;
|
||||
import com.google.android.apps.mytracks.services.tasks.SplitTask;
|
||||
import com.google.android.apps.mytracks.services.tasks.StatusAnnouncerFactory;
|
||||
import com.google.android.apps.mytracks.services.tasks.SplitPeriodicTaskFactory;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.stats.TripStatisticsBuilder;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
@@ -277,8 +277,8 @@ public class TrackRecordingService extends Service {
|
||||
context = this;
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
|
||||
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
announcementExecutor = new PeriodicTaskExecutor(this, new StatusAnnouncerFactory());
|
||||
splitExecutor = new PeriodicTaskExecutor(this, new SplitTask.Factory());
|
||||
announcementExecutor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory());
|
||||
splitExecutor = new PeriodicTaskExecutor(this, new SplitPeriodicTaskFactory());
|
||||
executorService = Executors.newSingleThreadExecutor();
|
||||
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
|
||||
+3
-3
@@ -38,7 +38,7 @@ import java.util.Locale;
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public class StatusAnnouncerTask implements PeriodicTask {
|
||||
public class AnnouncementPeriodicTask implements PeriodicTask {
|
||||
|
||||
/**
|
||||
* The rate at which announcements are spoken.
|
||||
@@ -46,7 +46,7 @@ public class StatusAnnouncerTask implements PeriodicTask {
|
||||
@VisibleForTesting
|
||||
static final float TTS_SPEECH_RATE = 0.9f;
|
||||
|
||||
private static final String TAG = StatusAnnouncerTask.class.getSimpleName();
|
||||
private static final String TAG = AnnouncementPeriodicTask.class.getSimpleName();
|
||||
private static final long HOUR_TO_MILLISECOND = 60 * 60 * 1000;
|
||||
|
||||
private final Context context;
|
||||
@@ -75,7 +75,7 @@ public class StatusAnnouncerTask implements PeriodicTask {
|
||||
}
|
||||
};
|
||||
|
||||
public StatusAnnouncerTask(Context context) {
|
||||
public AnnouncementPeriodicTask(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
+4
-5
@@ -20,15 +20,14 @@ import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Factory which wraps construction and setup of text-to-speech announcements in
|
||||
* an API-level-safe way.
|
||||
*
|
||||
* A {@link PeriodicTaskFactory} for text-to-speech announcement periodic task.
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class StatusAnnouncerFactory implements PeriodicTaskFactory {
|
||||
public class AnnouncementPeriodicTaskFactory implements PeriodicTaskFactory {
|
||||
|
||||
@Override
|
||||
public PeriodicTask create(Context context) {
|
||||
return ApiAdapterFactory.getApiAdapter().getStatusAnnouncerTask(context);
|
||||
return ApiAdapterFactory.getApiAdapter().getAnnouncementPeriodicTask(context);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -32,9 +32,9 @@ import java.util.HashMap;
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
@TargetApi(8)
|
||||
public class Api8StatusAnnouncerTask extends StatusAnnouncerTask {
|
||||
public class Api8AnnouncementPeriodicTask extends AnnouncementPeriodicTask {
|
||||
|
||||
private static final String TAG = Api8StatusAnnouncerTask.class.getSimpleName();
|
||||
private static final String TAG = Api8AnnouncementPeriodicTask.class.getSimpleName();
|
||||
private static final HashMap<String, String> SPEECH_PARAMS = new HashMap<String, String>();
|
||||
static {
|
||||
SPEECH_PARAMS.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "not_used");
|
||||
@@ -53,7 +53,7 @@ public class Api8StatusAnnouncerTask extends StatusAnnouncerTask {
|
||||
|
||||
private final AudioManager audioManager;
|
||||
|
||||
public Api8StatusAnnouncerTask(Context context) {
|
||||
public Api8AnnouncementPeriodicTask(Context context) {
|
||||
super(context);
|
||||
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
}
|
||||
+3
-3
@@ -19,16 +19,16 @@ package com.google.android.apps.mytracks.services.tasks;
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* An interface for classes that can create periodic tasks.
|
||||
* An interface for classes that can create {@link PeriodicTask}.
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public interface PeriodicTaskFactory {
|
||||
|
||||
/**
|
||||
* Creates a periodic task.
|
||||
* Creates a {@link PeriodicTask}.
|
||||
*
|
||||
* @return the task, or null if task is not supported
|
||||
* @return the task, or null if the task is not supported
|
||||
*/
|
||||
public PeriodicTask create(Context context);
|
||||
}
|
||||
+3
-18
@@ -19,36 +19,21 @@ package com.google.android.apps.mytracks.services.tasks;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingService;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* A simple task to insert statistics markers periodically.
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public class SplitTask implements PeriodicTask {
|
||||
|
||||
private SplitTask() {}
|
||||
public class SplitPeriodicTask implements PeriodicTask {
|
||||
|
||||
@Override
|
||||
public void start() {}
|
||||
|
||||
@Override
|
||||
public void run(TrackRecordingService service) {
|
||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
||||
public void run(TrackRecordingService trackRecordingService) {
|
||||
trackRecordingService.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {}
|
||||
|
||||
/**
|
||||
* Create new {@link SplitTask}.
|
||||
*/
|
||||
public static class Factory implements PeriodicTaskFactory {
|
||||
|
||||
@Override
|
||||
public PeriodicTask create(Context context) {
|
||||
return new SplitTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2012 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.tasks;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* A {@link PeriodicTaskFactory} for {@link SplitPeriodicTask}.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class SplitPeriodicTaskFactory implements PeriodicTaskFactory {
|
||||
|
||||
@Override
|
||||
public PeriodicTask create(Context context) {
|
||||
return new SplitPeriodicTask();
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.ContextualActionModeCallback;
|
||||
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
|
||||
import com.google.android.apps.mytracks.services.sensors.BluetoothConnectionManager;
|
||||
import com.google.android.apps.mytracks.services.tasks.AnnouncementPeriodicTask;
|
||||
import com.google.android.apps.mytracks.services.tasks.PeriodicTask;
|
||||
import com.google.android.apps.mytracks.services.tasks.StatusAnnouncerTask;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.apache.ApacheHttpTransport;
|
||||
|
||||
@@ -50,8 +50,8 @@ import java.util.List;
|
||||
public class Api7Adapter implements ApiAdapter {
|
||||
|
||||
@Override
|
||||
public PeriodicTask getStatusAnnouncerTask(Context context) {
|
||||
return new StatusAnnouncerTask(context);
|
||||
public PeriodicTask getAnnouncementPeriodicTask(Context context) {
|
||||
return new AnnouncementPeriodicTask(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
|
||||
import com.google.android.apps.mytracks.io.backup.Api8BackupPreferencesListener;
|
||||
import com.google.android.apps.mytracks.services.tasks.Api8StatusAnnouncerTask;
|
||||
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
|
||||
import com.google.android.apps.mytracks.services.tasks.Api8AnnouncementPeriodicTask;
|
||||
import com.google.android.apps.mytracks.services.tasks.PeriodicTask;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -30,8 +30,8 @@ import android.content.Context;
|
||||
public class Api8Adapter extends Api7Adapter {
|
||||
|
||||
@Override
|
||||
public PeriodicTask getStatusAnnouncerTask(Context context) {
|
||||
return new Api8StatusAnnouncerTask(context);
|
||||
public PeriodicTask getAnnouncementPeriodicTask(Context context) {
|
||||
return new Api8AnnouncementPeriodicTask(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,13 +42,13 @@ import java.util.List;
|
||||
public interface ApiAdapter {
|
||||
|
||||
/**
|
||||
* Gets a status announcer task.
|
||||
* Gets an announcement periodic task.
|
||||
* <p>
|
||||
* Due to changes in API level 8.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public PeriodicTask getStatusAnnouncerTask(Context context);
|
||||
public PeriodicTask getAnnouncementPeriodicTask(Context context);
|
||||
|
||||
/**
|
||||
* Gets a {@link BackupPreferencesListener}.
|
||||
|
||||
+5
-4
@@ -13,20 +13,21 @@
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.google.android.apps.mytracks.services.tasks;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link StatusAnnouncerFactory}.
|
||||
* Tests for {@link AnnouncementPeriodicTaskFactory}.
|
||||
* These tests require Donut+ to run.
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class StatusAnnouncerFactoryTest extends AndroidTestCase {
|
||||
public class AnnouncementPeriodicTaskFactoryTest extends AndroidTestCase {
|
||||
public void testCreate() {
|
||||
PeriodicTaskFactory factory = new StatusAnnouncerFactory();
|
||||
PeriodicTaskFactory factory = new AnnouncementPeriodicTaskFactory();
|
||||
PeriodicTask task = factory.create(getContext());
|
||||
assertTrue(task instanceof StatusAnnouncerTask);
|
||||
assertTrue(task instanceof AnnouncementPeriodicTask);
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -40,21 +40,21 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.easymock.Capture;
|
||||
|
||||
/**
|
||||
* Tests for {@link StatusAnnouncerTask}.
|
||||
* Tests for {@link AnnouncementPeriodicTask}.
|
||||
* WARNING: I'm not responsible if your eyes start bleeding while reading this
|
||||
* code. You have been warned. It's still better than no test, though.
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
public class AnnouncementPeriodicTaskTest extends AndroidTestCase {
|
||||
|
||||
// Use something other than our hardcoded value
|
||||
private static final Locale DEFAULT_LOCALE = Locale.KOREAN;
|
||||
private static final String ANNOUNCEMENT = "I can haz cheeseburger?";
|
||||
private Locale oldDefaultLocale;
|
||||
|
||||
private StatusAnnouncerTask task;
|
||||
private StatusAnnouncerTask mockTask;
|
||||
private AnnouncementPeriodicTask task;
|
||||
private AnnouncementPeriodicTask mockTask;
|
||||
private Capture<OnInitListener> initListenerCapture;
|
||||
private Capture<PhoneStateListener> phoneListenerCapture;
|
||||
private TextToSpeechDelegate ttsDelegate;
|
||||
@@ -252,7 +252,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
@UsesMocks({
|
||||
StatusAnnouncerTask.class,
|
||||
AnnouncementPeriodicTask.class,
|
||||
StringUtils.class,
|
||||
})
|
||||
@Override
|
||||
@@ -291,8 +291,8 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
phoneListenerCapture = new Capture<PhoneStateListener>();
|
||||
|
||||
// Create a partial forwarding mock
|
||||
mockTask = AndroidMock.createMock(StatusAnnouncerTask.class, getContext());
|
||||
task = new StatusAnnouncerTask(getContext()) {
|
||||
mockTask = AndroidMock.createMock(AnnouncementPeriodicTask.class, getContext());
|
||||
task = new AnnouncementPeriodicTask(getContext()) {
|
||||
@Override
|
||||
protected TextToSpeech newTextToSpeech(Context ctx,
|
||||
OnInitListener onInitListener) {
|
||||
@@ -369,7 +369,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
|
||||
expect(tts.isLanguageAvailable(DEFAULT_LOCALE)).andStubReturn(TextToSpeech.LANG_AVAILABLE);
|
||||
expect(tts.setLanguage(DEFAULT_LOCALE)).andReturn(TextToSpeech.LANG_AVAILABLE);
|
||||
expect(tts.setSpeechRate(StatusAnnouncerTask.TTS_SPEECH_RATE)).andReturn(TextToSpeech.SUCCESS);
|
||||
expect(tts.setSpeechRate(AnnouncementPeriodicTask.TTS_SPEECH_RATE)).andReturn(TextToSpeech.SUCCESS);
|
||||
|
||||
// Expect actual announcement call
|
||||
expect(tts.speak(
|
||||
@@ -458,7 +458,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StatusAnnouncerTask#getAnnounceTime(long)} with time zero.
|
||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with time zero.
|
||||
*/
|
||||
public void testGetAnnounceTime_time_zero() {
|
||||
long time = 0; // 0 seconds
|
||||
@@ -466,7 +466,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StatusAnnouncerTask#getAnnounceTime(long)} with time one.
|
||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with time one.
|
||||
*/
|
||||
public void testGetAnnounceTime_time_one() {
|
||||
long time = 1 * 1000; // 1 second
|
||||
@@ -474,7 +474,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StatusAnnouncerTask#getAnnounceTime(long)} with singular
|
||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with singular
|
||||
* numbers with the hour unit.
|
||||
*/
|
||||
public void testGetAnnounceTime_singular_has_hour() {
|
||||
@@ -483,7 +483,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StatusAnnouncerTask#getAnnounceTime(long)} with plural numbers
|
||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with plural numbers
|
||||
* with the hour unit.
|
||||
*/
|
||||
public void testGetAnnounceTime_plural_has_hour() {
|
||||
@@ -492,7 +492,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StatusAnnouncerTask#getAnnounceTime(long)} with singular
|
||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with singular
|
||||
* numbers without the hour unit.
|
||||
*/
|
||||
public void testGetAnnounceTime_singular_no_hour() {
|
||||
@@ -501,7 +501,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StatusAnnouncerTask#getAnnounceTime(long)} with plural numbers
|
||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with plural numbers
|
||||
* without the hour unit.
|
||||
*/
|
||||
public void testGetAnnounceTime_plural_no_hour() {
|
||||
Reference in New Issue
Block a user