28
28
29
29
import java .util .Random ;
30
30
31
- public class FusedLocationManager implements LocationManager {
31
+ public class FusedLocationProvider implements LocationProvider {
32
32
private final ReactApplicationContext context ;
33
33
private final FusedLocationProviderClient fusedLocationProviderClient ;
34
34
private final SettingsClient settingsClient ;
35
35
36
36
private int activityRequestCode ;
37
+ private LocationChangeListener locationChangeListener ;
37
38
private LocationOptions locationOptions ;
38
- private LocationListener locationListener ;
39
39
private LocationRequest locationRequest ;
40
40
41
41
private boolean isSingleUpdate = false ;
42
42
private final LocationCallback locationCallback = new LocationCallback () {
43
43
@ Override
44
44
public void onLocationResult (LocationResult locationResult ) {
45
- locationListener .onLocationChange (locationResult .getLastLocation ());
45
+ locationChangeListener .onLocationChange (locationResult .getLastLocation ());
46
46
47
47
if (isSingleUpdate ) {
48
48
timeoutHandler .removeCallbacks (timeoutRunnable );
@@ -55,7 +55,7 @@ public void onLocationAvailability(LocationAvailability locationAvailability) {
55
55
if (!locationAvailability .isLocationAvailable () &&
56
56
!LocationUtils .isLocationEnabled (context )
57
57
) {
58
- locationListener .onLocationError (
58
+ locationChangeListener .onLocationError (
59
59
LocationError .POSITION_UNAVAILABLE ,
60
60
"Unable to retrieve location."
61
61
);
@@ -66,22 +66,22 @@ public void onLocationAvailability(LocationAvailability locationAvailability) {
66
66
private final Runnable timeoutRunnable = new Runnable () {
67
67
@ Override
68
68
public void run () {
69
- locationListener .onLocationError (LocationError .TIMEOUT , null );
69
+ locationChangeListener .onLocationError (LocationError .TIMEOUT , null );
70
70
fusedLocationProviderClient .removeLocationUpdates (locationCallback );
71
71
}
72
72
};
73
73
74
- public FusedLocationManager (ReactApplicationContext context ) {
74
+ public FusedLocationProvider (ReactApplicationContext context ) {
75
75
this .context = context ;
76
76
this .fusedLocationProviderClient = LocationServices .getFusedLocationProviderClient (context );
77
77
this .settingsClient = LocationServices .getSettingsClient (context );
78
78
}
79
79
80
80
@ SuppressLint ("MissingPermission" )
81
81
@ Override
82
- public void getCurrentLocation (final LocationOptions locationOptions , final LocationListener locationListener ) {
82
+ public void getCurrentLocation (final LocationOptions locationOptions , final LocationChangeListener locationChangeListener ) {
83
83
this .isSingleUpdate = true ;
84
- this .locationListener = locationListener ;
84
+ this .locationChangeListener = locationChangeListener ;
85
85
this .locationOptions = locationOptions ;
86
86
this .locationRequest = buildLocationRequest (locationOptions );
87
87
@@ -93,7 +93,7 @@ public void onSuccess(Location location) {
93
93
(System .currentTimeMillis () - location .getTime ()) < locationOptions .getMaximumAge ()
94
94
) {
95
95
Log .i (RNFusedLocationModule .TAG , "returning cached location." );
96
- locationListener .onLocationChange (location );
96
+ locationChangeListener .onLocationChange (location );
97
97
return ;
98
98
}
99
99
@@ -126,16 +126,16 @@ public boolean onActivityResult(int requestCode, int resultCode) {
126
126
startLocationUpdates ();
127
127
} else {
128
128
LocationError error = !forceRequestLocation ? LocationError .SETTINGS_NOT_SATISFIED : LocationError .POSITION_UNAVAILABLE ;
129
- locationListener .onLocationError (error , null );
129
+ locationChangeListener .onLocationError (error , null );
130
130
}
131
131
132
132
return true ;
133
133
}
134
134
135
135
@ Override
136
- public void requestLocationUpdates (LocationOptions locationOptions , final LocationListener locationListener ) {
136
+ public void requestLocationUpdates (LocationOptions locationOptions , final LocationChangeListener locationChangeListener ) {
137
137
this .isSingleUpdate = false ;
138
- this .locationListener = locationListener ;
138
+ this .locationChangeListener = locationChangeListener ;
139
139
this .locationOptions = locationOptions ;
140
140
this .locationRequest = buildLocationRequest (locationOptions );
141
141
checkLocationSettings ();
@@ -178,7 +178,7 @@ public void onFailure(@NonNull Exception e) {
178
178
switch (exception .getStatusCode ()) {
179
179
case LocationSettingsStatusCodes .RESOLUTION_REQUIRED :
180
180
if (!locationOptions .isShowLocationDialog ()) {
181
- locationListener .onLocationError (LocationError .SETTINGS_NOT_SATISFIED , null );
181
+ locationChangeListener .onLocationError (LocationError .SETTINGS_NOT_SATISFIED , null );
182
182
break ;
183
183
}
184
184
@@ -187,7 +187,7 @@ public void onFailure(@NonNull Exception e) {
187
187
Activity activity = context .getCurrentActivity ();
188
188
189
189
if (activity == null ) {
190
- locationListener .onLocationError (
190
+ locationChangeListener .onLocationError (
191
191
LocationError .INTERNAL_ERROR ,
192
192
"Tried to open location dialog while not attached to an Activity."
193
193
);
@@ -197,9 +197,9 @@ public void onFailure(@NonNull Exception e) {
197
197
activityRequestCode = getActivityRequestCode ();
198
198
resolvable .startResolutionForResult (activity , activityRequestCode );
199
199
} catch (IntentSender .SendIntentException sie ) {
200
- locationListener .onLocationError (LocationError .INTERNAL_ERROR , null );
200
+ locationChangeListener .onLocationError (LocationError .INTERNAL_ERROR , null );
201
201
} catch (ClassCastException cce ) {
202
- locationListener .onLocationError (LocationError .INTERNAL_ERROR , null );
202
+ locationChangeListener .onLocationError (LocationError .INTERNAL_ERROR , null );
203
203
}
204
204
205
205
break ;
@@ -211,7 +211,7 @@ public void onFailure(@NonNull Exception e) {
211
211
break ;
212
212
}
213
213
default :
214
- locationListener .onLocationError (LocationError .SETTINGS_NOT_SATISFIED , null );
214
+ locationChangeListener .onLocationError (LocationError .SETTINGS_NOT_SATISFIED , null );
215
215
break ;
216
216
}
217
217
}
0 commit comments