use of android.location.Location in project Parse-SDK-Android by ParsePlatform.
the class LocationNotifier method getCurrentLocationAsync.
/**
* Asynchronously gets the current location of the device.
*
* This will request location updates from the best provider that match the given criteria
* and return the first location received.
*
* You can customize the criteria to meet your specific needs.
* * For higher accuracy, you can set {@link Criteria#setAccuracy(int)}, however result in longer
* times for a fix.
* * For better battery efficiency and faster location fixes, you can set
* {@link Criteria#setPowerRequirement(int)}, however, this will result in lower accuracy.
*
* @param context
* The context used to request location updates.
* @param timeout
* The number of milliseconds to allow before timing out.
* @param criteria
* The application criteria for selecting a location provider.
*
* @see android.location.LocationManager#getBestProvider(android.location.Criteria, boolean)
* @see android.location.LocationManager#requestLocationUpdates(String, long, float, android.location.LocationListener)
*/
/* package */
static Task<Location> getCurrentLocationAsync(Context context, long timeout, Criteria criteria) {
final TaskCompletionSource<Location> tcs = new TaskCompletionSource<>();
final Capture<ScheduledFuture<?>> timeoutFuture = new Capture<ScheduledFuture<?>>();
final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
final LocationListener listener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
if (location == null) {
return;
}
timeoutFuture.get().cancel(true);
tcs.trySetResult(location);
manager.removeUpdates(this);
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
};
timeoutFuture.set(ParseExecutors.scheduled().schedule(new Runnable() {
@Override
public void run() {
tcs.trySetError(new ParseException(ParseException.TIMEOUT, "Location fetch timed out."));
manager.removeUpdates(listener);
}
}, timeout, TimeUnit.MILLISECONDS));
String provider = manager.getBestProvider(criteria, true);
if (provider != null) {
manager.requestLocationUpdates(provider, /* minTime */
0, /* minDistance */
0.0f, listener);
}
if (fakeLocation != null) {
listener.onLocationChanged(fakeLocation);
}
return tcs.getTask();
}
use of android.location.Location in project XPrivacy by M66B.
the class XLocationManager method after.
@Override
protected void after(XParam param) throws Throwable {
switch(mMethod) {
case addGeofence:
case addNmeaListener:
case addGpsStatusListener:
case addProximityAlert:
case Srv_requestGeofence:
case Srv_addGpsStatusListener:
case Srv_addGpsMeasurementsListener:
case Srv_addGpsNavigationMessageListener:
case Srv_removeGeofence:
case Srv_removeGpsStatusListener:
case Srv_removeGpsMeasurementsListener:
case Srv_removeGpsNavigationMessageListener:
// Do nothing
break;
case isProviderEnabled:
case Srv_isProviderEnabled:
if (param.args.length > 0) {
String provider = (String) param.args[0];
if (isRestrictedExtra(param, provider))
param.setResult(false);
}
break;
case getGpsStatus:
if (param.getResult() instanceof GpsStatus)
if (isRestricted(param)) {
GpsStatus status = (GpsStatus) param.getResult();
// private GpsSatellite mSatellites[]
try {
Field mSatellites = status.getClass().getDeclaredField("mSatellites");
mSatellites.setAccessible(true);
mSatellites.set(status, new GpsSatellite[0]);
} catch (Throwable ex) {
Util.bug(null, ex);
}
}
break;
case getProviders:
case getAllProviders:
case Srv_getAllProviders:
case Srv_getProviders:
if (isRestricted(param))
param.setResult(new ArrayList<String>());
break;
case getBestProvider:
case Srv_getBestProvider:
if (param.getResult() != null)
if (isRestricted(param))
param.setResult(null);
break;
case getLastKnownLocation:
if (param.args.length > 0 && param.getResult() instanceof Location) {
String provider = (String) param.args[0];
Location location = (Location) param.getResult();
if (isRestrictedExtra(param, provider))
param.setResult(PrivacyManager.getDefacedLocation(Binder.getCallingUid(), location));
}
break;
case Srv_getLastLocation:
if (param.getResult() instanceof Location) {
Location location = (Location) param.getResult();
if (isRestricted(param))
param.setResult(PrivacyManager.getDefacedLocation(Binder.getCallingUid(), location));
}
break;
case removeUpdates:
case requestLocationUpdates:
case requestSingleUpdate:
case Srv_removeUpdates:
case Srv_requestLocationUpdates:
// Do nothing
break;
case sendExtraCommand:
case Srv_sendExtraCommand:
if (param.args.length > 0) {
String provider = (String) param.args[0];
if (isRestrictedExtra(param, provider))
param.setResult(false);
}
break;
}
}
use of android.location.Location in project phonegap-facebook-plugin by Wizcorp.
the class PlacePickerFragment method setPlacePickerSettingsFromBundle.
private void setPlacePickerSettingsFromBundle(Bundle inState) {
// We do this in a separate non-overridable method so it is safe to call from the constructor.
if (inState != null) {
setRadiusInMeters(inState.getInt(RADIUS_IN_METERS_BUNDLE_KEY, radiusInMeters));
setResultsLimit(inState.getInt(RESULTS_LIMIT_BUNDLE_KEY, resultsLimit));
if (inState.containsKey(SEARCH_TEXT_BUNDLE_KEY)) {
setSearchText(inState.getString(SEARCH_TEXT_BUNDLE_KEY));
}
if (inState.containsKey(LOCATION_BUNDLE_KEY)) {
Location location = inState.getParcelable(LOCATION_BUNDLE_KEY);
setLocation(location);
}
showSearchBox = inState.getBoolean(SHOW_SEARCH_BOX_BUNDLE_KEY, showSearchBox);
}
}
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 Talon-for-Twitter by klinker24.
the class LocalTrends method getTrends.
public void getTrends() {
new Thread(new Runnable() {
@Override
public void run() {
try {
Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);
int i = 0;
while (!connected && i < 5) {
try {
Thread.sleep(1500);
} catch (Exception e) {
}
i++;
}
twitter4j.Trends trends;
if (sharedPrefs.getBoolean("manually_config_location", false)) {
// chicago to default
trends = twitter.getPlaceTrends(sharedPrefs.getInt("woeid", 2379574));
} else {
Location location = mLastLocation;
ResponseList<twitter4j.Location> locations = twitter.getClosestTrends(new GeoLocation(location.getLatitude(), location.getLongitude()));
trends = twitter.getPlaceTrends(locations.get(0).getWoeid());
}
final ArrayList<String> currentTrends = new ArrayList<String>();
for (Trend t : trends.getTrends()) {
String name = t.getName();
currentTrends.add(name);
}
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
try {
if (currentTrends != null) {
listView.setAdapter(new TrendsArrayAdapter(context, currentTrends));
listView.setVisibility(View.VISIBLE);
} else {
Toast.makeText(context, getResources().getString(R.string.no_location), Toast.LENGTH_SHORT).show();
}
LinearLayout spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
spinner.setVisibility(View.GONE);
} catch (Exception e) {
// not attached to activity
}
}
});
HashtagDataSource source = HashtagDataSource.getInstance(context);
for (String s : currentTrends) {
Log.v("talon_hashtag", "trend: " + s);
if (s.contains("#")) {
// we want to add it to the auto complete
Log.v("talon_hashtag", "adding: " + s);
// could be much more efficient by querying and checking first, but I
// just didn't feel like it when there is only ever 10 of them here
source.deleteTag(s);
// add it to the userAutoComplete database
source.createTag(s);
}
}
} catch (Throwable e) {
e.printStackTrace();
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
try {
Toast.makeText(context, getResources().getString(R.string.no_location), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// not attached to activity
}
}
});
}
}
}).start();
}
Aggregations