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;
|
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 NotificationManager notificationManager;
|
||||||
private LocationManager locationManager;
|
private LocationManager locationManager;
|
||||||
private WakeLock wakeLock;
|
private WakeLock wakeLock;
|
||||||
@@ -1050,7 +1036,8 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
prefManager.setRecordingTrack(recordingTrackId);
|
prefManager.setRecordingTrack(recordingTrackId);
|
||||||
|
|
||||||
// Notify the world that we're now recording.
|
// Notify the world that we're now recording.
|
||||||
sendTrackBroadcast(START_TRACK_ACTION, recordingTrackId);
|
sendTrackBroadcast(
|
||||||
|
R.string.track_started_broadcast_action, recordingTrackId);
|
||||||
|
|
||||||
return recordingTrackId;
|
return recordingTrackId;
|
||||||
}
|
}
|
||||||
@@ -1086,15 +1073,17 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
releaseWakeLock();
|
releaseWakeLock();
|
||||||
|
|
||||||
// Notify the world that we're no longer recording.
|
// 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 =
|
Intent broadcastIntent =
|
||||||
new Intent()
|
new Intent()
|
||||||
.setAction(action)
|
.setAction(getString(actionResId))
|
||||||
.putExtra(TRACK_ID_EXTRA, trackId);
|
.putExtra(getString(R.string.track_id_broadcast_extra), trackId);
|
||||||
sendBroadcast(broadcastIntent, NOTIFICATION_PERMISSION);
|
sendBroadcast(broadcastIntent,
|
||||||
|
getString(R.string.broadcast_notifications_permission));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TripStatistics getTripStatistics() {
|
public TripStatistics getTripStatistics() {
|
||||||
|
|||||||
+10
-14
@@ -364,8 +364,8 @@ public class TrackRecordingServiceTest
|
|||||||
// My Tracks (go figure).
|
// My Tracks (go figure).
|
||||||
// Reference: http://code.google.com/p/android/issues/detail?id=5521
|
// Reference: http://code.google.com/p/android/issues/detail?id=5521
|
||||||
BlockingBroadcastReceiver startReceiver = new BlockingBroadcastReceiver();
|
BlockingBroadcastReceiver startReceiver = new BlockingBroadcastReceiver();
|
||||||
context.registerReceiver(startReceiver,
|
String startAction = context.getString(R.string.track_started_broadcast_action);
|
||||||
new IntentFilter(TrackRecordingService.START_TRACK_ACTION));
|
context.registerReceiver(startReceiver, new IntentFilter(startAction));
|
||||||
|
|
||||||
List<Track> tracks = providerUtils.getAllTracks();
|
List<Track> tracks = providerUtils.getAllTracks();
|
||||||
assertTrue(tracks.isEmpty());
|
assertTrue(tracks.isEmpty());
|
||||||
@@ -388,11 +388,9 @@ public class TrackRecordingServiceTest
|
|||||||
List<Intent> receivedIntents = startReceiver.getReceivedIntents();
|
List<Intent> receivedIntents = startReceiver.getReceivedIntents();
|
||||||
assertEquals(1, receivedIntents.size());
|
assertEquals(1, receivedIntents.size());
|
||||||
Intent broadcastIntent = receivedIntents.get(0);
|
Intent broadcastIntent = receivedIntents.get(0);
|
||||||
assertEquals(
|
assertEquals(startAction, broadcastIntent.getAction());
|
||||||
TrackRecordingService.START_TRACK_ACTION,
|
assertEquals(id, broadcastIntent.getLongExtra(
|
||||||
broadcastIntent.getAction());
|
context.getString(R.string.track_id_broadcast_extra), -1));
|
||||||
assertEquals(id,
|
|
||||||
broadcastIntent.getLongExtra(TrackRecordingService.TRACK_ID_EXTRA, -1));
|
|
||||||
|
|
||||||
context.unregisterReceiver(startReceiver);
|
context.unregisterReceiver(startReceiver);
|
||||||
}
|
}
|
||||||
@@ -419,8 +417,8 @@ public class TrackRecordingServiceTest
|
|||||||
public void testEndCurrentTrack_alreadyRecording() throws Exception {
|
public void testEndCurrentTrack_alreadyRecording() throws Exception {
|
||||||
// See comment above if this fails randomly.
|
// See comment above if this fails randomly.
|
||||||
BlockingBroadcastReceiver stopReceiver = new BlockingBroadcastReceiver();
|
BlockingBroadcastReceiver stopReceiver = new BlockingBroadcastReceiver();
|
||||||
context.registerReceiver(stopReceiver,
|
String stopAction = context.getString(R.string.track_stopped_broadcast_action);
|
||||||
new IntentFilter(TrackRecordingService.STOP_TRACK_ACTION));
|
context.registerReceiver(stopReceiver, new IntentFilter(stopAction));
|
||||||
|
|
||||||
createDummyTrack(123, -1, true);
|
createDummyTrack(123, -1, true);
|
||||||
|
|
||||||
@@ -439,11 +437,9 @@ public class TrackRecordingServiceTest
|
|||||||
List<Intent> receivedIntents = stopReceiver.getReceivedIntents();
|
List<Intent> receivedIntents = stopReceiver.getReceivedIntents();
|
||||||
assertEquals(1, receivedIntents.size());
|
assertEquals(1, receivedIntents.size());
|
||||||
Intent broadcastIntent = receivedIntents.get(0);
|
Intent broadcastIntent = receivedIntents.get(0);
|
||||||
assertEquals(
|
assertEquals(stopAction, broadcastIntent.getAction());
|
||||||
TrackRecordingService.STOP_TRACK_ACTION,
|
assertEquals(123, broadcastIntent.getLongExtra(
|
||||||
broadcastIntent.getAction());
|
context.getString(R.string.track_id_broadcast_extra), -1));
|
||||||
assertEquals(123,
|
|
||||||
broadcastIntent.getLongExtra(TrackRecordingService.TRACK_ID_EXTRA, -1));
|
|
||||||
|
|
||||||
context.unregisterReceiver(stopReceiver);
|
context.unregisterReceiver(stopReceiver);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user