diff options
author | Herbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com> | 2010-09-29 03:46:45 +0200 |
---|---|---|
committer | Herbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com> | 2010-09-29 03:46:45 +0200 |
commit | d27afafe7ff64e36191c45dbd2fb926697dc014c (patch) | |
tree | e019f31f59935d3e17b380e7340a4b4999f5e5f6 | |
parent | 044b33e8e83e28b002449c1f785bb161196a6864 (diff) | |
download | BlueGPS-d27afafe7ff64e36191c45dbd2fb926697dc014c.zip BlueGPS-d27afafe7ff64e36191c45dbd2fb926697dc014c.tar.gz BlueGPS-d27afafe7ff64e36191c45dbd2fb926697dc014c.tar.bz2 |
Correction of a bug and notification improvement
merge commit 605e2c6f59105c9bd9f7b4d23230e837b3041a89
made for version 1.1 in the master branch
-rw-r--r-- | res/values/strings.xml | 12 | ||||
-rw-r--r-- | src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java | 63 |
2 files changed, 64 insertions, 11 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index 046197f..3bec3f7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -65,8 +65,6 @@ <string name="pref_replace_std_gps_key">replaceStdtGps</string>
<string name="pref_mock_gps_name_key">mockGpsName</string>
<string name="pref_recording_key">trackRecording</string>
- <string name="pref_mindistance_key">trackMinDistance</string>
- <string name="pref_mintime_key">trackMinTime</string>
<string name="pref_trackfile_directory_key">trackFileDirectory</string>
<string name="pref_trackfile_prefix_key">trackFilePrefix</string>
<string name="pref_bluetooth_device_key">bluetoothDevice</string>
@@ -155,4 +153,14 @@ <string name="foreground_service_started_notification_title">BlueGps</string>
<string name="foreground_gps_provider_started_notification">BlueGps service started</string>
<string name="foreground_nmea_recording_started_notification">BlueGps NMEA recording service started</string>
+ <string name="connection_problem_notification_title">BlueGps connection problem</string>
+ <plurals name="connection_problem_notification">
+ <item quantity="one">will retry one more time</item>
+ <item quantity="other">will retry %d more times</item>
+ </plurals>
+ <!--
+ <string name="connection_problem_notification">Have tried %d times - will retry %d more times</string>
+ -->
+ <string name="service_closed_because_connection_problem_notification_title">BlueGps stopped</string>
+ <string name="service_closed_because_connection_problem_notification">Reason: too many connection problems</string>
</resources>
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index 0a1f67f..fc97751 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -39,11 +39,15 @@ import java.util.concurrent.TimeUnit; import org.broeuschmeul.android.gps.nmea.util.NmeaParser;
import org.broeuschmeul.android.gps.sirf.util.SirfUtils;
+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 android.content.Context;
+import android.content.Intent;
import android.location.LocationManager;
import android.location.GpsStatus.NmeaListener;
import android.os.SystemClock;
@@ -149,22 +153,44 @@ public class BlueetoothGpsManager { private List<NmeaListener> nmeaListeners = Collections.synchronizedList(new LinkedList<NmeaListener>());
private LocationManager locationManager;
private ConnectedGps connectedGps;
+ private Notification connectionProblemNotification;
+ private Notification serviceStoppedNotification;
+ private Context appContext;
+ private NotificationManager notificationManager;
- /**
- * @return true if the bluetooth GPS is enabled
- */
- public synchronized boolean isEnabled() {
- return enabled;
- }
-
public BlueetoothGpsManager(Service callingService, String deviceAddress) {
this.gpsDeviceAddress = deviceAddress;
this.callingService = callingService;
+ this.appContext = callingService.getApplicationContext();
locationManager = (LocationManager)callingService.getSystemService(Context.LOCATION_SERVICE);
+ notificationManager = (NotificationManager)callingService.getSystemService(Context.NOTIFICATION_SERVICE);
parser.setLocationManager(locationManager);
+
+ connectionProblemNotification = new Notification();
+ connectionProblemNotification.icon = R.drawable.icon;
+ Intent stopIntent = new Intent(BluetoothGpsProviderService.ACTION_STOP_GPS_PROVIDER);
+ // PendingIntent stopPendingIntent = PendingIntent.getService(appContext, 0, stopIntent, PendingIntent.FLAG_CANCEL_CURRENT);
+ PendingIntent stopPendingIntent = PendingIntent.getService(appContext, 0, stopIntent, 0);
+ connectionProblemNotification.contentIntent = stopPendingIntent;
+
+ serviceStoppedNotification = new Notification();
+ serviceStoppedNotification.icon=R.drawable.icon;
+ Intent restartIntent = new Intent(BluetoothGpsProviderService.ACTION_START_GPS_PROVIDER);
+ PendingIntent restartPendingIntent = PendingIntent.getService(appContext, 0, restartIntent, PendingIntent.FLAG_CANCEL_CURRENT);
+ serviceStoppedNotification.setLatestEventInfo(appContext, appContext.getString(R.string.service_closed_because_connection_problem_notification_title), appContext.getString(R.string.service_closed_because_connection_problem_notification_title), restartPendingIntent);
+
+
+ }
+
+ /**
+ * @return true if the bluetooth GPS is enabled
+ */
+ public synchronized boolean isEnabled() {
+ return enabled;
}
public synchronized boolean enable() {
+ notificationManager.cancel(R.string.service_closed_because_connection_problem_notification_title);
if (! enabled){
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
@@ -219,16 +245,33 @@ public class BlueetoothGpsManager { gpsSocket.connect();
// connection obtained so reset the number of connection try
connectionTry=0;
+ notificationManager.cancel(R.string.connection_problem_notification_title);
connectedGps = new ConnectedGps(gpsSocket);
connectionAndReadingPool.execute(connectedGps);
}
} catch (IOException connectException) {
- // Unable to connect; close everything and get out
+ // Unable to connect
Log.e("BT test", "error while connecting to socket", connectException);
} finally {
+ if (connectionTry > 0)
+ {
+ // Unable to connect
+ Log.e("BT test", "Unable to establish connection");
+ connectionProblemNotification.when = System.currentTimeMillis();
+ String pbMessage = appContext.getResources().getQuantityString(R.plurals.connection_problem_notification, 5-connectionTry, 5-connectionTry);
+ connectionProblemNotification.setLatestEventInfo(appContext,
+ appContext.getString(R.string.connection_problem_notification_title),
+ pbMessage,
+ connectionProblemNotification.contentIntent);
+ connectionProblemNotification.number = connectionTry;
+ notificationManager.notify(R.string.connection_problem_notification_title, connectionProblemNotification);
+ }
// if bluetooth has bean disabled or
// if two much tries consider that we are enable to connect. So close everything and get out
- if ((!bluetoothAdapter.isEnabled()) || (connectionTry > 5 )){
+ if ((!bluetoothAdapter.isEnabled()) || (connectionTry >= 5 )){
+ notificationManager.cancel(R.string.connection_problem_notification_title);
+ serviceStoppedNotification.when = System.currentTimeMillis();
+ notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification);
disable();
}
}
@@ -258,6 +301,8 @@ public class BlueetoothGpsManager { nmeaListeners.clear();
disableMockLocationProvider();
notificationPool.shutdown();
+ connectionAndReadingPool.shutdown();
+ notificationManager.cancel(R.string.connection_problem_notification_title);
callingService.stopSelf();
}
}
|