33import android .content .Context ;
44import android .location .Location ;
55import android .support .annotation .Nullable ;
6- import android .util .Log ;
76
87import com .mapbox .services .android .telemetry .location .LocationEngine ;
98import com .mapbox .services .android .telemetry .location .LocationEngineListener ;
1716
1817/**
1918 * Sample LocationEngine using the Open Source Lost library
20- *
21- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
2219 */
23- @ Deprecated
24- public class LostLocationEngine extends LocationEngine implements
25- LostApiClient .ConnectionCallbacks , LocationListener {
26-
27- private static final String LOG_TAG = LostLocationEngine .class .getSimpleName ();
20+ public class LostLocationEngine extends LocationEngine implements LocationListener {
2821
2922 private static LocationEngine instance ;
3023
3124 private WeakReference <Context > context ;
3225 private LostApiClient lostApiClient ;
3326
34- @ Deprecated
3527 public LostLocationEngine (Context context ) {
3628 super ();
3729 this .context = new WeakReference <>(context );
38- lostApiClient = new LostApiClient .Builder (this .context .get ())
39- .addConnectionCallbacks (this )
40- .build ();
30+ lostApiClient = new LostApiClient .Builder (this .context .get ()).build ();
4131 }
4232
43- @ Deprecated
4433 public static synchronized LocationEngine getLocationEngine (Context context ) {
4534 if (instance == null ) {
4635 instance = new LostLocationEngine (context .getApplicationContext ());
@@ -52,26 +41,25 @@ public static synchronized LocationEngine getLocationEngine(Context context) {
5241 /**
5342 * Activate the location engine which will connect whichever location provider you are using. You'll need to call
5443 * this before requesting user location updates using {@link LocationEngine#requestLocationUpdates()}.
55- *
56- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
5744 */
58- @ Deprecated
5945 @ Override
6046 public void activate () {
61- connect ();
47+ if (!lostApiClient .isConnected ()) {
48+ lostApiClient .connect ();
49+ }
50+ for (LocationEngineListener listener : locationListeners ) {
51+ listener .onConnected ();
52+ }
6253 }
6354
6455 /**
6556 * Disconnect the location engine which is useful when you no longer need location updates or requesting the users
6657 * {@link LocationEngine#getLastLocation()}. Before deactivating, you'll need to stop request user location updates
6758 * using {@link LocationEngine#removeLocationUpdates()}.
68- *
69- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
7059 */
71- @ Deprecated
7260 @ Override
7361 public void deactivate () {
74- if (lostApiClient != null && lostApiClient .isConnected ()) {
62+ if (lostApiClient .isConnected ()) {
7563 lostApiClient .disconnect ();
7664 }
7765 }
@@ -81,61 +69,30 @@ public void deactivate() {
8169 * the rare case when you'd like to know if your location engine is connected or not.
8270 *
8371 * @return boolean true if the location engine has been activated/connected, else false.
84- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
8572 */
86- @ Deprecated
8773 @ Override
8874 public boolean isConnected () {
8975 return lostApiClient .isConnected ();
9076 }
9177
9278 /**
93- * Invoked when the location provider has connected.
94- *
95- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
96- */
97- @ Deprecated
98- @ Override
99- public void onConnected () {
100- for (LocationEngineListener listener : locationListeners ) {
101- listener .onConnected ();
102- }
103- }
104-
105- /**
106- * Invoked when the location provider connection has been suspended.
107- *
108- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
109- */
110- @ Deprecated
111- @ Override
112- public void onConnectionSuspended () {
113- Log .d (LOG_TAG , "Connection suspended" );
114- }
115-
116- /**
117- * Returns the Last known location if the location provider is connected.
79+ * Returns the Last known location if the location provider is connected and location permissions are granted.
11880 *
11981 * @return the last known location
120- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
12182 */
122- @ Deprecated
12383 @ Override
12484 @ Nullable
12585 public Location getLastLocation () {
12686 if (lostApiClient .isConnected ()) {
12787 //noinspection MissingPermission
128- return LocationServices .FusedLocationApi .getLastLocation (lostApiClient );
88+ return LocationServices .FusedLocationApi .getLastLocation ();
12989 }
13090 return null ;
13191 }
13292
13393 /**
13494 * Request location updates to the location provider.
135- *
136- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
13795 */
138- @ Deprecated
13996 @ Override
14097 public void requestLocationUpdates () {
14198 LocationRequest request = LocationRequest .create ();
@@ -150,6 +107,7 @@ public void requestLocationUpdates() {
150107 request .setSmallestDisplacement (smallestDisplacement );
151108 }
152109
110+ // Priority matching is straightforward
153111 if (priority == LocationEnginePriority .NO_POWER ) {
154112 request .setPriority (LocationRequest .PRIORITY_NO_POWER );
155113 } else if (priority == LocationEnginePriority .LOW_POWER ) {
@@ -162,34 +120,29 @@ public void requestLocationUpdates() {
162120
163121 if (lostApiClient .isConnected ()) {
164122 //noinspection MissingPermission
165- LocationServices .FusedLocationApi .requestLocationUpdates (lostApiClient , request , this );
123+ LocationServices .FusedLocationApi .requestLocationUpdates (request , this );
166124 }
167125 }
168126
127+ @ Override
128+ public Type obtainType () {
129+ return Type .LOST ;
130+ }
131+
169132 /**
170133 * Dismiss ongoing location update to the location provider.
171- *
172- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
173134 */
174- @ Deprecated
175135 @ Override
176136 public void removeLocationUpdates () {
177137 if (lostApiClient .isConnected ()) {
178- LocationServices .FusedLocationApi .removeLocationUpdates (lostApiClient , this );
138+ LocationServices .FusedLocationApi .removeLocationUpdates (this );
179139 }
180140 }
181141
182- @ Deprecated
183- @ Override
184- public Type obtainType () {
185- return Type .LOST ;
186- }
187-
188142 /**
189143 * Invoked when the Location has changed.
190144 *
191145 * @param location the new location
192- * @deprecated Use {@link com.mapbox.services.android.telemetry.location.LostLocationEngine} instead
193146 */
194147 @ Deprecated
195148 @ Override
@@ -198,14 +151,4 @@ public void onLocationChanged(Location location) {
198151 listener .onLocationChanged (location );
199152 }
200153 }
201-
202- private void connect () {
203- if (lostApiClient != null ) {
204- if (lostApiClient .isConnected ()) {
205- onConnected ();
206- } else {
207- lostApiClient .connect ();
208- }
209- }
210- }
211154}
0 commit comments