Search in sources :

Example 16 with Location

use of android.location.Location in project Talon-for-Twitter by klinker24.

the class LocalTrendsFragment method getTrends.

@Override
protected Trends getTrends() {
    try {
        Twitter twitter = Utils.getTwitter(context, DrawerActivity.settings);
        Trends trends;
        if (sharedPrefs.getBoolean("manually_config_location", false)) {
            // chicago to default
            trends = twitter.getPlaceTrends(sharedPrefs.getInt("woeid", 2379574));
        } else {
            mGoogleApiClient.connect();
            connected = false;
            int i = 0;
            while (!connected && i < 5) {
                try {
                    Thread.sleep(1500);
                } catch (Exception e) {
                }
                i++;
            }
            Location location = mLastLocation;
            ResponseList<twitter4j.Location> locations = twitter.getClosestTrends(new GeoLocation(location.getLatitude(), location.getLongitude()));
            trends = twitter.getPlaceTrends(locations.get(0).getWoeid());
        }
        return trends;
    } catch (Exception e) {
        return null;
    }
}
Also used : Twitter(twitter4j.Twitter) Trends(twitter4j.Trends) GeoLocation(twitter4j.GeoLocation) GeoLocation(twitter4j.GeoLocation) Location(android.location.Location)

Example 17 with Location

use of android.location.Location in project c-geo by just-radovan.

the class cgMapMyOverlay method drawInternal.

private void drawInternal(Canvas canvas, MapProjectionImpl projection) {
    if (coordinates == null || location == null)
        return;
    MapFactory mapFactory = settings.getMapFactory();
    if (accuracyCircle == null) {
        accuracyCircle = new Paint();
        accuracyCircle.setAntiAlias(true);
        accuracyCircle.setStrokeWidth(1.0f);
    }
    if (historyLine == null) {
        historyLine = new Paint();
        historyLine.setAntiAlias(true);
        historyLine.setStrokeWidth(3.0f);
        historyLine.setColor(0xFFFFFFFF);
    }
    if (historyLineShadow == null) {
        historyLineShadow = new Paint();
        historyLineShadow.setAntiAlias(true);
        historyLineShadow.setStrokeWidth(7.0f);
        historyLineShadow.setColor(0x66000000);
    }
    if (setfil == null)
        setfil = new PaintFlagsDrawFilter(0, Paint.FILTER_BITMAP_FLAG);
    if (remfil == null)
        remfil = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG, 0);
    canvas.setDrawFilter(setfil);
    double latitude = coordinates.getLatitude();
    double longitude = coordinates.getLongitude();
    float accuracy = coordinates.getAccuracy();
    float[] result = new float[1];
    Location.distanceBetween(latitude, longitude, latitude, longitude + 1, result);
    float longitudeLineDistance = result[0];
    GeoPointImpl leftGeo = mapFactory.getGeoPointBase((int) (latitude * 1e6), (int) ((longitude - accuracy / longitudeLineDistance) * 1e6));
    projection.toPixels(leftGeo, left);
    projection.toPixels(location, center);
    int radius = center.x - left.x;
    accuracyCircle.setColor(0x66000000);
    accuracyCircle.setStyle(Style.STROKE);
    canvas.drawCircle(center.x, center.y, radius, accuracyCircle);
    accuracyCircle.setColor(0x08000000);
    accuracyCircle.setStyle(Style.FILL);
    canvas.drawCircle(center.x, center.y, radius, accuracyCircle);
    if (coordinates.getAccuracy() < 50f && ((historyRecent != null && cgBase.getDistance(historyRecent.getLatitude(), historyRecent.getLongitude(), coordinates.getLatitude(), coordinates.getLongitude()) > 0.005) || historyRecent == null)) {
        if (historyRecent != null)
            history.add(historyRecent);
        historyRecent = coordinates;
        int toRemove = history.size() - 700;
        if (toRemove > 0) {
            for (int cnt = 0; cnt < toRemove; cnt++) {
                history.remove(cnt);
            }
        }
    }
    if (settings.maptrail == 1) {
        int size = history.size();
        if (size > 1) {
            int alpha = 0;
            int alphaCnt = size - 201;
            if (alphaCnt < 1)
                alphaCnt = 1;
            for (int cnt = 1; cnt < size; cnt++) {
                Location prev = history.get(cnt - 1);
                Location now = history.get(cnt);
                if (prev != null && now != null) {
                    projection.toPixels(mapFactory.getGeoPointBase((int) (prev.getLatitude() * 1e6), (int) (prev.getLongitude() * 1e6)), historyPointP);
                    projection.toPixels(mapFactory.getGeoPointBase((int) (now.getLatitude() * 1e6), (int) (now.getLongitude() * 1e6)), historyPointN);
                    if ((alphaCnt - cnt) > 0)
                        alpha = Math.round(255 / (alphaCnt - cnt));
                    else
                        alpha = 255;
                    historyLineShadow.setAlpha(alpha);
                    historyLine.setAlpha(alpha);
                    canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLineShadow);
                    canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLine);
                }
            }
        }
        if (size > 0) {
            Location prev = history.get(size - 1);
            Location now = coordinates;
            if (prev != null && now != null) {
                projection.toPixels(mapFactory.getGeoPointBase((int) (prev.getLatitude() * 1e6), (int) (prev.getLongitude() * 1e6)), historyPointP);
                projection.toPixels(mapFactory.getGeoPointBase((int) (now.getLatitude() * 1e6), (int) (now.getLongitude() * 1e6)), historyPointN);
                historyLineShadow.setAlpha(255);
                historyLine.setAlpha(255);
                canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLineShadow);
                canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLine);
            }
        }
    }
    if (arrow == null) {
        arrow = BitmapFactory.decodeResource(settings.getContext().getResources(), R.drawable.my_location_chevron);
        widthArrow = arrow.getWidth();
        heightArrow = arrow.getHeight();
    }
    int marginLeft;
    int marginTop;
    marginLeft = center.x - (widthArrow / 2);
    marginTop = center.y - (heightArrow / 2);
    canvas.rotate(new Float(heading), center.x, center.y);
    canvas.drawBitmap(arrow, marginLeft, marginTop, null);
    canvas.rotate(-(new Float(heading)), center.x, center.y);
    canvas.setDrawFilter(remfil);
