public TrackLocation(){ isRunning=true; location=new Location("not defined"); location.setLatitude(0); location.setLongitude(0); } @Override
public Location toSysLocation() { Location location = new Location(LocationManager.GPS_PROVIDER); location.setAccuracy(8f); Bundle extraBundle = new Bundle(); location.setBearing(bearing); Reflect.on(location).call("setIsFromMockProvider", false); location.setLatitude(latitude); location.setLongitude(longitude); location.setSpeed(speed); location.setTime(System.currentTimeMillis()); location.setExtras(extraBundle); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { location.setElapsedRealtimeNanos(277000000); } int svCount = VirtualGPSSatalines.get().getSvCount(); extraBundle.putInt("satellites", svCount); extraBundle.putInt("satellitesvalue", svCount); return location; } }
@Test public void simulateLocation_shouldNotNotifyListenerIfLessThanFastestInterval() throws Exception { TestLocationListener listener = new TestLocationListener(); shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 2000, 0, listener); long time = System.currentTimeMillis(); Location location1 = new Location(GPS_PROVIDER); location1.setTime(time); Location location2 = new Location(GPS_PROVIDER); location2.setTime(time + 1000); shadowLocationManager.simulateLocation(location1); shadowLocationManager.simulateLocation(location2); assertThat(listener.location.getTime()).isEqualTo(location1.getTime()); }
private Location copyOf(Location location) { if (location == null) return null; Location copy = new Location(location); copy.setAccuracy(location.getAccuracy()); copy.setAltitude(location.getAltitude()); copy.setBearing(location.getBearing()); copy.setExtras(location.getExtras()); copy.setLatitude(location.getLatitude()); copy.setLongitude(location.getLongitude()); copy.setProvider(location.getProvider()); copy.setSpeed(location.getSpeed()); copy.setTime(location.getTime()); return copy; }
@Test public void requestLocationUpdates_shouldNotRegisterDuplicateListeners() throws Exception { TestLocationListener listener = new TestLocationListener(); shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 0, 0, listener); shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 0, 0, listener); shadowLocationManager.simulateLocation(new Location(GPS_PROVIDER)); assertThat(listener.updateCount).isEqualTo(1); }
@Test public void shouldNotThrowExceptionIfLocationListenerRemovedInsideOnLocationChanged() throws Exception { TestLocationListenerSelfRemoval listener = new TestLocationListenerSelfRemoval(locationManager); shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 0, 0, listener); Location location = new Location(GPS_PROVIDER); location.setLatitude(0); location.setLongitude(0); shadowLocationManager.simulateLocation(location); assertThat(shadowLocationManager.getRequestLocationUpdateListeners().size()).isEqualTo(0); }
@Test public void simulateLocation_shouldNotNotifyListenerIfLessThanMinimumDistance() throws Exception { TestLocationListener listener = new TestLocationListener(); locationManager.requestLocationUpdates(GPS_PROVIDER, 0, 200000, listener); Location location1 = new Location(GPS_PROVIDER); location1.setLatitude(1); location1.setLongitude(2); location1.setTime(0); Location location2 = new Location(GPS_PROVIDER); location2.setLatitude(1.5); location2.setLongitude(2.5); location2.setTime(1000); shadowLocationManager.simulateLocation(location1); shadowLocationManager.simulateLocation(location2); assertThat(listener.location.getLatitude()).isEqualTo(1.0d); assertThat(listener.location.getLongitude()).isEqualTo(2.0d); }
@Test public void shouldReturnLastKnownLocationForAProvider() throws Exception { assertNull(locationManager.getLastKnownLocation(NETWORK_PROVIDER)); Location networkLocation = new Location(NETWORK_PROVIDER); Location gpsLocation = new Location(GPS_PROVIDER); shadowLocationManager.setLastKnownLocation(NETWORK_PROVIDER, networkLocation); shadowLocationManager.setLastKnownLocation(GPS_PROVIDER, gpsLocation); assertSame(locationManager.getLastKnownLocation(NETWORK_PROVIDER), networkLocation); assertSame(locationManager.getLastKnownLocation(GPS_PROVIDER), gpsLocation); }
@Test public void testCreatePlacesSearchRequestWithLocation() { Location location = new Location(""); location.setLatitude(47.6204); location.setLongitude(-122.3491); GraphRequest request = GraphRequest.newPlacesSearchRequest(null, location, 1000, 50, null, null); assertTrue(request != null); assertEquals(HttpMethod.GET, request.getHttpMethod()); assertEquals("search", request.getGraphPath()); }
@Test public void testSearchPlaceForLocationRequest() { PlaceSearchRequestParams.Builder builder = new PlaceSearchRequestParams.Builder(); builder.setSearchText("search text"); builder.setLimit(5); builder.addCategory("category1"); builder.addCategory("category2"); builder.addField("field1"); builder.addField("field2"); builder.setDistance(500); PlaceSearchRequestParams params = builder.build(); Location location = new Location("dummy"); location.setLatitude(1); location.setLongitude(2); GraphRequest request = PlaceManager.newPlaceSearchRequestForLocation(params, location); assertEquals("search", request.getGraphPath()); assertEquals(HttpMethod.GET, request.getHttpMethod()); Bundle requestParams = request.getParameters(); assertEquals("search text", requestParams.get("q")); assertEquals(500, requestParams.get("distance")); assertEquals(5, requestParams.get("limit")); assertEquals("1.000000,2.000000", requestParams.get("center")); assertEquals("field1,field2", requestParams.get("fields")); assertEquals("place", requestParams.get("type")); assertEquals("[\"category2\",\"category1\"]", requestParams.get("categories")); }
@LargeTest public void testExecutePlaceRequestWithLocationAndSearchText() { Location location = new Location(""); location.setLatitude(47.6204); location.setLongitude(-122.3491); GraphRequest request = GraphRequest.newPlacesSearchRequest( AccessToken.getCurrentAccessToken(), location, 1000, 5, "Starbucks", null); GraphResponse response = request.executeAndWait(); assertNotNull(response); assertNull(response.getError()); JSONObject graphResult = response.getJSONObject(); assertNotNull(graphResult); JSONArray results = graphResult.optJSONArray("data"); assertNotNull(results); assertNotNull(response.getRawResponse()); }
@LargeTest public void testExecutePlaceRequestWithLocation() { Location location = new Location(""); location.setLatitude(47.6204); location.setLongitude(-122.3491); GraphRequest request = GraphRequest.newPlacesSearchRequest( AccessToken.getCurrentAccessToken(), location, 5, 5, null, null); GraphResponse response = request.executeAndWait(); assertNotNull(response); assertNull(response.getError()); JSONObject graphResult = response.getJSONObject(); assertNotNull(graphResult); JSONArray results = graphResult.optJSONArray("data"); assertNotNull(results); assertNotNull(response.getRawResponse()); }
private Location dummyLocation() { Location l = new Location(""); l.setLatitude(0.0); l.setLongitude(0.0); return l; }
@Override public void onLocationChanged(Location location) { diaryLocations = new Location(location); diaryHandler.removeCallbacksAndMessages(null); diaryHandler.sendEmptyMessage(0); try { locationManager.removeUpdates(this); } catch (SecurityException e) { e.printStackTrace(); } }
@Override public void onLocationChanged(Location location) { diaryLocations = new Location(location); diaryViewerHandler.removeCallbacksAndMessages(null); diaryViewerHandler.sendEmptyMessage(0); try { locationManager.removeUpdates(this); } catch (SecurityException e) { e.printStackTrace(); } }
@Override public void onMapLongClick(LatLng point) { if (mListener != null && !mPaused) { Location location = new Location("LongPressLocationProvider"); location.setLatitude(point.latitude); location.setLongitude(point.longitude); location.setAccuracy(100); mListener.onLocationChanged(location); } }
@Test public void testBuilder() { Location location = new Location("dummy"); location.setLatitude(1.0); location.setLongitude(2.0); CurrentPlaceRequestParams.Builder builder = new CurrentPlaceRequestParams.Builder(); builder.setMinConfidenceLevel(CurrentPlaceRequestParams.ConfidenceLevel.MEDIUM); builder.setLimit(22); builder.setScanMode(CurrentPlaceRequestParams.ScanMode.LOW_LATENCY); builder.setLocation(location); builder.addField("field1"); builder.addField("field2"); CurrentPlaceRequestParams params = builder.build(); assertEquals(22, params.getLimit()); assertEquals(location, params.getLocation()); assertEquals( CurrentPlaceRequestParams.ConfidenceLevel.MEDIUM, params.getMinConfidenceLevel()); assertEquals(CurrentPlaceRequestParams.ScanMode.LOW_LATENCY, params.getScanMode()); assertSetEqual(new String[]{"field1", "field2"}, params.getFields()); }
@NonNull public Location getLocation() { Location l= new Location("waypoint"); l.setLatitude(getGeofenceLatitude()); l.setLongitude(getGeofenceLongitude()); l.setAccuracy(getGeofenceRadius()); return l; }
@Test public void checkForLastKnownLocationShouldCallOnLocationReceivedAndReturnTrueWhenSufficient() { defaultLocationProvider.setCurrentProvider(GPS_PROVIDER); Location location = new Location(GPS_PROVIDER); when(defaultProviderConfiguration.acceptableAccuracy()).thenReturn(1F); when(defaultProviderConfiguration.acceptableTimePeriod()).thenReturn(1L); when(defaultLocationSource.getLastKnownLocation(GPS_PROVIDER)).thenReturn(location); when(defaultLocationSource.isLocationSufficient(location, 1L, 1F)).thenReturn(true); assertThat(defaultLocationProvider.checkForLastKnowLocation()).isTrue(); verify(locationListener).onLocationChanged(location); }
@Test public void onConnectedShouldNotCallLocationRequiredWhenLastKnowIsReadyAndNoNeedToKeepTracking() { when(mockedSource.getLocationAvailability()).thenReturn(true); when(mockedSource.getLastLocation()).thenReturn(new Location("")); when(locationConfiguration.keepTracking()).thenReturn(false); googlePlayServicesLocationProvider.waitingForConnectionToRequestLocationUpdate(false); googlePlayServicesLocationProvider.onConnected(null); verify(googlePlayServicesLocationProvider, never()).locationRequired(); }