diff --git a/LocationLib/bin/locationlib.jar b/LocationLib/bin/locationlib.jar index 53cfd01..f886d68 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..3552e2c --- /dev/null +++ b/LocationLib/src/com/TwentyCodes/android/debug/LocationLibraryConstants.java @@ -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; + } +} \ 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..3ebb8a6 100644 --- a/LocationLib/src/com/TwentyCodes/android/location/LocationService.java +++ b/LocationLib/src/com/TwentyCodes/android/location/LocationService.java @@ -22,6 +22,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. @@ -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 */ - new Handler().postDelayed(failSafe, Debug.MAX_LOCATION_SERVICE_RUN_TIME); + new Handler().postDelayed(failSafe, LocationLibraryConstants.MAX_LOCATION_SERVICE_RUN_TIME); super.onCreate(); } @@ -229,7 +230,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/PassiveLocationChangedReceiver.java b/LocationLib/src/com/TwentyCodes/android/location/PassiveLocationChangedReceiver.java new file mode 100644 index 0000000..19f18cb --- /dev/null +++ b/LocationLib/src/com/TwentyCodes/android/location/PassiveLocationChangedReceiver.java @@ -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); +} \ No newline at end of file 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..91311f7 --- /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 + * @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); + } + } +} \ No newline at end of file