Search in sources :

Example 1 with LatLng

use of fr.free.nrw.commons.location.LatLng in project apps-android-commons by commons-app.

the class NearbyControllerTest method testEmptyList.

@Test
public void testEmptyList() {
    LatLng location = new LatLng(0, 0, 0);
    List<Place> emptyList = new ArrayList<>();
    List<NearbyBaseMarker> options = NearbyController.loadAttractionsFromLocationToBaseMarkerOptions(location, emptyList, instrumentationContext);
    Assert.assertThat(options.size(), is(0));
}
Also used : NearbyBaseMarker(fr.free.nrw.commons.nearby.NearbyBaseMarker) ArrayList(java.util.ArrayList) LatLng(fr.free.nrw.commons.location.LatLng) Place(fr.free.nrw.commons.nearby.Place) Test(org.junit.Test)

Example 2 with LatLng

use of fr.free.nrw.commons.location.LatLng in project apps-android-commons by commons-app.

the class NearbyControllerTest method testNullAttractions.

@Test
public void testNullAttractions() {
    LatLng location = new LatLng(0, 0, 0);
    List<NearbyBaseMarker> options = NearbyController.loadAttractionsFromLocationToBaseMarkerOptions(location, null, instrumentationContext);
    Assert.assertThat(options.size(), is(0));
}
Also used : NearbyBaseMarker(fr.free.nrw.commons.nearby.NearbyBaseMarker) LatLng(fr.free.nrw.commons.location.LatLng) Test(org.junit.Test)

Example 3 with LatLng

use of fr.free.nrw.commons.location.LatLng in project apps-android-commons by commons-app.

the class NearbyListFragment method onItemClicked.

@OnItemClick(R.id.listView)
void onItemClicked(int position) {
    Place place = (Place) listview.getItemAtPosition(position);
    LatLng placeLatLng = place.location;
    double latitude = placeLatLng.getLatitude();
    double longitude = placeLatLng.getLongitude();
    Timber.d("Item at position %d has coords: Lat: %f Long: %f", position, latitude, longitude);
    NearbyInfoDialog.showYourself(getActivity(), place);
}
Also used : LatLng(fr.free.nrw.commons.location.LatLng) OnItemClick(butterknife.OnItemClick)

Example 4 with LatLng

use of fr.free.nrw.commons.location.LatLng in project apps-android-commons by commons-app.

the class NearbyPlaces method getFromWikiNeedsPictures.

List<Place> getFromWikiNeedsPictures() {
    if (places != null) {
        return places;
    } else {
        try {
            places = new ArrayList<>();
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
            URL file = new URL("https://tools.wmflabs.org/wiki-needs-pictures/data/data.csv");
            BufferedReader in = new BufferedReader(new InputStreamReader(file.openStream()));
            boolean firstLine = true;
            String line;
            Timber.d("Reading from CSV file...");
            while ((line = in.readLine()) != null) {
                // Skip CSV header.
                if (firstLine) {
                    firstLine = false;
                    continue;
                }
                String[] fields = line.split(",");
                String name = Utils.stripLocalizedString(fields[0]);
                double latitude;
                double longitude;
                try {
                    latitude = Double.parseDouble(fields[1]);
                } catch (NumberFormatException e) {
                    latitude = 0;
                }
                try {
                    longitude = Double.parseDouble(fields[2]);
                } catch (NumberFormatException e) {
                    longitude = 0;
                }
                String type = fields[3];
                places.add(new Place(name, // list
                type, // details
                type, null, new LatLng(latitude, longitude, 0), new Sitelinks.Builder().build()));
            }
            in.close();
        } catch (IOException e) {
            Timber.d(e.toString());
        }
    }
    return places;
}
Also used : InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) URL(java.net.URL) StrictMode(android.os.StrictMode) BufferedReader(java.io.BufferedReader) LatLng(fr.free.nrw.commons.location.LatLng)

Example 5 with LatLng

use of fr.free.nrw.commons.location.LatLng in project apps-android-commons by commons-app.

the class LatLngTests method testRounding.

@Test
public void testRounding() {
    LatLng place = new LatLng(0.1234567, -0.33333333, 0);
    String prettyString = place.getPrettyCoordinateString();
    Assert.assertThat(prettyString, is("0.1235 N, 0.3333 W"));
}
Also used : LatLng(fr.free.nrw.commons.location.LatLng) Test(org.junit.Test)

Aggregations

LatLng (fr.free.nrw.commons.location.LatLng)22 Test (org.junit.Test)16 Bundle (android.os.Bundle)2 NearbyBaseMarker (fr.free.nrw.commons.nearby.NearbyBaseMarker)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Uri (android.net.Uri)1 StrictMode (android.os.StrictMode)1 OnItemClick (butterknife.OnItemClick)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Place (fr.free.nrw.commons.nearby.Place)1 UriDeserializer (fr.free.nrw.commons.utils.UriDeserializer)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1 URLConnection (java.net.URLConnection)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1