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.
* support multiple remote callbacks in service delegate * ensure remote callbacks removed from delegate * allow requests w same parameters in different processes * add multiple processes example * simplify remote callback unique id to be pid
- Loading branch information
1 parent
3ed32b3
commit 1b40deb
Showing
22 changed files
with
316 additions
and
79 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
57 changes: 57 additions & 0 deletions
57
lost-sample/src/main/java/com/example/lost/ListenerService.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,57 @@ | ||
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.app.Service; | ||
import android.content.Intent; | ||
import android.location.Location; | ||
import android.os.IBinder; | ||
import android.support.annotation.Nullable; | ||
import android.util.Log; | ||
|
||
/** | ||
* Service running in separate process to request location updates. | ||
*/ | ||
public class ListenerService extends Service { | ||
|
||
private static final String TAG = ListenerService.class.getSimpleName(); | ||
|
||
LostApiClient client; | ||
LocationListener listener = new LocationListener() { | ||
@Override public void onLocationChanged(Location location) { | ||
Log.d(TAG, "Location Changed"); | ||
} | ||
}; | ||
|
||
@Nullable @Override public IBinder onBind(Intent intent) { | ||
return null; | ||
} | ||
|
||
@Override public void onCreate() { | ||
super.onCreate(); | ||
client = new LostApiClient.Builder(this).addConnectionCallbacks( | ||
new LostApiClient.ConnectionCallbacks() { | ||
@Override public void onConnected() { | ||
LocationRequest request = LocationRequest.create(); | ||
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); | ||
request.setInterval(100); | ||
|
||
LocationServices.FusedLocationApi.requestLocationUpdates(client, request, listener); | ||
} | ||
|
||
@Override public void onConnectionSuspended() { | ||
|
||
} | ||
}).build(); | ||
client.connect(); | ||
} | ||
|
||
@Override public void onDestroy() { | ||
super.onDestroy(); | ||
LocationServices.FusedLocationApi.removeLocationUpdates(client, listener); | ||
client.disconnect(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
lost-sample/src/main/java/com/example/lost/MultipleProcessesActivity.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,51 @@ | ||
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 android.content.Intent; | ||
import android.location.Location; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
/** | ||
* Demonstrates two different processes requesting location updates. | ||
*/ | ||
public class MultipleProcessesActivity extends PendingIntentActivity { | ||
|
||
private static final String TAG = MultipleProcessesActivity.class.getSimpleName(); | ||
|
||
LocationListener listener = new LocationListener() { | ||
@Override public void onLocationChanged(Location location) { | ||
Log.d(TAG, "Location Changed"); | ||
} | ||
}; | ||
|
||
@Override protected void onResume() { | ||
super.onResume(); | ||
Intent intent = new Intent(this, ListenerService.class); | ||
startService(intent); | ||
} | ||
|
||
@Override protected void onPause() { | ||
super.onPause(); | ||
Intent intent = new Intent(this, ListenerService.class); | ||
stopService(intent); | ||
} | ||
|
||
void requestLocationUpdates() { | ||
LocationRequest request = LocationRequest.create(); | ||
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); | ||
request.setInterval(100); | ||
|
||
LocationServices.FusedLocationApi.requestLocationUpdates(client, request, listener); | ||
|
||
Toast.makeText(this, R.string.requested, Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
void unregisterAndDisconnectClient() { | ||
LocationServices.FusedLocationApi.removeLocationUpdates(client, listener); | ||
disconnect(); | ||
} | ||
} |
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
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
Oops, something went wrong.