Merge branch 'feature/#53'

This commit is contained in:
2012-05-16 10:47:05 -04:00
10 changed files with 130 additions and 66 deletions

Binary file not shown.

View File

@@ -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" />
<ProgressBar
android:id="@+id/mapProgressBar"

View File

@@ -10,6 +10,7 @@ import android.telephony.TelephonyManager;
import android.util.Log;
import com.TwentyCodes.android.debug.Debug;
import com.TwentyCodes.android.debug.LocationLibraryConstants;
import com.skyhookwireless.wps.RegistrationCallback;
import com.skyhookwireless.wps.WPSAuthentication;
import com.skyhookwireless.wps.XPS;
@@ -60,7 +61,7 @@ public class SkyHookRegistration{
*/
public static String getUserName(final Context context){
switch(Debug.DEFAULT_REGISTRATION_BEHAVIOR){
switch(LocationLibraryConstants.DEFAULT_REGISTRATION_BEHAVIOR){
case NORMAL:
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if(tm == null)

View File

@@ -13,13 +13,14 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Handler;
import android.os.IBinder;
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.LocationReceiver;
import com.TwentyCodes.android.location.BaseLocationReceiver;
import com.google.android.maps.GeoPoint;
import com.skyhookwireless.wps.RegistrationCallback;
import com.skyhookwireless.wps.WPSContinuation;
@@ -49,8 +50,8 @@ public class SkyHookService extends Service implements GeoPointLocationListener,
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";
@@ -75,8 +76,8 @@ public class SkyHookService extends Service implements GeoPointLocationListener,
if(mIntent.getAction() != null)
locationUpdate.setAction(mIntent.getAction());
else
locationUpdate.setAction(LocationReceiver.INTENT_EXTRA_ACTION_UPDATE);
locationUpdate.putExtra(LocationReceiver.INTENT_EXTRA_LOCATION_PARCEL, convertLocation());
locationUpdate.setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE);
locationUpdate.putExtra(LocationManager.KEY_LOCATION_CHANGED, convertLocation());
sendBroadcast(locationUpdate);
}
}
@@ -121,7 +122,7 @@ public class SkyHookService extends Service implements GeoPointLocationListener,
public void run(){
stopSelfResult(mStartID);
}
}, Debug.MAX_LOCATION_SERVICE_RUN_TIME);
}, LocationLibraryConstants.MAX_LOCATION_SERVICE_RUN_TIME);
}
/**
@@ -228,7 +229,7 @@ public class SkyHookService extends Service implements GeoPointLocationListener,
* then continue
* 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);
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}
}