Catch number format exception (fix #21)

Этот коммит содержится в:
Anton Tananaev
2013-03-19 22:30:39 +13:00
родитель 27a6b7a3cc
Коммит 716072286e
+33 -22
Просмотреть файл
@@ -27,12 +27,15 @@ import android.location.LocationProvider;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log;
/** /**
* Background service * Background service
*/ */
public class TraccarService extends Service { public class TraccarService extends Service {
public static final String LOG_TAG = "Traccar.TraccarService";
private String id; private String id;
private String address; private String address;
private int port; private int port;
@@ -54,11 +57,15 @@ public class TraccarService extends Service {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
id = sharedPreferences.getString(TraccarActivity.KEY_ID, null); try {
address = sharedPreferences.getString(TraccarActivity.KEY_ADDRESS, null); id = sharedPreferences.getString(TraccarActivity.KEY_ID, null);
port = Integer.valueOf(sharedPreferences.getString(TraccarActivity.KEY_PORT, null)); address = sharedPreferences.getString(TraccarActivity.KEY_ADDRESS, null);
interval = Integer.valueOf(sharedPreferences.getString(TraccarActivity.KEY_INTERVAL, null)); provider = sharedPreferences.getString(TraccarActivity.KEY_PROVIDER, null);
provider = sharedPreferences.getString(TraccarActivity.KEY_PROVIDER, null); port = Integer.valueOf(sharedPreferences.getString(TraccarActivity.KEY_PORT, null));
interval = Integer.valueOf(sharedPreferences.getString(TraccarActivity.KEY_INTERVAL, null));
} catch (Exception error) {
Log.w(LOG_TAG, error);
}
clientController = new ClientController(this, address, port, Protocol.createLoginMessage(id)); clientController = new ClientController(this, address, port, Protocol.createLoginMessage(id));
clientController.start(); clientController.start();
@@ -121,23 +128,27 @@ public class TraccarService extends Service {
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
StatusActivity.addMessage(getString(R.string.status_preference_update)); StatusActivity.addMessage(getString(R.string.status_preference_update));
if (key.equals(TraccarActivity.KEY_ADDRESS)) { try {
address = sharedPreferences.getString(TraccarActivity.KEY_ADDRESS, null); if (key.equals(TraccarActivity.KEY_ADDRESS)) {
clientController.setNewServer(address, port); address = sharedPreferences.getString(TraccarActivity.KEY_ADDRESS, null);
} else if (key.equals(TraccarActivity.KEY_PORT)) { clientController.setNewServer(address, port);
port = Integer.valueOf(sharedPreferences.getString(TraccarActivity.KEY_PORT, null)); } else if (key.equals(TraccarActivity.KEY_PORT)) {
clientController.setNewServer(address, port); port = Integer.valueOf(sharedPreferences.getString(TraccarActivity.KEY_PORT, null));
} else if (key.equals(TraccarActivity.KEY_INTERVAL)) { clientController.setNewServer(address, port);
interval = Integer.valueOf(sharedPreferences.getString(TraccarActivity.KEY_INTERVAL, null)); } else if (key.equals(TraccarActivity.KEY_INTERVAL)) {
locationManager.removeUpdates(locationListener); interval = Integer.valueOf(sharedPreferences.getString(TraccarActivity.KEY_INTERVAL, null));
locationManager.requestLocationUpdates(provider, interval * 1000, 0, locationListener); locationManager.removeUpdates(locationListener);
} else if (key.equals(TraccarActivity.KEY_ID)) { locationManager.requestLocationUpdates(provider, interval * 1000, 0, locationListener);
id = sharedPreferences.getString(TraccarActivity.KEY_ID, null); } else if (key.equals(TraccarActivity.KEY_ID)) {
clientController.setNewLogin(Protocol.createLoginMessage(id)); id = sharedPreferences.getString(TraccarActivity.KEY_ID, null);
} else if (key.equals(TraccarActivity.KEY_PROVIDER)) { clientController.setNewLogin(Protocol.createLoginMessage(id));
provider = sharedPreferences.getString(TraccarActivity.KEY_PROVIDER, null); } else if (key.equals(TraccarActivity.KEY_PROVIDER)) {
locationManager.removeUpdates(locationListener); provider = sharedPreferences.getString(TraccarActivity.KEY_PROVIDER, null);
locationManager.requestLocationUpdates(provider, interval * 1000, 0, locationListener); locationManager.removeUpdates(locationListener);
locationManager.requestLocationUpdates(provider, interval * 1000, 0, locationListener);
}
} catch (Exception error) {
Log.w(LOG_TAG, error);
} }
} }