From 32b8a3337978a59b1a4cbc1f70cc294e96dcbe58 Mon Sep 17 00:00:00 2001 From: Herbert von Broeuschmeul Date: Sat, 14 May 2011 14:56:58 +0200 Subject: 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. --- .classpath | 1 + .project | 2 +- AndroidManifest.xml | 65 ++++++++++++++++- default.properties | 2 +- lib/backport-android-bluetooth2.jar | Bin 0 -> 87513 bytes src/backport_android_bluetooth.properties | 8 +++ .../bluetooth/provider/BlueetoothGpsManager.java | 8 +-- .../bluetooth/provider/BluetoothGpsActivity.java | 4 +- .../provider/BluetoothGpsProviderService.java | 79 ++++++++++++++++++--- .../android/gps/nmea/util/NmeaListener.java | 12 ++++ 10 files changed, 161 insertions(+), 20 deletions(-) create mode 100644 lib/backport-android-bluetooth2.jar create mode 100644 src/backport_android_bluetooth.properties create mode 100644 src/org/broeuschmeul/android/gps/nmea/util/NmeaListener.java diff --git a/.classpath b/.classpath index 6e9239f..8c3593d 100644 --- a/.classpath +++ b/.classpath @@ -3,5 +3,6 @@ + diff --git a/.project b/.project index 3b27c42..5b798e0 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - AndroidBluetoothGpsProvider + AndroidBlueGps4Cupcake diff --git a/AndroidManifest.xml b/AndroidManifest.xml index d306f52..81400f3 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -55,7 +55,69 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -63,5 +125,4 @@ - diff --git a/default.properties b/default.properties index dbf05f2..4513a1e 100644 --- a/default.properties +++ b/default.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-5 +target=android-3 diff --git a/lib/backport-android-bluetooth2.jar b/lib/backport-android-bluetooth2.jar new file mode 100644 index 0000000..367dca1 Binary files /dev/null and b/lib/backport-android-bluetooth2.jar differ 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); +} -- cgit v1.1