This repository has been archived by the owner on Apr 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update engine's location requests (#215)
* Add equals & hashCode to LocationRequest * remove location request and update engine when location updates removed * Add sample for multiple clients w/diff request priorities * newline * batch request removal and improve request management
- Loading branch information
1 parent
a7161c3
commit 40c3a4c
Showing
22 changed files
with
849 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
lost-sample/src/main/java/com/example/lost/MultiplePriorityMultipleClientsActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.example.lost; | ||
|
||
import com.mapzen.android.lost.api.LocationListener; | ||
import com.mapzen.android.lost.api.LocationRequest; | ||
import com.mapzen.android.lost.api.LocationServices; | ||
import com.mapzen.android.lost.api.LostApiClient; | ||
|
||
import android.location.Location; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
/** | ||
* Demonstrates two {@link LostApiClient}s receiving location updates with different request | ||
* priorities. | ||
*/ | ||
public class MultiplePriorityMultipleClientsActivity extends LostApiClientActivity { | ||
|
||
private static final String TAG = MultiplePriorityMultipleClientsActivity.class.getSimpleName(); | ||
|
||
LostApiClient otherClient; | ||
|
||
LocationListener noPowerListener = new LocationListener() { | ||
@Override public void onLocationChanged(Location location) { | ||
Log.d(TAG, "No Power Client Location:" + location.getLongitude() + " " + | ||
location.getLatitude()); | ||
} | ||
}; | ||
|
||
LocationListener highPriorityListener = new LocationListener() { | ||
@Override public void onLocationChanged(Location location) { | ||
Log.d(TAG, "High Priority Client Location:" + location.getLongitude() + " " + | ||
location.getLatitude()); | ||
} | ||
}; | ||
|
||
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_multiple_clients_requests); | ||
createOtherClient(); | ||
setupBtns(); | ||
} | ||
|
||
@Override public void onConnected() { | ||
super.onConnected(); | ||
requestNoPowerUpdates(); | ||
} | ||
|
||
private void setupBtns() { | ||
findViewById(R.id.connect_no_power_btn).setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
client.connect(); | ||
} | ||
}); | ||
findViewById(R.id.connect_high_priority_btn).setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
otherClient.connect(); | ||
} | ||
}); | ||
findViewById(R.id.rm_no_power_btn).setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
LocationServices.FusedLocationApi.removeLocationUpdates(client, noPowerListener); | ||
} | ||
}); | ||
findViewById(R.id.rm_high_priority_btn).setOnClickListener(new View.OnClickListener() { | ||
@Override public void onClick(View v) { | ||
LocationServices.FusedLocationApi.removeLocationUpdates(otherClient, highPriorityListener); | ||
} | ||
}); | ||
} | ||
|
||
private void requestNoPowerUpdates() { | ||
LocationRequest request = LocationRequest.create() | ||
.setPriority(LocationRequest.PRIORITY_NO_POWER) | ||
.setFastestInterval(0) | ||
.setSmallestDisplacement(0) | ||
.setInterval(1000); // 1 sec | ||
LocationServices.FusedLocationApi.requestLocationUpdates(client, request, noPowerListener); | ||
} | ||
|
||
private void createOtherClient() { | ||
otherClient = new LostApiClient.Builder(this) | ||
.addConnectionCallbacks(new LostApiClient.ConnectionCallbacks() { | ||
|
||
@Override public void onConnected() { | ||
Log.d("Test", "High priority onConnected"); | ||
|
||
LocationRequest request = LocationRequest.create() | ||
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) | ||
.setFastestInterval(0) | ||
.setSmallestDisplacement(0) | ||
.setInterval(1000); // 1 sec | ||
|
||
LocationServices.FusedLocationApi.requestLocationUpdates(otherClient, request, | ||
highPriorityListener); | ||
} | ||
|
||
@Override public void onConnectionSuspended() { | ||
|
||
} | ||
}) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
lost-sample/src/main/res/layout/activity_multiple_clients_requests.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Connect no power client" | ||
android:id="@+id/connect_no_power_btn" | ||
/> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Connect high priority client" | ||
android:id="@+id/connect_high_priority_btn" | ||
/> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Rm no power requests" | ||
android:id="@+id/rm_no_power_btn" | ||
/> | ||
|
||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Rm high priority requests" | ||
android:id="@+id/rm_high_priority_btn" | ||
/> | ||
|
||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lost/src/main/java/com/mapzen/android/lost/internal/ClientCallbackWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.mapzen.android.lost.internal; | ||
|
||
import com.mapzen.android.lost.api.LostApiClient; | ||
|
||
|
||
/** | ||
* Wraps a {@link LostApiClient} to either a {@link com.mapzen.android.lost.api.LocationListener}, | ||
* {@link android.app.PendingIntent}, or {@link com.mapzen.android.lost.api.LocationCallback}. | ||
*/ | ||
class ClientCallbackWrapper { | ||
|
||
private LostApiClient client; | ||
private Object callback; | ||
|
||
public <T> ClientCallbackWrapper(LostApiClient client, T callback) { | ||
this.client = client; | ||
this.callback = callback; | ||
} | ||
|
||
@Override public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
ClientCallbackWrapper wrapper = (ClientCallbackWrapper) o; | ||
|
||
if (!client.equals(wrapper.client)) { | ||
return false; | ||
} | ||
return callback.equals(wrapper.callback); | ||
} | ||
|
||
@Override public int hashCode() { | ||
int result = client.hashCode(); | ||
result = 31 * result + callback.hashCode(); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.