//super.draw(canvas, mapView, shadow);
}
Also used : MapFactory(carnero.cgeo.mapinterfaces.MapFactory) GeoPointImpl(carnero.cgeo.mapinterfaces.GeoPointImpl) Paint(android.graphics.Paint) PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter) Point(android.graphics.Point) Paint(android.graphics.Paint) Location(android.location.Location)

Example 18 with Location

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));
        }
    }));
}
Also used : PlaceLikelihoodBuffer(com.google.android.gms.location.places.PlaceLikelihoodBuffer) AutocompletePredictionBuffer(com.google.android.gms.location.places.AutocompletePredictionBuffer) ArrayList(java.util.ArrayList) LatLng(com.google.android.gms.maps.model.LatLng) Func2(rx.functions.Func2) Action1(rx.functions.Action1) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Observable(rx.Observable) CompositeSubscription(rx.subscriptions.CompositeSubscription) AutocompletePrediction(com.google.android.gms.location.places.AutocompletePrediction) PlaceLikelihood(com.google.android.gms.location.places.PlaceLikelihood) Location(android.location.Location)

Example 19 with Location

use of android.location.Location in project ignition by mttkay.

the class IgnitedLocationChangedReceiver method onReceive.

/**
     * When a new location is received, extract it from the Intent and use it to start the Service
     * used to update the list of nearby places.
     * 
     * This is the Active receiver, used to receive Location updates when the Activity is visible.
     */
@Override
public void onReceive(Context context, Intent intent) {
    String key = LocationManager.KEY_LOCATION_CHANGED;
    String providerEnabledKey = LocationManager.KEY_PROVIDER_ENABLED;
    if (intent.hasExtra(providerEnabledKey)) {
        if (!intent.getBooleanExtra(providerEnabledKey, true)) {
            Intent providerDisabledIntent = new Intent(IgnitedLocationConstants.ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED_ACTION);
            context.sendBroadcast(providerDisabledIntent);
        }
    }
    if (intent.hasExtra(key)) {
        Log.d(LOG_TAG, "Actively updating location...");
        Location location = (Location) intent.getExtras().get(key);
        currentLocation = location;
    }
}
Also used : Intent(android.content.Intent) IgnitedLocation(com.github.ignition.location.annotations.IgnitedLocation) Location(android.location.Location)

Example 20 with Location

use of android.location.Location in project ignition by mttkay.

the class AbstractIgnitedLocationManagerTest method ignitedLocationIsCurrentLocation.

@Test
public void ignitedLocationIsCurrentLocation() {
    resume();
    assertThat(lastKnownLocation, equalTo(activity.getCurrentLocation()));
    Location newLocation = sendMockLocationBroadcast(LocationManager.GPS_PROVIDER);
    assertThat(newLocation, equalTo(activity.getCurrentLocation()));
}
Also used : Location(android.location.Location) Test(org.junit.Test)

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