diff options
author | Cameron Mace <cameron@mapbox.com> | 2016-12-16 16:19:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-16 16:19:15 -0500 |
commit | 20b958301eb208fe9ed0ae8edfb14b6f3741d8f2 (patch) | |
tree | 94ae0ce250cda159be13f9a21cc70c92d4908974 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location | |
parent | f95b4838ea816b9da0c151a953a1f98f97c79a39 (diff) | |
download | qtlocation-mapboxgl-20b958301eb208fe9ed0ae8edfb14b6f3741d8f2.tar.gz |
Adds checkstyle to CI (#7442)
* adds checkstyle to CI
* fixed gradlew path
* resolved testapp checkstyle violations
* added back mapboxMap variable for test
* checkstyle annotations
* checkstyle SDK round 1
* maps package checkstyle
* rest of SDK checkstyle
* checkstyle gesture library
* checkstyle test
* finished rest of test checkstyle
* resolved all checkstyle errors
* fixed class name
* removed old test file
* fixed camera postion test
* fixed native crash
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location')
2 files changed, 156 insertions, 149 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationListener.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationListener.java index eb8c4100dc..7d86d8b096 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationListener.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationListener.java @@ -7,10 +7,11 @@ import android.location.Location; */ public interface LocationListener { - /** - * Callback method for receiving location updates from LocationServices. - * @param location The new Location data - */ - void onLocationChanged(Location location); + /** + * Callback method for receiving location updates from LocationServices. + * + * @param location The new Location data + */ + void onLocationChanged(Location location); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java index 6b8cdd1b76..666dcb565f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationServices.java @@ -8,6 +8,7 @@ import android.location.Location; import android.location.LocationManager; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; + import timber.log.Timber; import com.mapbox.mapboxsdk.telemetry.TelemetryLocationReceiver; @@ -19,169 +20,174 @@ import java.util.concurrent.CopyOnWriteArrayList; /** * Manages locational updates. Contains methods to register and unregister location listeners. * <ul> - * <li>You can register a {@link LocationListener} with {@link #addLocationListener(LocationListener)} to receive location updates.</li> + * <li>You can register a {@link LocationListener} with {@link #addLocationListener(LocationListener)} to receive + * location updates.</li> * <li> You can unregister a {@link LocationListener} with {@link #removeLocationListener(LocationListener)}.</li> * </ul> * <p> - * Note: If registering a listener in your Activity.onStart() implementation, you should unregister it in Activity.onStop(). - * (You won't receive location updates when paused, and this will cut down on unnecessary system overhead). - * Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back in the history stack. + * Note: If registering a listener in your Activity.onStart() implementation, you should unregister it in + * Activity.onStop(). (You won't receive location updates when paused, and this will cut down on unnecessary system + * overhead). Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back + * in the history stack. * </p> */ public class LocationServices implements com.mapzen.android.lost.api.LocationListener { - private static LocationServices instance; - - private Context context; - private LostApiClient locationClient; - private Location lastLocation; - - private CopyOnWriteArrayList<LocationListener> locationListeners; - - private boolean isGPSEnabled; - - /** - * Private constructor for singleton LocationServices - */ - private LocationServices(Context context) { - super(); - this.context = context; - // Setup location services - locationClient = new LostApiClient.Builder(context).build(); - locationListeners = new CopyOnWriteArrayList<>(); + private static LocationServices instance; + + private Context context; + private LostApiClient locationClient; + private Location lastLocation; + + private CopyOnWriteArrayList<LocationListener> locationListeners; + + private boolean isGpsEnabled; + + /** + * Private constructor for singleton LocationServices + */ + private LocationServices(Context context) { + super(); + this.context = context; + // Setup location services + locationClient = new LostApiClient.Builder(context).build(); + locationListeners = new CopyOnWriteArrayList<>(); + } + + /** + * Primary (singleton) access method for LocationServices + * + * @param context Context + * @return LocationServices + */ + public static LocationServices getLocationServices(@NonNull final Context context) { + if (instance == null) { + instance = new LocationServices(context.getApplicationContext()); } - - /** - * Primary (singleton) access method for LocationServices - * - * @param context Context - * @return LocationServices - */ - public static LocationServices getLocationServices(@NonNull final Context context) { - if (instance == null) { - instance = new LocationServices(context.getApplicationContext()); - } - return instance; + return instance; + } + + /** + * Enabled / Disable GPS focused location tracking + * + * @param enableGPS true if GPS is to be enabled, false if GPS is to be disabled + */ + public void toggleGPS(boolean enableGPS) { + if (!areLocationPermissionsGranted()) { + Timber.w("Location Permissions Not Granted Yet. Try again after requesting."); + return; } - /** - * Enabled / Disable GPS focused location tracking - * - * @param enableGPS true if GPS is to be enabled, false if GPS is to be disabled - */ - public void toggleGPS(boolean enableGPS) { - if (!areLocationPermissionsGranted()) { - Timber.w("Location Permissions Not Granted Yet. Try again after requesting."); - return; - } - - // Disconnect - if (locationClient.isConnected()) { - // Disconnect first to ensure that the new requests are GPS - com.mapzen.android.lost.api.LocationServices.FusedLocationApi.removeLocationUpdates(this); - locationClient.disconnect(); - } - - // Setup Fresh - locationClient.connect(); - Location lastLocation = com.mapzen.android.lost.api.LocationServices.FusedLocationApi.getLastLocation(); - if (lastLocation != null) { - this.lastLocation = lastLocation; - } - - LocationRequest locationRequest; - - if (enableGPS) { - // LocationRequest Tuned for GPS - locationRequest = LocationRequest.create() - .setFastestInterval(1000) - .setSmallestDisplacement(3.0f) - .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); - - com.mapzen.android.lost.api.LocationServices.FusedLocationApi.requestLocationUpdates(locationRequest, this); - } else { - // LocationRequest Tuned for PASSIVE - locationRequest = LocationRequest.create() - .setFastestInterval(1000) - .setSmallestDisplacement(3.0f) - .setPriority(LocationRequest.PRIORITY_NO_POWER); - - com.mapzen.android.lost.api.LocationServices.FusedLocationApi.requestLocationUpdates(locationRequest, this); - } - - isGPSEnabled = enableGPS; + // Disconnect + if (locationClient.isConnected()) { + // Disconnect first to ensure that the new requests are GPS + com.mapzen.android.lost.api.LocationServices.FusedLocationApi.removeLocationUpdates(this); + locationClient.disconnect(); } - /** - * Returns if the GPS sensor is currently enabled - * - * @return active state of the GPS - */ - public boolean isGPSEnabled() { - return isGPSEnabled; + // Setup Fresh + locationClient.connect(); + Location lastLocation = com.mapzen.android.lost.api.LocationServices.FusedLocationApi.getLastLocation(); + if (lastLocation != null) { + this.lastLocation = lastLocation; } - /** - * Called when the location has changed. - * - * @param location The updated location - */ - @Override - public void onLocationChanged(Location location) { -// Timber.d("onLocationChanged()..." + location); - this.lastLocation = location; - - // Update Listeners - for (LocationListener listener : this.locationListeners) { - listener.onLocationChanged(location); - } - - // Update the Telemetry Receiver - Intent locIntent = new Intent(TelemetryLocationReceiver.INTENT_STRING); - locIntent.putExtra(LocationManager.KEY_LOCATION_CHANGED, location); - context.sendBroadcast(locIntent); - } + LocationRequest locationRequest; - /** - * Last known location - * - * @return Last known location data - */ - public Location getLastLocation() { - return lastLocation; - } + if (enableGPS) { + // LocationRequest Tuned for GPS + locationRequest = LocationRequest.create() + .setFastestInterval(1000) + .setSmallestDisplacement(3.0f) + .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); - /** - * Registers a LocationListener to receive location updates - * - * @param locationListener LocationListener - */ - public void addLocationListener(@NonNull LocationListener locationListener) { - if (!this.locationListeners.contains(locationListener)) { - this.locationListeners.add(locationListener); - } + com.mapzen.android.lost.api.LocationServices.FusedLocationApi.requestLocationUpdates(locationRequest, this); + } else { + // LocationRequest Tuned for PASSIVE + locationRequest = LocationRequest.create() + .setFastestInterval(1000) + .setSmallestDisplacement(3.0f) + .setPriority(LocationRequest.PRIORITY_NO_POWER); + + com.mapzen.android.lost.api.LocationServices.FusedLocationApi.requestLocationUpdates(locationRequest, this); } - /** - * Unregister a LocationListener to stop receiving location updates - * - * @param locationListener LocationListener to remove - * @return True if LocationListener was found and removed, False if it was not - */ - public boolean removeLocationListener(@NonNull LocationListener locationListener) { - return this.locationListeners.remove(locationListener); + isGpsEnabled = enableGPS; + } + + /** + * Returns if the GPS sensor is currently enabled + * + * @return active state of the GPS + */ + public boolean isGpsEnabled() { + return isGpsEnabled; + } + + /** + * Called when the location has changed. + * + * @param location The updated location + */ + @Override + public void onLocationChanged(Location location) { + // Timber.d("onLocationChanged()..." + location); + this.lastLocation = location; + + // Update Listeners + for (LocationListener listener : this.locationListeners) { + listener.onLocationChanged(location); } - /** - * Check status of Location Permissions - * @return True if granted to the app, False if not - */ - public boolean areLocationPermissionsGranted() { - if ((ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) && - (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { - Timber.w("Location Permissions Not Granted Yet. Try again after requesting."); - return false; - } - return true; + // Update the Telemetry Receiver + Intent locIntent = new Intent(TelemetryLocationReceiver.INTENT_STRING); + locIntent.putExtra(LocationManager.KEY_LOCATION_CHANGED, location); + context.sendBroadcast(locIntent); + } + + /** + * Last known location + * + * @return Last known location data + */ + public Location getLastLocation() { + return lastLocation; + } + + /** + * Registers a LocationListener to receive location updates + * + * @param locationListener LocationListener + */ + public void addLocationListener(@NonNull LocationListener locationListener) { + if (!this.locationListeners.contains(locationListener)) { + this.locationListeners.add(locationListener); + } + } + + /** + * Unregister a LocationListener to stop receiving location updates + * + * @param locationListener LocationListener to remove + * @return True if LocationListener was found and removed, False if it was not + */ + public boolean removeLocationListener(@NonNull LocationListener locationListener) { + return this.locationListeners.remove(locationListener); + } + + /** + * Check status of Location Permissions + * + * @return True if granted to the app, False if not + */ + public boolean areLocationPermissionsGranted() { + if ((ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) + != PackageManager.PERMISSION_GRANTED) + && (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) + != PackageManager.PERMISSION_GRANTED)) { + Timber.w("Location Permissions Not Granted Yet. Try again after requesting."); + return false; } + return true; + } } |