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
Update engine's location requests #215
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6deadaa
Add equals & hashCode to LocationRequest
sarahsnow1 42b8e74
remove location request and update engine when location updates removed
sarahsnow1 d0d1712
Add sample for multiple clients w/diff request priorities
sarahsnow1 cf85c3f
newline
sarahsnow1 c10762d
batch request removal and improve request management
sarahsnow1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a runtime permission check here. Currently crashes on fresh install.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, I'll create a new activity and migrate these examples in a future PR #217