14
14
import java .util .List ;
15
15
import java .util .concurrent .CopyOnWriteArrayList ;
16
16
17
- import javax .inject .Inject ;
18
- import javax .inject .Singleton ;
19
-
20
17
import timber .log .Timber ;
21
18
22
19
public class LocationServiceManager implements LocationListener {
@@ -33,6 +30,7 @@ public class LocationServiceManager implements LocationListener {
33
30
34
31
/**
35
32
* Constructs a new instance of LocationServiceManager.
33
+ *
36
34
* @param context the context
37
35
*/
38
36
public LocationServiceManager (Context context ) {
@@ -42,6 +40,7 @@ public LocationServiceManager(Context context) {
42
40
43
41
/**
44
42
* Returns the current status of the GPS provider.
43
+ *
45
44
* @return true if the GPS provider is enabled
46
45
*/
47
46
public boolean isProviderEnabled () {
@@ -50,6 +49,7 @@ public boolean isProviderEnabled() {
50
49
51
50
/**
52
51
* Returns whether the location permission is granted.
52
+ *
53
53
* @return true if the location permission is granted
54
54
*/
55
55
public boolean isLocationPermissionGranted () {
@@ -59,6 +59,7 @@ public boolean isLocationPermissionGranted() {
59
59
60
60
/**
61
61
* Requests the location permission to be granted.
62
+ *
62
63
* @param activity the activity
63
64
*/
64
65
public void requestPermissions (Activity activity ) {
@@ -71,11 +72,9 @@ public void requestPermissions(Activity activity) {
71
72
}
72
73
73
74
public boolean isPermissionExplanationRequired (Activity activity ) {
74
- if (activity .isFinishing ()) {
75
- return false ;
76
- }
77
- return ActivityCompat .shouldShowRequestPermissionRationale (activity ,
78
- Manifest .permission .ACCESS_FINE_LOCATION );
75
+ return !activity .isFinishing () &&
76
+ ActivityCompat .shouldShowRequestPermissionRationale (activity ,
77
+ Manifest .permission .ACCESS_FINE_LOCATION );
79
78
}
80
79
81
80
public LatLng getLastLocation () {
@@ -85,7 +84,8 @@ public LatLng getLastLocation() {
85
84
return LatLng .from (lastLocation );
86
85
}
87
86
88
- /** Registers a LocationManager to listen for current location.
87
+ /**
88
+ * Registers a LocationManager to listen for current location.
89
89
*/
90
90
public void registerLocationManager () {
91
91
if (!isLocationManagerRegistered )
@@ -95,6 +95,7 @@ public void registerLocationManager() {
95
95
96
96
/**
97
97
* Requests location updates from the specified provider.
98
+ *
98
99
* @param locationProvider the location provider
99
100
* @return true if successful
100
101
*/
@@ -116,7 +117,8 @@ private boolean requestLocationUpdatesFromProvider(String locationProvider) {
116
117
117
118
/**
118
119
* Returns whether a given location is better than the current best location.
119
- * @param location the location to be tested
120
+ *
121
+ * @param location the location to be tested
120
122
* @param currentBestLocation the current best location
121
123
* @return true if the given location is better
122
124
*/
@@ -172,7 +174,8 @@ private boolean isSameProvider(String provider1, String provider2) {
172
174
return provider1 .equals (provider2 );
173
175
}
174
176
175
- /** Unregisters location manager.
177
+ /**
178
+ * Unregisters location manager.
176
179
*/
177
180
public void unregisterLocationManager () {
178
181
isLocationManagerRegistered = false ;
@@ -185,6 +188,7 @@ public void unregisterLocationManager() {
185
188
186
189
/**
187
190
* Adds a new listener to the list of location listeners.
191
+ *
188
192
* @param listener the new listener
189
193
*/
190
194
public void addLocationListener (LocationUpdateListener listener ) {
@@ -195,6 +199,7 @@ public void addLocationListener(LocationUpdateListener listener) {
195
199
196
200
/**
197
201
* Removes a listener from the list of location listeners.
202
+ *
198
203
* @param listener the listener to be removed
199
204
*/
200
205
public void removeLocationListener (LocationUpdateListener listener ) {
0 commit comments