forked from upstream-mirrors/OpenTracks
fix comment on 90eb53c0b4bd
This commit is contained in:
+35
-13
@@ -53,11 +53,6 @@ public class StatusAnnouncerTask implements PeriodicTask {
|
|||||||
*/
|
*/
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
/**
|
|
||||||
* String utilities.
|
|
||||||
*/
|
|
||||||
private final StringUtils stringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface to the text to speech engine.
|
* The interface to the text to speech engine.
|
||||||
*/
|
*/
|
||||||
@@ -93,14 +88,8 @@ public class StatusAnnouncerTask implements PeriodicTask {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public StatusAnnouncerTask(Context context) {
|
public StatusAnnouncerTask(Context context) {
|
||||||
this(context, new StringUtils(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
public StatusAnnouncerTask(Context context, StringUtils stringUtils) {
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.stringUtils = stringUtils;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,7 +195,7 @@ public class StatusAnnouncerTask implements PeriodicTask {
|
|||||||
double pace = 3600000.0 / s;
|
double pace = 3600000.0 / s;
|
||||||
Log.w(Constants.TAG,
|
Log.w(Constants.TAG,
|
||||||
"Converted speed: " + s + " to pace: " + pace);
|
"Converted speed: " + s + " to pace: " + pace);
|
||||||
speed = stringUtils.formatTimeLong((long) pace);
|
speed = getAnnounceTime((long) pace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +205,7 @@ public class StatusAnnouncerTask implements PeriodicTask {
|
|||||||
context.getString(metricUnits
|
context.getString(metricUnits
|
||||||
? R.string.voice_kilometers
|
? R.string.voice_kilometers
|
||||||
: R.string.voice_miles),
|
: R.string.voice_miles),
|
||||||
stringUtils.formatTimeLong(stats.getMovingTime()),
|
getAnnounceTime(stats.getMovingTime()),
|
||||||
speed,
|
speed,
|
||||||
context.getString(speedLabel));
|
context.getString(speedLabel));
|
||||||
}
|
}
|
||||||
@@ -333,4 +322,37 @@ public class StatusAnnouncerTask implements PeriodicTask {
|
|||||||
public static int getVolumeStream() {
|
public static int getVolumeStream() {
|
||||||
return TextToSpeech.Engine.DEFAULT_STREAM;
|
return TextToSpeech.Engine.DEFAULT_STREAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a string to announce the time.
|
||||||
|
*
|
||||||
|
* @param time the time
|
||||||
|
*/
|
||||||
|
private String getAnnounceTime(long time) {
|
||||||
|
int[] parts = StringUtils.getTimeParts(time);
|
||||||
|
String secLabel =
|
||||||
|
context.getString(parts[0] == 1 ? R.string.voice_second : R.string.voice_seconds);
|
||||||
|
String minLabel =
|
||||||
|
context.getString(parts[1] == 1 ? R.string.voice_minute : R.string.voice_minutes);
|
||||||
|
String hourLabel =
|
||||||
|
context.getString(parts[2] == 1 ? R.string.voice_hour : R.string.voice_hours);
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (parts[2] != 0) {
|
||||||
|
sb.append(parts[2]);
|
||||||
|
sb.append(" ");
|
||||||
|
sb.append(hourLabel);
|
||||||
|
sb.append(" ");
|
||||||
|
sb.append(parts[1]);
|
||||||
|
sb.append(minLabel);
|
||||||
|
} else {
|
||||||
|
sb.append(parts[1]);
|
||||||
|
sb.append(" ");
|
||||||
|
sb.append(minLabel);
|
||||||
|
sb.append(" ");
|
||||||
|
sb.append(parts[0]);
|
||||||
|
sb.append(secLabel);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,39 +221,6 @@ public class StringUtils implements DescriptionGenerator {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Formats a time for voice announcement.
|
|
||||||
*
|
|
||||||
* @param time the time
|
|
||||||
*/
|
|
||||||
public String formatTimeLong(long time) {
|
|
||||||
int[] parts = getTimeParts(time);
|
|
||||||
String secLabel =
|
|
||||||
context.getString(parts[0] == 1 ? R.string.voice_second : R.string.voice_seconds);
|
|
||||||
String minLabel =
|
|
||||||
context.getString(parts[1] == 1 ? R.string.voice_minute : R.string.voice_minutes);
|
|
||||||
String hourLabel =
|
|
||||||
context.getString(parts[2] == 1 ? R.string.voice_hour : R.string.voice_hours);
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
if (parts[2] != 0) {
|
|
||||||
sb.append(parts[2]);
|
|
||||||
sb.append(" ");
|
|
||||||
sb.append(hourLabel);
|
|
||||||
sb.append(" ");
|
|
||||||
sb.append(parts[1]);
|
|
||||||
sb.append(minLabel);
|
|
||||||
} else {
|
|
||||||
sb.append(parts[1]);
|
|
||||||
sb.append(" ");
|
|
||||||
sb.append(minLabel);
|
|
||||||
sb.append(" ");
|
|
||||||
sb.append(parts[0]);
|
|
||||||
sb.append(secLabel);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a description for a track (with information about the
|
* Generates a description for a track (with information about the
|
||||||
* statistics).
|
* statistics).
|
||||||
|
|||||||
+27
-31
@@ -20,7 +20,6 @@ import static com.google.android.testing.mocking.AndroidMock.eq;
|
|||||||
import static com.google.android.testing.mocking.AndroidMock.expect;
|
import static com.google.android.testing.mocking.AndroidMock.expect;
|
||||||
import static com.google.android.testing.mocking.AndroidMock.same;
|
import static com.google.android.testing.mocking.AndroidMock.same;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.services.tasks.StatusAnnouncerTask;
|
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
import com.google.android.apps.mytracks.util.StringUtils;
|
import com.google.android.apps.mytracks.util.StringUtils;
|
||||||
import com.google.android.testing.mocking.AndroidMock;
|
import com.google.android.testing.mocking.AndroidMock;
|
||||||
@@ -55,7 +54,6 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
private Locale oldDefaultLocale;
|
private Locale oldDefaultLocale;
|
||||||
|
|
||||||
private StatusAnnouncerTask task;
|
private StatusAnnouncerTask task;
|
||||||
private StringUtils stringUtils;
|
|
||||||
private StatusAnnouncerTask mockTask;
|
private StatusAnnouncerTask mockTask;
|
||||||
private Capture<OnInitListener> initListenerCapture;
|
private Capture<OnInitListener> initListenerCapture;
|
||||||
private Capture<PhoneStateListener> phoneListenerCapture;
|
private Capture<PhoneStateListener> phoneListenerCapture;
|
||||||
@@ -263,7 +261,6 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
|
|
||||||
oldDefaultLocale = Locale.getDefault();
|
oldDefaultLocale = Locale.getDefault();
|
||||||
Locale.setDefault(DEFAULT_LOCALE);
|
Locale.setDefault(DEFAULT_LOCALE);
|
||||||
stringUtils = AndroidMock.createMock(StringUtils.class, getContext());
|
|
||||||
|
|
||||||
// Eww, the effort required just to mock TextToSpeech is insane
|
// Eww, the effort required just to mock TextToSpeech is insane
|
||||||
final AtomicBoolean listenerCalled = new AtomicBoolean();
|
final AtomicBoolean listenerCalled = new AtomicBoolean();
|
||||||
@@ -294,9 +291,8 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
phoneListenerCapture = new Capture<PhoneStateListener>();
|
phoneListenerCapture = new Capture<PhoneStateListener>();
|
||||||
|
|
||||||
// Create a partial forwarding mock
|
// Create a partial forwarding mock
|
||||||
mockTask = AndroidMock.createMock(StatusAnnouncerTask.class,
|
mockTask = AndroidMock.createMock(StatusAnnouncerTask.class, getContext());
|
||||||
getContext(), stringUtils);
|
task = new StatusAnnouncerTask(getContext()) {
|
||||||
task = new StatusAnnouncerTask(getContext(), stringUtils) {
|
|
||||||
@Override
|
@Override
|
||||||
protected TextToSpeech newTextToSpeech(Context ctx,
|
protected TextToSpeech newTextToSpeech(Context ctx,
|
||||||
OnInitListener onInitListener) {
|
OnInitListener onInitListener) {
|
||||||
@@ -333,11 +329,11 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
expect(tts.setSpeechRate(StatusAnnouncerTask.TTS_SPEECH_RATE))
|
expect(tts.setSpeechRate(StatusAnnouncerTask.TTS_SPEECH_RATE))
|
||||||
.andReturn(TextToSpeech.SUCCESS);
|
.andReturn(TextToSpeech.SUCCESS);
|
||||||
|
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
|
|
||||||
ttsInitListener.onInit(TextToSpeech.SUCCESS);
|
ttsInitListener.onInit(TextToSpeech.SUCCESS);
|
||||||
|
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStart_languageNotSupported() {
|
public void testStart_languageNotSupported() {
|
||||||
@@ -352,11 +348,11 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
expect(tts.setSpeechRate(StatusAnnouncerTask.TTS_SPEECH_RATE))
|
expect(tts.setSpeechRate(StatusAnnouncerTask.TTS_SPEECH_RATE))
|
||||||
.andReturn(TextToSpeech.SUCCESS);
|
.andReturn(TextToSpeech.SUCCESS);
|
||||||
|
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
|
|
||||||
ttsInitListener.onInit(TextToSpeech.SUCCESS);
|
ttsInitListener.onInit(TextToSpeech.SUCCESS);
|
||||||
|
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStart_notReady() {
|
public void testStart_notReady() {
|
||||||
@@ -364,11 +360,11 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
OnInitListener ttsInitListener = initListenerCapture.getValue();
|
OnInitListener ttsInitListener = initListenerCapture.getValue();
|
||||||
assertNotNull(ttsInitListener);
|
assertNotNull(ttsInitListener);
|
||||||
|
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
|
|
||||||
ttsInitListener.onInit(TextToSpeech.ERROR);
|
ttsInitListener.onInit(TextToSpeech.ERROR);
|
||||||
|
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShutdown() {
|
public void testShutdown() {
|
||||||
@@ -382,9 +378,9 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
mockTask.listenToPhoneState(
|
mockTask.listenToPhoneState(
|
||||||
same(phoneListener), eq(PhoneStateListener.LISTEN_NONE));
|
same(phoneListener), eq(PhoneStateListener.LISTEN_NONE));
|
||||||
tts.shutdown();
|
tts.shutdown();
|
||||||
AndroidMock.replay(mockTask, tts, stringUtils);
|
AndroidMock.replay(mockTask, tts);
|
||||||
task.shutdown();
|
task.shutdown();
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRun() throws Exception {
|
public void testRun() throws Exception {
|
||||||
@@ -404,9 +400,9 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
.andReturn(TextToSpeech.SUCCESS);
|
.andReturn(TextToSpeech.SUCCESS);
|
||||||
|
|
||||||
// Run the announcement
|
// Run the announcement
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
task.runWithStatistics(stats);
|
task.runWithStatistics(stats);
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRun_notReady() throws Exception {
|
public void testRun_notReady() throws Exception {
|
||||||
@@ -414,9 +410,9 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
startTask(TextToSpeech.ERROR);
|
startTask(TextToSpeech.ERROR);
|
||||||
|
|
||||||
// Run the announcement
|
// Run the announcement
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
task.runWithStatistics(null);
|
task.runWithStatistics(null);
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRun_duringCall() throws Exception {
|
public void testRun_duringCall() throws Exception {
|
||||||
@@ -425,11 +421,11 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
expect(tts.isSpeaking()).andStubReturn(false);
|
expect(tts.isSpeaking()).andStubReturn(false);
|
||||||
|
|
||||||
// Run the announcement
|
// Run the announcement
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
||||||
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, null);
|
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, null);
|
||||||
task.runWithStatistics(null);
|
task.runWithStatistics(null);
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRun_ringWhileSpeaking() throws Exception {
|
public void testRun_ringWhileSpeaking() throws Exception {
|
||||||
@@ -438,7 +434,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
expect(tts.isSpeaking()).andStubReturn(true);
|
expect(tts.isSpeaking()).andStubReturn(true);
|
||||||
expect(tts.stop()).andReturn(TextToSpeech.SUCCESS);
|
expect(tts.stop()).andReturn(TextToSpeech.SUCCESS);
|
||||||
|
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
|
|
||||||
// Update the state to ringing - this should stop the current announcement.
|
// Update the state to ringing - this should stop the current announcement.
|
||||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
||||||
@@ -447,7 +443,7 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
// Run the announcement - this should do nothing.
|
// Run the announcement - this should do nothing.
|
||||||
task.runWithStatistics(null);
|
task.runWithStatistics(null);
|
||||||
|
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRun_whileRinging() throws Exception {
|
public void testRun_whileRinging() throws Exception {
|
||||||
@@ -456,20 +452,20 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
expect(tts.isSpeaking()).andStubReturn(false);
|
expect(tts.isSpeaking()).andStubReturn(false);
|
||||||
|
|
||||||
// Run the announcement
|
// Run the announcement
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
||||||
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);
|
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);
|
||||||
task.runWithStatistics(null);
|
task.runWithStatistics(null);
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRun_noService() throws Exception {
|
public void testRun_noService() throws Exception {
|
||||||
startTask(TextToSpeech.SUCCESS);
|
startTask(TextToSpeech.SUCCESS);
|
||||||
|
|
||||||
// Run the announcement
|
// Run the announcement
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
task.run(null);
|
task.run(null);
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRun_noStats() throws Exception {
|
public void testRun_noStats() throws Exception {
|
||||||
@@ -478,18 +474,18 @@ public class StatusAnnouncerTaskTest extends AndroidTestCase {
|
|||||||
startTask(TextToSpeech.SUCCESS);
|
startTask(TextToSpeech.SUCCESS);
|
||||||
|
|
||||||
// Run the announcement
|
// Run the announcement
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
task.runWithStatistics(null);
|
task.runWithStatistics(null);
|
||||||
AndroidMock.verify(mockTask, tts, stringUtils);
|
AndroidMock.verify(mockTask, tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startTask(int state) {
|
private void startTask(int state) {
|
||||||
AndroidMock.resetToNice(tts, stringUtils);
|
AndroidMock.resetToNice(tts);
|
||||||
AndroidMock.replay(tts, stringUtils);
|
AndroidMock.replay(tts);
|
||||||
doStart();
|
doStart();
|
||||||
OnInitListener ttsInitListener = initListenerCapture.getValue();
|
OnInitListener ttsInitListener = initListenerCapture.getValue();
|
||||||
ttsInitListener.onInit(state);
|
ttsInitListener.onInit(state);
|
||||||
AndroidMock.resetToDefault(tts, stringUtils);
|
AndroidMock.resetToDefault(tts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doStart() {
|
private void doStart() {
|
||||||
|
|||||||
Reference in New Issue
Block a user