forked from upstream-mirrors/OpenTracks
Moving intent constants to XML file.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<resources>
|
||||
<!-- Permissions -->
|
||||
<!-- This must be kept in sync with AndroidManifest.xml (we can't reference it there) -->
|
||||
<string name="broadcast_notifications_permission">com.google.android.apps.mytracks.TRACK_NOTIFICATIONS</string>
|
||||
<string name="read_track_data_permission">com.google.android.apps.mytracks.READ_TRACK_DATA</string>
|
||||
<string name="write_track_data_permission">com.google.android.apps.mytracks.WRITE_TRACK_DATA</string>
|
||||
|
||||
<!-- Broadcast notification Intent constants -->
|
||||
<string name="track_started_broadcast_action">com.google.android.apps.mytracks.TRACK_STARTED</string>
|
||||
<string name="track_paused_broadcast_action">com.google.android.apps.mytracks.TRACK_PAUSED</string>
|
||||
<string name="track_resumed_broadcast_action">com.google.android.apps.mytracks.TRACK_RESUMED</string>
|
||||
<string name="track_stopped_broadcast_action">com.google.android.apps.mytracks.TRACK_STOPPED</string>
|
||||
<string name="track_id_broadcast_extra">com.google.android.apps.mytracks.TRACK_ID</string>
|
||||
</resources>
|
||||
@@ -70,20 +70,6 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
|
||||
static final int MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS = 3;
|
||||
|
||||
// Broadcast-related constants.
|
||||
static final String NOTIFICATION_PERMISSION =
|
||||
"com.google.android.apps.mytracks.TRACK_NOTIFICATIONS";
|
||||
static final String START_TRACK_ACTION =
|
||||
"com.google.android.apps.mytracks.TRACK_STARTED";
|
||||
static final String PAUSE_TRACK_ACTION =
|
||||
"com.google.android.apps.mytracks.TRACK_PAUSED";
|
||||
static final String RESUME_TRACK_ACTION =
|
||||
"com.google.android.apps.mytracks.TRACK_RESUMED";
|
||||
static final String STOP_TRACK_ACTION =
|
||||
"com.google.android.apps.mytracks.TRACK_STOPPED";
|
||||
static final String TRACK_ID_EXTRA =
|
||||
"com.google.android.apps.mytracks.TRACK_ID";
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private LocationManager locationManager;
|
||||
private WakeLock wakeLock;
|
||||
@@ -1017,7 +1003,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
if (recordingTrackId != -1 || isRecording) {
|
||||
throw new IllegalStateException("A track is already in progress!");
|
||||
}
|
||||
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
acquireWakeLock();
|
||||
|
||||
@@ -1050,7 +1036,8 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
prefManager.setRecordingTrack(recordingTrackId);
|
||||
|
||||
// Notify the world that we're now recording.
|
||||
sendTrackBroadcast(START_TRACK_ACTION, recordingTrackId);
|
||||
sendTrackBroadcast(
|
||||
R.string.track_started_broadcast_action, recordingTrackId);
|
||||
|
||||
return recordingTrackId;
|
||||
}
|
||||
@@ -1086,15 +1073,17 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
releaseWakeLock();
|
||||
|
||||
// Notify the world that we're no longer recording.
|
||||
sendTrackBroadcast(STOP_TRACK_ACTION, recordedTrackId);
|
||||
sendTrackBroadcast(
|
||||
R.string.track_stopped_broadcast_action, recordedTrackId);
|
||||
}
|
||||
|
||||
private void sendTrackBroadcast(String action, long trackId) {
|
||||
private void sendTrackBroadcast(int actionResId, long trackId) {
|
||||
Intent broadcastIntent =
|
||||
new Intent()
|
||||
.setAction(action)
|
||||
.putExtra(TRACK_ID_EXTRA, trackId);
|
||||
sendBroadcast(broadcastIntent, NOTIFICATION_PERMISSION);
|
||||
.setAction(getString(actionResId))
|
||||
.putExtra(getString(R.string.track_id_broadcast_extra), trackId);
|
||||
sendBroadcast(broadcastIntent,
|
||||
getString(R.string.broadcast_notifications_permission));
|
||||
}
|
||||
|
||||
public TripStatistics getTripStatistics() {
|
||||
|
||||
+10
-14
@@ -364,8 +364,8 @@ public class TrackRecordingServiceTest
|
||||
// My Tracks (go figure).
|
||||
// Reference: http://code.google.com/p/android/issues/detail?id=5521
|
||||
BlockingBroadcastReceiver startReceiver = new BlockingBroadcastReceiver();
|
||||
context.registerReceiver(startReceiver,
|
||||
new IntentFilter(TrackRecordingService.START_TRACK_ACTION));
|
||||
String startAction = context.getString(R.string.track_started_broadcast_action);
|
||||
context.registerReceiver(startReceiver, new IntentFilter(startAction));
|
||||
|
||||
List<Track> tracks = providerUtils.getAllTracks();
|
||||
assertTrue(tracks.isEmpty());
|
||||
@@ -388,11 +388,9 @@ public class TrackRecordingServiceTest
|
||||
List<Intent> receivedIntents = startReceiver.getReceivedIntents();
|
||||
assertEquals(1, receivedIntents.size());
|
||||
Intent broadcastIntent = receivedIntents.get(0);
|
||||
assertEquals(
|
||||
TrackRecordingService.START_TRACK_ACTION,
|
||||
broadcastIntent.getAction());
|
||||
assertEquals(id,
|
||||
broadcastIntent.getLongExtra(TrackRecordingService.TRACK_ID_EXTRA, -1));
|
||||
assertEquals(startAction, broadcastIntent.getAction());
|
||||
assertEquals(id, broadcastIntent.getLongExtra(
|
||||
context.getString(R.string.track_id_broadcast_extra), -1));
|
||||
|
||||
context.unregisterReceiver(startReceiver);
|
||||
}
|
||||
@@ -419,8 +417,8 @@ public class TrackRecordingServiceTest
|
||||
public void testEndCurrentTrack_alreadyRecording() throws Exception {
|
||||
// See comment above if this fails randomly.
|
||||
BlockingBroadcastReceiver stopReceiver = new BlockingBroadcastReceiver();
|
||||
context.registerReceiver(stopReceiver,
|
||||
new IntentFilter(TrackRecordingService.STOP_TRACK_ACTION));
|
||||
String stopAction = context.getString(R.string.track_stopped_broadcast_action);
|
||||
context.registerReceiver(stopReceiver, new IntentFilter(stopAction));
|
||||
|
||||
createDummyTrack(123, -1, true);
|
||||
|
||||
@@ -439,11 +437,9 @@ public class TrackRecordingServiceTest
|
||||
List<Intent> receivedIntents = stopReceiver.getReceivedIntents();
|
||||
assertEquals(1, receivedIntents.size());
|
||||
Intent broadcastIntent = receivedIntents.get(0);
|
||||
assertEquals(
|
||||
TrackRecordingService.STOP_TRACK_ACTION,
|
||||
broadcastIntent.getAction());
|
||||
assertEquals(123,
|
||||
broadcastIntent.getLongExtra(TrackRecordingService.TRACK_ID_EXTRA, -1));
|
||||
assertEquals(stopAction, broadcastIntent.getAction());
|
||||
assertEquals(123, broadcastIntent.getLongExtra(
|
||||
context.getString(R.string.track_id_broadcast_extra), -1));
|
||||
|
||||
context.unregisterReceiver(stopReceiver);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user