use of android.location.Location in project cw-omnibus by commonsguy.
the class WeatherFragment method run.
@Override
public void run() {
Location loc = LocationServices.FusedLocationApi.getLastLocation(getPlayServices());
if (loc == null) {
getListView().postDelayed(this, 1000);
} else {
FetchForecastTask task = new FetchForecastTask();
task.execute(loc);
}
}
use of android.location.Location in project Android-ReactiveLocation by mcharmas.
the class PlacesActivity method onLocationPermissionGranted.
@Override
protected void onLocationPermissionGranted() {
compositeSubscription = new CompositeSubscription();
compositeSubscription.add(reactiveLocationProvider.getCurrentPlace(null).subscribe(new Action1<PlaceLikelihoodBuffer>() {
@Override
public void call(PlaceLikelihoodBuffer buffer) {
PlaceLikelihood likelihood = buffer.get(0);
if (likelihood != null) {
currentPlaceView.setText(likelihood.getPlace().getName());
}
buffer.release();
}
}));
Observable<String> queryObservable = RxTextView.textChanges(queryView).map(new Func1<CharSequence, String>() {
@Override
public String call(CharSequence charSequence) {
return charSequence.toString();
}
}).debounce(1, TimeUnit.SECONDS).filter(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
return !TextUtils.isEmpty(s);
}
});
Observable<Location> lastKnownLocationObservable = reactiveLocationProvider.getLastKnownLocation();
Observable<AutocompletePredictionBuffer> suggestionsObservable = Observable.combineLatest(queryObservable, lastKnownLocationObservable, new Func2<String, Location, QueryWithCurrentLocation>() {
@Override
public QueryWithCurrentLocation call(String query, Location currentLocation) {
return new QueryWithCurrentLocation(query, currentLocation);
}
}).flatMap(new Func1<QueryWithCurrentLocation, Observable<AutocompletePredictionBuffer>>() {
@Override
public Observable<AutocompletePredictionBuffer> call(QueryWithCurrentLocation q) {
if (q.location == null)
return Observable.empty();
double latitude = q.location.getLatitude();
double longitude = q.location.getLongitude();
LatLngBounds bounds = new LatLngBounds(new LatLng(latitude - 0.05, longitude - 0.05), new LatLng(latitude + 0.05, longitude + 0.05));
return reactiveLocationProvider.getPlaceAutocompletePredictions(q.query, bounds, null);
}
});
compositeSubscription.add(suggestionsObservable.subscribe(new Action1<AutocompletePredictionBuffer>() {
@Override
public void call(AutocompletePredictionBuffer buffer) {
List<AutocompleteInfo> infos = new ArrayList<>();
for (AutocompletePrediction prediction : buffer) {
infos.add(new AutocompleteInfo(prediction.getFullText(null).toString(), prediction.getPlaceId()));
}
buffer.release();
placeSuggestionsList.setAdapter(new ArrayAdapter<>(PlacesActivity.this, android.R.layout.simple_list_item_1, infos));
}
}));
}
use of android.location.Location in project actor-platform by actorapp.
the class MapPickerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.picker_activity_map_picker);
list = (ListView) findViewById(R.id.list);
list.setOnScrollListener(this);
list.setOnItemClickListener(this);
list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
loading = (ProgressBar) findViewById(R.id.loading);
status = (TextView) findViewById(R.id.status);
header = findViewById(R.id.header);
listHolder = findViewById(R.id.listNearbyHolder);
mapHolder = findViewById(R.id.mapholder);
accuranceView = (TextView) findViewById(R.id.accurance);
setUpMapIfNeeded();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(false);
fullSizeButton = (ImageView) findViewById(R.id.full);
fullSizeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
togglePlacesList();
}
});
defineMyLocationButton = findViewById(R.id.define_my_location);
defineMyLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Location location = mMap.getMyLocation();
if (location != null) {
LatLng target = new LatLng(location.getLatitude(), location.getLongitude());
CameraPosition.Builder builder = new CameraPosition.Builder();
builder.zoom(17);
builder.target(target);
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(builder.build()));
} else {
Toast.makeText(getBaseContext(), R.string.picker_map_pick_my_wait, Toast.LENGTH_SHORT).show();
}
}
});
pickCurrent = findViewById(R.id.pick_current);
pickCurrent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (currentLocation != null) {
Intent returnIntent = new Intent();
returnIntent.putExtra("latitude", currentLocation.getLatitude());
returnIntent.putExtra("longitude", currentLocation.getLongitude());
setResult(RESULT_OK, returnIntent);
finish();
}
}
});
// we dont need these buttons
select = findViewById(R.id.select);
select.setEnabled(false);
findViewById(R.id.select_text).setEnabled(false);
select.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent returnIntent = new Intent();
returnIntent.putExtra("latitude", geoData.latitude);
returnIntent.putExtra("longitude", geoData.longitude);
setResult(RESULT_OK, returnIntent);
finish();
}
});
View cancel = findViewById(R.id.cancel);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
use of android.location.Location in project android_frameworks_base by ParanoidAndroid.
the class LocationManagerService method dump.
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
pw.println("Permission Denial: can't dump LocationManagerService from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
return;
}
synchronized (mLock) {
pw.println("Current Location Manager state:");
pw.println(" Location Listeners:");
for (Receiver receiver : mReceivers.values()) {
pw.println(" " + receiver);
}
pw.println(" Records by Provider:");
for (Map.Entry<String, ArrayList<UpdateRecord>> entry : mRecordsByProvider.entrySet()) {
pw.println(" " + entry.getKey() + ":");
for (UpdateRecord record : entry.getValue()) {
pw.println(" " + record);
}
}
pw.println(" Last Known Locations:");
for (Map.Entry<String, Location> entry : mLastLocation.entrySet()) {
String provider = entry.getKey();
Location location = entry.getValue();
pw.println(" " + provider + ": " + location);
}
pw.println(" Last Known Locations Coarse Intervals:");
for (Map.Entry<String, Location> entry : mLastLocationCoarseInterval.entrySet()) {
String provider = entry.getKey();
Location location = entry.getValue();
pw.println(" " + provider + ": " + location);
}
mGeofenceManager.dump(pw);
if (mGeoFencer != null && mGeoFencerEnabled) {
mGeoFencer.dump(pw, "");
}
if (mEnabledProviders.size() > 0) {
pw.println(" Enabled Providers:");
for (String i : mEnabledProviders) {
pw.println(" " + i);
}
}
if (mDisabledProviders.size() > 0) {
pw.println(" Disabled Providers:");
for (String i : mDisabledProviders) {
pw.println(" " + i);
}
}
pw.append(" ");
mBlacklist.dump(pw);
if (mMockProviders.size() > 0) {
pw.println(" Mock Providers:");
for (Map.Entry<String, MockProvider> i : mMockProviders.entrySet()) {
i.getValue().dump(pw, " ");
}
}
pw.append(" fudger: ");
mLocationFudger.dump(fd, pw, args);
if (args.length > 0 && "short".equals(args[0])) {
return;
}
for (LocationProviderInterface provider : mProviders) {
pw.print(provider.getName() + " Internal State");
if (provider instanceof LocationProviderProxy) {
LocationProviderProxy proxy = (LocationProviderProxy) provider;
pw.print(" (" + proxy.getConnectedPackageName() + ")");
}
pw.println(":");
provider.dump(fd, pw, args);
}
}
}
use of android.location.Location in project android_frameworks_base by ParanoidAndroid.
the class LocationManagerService method handleLocationChanged.
private void handleLocationChanged(Location location, boolean passive) {
// create a working copy of the incoming Location so that the service can modify it without
// disturbing the caller's copy
Location myLocation = new Location(location);
String provider = myLocation.getProvider();
// forward locations from mock providers, and should not grant them legitimacy in doing so.
if (!myLocation.isFromMockProvider() && isMockProvider(provider)) {
myLocation.setIsFromMockProvider(true);
}
synchronized (mLock) {
if (isAllowedByCurrentUserSettingsLocked(provider)) {
if (!passive) {
// notify passive provider of the new location
mPassiveProvider.updateLocation(myLocation);
}
handleLocationChangedLocked(myLocation, passive);
}
}
}
Aggregations