Search in sources :

Example 36 with Location

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

Example 37 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 38 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 39 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)

Example 40 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)

Aggregations

Location (android.location.Location)290 Bundle (android.os.Bundle)50 LocationListener (android.location.LocationListener)38 LocationManager (android.location.LocationManager)33 ArrayList (java.util.ArrayList)29 Criteria (android.location.Criteria)20 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 Intent (android.content.Intent)8 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