Cleaned up code involving location broadcasts and the location lib
Updates. closes #54 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import com.TwentyCodes.android.LocationRinger.R;
|
||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.services.LocationService;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.SettingsActivity;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
|
||||
/**
|
||||
* This widget will be used to force a Location update from the users home screen
|
||||
@@ -48,7 +49,7 @@ public final String TAG = "GetLocationWidget";
|
||||
|
||||
Intent intent = new Intent(context, LocationService.class)
|
||||
.putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Integer.parseInt(context.getSharedPreferences(SettingsActivity.SETTINGS, Context.MODE_WORLD_READABLE).getString(SettingsActivity.ACCURACY , "50")))
|
||||
.setAction(LocationReceiver.LR_ACTION_UPDATE);
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
|
||||
//create a pending intent to start the post activity
|
||||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
||||
|
||||
@@ -14,21 +14,22 @@ import android.util.Log;
|
||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.services.RingerProcessingService;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.SettingsActivity;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
import com.TwentyCodes.android.location.BaseLocationReceiver;
|
||||
|
||||
/**
|
||||
* This class will receive broadcast from the location service. it will wake the ringer processing service.
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class LocationReceiver extends com.TwentyCodes.android.location.LocationReceiver {
|
||||
public class LocationChangedReceiver extends BaseLocationReceiver {
|
||||
|
||||
public static final String LR_ACTION_UPDATE = "com.TwentyCodes.android.LocationRinger.action.LocationUpdate";
|
||||
private static final String TAG = "LocationReceiver";
|
||||
protected static String TAG = "LocationReceiver";
|
||||
|
||||
@Override
|
||||
public void onLocationUpdate(Location location) {
|
||||
if(location != null)
|
||||
if(location.getAccuracy()<= Integer.parseInt(mContext.getSharedPreferences(SettingsActivity.SETTINGS, Context.MODE_PRIVATE).getString(SettingsActivity.IGNORE_LOCATION, "1000")))
|
||||
mContext.startService(new Intent(mContext, RingerProcessingService.class).putExtra(INTENT_EXTRA_LOCATION_PARCEL, location));
|
||||
mContext.startService(new Intent(mContext, RingerProcessingService.class).putExtra(LocationLibraryConstants.INTENT_EXTRA_LOCATION_CHANGED, location));
|
||||
else
|
||||
if(Debug.DEBUG)
|
||||
Log.d(TAG, "location accuracy = "+ location.getAccuracy()+" ignoring");
|
||||
@@ -6,37 +6,14 @@
|
||||
*/
|
||||
package com.TwentyCodes.android.LocationRinger.receivers;
|
||||
|
||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.services.RingerProcessingService;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.SettingsActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* This class will be used to listen for location updates passively
|
||||
* This class will be used to listen for location updates passively.
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class PassiveLocationChangedReceiver extends com.TwentyCodes.android.location.PassiveLocationChangedReceiver {
|
||||
public class PassiveLocationChangedReceiver extends LocationChangedReceiver {
|
||||
|
||||
private static final String TAG = "PassiveLocationChangedReceiver";
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see com.TwentyCodes.android.location.PassiveLocationChangedReceiver#onLocationUpdate(android.location.Location)
|
||||
*/
|
||||
@Override
|
||||
public void onLocationUpdate(Location location) {
|
||||
if(location != null)
|
||||
if(location.getAccuracy()<= Integer.parseInt(mContext.getSharedPreferences(SettingsActivity.SETTINGS, Context.MODE_PRIVATE).getString(SettingsActivity.IGNORE_LOCATION, "1000")))
|
||||
mContext.startService(new Intent(mContext, RingerProcessingService.class).putExtra(LocationReceiver.INTENT_EXTRA_LOCATION_PARCEL, location));
|
||||
else
|
||||
if(Debug.DEBUG)
|
||||
Log.d(TAG, "location accuracy = "+ location.getAccuracy()+" ignoring");
|
||||
else
|
||||
if(Debug.DEBUG)
|
||||
Log.d(TAG, "location was null");
|
||||
static{
|
||||
TAG = "PassiveLocationChangedReceiver";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import android.util.Log;
|
||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.services.LocationService;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.SettingsActivity;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
import com.TwentyCodes.android.location.PassiveLocationListener;
|
||||
|
||||
/**
|
||||
@@ -45,7 +46,7 @@ public class SystemReceiver extends BroadcastReceiver {
|
||||
Intent i = new Intent(context, LocationService.class)
|
||||
// .putExtra(LocationService.INTENT_EXTRA_PERIOD_BETWEEN_UPDATES, (long) (60000 * Integer.parseInt(context.getSharedPreferences(SettingsActivity.SETTINGS, 2).getString(SettingsActivity.UPDATE_INTVERVAL , "10"))))
|
||||
.putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Integer.parseInt(context.getSharedPreferences(SettingsActivity.SETTINGS, 2).getString(SettingsActivity.ACCURACY , "50")))
|
||||
.setAction(LocationReceiver.LR_ACTION_UPDATE);
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
|
||||
/*
|
||||
* if the phone finishes booting, then start the service if the user enabled it
|
||||
@@ -53,7 +54,7 @@ public class SystemReceiver extends BroadcastReceiver {
|
||||
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
|
||||
if(context.getSharedPreferences(SettingsActivity.SETTINGS, Context.MODE_WORLD_READABLE).getBoolean(SettingsActivity.START_ON_BOOT, false)){
|
||||
context.startService(i);
|
||||
PassiveLocationListener.requestPassiveLocationUpdates(context);
|
||||
PassiveLocationListener.requestPassiveLocationUpdates(context, new Intent(context, PassiveLocationChangedReceiver.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,9 @@ import android.widget.Toast;
|
||||
|
||||
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.receivers.LocationReceiver;
|
||||
import com.TwentyCodes.android.LocationRinger.receivers.LocationChangedReceiver;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.SettingsActivity;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||
import com.TwentyCodes.android.location.GeoUtils;
|
||||
import com.google.android.maps.GeoPoint;
|
||||
@@ -147,7 +148,7 @@ public class RingerProcessingService extends Service {
|
||||
if (values.get(RingerDatabase.KEY_UPDATE_INTERVAL) != null){
|
||||
Intent i = new Intent(this, LocationService.class)
|
||||
.putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Integer.parseInt(this.getSharedPreferences(SettingsActivity.SETTINGS, 2).getString(SettingsActivity.ACCURACY , "50")))
|
||||
.setAction(LocationReceiver.LR_ACTION_UPDATE);
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
PendingIntent pi = PendingIntent.getService(this, LocationService.REQUEST_CODE, i, 0);
|
||||
|
||||
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
@@ -294,8 +295,8 @@ public class RingerProcessingService extends Service {
|
||||
// backup();
|
||||
// }
|
||||
|
||||
if(intent.getParcelableExtra(LocationReceiver.INTENT_EXTRA_LOCATION_PARCEL) != null){
|
||||
this.mLocation = intent.getParcelableExtra(LocationReceiver.INTENT_EXTRA_LOCATION_PARCEL);
|
||||
if(intent.getParcelableExtra(LocationLibraryConstants.INTENT_EXTRA_LOCATION_CHANGED) != null){
|
||||
this.mLocation = intent.getParcelableExtra(LocationLibraryConstants.INTENT_EXTRA_LOCATION_CHANGED);
|
||||
processRingers();
|
||||
}else if(Debug.DEBUG)
|
||||
Log.d(TAG, "Location was null");
|
||||
|
||||
@@ -31,10 +31,12 @@ import android.widget.Toast;
|
||||
import com.TwentyCodes.android.LocationRinger.R;
|
||||
import com.TwentyCodes.android.LocationRinger.db.DatabaseListener;
|
||||
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||
import com.TwentyCodes.android.LocationRinger.receivers.LocationReceiver;
|
||||
import com.TwentyCodes.android.LocationRinger.receivers.LocationChangedReceiver;
|
||||
import com.TwentyCodes.android.LocationRinger.receivers.PassiveLocationChangedReceiver;
|
||||
import com.TwentyCodes.android.LocationRinger.services.LocationService;
|
||||
import com.TwentyCodes.android.SkyHook.SkyHookRegistration;
|
||||
import com.TwentyCodes.android.SkyHook.Splash;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
import com.TwentyCodes.android.location.PassiveLocationListener;
|
||||
import com.skyhookwireless.wps.RegistrationCallback;
|
||||
import com.skyhookwireless.wps.WPSContinuation;
|
||||
@@ -210,7 +212,7 @@ public class ListActivity extends Activity implements OnItemClickListener, OnCli
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
restartService();
|
||||
PassiveLocationListener.requestPassiveLocationUpdates(this);
|
||||
PassiveLocationListener.requestPassiveLocationUpdates(this, new Intent(this, PassiveLocationChangedReceiver.class));
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@@ -334,7 +336,7 @@ public class ListActivity extends Activity implements OnItemClickListener, OnCli
|
||||
//start the new service
|
||||
Intent i = new Intent(this, LocationService.class)
|
||||
.putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Integer.parseInt(this.getSharedPreferences(SettingsActivity.SETTINGS, 2).getString(SettingsActivity.ACCURACY , "50")))
|
||||
.setAction(LocationReceiver.LR_ACTION_UPDATE);
|
||||
.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
|
||||
this.startService(i);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user