Search in sources :

Example 11 with Location

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();
}
Also used : LocationManager(android.location.LocationManager) TaskCompletionSource(bolts.TaskCompletionSource) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Capture(bolts.Capture) ScheduledFuture(java.util.concurrent.ScheduledFuture) Location(android.location.Location)

Example 12 with Location

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;
    }
}
Also used : GpsStatus(android.location.GpsStatus) Field(java.lang.reflect.Field) GpsSatellite(android.location.GpsSatellite) ArrayList(java.util.ArrayList) Location(android.location.Location)

Example 13 with Location

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);
    }
}
Also used : Location(android.location.Location)

Example 14 with Location

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();
        }
    });
}
Also used : CameraPosition(com.google.android.gms.maps.model.CameraPosition) Intent(android.content.Intent) LatLng(com.google.android.gms.maps.model.LatLng) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) Location(android.location.Location)

Example 15 with Location

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();
}
Also used : HashtagDataSource(com.klinker.android.twitter.data.sq_lite.HashtagDataSource) ArrayList(java.util.ArrayList) Trend(twitter4j.Trend) Twitter(twitter4j.Twitter) DrawerActivity(com.klinker.android.twitter.activities.drawer_activities.DrawerActivity) Activity(android.app.Activity) TrendsArrayAdapter(com.klinker.android.twitter.adapters.TrendsArrayAdapter) GeoLocation(twitter4j.GeoLocation) LinearLayout(android.widget.LinearLayout) GeoLocation(twitter4j.GeoLocation) Location(android.location.Location)

Aggregations

Location (android.location.Location)284 Bundle (android.os.Bundle)48 LocationListener (android.location.LocationListener)36 LocationManager (android.location.LocationManager)31 ArrayList (java.util.ArrayList)29 Criteria (android.location.Criteria)19 LocationProviderInterface (com.android.server.location.LocationProviderInterface)18 GsmCellLocation (android.telephony.gsm.GsmCellLocation)17 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 BroadcastReceiver (android.content.BroadcastReceiver)12 Handler (android.os.Handler)10 MockProvider (com.android.server.location.MockProvider)9 Timer (java.util.Timer)8 Test (org.junit.Test)8 PendingIntent (android.app.PendingIntent)7 IOException (java.io.IOException)7 LocationProviderProxy (com.android.server.location.LocationProviderProxy)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6