Initial commit of the passive location listener
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
Binary file not shown.
@@ -13,7 +13,7 @@
|
|||||||
android:id="@+id/mapview"
|
android:id="@+id/mapview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:apiKey="0rKmsWMM0D-K15bEM_kwabPbNhsn4dp4rcq2q5Q" />
|
android:apiKey="0rKmsWMM0D-LWOndcfwrmW-S0OXlnQl2SJCMeTg" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/mapProgressBar"
|
android:id="@+id/mapProgressBar"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import android.telephony.TelephonyManager;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.TwentyCodes.android.debug.Debug;
|
import com.TwentyCodes.android.debug.Debug;
|
||||||
|
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||||
import com.skyhookwireless.wps.RegistrationCallback;
|
import com.skyhookwireless.wps.RegistrationCallback;
|
||||||
import com.skyhookwireless.wps.WPSAuthentication;
|
import com.skyhookwireless.wps.WPSAuthentication;
|
||||||
import com.skyhookwireless.wps.XPS;
|
import com.skyhookwireless.wps.XPS;
|
||||||
@@ -60,7 +61,7 @@ public class SkyHookRegistration{
|
|||||||
*/
|
*/
|
||||||
public static String getUserName(final Context context){
|
public static String getUserName(final Context context){
|
||||||
|
|
||||||
switch(Debug.DEFAULT_REGISTRATION_BEHAVIOR){
|
switch(LocationLibraryConstants.DEFAULT_REGISTRATION_BEHAVIOR){
|
||||||
case NORMAL:
|
case NORMAL:
|
||||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
if(tm == null)
|
if(tm == null)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import android.os.Handler;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.TwentyCodes.android.debug.Debug;
|
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||||
import com.TwentyCodes.android.location.GeoPointLocationListener;
|
import com.TwentyCodes.android.location.GeoPointLocationListener;
|
||||||
import com.TwentyCodes.android.location.LocationReceiver;
|
import com.TwentyCodes.android.location.LocationReceiver;
|
||||||
import com.google.android.maps.GeoPoint;
|
import com.google.android.maps.GeoPoint;
|
||||||
@@ -121,7 +121,7 @@ public class SkyHookService extends Service implements GeoPointLocationListener,
|
|||||||
public void run(){
|
public void run(){
|
||||||
stopSelfResult(mStartID);
|
stopSelfResult(mStartID);
|
||||||
}
|
}
|
||||||
}, Debug.MAX_LOCATION_SERVICE_RUN_TIME);
|
}, LocationLibraryConstants.MAX_LOCATION_SERVICE_RUN_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,7 +228,7 @@ public class SkyHookService extends Service implements GeoPointLocationListener,
|
|||||||
* then continue
|
* then continue
|
||||||
* else stop to report location
|
* else stop to report location
|
||||||
*/
|
*/
|
||||||
if(accuracy < (this.mRequiredAccuracy > -1 ? this.mRequiredAccuracy : Debug.MINIMUM_REQUIRED_ACCURACY) || Debug.REPORT_FIRST_LOCATION)
|
if(accuracy < (this.mRequiredAccuracy > -1 ? this.mRequiredAccuracy : LocationLibraryConstants.MINIMUM_REQUIRED_ACCURACY) || LocationLibraryConstants.REPORT_FIRST_LOCATION)
|
||||||
this.stopSelf(this.mStartID);
|
this.stopSelf(this.mStartID);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +1,21 @@
|
|||||||
/**
|
/**
|
||||||
* Debug.java
|
* Debug.java
|
||||||
* @date Mar 1, 2011
|
* @date May 15, 2012
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
* @author Twenty Codes, LLC
|
* @author Twenty Codes, LLC
|
||||||
*/
|
*/
|
||||||
package com.TwentyCodes.android.debug;
|
package com.TwentyCodes.android.debug;
|
||||||
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will be used to enable and disable debugging features
|
* This class will be used to enable and disable debugging features
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public final class Debug {
|
public class Debug {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the logging level for this library
|
* Sets the logging level for this library
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the default SkyHook Registration Behavior used by SkyHookRegistration.getUserName()
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public static final SkyHookRegistrationBehavior DEFAULT_REGISTRATION_BEHAVIOR = SkyHookRegistrationBehavior.NORMAL;
|
|
||||||
|
|
||||||
/**
|
}
|
||||||
* Sets the default compass sensor update interval
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public static final int COMPASS_UPDATE_INTERVAL = SensorManager.SENSOR_DELAY_NORMAL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum running time for a single shot location service
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public static final long MAX_LOCATION_SERVICE_RUN_TIME = 60000l;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Forces single shot location services to return the first location
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public static final boolean REPORT_FIRST_LOCATION = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Minimum Required accuracy to report
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public static final int MINIMUM_REQUIRED_ACCURACY = 50;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* Debug.java
|
||||||
|
* @date Mar 1, 2011
|
||||||
|
* @author ricky barrette
|
||||||
|
* @author Twenty Codes, LLC
|
||||||
|
*/
|
||||||
|
package com.TwentyCodes.android.debug;
|
||||||
|
|
||||||
|
import android.hardware.SensorManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class will be used to set the Location Library Constants
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public final class LocationLibraryConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default SkyHook Registration Behavior used by SkyHookRegistration.getUserName()
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static final SkyHookRegistrationBehavior DEFAULT_REGISTRATION_BEHAVIOR = SkyHookRegistrationBehavior.NORMAL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default compass sensor update interval
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static final int COMPASS_UPDATE_INTERVAL = SensorManager.SENSOR_DELAY_NORMAL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum running time for a single shot location service
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static final long MAX_LOCATION_SERVICE_RUN_TIME = 60000l;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces single shot location services to return the first location
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static final boolean REPORT_FIRST_LOCATION = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum Required accuracy to report
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static final int MINIMUM_REQUIRED_ACCURACY = 50;
|
||||||
|
|
||||||
|
public static final boolean SUPPORTS_FROYO;
|
||||||
|
|
||||||
|
public static final boolean SUPPORTS_GINGERBREAD;
|
||||||
|
|
||||||
|
static{
|
||||||
|
SUPPORTS_FROYO = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO;
|
||||||
|
|
||||||
|
SUPPORTS_GINGERBREAD = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ import android.view.Surface;
|
|||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import com.TwentyCodes.android.debug.Debug;
|
import com.TwentyCodes.android.debug.Debug;
|
||||||
|
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple convince class that accesses the compass sensor on another thread
|
* A simple convince class that accesses the compass sensor on another thread
|
||||||
@@ -206,9 +207,9 @@ public class CompassSensor{
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Register this class as a listener for the accelerometer sensor
|
// Register this class as a listener for the accelerometer sensor
|
||||||
mSensorManager.registerListener(mCallBack, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), Debug.COMPASS_UPDATE_INTERVAL);
|
mSensorManager.registerListener(mCallBack, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), LocationLibraryConstants.COMPASS_UPDATE_INTERVAL);
|
||||||
// ...and the orientation sensor
|
// ...and the orientation sensor
|
||||||
mSensorManager.registerListener(mCallBack, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), Debug.COMPASS_UPDATE_INTERVAL);
|
mSensorManager.registerListener(mCallBack, mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD), LocationLibraryConstants.COMPASS_UPDATE_INTERVAL);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.os.PowerManager.WakeLock;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.TwentyCodes.android.debug.Debug;
|
import com.TwentyCodes.android.debug.Debug;
|
||||||
|
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service class will be used broadcast the users location either one time, or periodically.
|
* This service class will be used broadcast the users location either one time, or periodically.
|
||||||
@@ -117,7 +118,7 @@ public class LocationService extends Service implements LocationListener {
|
|||||||
/*
|
/*
|
||||||
* que the fail safe runnable to kill the report location and kill it self after the MAX_RUN_TIME has been meet
|
* que the fail safe runnable to kill the report location and kill it self after the MAX_RUN_TIME has been meet
|
||||||
*/
|
*/
|
||||||
new Handler().postDelayed(failSafe, Debug.MAX_LOCATION_SERVICE_RUN_TIME);
|
new Handler().postDelayed(failSafe, LocationLibraryConstants.MAX_LOCATION_SERVICE_RUN_TIME);
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +230,7 @@ public class LocationService extends Service implements LocationListener {
|
|||||||
if(Debug.DEBUG)
|
if(Debug.DEBUG)
|
||||||
Log.d(TAG, "got location +- "+ location.getAccuracy() +"m");
|
Log.d(TAG, "got location +- "+ location.getAccuracy() +"m");
|
||||||
mLocation = location;
|
mLocation = location;
|
||||||
if(location.getAccuracy() <= (mRequiredAccuracy > -1 ? mRequiredAccuracy : Debug.MINIMUM_REQUIRED_ACCURACY) || Debug.REPORT_FIRST_LOCATION){
|
if(location.getAccuracy() <= (mRequiredAccuracy > -1 ? mRequiredAccuracy : LocationLibraryConstants.MINIMUM_REQUIRED_ACCURACY) || LocationLibraryConstants.REPORT_FIRST_LOCATION){
|
||||||
stopSelf(mStartId);
|
stopSelf(mStartId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
* PassiveLocationChangedReceiver.java
|
||||||
|
* @date May 15, 2012
|
||||||
|
* @author ricky barrette
|
||||||
|
* @author Twenty Codes, LLC
|
||||||
|
*/
|
||||||
|
package com.TwentyCodes.android.location;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public abstract class PassiveLocationChangedReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
protected Context mContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
mContext = context;
|
||||||
|
final String key = LocationManager.KEY_LOCATION_CHANGED;
|
||||||
|
if (intent.hasExtra(key))
|
||||||
|
onLocationUpdate((Location)intent.getExtras().get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* called when a location update is received
|
||||||
|
* @param parcelableExtra
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public abstract void onLocationUpdate(Location location);
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* PassiveLocationListener.java
|
||||||
|
* @date May 15, 2012
|
||||||
|
* @author ricky barrette
|
||||||
|
* @author Twenty Codes, LLC
|
||||||
|
*/
|
||||||
|
package com.TwentyCodes.android.location;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
|
||||||
|
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience class for requesting passive location updates
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public class PassiveLocationListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience method for requesting passive location updates
|
||||||
|
* @param context
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static final void requestPassiveLocationUpdates(final Context context){
|
||||||
|
if (LocationLibraryConstants.SUPPORTS_FROYO) {
|
||||||
|
final LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
final Intent passiveIntent = new Intent(context, PassiveLocationChangedReceiver.class);
|
||||||
|
final PendingIntent locationListenerPassivePendingIntent = PendingIntent.getBroadcast(context, 0, passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, locationListenerPassivePendingIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user