diff --git a/LocationLib/bin/locationlib.jar b/LocationLib/bin/locationlib.jar index 53cfd01..ca2cbd3 100644 Binary files a/LocationLib/bin/locationlib.jar and b/LocationLib/bin/locationlib.jar differ diff --git a/LocationLib/res/layout/base_map_fragment.xml b/LocationLib/res/layout/base_map_fragment.xml index a55b4c5..0c9c29a 100644 --- a/LocationLib/res/layout/base_map_fragment.xml +++ b/LocationLib/res/layout/base_map_fragment.xml @@ -13,7 +13,7 @@ android:id="@+id/mapview" android:layout_width="match_parent" android:layout_height="match_parent" - android:apiKey="0rKmsWMM0D-K15bEM_kwabPbNhsn4dp4rcq2q5Q" /> + android:apiKey="0rKmsWMM0D-LWOndcfwrmW-S0OXlnQl2SJCMeTg" /> -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); } diff --git a/LocationLib/src/com/TwentyCodes/android/debug/Debug.java b/LocationLib/src/com/TwentyCodes/android/debug/Debug.java index f3a9979..f4582fa 100644 --- a/LocationLib/src/com/TwentyCodes/android/debug/Debug.java +++ b/LocationLib/src/com/TwentyCodes/android/debug/Debug.java @@ -1,52 +1,21 @@ /** * Debug.java - * @date Mar 1, 2011 + * @date May 15, 2012 * @author ricky barrette * @author Twenty Codes, LLC */ package com.TwentyCodes.android.debug; -import android.hardware.SensorManager; - /** * This class will be used to enable and disable debugging features * @author ricky barrette */ -public final class Debug { - +public class Debug { + /** * Sets the logging level for this library * @author ricky barrette */ 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; -} \ No newline at end of file +} diff --git a/LocationLib/src/com/TwentyCodes/android/debug/LocationLibraryConstants.java b/LocationLib/src/com/TwentyCodes/android/debug/LocationLibraryConstants.java new file mode 100644 index 0000000..34072af --- /dev/null +++ b/LocationLib/src/com/TwentyCodes/android/debug/LocationLibraryConstants.java @@ -0,0 +1,61 @@ +/** + * LocationLibraryConstants.java + * @date Mar 1, 2011 + * @author ricky barrette + * @author Twenty Codes, LLC + */ +package com.TwentyCodes.android.debug; + +import android.hardware.SensorManager; +import android.location.LocationManager; + +/** + * This class will be used to set the Location Library Constants + * @author ricky barrette + */ +public final class LocationLibraryConstants { + + 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; + } + + /** + * 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; + + public static final String INTENT_ACTION_UPDATE = "TwentyCodes.intent.action.LocationUpdate"; + + public static final String INTENT_EXTRA_LOCATION_CHANGED = LocationManager.KEY_LOCATION_CHANGED; +} \ No newline at end of file diff --git a/LocationLib/src/com/TwentyCodes/android/location/LocationReceiver.java b/LocationLib/src/com/TwentyCodes/android/location/BaseLocationReceiver.java similarity index 58% rename from LocationLib/src/com/TwentyCodes/android/location/LocationReceiver.java rename to LocationLib/src/com/TwentyCodes/android/location/BaseLocationReceiver.java index 79178c3..1a618bb 100644 --- a/LocationLib/src/com/TwentyCodes/android/location/LocationReceiver.java +++ b/LocationLib/src/com/TwentyCodes/android/location/BaseLocationReceiver.java @@ -9,38 +9,32 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.location.Location; +import android.location.LocationManager; /** * this abstract class will be used as a for classes wishing to be a receiver of location updates from the location services * @author ricky barrette */ -public abstract class LocationReceiver extends BroadcastReceiver { +public abstract class BaseLocationReceiver extends BroadcastReceiver { - public static final String INTENT_EXTRA_ACTION_UPDATE = "TwentyCodes.intent.action.LocationUpdate"; - public static final String INTENT_EXTRA_LOCATION_PARCEL = "location_parcel"; public Context mContext; /** * (non-Javadoc) * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent) - * @param contextonBind - * @param intent - * @author ricky barrette */ @Override - public void onReceive(final Context context, final Intent intent) { + public void onReceive(Context context, Intent intent) { mContext = context; - if(intent.getParcelableExtra(INTENT_EXTRA_LOCATION_PARCEL) != null){ - Location location = intent.getParcelableExtra(INTENT_EXTRA_LOCATION_PARCEL); - onLocationUpdate(location); - } + 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); - } \ No newline at end of file diff --git a/LocationLib/src/com/TwentyCodes/android/location/CompassSensor.java b/LocationLib/src/com/TwentyCodes/android/location/CompassSensor.java index 2a8d1ed..8c4fd2c 100644 --- a/LocationLib/src/com/TwentyCodes/android/location/CompassSensor.java +++ b/LocationLib/src/com/TwentyCodes/android/location/CompassSensor.java @@ -21,6 +21,7 @@ import android.view.Surface; import android.view.WindowManager; import com.TwentyCodes.android.debug.Debug; +import com.TwentyCodes.android.debug.LocationLibraryConstants; /** * A simple convince class that accesses the compass sensor on another thread @@ -206,9 +207,9 @@ public class CompassSensor{ @Override public void run() { // 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 - 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(); } diff --git a/LocationLib/src/com/TwentyCodes/android/location/LocationService.java b/LocationLib/src/com/TwentyCodes/android/location/LocationService.java index 43f4304..f903451 100644 --- a/LocationLib/src/com/TwentyCodes/android/location/LocationService.java +++ b/LocationLib/src/com/TwentyCodes/android/location/LocationService.java @@ -14,6 +14,7 @@ import android.content.Context; import android.content.Intent; import android.location.Location; import android.location.LocationListener; +import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -22,6 +23,7 @@ import android.os.PowerManager.WakeLock; import android.util.Log; 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. @@ -47,8 +49,8 @@ public class LocationService extends Service implements LocationListener { public static final String INTENT_EXTRA_REQUIRED_ACCURACY = "required_accuracy"; /** - * Used to tell the service the update action to broadcast. If this is not supplied, {@link LocationReceiver.INTENT_EXTRA_ACTION_UPDATE } will be used. - * @see LocationReceiver.INTENT_EXTRA_ACTION_UPDATE + * Used to tell the service the update action to broadcast. If this is not supplied, {@link BaseLocationReceiver.INTENT_EXTRA_ACTION_UPDATE } will be used. + * @see BaseLocationReceiver.INTENT_EXTRA_ACTION_UPDATE */ public static final String INTENT_EXTRA_ACTION_UPDATE = "action_update"; @@ -94,8 +96,8 @@ public class LocationService extends Service implements LocationListener { if(mIntent.getAction() != null) locationUpdate.setAction(mIntent.getAction()); else - locationUpdate.setAction(LocationReceiver.INTENT_EXTRA_ACTION_UPDATE); - locationUpdate.putExtra(LocationReceiver.INTENT_EXTRA_LOCATION_PARCEL, mLocation); + locationUpdate.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE); + locationUpdate.putExtra(LocationManager.KEY_LOCATION_CHANGED, mLocation); sendBroadcast(locationUpdate); stopSelf(mStartId); } @@ -117,7 +119,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 */ - new Handler().postDelayed(failSafe, Debug.MAX_LOCATION_SERVICE_RUN_TIME); + new Handler().postDelayed(failSafe, LocationLibraryConstants.MAX_LOCATION_SERVICE_RUN_TIME); super.onCreate(); } @@ -229,7 +231,7 @@ public class LocationService extends Service implements LocationListener { if(Debug.DEBUG) Log.d(TAG, "got location +- "+ location.getAccuracy() +"m"); 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); } } diff --git a/LocationLib/src/com/TwentyCodes/android/location/PassiveLocationListener.java b/LocationLib/src/com/TwentyCodes/android/location/PassiveLocationListener.java new file mode 100644 index 0000000..8f5ff10 --- /dev/null +++ b/LocationLib/src/com/TwentyCodes/android/location/PassiveLocationListener.java @@ -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 + * @param receiverIntent + * @author ricky barrette + */ + public static final void requestPassiveLocationUpdates(final Context context, final Intent receiverIntent){ + if (LocationLibraryConstants.SUPPORTS_FROYO) { + final LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + final PendingIntent locationListenerPassivePendingIntent = PendingIntent.getBroadcast(context, 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT); + locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, locationListenerPassivePendingIntent); + } + } +} \ No newline at end of file