aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2011-05-14 14:56:58 +0200
committerHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2011-05-14 15:11:45 +0200
commit32b8a3337978a59b1a4cbc1f70cc294e96dcbe58 (patch)
treeef530d785e5570dee35c255a837121a9f9064d39 /src
parent607f9abfb96d7d421caf91c665cf801849b20bd6 (diff)
downloadBlueGPS-32b8a3337978a59b1a4cbc1f70cc294e96dcbe58.zip
BlueGPS-32b8a3337978a59b1a4cbc1f70cc294e96dcbe58.tar.gz
BlueGPS-32b8a3337978a59b1a4cbc1f70cc294e96dcbe58.tar.bz2
First rebuild for cupcake using backport-android-bluetooth.
Use backport-android-bluetooth (http://code.google.com/p/backport-android-bluetooth/) in order use bluetooth API introduced with Eclair.
Diffstat (limited to 'src')
-rw-r--r--src/backport_android_bluetooth.properties8
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java8
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java4
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java79
-rw-r--r--src/org/broeuschmeul/android/gps/nmea/util/NmeaListener.java12
5 files changed, 95 insertions, 16 deletions
diff --git a/src/backport_android_bluetooth.properties b/src/backport_android_bluetooth.properties
new file mode 100644
index 0000000..72845a9
--- /dev/null
+++ b/src/backport_android_bluetooth.properties
@@ -0,0 +1,8 @@
+#permission_name = ${your package name).PERMISSION_BLUETOOTH
+permission_name = org.broeuschmeul.android.gps.bluetooth.provider.PERMISSION_BLUETOOTH
+
+#request_enable = ${your package name}.action.REQUEST_ENABLE
+request_enable = org.broeuschmeul.android.gps.bluetooth.provider.action.REQUEST_ENABLE
+
+#request_discoverable = ${your package name}.action.REQUEST_DISCOVERABLE
+request_discoverable = org.broeuschmeul.android.gps.bluetooth.provider.action.REQUEST_DISCOVERABLE \ No newline at end of file
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
index 4deba63..d8cf9a0 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
@@ -36,6 +36,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import org.broeuschmeul.android.gps.nmea.util.NmeaListener;
import org.broeuschmeul.android.gps.nmea.util.NmeaParser;
import org.broeuschmeul.android.gps.sirf.util.SirfUtils;
@@ -43,14 +44,13 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothSocket;
+import backport.android.bluetooth.BluetoothAdapter;
+import backport.android.bluetooth.BluetoothDevice;
+import backport.android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.Intent;
import android.location.LocationManager;
-import android.location.GpsStatus.NmeaListener;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.os.SystemClock;
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java
index 885148c..1112ceb 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java
@@ -24,8 +24,8 @@ import java.util.HashSet;
import java.util.Set;
import android.app.AlertDialog;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
+import backport.android.bluetooth.BluetoothAdapter;
+import backport.android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
index 1290344..3570053 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
@@ -31,16 +31,19 @@ import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
+import org.broeuschmeul.android.gps.nmea.util.NmeaListener;
+
import android.app.Notification;
+import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
-import android.bluetooth.BluetoothAdapter;
+import backport.android.bluetooth.BluetoothAdapter;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
-import android.location.GpsStatus.NmeaListener;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
@@ -90,6 +93,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
public static final String PREF_SIRF_ENABLE_NMEA = "enableNMEA";
public static final String PREF_SIRF_ENABLE_STATIC_NAVIGATION = "enableStaticNavigation";
+ private NotificationManager notificationManager = null;
private BlueetoothGpsManager gpsManager = null;
private PrintWriter writer;
private File trackFile;
@@ -99,6 +103,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
@Override
public void onCreate() {
super.onCreate();
+ NotificationManager notificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
toast = Toast.makeText(getApplicationContext(), "NMEA track recording... on", Toast.LENGTH_SHORT);
}
@@ -195,6 +200,58 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
}
}
+ /**
+ * The notification id used to signal that this service runs in the foreground.
+ *
+ * @see #startForeground(int, Notification)
+ * @see #stopForeground(boolean)
+ */
+ private int notificationId = R.string.foreground_gps_provider_started_notification;
+
+
+ private NotificationManager getNotificationManager(){
+ if (notificationManager == null){
+ notificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
+ }
+ return notificationManager;
+ }
+
+ /**
+ * Compatibility (see API 5) method used to run this service in the foreground,
+ * supplying the ongoing notification to be shown to the user while in this state.
+ *
+ * @param id The identifier for this notification as per NotificationManager.notify(int, Notification)
+ * @param notification The Notification to be displayed.
+ *
+ * @see #stopForeground(boolean)
+ */
+ private final void startForeground (int id, Notification notification){
+ NotificationManager notificationManager = this.getNotificationManager();
+ setForeground(true);
+ if (notificationManager != null){
+ notificationManager.notify(notificationId = id, notification);
+ }
+ }
+
+ /**
+ * Compatibility (see API 5) method used to remove this service from foreground state,
+ * allowing it to be killed if more memory is needed.
+ * This method should be called with value false, when the service is destroyed.
+ *
+ * @param removeNotification If true, the notification previously provided
+ * to startForeground(int, Notification) will be removed.
+ * Otherwise it will remain until a later call removes it (or the service is destroyed).
+ *
+ * @see #startForeground(int, Notification)
+ */
+ private final void stopForeground (boolean removeNotification){
+ NotificationManager notificationManager = this.getNotificationManager();
+ if (removeNotification && (notificationManager != null)){
+ notificationManager.cancel(notificationId);
+ }
+ setForeground(false);
+ }
+
private void enableSirfConfig(Bundle extras){
if (extras.containsKey(PREF_SIRF_ENABLE_GGA)){
enableNmeaGGA(extras.getBoolean(PREF_SIRF_ENABLE_GGA, true));
@@ -380,14 +437,15 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
}
}
- /* (non-Javadoc)
- * @see android.app.Service#onStartCommand(android.content.Intent, int, int)
- */
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- onStart(intent, startId);
- return Service.START_NOT_STICKY;
- }
+// This method has been introduced in Eclair
+// /* (non-Javadoc)
+// * @see android.app.Service#onStartCommand(android.content.Intent, int, int)
+// */
+// @Override
+// public int onStartCommand(Intent intent, int flags, int startId) {
+// onStart(intent, startId);
+// return Service.START_NOT_STICKY;
+// }
@Override
public void onDestroy() {
@@ -416,6 +474,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
edit.putBoolean(PREF_START_GPS_PROVIDER,false);
edit.commit();
}
+ stopForeground(true);
super.onDestroy();
}
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaListener.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaListener.java
new file mode 100644
index 0000000..f36a312
--- /dev/null
+++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaListener.java
@@ -0,0 +1,12 @@
+/**
+ *
+ */
+package org.broeuschmeul.android.gps.nmea.util;
+
+/**
+ * @author Herbert von Broeuschmeul
+ *
+ */
+public interface NmeaListener {
+ abstract void onNmeaReceived(long timestamp, String nmea);
+}